Plane Connection Refactor (#4556)
* Refactors all plane parts to use a common helper for calculating connections to adjacent planes. Also fixes problems with updating these connections on neighbor updates. * Fix conflicting GuiSync ID. * Slightly refactor PlaneConnectionHelper, and fix an issue where the bounding box was calculated incorrectly by using the wrong up-direction.
This commit is contained in:
@@ -4,16 +4,13 @@ package appeng.parts.automation;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.cells.ICellContainer;
|
||||
import appeng.api.storage.cells.ICellInventory;
|
||||
@@ -30,6 +27,7 @@ public abstract class AbstractFormationPlanePart<T extends IAEStack<T>> extends
|
||||
private boolean wasActive = false;
|
||||
private int priority = 0;
|
||||
protected boolean blocked = false;
|
||||
private final PlaneConnectionHelper connectionHelper = new PlaneConnectionHelper(this);
|
||||
|
||||
public AbstractFormationPlanePart(ItemStack is) {
|
||||
super(is);
|
||||
@@ -64,103 +62,11 @@ public abstract class AbstractFormationPlanePart<T extends IAEStack<T>> extends
|
||||
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
int minX = 1;
|
||||
int minY = 1;
|
||||
int maxX = 15;
|
||||
int maxY = 15;
|
||||
|
||||
final IPartHost host = this.getHost();
|
||||
if (host != null) {
|
||||
final TileEntity te = host.getTile();
|
||||
|
||||
final BlockPos pos = te.getPos();
|
||||
|
||||
final Direction e = bch.getWorldX();
|
||||
final Direction u = bch.getWorldY();
|
||||
|
||||
if (this.isTransitionPlane(te.getWorld().getTileEntity(pos.offset(e.getOpposite())), this.getSide())) {
|
||||
minX = 0;
|
||||
}
|
||||
|
||||
if (this.isTransitionPlane(te.getWorld().getTileEntity(pos.offset(e)), this.getSide())) {
|
||||
maxX = 16;
|
||||
}
|
||||
|
||||
if (this.isTransitionPlane(te.getWorld().getTileEntity(pos.offset(u.getOpposite())), this.getSide())) {
|
||||
minY = 0;
|
||||
}
|
||||
|
||||
if (this.isTransitionPlane(te.getWorld().getTileEntity(pos.offset(u)), this.getSide())) {
|
||||
maxY = 16;
|
||||
}
|
||||
}
|
||||
|
||||
bch.addBox(5, 5, 14, 11, 11, 15);
|
||||
bch.addBox(minX, minY, 15, maxX, maxY, 16);
|
||||
connectionHelper.getBoxes(bch);
|
||||
}
|
||||
|
||||
public PlaneConnections getConnections() {
|
||||
|
||||
final Direction facingRight, facingUp;
|
||||
AEPartLocation location = this.getSide();
|
||||
switch (location) {
|
||||
case UP:
|
||||
facingRight = Direction.EAST;
|
||||
facingUp = Direction.NORTH;
|
||||
break;
|
||||
case DOWN:
|
||||
facingRight = Direction.WEST;
|
||||
facingUp = Direction.NORTH;
|
||||
break;
|
||||
case NORTH:
|
||||
facingRight = Direction.WEST;
|
||||
facingUp = Direction.UP;
|
||||
break;
|
||||
case SOUTH:
|
||||
facingRight = Direction.EAST;
|
||||
facingUp = Direction.UP;
|
||||
break;
|
||||
case WEST:
|
||||
facingRight = Direction.SOUTH;
|
||||
facingUp = Direction.UP;
|
||||
break;
|
||||
case EAST:
|
||||
facingRight = Direction.NORTH;
|
||||
facingUp = Direction.UP;
|
||||
break;
|
||||
default:
|
||||
case INTERNAL:
|
||||
return PlaneConnections.of(false, false, false, false);
|
||||
}
|
||||
|
||||
boolean left = false, right = false, down = false, up = false;
|
||||
|
||||
final IPartHost host = this.getHost();
|
||||
if (host != null) {
|
||||
final TileEntity te = host.getTile();
|
||||
|
||||
final BlockPos pos = te.getPos();
|
||||
|
||||
if (this.isTransitionPlane(te.getWorld().getTileEntity(pos.offset(facingRight.getOpposite())),
|
||||
this.getSide())) {
|
||||
left = true;
|
||||
}
|
||||
|
||||
if (this.isTransitionPlane(te.getWorld().getTileEntity(pos.offset(facingRight)), this.getSide())) {
|
||||
right = true;
|
||||
}
|
||||
|
||||
if (this.isTransitionPlane(te.getWorld().getTileEntity(pos.offset(facingUp.getOpposite())),
|
||||
this.getSide())) {
|
||||
down = true;
|
||||
}
|
||||
|
||||
if (this.isTransitionPlane(te.getWorld().getTileEntity(pos.offset(facingUp)), this.getSide())) {
|
||||
up = true;
|
||||
}
|
||||
}
|
||||
|
||||
return PlaneConnections.of(up, right, down, left);
|
||||
return connectionHelper.getConnections();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -172,6 +78,8 @@ public abstract class AbstractFormationPlanePart<T extends IAEStack<T>> extends
|
||||
final BlockPos tePos = te.getPos().offset(side.getFacing());
|
||||
|
||||
this.blocked = !w.getBlockState(tePos).getMaterial().isReplaceable();
|
||||
} else {
|
||||
connectionHelper.updateConnections();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,14 +88,6 @@ public abstract class AbstractFormationPlanePart<T extends IAEStack<T>> extends
|
||||
return 1;
|
||||
}
|
||||
|
||||
protected boolean isTransitionPlane(final TileEntity blockTileEntity, final AEPartLocation side) {
|
||||
if (blockTileEntity instanceof IPartHost) {
|
||||
final IPart p = ((IPartHost) blockTileEntity).getPart(side);
|
||||
return p != null && this.getClass() == p.getClass();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T extractItems(final T request, final Actionable mode, final IActionSource src) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user