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
This commit is contained in:
simibubi 2021-03-09 04:24:45 +01:00
parent 62c3ae4040
commit d61b840c5c
8 changed files with 93 additions and 42 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -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"},

View File

@ -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"},

View File

@ -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"}
}
},
{

View File

@ -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"},