From 467544ebfe545cfa573720d888bf1bb8f5e193b2 Mon Sep 17 00:00:00 2001 From: ProfessorProspector Date: Wed, 7 Dec 2016 22:09:13 -0800 Subject: [PATCH] Much improve the StackInfoHUD and move it to RC --- .../java/techreborn/client/hud/ChargeHud.java | 138 ------------------ .../items/ItemFrequencyTransmitter.java | 74 +++++++--- .../java/techreborn/proxies/ClientProxy.java | 58 ++++---- 3 files changed, 85 insertions(+), 185 deletions(-) delete mode 100644 src/main/java/techreborn/client/hud/ChargeHud.java diff --git a/src/main/java/techreborn/client/hud/ChargeHud.java b/src/main/java/techreborn/client/hud/ChargeHud.java deleted file mode 100644 index b89a62144..000000000 --- a/src/main/java/techreborn/client/hud/ChargeHud.java +++ /dev/null @@ -1,138 +0,0 @@ -package techreborn.client.hud; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.renderer.RenderItem; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.EntityEquipmentSlot; -import net.minecraft.item.ItemStack; -import net.minecraftforge.client.event.RenderGameOverlayEvent; -import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; -import net.minecraftforge.fml.common.eventhandler.EventPriority; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; -import org.lwjgl.opengl.GL11; -import reborncore.api.power.IEnergyInterfaceItem; -import reborncore.common.powerSystem.PowerSystem; -import reborncore.common.util.Color; -import techreborn.client.keybindings.KeyBindings; -import techreborn.config.ConfigTechReborn; - -public class ChargeHud { - public static final ChargeHud instance = new ChargeHud(); - public static KeyBindings key; - public static boolean showHud = true; - private static Minecraft mc = Minecraft.getMinecraft(); - - @SideOnly(Side.CLIENT) - @SubscribeEvent(priority = EventPriority.LOW) - public void onRenderExperienceBar(RenderGameOverlayEvent event) { - if (key.config.isPressed()) { - showHud = !showHud; - } - - if (event.isCancelable() || event.getType() != ElementType.ALL) - return; - - if (mc.inGameHasFocus || (mc.currentScreen != null && mc.gameSettings.showDebugInfo)) { - if (ConfigTechReborn.ShowChargeHud) - drawChargeHud(event.getResolution()); - } - } - - public void drawChargeHud(ScaledResolution res) { - EntityPlayer player = mc.player; - ItemStack armorstack = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST); - ItemStack offHandstack = player.getItemStackFromSlot(EntityEquipmentSlot.OFFHAND); - ItemStack stack = mc.player.inventory.getCurrentItem(); - - int y = 5; - - if (armorstack != ItemStack.EMPTY && ConfigTechReborn.ShowChargeHud - && armorstack.getItem() instanceof IEnergyInterfaceItem) { - double MaxCharge = ((IEnergyInterfaceItem) armorstack.getItem()).getMaxPower(armorstack); - double CurrentCharge = ((IEnergyInterfaceItem) armorstack.getItem()).getEnergy(armorstack); - Color color = Color.GREEN; - double quarter = MaxCharge / 4; - double half = MaxCharge / 2; - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - GL11.glEnable(32826); - RenderHelper.enableStandardItemLighting(); - RenderHelper.enableGUIStandardItemLighting(); - // Render the stack - renderItemStack(armorstack, 0, y - 5); - // Get the color depending on current charge - if (CurrentCharge <= half) { - color = Color.YELLOW; - } - if (CurrentCharge <= quarter) { - color = Color.DARK_RED; - } - mc.fontRendererObj.drawString(color + PowerSystem.getLocaliszedPower(CurrentCharge) + "/" - + PowerSystem.getLocaliszedPower(MaxCharge), 20, y, 0); - y += 20; - } - - if (showHud) { - if (offHandstack != ItemStack.EMPTY && offHandstack.getItem() instanceof IEnergyInterfaceItem) { - double MaxCharge = ((IEnergyInterfaceItem) offHandstack.getItem()).getMaxPower(offHandstack); - double CurrentCharge = ((IEnergyInterfaceItem) offHandstack.getItem()).getEnergy(offHandstack); - if (MaxCharge != 0) { - Color color = Color.GREEN; - double quarter = MaxCharge / 4; - double half = MaxCharge / 2; - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - GL11.glEnable(32826); - RenderHelper.enableStandardItemLighting(); - RenderHelper.enableGUIStandardItemLighting(); - renderItemStack(offHandstack, 0, y - 5); - if (CurrentCharge <= half) { - color = Color.YELLOW; - } - if (CurrentCharge <= quarter) { - color = Color.DARK_RED; - } - mc.fontRendererObj.drawString(color + PowerSystem.getLocaliszedPower(CurrentCharge) + "/" - + PowerSystem.getLocaliszedPower(MaxCharge), 20, y, 0); - y += 20; - } - } - if (stack != ItemStack.EMPTY && stack.getItem() instanceof IEnergyInterfaceItem) { - double MaxCharge = ((IEnergyInterfaceItem) stack.getItem()).getMaxPower(stack); - double CurrentCharge = ((IEnergyInterfaceItem) stack.getItem()).getEnergy(stack); - Color color = Color.GREEN; - double quarter = MaxCharge / 4; - double half = MaxCharge / 2; - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - GL11.glEnable(32826); - RenderHelper.enableStandardItemLighting(); - RenderHelper.enableGUIStandardItemLighting(); - renderItemStack(stack, 0, y - 5); - if (CurrentCharge <= half) { - color = Color.YELLOW; - } - if (CurrentCharge <= quarter) { - color = Color.DARK_RED; - } - mc.fontRendererObj.drawString(color + PowerSystem.getLocaliszedPower(CurrentCharge) + "/" + PowerSystem.getLocaliszedPower(MaxCharge), 20, y, 0); - } - } - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - } - - public void renderItemStack(ItemStack stack, int x, int y) { - if (stack != null) { - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - RenderHelper.enableGUIStandardItemLighting(); - - RenderItem itemRenderer = Minecraft.getMinecraft().getRenderItem(); - itemRenderer.renderItemAndEffectIntoGUI(stack, x, y); - - GL11.glDisable(GL11.GL_LIGHTING); - } - } - -} diff --git a/src/main/java/techreborn/items/ItemFrequencyTransmitter.java b/src/main/java/techreborn/items/ItemFrequencyTransmitter.java index 6a07371a8..343a97368 100644 --- a/src/main/java/techreborn/items/ItemFrequencyTransmitter.java +++ b/src/main/java/techreborn/items/ItemFrequencyTransmitter.java @@ -15,9 +15,13 @@ import net.minecraft.util.text.translation.I18n; import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; import reborncore.RebornCore; +import reborncore.client.hud.StackInfoElement; +import reborncore.client.hud.StackInfoHUD; import reborncore.common.util.ChatUtils; +import reborncore.common.util.Color; import techreborn.client.TechRebornCreativeTabMisc; import techreborn.config.ConfigTechReborn; +import techreborn.init.ModItems; import techreborn.lib.MessageIDs; import java.util.List; @@ -29,31 +33,42 @@ public class ItemFrequencyTransmitter extends ItemTextureBase implements ITextur setCreativeTab(TechRebornCreativeTabMisc.instance); setMaxStackSize(1); RebornCore.jsonDestroyer.registerObject(this); + StackInfoHUD.registerElement(new StackInfoFreqTransmitter()); } @Override public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { ItemStack stack = player.getHeldItem(hand); - stack.setTagCompound(new NBTTagCompound()); - stack.getTagCompound().setInteger("x", pos.getX()); - stack.getTagCompound().setInteger("y", pos.getY()); - stack.getTagCompound().setInteger("z", pos.getZ()); - stack.getTagCompound().setInteger("dim", world.provider.getDimension()); + if (player.isSneaking()) { + stack.setTagCompound(null); + if (!world.isRemote && ConfigTechReborn.FreqTransmitterChat) { + ChatUtils.sendNoSpamMessages(MessageIDs.freqTransmitterID, new TextComponentString( + TextFormatting.GRAY + I18n.translateToLocal("techreborn.message.coordsHaveBeen") + " " + + TextFormatting.GOLD + I18n.translateToLocal("techreborn.message.cleared"))); + } + return EnumActionResult.PASS; + } else { + stack.setTagCompound(new NBTTagCompound()); + stack.getTagCompound().setInteger("x", pos.getX()); + stack.getTagCompound().setInteger("y", pos.getY()); + stack.getTagCompound().setInteger("z", pos.getZ()); + stack.getTagCompound().setInteger("dim", world.provider.getDimension()); - if (!world.isRemote && ConfigTechReborn.FreqTransmitterChat) { - ChatUtils.sendNoSpamMessages(MessageIDs.freqTransmitterID, new TextComponentString( - TextFormatting.GRAY + I18n.translateToLocal("techreborn.message.setTo") + " X: " + - TextFormatting.GOLD + pos.getX() + - TextFormatting.GRAY + " Y: " + - TextFormatting.GOLD + pos.getY() + - TextFormatting.GRAY + " Z: " + - TextFormatting.GOLD + pos.getZ() + - TextFormatting.GRAY + " " + I18n.translateToLocal("techreborn.message.in") + " " + - TextFormatting.GOLD + DimensionManager.getProviderType(world.provider.getDimension()) - .getName() + " (" + world.provider.getDimension() + ")")); + if (!world.isRemote && ConfigTechReborn.FreqTransmitterChat) { + ChatUtils.sendNoSpamMessages(MessageIDs.freqTransmitterID, new TextComponentString( + TextFormatting.GRAY + I18n.translateToLocal("techreborn.message.setTo") + " X: " + + TextFormatting.GOLD + pos.getX() + + TextFormatting.GRAY + " Y: " + + TextFormatting.GOLD + pos.getY() + + TextFormatting.GRAY + " Z: " + + TextFormatting.GOLD + pos.getZ() + + TextFormatting.GRAY + " " + I18n.translateToLocal("techreborn.message.in") + " " + + TextFormatting.GOLD + DimensionManager.getProviderType(world.provider.getDimension()) + .getName() + " (" + world.provider.getDimension() + ")")); + } + return EnumActionResult.SUCCESS; } - return EnumActionResult.SUCCESS; } @Override @@ -100,4 +115,29 @@ public class ItemFrequencyTransmitter extends ItemTextureBase implements ITextur public String getTextureName(int arg0) { return "techreborn:items/tool/frequency_transmitter"; } + + public static class StackInfoFreqTransmitter extends StackInfoElement { + public StackInfoFreqTransmitter() { + super(ModItems.frequencyTransmitter); + } + + @Override + public String getText(ItemStack stack) { + String text = ""; + Color gold = Color.GOLD; + Color grey = Color.GRAY; + if (stack.getItem() instanceof ItemFrequencyTransmitter) { + if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("x") && stack.getTagCompound().hasKey("y") && stack.getTagCompound().hasKey("z") && stack.getTagCompound().hasKey("dim")) { + int coordX = stack.getTagCompound().getInteger("x"); + int coordY = stack.getTagCompound().getInteger("y"); + int coordZ = stack.getTagCompound().getInteger("z"); + int coordDim = stack.getTagCompound().getInteger("dim"); + text = grey + "X: " + gold + coordX + grey + " Y: " + gold + coordY + grey + " Z: " + gold + coordZ + grey + " Dim: " + gold + DimensionManager.getProviderType(coordDim).getName() + " (" + coordDim + ")"; + } else { + text = grey + I18n.translateToLocal("techreborn.message.noCoordsSet"); + } + } + return text; + } + } } diff --git a/src/main/java/techreborn/proxies/ClientProxy.java b/src/main/java/techreborn/proxies/ClientProxy.java index 0bc3cac31..aab1c1fee 100644 --- a/src/main/java/techreborn/proxies/ClientProxy.java +++ b/src/main/java/techreborn/proxies/ClientProxy.java @@ -30,7 +30,6 @@ import techreborn.client.ClientMultiBlocks; import techreborn.client.IconSupplier; import techreborn.client.RegisterItemJsons; import techreborn.client.StackToolTipEvent; -import techreborn.client.hud.ChargeHud; import techreborn.client.keybindings.KeyBindings; import techreborn.client.render.ModelDynamicCell; import techreborn.client.render.entitys.RenderNukePrimed; @@ -45,6 +44,26 @@ public class ClientProxy extends CommonProxy { public static MultiblockRenderEvent multiblockRenderEvent; + public static ResourceLocation getItemLocation(Item item) { + Object o = item.getRegistryName(); + if (o == null) { + return null; + } + return (ResourceLocation) o; + } + + private static ResourceLocation registerIt(Item item, final ResourceLocation location) { + ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition() { + @Override + public ModelResourceLocation getModelLocation(ItemStack stack) { + return new ModelResourceLocation(location, "inventory"); + } + }); + ModelLoader.registerItemVariants(item, location); + + return location; + } + @Override public void preInit(FMLPreInitializationEvent event) { super.preInit(event); @@ -89,7 +108,6 @@ public class ClientProxy extends CommonProxy { public void init(FMLInitializationEvent event) { super.init(event); MinecraftForge.EVENT_BUS.register(new IconSupplier()); - MinecraftForge.EVENT_BUS.register(new ChargeHud()); //MinecraftForge.EVENT_BUS.register(new VersionCheckerClient()); MinecraftForge.EVENT_BUS.register(new StackToolTipEvent()); multiblockRenderEvent = new MultiblockRenderEvent(); @@ -118,34 +136,6 @@ public class ClientProxy extends CommonProxy { return registerIt(item, itemLocation); } - public static ResourceLocation getItemLocation(Item item) { - Object o = item.getRegistryName(); - if (o == null) { - return null; - } - return (ResourceLocation) o; - } - - private static ResourceLocation registerIt(Item item, final ResourceLocation location) { - ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition() { - @Override - public ModelResourceLocation getModelLocation(ItemStack stack) { - return new ModelResourceLocation(location, "inventory"); - } - }); - ModelLoader.registerItemVariants(item, location); - - return location; - } - - public class RenderManagerNuke implements IRenderFactory { - - @Override - public Render createRenderFor(RenderManager manager) { - return new RenderNukePrimed(manager); - } - } - @Override public void registerFluidBlockRendering(Block block, String name) { name = name.toLowerCase(); @@ -202,4 +192,12 @@ public class ClientProxy extends CommonProxy { return isChiselAround; } + public class RenderManagerNuke implements IRenderFactory { + + @Override + public Render createRenderFor(RenderManager manager) { + return new RenderNukePrimed(manager); + } + } + }