7 Commits

Author SHA1 Message Date
Christian Knaapen
2c6b58ddc6 Fixed issue #45: Can't break blocks in survival mode if breakFar=false. 2019-07-09 02:23:35 +02:00
Christian Knaapen
3921a0b70b Fixed issue #43: Duplicating blocks in survival (undo/redo not working in normal mode).
Fixed QuickReplace in normal mode not placing any blocks.
Fixed blockstates sometimes changing on undo/redo.
Now clearing UndoRedo stacks on clientside when changing dimension or logging out.
Breaking mirror/array in survival is now possible again.
Breaking blocks in survival in any buildmode is now possible (previously only in normal mode unless instabreaking was enabled). Still with limited (vanilla) reach.
2019-07-09 02:11:32 +02:00
Christian Knaapen
11cd20c3d3 Fixed QuickReplace in normal mode not placing any blocks. 2019-07-08 22:54:33 +02:00
Christian Knaapen
4ce8b1e927 Fixed issue #23 dank/null compat only uses one block at a time regardless of how many are placed. 2019-07-06 13:17:08 +02:00
Christian Knaapen
0485e6c888 README.md created online with Bitbucket 2019-07-03 10:26:25 +00:00
Christian Knaapen
89057356df Changed MaxBlocksPerAxis and MaxBlocksPlaced formulas. Now allows placing of 60x60 floors and walls with reach upgrade 3 in survival. 2019-06-05 20:02:37 +02:00
Christian Knaapen
a7ac229242 Fixed issue #37 Visual Glitch when destroying blocks 2019-05-17 16:26:19 +02:00
19 changed files with 357 additions and 139 deletions

3
README.md Normal file
View File

@@ -0,0 +1,3 @@
This is the version for Minecraft 1.12.
1.13 can be found here: https://bitbucket.org/Requios/effortless-building-1.13/src/master/

View File

@@ -11,7 +11,7 @@ apply plugin: 'net.minecraftforge.gradle.forge'
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
version = "1.12.2-2.10"
version = "1.12.2-2.13"
group = "nl.requios.effortlessbuilding" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "effortlessbuilding"

View File

