From 488c1a137408bacea51eece88966146c4ab6d810 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Sun, 28 Jul 2019 19:23:42 +0200 Subject: [PATCH] Last Minute Patches - Fixed Symmetry Wand taking blocks from the inventory inconsistently - Improved the replacer beams visual effects - Fixed hand bobbing on servers with latency - Fixed trees growing into bedrock again --- .../foundation/utility/BlockHelper.java | 19 ++++- .../curiosities/item/TreeFertilizerItem.java | 2 +- .../BuilderGunBeamPacket.java | 14 +++- .../placementHandgun/BuilderGunHandler.java | 71 +++++++++++++++---- .../placementHandgun/BuilderGunItem.java | 52 ++++++++------ .../placementHandgun/BuilderGunScreen.java | 2 +- .../modules/symmetry/SymmetryWandItem.java | 6 +- 7 files changed, 121 insertions(+), 45 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/utility/BlockHelper.java b/src/main/java/com/simibubi/create/foundation/utility/BlockHelper.java index ed9d0aa5d..891504fa7 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/BlockHelper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/BlockHelper.java @@ -19,6 +19,20 @@ public class BlockHelper { if (needsTwo) amount *= 2; + { + // Try held Item first + int preferredSlot = player.inventory.currentItem; + ItemStack itemstack = player.inventory.getStackInSlot(preferredSlot); + int count = itemstack.getCount(); + if (itemstack.getItem() == required && count > 0) { + int taken = Math.min(count, amount - amountFound); + player.inventory.setInventorySlotContents(preferredSlot, + new ItemStack(itemstack.getItem(), count - taken)); + amountFound += taken; + } + } + + // Search inventory for (int i = 0; i < player.inventory.getSizeInventory(); ++i) { if (amountFound == amount) break; @@ -31,15 +45,14 @@ public class BlockHelper { amountFound += taken; } } - - + if (needsTwo) { // Give back 1 if uneven amount was removed if (amountFound % 2 != 0) player.inventory.addItemStackToInventory(new ItemStack(required)); amountFound /= 2; } - + return amountFound; } diff --git a/src/main/java/com/simibubi/create/modules/curiosities/item/TreeFertilizerItem.java b/src/main/java/com/simibubi/create/modules/curiosities/item/TreeFertilizerItem.java index b5c2d9e67..1e7945980 100644 --- a/src/main/java/com/simibubi/create/modules/curiosities/item/TreeFertilizerItem.java +++ b/src/main/java/com/simibubi/create/modules/curiosities/item/TreeFertilizerItem.java @@ -78,7 +78,7 @@ public class TreeFertilizerItem extends Item { BlockPos actualPos = pos.add(saplingPos).down(10); // Don't replace Bedrock - if (context.getWorld().getBlockState(pos).getBlockHardness(context.getWorld(), pos) == -1) + if (context.getWorld().getBlockState(actualPos).getBlockHardness(context.getWorld(), actualPos) == -1) continue; // Don't replace solid blocks with leaves if (!world.getBlockState(pos).isNormalCube(world, pos) diff --git a/src/main/java/com/simibubi/create/modules/curiosities/placementHandgun/BuilderGunBeamPacket.java b/src/main/java/com/simibubi/create/modules/curiosities/placementHandgun/BuilderGunBeamPacket.java index 62b14bcd7..375c21131 100644 --- a/src/main/java/com/simibubi/create/modules/curiosities/placementHandgun/BuilderGunBeamPacket.java +++ b/src/main/java/com/simibubi/create/modules/curiosities/placementHandgun/BuilderGunBeamPacket.java @@ -18,17 +18,20 @@ public class BuilderGunBeamPacket { public Vec3d start; public Vec3d target; public Hand hand; + public boolean self; - public BuilderGunBeamPacket(Vec3d start, Vec3d target, Hand hand) { + public BuilderGunBeamPacket(Vec3d start, Vec3d target, Hand hand, boolean self) { this.start = start; this.target = target; this.hand = hand; + this.self = self; } public BuilderGunBeamPacket(PacketBuffer buffer) { start = new Vec3d(buffer.readDouble(), buffer.readDouble(), buffer.readDouble()); target = new Vec3d(buffer.readDouble(), buffer.readDouble(), buffer.readDouble()); hand = buffer.readBoolean()? Hand.MAIN_HAND : Hand.OFF_HAND; + self = buffer.readBoolean(); } public void toBytes(PacketBuffer buffer) { @@ -40,14 +43,19 @@ public class BuilderGunBeamPacket { buffer.writeDouble(target.z); buffer.writeBoolean(hand == Hand.MAIN_HAND); + buffer.writeBoolean(self); } public void handle(Supplier context) { context.get().enqueueWork(() -> DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> { if (Minecraft.getInstance().player.getPositionVector().distanceTo(start) > 100) return; - BuilderGunHandler.addBeam(new LaserBeam(start, target)); - BuilderGunHandler.playSound(hand, new BlockPos(start)); + BuilderGunHandler.addBeam(new LaserBeam(start, target).followPlayer(self, hand == Hand.MAIN_HAND)); + + if (self) + BuilderGunHandler.shoot(hand); + else + BuilderGunHandler.playSound(hand, new BlockPos(start)); })); context.get().setPacketHandled(true); } diff --git a/src/main/java/com/simibubi/create/modules/curiosities/placementHandgun/BuilderGunHandler.java b/src/main/java/com/simibubi/create/modules/curiosities/placementHandgun/BuilderGunHandler.java index 44b4b4368..330768892 100644 --- a/src/main/java/com/simibubi/create/modules/curiosities/placementHandgun/BuilderGunHandler.java +++ b/src/main/java/com/simibubi/create/modules/curiosities/placementHandgun/BuilderGunHandler.java @@ -2,6 +2,8 @@ package com.simibubi.create.modules.curiosities.placementHandgun; import java.util.LinkedList; import java.util.List; +import java.util.Random; +import java.util.function.Supplier; import org.lwjgl.opengl.GL11; @@ -49,16 +51,45 @@ public class BuilderGunHandler { private static float lastLeftHandAnimation; private static float lastRightHandAnimation; + private static boolean dontReequipLeft; + private static boolean dontReequipRight; + public static class LaserBeam { float itensity; Vec3d start; Vec3d end; + boolean follow; + boolean mainHand; public LaserBeam(Vec3d start, Vec3d end) { this.start = start; this.end = end; itensity = 1; } + + public LaserBeam followPlayer(boolean follow, boolean mainHand) { + this.follow = follow; + this.mainHand = mainHand; + return this; + } + + public Vec3d getStart() { + if (follow) + return getExactBarrelPos(mainHand); + return start; + } + } + + public static Vec3d getExactBarrelPos(boolean mainHand) { + float partialTicks = Minecraft.getInstance().getRenderPartialTicks(); + ClientPlayerEntity player = Minecraft.getInstance().player; + float yaw = (float) ((player.getYaw(partialTicks)) / -180 * Math.PI); + float pitch = (float) ((player.getPitch(partialTicks)) / -180 * Math.PI); + Vec3d barrelPosNoTransform = new Vec3d(mainHand == (player.getPrimaryHand() == HandSide.RIGHT) ? -.35f : .35f, + -0.1f, 1); + Vec3d barrelPos = player.getEyePosition(partialTicks) + .add(barrelPosNoTransform.rotatePitch(pitch).rotateYaw(yaw)); + return barrelPos; } @SubscribeEvent(priority = EventPriority.HIGHEST) @@ -106,7 +137,7 @@ public class BuilderGunHandler { BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer(); bufferBuilder.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION); - bufferBuilder.pos(beam.start.x, beam.start.y, beam.start.z).endVertex(); + bufferBuilder.pos(beam.getStart().x, beam.getStart().y, beam.getStart().z).endVertex(); bufferBuilder.pos(beam.end.x, beam.end.y, beam.end.z).endVertex(); Tessellator.getInstance().draw(); @@ -119,10 +150,13 @@ public class BuilderGunHandler { public static void shoot(Hand hand) { ClientPlayerEntity player = Minecraft.getInstance().player; boolean rightHand = hand == Hand.MAIN_HAND ^ player.getPrimaryHand() == HandSide.LEFT; - if (rightHand) + if (rightHand) { rightHandAnimation = .2f; - else + dontReequipRight = false; + } else { leftHandAnimation = .2f; + dontReequipLeft = false; + } playSound(hand, player.getPosition()); } @@ -133,15 +167,22 @@ public class BuilderGunHandler { } public static void addBeam(LaserBeam beam) { - Vec3d step = beam.end.subtract(beam.start).normalize(); - int steps = (int) (beam.end.squareDistanceTo(beam.start) / step.lengthSquared()); - for (int i = 0; i <= steps; i++) { - Vec3d pos = beam.start.add(step.scale(i)); - Minecraft.getInstance().world.addParticle(ParticleTypes.END_ROD, pos.x, pos.y, pos.z, 0, -15000, 0); + Random r = new Random(); + double x = beam.end.x; + double y = beam.end.y; + double z = beam.end.z; + ClientWorld world = Minecraft.getInstance().world; + Supplier randomSpeed = () -> (r.nextDouble() - .5d) * .2f; + Supplier randomOffset = () -> (r.nextDouble() - .5d) * .2f; + for (int i = 0; i < 10; i++) { + world.addParticle(ParticleTypes.END_ROD, x, y, z, randomSpeed.get(), randomSpeed.get(), randomSpeed.get()); + world.addParticle(ParticleTypes.FIREWORK, x + randomOffset.get(), y + randomOffset.get(), + z + randomOffset.get(), 0, 0, 0); } + cachedBeams.add(beam); } - + @SubscribeEvent public static void onRenderPlayerHand(RenderSpecificHandEvent event) { if (AllItems.PLACEMENT_HANDGUN.typeOf(event.getItemStack())) { @@ -156,9 +197,9 @@ public class BuilderGunHandler { float equipProgress = event.getEquipProgress(); - if (rightHand && rightHandAnimation > .01f) + if (rightHand && (rightHandAnimation > .01f || dontReequipRight)) equipProgress = 0; - if (!rightHand && leftHandAnimation > .01f) + if (!rightHand && (leftHandAnimation > .01f || dontReequipLeft)) equipProgress = 0; // Render arm @@ -212,5 +253,11 @@ public class BuilderGunHandler { event.setCanceled(true); } } - + + public static void dontAnimateItem(Hand hand) { + boolean rightHand = hand == Hand.MAIN_HAND ^ Minecraft.getInstance().player.getPrimaryHand() == HandSide.LEFT; + dontReequipRight |= rightHand; + dontReequipLeft |= !rightHand; + } + } diff --git a/src/main/java/com/simibubi/create/modules/curiosities/placementHandgun/BuilderGunItem.java b/src/main/java/com/simibubi/create/modules/curiosities/placementHandgun/BuilderGunItem.java index 64caf3a01..b83f3560e 100644 --- a/src/main/java/com/simibubi/create/modules/curiosities/placementHandgun/BuilderGunItem.java +++ b/src/main/java/com/simibubi/create/modules/curiosities/placementHandgun/BuilderGunItem.java @@ -14,7 +14,6 @@ import com.simibubi.create.Create; import com.simibubi.create.foundation.gui.ScreenOpener; import com.simibubi.create.foundation.utility.BlockHelper; import com.simibubi.create.foundation.utility.KeyboardHelper; -import com.simibubi.create.modules.curiosities.placementHandgun.BuilderGunHandler.LaserBeam; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -23,6 +22,7 @@ import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.fluid.IFluidState; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; @@ -38,6 +38,7 @@ import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResultType; import net.minecraft.util.Direction; import net.minecraft.util.Hand; +import net.minecraft.util.HandSide; import net.minecraft.util.NonNullList; import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundEvents; @@ -207,29 +208,30 @@ public class BuilderGunItem extends Item { // Find exact position of gun barrel for VFX float yaw = (float) ((player.rotationYaw) / -180 * Math.PI); float pitch = (float) ((player.rotationPitch) / -180 * Math.PI); - Vec3d barrelPosNoTransform = new Vec3d(mainHand ? -.35f : .35f, -0.1f, 1); + Vec3d barrelPosNoTransform = new Vec3d(mainHand == (player.getPrimaryHand() == HandSide.RIGHT) ? -.35f : .35f, -0.1f, 1); Vec3d barrelPos = start.add(barrelPosNoTransform.rotatePitch(pitch).rotateYaw(yaw)); // Client side - Shoot visual laser if (world.isRemote) { - BuilderGunHandler.addBeam(new LaserBeam(barrelPos, raytrace.getHitVec())); - - if (getTier(Components.Amplifier, item) == ComponentTier.BlazeBrass) { - BuilderGunHandler.addBeam(new LaserBeam( - start.add(barrelPosNoTransform.add(-.09f, -.08f, 0).rotatePitch(pitch).rotateYaw(yaw)), - raytrace.getHitVec())); - } - if (getTier(Components.Amplifier, item) == ComponentTier.ChorusChrome) { - BuilderGunHandler.addBeam(new LaserBeam( - start.add(barrelPosNoTransform.add(-.09f, -.08f, 0).rotatePitch(pitch).rotateYaw(yaw)), - raytrace.getHitVec())); - BuilderGunHandler.addBeam(new LaserBeam( - start.add(barrelPosNoTransform.add(.09f, -.08f, 0).rotatePitch(pitch).rotateYaw(yaw)), - raytrace.getHitVec())); - } - - BuilderGunHandler.shoot(hand); - applyCooldown(player, item, gunInOtherHand); +// BuilderGunHandler.addBeam(new LaserBeam(barrelPos, raytrace.getHitVec())); +// +// if (getTier(Components.Amplifier, item) == ComponentTier.BlazeBrass) { +// BuilderGunHandler.addBeam(new LaserBeam( +// start.add(barrelPosNoTransform.add(-.09f, -.08f, 0).rotatePitch(pitch).rotateYaw(yaw)), +// raytrace.getHitVec())); +// } +// if (getTier(Components.Amplifier, item) == ComponentTier.ChorusChrome) { +// BuilderGunHandler.addBeam(new LaserBeam( +// start.add(barrelPosNoTransform.add(-.09f, -.08f, 0).rotatePitch(pitch).rotateYaw(yaw)), +// raytrace.getHitVec())); +// BuilderGunHandler.addBeam(new LaserBeam( +// start.add(barrelPosNoTransform.add(.09f, -.08f, 0).rotatePitch(pitch).rotateYaw(yaw)), +// raytrace.getHitVec())); +// } +// +// BuilderGunHandler.shoot(hand); +// applyCooldown(player, item, gunInOtherHand); + BuilderGunHandler.dontAnimateItem(hand); return new ActionResult(ActionResultType.SUCCESS, item); } @@ -268,7 +270,9 @@ public class BuilderGunItem extends Item { applyCooldown(player, item, gunInOtherHand); AllPackets.channel.send(PacketDistributor.TRACKING_ENTITY.with(() -> player), - new BuilderGunBeamPacket(barrelPos, raytrace.getHitVec(), hand)); + new BuilderGunBeamPacket(barrelPos, raytrace.getHitVec(), hand, false)); + AllPackets.channel.send(PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity) player), + new BuilderGunBeamPacket(barrelPos, raytrace.getHitVec(), hand, true)); return new ActionResult(ActionResultType.SUCCESS, item); @@ -316,6 +320,8 @@ public class BuilderGunItem extends Item { return true; if (newState.has(BlockStateProperties.STAIRS_SHAPE)) newState = newState.with(BlockStateProperties.STAIRS_SHAPE, StairsShape.STRAIGHT); + if (newState.has(BlockStateProperties.PERSISTENT)) + newState = newState.with(BlockStateProperties.PERSISTENT, true); if (stack.getTag().contains("BlockUsed") && NBTUtil.readBlockState(stack.getTag().getCompound("BlockUsed")) == newState) @@ -495,9 +501,9 @@ public class BuilderGunItem extends Item { public static int getCooldownDelay(ItemStack stack) { ComponentTier tier = getTier(Components.Accelerator, stack); if (tier == ComponentTier.None) - return 8; + return 10; if (tier == ComponentTier.BlazeBrass) - return 5; + return 6; if (tier == ComponentTier.ChorusChrome) return 2; diff --git a/src/main/java/com/simibubi/create/modules/curiosities/placementHandgun/BuilderGunScreen.java b/src/main/java/com/simibubi/create/modules/curiosities/placementHandgun/BuilderGunScreen.java index c3234b260..d8e0de613 100644 --- a/src/main/java/com/simibubi/create/modules/curiosities/placementHandgun/BuilderGunScreen.java +++ b/src/main/java/com/simibubi/create/modules/curiosities/placementHandgun/BuilderGunScreen.java @@ -173,7 +173,7 @@ public class BuilderGunScreen extends AbstractSimiScreen { int j = topLeftY; ScreenResources.PLACEMENT_GUN.draw(this, i, j); - font.drawStringWithShadow("Placement Handgun", i + 8, j + 10, 0xCCDDFF); + font.drawStringWithShadow("Handheld Blockzapper", i + 8, j + 10, 0xCCDDFF); font.drawString("Patterns", i + 148, j + 11, ScreenResources.FONT_COLOR); minecraft.getTextureManager().bindTexture(AtlasTexture.LOCATION_BLOCKS_TEXTURE); diff --git a/src/main/java/com/simibubi/create/modules/symmetry/SymmetryWandItem.java b/src/main/java/com/simibubi/create/modules/symmetry/SymmetryWandItem.java index 2d5dba869..f2b534884 100644 --- a/src/main/java/com/simibubi/create/modules/symmetry/SymmetryWandItem.java +++ b/src/main/java/com/simibubi/create/modules/symmetry/SymmetryWandItem.java @@ -194,6 +194,8 @@ public class SymmetryWandItem extends Item { Vec3d mirrorPos = symmetry.getPosition(); if (mirrorPos.distanceTo(new Vec3d(pos)) > 50) return; + if (!player.isCreative() && BlockHelper.findAndRemoveInInventory(block, player, 1) == 0) + return; symmetry.process(blockSet); BlockPos to = new BlockPos(mirrorPos); @@ -203,7 +205,7 @@ public class SymmetryWandItem extends Item { for (BlockPos position : blockSet.keySet()) { if (position.equals(pos)) continue; - + if (world.func_217350_a(block, position, ISelectionContext.forEntity(player))) { BlockState blockState = blockSet.get(position); for (Direction face : Direction.values()) @@ -223,7 +225,7 @@ public class SymmetryWandItem extends Item { continue; if (BlockHelper.findAndRemoveInInventory(blockState, player, 1) == 0) continue; - + world.setBlockState(position, blockState); targets.add(position); }