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);
}
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();
}
}
Aggregations