Locally sourced arms
- Mechanical arms now serialize target positions in relative coordinates
This commit is contained in:
parent
64b2c61389
commit
fa6bac2bfc
4 changed files with 23 additions and 25 deletions
|
@ -83,6 +83,12 @@ public class ContraptionCollider {
|
||||||
PlayerType playerType = getPlayerType(entity);
|
PlayerType playerType = getPlayerType(entity);
|
||||||
if (playerType == PlayerType.REMOTE)
|
if (playerType == PlayerType.REMOTE)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (playerType == PlayerType.SERVER && entity instanceof ServerPlayerEntity) {
|
||||||
|
((ServerPlayerEntity) entity).connection.floatingTickCount = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (playerType == PlayerType.CLIENT)
|
if (playerType == PlayerType.CLIENT)
|
||||||
if (skipClientPlayer)
|
if (skipClientPlayer)
|
||||||
continue;
|
continue;
|
||||||
|
@ -193,7 +199,7 @@ public class ContraptionCollider {
|
||||||
totalResponse = VecHelper.rotate(totalResponse, yawOffset, Axis.Y);
|
totalResponse = VecHelper.rotate(totalResponse, yawOffset, Axis.Y);
|
||||||
rotationMatrix.transpose();
|
rotationMatrix.transpose();
|
||||||
|
|
||||||
if (temporalCollision && playerType != PlayerType.SERVER) {
|
if (temporalCollision) {
|
||||||
double idealVerticalMotion = motionResponse.y;
|
double idealVerticalMotion = motionResponse.y;
|
||||||
if (idealVerticalMotion != entityMotion.y) {
|
if (idealVerticalMotion != entityMotion.y) {
|
||||||
entity.setMotion(entityMotion.mul(1, 0, 1)
|
entity.setMotion(entityMotion.mul(1, 0, 1)
|
||||||
|
@ -223,11 +229,6 @@ public class ContraptionCollider {
|
||||||
if (!hardCollision && surfaceCollision.isFalse())
|
if (!hardCollision && surfaceCollision.isFalse())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (playerType == PlayerType.SERVER && entity instanceof ServerPlayerEntity) {
|
|
||||||
((ServerPlayerEntity) entity).connection.floatingTickCount = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec3d allowedMovement = getAllowedMovement(totalResponse, entity);
|
Vec3d allowedMovement = getAllowedMovement(totalResponse, entity);
|
||||||
entity.setPosition(entityPosition.x + allowedMovement.x, entityPosition.y + allowedMovement.y,
|
entity.setPosition(entityPosition.x + allowedMovement.x, entityPosition.y + allowedMovement.y,
|
||||||
entityPosition.z + allowedMovement.z);
|
entityPosition.z + allowedMovement.z);
|
||||||
|
@ -242,12 +243,10 @@ public class ContraptionCollider {
|
||||||
contraptionEntity.collidingEntities.put(entity, new MutableInt(0));
|
contraptionEntity.collidingEntities.put(entity, new MutableInt(0));
|
||||||
if (entity instanceof ItemEntity)
|
if (entity instanceof ItemEntity)
|
||||||
entityMotion = entityMotion.mul(.5f, 1, .5f);
|
entityMotion = entityMotion.mul(.5f, 1, .5f);
|
||||||
if (playerType != PlayerType.SERVER) {
|
|
||||||
contactPointMotion = contraptionEntity.getContactPointMotion(entityPosition);
|
contactPointMotion = contraptionEntity.getContactPointMotion(entityPosition);
|
||||||
allowedMovement = getAllowedMovement(contactPointMotion, entity);
|
allowedMovement = getAllowedMovement(contactPointMotion, entity);
|
||||||
entity.setPosition(entityPosition.x + allowedMovement.x,
|
entity.setPosition(entityPosition.x + allowedMovement.x, entityPosition.y,
|
||||||
entityPosition.y, entityPosition.z + allowedMovement.z);
|
entityPosition.z + allowedMovement.z);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
entity.setMotion(entityMotion);
|
entity.setMotion(entityMotion);
|
||||||
|
@ -260,8 +259,7 @@ public class ContraptionCollider {
|
||||||
float limbSwing = MathHelper.sqrt(d0 * d0 + d1 * d1) * 4.0F;
|
float limbSwing = MathHelper.sqrt(d0 * d0 + d1 * d1) * 4.0F;
|
||||||
if (limbSwing > 1.0F)
|
if (limbSwing > 1.0F)
|
||||||
limbSwing = 1.0F;
|
limbSwing = 1.0F;
|
||||||
AllPackets.channel
|
AllPackets.channel.sendToServer(new ClientMotionPacket(entityMotion, true, limbSwing));
|
||||||
.sendToServer(new ClientMotionPacket(entityMotion, true, limbSwing));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,16 +177,16 @@ public abstract class ArmInteractionPoint {
|
||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompoundNBT serialize() {
|
CompoundNBT serialize(BlockPos anchor) {
|
||||||
CompoundNBT nbt = new CompoundNBT();
|
CompoundNBT nbt = new CompoundNBT();
|
||||||
nbt.put("Pos", NBTUtil.writeBlockPos(pos));
|
nbt.put("Pos", NBTUtil.writeBlockPos(pos.subtract(anchor)));
|
||||||
NBTHelper.writeEnum(nbt, "Mode", mode);
|
NBTHelper.writeEnum(nbt, "Mode", mode);
|
||||||
return nbt;
|
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"));
|
BlockPos pos = NBTUtil.readBlockPos(nbt.getCompound("Pos"));
|
||||||
ArmInteractionPoint interactionPoint = createAt(world, pos);
|
ArmInteractionPoint interactionPoint = createAt(world, pos.add(anchor));
|
||||||
if (interactionPoint == null)
|
if (interactionPoint == null)
|
||||||
return null;
|
return null;
|
||||||
interactionPoint.mode = NBTHelper.readEnum(nbt, "Mode", Mode.class);
|
interactionPoint.mode = NBTHelper.readEnum(nbt, "Mode", Mode.class);
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class ArmPlacementPacket extends SimplePacketBase {
|
||||||
CompoundNBT nbt = new CompoundNBT();
|
CompoundNBT nbt = new CompoundNBT();
|
||||||
ListNBT pointsNBT = new ListNBT();
|
ListNBT pointsNBT = new ListNBT();
|
||||||
points.stream()
|
points.stream()
|
||||||
.map(ArmInteractionPoint::serialize)
|
.map(aip -> aip.serialize(pos))
|
||||||
.forEach(pointsNBT::add);
|
.forEach(pointsNBT::add);
|
||||||
nbt.put("Points", pointsNBT);
|
nbt.put("Points", pointsNBT);
|
||||||
buffer.writeCompoundTag(nbt);
|
buffer.writeCompoundTag(nbt);
|
||||||
|
|
|
@ -369,7 +369,7 @@ public class ArmTileEntity extends KineticTileEntity {
|
||||||
|
|
||||||
boolean hasBlazeBurner = false;
|
boolean hasBlazeBurner = false;
|
||||||
for (INBT inbt : interactionPointTag) {
|
for (INBT inbt : interactionPointTag) {
|
||||||
ArmInteractionPoint point = ArmInteractionPoint.deserialize(world, (CompoundNBT) inbt);
|
ArmInteractionPoint point = ArmInteractionPoint.deserialize(world, pos, (CompoundNBT) inbt);
|
||||||
if (point == null)
|
if (point == null)
|
||||||
continue;
|
continue;
|
||||||
if (point.mode == Mode.DEPOSIT)
|
if (point.mode == Mode.DEPOSIT)
|
||||||
|
@ -401,10 +401,10 @@ public class ArmTileEntity extends KineticTileEntity {
|
||||||
} else {
|
} else {
|
||||||
ListNBT pointsNBT = new ListNBT();
|
ListNBT pointsNBT = new ListNBT();
|
||||||
inputs.stream()
|
inputs.stream()
|
||||||
.map(ArmInteractionPoint::serialize)
|
.map(aip -> aip.serialize(pos))
|
||||||
.forEach(pointsNBT::add);
|
.forEach(pointsNBT::add);
|
||||||
outputs.stream()
|
outputs.stream()
|
||||||
.map(ArmInteractionPoint::serialize)
|
.map(aip -> aip.serialize(pos))
|
||||||
.forEach(pointsNBT::add);
|
.forEach(pointsNBT::add);
|
||||||
compound.put("InteractionPoints", pointsNBT);
|
compound.put("InteractionPoints", pointsNBT);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue