private boolean linkTo(TileMarker marker, int n) { if (marker == null) { return false; } if (origin.isSet() && marker.origin.isSet()) { return false; } if (!origin.isSet() && !marker.origin.isSet()) { origin = new Origin(); marker.origin = origin; origin.vectO = new TileWrapper(xCoord, yCoord, zCoord); origin.vect[n] = new TileWrapper(marker.xCoord, marker.yCoord, marker.zCoord); } else if (!origin.isSet()) { origin = marker.origin; origin.vect[n] = new TileWrapper(xCoord, yCoord, zCoord); } else { marker.origin = origin; origin.vect[n] = new TileWrapper(marker.xCoord, marker.yCoord, marker.zCoord); } origin.vectO.getMarker(worldObj).createLasers(); updateSignals(); marker.updateSignals(); return true; }
private void switchSignals() { if (signals != null) { for (EntityBlock b : signals) { if (b != null) { CoreProxy.proxy.removeEntity(b); } } signals = null; } if (showSignals) { signals = new EntityBlock[6]; if (!origin.isSet() || !origin.vect[0].isSet()) { signals[0] = Utils.createLaser( worldObj, new Position(xCoord, yCoord, zCoord), new Position(xCoord + maxSize - 1, yCoord, zCoord), LaserKind.Blue); signals[1] = Utils.createLaser( worldObj, new Position(xCoord - maxSize + 1, yCoord, zCoord), new Position(xCoord, yCoord, zCoord), LaserKind.Blue); } if (!origin.isSet() || !origin.vect[1].isSet()) { signals[2] = Utils.createLaser( worldObj, new Position(xCoord, yCoord, zCoord), new Position(xCoord, yCoord + maxSize - 1, zCoord), LaserKind.Blue); signals[3] = Utils.createLaser( worldObj, new Position(xCoord, yCoord - maxSize + 1, zCoord), new Position(xCoord, yCoord, zCoord), LaserKind.Blue); } if (!origin.isSet() || !origin.vect[2].isSet()) { signals[4] = Utils.createLaser( worldObj, new Position(xCoord, yCoord, zCoord), new Position(xCoord, yCoord, zCoord + maxSize - 1), LaserKind.Blue); signals[5] = Utils.createLaser( worldObj, new Position(xCoord, yCoord, zCoord - maxSize + 1), new Position(xCoord, yCoord, zCoord), LaserKind.Blue); } } }
@Override public int zMax() { if (origin.isSet()) { return origin.zMax; } return zCoord; }
@Override public int yMax() { if (origin.isSet()) { return origin.yMax; } return yCoord; }
@Override public int xMax() { if (origin.isSet()) { return origin.xMax; } return xCoord; }
public void tryConnection() { if (worldObj.isRemote) { return; } for (int j = 0; j < 3; ++j) { if (!origin.isSet() || !origin.vect[j].isSet()) { setVect(j); } } sendNetworkUpdate(); }
@Override public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); if (origin.isSet() && origin.vectO.getMarker(worldObj) == this) { NBTTagCompound vectO = new NBTTagCompound(); new Position(origin.vectO.getMarker(worldObj)).writeToNBT(vectO); nbttagcompound.setTag("vectO", vectO); for (int i = 0; i < 3; ++i) { if (origin.vect[i].isSet()) { NBTTagCompound vect = new NBTTagCompound(); new Position(origin.vect[i].x, origin.vect[i].y, origin.vect[i].z).writeToNBT(vect); nbttagcompound.setTag("vect" + i, vect); } } } }
@Override public void removeFromWorld() { if (!origin.isSet()) { return; } Origin o = origin; for (TileWrapper m : o.vect.clone()) { if (m.isSet()) { worldObj.setBlockToAir(m.x, m.y, m.z); BuildCraftBuilders.markerBlock.dropBlockAsItem(worldObj, m.x, m.y, m.z, 0, 0); } } worldObj.setBlockToAir(o.vectO.x, o.vectO.y, o.vectO.z); BuildCraftBuilders.markerBlock.dropBlockAsItem(worldObj, o.vectO.x, o.vectO.y, o.vectO.z, 0, 0); }
void setVect(int n) { int[] coords = new int[3]; coords[0] = xCoord; coords[1] = yCoord; coords[2] = zCoord; if (!origin.isSet() || !origin.vect[n].isSet()) { for (int j = 1; j < maxSize; ++j) { coords[n] += j; Block block = worldObj.getBlock(coords[0], coords[1], coords[2]); if (block == BuildCraftBuilders.markerBlock) { TileMarker marker = (TileMarker) worldObj.getTileEntity(coords[0], coords[1], coords[2]); if (linkTo(marker, n)) { break; } } coords[n] -= j; coords[n] -= j; block = worldObj.getBlock(coords[0], coords[1], coords[2]); if (block == BuildCraftBuilders.markerBlock) { TileMarker marker = (TileMarker) worldObj.getTileEntity(coords[0], coords[1], coords[2]); if (linkTo(marker, n)) { break; } } coords[n] += j; } } }
@Override public void destroy() { TileMarker markerOrigin = null; if (origin.isSet()) { markerOrigin = origin.vectO.getMarker(worldObj); Origin o = origin; if (markerOrigin != null && markerOrigin.lasers != null) { for (EntityBlock entity : markerOrigin.lasers) { if (entity != null) { entity.setDead(); } } markerOrigin.lasers = null; } for (TileWrapper m : o.vect) { TileMarker mark = m.getMarker(worldObj); if (mark != null) { if (mark.lasers != null) { for (EntityBlock entity : mark.lasers) { if (entity != null) { entity.setDead(); } } mark.lasers = null; } if (mark != this) { mark.origin = new Origin(); } } } if (markerOrigin != this && markerOrigin != null) { markerOrigin.origin = new Origin(); } for (TileWrapper wrapper : o.vect) { TileMarker mark = wrapper.getMarker(worldObj); if (mark != null) { mark.updateSignals(); } } if (markerOrigin != null) { markerOrigin.updateSignals(); } } if (signals != null) { for (EntityBlock block : signals) { if (block != null) { block.setDead(); } } } signals = null; if (!worldObj.isRemote && markerOrigin != null && markerOrigin != this) { markerOrigin.sendNetworkUpdate(); } }