use of powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetCable in project MineFactoryReloaded by powercrystals.
the class BlockRedNetCable method isProvidingStrongPower.
@Override
public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z, int side) {
int power = 0;
TileEntity te = world.getBlockTileEntity(x, y, z);
if (te instanceof TileEntityRedNetCable) {
TileEntityRedNetCable cable = ((TileEntityRedNetCable) te);
if (cable.getNetwork() == null || cable.getConnectionState(ForgeDirection.VALID_DIRECTIONS[side].getOpposite()) == RedNetConnectionType.None) {
return 0;
}
BlockPosition nodebp = new BlockPosition(x, y, z, ForgeDirection.getOrientation(side).getOpposite());
nodebp.moveForwards(1);
int subnet = cable.getSideColor(nodebp.orientation);
if (cable.getNetwork().isWeakNode(nodebp)) {
power = 0;
RedstoneNetwork.log("Asked for strong power at " + x + "," + y + "," + z + " - weak node, power 0");
} else {
power = Math.min(Math.max(cable.getNetwork().getPowerLevelOutput(subnet), 0), 15);
RedstoneNetwork.log("Asked for strong power at " + x + "," + y + "," + z + " - got " + power + " from network " + ((TileEntityRedNetCable) te).getNetwork().getId() + ":" + subnet);
}
}
return power;
}
use of powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetCable in project MineFactoryReloaded by powercrystals.
the class BlockRedNetCable method isProvidingWeakPower.
@Override
public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int side) {
int power = 0;
TileEntity te = world.getBlockTileEntity(x, y, z);
if (te instanceof TileEntityRedNetCable) {
TileEntityRedNetCable cable = ((TileEntityRedNetCable) te);
if (cable.getNetwork() == null || cable.getConnectionState(ForgeDirection.VALID_DIRECTIONS[side].getOpposite()) == RedNetConnectionType.None) {
return 0;
}
int subnet = ((TileEntityRedNetCable) te).getSideColor(ForgeDirection.getOrientation(side).getOpposite());
power = Math.min(Math.max(((TileEntityRedNetCable) te).getNetwork().getPowerLevelOutput(subnet), 0), 15);
RedstoneNetwork.log("Asked for weak power at " + x + "," + y + "," + z + " - got " + power + " from network " + ((TileEntityRedNetCable) te).getNetwork().getId() + ":" + subnet);
}
return power;
}
use of powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetCable in project MineFactoryReloaded by powercrystals.
the class ItemRedNetMeter method onItemUse.
@Override
public boolean onItemUse(ItemStack itemstack, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffset) {
if (world.isRemote) {
return true;
}
TileEntity te = world.getBlockTileEntity(x, y, z);
if (te instanceof TileEntityRedNetCable) {
int value;
boolean foundNonZero = false;
for (int i = 0; i < 16; i++) {
value = ((TileEntityRedNetCable) te).getNetwork().getPowerLevelOutput(i);
if (value != 0) {
player.sendChatToPlayer(_colorNames[i] + ": " + value);
foundNonZero = true;
}
}
if (!foundNonZero) {
player.sendChatToPlayer("All RedNet subnets are 0");
} else {
player.sendChatToPlayer("All other RedNet subnets are 0");
}
return true;
} else if (te instanceof TileEntityRedNetLogic) {
int value;
boolean foundNonZero = false;
for (int i = 0; i < ((TileEntityRedNetLogic) te).getBufferLength(13); i++) {
value = ((TileEntityRedNetLogic) te).getVariableValue(i);
if (value != 0) {
player.sendChatToPlayer("Variable " + i + ": " + value);
foundNonZero = true;
}
}
if (!foundNonZero) {
player.sendChatToPlayer("All variables are 0");
} else {
player.sendChatToPlayer("All other variables are 0");
}
return true;
} else if (world.getBlockId(x, y, z) == Block.redstoneWire.blockID) {
player.sendChatToPlayer("Dust: " + world.getBlockMetadata(x, y, z));
}
return false;
}
use of powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetCable in project MineFactoryReloaded by powercrystals.
the class ClientPacketHandler method onPacketData.
@SuppressWarnings("rawtypes")
@Override
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) {
DataInputStream data = new DataInputStream(new ByteArrayInputStream(packet.data));
int packetType = PacketWrapper.readPacketID(data);
if (// server -> client; server propagating machine rotation; args X Y Z rotation isActive
packetType == Packets.TileDescription) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class, Boolean.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityFactory) {
TileEntityFactory tef = (TileEntityFactory) te;
tef.rotateDirectlyTo((Integer) packetReadout[3]);
tef.setIsActive((Boolean) packetReadout[4]);
}
} else if (// server -> client; server propagating conveyor color, activity state
packetType == Packets.ConveyorDescription) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class, Boolean.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityConveyor) {
TileEntityConveyor tec = (TileEntityConveyor) te;
tec.setDyeColor((Integer) packetReadout[3]);
tec.setConveyorActive((Boolean) packetReadout[4]);
}
} else if (// server -> client; server playing a record
packetType == Packets.AutoJukeboxPlay) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityAutoJukebox) {
Minecraft.getMinecraft().ingameGUI.setRecordPlayingMessage(((ItemRecord) Item.itemsList[(Integer) packetReadout[3]]).recordName);
}
} else if (// server -> client; road block light changed
packetType == Packets.RoadBlockUpdate) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
((EntityPlayer) player).worldObj.setBlock((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2], MineFactoryReloadedCore.factoryRoadBlock.blockID, (Integer) packetReadout[3], 6);
((EntityPlayer) player).worldObj.markBlockForRenderUpdate((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
} else if (// server -> client; cable side colors
packetType == Packets.CableDescription) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Byte.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityRedNetCable) {
TileEntityRedNetCable tec = (TileEntityRedNetCable) te;
tec.setSideColor(ForgeDirection.DOWN, (Integer) packetReadout[3]);
tec.setSideColor(ForgeDirection.UP, (Integer) packetReadout[4]);
tec.setSideColor(ForgeDirection.NORTH, (Integer) packetReadout[5]);
tec.setSideColor(ForgeDirection.SOUTH, (Integer) packetReadout[6]);
tec.setSideColor(ForgeDirection.WEST, (Integer) packetReadout[7]);
tec.setSideColor(ForgeDirection.EAST, (Integer) packetReadout[8]);
tec.setMode((Byte) packetReadout[9]);
}
} else if (// server -> client: logic circuit (class and pins)
packetType == Packets.LogicCircuitDefinition) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityRedNetLogic) {
((TileEntityRedNetLogic) te).setCircuitFromPacket(data);
}
} else if (packetType == Packets.HistorianValueChanged) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityRedNetHistorian) {
((TileEntityRedNetHistorian) te).setClientValue((Integer) packetReadout[3]);
}
}
}
use of powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetCable in project MineFactoryReloaded by powercrystals.
the class BlockRedNetCable method breakBlock.
@Override
public void breakBlock(World world, int x, int y, int z, int id, int meta) {
TileEntity te = world.getBlockTileEntity(x, y, z);
if (te instanceof TileEntityRedNetCable && ((TileEntityRedNetCable) te).getNetwork() != null) {
((TileEntityRedNetCable) te).getNetwork().setInvalid();
}
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
BlockPosition bp = new BlockPosition(x, y, z);
bp.orientation = d;
bp.moveForwards(1);
world.notifyBlockOfNeighborChange(bp.x, bp.y, bp.z, MineFactoryReloadedCore.rednetCableBlock.blockID);
world.notifyBlocksOfNeighborChange(bp.x, bp.y, bp.z, MineFactoryReloadedCore.rednetCableBlock.blockID);
}
super.breakBlock(world, x, y, z, id, meta);
}
Aggregations