Search in sources :

Example 6 with TileEntityRedNetCable

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockPosition(powercrystals.core.position.BlockPosition) TileEntityRedNetCable(powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetCable)

Example 7 with TileEntityRedNetCable

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityRedNetCable(powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetCable)

Example 8 with TileEntityRedNetCable

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityRedNetCable(powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetCable) TileEntityRedNetLogic(powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetLogic)

Example 9 with TileEntityRedNetCable

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]);
        }
    }
}
Also used : TileEntityFactory(powercrystals.minefactoryreloaded.tile.base.TileEntityFactory) TileEntityRedNetCable(powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetCable) DataInputStream(java.io.DataInputStream) TileEntityRedNetLogic(powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetLogic) TileEntity(net.minecraft.tileentity.TileEntity) ByteArrayInputStream(java.io.ByteArrayInputStream) TileEntityConveyor(powercrystals.minefactoryreloaded.tile.conveyor.TileEntityConveyor) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TileEntityAutoJukebox(powercrystals.minefactoryreloaded.tile.machine.TileEntityAutoJukebox) TileEntityRedNetHistorian(powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetHistorian)

Example 10 with TileEntityRedNetCable

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);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockPosition(powercrystals.core.position.BlockPosition) TileEntityRedNetCable(powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetCable) ForgeDirection(net.minecraftforge.common.ForgeDirection)

Aggregations

TileEntityRedNetCable (powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetCable)10 TileEntity (net.minecraft.tileentity.TileEntity)9 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)2 BlockPosition (powercrystals.core.position.BlockPosition)2 TileEntityRedNetLogic (powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetLogic)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 ForgeDirection (net.minecraftforge.common.ForgeDirection)1 PlayerInteractEvent (net.minecraftforge.event.entity.player.PlayerInteractEvent)1 TileEntityFactory (powercrystals.minefactoryreloaded.tile.base.TileEntityFactory)1 TileEntityConveyor (powercrystals.minefactoryreloaded.tile.conveyor.TileEntityConveyor)1 TileEntityAutoJukebox (powercrystals.minefactoryreloaded.tile.machine.TileEntityAutoJukebox)1 TileEntityRedNetHistorian (powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetHistorian)1