From bea5d783ce231a879358033d34dace414ea1e955 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Sat, 7 Mar 2020 19:08:16 +0100 Subject: [PATCH] Contraption Bug-Fixes - Fixed the generated rendering bounding box of rotating contraptions - Fixed clockwork bearings moving their hands inconsistently in some cases - Pistons, Pulleys and Bearings can now be kick-started with a right click - Contacts no longer apply a pulse to the contact they were powering before movement - Fixed deployers animating strangely when the contaption is stalled - Fixed minecart contraptions not having the same orientation on server and client - Fixed minecart contraptions not reacting to movement when the minecart is itself mounting another entity - Fixed minecart contraptions not remembering their motion when unloaded while stalling - Fixed minecart contraptions not being initialized with the correct angles --- .../components/contraptions/Contraption.java | 46 +++++++++--- .../contraptions/ContraptionEntity.java | 72 +++++++++++-------- .../bearing/BearingContraption.java | 4 +- .../bearing/ClockworkBearingBlock.java | 37 ++++++++-- .../bearing/ClockworkBearingTileEntity.java | 42 +++++++---- .../bearing/ClockworkContraption.java | 5 +- .../bearing/MechanicalBearingBlock.java | 25 +++++++ .../bearing/MechanicalBearingTileEntity.java | 1 + .../mounted/CartAssemblerBlock.java | 22 +++++- .../mounted/MountedContraption.java | 1 + .../piston/LinearActuatorTileEntity.java | 2 +- .../piston/MechanicalPistonBlock.java | 21 ++++-- .../piston/PistonContraption.java | 6 +- .../contraptions/pulley/PulleyBlock.java | 20 +++++- .../deployer/DeployerMovementBehaviour.java | 1 - .../deployer/DeployerTileEntityRenderer.java | 15 ++-- .../redstone/ContactMovementBehaviour.java | 2 + 17 files changed, 243 insertions(+), 79 deletions(-) diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/Contraption.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/Contraption.java index b648861b6..8225304ad 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/Contraption.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/Contraption.java @@ -19,6 +19,7 @@ import org.apache.commons.lang3.tuple.Pair; import com.simibubi.create.AllBlocks; import com.simibubi.create.config.AllConfigs; import com.simibubi.create.foundation.utility.NBTHelper; +import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.modules.contraptions.base.KineticTileEntity; import com.simibubi.create.modules.contraptions.components.contraptions.chassis.AbstractChassisBlock; import com.simibubi.create.modules.contraptions.components.contraptions.chassis.ChassisTileEntity; @@ -34,6 +35,8 @@ import net.minecraft.nbt.NBTUtil; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.Direction; +import net.minecraft.util.Direction.Axis; +import net.minecraft.util.Direction.AxisDirection; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; @@ -50,7 +53,7 @@ public abstract class Contraption { public List> actors; public CombinedInvWrapper inventory; - public AxisAlignedBB constructCollisionBox; + public AxisAlignedBB bounds; public boolean stalled; protected Set cachedColliders; @@ -95,8 +98,8 @@ public abstract class Contraption { Set visited = new HashSet<>(); anchor = pos; - if (constructCollisionBox == null) - constructCollisionBox = new AxisAlignedBB(BlockPos.ZERO); + if (bounds == null) + bounds = new AxisAlignedBB(BlockPos.ZERO); frontier.add(pos); if (!addToInitialFrontier(world, pos, forcedDirection, frontier)) @@ -203,7 +206,7 @@ public abstract class Contraption { if (blocks.put(localPos, blockInfo) != null) return; - constructCollisionBox = constructCollisionBox.union(new AxisAlignedBB(localPos)); + bounds = bounds.union(new AxisAlignedBB(localPos)); TileEntity te = pair.getValue(); if (te != null && MountedStorage.canUseAsStorage(te)) @@ -257,7 +260,7 @@ public abstract class Contraption { inventory = new CombinedInvWrapper(Arrays.copyOf(list.toArray(), list.size(), IItemHandlerModifiable[].class)); if (nbt.contains("BoundsFront")) - constructCollisionBox = NBTHelper.readAABB(nbt.getList("BoundsFront", 5)); + bounds = NBTHelper.readAABB(nbt.getList("BoundsFront", 5)); stalled = nbt.getBoolean("Stalled"); anchor = NBTUtil.readBlockPos(nbt.getCompound("Anchor")); @@ -302,8 +305,8 @@ public abstract class Contraption { nbt.put("Anchor", NBTUtil.writeBlockPos(anchor)); nbt.putBoolean("Stalled", stalled); - if (constructCollisionBox != null) { - ListNBT bb = NBTHelper.writeAABB(constructCollisionBox); + if (bounds != null) { + ListNBT bb = NBTHelper.writeAABB(bounds); nbt.put("BoundsFront", bb); } @@ -359,7 +362,7 @@ public abstract class Contraption { block.nbt.putInt("y", targetPos.getY()); block.nbt.putInt("z", targetPos.getZ()); tileEntity.read(block.nbt); - + if (tileEntity instanceof KineticTileEntity) { KineticTileEntity kineticTileEntity = (KineticTileEntity) tileEntity; kineticTileEntity.source = null; @@ -367,7 +370,7 @@ public abstract class Contraption { kineticTileEntity.network = null; kineticTileEntity.attachKinetics(); } - + if (storage.containsKey(block.pos)) { MountedStorage mountedStorage = storage.get(block.pos); if (mountedStorage.isWorking()) @@ -387,8 +390,8 @@ public abstract class Contraption { } } - public AxisAlignedBB getCollisionBox() { - return constructCollisionBox; + public AxisAlignedBB getBoundingBox() { + return bounds; } public List> getActors() { @@ -421,6 +424,27 @@ public abstract class Contraption { return ((IPortableBlock) block).getMovementBehaviour(); } + public void expandBoundsAroundAxis(Axis axis) { + AxisAlignedBB bb = bounds; + double maxXDiff = Math.max(bb.maxX - 1, -bb.minX); + double maxYDiff = Math.max(bb.maxY - 1, -bb.minY); + double maxZDiff = Math.max(bb.maxZ - 1, -bb.minZ); + double maxDiff = 0; + + if (axis == Axis.X) + maxDiff = Math.max(maxZDiff, maxYDiff); + if (axis == Axis.Y) + maxDiff = Math.max(maxZDiff, maxXDiff); + if (axis == Axis.Z) + maxDiff = Math.max(maxXDiff, maxYDiff); + + Vec3d vec = new Vec3d(Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis).getDirectionVec()); + Vec3d planeByNormal = VecHelper.planeByNormal(vec); + Vec3d min = vec.mul(bb.minX, bb.minY, bb.minZ).add(planeByNormal.scale(-maxDiff)); + Vec3d max = vec.mul(bb.maxX, bb.maxY, bb.maxZ).add(planeByNormal.scale(maxDiff + 1)); + bounds = new AxisAlignedBB(min, max); + } + protected abstract AllContraptionTypes getType(); } \ No newline at end of file diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/ContraptionEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/ContraptionEntity.java index ecd6e7087..f3030097b 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/ContraptionEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/ContraptionEntity.java @@ -12,6 +12,7 @@ import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; +import net.minecraft.entity.item.BoatEntity; import net.minecraft.entity.item.minecart.AbstractMinecartEntity; import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.ListNBT; @@ -43,8 +44,8 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD protected Vec3d motionBeforeStall; protected boolean stationary; - private static final DataParameter STALLED = EntityDataManager.createKey(ContraptionEntity.class, - DataSerializers.BOOLEAN); + private static final DataParameter STALLED = + EntityDataManager.createKey(ContraptionEntity.class, DataSerializers.BOOLEAN); public float prevYaw; public float prevPitch; @@ -101,39 +102,41 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD Entity e = getRidingEntity(); if (e != null) { - Vec3d movementVector = e.getMotion(); + Entity riding = e; + while (riding.getRidingEntity() != null) + riding = riding.getRidingEntity(); + Vec3d movementVector = riding.getMotion(); + if (riding instanceof BoatEntity) + movementVector = new Vec3d(posX - prevPosX, posY - prevPosY, posZ - prevPosZ); Vec3d motion = movementVector.normalize(); if (motion.length() > 0) { targetYaw = yawFromVector(motion); - targetPitch = (float) ((Math.atan(motion.y) * 73.0D) / Math.PI * 180); if (targetYaw < 0) targetYaw += 360; if (yaw < 0) yaw += 360; } - if (Math.abs(getShortestAngleDiff(yaw, targetYaw)) >= 175) { - initialAngle += 180; - yaw += 180; - prevYaw = yaw; - } else { - float speed = 0.2f; - prevYaw = yaw; - yaw = angleLerp(speed, yaw, targetYaw); - prevPitch = pitch; - pitch = angleLerp(speed, pitch, targetPitch); - } +// if (Math.abs(getShortestAngleDiff(yaw, targetYaw)) >= 175) { +// initialAngle += 180; +// yaw += 180; +// prevYaw = yaw; +// } else { + float speed = 0.2f; + prevYaw = yaw; + yaw = angleLerp(speed, yaw, targetYaw); +// } boolean wasStalled = isStalled(); tickActors(movementVector); if (isStalled()) { if (!wasStalled) - motionBeforeStall = e.getMotion(); - e.setMotion(0, 0, 0); + motionBeforeStall = riding.getMotion(); + riding.setMotion(0, 0, 0); } if (wasStalled && !isStalled()) { - e.setMotion(motionBeforeStall); + riding.setMotion(motionBeforeStall); motionBeforeStall = Vec3d.ZERO; } @@ -249,8 +252,11 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD public void setPosition(double x, double y, double z) { Entity e = getRidingEntity(); if (e != null && e instanceof AbstractMinecartEntity) { - x -= .5; - z -= .5; + Entity riding = e; + while (riding.getRidingEntity() != null) + riding = riding.getRidingEntity(); + x = riding.posX - .5; + z = riding.posZ - .5; } this.posX = x; @@ -260,7 +266,7 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD if (this.isAddedToWorld() && !this.world.isRemote && world instanceof ServerWorld) ((ServerWorld) this.world).chunkCheck(this); // Forge - Process chunk registration after moving. if (contraption != null) { - AxisAlignedBB cbox = contraption.getCollisionBox(); + AxisAlignedBB cbox = contraption.getBoundingBox(); if (cbox != null) this.setBoundingBox(cbox.offset(x, y, z)); } @@ -268,9 +274,9 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD @Override public void stopRiding() { - super.stopRiding(); if (!world.isRemote) disassemble(); + super.stopRiding(); } public static float yawFromVector(Vec3d vec) { @@ -309,14 +315,17 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD protected void readAdditional(CompoundNBT compound) { contraption = Contraption.fromNBT(world, compound.getCompound("Contraption")); initialAngle = compound.getFloat("InitialAngle"); + targetYaw = yaw = prevYaw = initialAngle; + dataManager.set(STALLED, compound.getBoolean("Stalled")); ListNBT vecNBT = compound.getList("CachedMotion", 6); - if (!vecNBT.isEmpty()) + if (!vecNBT.isEmpty()) { motionBeforeStall = new Vec3d(vecNBT.getDouble(0), vecNBT.getDouble(1), vecNBT.getDouble(2)); + if (!motionBeforeStall.equals(Vec3d.ZERO)) + targetYaw = prevYaw = yaw += yawFromVector(motionBeforeStall); + setMotion(Vec3d.ZERO); + } if (compound.contains("Controller")) controllerPos = NBTUtil.readBlockPos(compound.getCompound("Controller")); - prevYaw = initialAngle; - yaw = initialAngle; - targetYaw = initialAngle; } public void attachToController() { @@ -341,7 +350,10 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD protected void writeAdditional(CompoundNBT compound) { compound.put("Contraption", getContraption().writeNBT()); compound.putFloat("InitialAngle", initialAngle); - compound.put("CachedMotion", newDoubleNBTList(motionBeforeStall.x, motionBeforeStall.y, motionBeforeStall.z)); + if (!stationary) + compound.put("CachedMotion", + newDoubleNBTList(motionBeforeStall.x, motionBeforeStall.y, motionBeforeStall.z)); + compound.putBoolean("Stalled", isStalled()); if (controllerPos != null) compound.put("Controller", NBTUtil.writeBlockPos(controllerPos)); } @@ -364,9 +376,11 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD } public void disassemble() { - if (getContraption() != null) + if (getContraption() != null) { + float yaw = getYaw(1); getContraption().disassemble(world, new BlockPos(getPositionVec().add(.5, .5, .5)), - new Vec3d(getRoll(1), getYaw(1), getPitch(1))); + new Vec3d(getRoll(1), yaw, getPitch(1))); + } remove(); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/BearingContraption.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/BearingContraption.java index 1563729a8..43e138edf 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/BearingContraption.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/BearingContraption.java @@ -28,9 +28,11 @@ public class BearingContraption extends Contraption { return null; BearingContraption construct = new BearingContraption(); construct.facing = direction; - if (!construct.searchMovedStructure(world, pos.offset(direction), null)) + BlockPos offset = pos.offset(direction); + if (!construct.searchMovedStructure(world, offset, null)) return null; construct.initActors(world); + construct.expandBoundsAroundAxis(direction.getAxis()); return construct; } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/ClockworkBearingBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/ClockworkBearingBlock.java index fa4694369..5a2cd7f73 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/ClockworkBearingBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/ClockworkBearingBlock.java @@ -1,14 +1,43 @@ package com.simibubi.create.modules.contraptions.components.contraptions.bearing; -import net.minecraft.block.BlockState; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.IBlockReader; +import com.simibubi.create.foundation.block.IWithTileEntity; -public class ClockworkBearingBlock extends BearingBlock { +import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.Hand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; +import net.minecraft.world.IBlockReader; +import net.minecraft.world.World; + +public class ClockworkBearingBlock extends BearingBlock implements IWithTileEntity { @Override public TileEntity createTileEntity(BlockState state, IBlockReader world) { return new ClockworkBearingTileEntity(); } + @Override + public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, + BlockRayTraceResult hit) { + if (!player.isAllowEdit()) + return false; + if (player.isSneaking()) + return false; + if (player.getHeldItem(handIn).isEmpty()) { + if (!worldIn.isRemote) { + withTileEntityDo(worldIn, pos, te -> { + if (te.running) { + te.disassembleConstruct(); + return; + } + te.assembleNextTick = true; + }); + } + return true; + } + return false; + } + } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/ClockworkBearingTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/ClockworkBearingTileEntity.java index 618675dd3..b41a55464 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/ClockworkBearingTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/ClockworkBearingTileEntity.java @@ -104,31 +104,41 @@ public class ClockworkBearingTileEntity extends KineticTileEntity implements IBe } public float getHourArmSpeed() { - float speed = getAngularSpeed() / 2f + clientHourAngleDiff / 3f; - + float speed = getAngularSpeed() / 2f; + if (speed != 0) { int dayTime = (int) (world.getDayTime() % 24000); int hours = (dayTime / 1000 + 6) % 24; int offset = getBlockState().get(ClockworkBearingBlock.FACING).getAxisDirection().getOffset(); float hourTarget = (float) (offset * -360 / 12f * (hours % 12)); - speed = Math.max(speed, AngleHelper.getShortestAngleDiff(hourAngle, hourTarget)); + float shortestAngleDiff = AngleHelper.getShortestAngleDiff(hourAngle, hourTarget); + if (shortestAngleDiff < 0) { + speed = Math.max(speed, shortestAngleDiff); + } else { + speed = Math.min(-speed, shortestAngleDiff); + } } - - return speed; + + return speed + clientHourAngleDiff / 3f; } public float getMinuteArmSpeed() { - float speed = getAngularSpeed() + clientMinuteAngleDiff / 3f; - + float speed = getAngularSpeed(); + if (speed != 0) { int dayTime = (int) (world.getDayTime() % 24000); int minutes = (dayTime % 1000) * 60 / 1000; int offset = getBlockState().get(ClockworkBearingBlock.FACING).getAxisDirection().getOffset(); - float hourTarget = (float) (offset * -360 / 60f * (minutes)); - speed = Math.max(speed, AngleHelper.getShortestAngleDiff(minuteAngle, hourTarget)); + float minuteTarget = (float) (offset * -360 / 60f * (minutes)); + float shortestAngleDiff = AngleHelper.getShortestAngleDiff(minuteAngle, minuteTarget); + if (shortestAngleDiff < 0) { + speed = Math.max(speed, shortestAngleDiff); + } else { + speed = Math.min(-speed, shortestAngleDiff); + } } - - return speed; + + return speed + clientMinuteAngleDiff / 3f; } public float getAngularSpeed() { @@ -175,16 +185,20 @@ public class ClockworkBearingTileEntity extends KineticTileEntity implements IBe public void disassembleConstruct() { if (!running) return; - if (hourHand != null) + + hourAngle = 0; + minuteAngle = 0; + applyRotations(); + + if (hourHand != null) { hourHand.disassemble(); + } if (minuteHand != null) minuteHand.disassemble(); hourHand = null; minuteHand = null; running = false; - hourAngle = 0; - minuteAngle = 0; sendData(); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/ClockworkContraption.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/ClockworkContraption.java index 454b29ae6..25d4687ee 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/ClockworkContraption.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/ClockworkContraption.java @@ -67,8 +67,11 @@ public class ClockworkContraption extends Contraption { } hourArm.initActors(world); - if (minuteArm != null) + hourArm.expandBoundsAroundAxis(direction.getAxis()); + if (minuteArm != null) { minuteArm.initActors(world); + minuteArm.expandBoundsAroundAxis(direction.getAxis()); + } return Pair.of(hourArm, minuteArm); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/MechanicalBearingBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/MechanicalBearingBlock.java index 228290415..9cba2e4d1 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/MechanicalBearingBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/MechanicalBearingBlock.java @@ -4,8 +4,11 @@ import com.simibubi.create.foundation.block.IWithTileEntity; import net.minecraft.block.Block; import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; @@ -16,6 +19,28 @@ public class MechanicalBearingBlock extends BearingBlock implements IWithTileEnt return new MechanicalBearingTileEntity(); } + @Override + public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, + BlockRayTraceResult hit) { + if (!player.isAllowEdit()) + return false; + if (player.isSneaking()) + return false; + if (player.getHeldItem(handIn).isEmpty()) { + if (!worldIn.isRemote) { + withTileEntityDo(worldIn, pos, te -> { + if (te.running) { + te.disassembleConstruct(); + return; + } + te.assembleNextTick = true; + }); + } + return true; + } + return false; + } + @Override public void onBlockAdded(BlockState state, World worldIn, BlockPos pos, BlockState oldState, boolean isMoving) { withTileEntityDo(worldIn, pos, MechanicalBearingTileEntity::neighbourChanged); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/MechanicalBearingTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/MechanicalBearingTileEntity.java index aa40d7e57..90bbd19c2 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/MechanicalBearingTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/MechanicalBearingTileEntity.java @@ -178,6 +178,7 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity imp running = false; angle = 0; updateGeneratedRotation(); + assembleNextTick = false; sendData(); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/mounted/CartAssemblerBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/mounted/CartAssemblerBlock.java index 52e3c9e58..7a47059bd 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/mounted/CartAssemblerBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/mounted/CartAssemblerBlock.java @@ -22,6 +22,7 @@ import net.minecraft.state.properties.RailShape; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShapes; @@ -30,8 +31,8 @@ import net.minecraft.world.World; public class CartAssemblerBlock extends AbstractRailBlock { - public static IProperty RAIL_SHAPE = EnumProperty.create("shape", RailShape.class, RailShape.EAST_WEST, - RailShape.NORTH_SOUTH); + public static IProperty RAIL_SHAPE = + EnumProperty.create("shape", RailShape.class, RailShape.EAST_WEST, RailShape.NORTH_SOUTH); public static BooleanProperty POWERED = BlockStateProperties.POWERED; public CartAssemblerBlock() { @@ -62,6 +63,16 @@ public class CartAssemblerBlock extends AbstractRailBlock { public void onMinecartPass(BlockState state, World world, BlockPos pos, AbstractMinecartEntity cart) { if (!cart.canBeRidden()) return; + + Vec3d p = cart.getPositionVec(); + Vec3d m = cart.getMotion(); + Vec3d p2 = p.add(m); + Direction facing = Direction.getFacingFromVector(m.x, m.y, m.z); + Axis axis = facing.getAxis(); + double coord = axis.getCoordinate(pos.getX(), pos.getY(), pos.getZ()) + .5 + .25f * facing.getAxisDirection().getOffset(); + if ((axis.getCoordinate(p.x, p.y, p.z) > coord) == (axis.getCoordinate(p2.x, p2.y, p2.z) % 1 > coord)) + return; + if (state.get(POWERED)) disassemble(world, pos, cart); else @@ -75,6 +86,8 @@ public class CartAssemblerBlock extends AbstractRailBlock { Contraption contraption = MountedContraption.assembleMinecart(world, pos); if (contraption == null) return; + if (contraption.blocks.size() == 1) + return; float initialAngle = ContraptionEntity.yawFromVector(cart.getMotion()); ContraptionEntity entity = ContraptionEntity.createMounted(world, contraption, initialAngle); entity.setPosition(pos.getX(), pos.getY(), pos.getZ()); @@ -135,6 +148,11 @@ public class CartAssemblerBlock extends AbstractRailBlock { builder.add(BlockStateProperties.HORIZONTAL_AXIS); super.fillStateContainer(builder); } + + @Override + public boolean isSolid(BlockState state) { + return false; + } } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/mounted/MountedContraption.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/mounted/MountedContraption.java index 53730fa5b..364d01a19 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/mounted/MountedContraption.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/mounted/MountedContraption.java @@ -48,6 +48,7 @@ public class MountedContraption extends Contraption { null), null)); contraption.removeBlocksFromWorld(world, BlockPos.ZERO); contraption.initActors(world); + contraption.expandBoundsAroundAxis(Axis.Y); return contraption; } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/LinearActuatorTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/LinearActuatorTileEntity.java index 1c5a47370..5ae0e36d1 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/LinearActuatorTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/LinearActuatorTileEntity.java @@ -20,7 +20,7 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity impleme public float offset; public boolean running; - protected boolean assembleNextTick; + public boolean assembleNextTick; public ContraptionEntity movedContraption; protected boolean forceMove; protected ScrollOptionBehaviour movementMode; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/MechanicalPistonBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/MechanicalPistonBlock.java index 075b5a9c7..e22d7d932 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/MechanicalPistonBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/MechanicalPistonBlock.java @@ -3,6 +3,7 @@ package com.simibubi.create.modules.contraptions.components.contraptions.piston; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllSoundEvents; import com.simibubi.create.config.AllConfigs; +import com.simibubi.create.foundation.block.IWithTileEntity; import com.simibubi.create.foundation.utility.AllShapes; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.modules.contraptions.base.DirectionalAxisKineticBlock; @@ -32,7 +33,8 @@ import net.minecraft.world.IBlockReader; import net.minecraft.world.World; import net.minecraftforge.common.Tags; -public class MechanicalPistonBlock extends DirectionalAxisKineticBlock { +public class MechanicalPistonBlock extends DirectionalAxisKineticBlock + implements IWithTileEntity { public static final EnumProperty STATE = EnumProperty.create("state", PistonState.class); protected boolean isSticky; @@ -52,11 +54,18 @@ public class MechanicalPistonBlock extends DirectionalAxisKineticBlock { @Override public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) { - if (state.get(STATE) != PistonState.RETRACTED) - return false; if (!player.isAllowEdit()) return false; - if (!player.getHeldItem(handIn).getItem().isIn(Tags.Items.SLIMEBALLS)) + if (player.isSneaking()) + return false; + if (!player.getHeldItem(handIn).getItem().isIn(Tags.Items.SLIMEBALLS)) { + if (player.getHeldItem(handIn).isEmpty()) { + withTileEntityDo(worldIn, pos, te -> te.assembleNextTick = true); + return true; + } + return false; + } + if (state.get(STATE) != PistonState.RETRACTED) return false; Direction direction = state.get(FACING); if (hit.getFace() != direction) @@ -99,9 +108,7 @@ public class MechanicalPistonBlock extends DirectionalAxisKineticBlock { } public enum PistonState implements IStringSerializable { - RETRACTED, - MOVING, - EXTENDED; + RETRACTED, MOVING, EXTENDED; @Override public String getName() { diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/PistonContraption.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/PistonContraption.java index 5a817099f..00ea4401c 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/PistonContraption.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/PistonContraption.java @@ -110,7 +110,7 @@ public class PistonContraption extends Contraption { if (extensionLength == 0) return false; - constructCollisionBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0); + bounds = new AxisAlignedBB(0, 0, 0, 0, 0, 0); for (BlockInfo pole : poles) { BlockPos relPos = pole.pos.offset(direction, -extensionsInFront); @@ -213,7 +213,7 @@ public class PistonContraption extends Contraption { } @Override - public AxisAlignedBB getCollisionBox() { - return super.getCollisionBox().union(pistonExtensionCollisionBox); + public AxisAlignedBB getBoundingBox() { + return super.getBoundingBox().union(pistonExtensionCollisionBox); } } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/pulley/PulleyBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/pulley/PulleyBlock.java index 5dc3d9bf4..b38eb6cb3 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/pulley/PulleyBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/pulley/PulleyBlock.java @@ -2,24 +2,28 @@ package com.simibubi.create.modules.contraptions.components.contraptions.pulley; import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.block.IHaveNoBlockItem; +import com.simibubi.create.foundation.block.IWithTileEntity; import com.simibubi.create.foundation.utility.AllShapes; import com.simibubi.create.modules.contraptions.base.HorizontalAxisKineticBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.state.EnumProperty; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; +import net.minecraft.util.Hand; import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; -public class PulleyBlock extends HorizontalAxisKineticBlock { +public class PulleyBlock extends HorizontalAxisKineticBlock implements IWithTileEntity { public static EnumProperty HORIZONTAL_AXIS = BlockStateProperties.HORIZONTAL_AXIS; @@ -37,6 +41,20 @@ public class PulleyBlock extends HorizontalAxisKineticBlock { return true; } + @Override + public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, + BlockRayTraceResult hit) { + if (!player.isAllowEdit()) + return false; + if (player.isSneaking()) + return false; + if (player.getHeldItem(handIn).isEmpty()) { + withTileEntityDo(worldIn, pos, te -> te.assembleNextTick = true); + return true; + } + return false; + } + @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { return AllShapes.PULLEY.get(state.get(HORIZONTAL_AXIS)); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerMovementBehaviour.java b/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerMovementBehaviour.java index 67ca519b1..784c7aebd 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerMovementBehaviour.java @@ -52,7 +52,6 @@ public class DeployerMovementBehaviour extends MovementBehaviour { Vec3d facingVec = new Vec3d(context.state.get(DeployerBlock.FACING).getDirectionVec()); facingVec = VecHelper.rotate(facingVec, context.rotation.x, context.rotation.y, context.rotation.z); Vec3d vec = context.position.subtract(facingVec.scale(2)); - player.rotationYaw = ContraptionEntity.yawFromVector(facingVec); player.rotationPitch = ContraptionEntity.pitchFromVector(facingVec) - 90; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerTileEntityRenderer.java index 69804f4fd..d5ad8eeef 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerTileEntityRenderer.java @@ -167,11 +167,18 @@ public class DeployerTileEntityRenderer extends SafeTileEntityRenderer