From 9a3fef218e952864c25c2267cd8df642449217a2 Mon Sep 17 00:00:00 2001 From: Christian Knaapen Date: Fri, 22 Feb 2019 16:35:19 +0100 Subject: [PATCH] Fixed having to click after breaking. Outlines now adhere to bounding boxes. Fixed not being able to place when holding sneak. Repeated placing when holding is now possible in NormalPlus mode. Repeated breaking when holding now only happens in NormalPlus mode. Repeated placing and breaking is now possible when not moving the mouse. Fixed not being able to break when clicking in air. Sounds no longer depend on distance to player, all are in category BLOCKS, and breaking sound is played when appropriate when previewing. --- build.gradle | 2 +- .../EffortlessBuilding.java | 2 +- .../effortlessbuilding/EventHandler.java | 6 +- .../buildmode/BuildModes.java | 34 +++-- .../compatibility/CompatHelper.java | 16 +- .../helper/SurvivalHelper.java | 67 ++++++++- .../effortlessbuilding/proxy/ClientProxy.java | 140 ++++++++++-------- .../render/BlockPreviewRenderer.java | 27 ++-- .../render/RenderHandler.java | 9 ++ 9 files changed, 207 insertions(+), 96 deletions(-) diff --git a/build.gradle b/build.gradle index a88f717..87cac77 100644 --- a/build.gradle +++ b/build.gradle @@ -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.1" +version = "1.12.2-2.2" group = "nl.requios.effortlessbuilding" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "effortlessbuilding" diff --git a/src/main/java/nl/requios/effortlessbuilding/EffortlessBuilding.java b/src/main/java/nl/requios/effortlessbuilding/EffortlessBuilding.java index eb843a5..18c80ce 100644 --- a/src/main/java/nl/requios/effortlessbuilding/EffortlessBuilding.java +++ b/src/main/java/nl/requios/effortlessbuilding/EffortlessBuilding.java @@ -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.1"; + public static final String VERSION = "1.12.2-2.2"; @Mod.Instance(EffortlessBuilding.MODID) public static EffortlessBuilding instance; diff --git a/src/main/java/nl/requios/effortlessbuilding/EventHandler.java b/src/main/java/nl/requios/effortlessbuilding/EventHandler.java index 1cfd34f..46069f9 100644 --- a/src/main/java/nl/requios/effortlessbuilding/EventHandler.java +++ b/src/main/java/nl/requios/effortlessbuilding/EventHandler.java @@ -88,7 +88,7 @@ public class EventHandler event.setCanceled(true); } else { //Normal mode, let vanilla handle block placing - //But modifiers should still work + //But modifiers and QuickReplace should still work //Send message to client, which sends message back with raytrace info EffortlessBuilding.packetHandler.sendTo(new RequestLookAtMessage(), (EntityPlayerMP) player); @@ -104,8 +104,8 @@ public class EventHandler event.setCanceled(true); } else { //Normal mode, let vanilla handle block breaking - //But modifiers should still work - BuildModes.onBlockBroken(event); + //But modifiers and QuickReplace should still work + BuildModes.onBlockBroken(event.getPlayer(), event.getPos()); } } diff --git a/src/main/java/nl/requios/effortlessbuilding/buildmode/BuildModes.java b/src/main/java/nl/requios/effortlessbuilding/buildmode/BuildModes.java index 61e2cc3..935a472 100644 --- a/src/main/java/nl/requios/effortlessbuilding/buildmode/BuildModes.java +++ b/src/main/java/nl/requios/effortlessbuilding/buildmode/BuildModes.java @@ -1,5 +1,6 @@ package nl.requios.effortlessbuilding.buildmode; +import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; @@ -10,6 +11,7 @@ import nl.requios.effortlessbuilding.EffortlessBuilding; import nl.requios.effortlessbuilding.buildmodifier.*; import nl.requios.effortlessbuilding.compatibility.CompatHelper; import nl.requios.effortlessbuilding.helper.ReachHelper; +import nl.requios.effortlessbuilding.helper.SurvivalHelper; import nl.requios.effortlessbuilding.network.BlockBrokenMessage; import nl.requios.effortlessbuilding.network.BlockPlacedMessage; @@ -61,7 +63,6 @@ public class BuildModes { ModifierSettingsManager.ModifierSettings modifierSettings = ModifierSettingsManager.getModifierSettings(player); ModeSettingsManager.ModeSettings modeSettings = ModeSettingsManager.getModeSettings(player); BuildModeEnum buildMode = modeSettings.getBuildMode(); - int maxReach = ReachHelper.getMaxReach(player); BlockPos startPos = null; @@ -70,7 +71,8 @@ public class BuildModes { //Offset in direction of sidehit if not quickreplace and not replaceable boolean replaceable = player.world.getBlockState(startPos).getBlock().isReplaceable(player.world, startPos); - if (!modifierSettings.doQuickReplace() && !replaceable) { + boolean becomesDoubleSlab = SurvivalHelper.doesBecomeDoubleSlab(player, startPos, message.getSideHit()); + if (!modifierSettings.doQuickReplace() && !replaceable && !becomesDoubleSlab) { startPos = startPos.offset(message.getSideHit()); } @@ -80,6 +82,7 @@ public class BuildModes { } //Check if player reach does not exceed startpos + int maxReach = ReachHelper.getMaxReach(player); if (player.getPosition().distanceSq(startPos) > maxReach * maxReach) { EffortlessBuilding.log(player, "Placement exceeds your reach."); return; @@ -117,19 +120,16 @@ public class BuildModes { //Use a network message to break blocks in the distance using clientside mouse input public static void onBlockBrokenMessage(EntityPlayer player, BlockBrokenMessage message) { - BlockPos blockPos = message.getBlockPos(); - if (ReachHelper.canBreakFar(player) && message.isBlockHit() && + if (ReachHelper.canBreakFar(player) && !CompatHelper.chiselsAndBitsProxy.isHoldingChiselTool(EnumHand.MAIN_HAND)) { - BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(player.world, blockPos, player.world.getBlockState(blockPos), player); - onBlockBroken(event); + BlockPos startPos = message.isBlockHit() ? message.getBlockPos() : null; + onBlockBroken(player, startPos); } } - public static void onBlockBroken(BlockEvent.BreakEvent event) { - EntityPlayer player = event.getPlayer(); - BlockPos pos = event.getPos(); + public static void onBlockBroken(EntityPlayer player, BlockPos startPos) { //Check if not in the middle of placing Dictionary currentlyBreaking = player.world.isRemote ? currentlyBreakingClient : currentlyBreakingServer; @@ -139,18 +139,28 @@ public class BuildModes { return; } - //get coordinates + //If first click + if (currentlyBreaking.get(player) == null) { + //If startpos is null, dont do anything + if (startPos == null) return; + } + + //Get coordinates ModeSettingsManager.ModeSettings modeSettings = ModeSettingsManager.getModeSettings(player); BuildModeEnum buildMode = modeSettings.getBuildMode(); - List coordinates = buildMode.instance.onRightClick(player, pos, EnumFacing.UP, Vec3d.ZERO, true); + List coordinates = buildMode.instance.onRightClick(player, startPos, EnumFacing.UP, Vec3d.ZERO, true); if (coordinates.isEmpty()) { currentlyBreaking.put(player, true); return; } - //let buildmodifiers break blocks + //Let buildmodifiers break blocks BuildModifiers.onBlockBroken(player, coordinates); + + //Only works when finishing a buildmode is equal to breaking some blocks + //No intermediate blocks allowed + currentlyBreaking.remove(player); } public static List findCoordinates(EntityPlayer player, BlockPos startPos, boolean skipRaytrace) { diff --git a/src/main/java/nl/requios/effortlessbuilding/compatibility/CompatHelper.java b/src/main/java/nl/requios/effortlessbuilding/compatibility/CompatHelper.java index d7273dc..af093ac 100644 --- a/src/main/java/nl/requios/effortlessbuilding/compatibility/CompatHelper.java +++ b/src/main/java/nl/requios/effortlessbuilding/compatibility/CompatHelper.java @@ -35,11 +35,11 @@ public class CompatHelper { // /dank/null, or plain old blocks. public static boolean isItemBlockProxy(ItemStack stack) { Item item = stack.getItem(); - if(item instanceof ItemBlock) + if (item instanceof ItemBlock) return true; - if((item instanceof ItemRandomizerBag)) + if ((item instanceof ItemRandomizerBag)) return true; - if(item == dankNullItem) + if (item == dankNullItem) return true; return false; } @@ -48,14 +48,20 @@ public class CompatHelper { // pointed to by nbt integer selectedIndex. public static ItemStack getItemBlockFromStack(ItemStack stack) { Item item = stack.getItem(); - if(item instanceof ItemRandomizerBag) { + + if (item instanceof ItemBlock) + return stack; + + if (item instanceof ItemRandomizerBag) return ItemRandomizerBag.pickRandomStack(ItemRandomizerBag.getBagInventory(stack)); - } else if(item == dankNullItem) { + + if(item == dankNullItem) { int index = 0; if(stack.hasTagCompound() && stack.getTagCompound().hasKey("selectedIndex")) index = stack.getTagCompound().getInteger("selectedIndex"); return stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).getStackInSlot(index); } + return ItemStack.EMPTY; } diff --git a/src/main/java/nl/requios/effortlessbuilding/helper/SurvivalHelper.java b/src/main/java/nl/requios/effortlessbuilding/helper/SurvivalHelper.java index 878456e..d64fca8 100644 --- a/src/main/java/nl/requios/effortlessbuilding/helper/SurvivalHelper.java +++ b/src/main/java/nl/requios/effortlessbuilding/helper/SurvivalHelper.java @@ -2,8 +2,10 @@ package nl.requios.effortlessbuilding.helper; import net.minecraft.block.Block; import net.minecraft.block.BlockLiquid; +import net.minecraft.block.BlockSlab; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; +import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.Entity; @@ -12,15 +14,20 @@ import net.minecraft.init.Blocks; import net.minecraft.init.Enchantments; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemSlab; import net.minecraft.item.ItemStack; import net.minecraft.stats.StatList; +import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import net.minecraftforge.common.ForgeHooks; +import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.items.ItemHandlerHelper; import nl.requios.effortlessbuilding.EffortlessBuilding; import nl.requios.effortlessbuilding.buildmodifier.ModifierSettingsManager; @@ -43,13 +50,15 @@ public class SurvivalHelper { //Randomizer bag, other proxy item synergy //Preliminary compatibility code for other items that hold blocks - if(CompatHelper.isItemBlockProxy(itemstack)) + if (CompatHelper.isItemBlockProxy(itemstack)) itemstack = CompatHelper.getItemBlockByState(itemstack, blockState); - if(!(itemstack.getItem() instanceof ItemBlock)) + if (!(itemstack.getItem() instanceof ItemBlock)) return false; Block block = ((ItemBlock) itemstack.getItem()).getBlock(); + + //More manual with ItemBlock#placeBlockAt if (canPlace(world, player, pos, blockState, itemstack, skipCollisionCheck, facing.getOpposite())) { //Drop existing block dropBlock(world, player, pos); @@ -71,6 +80,30 @@ public class SurvivalHelper { return true; } return false; + + //Using ItemBlock#onItemUse +// EnumActionResult result; +// PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(player, EnumHand.MAIN_HAND, pos, facing, net.minecraftforge.common.ForgeHooks.rayTraceEyeHitVec(player, ReachHelper.getPlacementReach(player))); +// if (player.isCreative()) +// { +// int i = itemstack.getMetadata(); +// int j = itemstack.getCount(); +// if (event.getUseItem() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY) { +// EnumActionResult enumactionresult = itemstack.getItem().onItemUse(player, world, pos, EnumHand.MAIN_HAND, facing, (float) hitVec.x, (float) hitVec.y, (float) hitVec.z); +// itemstack.setItemDamage(i); +// itemstack.setCount(j); +// return enumactionresult == EnumActionResult.SUCCESS; +// } else return false; +// } +// else +// { +// ItemStack copyForUse = itemstack.copy(); +// if (event.getUseItem() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY) +// result = itemstack.getItem().onItemUse(player, world, pos, EnumHand.MAIN_HAND, facing, (float) hitVec.x, (float) hitVec.y, (float) hitVec.z); +// if (itemstack.isEmpty()) net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, copyForUse, EnumHand.MAIN_HAND); +// return false; +// } + } //Used for all breaking of blocks in this mod. @@ -202,6 +235,11 @@ public class SurvivalHelper { return false; } + //Check if double slab + if (placer != null && doesBecomeDoubleSlab(((EntityPlayer) placer), pos, sidePlacedOn)) { + return true; + } + //Check if same block //Necessary otherwise extra items will be dropped if (iblockstate1 == newBlockState) { @@ -266,4 +304,29 @@ public class SurvivalHelper { return toolLevel >= block.getHarvestLevel(state); } + + public static boolean doesBecomeDoubleSlab(EntityPlayer player, BlockPos pos, EnumFacing facing) { + IBlockState placedBlockState = player.world.getBlockState(pos); + + ItemStack itemstack = player.getHeldItem(EnumHand.MAIN_HAND); + if (CompatHelper.isItemBlockProxy(itemstack)) + itemstack = CompatHelper.getItemBlockFromStack(itemstack); + + if (itemstack.isEmpty() || !(itemstack.getItem() instanceof ItemSlab)) return false; + BlockSlab heldSlab = (BlockSlab) ((ItemSlab) itemstack.getItem()).getBlock(); + + if (placedBlockState.getBlock() == heldSlab) { + IProperty variantProperty = heldSlab.getVariantProperty(); + Comparable placedVariant = placedBlockState.getValue(variantProperty); + BlockSlab.EnumBlockHalf placedHalf = placedBlockState.getValue(BlockSlab.HALF); + + Comparable heldVariant = heldSlab.getTypeForItem(itemstack); + + if ((facing == EnumFacing.UP && placedHalf == BlockSlab.EnumBlockHalf.BOTTOM || facing == EnumFacing.DOWN && placedHalf == BlockSlab.EnumBlockHalf.TOP) && placedVariant == heldVariant) + { + return true; + } + } + return false; + } } diff --git a/src/main/java/nl/requios/effortlessbuilding/proxy/ClientProxy.java b/src/main/java/nl/requios/effortlessbuilding/proxy/ClientProxy.java index 802126b..b98b683 100644 --- a/src/main/java/nl/requios/effortlessbuilding/proxy/ClientProxy.java +++ b/src/main/java/nl/requios/effortlessbuilding/proxy/ClientProxy.java @@ -13,6 +13,7 @@ import net.minecraft.client.settings.KeyBinding; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumHand; import net.minecraft.util.IThreadListener; @@ -52,6 +53,7 @@ import nl.requios.effortlessbuilding.render.ShaderHandler; import nl.requios.effortlessbuilding.network.*; import org.lwjgl.input.Keyboard; +import javax.annotation.Nullable; import java.util.HashMap; @Mod.EventBusSubscriber(Side.CLIENT) @@ -59,6 +61,7 @@ public class ClientProxy implements IProxy { public static KeyBinding[] keyBindings; public static RayTraceResult previousLookAt; public static RayTraceResult currentLookAt; + private static int placeCooldown = 0; private static int breakCooldown = 0; public static int ticksInGame = 0; @@ -143,63 +146,111 @@ public class ClientProxy implements IProxy { } @SubscribeEvent - public static void onMouseInput(InputEvent.MouseInputEvent event) { + public static void onClientTick(TickEvent.ClientTickEvent event) { + + if (event.phase == TickEvent.Phase.START) { + onMouseInput(); + + //Update previousLookAt + RayTraceResult objectMouseOver = Minecraft.getMinecraft().objectMouseOver; + //Checking for null is necessary! Even in vanilla when looking down ladders it is occasionally null (instead of Type MISS) + if (objectMouseOver == null) return; + + if (currentLookAt == null) { + currentLookAt = objectMouseOver; + previousLookAt = objectMouseOver; + return; + } + + if (objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK) { + if (currentLookAt.typeOfHit != RayTraceResult.Type.BLOCK) { + currentLookAt = objectMouseOver; + previousLookAt = objectMouseOver; + } else { + if (currentLookAt.getBlockPos() != objectMouseOver.getBlockPos()) { + previousLookAt = currentLookAt; + currentLookAt = objectMouseOver; + } + } + } + } else if (event.phase == TickEvent.Phase.END){ + GuiScreen gui = Minecraft.getMinecraft().currentScreen; + if(gui == null || !gui.doesGuiPauseGame()) { + ticksInGame++; + } + } + + } + + private static void onMouseInput() { Minecraft mc = Minecraft.getMinecraft(); EntityPlayerSP player = mc.player; + if (player == null) return; + BuildModes.BuildModeEnum buildMode = ModeSettingsManager.getModeSettings(player).getBuildMode(); if (Minecraft.getMinecraft().currentScreen != null || - ModeSettingsManager.getModeSettings(player).getBuildMode() == BuildModes.BuildModeEnum.Normal || + buildMode == BuildModes.BuildModeEnum.Normal || RadialMenu.instance.isVisible()) { return; } - if (mc.gameSettings.keyBindUseItem.isPressed()) { + if (mc.gameSettings.keyBindUseItem.isKeyDown()) { //KeyBinding.setKeyBindState(mc.gameSettings.keyBindUseItem.getKeyCode(), false); - ItemStack currentItemStack = player.getHeldItem(EnumHand.MAIN_HAND); - if (CompatHelper.isItemBlockProxy(currentItemStack) && !player.isSneaking()) { + if (placeCooldown <= 0) { + placeCooldown = 4; - //find position in distance - RayTraceResult lookingAt = getLookingAt(player); - BuildModes.onBlockPlacedMessage(player, new BlockPlacedMessage(lookingAt)); - EffortlessBuilding.packetHandler.sendToServer(new BlockPlacedMessage(lookingAt)); + ItemStack currentItemStack = player.getHeldItem(EnumHand.MAIN_HAND); + if (currentItemStack.getItem() instanceof ItemBlock || + (CompatHelper.isItemBlockProxy(currentItemStack) && !player.isSneaking())) { - //play sound if further than normal - if (lookingAt != null && lookingAt.typeOfHit == RayTraceResult.Type.BLOCK && - (lookingAt.hitVec.subtract(player.getPositionEyes(1f))).lengthSquared() > 25f) { + //find position in distance + RayTraceResult lookingAt = getLookingAt(player); + BuildModes.onBlockPlacedMessage(player, lookingAt == null ? new BlockPlacedMessage() : new BlockPlacedMessage(lookingAt)); + EffortlessBuilding.packetHandler.sendToServer(lookingAt == null ? new BlockPlacedMessage() : new BlockPlacedMessage(lookingAt)); - BlockPos blockPos = lookingAt.getBlockPos(); - IBlockState state = player.world.getBlockState(blockPos); - SoundType soundtype = state.getBlock().getSoundType(state, player.world, blockPos, player); - player.world.playSound(player, blockPos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, - (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F); - player.swingArm(EnumHand.MAIN_HAND); + //play sound if further than normal + if (lookingAt != null && lookingAt.typeOfHit == RayTraceResult.Type.BLOCK && + (lookingAt.hitVec.subtract(player.getPositionEyes(1f))).lengthSquared() > 25f) { + + IBlockState state = ((ItemBlock) currentItemStack.getItem()).getBlock().getDefaultState(); + BlockPos blockPos = lookingAt.getBlockPos(); + SoundType soundType = state.getBlock().getSoundType(state, player.world, blockPos, player); + player.world.playSound(player, player.getPosition(), soundType.getPlaceSound(), SoundCategory.BLOCKS, + 0.4f, soundType.getPitch() * 1f); + player.swingArm(EnumHand.MAIN_HAND); + } } + } else if (buildMode == BuildModes.BuildModeEnum.NormalPlus) { + placeCooldown--; } + } else { + placeCooldown = 0; } if (mc.gameSettings.keyBindAttack.isKeyDown()) { - //KeyBinding.setKeyBindState(mc.gameSettings.keyBindAttack.getKeyCode(), false); //Break block in distance in creative (or survival if enabled in config) if (ReachHelper.canBreakFar(player)) { if (breakCooldown <= 0) { - breakCooldown = 6; + breakCooldown = 4; RayTraceResult lookingAt = getLookingAt(player); - BuildModes.onBlockBrokenMessage(player, new BlockBrokenMessage(lookingAt)); - EffortlessBuilding.packetHandler.sendToServer(new BlockBrokenMessage(lookingAt)); + BuildModes.onBlockBrokenMessage(player, lookingAt == null ? new BlockBrokenMessage() : new BlockBrokenMessage(lookingAt)); + EffortlessBuilding.packetHandler.sendToServer(lookingAt == null ? new BlockBrokenMessage() : new BlockBrokenMessage(lookingAt)); + + //play sound if further than normal + if (lookingAt != null && lookingAt.typeOfHit == RayTraceResult.Type.BLOCK && + (lookingAt.hitVec.subtract(player.getPositionEyes(1f))).lengthSquared() > 25f) { - //play sound - if (lookingAt != null && lookingAt.typeOfHit == RayTraceResult.Type.BLOCK) { BlockPos blockPos = lookingAt.getBlockPos(); IBlockState state = player.world.getBlockState(blockPos); SoundType soundtype = state.getBlock().getSoundType(state, player.world, blockPos, player); - player.world.playSound(player, blockPos, soundtype.getBreakSound(), SoundCategory.BLOCKS, - (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F); + player.world.playSound(player, player.getPosition(), soundtype.getBreakSound(), SoundCategory.BLOCKS, + 0.4f, soundtype.getPitch() * 1f); player.swingArm(EnumHand.MAIN_HAND); } - } else { + } else if (buildMode == BuildModes.BuildModeEnum.NormalPlus) { breakCooldown--; } } @@ -209,7 +260,6 @@ public class ClientProxy implements IProxy { } else { breakCooldown = 0; } - event.setResult(Event.Result.ALLOW); } @SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true) @@ -257,39 +307,6 @@ public class ClientProxy implements IProxy { } - @SubscribeEvent - public static void onClientTick(TickEvent.ClientTickEvent event) { - if (event.phase == TickEvent.Phase.START) { - RayTraceResult objectMouseOver = Minecraft.getMinecraft().objectMouseOver; - //Checking for null is necessary! Even in vanilla when looking down ladders it is occasionally null (instead of Type MISS) - if (objectMouseOver == null) return; - - if (currentLookAt == null) { - currentLookAt = objectMouseOver; - previousLookAt = objectMouseOver; - return; - } - - if (objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK) { - if (currentLookAt.typeOfHit != RayTraceResult.Type.BLOCK) { - currentLookAt = objectMouseOver; - previousLookAt = objectMouseOver; - } else { - if (currentLookAt.getBlockPos() != objectMouseOver.getBlockPos()) { - previousLookAt = currentLookAt; - currentLookAt = objectMouseOver; - } - } - } - } else if (event.phase == TickEvent.Phase.END){ - GuiScreen gui = Minecraft.getMinecraft().currentScreen; - if(gui == null || !gui.doesGuiPauseGame()) { - ticksInGame++; - } - } - - } - @SubscribeEvent public static void onGuiOpen(GuiOpenEvent event) { EntityPlayer player = Minecraft.getMinecraft().player; @@ -298,6 +315,7 @@ public class ClientProxy implements IProxy { } } + @Nullable public static RayTraceResult getLookingAt(EntityPlayer player) { // World world = player.world; diff --git a/src/main/java/nl/requios/effortlessbuilding/render/BlockPreviewRenderer.java b/src/main/java/nl/requios/effortlessbuilding/render/BlockPreviewRenderer.java index 330d2a0..d682dcc 100644 --- a/src/main/java/nl/requios/effortlessbuilding/render/BlockPreviewRenderer.java +++ b/src/main/java/nl/requios/effortlessbuilding/render/BlockPreviewRenderer.java @@ -1,5 +1,6 @@ package nl.requios.effortlessbuilding.render; +import net.minecraft.block.SoundType; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; @@ -11,10 +12,9 @@ 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.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.RayTraceResult; -import net.minecraft.util.math.Vec3d; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.SoundEvent; +import net.minecraft.util.math.*; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import nl.requios.effortlessbuilding.BuildConfig; @@ -114,7 +114,8 @@ public class BlockPreviewRenderer { //Check if tool (or none) in hand boolean replaceable = player.world.getBlockState(startPos).getBlock().isReplaceable(player.world, startPos); - if (!modifierSettings.doQuickReplace() && !toolInHand && !replaceable) { + boolean becomesDoubleSlab = SurvivalHelper.doesBecomeDoubleSlab(player, startPos, lookingAt.sideHit); + if (!modifierSettings.doQuickReplace() && !toolInHand && !replaceable && !becomesDoubleSlab) { startPos = startPos.offset(lookingAt.sideHit); } @@ -196,9 +197,11 @@ public class BlockPreviewRenderer { //and play sound (max once every tick) if (startCoordinates.size() > 1 && blockStates.size() > 1 && soundTime < ClientProxy.ticksInGame - 0) { soundTime = ClientProxy.ticksInGame; - //player.playSound(EffortlessBuilding.SOUND_BUILD_CLICK, 0.2f, 1f); - player.playSound(blockStates.get(0).getBlock().getSoundType(blockStates.get(0), player.world, - newCoordinates.get(0), player).getPlaceSound(), 0.3f, 1f); + + SoundType soundType = blockStates.get(0).getBlock().getSoundType(blockStates.get(0), player.world, + newCoordinates.get(0), player); + player.world.playSound(player, player.getPosition(), breaking ? soundType.getBreakSound() : soundType.getPlaceSound(), + SoundCategory.BLOCKS, 0.3f, 0.8f); } } @@ -220,7 +223,8 @@ public class BlockPreviewRenderer { if (breaking) color = new Vec3d(1f, 0f, 0f); for (int i = newCoordinates.size() - 1; i >= 0; i--) { - RenderHandler.renderBlockOutline(newCoordinates.get(i), color); + AxisAlignedBB boundingBox = blockStates.get(i).getBoundingBox(player.world, newCoordinates.get(i)); + RenderHandler.renderBlockOutline(newCoordinates.get(i), boundingBox, color); } RenderHandler.endLines(); @@ -244,7 +248,8 @@ public class BlockPreviewRenderer { IBlockState blockState = player.world.getBlockState(coordinate); if (!blockState.getBlock().isAir(blockState, player.world, coordinate)) { if (SurvivalHelper.canBreak(player.world, player, coordinate) || i == 0) { - RenderHandler.renderBlockOutline(coordinate, new Vec3d(0f, 0f, 0f)); + AxisAlignedBB boundingBox = blockState.getBoundingBox(player.world, coordinate); + RenderHandler.renderBlockOutline(coordinate, boundingBox, new Vec3d(0f, 0f, 0f)); } } } @@ -278,7 +283,7 @@ public class BlockPreviewRenderer { //Check if can place //If check is turned off, check if blockstate is the same (for dissolve effect) - if ((!checkCanPlace /*&& player.world.getBlockState(blockPos) == blockState*/) || + if ((!checkCanPlace /*&& player.world.getBlockState(blockPos) == blockState*/) || //TODO enable SurvivalHelper.canPlace(player.world, player, blockPos, blockState, itemstack, modifierSettings.doQuickReplace(), EnumFacing.UP)) { ShaderHandler.useShader(ShaderHandler.dissolve, generateShaderCallback(dissolve, diff --git a/src/main/java/nl/requios/effortlessbuilding/render/RenderHandler.java b/src/main/java/nl/requios/effortlessbuilding/render/RenderHandler.java index ca9fea9..656100d 100644 --- a/src/main/java/nl/requios/effortlessbuilding/render/RenderHandler.java +++ b/src/main/java/nl/requios/effortlessbuilding/render/RenderHandler.java @@ -219,6 +219,15 @@ public class RenderHandler implements IWorldEventListener { RenderGlobal.drawSelectionBoundingBox(aabb, (float) color.x, (float) color.y, (float) color.z, 0.4f); } + //Renders outline with given bounding box + protected static void renderBlockOutline(BlockPos pos, AxisAlignedBB boundingBox, Vec3d color) { + GL11.glLineWidth(2); + + AxisAlignedBB aabb = boundingBox.offset(pos).grow(0.0020000000949949026); + + RenderGlobal.drawSelectionBoundingBox(aabb, (float) color.x, (float) color.y, (float) color.z, 0.4f); + } + //IWORLDEVENTLISTENER IMPLEMENTATION