use of buildcraft.api.transport.pluggable.PipePluggable in project BuildCraft by BuildCraft.
the class Pipe method updateConnections.
private void updateConnections() {
if (holder.getPipeWorld().isRemote) {
return;
}
updateMarked = false;
EnumMap<EnumFacing, Float> old = connected.clone();
connected.clear();
types.clear();
textures.clear();
for (EnumFacing facing : EnumFacing.VALUES) {
PipePluggable plug = getHolder().getPluggable(facing);
if (plug != null && plug.isBlocking()) {
continue;
}
TileEntity oTile = getHolder().getNeighbourTile(facing);
if (oTile == null) {
continue;
}
IPipe oPipe = getHolder().getNeighbourPipe(facing);
if (oPipe != null) {
PipeBehaviour oBehaviour = oPipe.getBehaviour();
if (oBehaviour == null) {
continue;
}
PipePluggable oPlug = oTile.getCapability(PipeApi.CAP_PLUG, facing.getOpposite());
if (oPlug == null || !oPlug.isBlocking()) {
if (canPipesConnect(facing, this, oPipe)) {
connected.put(facing, DEFAULT_CONNECTION_DISTANCE);
types.put(facing, ConnectedType.PIPE);
textures.put(facing, behaviour.getTextureIndex(facing));
}
continue;
}
}
BlockPos nPos = holder.getPipePos().offset(facing);
IBlockState neighbour = holder.getPipeWorld().getBlockState(nPos);
ICustomPipeConnection cust = PipeConnectionAPI.getCustomConnection(neighbour.getBlock());
if (cust == null) {
cust = DefaultPipeConnection.INSTANCE;
}
float ext = DEFAULT_CONNECTION_DISTANCE + cust.getExtension(holder.getPipeWorld(), nPos, facing.getOpposite(), neighbour);
if (behaviour.canConnect(facing, oTile) & flow.canConnect(facing, oTile)) {
connected.put(facing, ext);
types.put(facing, ConnectedType.TILE);
textures.put(facing, behaviour.getTextureIndex(facing));
}
}
if (!old.equals(connected)) {
for (EnumFacing face : EnumFacing.VALUES) {
boolean o = old.containsKey(face);
boolean n = connected.containsKey(face);
if (o != n) {
IPipe oPipe = getHolder().getNeighbourPipe(face);
if (oPipe != null) {
oPipe.markForUpdate();
}
}
}
}
getHolder().scheduleNetworkUpdate(PipeMessageReceiver.BEHAVIOUR);
}
use of buildcraft.api.transport.pluggable.PipePluggable in project BuildCraft by BuildCraft.
the class PipePluggableState method readData.
@Override
public void readData(ByteBuf data) {
this.pluggableMatrix.readData(data);
for (EnumFacing dir : EnumFacing.VALUES) {
if (this.pluggableMatrix.isConnected(dir)) {
PipePluggable old = pluggables[dir.ordinal()];
try {
Class<? extends PipePluggable> pc = PipeManager.pipePluggables.get(data.readUnsignedShort());
if (pluggables[dir.ordinal()] == null || pc != pluggables[dir.ordinal()].getClass()) {
PipePluggable p = pc.newInstance();
pluggables[dir.ordinal()] = p;
}
} catch (Exception e) {
e.printStackTrace();
}
if (pluggables[dir.ordinal()] != null) {
pluggables[dir.ordinal()].readData(data);
}
} else {
pluggables[dir.ordinal()] = null;
}
}
}
use of buildcraft.api.transport.pluggable.PipePluggable in project BuildCraft by BuildCraft.
the class TileGenericPipe method refreshRenderState.
/**
* PRECONDITION: worldObj must not be null
*
* @return <code>True</code> if any part of the render state changed
*/
protected boolean refreshRenderState() {
renderState.setGlassColor((byte) glassColor);
// Pipe connections;
for (EnumFacing o : EnumFacing.VALUES) {
renderState.pipeConnectionMatrix.setConnected(o, this.pipeConnectionsBuffer[o.ordinal()]);
if (pipeConnectionsBuffer[o.ordinal()]) {
BlockPos connected = getPos().offset(o);
IBlockState state = worldObj.getBlockState(connected);
Block block = state.getBlock();
ICustomPipeConnection connection = PipeConnectionAPI.getCustomConnection(block);
if (connection == null) {
connection = DefaultPipeConnection.INSTANCE;
}
renderState.setExtension(o, connection.getExtension(worldObj, connected, o, state));
}
}
// Pipe Textures
renderState.textureMatrix.setIconIndex(null, pipe.getIconIndex(null));
for (EnumFacing o : EnumFacing.values()) {
renderState.textureMatrix.setIconIndex(o, pipe.getIconIndex(o));
}
// WireState
for (PipeWire color : PipeWire.values()) {
renderState.wireMatrix.setWire(color, pipe.wireSet[color.ordinal()]);
for (EnumFacing direction : EnumFacing.VALUES) {
renderState.wireMatrix.setWireConnected(color, direction, pipe.isWireConnectedTo(this.getTile(direction), color, direction));
}
boolean lit = pipe.signalStrength[color.ordinal()] > 0;
renderState.wireMatrix.setWireLit(color, lit);
}
// Facades
for (EnumFacing direction : EnumFacing.VALUES) {
PipePluggable pluggable = sideProperties.pluggables[direction.ordinal()];
if (!(pluggable instanceof FacadePluggable)) {
continue;
}
FacadeState[] states = ((FacadePluggable) pluggable).states;
// Iterate over all states and activate first proper
int defaultState = -1;
int activeState = -1;
for (int i = 0; i < states.length; i++) {
FacadeState state = states[i];
if (state.wire == null) {
defaultState = i;
continue;
}
if (pipe != null && pipe.isWireActive(state.wire)) {
activeState = i;
break;
}
}
if (activeState < 0) {
activeState = defaultState;
}
((FacadePluggable) pluggable).setActiveState(activeState);
}
pluggableState.setPluggables(sideProperties.pluggables);
boolean isDirty = renderState.isDirty() || pluggableState.isDirty();
if (isDirty) {
sendNetworkUpdate();
renderState.clean();
}
return isDirty;
}
use of buildcraft.api.transport.pluggable.PipePluggable in project BuildCraft by BuildCraft.
the class BlockGenericPipe method addOrStripPipePluggable.
private boolean addOrStripPipePluggable(World world, BlockPos pos, ItemStack stack, EntityPlayer player, EnumFacing side, Pipe<?> pipe) {
RaytraceResult rayTraceResult = doRayTrace(world, pos, player);
EnumFacing placementSide = rayTraceResult != null && rayTraceResult.sideHit != null ? rayTraceResult.sideHit : side;
IPipePluggableItem pluggableItem = (IPipePluggableItem) stack.getItem();
PipePluggable pluggable = pluggableItem.createPipePluggable(pipe, placementSide, stack);
if (pluggable == null) {
return false;
}
if (player.isSneaking()) {
if (pipe.container.hasPipePluggable(side) && rayTraceResult != null && rayTraceResult.hitPart == Part.Pluggable && pluggable.getClass().isInstance(pipe.container.getPipePluggable(side))) {
return pipe.container.setPluggable(side, null, player);
}
}
if (rayTraceResult != null && rayTraceResult.hitPart == Part.Pipe) {
if (!pipe.container.hasPipePluggable(placementSide)) {
if (pipe.container.setPluggable(placementSide, pluggable, player)) {
if (!player.capabilities.isCreativeMode) {
stack.stackSize--;
}
world.playSoundEffect(pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, "dig.stone", 1.0f, 0.8f);
return true;
} else {
return false;
}
}
}
return false;
}
use of buildcraft.api.transport.pluggable.PipePluggable in project BuildCraft by BuildCraft.
the class ItemGateCopier method onItemUse.
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
if (world.isRemote) {
return true;
}
boolean isCopying = !player.isSneaking();
Block block = world.getBlockState(pos).getBlock();
TileEntity tile = world.getTileEntity(pos);
NBTTagCompound data = NBTUtilBC.getItemData(stack);
PipePluggable pluggable = null;
Gate gate = null;
if (tile == null || !(tile instanceof IPipeTile)) {
isCopying = true;
} else {
if (tile instanceof TileGenericPipe && block instanceof BlockGenericPipe) {
RaytraceResult rayTraceResult = ((BlockGenericPipe) block).doRayTrace(world, pos, player);
if (rayTraceResult != null && rayTraceResult.boundingBox != null && rayTraceResult.hitPart == Part.Pluggable) {
pluggable = ((TileGenericPipe) tile).getPipePluggable(rayTraceResult.sideHit);
}
} else {
pluggable = ((IPipeTile) tile).getPipePluggable(side);
}
}
if (pluggable instanceof GatePluggable) {
gate = ((GatePluggable) pluggable).realGate;
}
if (isCopying) {
if (gate == null) {
data = new NBTTagCompound();
stack.setTagCompound(data);
// Tell ItemModelMesher that this is NOT damageable, so it will use the meta for the icon
data.setBoolean("Unbreakable", true);
// Tell ItemStack.getToolTip() that we want to hide the resulting "Unbreakable" line that we just added
data.setInteger("HideFlags", 4);
player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.clear"));
return true;
}
data = new NBTTagCompound();
stack.setTagCompound(data);
gate.writeStatementsToNBT(data);
data.setByte("material", (byte) gate.material.ordinal());
data.setByte("logic", (byte) gate.logic.ordinal());
player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.gateCopied"));
// Tell ItemModelMesher that this is NOT damageable, so it will use the meta for the icon
data.setBoolean("Unbreakable", true);
// Tell ItemStack.getToolTip() that we want to hide the resulting "Unbreakable" line that we just added
data.setInteger("HideFlags", 4);
} else {
if (!data.hasKey("logic")) {
player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.noInformation"));
return true;
} else if (gate == null) {
player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.noGate"));
return true;
}
GateMaterial dataMaterial = GateMaterial.fromOrdinal(data.getByte("material"));
GateMaterial gateMaterial = gate.material;
if (gateMaterial.numSlots < dataMaterial.numSlots) {
player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.warning.slots"));
}
if (gateMaterial.numActionParameters < dataMaterial.numActionParameters) {
player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.warning.actionParameters"));
}
if (gateMaterial.numTriggerParameters < dataMaterial.numTriggerParameters) {
player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.warning.triggerParameters"));
}
if (data.getByte("logic") != gate.logic.ordinal()) {
player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.warning.logic"));
}
gate.readStatementsFromNBT(data);
if (!gate.verifyGateStatements()) {
player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.warning.load"));
}
if (tile instanceof TileGenericPipe) {
((TileGenericPipe) tile).sendNetworkUpdate();
}
player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.gatePasted"));
return true;
}
return true;
}
Aggregations