Fix piston hitbox is directional (#453, #489)

This commit is contained in:
Snownee 2020-12-09 20:04:57 +08:00
parent e62bbfd9c0
commit 169856858c
2 changed files with 13 additions and 5 deletions

View File

@ -1,5 +1,6 @@
package com.simibubi.create.content.contraptions.components.structureMovement; package com.simibubi.create.content.contraptions.components.structureMovement;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -16,7 +17,7 @@ public abstract class TranslatingContraption extends Contraption {
public Set<BlockPos> getColliders(World world, Direction movementDirection) { public Set<BlockPos> getColliders(World world, Direction movementDirection) {
if (getBlocks() == null) if (getBlocks() == null)
return null; return Collections.EMPTY_SET;
if (cachedColliders == null || cachedColliderDirection != movementDirection) { if (cachedColliders == null || cachedColliderDirection != movementDirection) {
cachedColliders = new HashSet<>(); cachedColliders = new HashSet<>();
cachedColliderDirection = movementDirection; cachedColliderDirection = movementDirection;

View File

@ -53,9 +53,14 @@ public class PistonContraption extends TranslatingContraption {
public boolean assemble(World world, BlockPos pos) { public boolean assemble(World world, BlockPos pos) {
if (!collectExtensions(world, pos, orientation)) if (!collectExtensions(world, pos, orientation))
return false; return false;
int count = blocks.size();
if (!searchMovedStructure(world, anchor, retract ? orientation.getOpposite() : orientation)) if (!searchMovedStructure(world, anchor, retract ? orientation.getOpposite() : orientation))
return false; return false;
if (blocks.size() == count) { // no new blocks added
bounds = pistonExtensionCollisionBox;
} else {
bounds = bounds.union(pistonExtensionCollisionBox); bounds = bounds.union(pistonExtensionCollisionBox);
}
startMoving(world); startMoving(world);
return true; return true;
} }
@ -112,8 +117,10 @@ public class PistonContraption extends TranslatingContraption {
anchor = pos.offset(direction, initialExtensionProgress + 1); anchor = pos.offset(direction, initialExtensionProgress + 1);
extensionLength = extensionsInBack + extensionsInFront; extensionLength = extensionsInBack + extensionsInFront;
initialExtensionProgress = extensionsInFront; initialExtensionProgress = extensionsInFront;
pistonExtensionCollisionBox = new AxisAlignedBB(end.offset(direction, -extensionsInFront) pistonExtensionCollisionBox = new AxisAlignedBB(
.subtract(anchor)); BlockPos.ZERO.offset(direction, -1),
BlockPos.ZERO.offset(direction, -extensionLength - 1)).expand(1,
1, 1);
if (extensionLength == 0) if (extensionLength == 0)
return false; return false;
@ -124,7 +131,7 @@ public class PistonContraption extends TranslatingContraption {
BlockPos relPos = pole.pos.offset(direction, -extensionsInFront); BlockPos relPos = pole.pos.offset(direction, -extensionsInFront);
BlockPos localPos = relPos.subtract(anchor); BlockPos localPos = relPos.subtract(anchor);
getBlocks().put(localPos, new BlockInfo(localPos, pole.state, null)); getBlocks().put(localPos, new BlockInfo(localPos, pole.state, null));
pistonExtensionCollisionBox = pistonExtensionCollisionBox.union(new AxisAlignedBB(localPos)); //pistonExtensionCollisionBox = pistonExtensionCollisionBox.union(new AxisAlignedBB(localPos));
} }
return true; return true;