@@ -55,7 +55,7 @@ public class BuildConfig {
@Comment({"Determines what blocks can be replaced in survival.",
"-1: only blocks that can be harvested by hand (default)",
"0: blocks that can be harvested with wooden oref gold tools",
"0: blocks that can be harvested with wooden or gold tools",
"1: blocks that can be harvested with stone tools",
"2: blocks that can be harvested with iron tools",
"3: blocks that can be harvested with diamond tools",

View File

@@ -39,7 +39,7 @@ public class EffortlessBuilding
{
public static final String MODID = "effortlessbuilding";
public static final String NAME = "Effortless Building";
public static final String VERSION = "1.12.2-2.10";
public static final String VERSION = "1.12.2-2.13";
@Mod.Instance(EffortlessBuilding.MODID)
public static EffortlessBuilding instance;
@@ -93,11 +93,20 @@ public class EffortlessBuilding
EffortlessBuilding.packetHandler.registerMessage(BlockPlacedMessage.MessageHandler.class, BlockPlacedMessage.class, 3, Side.CLIENT);
EffortlessBuilding.packetHandler.registerMessage(BlockBrokenMessage.MessageHandler.class, BlockBrokenMessage.class, 4, Side.SERVER);
EffortlessBuilding.packetHandler.registerMessage(BlockBrokenMessage.MessageHandler.class, BlockBrokenMessage.class, 4, Side.CLIENT);
EffortlessBuilding.packetHandler.registerMessage(CancelModeMessage.MessageHandler.class, CancelModeMessage.class, 5, Side.SERVER);
EffortlessBuilding.packetHandler.registerMessage(CancelModeMessage.MessageHandler.class, CancelModeMessage.class, 5, Side.CLIENT);
EffortlessBuilding.packetHandler.registerMessage(RequestLookAtMessage.MessageHandler.class, RequestLookAtMessage.class, 6, Side.SERVER);
EffortlessBuilding.packetHandler.registerMessage(RequestLookAtMessage.MessageHandler.class, RequestLookAtMessage.class, 6, Side.CLIENT);
EffortlessBuilding.packetHandler.registerMessage(AddUndoMessage.MessageHandler.class, AddUndoMessage.class, 7, Side.SERVER);
EffortlessBuilding.packetHandler.registerMessage(AddUndoMessage.MessageHandler.class, AddUndoMessage.class, 7, Side.CLIENT);
EffortlessBuilding.packetHandler.registerMessage(ClearUndoMessage.MessageHandler.class, ClearUndoMessage.class, 8, Side.SERVER);
EffortlessBuilding.packetHandler.registerMessage(ClearUndoMessage.MessageHandler.class, ClearUndoMessage.class, 8, Side.CLIENT);
proxy.preInit(event);
}

View File

@@ -5,6 +5,7 @@ import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.util.ResourceLocation;
@@ -30,6 +31,9 @@ import nl.requios.effortlessbuilding.capability.ModeCapabilityManager;
import nl.requios.effortlessbuilding.capability.ModifierCapabilityManager;
import nl.requios.effortlessbuilding.helper.ReachHelper;
import nl.requios.effortlessbuilding.helper.SurvivalHelper;
import nl.requios.effortlessbuilding.network.AddUndoMessage;
import nl.requios.effortlessbuilding.network.BlockBrokenMessage;
import nl.requios.effortlessbuilding.network.ClearUndoMessage;
import nl.requios.effortlessbuilding.network.RequestLookAtMessage;
import scala.actors.threadpool.Arrays;
@@ -91,14 +95,20 @@ public class EventHandler
BuildModes.BuildModeEnum buildMode = ModeSettingsManager.getModeSettings(player).getBuildMode();
ModifierSettingsManager.ModifierSettings modifierSettings = ModifierSettingsManager.getModifierSettings(player);
if (buildMode != BuildModes.BuildModeEnum.NORMAL || modifierSettings.doQuickReplace()) {
if (buildMode != BuildModes.BuildModeEnum.NORMAL) {
event.setCanceled(true);
} else if (modifierSettings.doQuickReplace()) {
//Cancel event and send message if QuickReplace
event.setCanceled(true);
EffortlessBuilding.packetHandler.sendTo(new RequestLookAtMessage(true), (EntityPlayerMP) player);
EffortlessBuilding.packetHandler.sendTo(new AddUndoMessage(event.getPos(), event.getBlockSnapshot().getReplacedBlock(), event.getState()), (EntityPlayerMP) player);
} else {
//NORMAL mode, let vanilla handle block placing
//But modifiers and QuickReplace should still work
//But modifiers should still work
//Send message to client, which sends message back with raytrace info
EffortlessBuilding.packetHandler.sendTo(new RequestLookAtMessage(event.getPos(), event.getBlockSnapshot().getReplacedBlock(), event.getState()), (EntityPlayerMP) player);
EffortlessBuilding.packetHandler.sendTo(new RequestLookAtMessage(false), (EntityPlayerMP) player);
EffortlessBuilding.packetHandler.sendTo(new AddUndoMessage(event.getPos(), event.getBlockSnapshot().getReplacedBlock(), event.getState()), (EntityPlayerMP) player);
}
}
@@ -113,9 +123,12 @@ public class EventHandler
event.setCanceled(true);
} else {
//NORMAL mode, let vanilla handle block breaking
//But modifiers and QuickReplace should still work
//But modifiers should still work
//Dont break the original block yourself, otherwise Tinkers Hammer and Veinminer won't work
BuildModes.onBlockBroken(event.getPlayer(), event.getPos(), false);
//Add to undo stack in client
EffortlessBuilding.packetHandler.sendTo(new AddUndoMessage(event.getPos(), event.getState(), Blocks.AIR.getDefaultState()), (EntityPlayerMP) event.getPlayer());
}
}
@@ -165,8 +178,11 @@ public class EventHandler
@SubscribeEvent
public static void onPlayerLoggedOut(PlayerLoggedOutEvent event) {
UndoRedo.clear(event.player);
//TODO call clientside
EntityPlayer player = event.player;
if (player.getEntityWorld().isRemote) return;
UndoRedo.clear(player);
EffortlessBuilding.packetHandler.sendTo(new ClearUndoMessage(), (EntityPlayerMP) player);
}
@SubscribeEvent
@@ -179,10 +195,12 @@ public class EventHandler
@SubscribeEvent
public static void onPlayerChangedDimension(PlayerChangedDimensionEvent event) {
EntityPlayer player = event.player;
if (player.getEntityWorld().isRemote) return;
ModifierSettingsManager.handleNewPlayer(player);
ModeSettingsManager.handleNewPlayer(player);
UndoRedo.clear(event.player);
//TODO call clientside
EffortlessBuilding.packetHandler.sendTo(new ClearUndoMessage(), (EntityPlayerMP) player);
}
}

View File

@@ -135,16 +135,16 @@ public class BuildModes {
return;
}
if (!ReachHelper.canBreakFar(player)) return;
//If first click
if (currentlyBreaking.get(player) == null) {
//If startpos is null, dont do anything
if (startPos == null) return;
}
//Get coordinates
ModifierSettingsManager.ModifierSettings modifierSettings = ModifierSettingsManager.getModifierSettings(player);
ModeSettingsManager.ModeSettings modeSettings = ModeSettingsManager.getModeSettings(player);
//Get coordinates
BuildModeEnum buildMode = modeSettings.getBuildMode();
List<BlockPos> coordinates = buildMode.instance.onRightClick(player, startPos, EnumFacing.UP, Vec3d.ZERO, true);

View File

