use of micdoodle8.mods.galacticraft.core.tile.TileEntityScreen in project Galacticraft by micdoodle8.
the class TileEntityScreen method checkScreenSize.
public void checkScreenSize() {
this.log("Checking screen size");
int up = 0;
int down = 0;
int left = 0;
int right = 0;
int meta = this.getBlockMetadata() & 7;
BlockVec3 vec = new BlockVec3(this);
TileEntityScreen tile = this;
while (up < 8) {
if (tile.connectedUp) {
up++;
TileEntity newTile = vec.getTileEntityOnSide(this.worldObj, 1);
if (newTile instanceof TileEntityScreen) {
tile = (TileEntityScreen) newTile;
vec.translate(0, 1, 0);
} else {
System.out.println("Debug - connected up to a non-screen tile");
// tile.connectedUp = false;
this.setConnectedUp(false);
tile.markDirty();
up--;
break;
}
} else {
break;
}
}
vec = new BlockVec3(this);
tile = this;
while (down < 8 - up) {
if (tile.connectedDown) {
down++;
TileEntity newTile = vec.getTileEntityOnSide(this.worldObj, 0);
if (newTile instanceof TileEntityScreen) {
tile = (TileEntityScreen) newTile;
vec.translate(0, -1, 0);
} else {
System.out.println("Debug - connected down to a non-screen tile");
// tile.connectedDown = false;
this.setConnectedDown(false);
tile.markDirty();
down--;
break;
}
} else {
break;
}
}
vec = new BlockVec3(this);
tile = this;
int leftside = this.getLeft(meta);
while (left < ((up + down == 0) ? 1 : 8)) {
if (tile.connectedLeft) {
left++;
TileEntity newTile = vec.getTileEntityOnSide(this.worldObj, leftside);
if (newTile instanceof TileEntityScreen) {
tile = (TileEntityScreen) newTile;
vec = vec.newVecSide(leftside);
} else {
System.out.println("Debug - connected left to a non-screen tile");
// tile.connectedLeft = false;
this.setConnectedLeft(false);
tile.markDirty();
left--;
break;
}
} else {
break;
}
}
vec = new BlockVec3(this);
tile = this;
int rightside = this.getRight(meta);
while (right < ((up + down == 0) ? 1 : 8) - left) {
if (tile.connectedRight) {
right++;
TileEntity newTile = vec.getTileEntityOnSide(this.worldObj, rightside);
if (newTile instanceof TileEntityScreen) {
tile = (TileEntityScreen) newTile;
vec = vec.newVecSide(rightside);
} else {
System.out.println("Debug - connected right to a non-screen tile");
// tile.connectedRight = false;
this.setConnectedRight(false);
tile.markDirty();
right--;
break;
}
} else {
break;
}
}
this.log("Screen size check midpoint " + up + " " + down + " " + left + " " + right + " ");
vec = new BlockVec3(this);
TileEntity newtile = vec.getTileEntityOnSide(this.worldObj, 1);
TileEntityScreen tileUp = (newtile instanceof TileEntityScreen) ? (TileEntityScreen) newtile : null;
newtile = vec.getTileEntityOnSide(this.worldObj, 0);
TileEntityScreen tileDown = (newtile instanceof TileEntityScreen) ? (TileEntityScreen) newtile : null;
newtile = vec.getTileEntityOnSide(this.worldObj, leftside);
TileEntityScreen tileLeft = (newtile instanceof TileEntityScreen) ? (TileEntityScreen) newtile : null;
newtile = vec.getTileEntityOnSide(this.worldObj, rightside);
TileEntityScreen tileRight = (newtile instanceof TileEntityScreen) ? (TileEntityScreen) newtile : null;
// Prevent 3 x 1 and longer
if (left + right == 0 && up + down >= 1) {
if (// No need for null check if up > 0
up > 0 && !tileUp.connectedUp) {
up = 1;
down = 0;
} else {
up = 0;
if (tileDown != null && !tileDown.connectedDown) {
down = 1;
} else {
down = 0;
}
}
}
if (up + down == 0 && left + right >= 1) {
if (// No need for null check if right > 0
left > 0 && !tileLeft.connectedLeft) {
if (right == 0 || tileRight == null || tileRight.connectionsLeft == 0) {
left = 1;
right = 0;
} else {
left = 0;
right = 1;
}
} else {
left = 0;
if (tileRight != null && !tileRight.connectedRight) {
right = 1;
} else {
right = 0;
}
}
}
if (up == 0) {
this.setConnectedUp(false);
if (tileUp != null) {
tileUp.setConnectedDown(false);
}
// this.connectedUp = false;
// if (tileUp != null) tileUp.connectedDown = false;
}
if (down == 0) {
this.setConnectedDown(false);
if (tileUp != null) {
tileUp.setConnectedUp(false);
}
// this.connectedDown = false;
// if (tileDown != null) tileDown.connectedUp = false;
}
if (left == 0) {
this.setConnectedLeft(false);
if (tileUp != null) {
tileUp.setConnectedRight(false);
}
// this.connectedLeft = false;
// if (tileLeft != null) tileLeft.connectedRight = false;
}
if (right == 0) {
this.setConnectedRight(false);
if (tileUp != null) {
tileUp.setConnectedLeft(false);
}
// this.connectedRight = false;
// if (tileRight != null) tileRight.connectedLeft = false;
}
this.log("Finished screen size check");
this.checkWholeScreen(up, down, left, right);
}
use of micdoodle8.mods.galacticraft.core.tile.TileEntityScreen in project Galacticraft by micdoodle8.
the class TileEntityScreen method joinRight.
private void joinRight() {
int meta = this.getBlockMetadata();
int side = this.getRight(meta);
BlockVec3 vec = new BlockVec3(this);
for (int z = -this.connectionsUp; z <= this.connectionsDown; z++) {
TileEntity tile;
BlockVec3 newVec = vec.clone().modifyPositionFromSide(EnumFacing.DOWN, z);
if (z == 0) {
tile = this;
} else {
tile = newVec.getTileEntity(this.worldObj);
}
if (tile instanceof TileEntityScreen && tile.getBlockMetadata() == meta && !tile.isInvalid()) {
TileEntityScreen screenTile = (TileEntityScreen) tile;
// screenTile.connectedRight = true;
screenTile.setConnectedRight(true);
TileEntity te2 = newVec.getTileEntityOnSide(this.worldObj, side);
if (te2 instanceof TileEntityScreen && te2.getBlockMetadata() == meta && !te2.isInvalid()) {
screenTile.tryConnectRight((TileEntityScreen) te2);
}
}
}
}
use of micdoodle8.mods.galacticraft.core.tile.TileEntityScreen in project Galacticraft by micdoodle8.
the class TileEntityScreen method refreshConnections.
/**
* Check whether the screen can sustain 'multi-screen' connections on each of its 4 sides
* (note: this can be called recursively from inside itself)
*
* @param doScreen If true, build a new multi-screen if connections are found
*/
public void refreshConnections(boolean doScreen) {
this.log("Starting connection check");
IBlockState iblockstate = this.worldObj.getBlockState(this.pos);
EnumFacing facing = iblockstate.getValue(BlockScreen.FACING);
int meta = this.getBlockMetadata() & 7;
if (meta < 2) {
// TODO System.out.println("Up/down oriented screens cannot be multiscreen");
this.resetToSingle();
return;
}
TileEntity tileUp = null;
TileEntity tileDown = null;
TileEntity tileLeft = null;
TileEntity tileRight = null;
BlockVec3 vec = new BlockVec3(this);
// First, basic check that a neighbour is there and in the same orientation
if (this.connectedUp) {
tileUp = vec.getTileEntityOnSide(this.worldObj, 1);
// this.connectedUp = tileUp instanceof TileEntityScreen && tileUp.getBlockMetadata() == meta && !tileUp.isInvalid();
this.setConnectedUp(tileUp instanceof TileEntityScreen && tileUp.getBlockMetadata() == meta && !tileUp.isInvalid());
}
if (this.connectedDown) {
tileDown = vec.getTileEntityOnSide(this.worldObj, 0);
// this.connectedDown = tileDown instanceof TileEntityScreen && tileDown.getBlockMetadata() == meta && !tileDown.isInvalid();
this.setConnectedDown(tileDown instanceof TileEntityScreen && tileDown.getBlockMetadata() == meta && !tileDown.isInvalid());
}
if (this.connectedLeft) {
int side = this.getLeft(meta);
tileLeft = vec.getTileEntityOnSide(this.worldObj, side);
// this.connectedLeft = tileLeft instanceof TileEntityScreen && tileLeft.getBlockMetadata() == meta && !tileLeft.isInvalid();
this.setConnectedLeft(tileLeft instanceof TileEntityScreen && tileLeft.getBlockMetadata() == meta && !tileLeft.isInvalid());
}
if (this.connectedRight) {
int side = this.getRight(meta);
tileRight = vec.getTileEntityOnSide(this.worldObj, side);
// this.connectedRight = tileRight instanceof TileEntityScreen && tileRight.getBlockMetadata() == meta && !tileRight.isInvalid();
this.setConnectedRight(tileRight instanceof TileEntityScreen && tileRight.getBlockMetadata() == meta && !tileRight.isInvalid());
}
// Now test whether a connection can be sustained with that other tile
if (this.connectedUp) {
// this.connectedUp = this.tryConnectUp((TileEntityScreen)tileUp);
this.setConnectedUp(this.tryConnectUp((TileEntityScreen) tileUp));
}
if (this.connectedDown) {
// this.connectedDown = this.tryConnectDown((TileEntityScreen)tileDown);
this.setConnectedDown(this.tryConnectDown((TileEntityScreen) tileDown));
}
if (this.connectedLeft) {
// this.connectedLeft = this.tryConnectLeft((TileEntityScreen)tileLeft);
this.setConnectedLeft(this.tryConnectLeft((TileEntityScreen) tileLeft));
}
if (this.connectedRight) {
// this.connectedRight = this.tryConnectRight((TileEntityScreen)tileRight);
this.setConnectedRight(this.tryConnectRight((TileEntityScreen) tileRight));
}
this.log("Ending connection check");
if (doScreen) {
this.checkScreenSize();
this.markDirty();
}
}
Aggregations