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
This commit is contained in:
simibubi 2019-07-28 19:23:42 +02:00
parent 903ad95bf0
commit 488c1a1374
7 changed files with 121 additions and 45 deletions

View file

@ -19,6 +19,20 @@ public class BlockHelper {
if (needsTwo) if (needsTwo)
amount *= 2; 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) { for (int i = 0; i < player.inventory.getSizeInventory(); ++i) {
if (amountFound == amount) if (amountFound == amount)
break; break;
@ -32,7 +46,6 @@ public class BlockHelper {
} }
} }
if (needsTwo) { if (needsTwo) {
// Give back 1 if uneven amount was removed // Give back 1 if uneven amount was removed
if (amountFound % 2 != 0) if (amountFound % 2 != 0)

View file

@ -78,7 +78,7 @@ public class TreeFertilizerItem extends Item {
BlockPos actualPos = pos.add(saplingPos).down(10); BlockPos actualPos = pos.add(saplingPos).down(10);
// Don't replace Bedrock // 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; continue;
// Don't replace solid blocks with leaves // Don't replace solid blocks with leaves
if (!world.getBlockState(pos).isNormalCube(world, pos) if (!world.getBlockState(pos).isNormalCube(world, pos)

View file

@ -18,17 +18,20 @@ public class BuilderGunBeamPacket {
public Vec3d start; public Vec3d start;
public Vec3d target; public Vec3d target;
public Hand hand; 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.start = start;
this.target = target; this.target = target;
this.hand = hand; this.hand = hand;
this.self = self;
} }
public BuilderGunBeamPacket(PacketBuffer buffer) { public BuilderGunBeamPacket(PacketBuffer buffer) {
start = new Vec3d(buffer.readDouble(), buffer.readDouble(), buffer.readDouble()); start = new Vec3d(buffer.readDouble(), buffer.readDouble(), buffer.readDouble());
target = 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; hand = buffer.readBoolean()? Hand.MAIN_HAND : Hand.OFF_HAND;
self = buffer.readBoolean();
} }
public void toBytes(PacketBuffer buffer) { public void toBytes(PacketBuffer buffer) {
@ -40,14 +43,19 @@ public class BuilderGunBeamPacket {
buffer.writeDouble(target.z); buffer.writeDouble(target.z);
buffer.writeBoolean(hand == Hand.MAIN_HAND); buffer.writeBoolean(hand == Hand.MAIN_HAND);
buffer.writeBoolean(self);
} }
public void handle(Supplier<Context> context) { public void handle(Supplier<Context> context) {
context.get().enqueueWork(() -> DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> { context.get().enqueueWork(() -> DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> {
if (Minecraft.getInstance().player.getPositionVector().distanceTo(start) > 100) if (Minecraft.getInstance().player.getPositionVector().distanceTo(start) > 100)
return; return;
BuilderGunHandler.addBeam(new LaserBeam(start, target)); BuilderGunHandler.addBeam(new LaserBeam(start, target).followPlayer(self, hand == Hand.MAIN_HAND));
BuilderGunHandler.playSound(hand, new BlockPos(start));
if (self)
BuilderGunHandler.shoot(hand);
else
BuilderGunHandler.playSound(hand, new BlockPos(start));
})); }));
context.get().setPacketHandled(true); context.get().setPacketHandled(true);
} }

View file

@ -2,6 +2,8 @@ package com.simibubi.create.modules.curiosities.placementHandgun;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Random;
import java.util.function.Supplier;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
@ -49,16 +51,45 @@ public class BuilderGunHandler {
private static float lastLeftHandAnimation; private static float lastLeftHandAnimation;
private static float lastRightHandAnimation; private static float lastRightHandAnimation;
private static boolean dontReequipLeft;
private static boolean dontReequipRight;
public static class LaserBeam { public static class LaserBeam {
float itensity; float itensity;
Vec3d start; Vec3d start;
Vec3d end; Vec3d end;
boolean follow;
boolean mainHand;
public LaserBeam(Vec3d start, Vec3d end) { public LaserBeam(Vec3d start, Vec3d end) {
this.start = start; this.start = start;
this.end = end; this.end = end;
itensity = 1; 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) @SubscribeEvent(priority = EventPriority.HIGHEST)
@ -106,7 +137,7 @@ public class BuilderGunHandler {
BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer(); BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer();
bufferBuilder.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION); 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(); bufferBuilder.pos(beam.end.x, beam.end.y, beam.end.z).endVertex();
Tessellator.getInstance().draw(); Tessellator.getInstance().draw();
@ -119,10 +150,13 @@ public class BuilderGunHandler {
public static void shoot(Hand hand) { public static void shoot(Hand hand) {
ClientPlayerEntity player = Minecraft.getInstance().player; ClientPlayerEntity player = Minecraft.getInstance().player;
boolean rightHand = hand == Hand.MAIN_HAND ^ player.getPrimaryHand() == HandSide.LEFT; boolean rightHand = hand == Hand.MAIN_HAND ^ player.getPrimaryHand() == HandSide.LEFT;
if (rightHand) if (rightHand) {
rightHandAnimation = .2f; rightHandAnimation = .2f;
else dontReequipRight = false;
} else {
leftHandAnimation = .2f; leftHandAnimation = .2f;
dontReequipLeft = false;
}
playSound(hand, player.getPosition()); playSound(hand, player.getPosition());
} }
@ -133,12 +167,19 @@ public class BuilderGunHandler {
} }
public static void addBeam(LaserBeam beam) { public static void addBeam(LaserBeam beam) {
Vec3d step = beam.end.subtract(beam.start).normalize(); Random r = new Random();
int steps = (int) (beam.end.squareDistanceTo(beam.start) / step.lengthSquared()); double x = beam.end.x;
for (int i = 0; i <= steps; i++) { double y = beam.end.y;
Vec3d pos = beam.start.add(step.scale(i)); double z = beam.end.z;
Minecraft.getInstance().world.addParticle(ParticleTypes.END_ROD, pos.x, pos.y, pos.z, 0, -15000, 0); ClientWorld world = Minecraft.getInstance().world;
Supplier<Double> randomSpeed = () -> (r.nextDouble() - .5d) * .2f;
Supplier<Double> 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); cachedBeams.add(beam);
} }
@ -156,9 +197,9 @@ public class BuilderGunHandler {
float equipProgress = event.getEquipProgress(); float equipProgress = event.getEquipProgress();
if (rightHand && rightHandAnimation > .01f) if (rightHand && (rightHandAnimation > .01f || dontReequipRight))
equipProgress = 0; equipProgress = 0;
if (!rightHand && leftHandAnimation > .01f) if (!rightHand && (leftHandAnimation > .01f || dontReequipLeft))
equipProgress = 0; equipProgress = 0;
// Render arm // Render arm
@ -213,4 +254,10 @@ public class BuilderGunHandler {
} }
} }
public static void dontAnimateItem(Hand hand) {
boolean rightHand = hand == Hand.MAIN_HAND ^ Minecraft.getInstance().player.getPrimaryHand() == HandSide.LEFT;
dontReequipRight |= rightHand;
dontReequipLeft |= !rightHand;
}
} }

View file

@ -14,7 +14,6 @@ import com.simibubi.create.Create;
import com.simibubi.create.foundation.gui.ScreenOpener; import com.simibubi.create.foundation.gui.ScreenOpener;
import com.simibubi.create.foundation.utility.BlockHelper; import com.simibubi.create.foundation.utility.BlockHelper;
import com.simibubi.create.foundation.utility.KeyboardHelper; 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.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
@ -23,6 +22,7 @@ import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.fluid.IFluidState; import net.minecraft.fluid.IFluidState;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemGroup;
@ -38,6 +38,7 @@ import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType; import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.HandSide;
import net.minecraft.util.NonNullList; import net.minecraft.util.NonNullList;
import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents; import net.minecraft.util.SoundEvents;
@ -207,29 +208,30 @@ public class BuilderGunItem extends Item {
// Find exact position of gun barrel for VFX // Find exact position of gun barrel for VFX
float yaw = (float) ((player.rotationYaw) / -180 * Math.PI); float yaw = (float) ((player.rotationYaw) / -180 * Math.PI);
float pitch = (float) ((player.rotationPitch) / -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)); Vec3d barrelPos = start.add(barrelPosNoTransform.rotatePitch(pitch).rotateYaw(yaw));
// Client side - Shoot visual laser // Client side - Shoot visual laser
if (world.isRemote) { if (world.isRemote) {
BuilderGunHandler.addBeam(new LaserBeam(barrelPos, raytrace.getHitVec())); // BuilderGunHandler.addBeam(new LaserBeam(barrelPos, raytrace.getHitVec()));
//
if (getTier(Components.Amplifier, item) == ComponentTier.BlazeBrass) { // if (getTier(Components.Amplifier, item) == ComponentTier.BlazeBrass) {
BuilderGunHandler.addBeam(new LaserBeam( // BuilderGunHandler.addBeam(new LaserBeam(
start.add(barrelPosNoTransform.add(-.09f, -.08f, 0).rotatePitch(pitch).rotateYaw(yaw)), // start.add(barrelPosNoTransform.add(-.09f, -.08f, 0).rotatePitch(pitch).rotateYaw(yaw)),
raytrace.getHitVec())); // raytrace.getHitVec()));
} // }
if (getTier(Components.Amplifier, item) == ComponentTier.ChorusChrome) { // if (getTier(Components.Amplifier, item) == ComponentTier.ChorusChrome) {
BuilderGunHandler.addBeam(new LaserBeam( // BuilderGunHandler.addBeam(new LaserBeam(
start.add(barrelPosNoTransform.add(-.09f, -.08f, 0).rotatePitch(pitch).rotateYaw(yaw)), // start.add(barrelPosNoTransform.add(-.09f, -.08f, 0).rotatePitch(pitch).rotateYaw(yaw)),
raytrace.getHitVec())); // raytrace.getHitVec()));
BuilderGunHandler.addBeam(new LaserBeam( // BuilderGunHandler.addBeam(new LaserBeam(
start.add(barrelPosNoTransform.add(.09f, -.08f, 0).rotatePitch(pitch).rotateYaw(yaw)), // start.add(barrelPosNoTransform.add(.09f, -.08f, 0).rotatePitch(pitch).rotateYaw(yaw)),
raytrace.getHitVec())); // raytrace.getHitVec()));
} // }
//
BuilderGunHandler.shoot(hand); // BuilderGunHandler.shoot(hand);
applyCooldown(player, item, gunInOtherHand); // applyCooldown(player, item, gunInOtherHand);
BuilderGunHandler.dontAnimateItem(hand);
return new ActionResult<ItemStack>(ActionResultType.SUCCESS, item); return new ActionResult<ItemStack>(ActionResultType.SUCCESS, item);
} }
@ -268,7 +270,9 @@ public class BuilderGunItem extends Item {
applyCooldown(player, item, gunInOtherHand); applyCooldown(player, item, gunInOtherHand);
AllPackets.channel.send(PacketDistributor.TRACKING_ENTITY.with(() -> player), 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<ItemStack>(ActionResultType.SUCCESS, item); return new ActionResult<ItemStack>(ActionResultType.SUCCESS, item);
@ -316,6 +320,8 @@ public class BuilderGunItem extends Item {
return true; return true;
if (newState.has(BlockStateProperties.STAIRS_SHAPE)) if (newState.has(BlockStateProperties.STAIRS_SHAPE))
newState = newState.with(BlockStateProperties.STAIRS_SHAPE, StairsShape.STRAIGHT); newState = newState.with(BlockStateProperties.STAIRS_SHAPE, StairsShape.STRAIGHT);
if (newState.has(BlockStateProperties.PERSISTENT))
newState = newState.with(BlockStateProperties.PERSISTENT, true);
if (stack.getTag().contains("BlockUsed") if (stack.getTag().contains("BlockUsed")
&& NBTUtil.readBlockState(stack.getTag().getCompound("BlockUsed")) == newState) && NBTUtil.readBlockState(stack.getTag().getCompound("BlockUsed")) == newState)
@ -495,9 +501,9 @@ public class BuilderGunItem extends Item {
public static int getCooldownDelay(ItemStack stack) { public static int getCooldownDelay(ItemStack stack) {
ComponentTier tier = getTier(Components.Accelerator, stack); ComponentTier tier = getTier(Components.Accelerator, stack);
if (tier == ComponentTier.None) if (tier == ComponentTier.None)
return 8; return 10;
if (tier == ComponentTier.BlazeBrass) if (tier == ComponentTier.BlazeBrass)
return 5; return 6;
if (tier == ComponentTier.ChorusChrome) if (tier == ComponentTier.ChorusChrome)
return 2; return 2;

View file

@ -173,7 +173,7 @@ public class BuilderGunScreen extends AbstractSimiScreen {
int j = topLeftY; int j = topLeftY;
ScreenResources.PLACEMENT_GUN.draw(this, i, j); 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); font.drawString("Patterns", i + 148, j + 11, ScreenResources.FONT_COLOR);
minecraft.getTextureManager().bindTexture(AtlasTexture.LOCATION_BLOCKS_TEXTURE); minecraft.getTextureManager().bindTexture(AtlasTexture.LOCATION_BLOCKS_TEXTURE);

View file

@ -194,6 +194,8 @@ public class SymmetryWandItem extends Item {
Vec3d mirrorPos = symmetry.getPosition(); Vec3d mirrorPos = symmetry.getPosition();
if (mirrorPos.distanceTo(new Vec3d(pos)) > 50) if (mirrorPos.distanceTo(new Vec3d(pos)) > 50)
return; return;
if (!player.isCreative() && BlockHelper.findAndRemoveInInventory(block, player, 1) == 0)
return;
symmetry.process(blockSet); symmetry.process(blockSet);
BlockPos to = new BlockPos(mirrorPos); BlockPos to = new BlockPos(mirrorPos);