@@ -3,6 +3,7 @@ package nl.requios.effortlessbuilding.buildmodifier;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
@@ -75,12 +76,21 @@ public class BuildModifiers {
}
}
//Set first previousBlockState to empty if in NORMAL mode, to make undo/redo work
//(Block is placed by the time it gets here, and unplaced after this)
if (!placeStartPos) previousBlockStates.set(0, Blocks.AIR.getDefaultState());
//If all new blockstates are air then no use in adding it, no block was actually placed
//Can happen when e.g. placing one block in yourself
if (Collections.frequency(newBlockStates, Blocks.AIR.getDefaultState()) != newBlockStates.size()) {
//add to undo stack
BlockPos firstPos = startCoordinates.get(0);
BlockPos secondPos = startCoordinates.get(startCoordinates.size() - 1);
UndoRedo.addUndo(player, new BlockSet(coordinates, previousBlockStates, newBlockStates, hitVec, firstPos, secondPos));
}
}
public static void onBlockBroken(EntityPlayer player, List<BlockPos> startCoordinates, boolean breakStartPos) {
World world = player.world;
@@ -100,7 +110,7 @@ public class BuildModifiers {
//list of air blockstates
for (BlockPos coordinate : coordinates) {
newBlockStates.add(Block.getBlockById(0).getDefaultState());
newBlockStates.add(Blocks.AIR.getDefaultState());
}
} else {
@@ -125,6 +135,10 @@ public class BuildModifiers {
}
}
//Set first newBlockState to empty if in NORMAL mode, to make undo/redo work
//(Block isn't broken yet by the time it gets here, and broken after this)
if (!breakStartPos) newBlockStates.set(0, Blocks.AIR.getDefaultState());
//add to undo stack
BlockPos firstPos = startCoordinates.get(0);
BlockPos secondPos = startCoordinates.get(startCoordinates.size() - 1);

View File

@@ -3,6 +3,7 @@ package nl.requios.effortlessbuilding.buildmodifier;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
@@ -31,17 +32,36 @@ public class UndoRedo {
public static void addUndo(EntityPlayer player, BlockSet blockSet) {
Map<UUID, FixedStack<BlockSet>> undoStacks = player.world.isRemote ? undoStacksClient : undoStacksServer;
//Assert coordinates is as long as previous and new blockstate lists
if (blockSet.getCoordinates().size() != blockSet.getPreviousBlockStates().size() ||
blockSet.getCoordinates().size() != blockSet.getNewBlockStates().size()) {
EffortlessBuilding.logger.error("Coordinates and blockstate lists are not equal length. Coordinates: {}. Previous blockstates: {}. New blockstates: {}.",
blockSet.getCoordinates().size(), blockSet.getPreviousBlockStates().size(), blockSet.getNewBlockStates().size());
}
//Warn if previous and new blockstate are equal
//Can happen in a lot of valid cases
// for (int i = 0; i < blockSet.getCoordinates().size(); i++) {
// if (blockSet.getPreviousBlockStates().get(i).equals(blockSet.getNewBlockStates().get(i))) {
// EffortlessBuilding.logger.warn("Previous and new blockstates are equal at index {}. Blockstate: {}.",
// i, blockSet.getPreviousBlockStates().get(i));
// }
// }
//If no stack exists, make one
if (!undoStacks.containsKey(player.getUniqueID())) {
undoStacks.put(player.getUniqueID(), new FixedStack<>(new BlockSet[BuildConfig.survivalBalancers.undoStackSize]));
}
undoStacks.get(player.getUniqueID()).push(blockSet);
}
private static void addRedo(EntityPlayer player, BlockSet blockSet) {
Map<UUID, FixedStack<BlockSet>> redoStacks = player.world.isRemote ? redoStacksClient : redoStacksServer;
//(No asserts necessary, it's private)
//If no stack exists, make one
if (!redoStacks.containsKey(player.getUniqueID())) {
redoStacks.put(player.getUniqueID(), new FixedStack<>(new BlockSet[BuildConfig.survivalBalancers.undoStackSize]));
@@ -76,10 +96,12 @@ public class UndoRedo {
BlockPos coordinate = coordinates.get(i);
ItemStack itemStack = itemStacks.get(i);
if (previousBlockStates.get(i).equals(newBlockStates.get(i))) continue;
//get blockstate from itemstack
IBlockState previousBlockState = Block.getBlockById(0).getDefaultState();
IBlockState previousBlockState = Blocks.AIR.getDefaultState();
if (itemStack.getItem() instanceof ItemBlock) {
previousBlockState = ((ItemBlock) itemStack.getItem()).getBlock().getDefaultState();
previousBlockState = previousBlockStates.get(i);//((ItemBlock) itemStack.getItem()).getBlock().getDefaultState();
}
if (player.world.isBlockLoaded(coordinate, true)) {
@@ -88,7 +110,9 @@ public class UndoRedo {
itemStack = findItemStackInInventory(player, previousBlockStates.get(i));
//get blockstate from new itemstack
if (!itemStack.isEmpty() && itemStack.getItem() instanceof ItemBlock) {
previousBlockState = ((ItemBlock) itemStack.getItem()).getBlock().getDefaultState();
previousBlockState = previousBlockStates.get(i);//((ItemBlock) itemStack.getItem()).getBlock().getDefaultState();
} else {
previousBlockState = Blocks.AIR.getDefaultState();
}
}
if (itemStack.isEmpty()) SurvivalHelper.breakBlock(player.world, player, coordinate, true);
@@ -115,6 +139,7 @@ public class UndoRedo {
BlockSet blockSet = redoStack.pop();
List<BlockPos> coordinates = blockSet.getCoordinates();
List<IBlockState> previousBlockStates = blockSet.getPreviousBlockStates();
List<IBlockState> newBlockStates = blockSet.getNewBlockStates();
Vec3d hitVec = blockSet.getHitVec();
@@ -127,16 +152,25 @@ public class UndoRedo {
//place blocks
for (int i = 0; i < coordinates.size(); i++) {
BlockPos coordinate = coordinates.get(i);
IBlockState newBlockState = newBlockStates.get(i);
ItemStack itemStack = itemStacks.get(i);
if (previousBlockStates.get(i).equals(newBlockStates.get(i))) continue;
//get blockstate from itemstack
IBlockState newBlockState = Blocks.AIR.getDefaultState();
if (itemStack.getItem() instanceof ItemBlock) {
newBlockState = newBlockStates.get(i);//((ItemBlock) itemStack.getItem()).getBlock().getDefaultState();
}
if (player.world.isBlockLoaded(coordinate, true)) {
//check itemstack empty
if (itemStack.isEmpty()) {
itemStack = findItemStackInInventory(player, newBlockStates.get(i));
//get blockstate from new itemstack
if (!itemStack.isEmpty() && itemStack.getItem() instanceof ItemBlock) {
newBlockState = ((ItemBlock) itemStack.getItem()).getBlock().getDefaultState();
newBlockState = newBlockStates.get(i);//((ItemBlock) itemStack.getItem()).getBlock().getDefaultState();
} else {
newBlockState = Blocks.AIR.getDefaultState();
}
}
if (itemStack.isEmpty()) SurvivalHelper.breakBlock(player.world, player, coordinate, true);
@@ -174,6 +208,8 @@ public class UndoRedo {
ItemStack itemStack = ItemStack.EMPTY;
//First try previousBlockStates
//TODO try to find itemstack with right blockstate first
// then change line 103 back (get state from item)
itemStack = InventoryHelper.findItemStackInInventory(player, blockState.getBlock());
//then anything it drops

View File

@@ -1,9 +1,11 @@
package nl.requios.effortlessbuilding.compatibility;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.items.CapabilityItemHandler;
@@ -63,9 +65,9 @@ public class CompatHelper {
}
//Dank Null
if(proxyItem == dankNullItem) {
if (proxyItem == dankNullItem) {
int index = 0;
if(proxy.hasTagCompound() && proxy.getTagCompound().hasKey("selectedIndex"))
if (proxy.hasTagCompound() && proxy.getTagCompound().hasKey("selectedIndex"))
index = proxy.getTagCompound().getInteger("selectedIndex");
return proxy.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).getStackInSlot(index);
}
@@ -75,14 +77,14 @@ public class CompatHelper {
public static ItemStack getItemBlockByState(ItemStack stack, IBlockState state) {
Item blockItem = Item.getItemFromBlock(state.getBlock());
if(stack.getItem() instanceof ItemBlock)
if (stack.getItem() instanceof ItemBlock)
return stack;
else if(stack.getItem() instanceof ItemRandomizerBag) {
else if (stack.getItem() instanceof ItemRandomizerBag) {
IItemHandler bagInventory = ItemRandomizerBag.getBagInventory(stack);
return ItemRandomizerBag.findStack(bagInventory, blockItem);
} else if(stack.getItem() == dankNullItem) {
} else if (stack.getItem() == dankNullItem) {
int index = itemHandlerSlotForItem(stack, blockItem);
if(index >= 0)
if (index >= 0)
return stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).getStackInSlot(index);
}
return ItemStack.EMPTY;
@@ -90,8 +92,11 @@ public class CompatHelper {
// Handle IItemHandler slot stacks not being modifiable. We must call IItemHandler#extractItem,
// because the ItemStack returned by IItemHandler#getStackInSlot isn't modifiable.
public static void shrinkStack(ItemStack origStack, ItemStack curStack) {
if(origStack.getItem() == dankNullItem) {
public static void shrinkStack(ItemStack origStack, ItemStack curStack, EntityPlayer player) {
//Hacky way to get the origstack, because given origStack is itemblock stack and never a proxy
origStack = player.getHeldItem(EnumHand.MAIN_HAND);
if (origStack.getItem() == dankNullItem) {
int index = itemHandlerSlotForItem(origStack, curStack.getItem());
origStack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).extractItem(index, 1, false);
} else
@@ -100,10 +105,10 @@ public class CompatHelper {
private static int itemHandlerSlotForItem(ItemStack stack, Item blockItem) {
IItemHandler handler = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
for(int i = 0; i < handler.getSlots(); i++) {
for (int i = 0; i < handler.getSlots(); i++) {
ItemStack ref = handler.getStackInSlot(i);
if(ref.getItem() instanceof ItemBlock)
if(ref.getItem() == blockItem)
if (ref.getItem() instanceof ItemBlock)
if (ref.getItem() == blockItem)
return i;
}
return -1;

View File

@@ -28,12 +28,20 @@ public class ReachHelper {
public static int getMaxBlocksPlacedAtOnce(EntityPlayer player) {
if (player.isCreative()) return 1000000;
return getMaxReach(player) * 5;
return MathHelper.ceil(Math.pow(getMaxReach(player), 1.6));
//Level 0: 121
//Level 1: 523
//Level 2: 1585
//Level 3: 4805
}
public static int getMaxBlocksPerAxis(EntityPlayer player) {
if (player.isCreative()) return 2000;
return MathHelper.ceil(MathHelper.sqrt(getMaxReach(player)));
return MathHelper.ceil(getMaxReach(player) * 0.3);
//Level 0: 6
//Level 1: 15
//Level 2: 30
//Level 3: 60
}
public static boolean canBreakFar(EntityPlayer player) {

View File

@@ -71,7 +71,7 @@ public class SurvivalHelper {
}
if (!player.isCreative() && Block.getBlockFromItem(itemstack.getItem()) == block) {
CompatHelper.shrinkStack(origstack, itemstack);
CompatHelper.shrinkStack(origstack, itemstack, player);
}
return true;

View File

@@ -0,0 +1,94 @@
package nl.requios.effortlessbuilding.network;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import nl.requios.effortlessbuilding.buildmodifier.BlockSet;
import nl.requios.effortlessbuilding.buildmodifier.UndoRedo;
import nl.requios.effortlessbuilding.proxy.ClientProxy;
import java.util.ArrayList;
/***
* Sends a message to the client asking to add a block to the undo stack.
*/
public class AddUndoMessage implements IMessage {
private BlockPos coordinate;
private IBlockState previousBlockState;
private IBlockState newBlockState;
public AddUndoMessage() {
coordinate = BlockPos.ORIGIN;
previousBlockState = null;
newBlockState = null;
}
public AddUndoMessage(BlockPos coordinate, IBlockState previousBlockState, IBlockState newBlockState) {
this.coordinate = coordinate;
this.previousBlockState = previousBlockState;
this.newBlockState = newBlockState;
}
public BlockPos getCoordinate() {
return coordinate;
}
public IBlockState getPreviousBlockState() {
return previousBlockState;
}
public IBlockState getNewBlockState() {
return newBlockState;
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(this.coordinate.getX());
buf.writeInt(this.coordinate.getY());
buf.writeInt(this.coordinate.getZ());
buf.writeInt(Block.getStateId(this.previousBlockState));
buf.writeInt(Block.getStateId(this.newBlockState));
}
@Override
public void fromBytes(ByteBuf buf) {
coordinate = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt());
previousBlockState = Block.getStateById(buf.readInt());
newBlockState = Block.getStateById(buf.readInt());
}
// The params of the IMessageHandler are <REQ, REPLY>
public static class MessageHandler implements IMessageHandler<AddUndoMessage, IMessage> {
// Do note that the default constructor is required, but implicitly defined in this case
@Override
public IMessage onMessage(AddUndoMessage message, MessageContext ctx) {
//EffortlessBuilding.log("message received on " + ctx.side + " side");
if (ctx.side == Side.CLIENT){
//Received clientside
EffortlessBuilding.proxy.getThreadListenerFromContext(ctx).addScheduledTask(() -> {
EntityPlayer player = EffortlessBuilding.proxy.getPlayerEntityFromContext(ctx);
//Add to undo stack clientside
UndoRedo.addUndo(player, new BlockSet(
new ArrayList<BlockPos>() {{add(message.getCoordinate());}},
new ArrayList<IBlockState>() {{add(message.getPreviousBlockState());}},
new ArrayList<IBlockState>() {{add(message.getNewBlockState());}},
new Vec3d(0,0,0),
message.getCoordinate(), message.getCoordinate()));
});
}
return null;
}
}
}

View File

@@ -0,0 +1,57 @@
package nl.requios.effortlessbuilding.network;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import nl.requios.effortlessbuilding.buildmodifier.BlockSet;
import nl.requios.effortlessbuilding.buildmodifier.UndoRedo;
import nl.requios.effortlessbuilding.proxy.ClientProxy;
import java.util.ArrayList;
/***
* Sends a message to the client asking to clear the undo and redo stacks.
*/
public class ClearUndoMessage implements IMessage {
public ClearUndoMessage() {
}
@Override
public void toBytes(ByteBuf buf) {
}
@Override
public void fromBytes(ByteBuf buf) {
}
// The params of the IMessageHandler are <REQ, REPLY>
public static class MessageHandler implements IMessageHandler<ClearUndoMessage, IMessage> {
// Do note that the default constructor is required, but implicitly defined in this case
@Override
public IMessage onMessage(ClearUndoMessage message, MessageContext ctx) {
//EffortlessBuilding.log("message received on " + ctx.side + " side");
if (ctx.side == Side.CLIENT){
//Received clientside
EffortlessBuilding.proxy.getThreadListenerFromContext(ctx).addScheduledTask(() -> {
EntityPlayer player = EffortlessBuilding.proxy.getPlayerEntityFromContext(ctx);
//Add to undo stack clientside
UndoRedo.clear(player);
});
}
return null;
}
}
}

View File

@@ -22,48 +22,28 @@ import java.util.ArrayList;
* This is then sent back with a BlockPlacedMessage.
*/
public class RequestLookAtMessage implements IMessage {
private BlockPos coordinate;
private IBlockState previousBlockState;
private IBlockState newBlockState;
private boolean placeStartPos;
public RequestLookAtMessage() {
coordinate = BlockPos.ORIGIN;
previousBlockState = null;
newBlockState = null;
placeStartPos = false;
}
public RequestLookAtMessage(BlockPos coordinate, IBlockState previousBlockState, IBlockState newBlockState) {
this.coordinate = coordinate;
this.previousBlockState = previousBlockState;
this.newBlockState = newBlockState;
public RequestLookAtMessage(boolean placeStartPos) {
this.placeStartPos = placeStartPos;
}
public BlockPos getCoordinate() {
return coordinate;
}
public IBlockState getPreviousBlockState() {
return previousBlockState;
}
public IBlockState getNewBlockState() {
return newBlockState;
public boolean getPlaceStartPos() {
return placeStartPos;
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(this.coordinate.getX());
buf.writeInt(this.coordinate.getY());
buf.writeInt(this.coordinate.getZ());
buf.writeInt(Block.getStateId(this.previousBlockState));
buf.writeInt(Block.getStateId(this.newBlockState));
buf.writeBoolean(this.placeStartPos);
}
@Override
public void fromBytes(ByteBuf buf) {
coordinate = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt());
previousBlockState = Block.getStateById(buf.readInt());
newBlockState = Block.getStateById(buf.readInt());
placeStartPos = buf.readBoolean();
}
// The params of the IMessageHandler are <REQ, REPLY>
@@ -78,20 +58,14 @@ public class RequestLookAtMessage implements IMessage {
//Received clientside
//Send back your info
EffortlessBuilding.proxy.getThreadListenerFromContext(ctx).addScheduledTask(() -> {
EntityPlayer player = EffortlessBuilding.proxy.getPlayerEntityFromContext(ctx);
// EffortlessBuilding.proxy.getThreadListenerFromContext(ctx).addScheduledTask(() -> {
// EntityPlayer player = EffortlessBuilding.proxy.getPlayerEntityFromContext(ctx);
//
// });
//Add to undo stack clientside
UndoRedo.addUndo(player, new BlockSet(
new ArrayList<BlockPos>() {{add(message.getCoordinate());}},
new ArrayList<IBlockState>() {{add(message.getPreviousBlockState());}},
new ArrayList<IBlockState>() {{add(message.getNewBlockState());}},
new Vec3d(0,0,0),
message.getCoordinate(), message.getCoordinate()));
});
//Prevent double placing in normal mode with placeStartPos false
return new BlockPlacedMessage(ClientProxy.previousLookAt, false);
//Prevent double placing in normal mode with placeStartPos false.
//Unless QuickReplace is on, then we do need to place start pos.
return new BlockPlacedMessage(ClientProxy.previousLookAt, message.getPlaceStartPos());
}
return null;
}

View File

@@ -81,7 +81,7 @@ public class ClientProxy implements IProxy {
@Override
public void init(FMLInitializationEvent event) {
// register key bindings
keyBindings = new KeyBinding[7];
keyBindings = new KeyBinding[6];
// instantiate the key bindings
keyBindings[0] = new KeyBinding("key.effortlessbuilding.hud.desc", KeyConflictContext.UNIVERSAL, Keyboard.KEY_ADD, "key.effortlessbuilding.category");
@@ -97,7 +97,7 @@ public class ClientProxy implements IProxy {
};
keyBindings[4] = new KeyBinding("key.effortlessbuilding.undo.desc", KeyConflictContext.IN_GAME, KeyModifier.CONTROL, Keyboard.KEY_Z, "key.effortlessbuilding.category");
keyBindings[5] = new KeyBinding("key.effortlessbuilding.redo.desc", KeyConflictContext.IN_GAME, KeyModifier.CONTROL, Keyboard.KEY_Y, "key.effortlessbuilding.category");
keyBindings[6] = new KeyBinding("Reload shaders", Keyboard.KEY_TAB, "key.effortlessbuilding.category");
// keyBindings[6] = new KeyBinding("Reload shaders", Keyboard.KEY_TAB, "key.effortlessbuilding.category");
// register all the key bindings
for (int i = 0; i < keyBindings.length; ++i) {
@@ -261,6 +261,11 @@ public class ClientProxy implements IProxy {
//Break block in distance in creative (or survival if enabled in config)
if (breakCooldown <= 0) {
breakCooldown = 4;
//Early out if cant break far, coming from own mouse event (not block broken event)
//To make breaking blocks in survival possible without breaking instantly
if (!ReachHelper.canBreakFar(player)) return;
RayTraceResult lookingAt = getLookingAt(player);
BuildModes.onBlockBrokenMessage(player, lookingAt == null ? new BlockBrokenMessage() : new BlockBrokenMessage(lookingAt));

View File

@@ -5,11 +5,13 @@ import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.renderer.BlockRendererDispatcher;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.*;
import net.minecraftforge.fml.relauncher.Side;
@@ -24,13 +26,14 @@ import nl.requios.effortlessbuilding.buildmodifier.BuildModifiers;
import nl.requios.effortlessbuilding.buildmodifier.ModifierSettingsManager;
import nl.requios.effortlessbuilding.buildmodifier.ModifierSettingsManager.ModifierSettings;
import nl.requios.effortlessbuilding.compatibility.CompatHelper;
import nl.requios.effortlessbuilding.helper.InventoryHelper;
import nl.requios.effortlessbuilding.helper.ReachHelper;
import nl.requios.effortlessbuilding.helper.SurvivalHelper;
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
import nl.requios.effortlessbuilding.proxy.ClientProxy;
import org.lwjgl.opengl.ARBMultitexture;
import org.lwjgl.opengl.ARBShaderObjects;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL20;
import java.util.ArrayList;
import java.util.Collections;
@@ -70,7 +73,7 @@ public class BlockPreviewRenderer {
private static List<PlacedData> placedDataList = new ArrayList<>();
private static final int primaryTextureUnit = 0;
private static final int secondaryTextureUnit = 1;
private static final int secondaryTextureUnit = 2;
public static void render(EntityPlayer player, ModifierSettings modifierSettings, ModeSettings modeSettings) {
@@ -370,40 +373,39 @@ public class BlockPreviewRenderer {
final boolean highlight, final boolean red) {
Minecraft mc = Minecraft.getMinecraft();
return (Integer shader) -> {
int percentileUniform = GL20.glGetUniformLocation(shader, "dissolve");
int highlightUniform = GL20.glGetUniformLocation(shader, "highlight");
int redUniform = GL20.glGetUniformLocation(shader, "red");
int blockposUniform = GL20.glGetUniformLocation(shader, "blockpos");
int firstposUniform = GL20.glGetUniformLocation(shader, "firstpos");
int secondposUniform = GL20.glGetUniformLocation(shader, "secondpos");
int imageUniform = GL20.glGetUniformLocation(shader, "image");
int maskUniform = GL20.glGetUniformLocation(shader, "mask");
int percentileUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "dissolve");
int highlightUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "highlight");
int redUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "red");
int blockposUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "blockpos");
int firstposUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "firstpos");
int secondposUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "secondpos");
int imageUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "image");
int maskUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "mask");
//image
GL20.glUniform1i(imageUniform, primaryTextureUnit);
OpenGlHelper.setActiveTexture(ARBMultitexture.GL_TEXTURE0_ARB + primaryTextureUnit);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, mc.renderEngine.getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).getGlTextureId());
// GlStateManager.enableTexture2D();
// GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
GlStateManager.enableTexture2D();
GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
//mask
GL20.glUniform1i(maskUniform, secondaryTextureUnit);
ARBShaderObjects.glUniform1iARB(maskUniform, secondaryTextureUnit);
OpenGlHelper.setActiveTexture(ARBMultitexture.GL_TEXTURE0_ARB + secondaryTextureUnit);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, mc.renderEngine.getTexture(ShaderHandler.shaderMaskTextureLocation).getGlTextureId());
//image
ARBShaderObjects.glUniform1iARB(imageUniform, primaryTextureUnit);
OpenGlHelper.setActiveTexture(ARBMultitexture.GL_TEXTURE0_ARB + primaryTextureUnit);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, mc.renderEngine.getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).getGlTextureId());
//blockpos
GL20.glUniform3f(blockposUniform, (float) blockpos.x, (float) blockpos.y, (float) blockpos.z);
GL20.glUniform3f(firstposUniform, (float) firstpos.x, (float) firstpos.y, (float) firstpos.z);
GL20.glUniform3f(secondposUniform, (float) secondpos.x, (float) secondpos.y, (float) secondpos.z);
ARBShaderObjects.glUniform3fARB(blockposUniform, (float) blockpos.x, (float) blockpos.y, (float) blockpos.z);
ARBShaderObjects.glUniform3fARB(firstposUniform, (float) firstpos.x, (float) firstpos.y, (float) firstpos.z);
ARBShaderObjects.glUniform3fARB(secondposUniform, (float) secondpos.x, (float) secondpos.y, (float) secondpos.z);
//dissolve
GL20.glUniform1f(percentileUniform, dissolve);
ARBShaderObjects.glUniform1fARB(percentileUniform, dissolve);
//highlight
GL20.glUniform1i(highlightUniform, highlight ? 1 : 0);
ARBShaderObjects.glUniform1iARB(highlightUniform, highlight ? 1 : 0);
//red
GL20.glUniform1i(redUniform, red ? 1 : 0);
ARBShaderObjects.glUniform1iARB(redUniform, red ? 1 : 0);
};
}

View File

@@ -185,7 +185,7 @@ public class RenderHandler implements IWorldEventListener {
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_TEXTURE_2D);
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
// Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
Minecraft.getMinecraft().renderEngine.bindTexture(ShaderHandler.shaderMaskTextureLocation);
GlStateManager.enableBlend();

View File

@@ -28,9 +28,8 @@ import java.util.function.Consumer;
public final class ShaderHandler {
private static final int VERT_ST = GL20.GL_VERTEX_SHADER;
private static final int FRAG_ST = GL20.GL_FRAGMENT_SHADER;
private static final int VERT_ST = ARBVertexShader.GL_VERTEX_SHADER_ARB;
private static final int FRAG_ST = ARBFragmentShader.GL_FRAGMENT_SHADER_ARB;
private static final int VERT = 1;
private static final int FRAG = 2;
@@ -55,11 +54,11 @@ public final class ShaderHandler {
if(!doUseShaders())
return;
GL20.glUseProgram(shader);
ARBShaderObjects.glUseProgramObjectARB(shader);
if(shader != 0) {
int time = GL20.glGetUniformLocation(shader, "time");
GL20.glUniform1i(time, ClientProxy.ticksInGame);
int time = ARBShaderObjects.glGetUniformLocationARB(shader, "time");
ARBShaderObjects.glUniform1iARB(time, ClientProxy.ticksInGame);
if(callback != null)
callback.accept(shader);
@@ -75,7 +74,7 @@ public final class ShaderHandler {
}
public static boolean doUseShaders() {
return BuildConfig.visuals.useShaders && OpenGlHelper.shadersSupported && OpenGlHelper.openGL21; //Only GL2.1 shaders
return BuildConfig.visuals.useShaders && OpenGlHelper.shadersSupported;
}
private static int createProgram(String s, int sides) {
@@ -95,24 +94,24 @@ public final class ShaderHandler {
if(frag != null)
fragId = createShader(frag, FRAG_ST);
program = GL20.glCreateProgram();
program = ARBShaderObjects.glCreateProgramObjectARB();
if(program == 0)
return 0;
if(vert != null)
GL20.glAttachShader(program, vertId);
ARBShaderObjects.glAttachObjectARB(program, vertId);
if(frag != null)
GL20.glAttachShader(program, fragId);
ARBShaderObjects.glAttachObjectARB(program, fragId);
GL20.glLinkProgram(program);
if(GL20.glGetProgrami(program, GL20.GL_LINK_STATUS) == GL11.GL_FALSE) {
EffortlessBuilding.logger.log(Level.ERROR, getProgramLogInfo(program));
ARBShaderObjects.glLinkProgramARB(program);
if(ARBShaderObjects.glGetObjectParameteriARB(program, ARBShaderObjects.GL_OBJECT_LINK_STATUS_ARB) == GL11.GL_FALSE) {
EffortlessBuilding.logger.log(Level.ERROR, getLogInfo(program));
return 0;
}
GL20.glValidateProgram(program);
if (GL20.glGetProgrami(program, GL20.GL_VALIDATE_STATUS) == GL11.GL_FALSE) {
EffortlessBuilding.logger.log(Level.ERROR, getProgramLogInfo(program));
ARBShaderObjects.glValidateProgramARB(program);
if (ARBShaderObjects.glGetObjectParameteriARB(program, ARBShaderObjects.GL_OBJECT_VALIDATE_STATUS_ARB) == GL11.GL_FALSE) {
EffortlessBuilding.logger.log(Level.ERROR, getLogInfo(program));
return 0;
}
@@ -122,32 +121,28 @@ public final class ShaderHandler {
private static int createShader(String filename, int shaderType){
int shader = 0;
try {
shader = GL20.glCreateShader(shaderType);
shader = ARBShaderObjects.glCreateShaderObjectARB(shaderType);
if(shader == 0)
return 0;
GL20.glShaderSource(shader, readFileAsString(filename));
GL20.glCompileShader(shader);
ARBShaderObjects.glShaderSourceARB(shader, readFileAsString(filename));
ARBShaderObjects.glCompileShaderARB(shader);
if (GL20.glGetShaderi(shader, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE)
throw new RuntimeException("Error creating shader: " + getShaderLogInfo(shader));
if (ARBShaderObjects.glGetObjectParameteriARB(shader, ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB) == GL11.GL_FALSE)
throw new RuntimeException("Error creating shader: " + getLogInfo(shader));
return shader;
}
catch(Exception e) {
GL20.glDeleteShader(shader);
ARBShaderObjects.glDeleteObjectARB(shader);
e.printStackTrace();
return -1;
}
}
private static String getProgramLogInfo(int program) {
return GL20.glGetProgramInfoLog(program, GL20.glGetProgrami(program, GL20.GL_INFO_LOG_LENGTH));
}
private static String getShaderLogInfo(int shader) {
return GL20.glGetShaderInfoLog(shader, GL20.glGetShaderi(shader, GL20.GL_INFO_LOG_LENGTH));
private static String getLogInfo(int obj) {
return ARBShaderObjects.glGetInfoLogARB(obj, ARBShaderObjects.glGetObjectParameteriARB(obj, ARBShaderObjects.GL_OBJECT_INFO_LOG_LENGTH_ARB));
}
private static String readFileAsString(String filename) throws Exception {

View File

@@ -31,9 +31,7 @@ void main() {
float placeFromFirst = length(worldpos - firstposc) / firstToSecond;
float placeFromSecond = length(worldpos - secondposc) / firstToSecond;
place = (placeFromFirst + (1.0 - placeFromSecond)) / 2.0;
} else {
//only one block
}
} //else only one block
//find 2d texture coordinate for noise texture based on world position
vec2 maskcoord = vec2(worldpos.y, worldpos.z);
@@ -80,8 +78,8 @@ void main() {
// color.rgb += vec3(0.5 - smoothstep(0, 0.5, distToEdge)) * 0.5;
//add flat shading
if (abs(normal.x) > 0.5)
color.rgb -= 0.0;
// if (abs(normal.x) > 0.5)
// color.rgb -= 0.0;
if (abs(normal.y) > 0.5)
color.rgb += 0.05;
if (abs(normal.z) > 0.5)