use of mekanism.common.item.interfaces.IItemHUDProvider in project Mekanism by mekanism.
the class RenderTickHandler method renderOverlay.
@SubscribeEvent
public void renderOverlay(RenderGameOverlayEvent.Post event) {
if (event.getType() == ElementType.HOTBAR) {
if (!minecraft.player.isSpectator() && MekanismConfig.client.enableHUD.get() && MekanismClient.renderHUD) {
int count = 0;
Map<EquipmentSlotType, List<ITextComponent>> renderStrings = new LinkedHashMap<>();
for (EquipmentSlotType slotType : EQUIPMENT_ORDER) {
ItemStack stack = minecraft.player.getItemBySlot(slotType);
if (stack.getItem() instanceof IItemHUDProvider) {
List<ITextComponent> list = new ArrayList<>();
((IItemHUDProvider) stack.getItem()).addHUDStrings(list, minecraft.player, stack, slotType);
int size = list.size();
if (size > 0) {
renderStrings.put(slotType, list);
count += size;
}
}
}
MatrixStack matrix = event.getMatrixStack();
if (count > 0) {
int start = (renderStrings.size() * 2) + (count * 9);
boolean alignLeft = MekanismConfig.client.alignHUDLeft.get();
MainWindow window = event.getWindow();
int y = window.getGuiScaledHeight();
float hudScale = MekanismConfig.client.hudScale.get();
int yScale = (int) ((1 / hudScale) * y);
matrix.pushPose();
matrix.scale(hudScale, hudScale, hudScale);
for (Map.Entry<EquipmentSlotType, List<ITextComponent>> entry : renderStrings.entrySet()) {
for (ITextComponent text : entry.getValue()) {
drawString(window, matrix, text, alignLeft, yScale - start, 0xC8C8C8);
start -= 9;
}
start -= 2;
}
matrix.popPose();
}
if (minecraft.player.getItemBySlot(EquipmentSlotType.HEAD).getItem() instanceof ItemMekaSuitArmor) {
hudRenderer.renderHUD(matrix, event.getPartialTicks());
}
}
} else if (event.getType() == ElementType.ARMOR) {
FloatingLong capacity = FloatingLong.ZERO, stored = FloatingLong.ZERO;
for (ItemStack stack : minecraft.player.inventory.armor) {
if (stack.getItem() instanceof ItemMekaSuitArmor) {
IEnergyContainer container = StorageUtils.getEnergyContainer(stack, 0);
if (container != null) {
capacity = capacity.plusEqual(container.getMaxEnergy());
stored = stored.plusEqual(container.getEnergy());
}
}
}
if (!capacity.isZero()) {
int x = event.getWindow().getGuiScaledWidth() / 2 - 91;
int y = event.getWindow().getGuiScaledHeight() - ForgeIngameGui.left_height + 2;
int length = (int) Math.round(stored.divide(capacity).doubleValue() * 79);
MatrixStack matrix = event.getMatrixStack();
GuiUtils.renderExtendedTexture(matrix, GuiBar.BAR, 2, 2, x, y, 81, 6);
minecraft.getTextureManager().bind(POWER_BAR);
AbstractGui.blit(matrix, x + 1, y + 1, length, 4, 0, 0, length, 4, 79, 4);
minecraft.getTextureManager().bind(AbstractGui.GUI_ICONS_LOCATION);
ForgeIngameGui.left_height += 8;
}
}
}
Aggregations