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)
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;
}

View File

@ -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)

View File

@ -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) {
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);
}

View File

@ -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<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);
}
@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;
}
}

View File

@ -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<ItemStack>(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<ItemStack>(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;

View File

@ -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);

View File

@ -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);
}