From fa6bac2bfcba684856f242a8708a2691a57c0380 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Wed, 16 Dec 2020 11:16:46 +0100 Subject: [PATCH] Locally sourced arms - Mechanical arms now serialize target positions in relative coordinates --- .../ContraptionCollider.java | 26 +++++++++---------- .../mechanicalArm/ArmInteractionPoint.java | 8 +++--- .../mechanicalArm/ArmPlacementPacket.java | 2 +- .../block/mechanicalArm/ArmTileEntity.java | 12 ++++----- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionCollider.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionCollider.java index 3d9fd25ee..d3ffcca36 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionCollider.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionCollider.java @@ -83,6 +83,12 @@ public class ContraptionCollider { PlayerType playerType = getPlayerType(entity); if (playerType == PlayerType.REMOTE) continue; + + if (playerType == PlayerType.SERVER && entity instanceof ServerPlayerEntity) { + ((ServerPlayerEntity) entity).connection.floatingTickCount = 0; + continue; + } + if (playerType == PlayerType.CLIENT) if (skipClientPlayer) continue; @@ -193,7 +199,7 @@ public class ContraptionCollider { totalResponse = VecHelper.rotate(totalResponse, yawOffset, Axis.Y); rotationMatrix.transpose(); - if (temporalCollision && playerType != PlayerType.SERVER) { + if (temporalCollision) { double idealVerticalMotion = motionResponse.y; if (idealVerticalMotion != entityMotion.y) { entity.setMotion(entityMotion.mul(1, 0, 1) @@ -223,11 +229,6 @@ public class ContraptionCollider { if (!hardCollision && surfaceCollision.isFalse()) continue; - if (playerType == PlayerType.SERVER && entity instanceof ServerPlayerEntity) { - ((ServerPlayerEntity) entity).connection.floatingTickCount = 0; - continue; - } - Vec3d allowedMovement = getAllowedMovement(totalResponse, entity); entity.setPosition(entityPosition.x + allowedMovement.x, entityPosition.y + allowedMovement.y, entityPosition.z + allowedMovement.z); @@ -242,12 +243,10 @@ public class ContraptionCollider { contraptionEntity.collidingEntities.put(entity, new MutableInt(0)); if (entity instanceof ItemEntity) entityMotion = entityMotion.mul(.5f, 1, .5f); - if (playerType != PlayerType.SERVER) { - contactPointMotion = contraptionEntity.getContactPointMotion(entityPosition); - allowedMovement = getAllowedMovement(contactPointMotion, entity); - entity.setPosition(entityPosition.x + allowedMovement.x, - entityPosition.y, entityPosition.z + allowedMovement.z); - } + contactPointMotion = contraptionEntity.getContactPointMotion(entityPosition); + allowedMovement = getAllowedMovement(contactPointMotion, entity); + entity.setPosition(entityPosition.x + allowedMovement.x, entityPosition.y, + entityPosition.z + allowedMovement.z); } entity.setMotion(entityMotion); @@ -260,8 +259,7 @@ public class ContraptionCollider { float limbSwing = MathHelper.sqrt(d0 * d0 + d1 * d1) * 4.0F; if (limbSwing > 1.0F) limbSwing = 1.0F; - AllPackets.channel - .sendToServer(new ClientMotionPacket(entityMotion, true, limbSwing)); + AllPackets.channel.sendToServer(new ClientMotionPacket(entityMotion, true, limbSwing)); } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInteractionPoint.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInteractionPoint.java index 99a83a092..de5677b64 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInteractionPoint.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInteractionPoint.java @@ -177,16 +177,16 @@ public abstract class ArmInteractionPoint { return point; } - CompoundNBT serialize() { + CompoundNBT serialize(BlockPos anchor) { CompoundNBT nbt = new CompoundNBT(); - nbt.put("Pos", NBTUtil.writeBlockPos(pos)); + nbt.put("Pos", NBTUtil.writeBlockPos(pos.subtract(anchor))); NBTHelper.writeEnum(nbt, "Mode", mode); return nbt; } - static ArmInteractionPoint deserialize(IBlockReader world, CompoundNBT nbt) { + static ArmInteractionPoint deserialize(IBlockReader world, BlockPos anchor, CompoundNBT nbt) { BlockPos pos = NBTUtil.readBlockPos(nbt.getCompound("Pos")); - ArmInteractionPoint interactionPoint = createAt(world, pos); + ArmInteractionPoint interactionPoint = createAt(world, pos.add(anchor)); if (interactionPoint == null) return null; interactionPoint.mode = NBTHelper.readEnum(nbt, "Mode", Mode.class); diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmPlacementPacket.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmPlacementPacket.java index 7ed4f378e..5ef6187a7 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmPlacementPacket.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmPlacementPacket.java @@ -37,7 +37,7 @@ public class ArmPlacementPacket extends SimplePacketBase { CompoundNBT nbt = new CompoundNBT(); ListNBT pointsNBT = new ListNBT(); points.stream() - .map(ArmInteractionPoint::serialize) + .map(aip -> aip.serialize(pos)) .forEach(pointsNBT::add); nbt.put("Points", pointsNBT); buffer.writeCompoundTag(nbt); diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java index 00a25e2dd..7d72c4ff1 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java @@ -366,10 +366,10 @@ public class ArmTileEntity extends KineticTileEntity { return; inputs.clear(); outputs.clear(); - + boolean hasBlazeBurner = false; for (INBT inbt : interactionPointTag) { - ArmInteractionPoint point = ArmInteractionPoint.deserialize(world, (CompoundNBT) inbt); + ArmInteractionPoint point = ArmInteractionPoint.deserialize(world, pos, (CompoundNBT) inbt); if (point == null) continue; if (point.mode == Mode.DEPOSIT) @@ -378,14 +378,14 @@ public class ArmTileEntity extends KineticTileEntity { inputs.add(point); hasBlazeBurner |= point instanceof ArmInteractionPoint.BlazeBurner; } - + if (!world.isRemote) { if (outputs.size() >= 10) AllTriggers.triggerForNearbyPlayers(AllTriggers.ARM_MANY_TARGETS, world, pos, 5); if (hasBlazeBurner) AllTriggers.triggerForNearbyPlayers(AllTriggers.ARM_BLAZE_BURNER, world, pos, 5); } - + updateInteractionPoints = false; sendData(); markDirty(); @@ -401,10 +401,10 @@ public class ArmTileEntity extends KineticTileEntity { } else { ListNBT pointsNBT = new ListNBT(); inputs.stream() - .map(ArmInteractionPoint::serialize) + .map(aip -> aip.serialize(pos)) .forEach(pointsNBT::add); outputs.stream() - .map(ArmInteractionPoint::serialize) + .map(aip -> aip.serialize(pos)) .forEach(pointsNBT::add); compound.put("InteractionPoints", pointsNBT); }