From d61b840c5c07c9f1ac029b142534d1897b0ce612 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Tue, 9 Mar 2021 04:24:45 +0100 Subject: [PATCH] Back to fighting Minecarts - Fixed Minecart Contraptions started on a powered rail facing in unwanted directions - Fixed powered rail Cart Assemblers not respecting the solid block rule of powered rails - Fixed Minecart contraption items not facing away from the player when placed - Polished every last bit of the belt uvs --- .../AbstractContraptionEntity.java | 2 +- .../OrientedContraptionEntity.java | 45 ++++++++++------ .../mounted/CartAssemblerBlock.java | 51 +++++++++++++------ .../mounted/MinecartContraptionItem.java | 7 ++- .../models/block/belt/diagonal_end.json | 12 +++-- .../assets/create/models/block/belt/end.json | 10 ++-- .../create/models/block/belt/start.json | 4 +- .../models/block/belt/start_bottom.json | 4 +- 8 files changed, 93 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java index 3a9bd106d..867d8d685 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java @@ -58,7 +58,7 @@ public abstract class AbstractContraptionEntity extends Entity implements IEntit protected Contraption contraption; protected boolean initialized; - private boolean prevPosInvalid; + protected boolean prevPosInvalid; private boolean ticking; public AbstractContraptionEntity(EntityType entityTypeIn, World worldIn) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/OrientedContraptionEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/OrientedContraptionEntity.java index 6d241061a..b5d3c21e7 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/OrientedContraptionEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/OrientedContraptionEntity.java @@ -64,6 +64,7 @@ public class OrientedContraptionEntity extends AbstractContraptionEntity { protected boolean forceAngle; private boolean isSerializingFurnaceCart; private boolean attachedExtraInventories; + private boolean manuallyPlaced; public float prevYaw; public float yaw; @@ -94,6 +95,14 @@ public class OrientedContraptionEntity extends AbstractContraptionEntity { return entity; } + public static OrientedContraptionEntity createAtYaw(World world, Contraption contraption, + Optional initialOrientation, float initialYaw) { + OrientedContraptionEntity entity = create(world, contraption, initialOrientation); + entity.startAtYaw(initialYaw); + entity.manuallyPlaced = true; + return entity; + } + public void setInitialOrientation(Direction direction) { dataManager.set(INITIAL_ORIENTATION, direction); } @@ -153,6 +162,11 @@ public class OrientedContraptionEntity extends AbstractContraptionEntity { if (compound.contains("InitialOrientation")) setInitialOrientation(NBTHelper.readEnum(compound, "InitialOrientation", Direction.class)); + + yaw = compound.getFloat("Yaw"); + pitch = compound.getFloat("Pitch"); + manuallyPlaced = compound.getBoolean("Placed"); + if (compound.contains("ForceYaw")) startAtYaw(compound.getFloat("ForceYaw")); @@ -164,9 +178,6 @@ public class OrientedContraptionEntity extends AbstractContraptionEntity { setMotion(Vec3d.ZERO); } - yaw = compound.getFloat("Yaw"); - pitch = compound.getFloat("Pitch"); - setCouplingId( compound.contains("OnCoupling") ? NBTUtil.readUniqueId(compound.getCompound("OnCoupling")) : null); } @@ -188,6 +199,7 @@ public class OrientedContraptionEntity extends AbstractContraptionEntity { forceAngle = false; } + compound.putBoolean("Placed", manuallyPlaced); compound.putFloat("Yaw", yaw); compound.putFloat("Pitch", pitch); @@ -198,7 +210,7 @@ public class OrientedContraptionEntity extends AbstractContraptionEntity { @Override public void notifyDataManagerChange(DataParameter key) { super.notifyDataManagerChange(key); - if (key == INITIAL_ORIENTATION && isInitialOrientationPresent()) + if (key == INITIAL_ORIENTATION && isInitialOrientationPresent() && !manuallyPlaced) startAtInitialYaw(); } @@ -357,14 +369,16 @@ public class OrientedContraptionEntity extends AbstractContraptionEntity { boolean rotating = false; Vec3d movementVector = riding.getMotion(); - + Vec3d locationDiff = riding.getPositionVec() + .subtract(riding.prevPosX, riding.prevPosY, riding.prevPosZ); if (!(riding instanceof AbstractMinecartEntity)) - movementVector = getPositionVec().subtract(prevPosX, prevPosY, prevPosZ); + movementVector = locationDiff; Vec3d motion = movementVector.normalize(); if (!isInitialOrientationPresent() && !world.isRemote) { - if (motion.length() > 0) { - Direction facingFromVector = Direction.getFacingFromVector(motion.x, motion.y, motion.z); + if (locationDiff.length() > 0) { + Direction facingFromVector = + Direction.getFacingFromVector(locationDiff.x, locationDiff.y, locationDiff.z); if (initialYawOffset != -1) facingFromVector = Direction.fromAngle(facingFromVector.getHorizontalAngle() - initialYawOffset); if (facingFromVector.getAxis() @@ -520,12 +534,12 @@ public class OrientedContraptionEntity extends AbstractContraptionEntity { for (MatrixStack stack : matrixStacks) MatrixStacker.of(stack) - .nudge(getEntityId()) - .centre() - .rotateY(angleYaw) - .rotateZ(anglePitch) - .rotateY(angleInitialYaw) - .unCentre(); + .nudge(getEntityId()) + .centre() + .rotateY(angleYaw) + .rotateZ(anglePitch) + .rotateY(angleInitialYaw) + .unCentre(); } @OnlyIn(Dist.CLIENT) @@ -541,7 +555,8 @@ public class OrientedContraptionEntity extends AbstractContraptionEntity { private void repositionOnCart(float partialTicks, MatrixStack[] matrixStacks, Entity ridingEntity) { Vec3d cartPos = getCartOffset(partialTicks, ridingEntity); - if (cartPos == Vec3d.ZERO) return; + if (cartPos == Vec3d.ZERO) + return; for (MatrixStack stack : matrixStacks) stack.translate(cartPos.x, cartPos.y, cartPos.z); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerBlock.java index f6f67fe4f..786c994a4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerBlock.java @@ -92,15 +92,18 @@ public class CartAssemblerBlock extends AbstractRailBlock } private static Item getRailItem(BlockState state) { - return state.get(RAIL_TYPE).getItem(); + return state.get(RAIL_TYPE) + .getItem(); } public static BlockState getRailBlock(BlockState state) { - AbstractRailBlock railBlock = (AbstractRailBlock) state.get(RAIL_TYPE).getBlock(); + AbstractRailBlock railBlock = (AbstractRailBlock) state.get(RAIL_TYPE) + .getBlock(); BlockState railState = railBlock.getDefaultState() .with(railBlock.getShapeProperty(), state.get(RAIL_SHAPE)); if (railState.has(ControllerRailBlock.BACKWARDS)) { - railState = railState.with(ControllerRailBlock.BACKWARDS, state.get(RAIL_TYPE) == CartAssembleRailType.CONTROLLER_RAIL_BACKWARDS); + railState = railState.with(ControllerRailBlock.BACKWARDS, + state.get(RAIL_TYPE) == CartAssembleRailType.CONTROLLER_RAIL_BACKWARDS); } return railState; } @@ -145,11 +148,22 @@ public class CartAssemblerBlock extends AbstractRailBlock disassemble(world, pos, cart); if (action == CartAssemblerAction.ASSEMBLE_ACCELERATE) { Direction facing = cart.getAdjustedHorizontalFacing(); + + RailShape railShape = state.get(RAIL_SHAPE); + for (Direction d : Iterate.directionsInAxis(railShape == RailShape.EAST_WEST ? Axis.X : Axis.Z)) + if (world.getBlockState(pos.offset(d)) + .isNormalCube(world, pos.offset(d))) + facing = d.getOpposite(); + float speed = getRailMaxSpeed(state, world, pos, cart); cart.setMotion(facing.getXOffset() * speed, facing.getYOffset() * speed, facing.getZOffset() * speed); } if (action == CartAssemblerAction.ASSEMBLE_ACCELERATE_DIRECTIONAL) { - Vec3i accelerationVector = ControllerRailBlock.getAccelerationVector(AllBlocks.CONTROLLER_RAIL.getDefaultState().with(ControllerRailBlock.SHAPE, state.get(RAIL_SHAPE)).with(ControllerRailBlock.BACKWARDS, state.get(RAIL_TYPE) == CartAssembleRailType.CONTROLLER_RAIL_BACKWARDS)); + Vec3i accelerationVector = + ControllerRailBlock.getAccelerationVector(AllBlocks.CONTROLLER_RAIL.getDefaultState() + .with(ControllerRailBlock.SHAPE, state.get(RAIL_SHAPE)) + .with(ControllerRailBlock.BACKWARDS, + state.get(RAIL_TYPE) == CartAssembleRailType.CONTROLLER_RAIL_BACKWARDS)); float speed = getRailMaxSpeed(state, world, pos, cart); cart.setMotion(new Vec3d(accelerationVector).scale(speed)); } @@ -192,7 +206,8 @@ public class CartAssemblerBlock extends AbstractRailBlock .isEmpty() ? CartAssemblerAction.ASSEMBLE_ACCELERATE : CartAssemblerAction.DISASSEMBLE; if (type == CartAssembleRailType.CONTROLLER_RAIL || type == CartAssembleRailType.CONTROLLER_RAIL_BACKWARDS) - return powered ? CartAssemblerAction.ASSEMBLE_ACCELERATE_DIRECTIONAL : CartAssemblerAction.DISASSEMBLE_BRAKE; + return powered ? CartAssemblerAction.ASSEMBLE_ACCELERATE_DIRECTIONAL + : CartAssemblerAction.DISASSEMBLE_BRAKE; return CartAssemblerAction.PASS; } @@ -241,10 +256,9 @@ public class CartAssemblerBlock extends AbstractRailBlock .isCoupledThroughContraption()) return; - Optional assembler = getTileEntityOptional(world, pos); CartMovementMode mode = assembler.map(te -> CartMovementMode.values()[te.movementMode.value]) - .orElse(CartMovementMode.ROTATE); + .orElse(CartMovementMode.ROTATE); MountedContraption contraption = new MountedContraption(mode); try { @@ -485,15 +499,22 @@ public class CartAssemblerBlock extends AbstractRailBlock if (world.isRemote) return ActionResultType.SUCCESS; BlockPos pos = context.getPos(); - BlockState newState = state.with(RAIL_SHAPE, state.get(RAIL_SHAPE) == RailShape.NORTH_SOUTH ? RailShape.EAST_WEST : RailShape.NORTH_SOUTH); - if (state.get(RAIL_TYPE) == CartAssembleRailType.CONTROLLER_RAIL || state.get(RAIL_TYPE) == CartAssembleRailType.CONTROLLER_RAIL_BACKWARDS) { - newState = newState.with(RAIL_TYPE, AllBlocks.CONTROLLER_RAIL.get().rotate(AllBlocks.CONTROLLER_RAIL.getDefaultState() - .with(ControllerRailBlock.SHAPE, state.get(RAIL_SHAPE)).with(ControllerRailBlock.BACKWARDS, - state.get(RAIL_TYPE) == CartAssembleRailType.CONTROLLER_RAIL_BACKWARDS), Rotation.CLOCKWISE_90) - .get(ControllerRailBlock.BACKWARDS) ? CartAssembleRailType.CONTROLLER_RAIL_BACKWARDS : CartAssembleRailType.CONTROLLER_RAIL); + BlockState newState = state.with(RAIL_SHAPE, + state.get(RAIL_SHAPE) == RailShape.NORTH_SOUTH ? RailShape.EAST_WEST : RailShape.NORTH_SOUTH); + if (state.get(RAIL_TYPE) == CartAssembleRailType.CONTROLLER_RAIL + || state.get(RAIL_TYPE) == CartAssembleRailType.CONTROLLER_RAIL_BACKWARDS) { + newState = newState.with(RAIL_TYPE, AllBlocks.CONTROLLER_RAIL.get() + .rotate(AllBlocks.CONTROLLER_RAIL.getDefaultState() + .with(ControllerRailBlock.SHAPE, state.get(RAIL_SHAPE)) + .with(ControllerRailBlock.BACKWARDS, + state.get(RAIL_TYPE) == CartAssembleRailType.CONTROLLER_RAIL_BACKWARDS), + Rotation.CLOCKWISE_90) + .get(ControllerRailBlock.BACKWARDS) ? CartAssembleRailType.CONTROLLER_RAIL_BACKWARDS + : CartAssembleRailType.CONTROLLER_RAIL); } - context.getWorld().setBlockState(pos, newState, 3); - world.notifyNeighborsOfStateChange(pos.down(), this); + context.getWorld() + .setBlockState(pos, newState, 3); + world.notifyNeighborsOfStateChange(pos.down(), this); return ActionResultType.SUCCESS; } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MinecartContraptionItem.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MinecartContraptionItem.java index 6c38f9c41..75058a61a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MinecartContraptionItem.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MinecartContraptionItem.java @@ -169,7 +169,9 @@ public class MinecartContraptionItem extends Item { Contraption mountedContraption = Contraption.fromNBT(world, contraptionTag, false); OrientedContraptionEntity contraptionEntity = - OrientedContraptionEntity.create(world, mountedContraption, intialOrientation); + newFacing == null ? OrientedContraptionEntity.create(world, mountedContraption, intialOrientation) + : OrientedContraptionEntity.createAtYaw(world, mountedContraption, intialOrientation, + newFacing.getHorizontalAngle()); contraptionEntity.startRiding(cart); contraptionEntity.setPosition(cart.getX(), cart.getY(), cart.getZ()); @@ -209,7 +211,8 @@ public class MinecartContraptionItem extends Item { OrientedContraptionEntity contraption = (OrientedContraptionEntity) passengers.get(0); if (!event.getWorld().isRemote) { - player.inventory.placeItemBackInInventory(event.getWorld(), create(type, contraption).setDisplayName(entity.getCustomName())); + player.inventory.placeItemBackInInventory(event.getWorld(), + create(type, contraption).setDisplayName(entity.getCustomName())); contraption.remove(); entity.remove(); } diff --git a/src/main/resources/assets/create/models/block/belt/diagonal_end.json b/src/main/resources/assets/create/models/block/belt/diagonal_end.json index 5a73025f5..02bd2d2d7 100644 --- a/src/main/resources/assets/create/models/block/belt/diagonal_end.json +++ b/src/main/resources/assets/create/models/block/belt/diagonal_end.json @@ -10,6 +10,7 @@ "name": "Bottom", "from": [0.9, 3, 1], "to": [15.1, 5, 6.8], + "rotation": {"angle": 0, "axis": "y", "origin": [0, 0, 0]}, "faces": { "north": {"uv": [1, 6, 15, 7], "rotation": 180, "texture": "#0"}, "east": {"uv": [14, 0, 16, 6], "rotation": 270, "texture": "#0"}, @@ -22,6 +23,7 @@ "name": "Bottom", "from": [2.9, 5, 2], "to": [13.1, 6, 6.8], + "rotation": {"angle": 0, "axis": "y", "origin": [0, 0, 0]}, "faces": { "east": {"uv": [3, 0, 4, 5], "rotation": 270, "texture": "#0"}, "west": {"uv": [12, 0, 13, 5], "rotation": 90, "texture": "#0"}, @@ -32,8 +34,9 @@ "name": "Top", "from": [0.9, 11, 1], "to": [15.1, 13, 10.1], + "rotation": {"angle": 0, "axis": "y", "origin": [0, 0, 0]}, "faces": { - "north": {"uv": [1, 6, 15, 5], "rotation": 180, "texture": "#0"}, + "north": {"uv": [1, 5, 15, 6], "rotation": 180, "texture": "#0"}, "east": {"uv": [14, 6, 16, 15], "rotation": 90, "texture": "#0"}, "west": {"uv": [0, 6, 2, 15], "rotation": 270, "texture": "#0"}, "up": {"uv": [1, 6, 15, 15], "texture": "#0"}, @@ -44,6 +47,7 @@ "name": "Top", "from": [2.9, 10, 2], "to": [13.1, 11, 10.1], + "rotation": {"angle": 0, "axis": "y", "origin": [0, 0, 0]}, "faces": { "east": {"uv": [3, 7, 4, 15], "rotation": 90, "texture": "#0"}, "west": {"uv": [12, 7, 13, 15], "rotation": 270, "texture": "#0"}, @@ -54,19 +58,21 @@ "name": "Side", "from": [1, 4, 0], "to": [15, 12, 2], + "rotation": {"angle": 0, "axis": "y", "origin": [0, 0, 0]}, "faces": { "north": {"uv": [1, 8, 15, 16], "rotation": 180, "texture": "#0"}, "east": {"uv": [14, 8, 16, 16], "rotation": 180, "texture": "#0"}, "south": {"uv": [1, 8, 15, 16], "rotation": 180, "texture": "#0"}, "west": {"uv": [0, 8, 2, 16], "rotation": 180, "texture": "#0"}, - "up": {"uv": [1, 4, 15, 5], "rotation": 180, "texture": "#0"}, - "down": {"uv": [1, 7, 15, 8], "rotation": 180, "texture": "#0"} + "up": {"uv": [1, 4, 15, 5], "texture": "#0"}, + "down": {"uv": [1, 7, 15, 8], "texture": "#0"} } }, { "name": "Side", "from": [2.9, 6, 2], "to": [13.1, 10, 3], + "rotation": {"angle": 0, "axis": "y", "origin": [0, 0, 0]}, "faces": { "east": {"uv": [3, 10, 4, 14], "rotation": 180, "texture": "#0"}, "south": {"uv": [3, 10, 13, 14], "rotation": 180, "texture": "#0"}, diff --git a/src/main/resources/assets/create/models/block/belt/end.json b/src/main/resources/assets/create/models/block/belt/end.json index 142f58c71..d8f167443 100644 --- a/src/main/resources/assets/create/models/block/belt/end.json +++ b/src/main/resources/assets/create/models/block/belt/end.json @@ -9,9 +9,10 @@ "name": "Top", "from": [1, 11, 0], "to": [15, 13, 15], + "rotation": {"angle": 0, "axis": "y", "origin": [0, 0, 0]}, "faces": { "east": {"uv": [0, 1, 2, 16], "rotation": 270, "texture": "#0"}, - "south": {"uv": [1, 1, 15, 0], "texture": "#0"}, + "south": {"uv": [1, 0, 15, 1], "rotation": 180, "texture": "#0"}, "west": {"uv": [14, 1, 16, 16], "rotation": 90, "texture": "#0"}, "up": {"uv": [1, 1, 15, 16], "rotation": 180, "texture": "#0"}, "down": {"uv": [1, 1, 15, 16], "texture": "#0"} @@ -21,6 +22,7 @@ "name": "Top", "from": [3, 10, 0], "to": [13, 11, 14], + "rotation": {"angle": 0, "axis": "y", "origin": [0, 0, 0]}, "faces": { "east": {"uv": [3, 2, 4, 16], "rotation": 270, "texture": "#0"}, "west": {"uv": [12, 2, 13, 16], "rotation": 90, "texture": "#0"}, @@ -31,19 +33,21 @@ "name": "Side", "from": [1.1, 4, 14], "to": [14.9, 12, 16], + "rotation": {"angle": 0, "axis": "y", "origin": [0, 0, 0]}, "faces": { "north": {"uv": [1, 8, 15, 16], "rotation": 180, "texture": "#0"}, "east": {"uv": [0, 8, 2, 16], "rotation": 180, "texture": "#0"}, "south": {"uv": [1, 8, 15, 16], "rotation": 180, "texture": "#0"}, "west": {"uv": [14, 8, 16, 16], "rotation": 180, "texture": "#0"}, - "up": {"uv": [1, 15, 15, 16], "rotation": 180, "texture": "#0"}, - "down": {"uv": [1, 8, 15, 9], "rotation": 180, "texture": "#0"} + "up": {"uv": [1, 0, 15, 1], "rotation": 180, "texture": "#0"}, + "down": {"uv": [1, 7, 15, 8], "rotation": 180, "texture": "#0"} } }, { "name": "Side", "from": [3, 6, 13], "to": [13, 10, 14], + "rotation": {"angle": 0, "axis": "y", "origin": [0, 0, 0]}, "faces": { "north": {"uv": [3, 10, 13, 14], "rotation": 180, "texture": "#0"}, "east": {"uv": [12, 10, 13, 14], "rotation": 180, "texture": "#0"}, diff --git a/src/main/resources/assets/create/models/block/belt/start.json b/src/main/resources/assets/create/models/block/belt/start.json index 1402bc0ac..c262e4bb5 100644 --- a/src/main/resources/assets/create/models/block/belt/start.json +++ b/src/main/resources/assets/create/models/block/belt/start.json @@ -39,8 +39,8 @@ "east": {"uv": [0, 0, 2, 8], "texture": "#0"}, "south": {"uv": [1, 0, 15, 8], "texture": "#0"}, "west": {"uv": [14, 0, 16, 8], "texture": "#0"}, - "up": {"uv": [1, 0, 15, 1], "rotation": 180, "texture": "#0"}, - "down": {"uv": [1, 7, 15, 8], "rotation": 180, "texture": "#0"} + "up": {"uv": [1, 15, 15, 16], "rotation": 180, "texture": "#0"}, + "down": {"uv": [1, 8, 15, 9], "rotation": 180, "texture": "#0"} } }, { diff --git a/src/main/resources/assets/create/models/block/belt/start_bottom.json b/src/main/resources/assets/create/models/block/belt/start_bottom.json index cecb17d1d..bacf34a55 100644 --- a/src/main/resources/assets/create/models/block/belt/start_bottom.json +++ b/src/main/resources/assets/create/models/block/belt/start_bottom.json @@ -9,8 +9,9 @@ "name": "Bottom", "from": [1, 3, 1], "to": [15, 5, 16], + "rotation": {"angle": 0, "axis": "y", "origin": [0, 0, 0]}, "faces": { - "north": {"uv": [1, 0, 15, 1], "rotation": 180, "texture": "#1"}, + "north": {"uv": [1, 0, 15, 1], "texture": "#1"}, "east": {"uv": [0, 1, 2, 16], "rotation": 90, "texture": "#1"}, "west": {"uv": [14, 1, 16, 16], "rotation": 270, "texture": "#1"}, "up": {"uv": [1, 1, 15, 16], "texture": "#1"}, @@ -21,6 +22,7 @@ "name": "Bottom", "from": [3, 5, 2], "to": [13, 6, 16], + "rotation": {"angle": 0, "axis": "y", "origin": [0, 0, 0]}, "faces": { "east": {"uv": [12, 2, 13, 16], "rotation": 90, "texture": "#1"}, "west": {"uv": [3, 2, 4, 16], "rotation": 270, "texture": "#1"},