Search in sources :

Example 1 with IMachineInformation

use of mcjty.lib.api.information.IMachineInformation 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)

Example 2 with IMachineInformation

use of mcjty.lib.api.information.IMachineInformation in project RFTools by McJty.

the class RenderWorldLastEventHandler method renderPower.

private static void renderPower(RenderWorldLastEvent evt) {
    EntityPlayerSP player = Minecraft.getMinecraft().player;
    ItemStack mainItem = player.getHeldItemMainhand();
    ItemStack offItem = player.getHeldItemOffhand();
    if ((!mainItem.isEmpty() && mainItem.getItem() instanceof NetworkMonitorItem) || (!offItem.isEmpty() && offItem.getItem() instanceof NetworkMonitorItem)) {
        double doubleX = player.lastTickPosX + (player.posX - player.lastTickPosX) * evt.getPartialTicks();
        double doubleY = player.lastTickPosY + (player.posY - player.lastTickPosY) * evt.getPartialTicks();
        double doubleZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * evt.getPartialTicks();
        GlStateManager.pushMatrix();
        GlStateManager.translate(-doubleX, -doubleY, -doubleZ);
        GlStateManager.disableDepth();
        GlStateManager.enableTexture2D();
        if (System.currentTimeMillis() - lastTime > 500) {
            lastTime = System.currentTimeMillis();
            RFToolsMessages.sendToServer(CommandHandler.CMD_GET_RF_IN_RANGE);
        }
        if (PacketReturnRfInRange.clientLevels == null) {
            return;
        }
        for (Map.Entry<BlockPos, MachineInfo> entry : PacketReturnRfInRange.clientLevels.entrySet()) {
            BlockPos pos = entry.getKey();
            List<String> log = new ArrayList<>();
            MachineInfo info = entry.getValue();
            log.add(TextFormatting.BLUE + "RF:  " + TextFormatting.WHITE + info.getEnergy());
            log.add(TextFormatting.BLUE + "Max: " + TextFormatting.WHITE + info.getMaxEnergy());
            if (info.getEnergyPerTick() != null) {
                TileEntity te = player.getEntityWorld().getTileEntity(pos);
                String unit = "";
                if (te instanceof IMachineInformation) {
                    unit = ((IMachineInformation) te).getEnergyUnitName();
                    if (unit == null) {
                        unit = "";
                    }
                }
                int usage = info.getEnergyPerTick();
                if (usage < 0) {
                    log.add(TextFormatting.RED + "" + usage + unit + "/t");
                } else if (usage > 0) {
                    log.add(TextFormatting.GREEN + "" + usage + unit + "/t");
                }
            }
            HudRenderHelper.renderHud(log, HudRenderHelper.HudPlacement.HUD_CENTER, HudRenderHelper.HudOrientation.HUD_TOPLAYER, null, pos.getX(), pos.getY(), pos.getZ(), 2.0f);
            renderBoxOutline(pos);
        }
        GlStateManager.enableDepth();
        GlStateManager.popMatrix();
    }
}
Also used : NetworkMonitorItem(mcjty.rftools.items.netmonitor.NetworkMonitorItem) BlockProtectorTileEntity(mcjty.rftools.blocks.blockprotector.BlockProtectorTileEntity) BuilderTileEntity(mcjty.rftools.blocks.builder.BuilderTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) MachineInfo(mcjty.rftools.network.MachineInfo) IMachineInformation(mcjty.lib.api.information.IMachineInformation) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IMachineInformation (mcjty.lib.api.information.IMachineInformation)2 MachineInfo (mcjty.rftools.network.MachineInfo)2 TileEntity (net.minecraft.tileentity.TileEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 HashMap (java.util.HashMap)1 EnergyTools (mcjty.lib.varia.EnergyTools)1 BlockProtectorTileEntity (mcjty.rftools.blocks.blockprotector.BlockProtectorTileEntity)1 BuilderTileEntity (mcjty.rftools.blocks.builder.BuilderTileEntity)1 NetworkMonitorItem (mcjty.rftools.items.netmonitor.NetworkMonitorItem)1 PacketReturnRfInRange (mcjty.rftools.network.PacketReturnRfInRange)1 EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)1 ItemStack (net.minecraft.item.ItemStack)1 World (net.minecraft.world.World)1