Search in sources :

Example 1 with PacketReturnRfInRange

use of mcjty.rftools.network.PacketReturnRfInRange in project RFTools by McJty.

the class RFToolsTools method returnRfInRange.

public static void returnRfInRange(EntityPlayer player) {
    BlockPos pos = player.getPosition();
    World world = player.getEntityWorld();
    Map<BlockPos, MachineInfo> result = new HashMap<>();
    int range = 12;
    for (int x = -range; x <= range; x++) {
        for (int y = -range; y <= range; y++) {
            for (int z = -range; z <= range; z++) {
                BlockPos p = pos.add(x, y, z);
                TileEntity te = world.getTileEntity(p);
                if (EnergyTools.isEnergyTE(te)) {
                    EnergyTools.EnergyLevel level = EnergyTools.getEnergyLevel(te);
                    Integer usage = null;
                    if (te instanceof IMachineInformation) {
                        usage = ((IMachineInformation) te).getEnergyDiffPerTick();
                    }
                    result.put(p, new MachineInfo(level.getEnergy(), level.getMaxEnergy(), usage));
                }
            }
        }
    }
    RFToolsMessages.INSTANCE.sendTo(new PacketReturnRfInRange(result), (EntityPlayerMP) player);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) MachineInfo(mcjty.rftools.network.MachineInfo) IMachineInformation(mcjty.lib.api.information.IMachineInformation) PacketReturnRfInRange(mcjty.rftools.network.PacketReturnRfInRange) HashMap(java.util.HashMap) BlockPos(net.minecraft.util.math.BlockPos) EnergyTools(mcjty.lib.varia.EnergyTools) World(net.minecraft.world.World)

Aggregations

HashMap (java.util.HashMap)1 IMachineInformation (mcjty.lib.api.information.IMachineInformation)1 EnergyTools (mcjty.lib.varia.EnergyTools)1 MachineInfo (mcjty.rftools.network.MachineInfo)1 PacketReturnRfInRange (mcjty.rftools.network.PacketReturnRfInRange)1 TileEntity (net.minecraft.tileentity.TileEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1