diff --git a/src/main/java/WayofTime/bloodmagic/BloodMagic.java b/src/main/java/WayofTime/bloodmagic/BloodMagic.java index 630607c9..1374c78c 100644 --- a/src/main/java/WayofTime/bloodmagic/BloodMagic.java +++ b/src/main/java/WayofTime/bloodmagic/BloodMagic.java @@ -29,7 +29,7 @@ import org.apache.commons.lang3.tuple.Pair; import java.io.File; import java.util.List; -@Mod(modid = BloodMagic.MODID, name = BloodMagic.NAME, version = BloodMagic.VERSION, dependencies = BloodMagic.DEPEND) +@Mod(modid = BloodMagic.MODID, name = BloodMagic.NAME, version = BloodMagic.VERSION, dependencies = BloodMagic.DEPEND, guiFactory = "WayofTime.bloodmagic.client.gui.GuiBloodMagicConfig$Factory") public class BloodMagic { public static final String MODID = "bloodmagic"; public static final String NAME = "Blood Magic: Alchemical Wizardry"; diff --git a/src/main/java/WayofTime/bloodmagic/client/Sprite.java b/src/main/java/WayofTime/bloodmagic/client/Sprite.java index 795286a0..cb92dcd1 100644 --- a/src/main/java/WayofTime/bloodmagic/client/Sprite.java +++ b/src/main/java/WayofTime/bloodmagic/client/Sprite.java @@ -1,5 +1,6 @@ package WayofTime.bloodmagic.client; +import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; @@ -42,6 +43,7 @@ public class Sprite { } public void draw(int x, int y) { + Minecraft.getMinecraft().renderEngine.bindTexture(textureLocation); float f = 0.00390625F; float f1 = 0.00390625F; Tessellator tessellator = Tessellator.getInstance(); diff --git a/src/main/java/WayofTime/bloodmagic/client/gui/GuiBloodMagicConfig.java b/src/main/java/WayofTime/bloodmagic/client/gui/GuiBloodMagicConfig.java new file mode 100644 index 00000000..a13b950c --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/client/gui/GuiBloodMagicConfig.java @@ -0,0 +1,63 @@ +package WayofTime.bloodmagic.client.gui; + +import WayofTime.bloodmagic.BloodMagic; +import WayofTime.bloodmagic.ConfigHandler; +import WayofTime.bloodmagic.client.hud.ConfigEntryEditHUD; +import com.google.common.collect.Lists; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; +import net.minecraftforge.common.config.ConfigElement; +import net.minecraftforge.fml.client.IModGuiFactory; +import net.minecraftforge.fml.client.config.DummyConfigElement; +import net.minecraftforge.fml.client.config.GuiConfig; +import net.minecraftforge.fml.client.config.IConfigElement; + +import java.util.Collections; +import java.util.List; +import java.util.Set; + +public class GuiBloodMagicConfig extends GuiConfig { + + public GuiBloodMagicConfig(GuiScreen parentScreen) { + super(parentScreen, getElements(), BloodMagic.MODID, false, false, BloodMagic.NAME); + } + + public static List getElements() { + List elements = Lists.newArrayList(); + + elements.addAll(ConfigElement.from(ConfigHandler.class).getChildElements()); + if (Minecraft.getMinecraft().world != null) + elements.add(new DummyElementEditHUD(BloodMagic.NAME, "config." + BloodMagic.MODID + ".edit_hud")); + + return elements; + } + + public static class DummyElementEditHUD extends DummyConfigElement.DummyCategoryElement { + + public DummyElementEditHUD(String name, String langKey) { + super(name, langKey, Collections.emptyList(), ConfigEntryEditHUD.class); + } + } + + public static class Factory implements IModGuiFactory { + @Override + public void initialize(Minecraft minecraftInstance) { + + } + + @Override + public boolean hasConfigGui() { + return true; + } + + @Override + public GuiScreen createConfigGui(GuiScreen parentScreen) { + return new GuiBloodMagicConfig(parentScreen); + } + + @Override + public Set runtimeGuiCategories() { + return null; + } + } +} diff --git a/src/main/java/WayofTime/bloodmagic/client/hud/ConfigEntryEditHUD.java b/src/main/java/WayofTime/bloodmagic/client/hud/ConfigEntryEditHUD.java new file mode 100644 index 00000000..d713e3b6 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/client/hud/ConfigEntryEditHUD.java @@ -0,0 +1,39 @@ +package WayofTime.bloodmagic.client.hud; + +import net.minecraftforge.fml.client.config.GuiConfig; +import net.minecraftforge.fml.client.config.GuiConfigEntries; +import net.minecraftforge.fml.client.config.IConfigElement; + +public class ConfigEntryEditHUD extends GuiConfigEntries.CategoryEntry { + + public ConfigEntryEditHUD(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement element) { + super(owningScreen, owningEntryList, element); + + this.childScreen = new GuiEditHUD(owningScreen); + } + + @Override + public boolean isDefault() { + return true; + } + + @Override + public void setToDefault() { + ElementRegistry.resetPos(); + } + + @Override + public boolean isChanged() { + return ((GuiEditHUD) childScreen).changes; + } + + @Override + public void undoChanges() { + + } + + @Override + public boolean saveConfigElement() { + return false; + } +} diff --git a/src/main/java/WayofTime/bloodmagic/client/hud/ElementInfo.java b/src/main/java/WayofTime/bloodmagic/client/hud/ElementInfo.java new file mode 100644 index 00000000..9544dcdc --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/client/hud/ElementInfo.java @@ -0,0 +1,39 @@ +package WayofTime.bloodmagic.client.hud; + +import javax.vecmath.Vector2f; + +public class ElementInfo { + + public static final ElementInfo DUMMY = new ElementInfo(new Vector2f(0F, 0F), ElementRegistry.getRandomColor()); + + private final Vector2f defaultPosition; + private final int boxColor; + private Vector2f currentPosition; + + public ElementInfo(Vector2f defaultPosition, int boxColor) { + this.defaultPosition = defaultPosition; + this.boxColor = boxColor; + this.currentPosition = defaultPosition; + } + + public Vector2f getDefaultPosition() { + return defaultPosition; + } + + public int getBoxColor() { + return boxColor; + } + + public ElementInfo setPosition(Vector2f position) { + this.currentPosition = position; + return this; + } + + public Vector2f getPosition() { + return currentPosition; + } + + public void resetPosition() { + this.currentPosition = defaultPosition; + } +} diff --git a/src/main/java/WayofTime/bloodmagic/client/hud/ElementRegistry.java b/src/main/java/WayofTime/bloodmagic/client/hud/ElementRegistry.java new file mode 100644 index 00000000..d83cb03c --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/client/hud/ElementRegistry.java @@ -0,0 +1,148 @@ +package WayofTime.bloodmagic.client.hud; + +import WayofTime.bloodmagic.BloodMagic; +import WayofTime.bloodmagic.client.hud.element.HUDElement; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Maps; +import com.google.common.reflect.TypeToken; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import javax.vecmath.Vector2f; +import java.awt.Color; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.function.BiFunction; + +@Mod.EventBusSubscriber(modid = BloodMagic.MODID, value = Side.CLIENT) +public class ElementRegistry { + + private static final File CONFIG = new File(Loader.instance().getConfigDir(), BloodMagic.MODID + "/hud_elements.json"); + private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + private static final Map HUD_ELEMENTS = Maps.newLinkedHashMap(); + private static final Map REVERSE = Maps.newHashMap(); + private static final Map ELEMENT_INFO = Maps.newHashMap(); + + public static void registerHandler(ResourceLocation key, HUDElement element, Vector2f defaultPosition) { + HUD_ELEMENTS.put(key, element); + REVERSE.put(element, key); + + + ELEMENT_INFO.put(key, new ElementInfo(defaultPosition, getRandomColor())); + } + + public static void resetPos() { + ELEMENT_INFO.values().forEach(ElementInfo::resetPosition); + } + + public static List getElements() { + return ImmutableList.copyOf(HUD_ELEMENTS.values()); + } + + public static ResourceLocation getKey(HUDElement element) { + return REVERSE.get(element); + } + + public static int getColor(ResourceLocation element) { + return ELEMENT_INFO.getOrDefault(element, ElementInfo.DUMMY).getBoxColor(); + } + + public static Vector2f getPosition(ResourceLocation element) { + return ELEMENT_INFO.get(element).getPosition(); + } + + public static void setPosition(ResourceLocation element, Vector2f point) { + ELEMENT_INFO.compute(element, (resourceLocation, elementInfo) -> { + if (elementInfo == null) + return new ElementInfo(point, getRandomColor()); + + elementInfo.setPosition(point); + return elementInfo; + }); + } + + public static void save(Map newLocations) { + newLocations.forEach((k, v) -> { + ElementInfo info = ELEMENT_INFO.get(k); + if (info != null) + info.setPosition(v); + }); + + Map toWrite = Maps.newHashMap(); + for (Map.Entry entry : ELEMENT_INFO.entrySet()) + toWrite.put(entry.getKey().toString(), entry.getValue().getPosition()); + + String json = GSON.toJson(toWrite); + try (FileWriter writer = new FileWriter(CONFIG)) { + writer.write(json); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void readConfig() { + if (!CONFIG.exists()) + return; + + try (FileReader reader = new FileReader(CONFIG)) { + Map toLoad = GSON.fromJson(reader, new TypeToken>() {}.getType()); + for (Map.Entry entry : toLoad.entrySet()) { + ElementInfo info = ELEMENT_INFO.get(new ResourceLocation(entry.getKey())); + if (info != null) + info.setPosition(entry.getValue()); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + @SideOnly(Side.CLIENT) + @SubscribeEvent + public static void onRenderOverlay(RenderGameOverlayEvent.Pre event) { + if (event.getType() == RenderGameOverlayEvent.ElementType.HOTBAR) { + ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft()); + + for (HUDElement element : HUD_ELEMENTS.values()) { + if (!element.shouldRender(Minecraft.getMinecraft())) + continue; + + Vector2f position = ELEMENT_INFO.get(getKey(element)).getPosition(); + int xPos = (int) (resolution.getScaledWidth_double() * position.x); + if (xPos - element.getWidth() < 0) + xPos *= 2; + if (xPos + element.getWidth() > resolution.getScaledWidth()) + xPos -= element.getWidth(); + + int yPos = (int) (resolution.getScaledHeight_double() * position.y); + if (yPos - element.getHeight() < 0) + yPos *= 2; + if (yPos + element.getHeight() > resolution.getScaledHeight()) + yPos -= element.getHeight(); + + element.draw(event.getResolution(), event.getPartialTicks(), xPos, yPos); + } + } + } + + public static int getRandomColor() { + Random rand = new Random(); + float r = rand.nextFloat() / 2F + 0.5F; + float g = rand.nextFloat() / 2F + 0.5F; + float b = rand.nextFloat() / 2F + 0.5F; + float a = 0.5F; + return new Color(r, g, b, a).getRGB(); + } +} diff --git a/src/main/java/WayofTime/bloodmagic/client/hud/Elements.java b/src/main/java/WayofTime/bloodmagic/client/hud/Elements.java index 6c507d1a..cc11d92c 100644 --- a/src/main/java/WayofTime/bloodmagic/client/hud/Elements.java +++ b/src/main/java/WayofTime/bloodmagic/client/hud/Elements.java @@ -2,100 +2,135 @@ package WayofTime.bloodmagic.client.hud; import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.client.Sprite; +import WayofTime.bloodmagic.client.hud.element.ElementDemonAura; +import WayofTime.bloodmagic.client.hud.element.ElementDivinedInformation; +import WayofTime.bloodmagic.client.hud.element.ElementHolding; import WayofTime.bloodmagic.tile.TileAltar; import WayofTime.bloodmagic.tile.TileIncenseAltar; import WayofTime.bloodmagic.tile.TileInversionPillar; import WayofTime.bloodmagic.util.helper.NumeralHelper; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.resources.I18n; import net.minecraft.util.ResourceLocation; import org.apache.commons.lang3.tuple.Pair; -import java.util.List; +import javax.vecmath.Vector2f; +import java.awt.Point; +import java.util.function.Consumer; import java.util.function.Function; public class Elements { - public static void createHUDElements() { - new HUDElementHolding(); - new HUDElementDemonWillAura(); - // Blood Altar with Divination Sigil - new HUDElementCornerTile.DivinedView(TileAltar.class, true) { - @Override - protected void addInformation(List>> information) { - // Current tier - information.add(Pair.of( - new Sprite(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png"), 0, 46, 16, 16), - altar -> NumeralHelper.toRoman(altar.getTier().toInt()) - )); - // Stored/Capacity - information.add(Pair.of( - new Sprite(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png"), 16, 46, 16, 16), - altar -> String.format("%d/%d", altar.getCurrentBlood(), altar.getCapacity()) - )); - } - }; - // Blood Altar with Seers Sigil - new HUDElementCornerTile.DivinedView(TileAltar.class, false) { - @Override - protected void addInformation(List>> information) { - // Current tier - information.add(Pair.of( - new Sprite(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png"), 0, 46, 16, 16), - altar -> NumeralHelper.toRoman(altar.getTier().toInt()) - )); - // Stored/Capacity - information.add(Pair.of( - new Sprite(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png"), 16, 46, 16, 16), - altar -> String.format("%d/%d", altar.getCurrentBlood(), altar.getCapacity()) - )); - // Crafting progress/Crafting requirement - information.add(Pair.of( - new Sprite(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png"), 32, 46, 16, 16), - altar -> { - if (!altar.isActive()) - return "Inactive"; // FIXME localize - int progress = altar.getProgress(); - int totalLiquidRequired = altar.getLiquidRequired() * altar.getStackInSlot(0).getCount(); - return String.format("%d/%d", progress, totalLiquidRequired); - } - )); - // Consumption rate - information.add(Pair.of( - new Sprite(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png"), 48, 46, 16, 16), - altar -> String.valueOf((int) (altar.getConsumptionRate() * (altar.getConsumptionMultiplier() + 1))) - )); - // Total charge - information.add(Pair.of( - new Sprite(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png"), 64, 46, 16, 16), - altar -> String.valueOf(altar.getTotalCharge()) - )); - } - }; - // Incense Altar - new HUDElementCornerTile.DivinedView(TileIncenseAltar.class, true) { - @Override - protected void addInformation(List>> information) { - // Current tranquility - information.add(Pair.of( - new Sprite(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png"), 80, 46, 16, 16), - incense -> String.valueOf((int) ((100D * (int) (100 * incense.tranquility)) / 100D)) - )); - // Sacrifice bonus - information.add(Pair.of( - new Sprite(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png"), 96, 46, 16, 16), - incense -> String.valueOf((int) (100 * incense.incenseAddition)) - )); - } - }; - // Inversion Pillar - new HUDElementCornerTile.DivinedView(TileInversionPillar.class, true) { - @Override - protected void addInformation(List>> information) { - // Current inversion - information.add(Pair.of( - new Sprite(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png"), 112, 46, 16, 16), - pillar -> String.valueOf(((int) (10 * pillar.getCurrentInversion())) / 10D) - )); - } - }; + public static void registerElements() { + ElementRegistry.registerHandler( + new ResourceLocation(BloodMagic.MODID, "blood_altar"), + new ElementDivinedInformation(2, true, TileAltar.class) { + @Override + public void gatherInformation(Consumer>> information) { + // Current tier + information.accept(Pair.of( + new Sprite(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png"), 0, 46, 16, 16), + altar -> altar == null ? "IV" : NumeralHelper.toRoman(altar.getTier().toInt()) + )); + // Stored/Capacity + information.accept(Pair.of( + new Sprite(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png"), 16, 46, 16, 16), + altar -> String.format("%d/%d", altar == null ? 0 : altar.getCurrentBlood(), altar == null ? 10000 : altar.getCapacity()) + )); + } + }, + new Vector2f(0.01F, 0.01F) + ); + + ElementRegistry.registerHandler( + new ResourceLocation(BloodMagic.MODID, "blood_altar_adv"), + new ElementDivinedInformation(5, false, TileAltar.class) { + @Override + public void gatherInformation(Consumer>> information) { + // Current tier + information.accept(Pair.of( + new Sprite(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png"), 0, 46, 16, 16), + altar -> altar == null ? "IV" : NumeralHelper.toRoman(altar.getTier().toInt()) + )); + // Stored/Capacity + information.accept(Pair.of( + new Sprite(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png"), 16, 46, 16, 16), + altar -> String.format("%d/%d", altar == null ? 0 : altar.getCurrentBlood(), altar == null ? 10000 : altar.getCapacity()) + )); + // Crafting progress/Crafting requirement + information.accept(Pair.of( + new Sprite(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png"), 32, 46, 16, 16), + altar -> { + if (altar == null || !altar.isActive()) + return I18n.format("hud.bloodmagic.inactive"); + int progress = altar.getProgress(); + int totalLiquidRequired = altar.getLiquidRequired() * altar.getStackInSlot(0).getCount(); + return String.format("%d/%d", progress, totalLiquidRequired); + } + )); + // Consumption rate + information.accept(Pair.of( + new Sprite(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png"), 48, 46, 16, 16), + altar -> altar == null ? "0" : String.valueOf((int) (altar.getConsumptionRate() * (altar.getConsumptionMultiplier() + 1))) + )); + // Total charge + information.accept(Pair.of( + new Sprite(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png"), 64, 46, 16, 16), + altar -> altar == null ? "0" : String.valueOf(altar.getTotalCharge()) + )); + } + }, + new Vector2f(0.01F, 0.01F) + ); + + ElementRegistry.registerHandler( + new ResourceLocation(BloodMagic.MODID, "incense_altar"), + new ElementDivinedInformation(2, true, TileIncenseAltar.class) { + @Override + public void gatherInformation(Consumer>> information) { + // Current tranquility + information.accept(Pair.of( + new Sprite(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png"), 80, 46, 16, 16), + incense -> incense == null ? "0" : String.valueOf((int) ((100D * (int) (100 * incense.tranquility)) / 100D)) + )); + // Sacrifice bonus + information.accept(Pair.of( + new Sprite(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png"), 96, 46, 16, 16), + incense -> incense == null ? "0" : String.valueOf((int) (100 * incense.incenseAddition)) + )); + } + }, + new Vector2f(0.01F, 0.01F) + ); + + ElementRegistry.registerHandler( + new ResourceLocation(BloodMagic.MODID, "inversion_pillar"), + new ElementDivinedInformation(1, true, TileInversionPillar.class) { + @Override + public void gatherInformation(Consumer>> information) { + // Current inversion + information.accept(Pair.of( + new Sprite(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png"), 112, 46, 16, 16), + pillar -> pillar == null ? "0" : String.valueOf(((int) (10 * pillar.getCurrentInversion())) / 10D) + )); + } + }, + new Vector2f(0.01F, 0.01F) + ); + + ElementRegistry.registerHandler( + new ResourceLocation(BloodMagic.MODID, "demon_will_aura"), + new ElementDemonAura(), + new Vector2f(0.01F, 0.01F) + ); + + ElementRegistry.registerHandler( + new ResourceLocation(BloodMagic.MODID, "holding"), + new ElementHolding(), + new Vector2f(0.72F, 1.0F) + ); + + ElementRegistry.readConfig(); } } diff --git a/src/main/java/WayofTime/bloodmagic/client/hud/GuiEditHUD.java b/src/main/java/WayofTime/bloodmagic/client/hud/GuiEditHUD.java new file mode 100644 index 00000000..a25a5b6c --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/client/hud/GuiEditHUD.java @@ -0,0 +1,183 @@ +package WayofTime.bloodmagic.client.hud; + +import WayofTime.bloodmagic.client.hud.element.HUDElement; +import com.google.common.collect.Maps; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.resources.I18n; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.client.config.GuiButtonExt; +import org.lwjgl.input.Keyboard; + +import javax.annotation.Nullable; +import javax.vecmath.Vector2f; +import java.awt.Point; +import java.util.Map; + +public class GuiEditHUD extends GuiScreen { + + private static final int LINE_COLOR = 0x2D2D2D; + + private final GuiScreen parent; + private final Map currentOverrides = Maps.newHashMap(); + private HUDElement dragged; + public boolean changes; + + public GuiEditHUD(GuiScreen parent) { + this.parent = parent; + } + + @Override + public void initGui() { + super.initGui(); + + addButton(new GuiButtonExt(0, width / 2 - 155, height - 30, 70, 20, I18n.format("gui.bloodmagic.toggle")){{enabled = false;}}); + addButton(new GuiButtonExt(1, width / 2 - 75, height - 30, 70, 20, I18n.format("gui.bloodmagic.default"))); + addButton(new GuiButtonExt(2, width / 2 + 5, height - 30, 70, 20, I18n.format("gui.bloodmagic.save"))); + addButton(new GuiButtonExt(3, width / 2 + 90, height - 30, 70, 20, I18n.format("gui.bloodmagic.cancel"))); + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + drawDefaultBackground(); + super.drawScreen(mouseX, mouseY, partialTicks); + + ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft()); + for (HUDElement element : ElementRegistry.getElements()) { + if (dragged == element) + continue; + + ResourceLocation key = ElementRegistry.getKey(element); + Vector2f position = currentOverrides.getOrDefault(key, ElementRegistry.getPosition(key)); + int xPos = (int) (resolution.getScaledWidth_double() * position.x); + int yPos = (int) (resolution.getScaledHeight_double() * position.y); + + drawWithBox(resolution, element, partialTicks, xPos, yPos); + } + + if (dragged != null) { + Point bounded = getBoundedDrag(resolution, mouseX, mouseY); + drawWithBox(resolution, dragged, partialTicks, bounded.x, bounded.y); + } + } + + @Override + public boolean doesGuiPauseGame() { + return true; + } + + @Override + protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { + if (dragged != null) + return; + + HUDElement element = getHoveredElement(mouseX, mouseY); + if (element == null) + return; + + if (clickedMouseButton == 0) + dragged = element; + } + + @Override + protected void mouseReleased(int mouseX, int mouseY, int state) { + if (dragged != null) { + ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft()); + Point bounded = getBoundedDrag(resolution, mouseX, mouseY); + float xPos = (float) ((bounded.x) / resolution.getScaledWidth_double()); + float yPos = (float) ((bounded.y) / resolution.getScaledHeight_double()); + + currentOverrides.put(ElementRegistry.getKey(dragged), new Vector2f(xPos, yPos)); + changes = true; + dragged = null; + return; + } + + super.mouseReleased(mouseX, mouseY, state); + } + + @Override + protected void actionPerformed(GuiButton button) { + switch (button.id) { + case 0: { + Minecraft.getMinecraft().displayGuiScreen(parent); + break; + } + case 1: { + currentOverrides.clear(); + ElementRegistry.resetPos(); + changes = false; + break; + } + case 2: { + ElementRegistry.save(currentOverrides); + Minecraft.getMinecraft().displayGuiScreen(parent); + break; + } + case 3: { + currentOverrides.clear(); + Minecraft.getMinecraft().displayGuiScreen(parent); + break; + } + } + } + + @Nullable + public HUDElement getHoveredElement(int mouseX, int mouseY) { + for (HUDElement element : ElementRegistry.getElements()) { + ResourceLocation key = ElementRegistry.getKey(element); + Vector2f position = currentOverrides.getOrDefault(key, ElementRegistry.getPosition(key)); + ScaledResolution resolution = new ScaledResolution(mc); + int xPos = (int) (resolution.getScaledWidth_double() * position.x); + int yPos = (int) (resolution.getScaledHeight_double() * position.y); + + if (mouseX < xPos || mouseX > xPos + element.getWidth()) + continue; + + if (mouseY < yPos || mouseY > yPos + element.getHeight()) + continue; + + return element; + } + + return null; + } + + protected Point getBoundedDrag(ScaledResolution resolution, int mouseX, int mouseY) { + int drawX = mouseX - dragged.getWidth() / 2; + if (drawX + dragged.getWidth() >= resolution.getScaledWidth()) + drawX = resolution.getScaledWidth() - dragged.getWidth(); + if (drawX < 0) + drawX = 0; + + int drawY = mouseY - dragged.getHeight() / 2; + if (drawY + dragged.getHeight() >= resolution.getScaledHeight()) + drawY = resolution.getScaledHeight() - dragged.getHeight(); + if (drawY < 0) + drawY = 0; + + return new Point(drawX, drawY); + } + + protected void drawWithBox(ScaledResolution resolution, HUDElement element, float partialTicks, int drawX, int drawY) { + int color = ElementRegistry.getColor(ElementRegistry.getKey(element)); + GlStateManager.pushMatrix(); + GlStateManager.enableAlpha(); + GlStateManager.enableBlend(); + GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); + drawVerticalLine(drawX, drawY, drawY + element.getHeight() - 1, color); + drawVerticalLine(drawX + element.getWidth() - 1, drawY, drawY + element.getHeight() - 1, color); + drawHorizontalLine(drawX, drawX + element.getWidth() - 1, drawY, color); + drawHorizontalLine(drawX, drawX + element.getWidth() - 1, drawY + element.getHeight() - 1, color); + GlStateManager.disableBlend(); + GlStateManager.disableAlpha(); + GlStateManager.popMatrix(); + GlStateManager.color(1.0F, 1.0F, 1.0F); + GlStateManager.enableTexture2D(); + element.draw(resolution, partialTicks, drawX, drawY); + GlStateManager.disableTexture2D(); + } +} diff --git a/src/main/java/WayofTime/bloodmagic/client/hud/HUDElement.java b/src/main/java/WayofTime/bloodmagic/client/hud/HUDElement.java deleted file mode 100644 index c9a605a5..00000000 --- a/src/main/java/WayofTime/bloodmagic/client/hud/HUDElement.java +++ /dev/null @@ -1,73 +0,0 @@ -package WayofTime.bloodmagic.client.hud; - -import WayofTime.bloodmagic.util.handler.event.ClientHandler; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraftforge.client.event.RenderGameOverlayEvent; - -public abstract class HUDElement { - private final int xOffsetDefault; - private final int yOffsetDefault; - private final RenderGameOverlayEvent.ElementType elementType; - private int xOffset; - private int yOffset; - - public HUDElement(int xOffset, int yOffset, RenderGameOverlayEvent.ElementType elementType) { - this.xOffset = xOffset; - this.xOffsetDefault = xOffset; - this.yOffset = yOffset; - this.yOffsetDefault = yOffset; - this.elementType = elementType; - - ClientHandler.hudElements.add(this); - } - - public abstract void render(Minecraft minecraft, ScaledResolution resolution, float partialTicks); - - public abstract boolean shouldRender(Minecraft minecraft); - - public void onPositionChanged() { - - } - - public void resetToDefault() { - this.xOffset = xOffsetDefault; - this.yOffset = yOffsetDefault; - } - - public void drawTexturedModalRect(double x, double y, double textureX, double textureY, double width, double height) { - float f = 0.00390625F; - float f1 = 0.00390625F; - Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder buffer = tessellator.getBuffer(); - buffer.begin(7, DefaultVertexFormats.POSITION_TEX); - buffer.pos(x + 0, y + height, 0).tex((double) ((float) (textureX + 0) * f), (double) ((float) (textureY + height) * f1)).endVertex(); - buffer.pos(x + width, y + height, 0).tex((double) ((float) (textureX + width) * f), (double) ((float) (textureY + height) * f1)).endVertex(); - buffer.pos(x + width, y + 0, 0).tex((double) ((float) (textureX + width) * f), (double) ((float) (textureY + 0) * f1)).endVertex(); - buffer.pos(x + 0, y + 0, 0).tex((double) ((float) (textureX + 0) * f), (double) ((float) (textureY + 0) * f1)).endVertex(); - tessellator.draw(); - } - - public int getXOffset() { - return xOffset; - } - - public int getYOffset() { - return yOffset; - } - - public int getXOffsetDefault() { - return xOffsetDefault; - } - - public int getYOffsetDefault() { - return yOffsetDefault; - } - - public RenderGameOverlayEvent.ElementType getElementType() { - return elementType; - } -} diff --git a/src/main/java/WayofTime/bloodmagic/client/hud/HUDElementCornerTile.java b/src/main/java/WayofTime/bloodmagic/client/hud/HUDElementCornerTile.java deleted file mode 100644 index fac02451..00000000 --- a/src/main/java/WayofTime/bloodmagic/client/hud/HUDElementCornerTile.java +++ /dev/null @@ -1,95 +0,0 @@ -package WayofTime.bloodmagic.client.hud; - -import WayofTime.bloodmagic.client.Sprite; -import WayofTime.bloodmagic.core.RegistrarBloodMagicItems; -import WayofTime.bloodmagic.item.sigil.ItemSigilDivination; -import com.google.common.collect.Lists; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumHand; -import net.minecraft.util.math.RayTraceResult; -import net.minecraftforge.client.event.RenderGameOverlayEvent; -import org.apache.commons.lang3.tuple.Pair; - -import java.awt.Color; -import java.util.List; -import java.util.function.Function; - -public abstract class HUDElementCornerTile extends HUDElement { - - protected final List>> information; - - public HUDElementCornerTile() { - super(5, 5, RenderGameOverlayEvent.ElementType.HOTBAR); - - this.information = Lists.newArrayList(); - addInformation(information); - } - - protected abstract void addInformation(List>> information); - - @SuppressWarnings("unchecked") - @Override - public void render(Minecraft minecraft, ScaledResolution resolution, float partialTicks) { - T tile = (T) Minecraft.getMinecraft().world.getTileEntity(Minecraft.getMinecraft().objectMouseOver.getBlockPos()); - - int yOffset = 0; - for (Pair> sprite : information) { - Minecraft.getMinecraft().renderEngine.bindTexture(sprite.getLeft().getTextureLocation()); - sprite.getLeft().draw(getXOffset(), getYOffset() + yOffset); - int textY = getYOffset() + yOffset + (sprite.getLeft().getTextureHeight() / 4); - Minecraft.getMinecraft().fontRenderer.drawStringWithShadow(sprite.getRight().apply(tile), getXOffset() + sprite.getLeft().getTextureWidth() + 2, textY, Color.WHITE.getRGB()); - yOffset += sprite.getLeft().getTextureHeight() + 2; - } - } - - public static abstract class DivinedView extends HUDElementCornerTile { - - private final Class tileClass; - private final boolean simple; - - public DivinedView(Class tileClass, boolean simple) { - this.tileClass = tileClass; - this.simple = simple; - } - - @Override - public boolean shouldRender(Minecraft minecraft) { - EntityPlayer player = Minecraft.getMinecraft().player; - ItemStack sigilStack = player.getHeldItem(EnumHand.MAIN_HAND); - boolean flag = false; - if (simple) { - if (sigilStack.getItem() instanceof ItemSigilDivination) - flag = true; - - if (!flag) { - sigilStack = player.getHeldItem(EnumHand.OFF_HAND); - if (sigilStack.getItem() instanceof ItemSigilDivination) - flag = true; - } - } else { - if (sigilStack.getItem() == RegistrarBloodMagicItems.SIGIL_SEER) - flag = true; - - if (!flag) { - sigilStack = player.getHeldItem(EnumHand.OFF_HAND); - if (sigilStack.getItem() == RegistrarBloodMagicItems.SIGIL_SEER) - flag = true; - } - } - - RayTraceResult trace = Minecraft.getMinecraft().objectMouseOver; - if (trace == null || trace.typeOfHit != RayTraceResult.Type.BLOCK) - return false; - - TileEntity tile = Minecraft.getMinecraft().world.getTileEntity(trace.getBlockPos()); - if (tile == null || !tileClass.isAssignableFrom(tile.getClass())) - flag = false; - - return flag; - } - } -} diff --git a/src/main/java/WayofTime/bloodmagic/client/hud/HUDElementDemonWillAura.java b/src/main/java/WayofTime/bloodmagic/client/hud/element/ElementDemonAura.java similarity index 52% rename from src/main/java/WayofTime/bloodmagic/client/hud/HUDElementDemonWillAura.java rename to src/main/java/WayofTime/bloodmagic/client/hud/element/ElementDemonAura.java index 20003b61..29c7a889 100644 --- a/src/main/java/WayofTime/bloodmagic/client/hud/HUDElementDemonWillAura.java +++ b/src/main/java/WayofTime/bloodmagic/client/hud/element/ElementDemonAura.java @@ -1,51 +1,50 @@ -package WayofTime.bloodmagic.client.hud; +package WayofTime.bloodmagic.client.hud.element; import WayofTime.bloodmagic.BloodMagic; -import WayofTime.bloodmagic.soul.EnumDemonWillType; import WayofTime.bloodmagic.proxy.ClientProxy; +import WayofTime.bloodmagic.soul.EnumDemonWillType; import WayofTime.bloodmagic.util.Utils; +import com.google.common.collect.Lists; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.event.RenderGameOverlayEvent; -import java.util.ArrayList; import java.util.List; -public class HUDElementDemonWillAura extends HUDElement { - protected List barOrder = new ArrayList<>(); +public class ElementDemonAura extends HUDElement { - public HUDElementDemonWillAura() { - super(5, 5, RenderGameOverlayEvent.ElementType.HOTBAR); + private static final ResourceLocation BAR_LOCATION = new ResourceLocation(BloodMagic.MODID, "textures/hud/bars.png"); - barOrder.add(EnumDemonWillType.DEFAULT); - barOrder.add(EnumDemonWillType.CORROSIVE); - barOrder.add(EnumDemonWillType.STEADFAST); - barOrder.add(EnumDemonWillType.DESTRUCTIVE); - barOrder.add(EnumDemonWillType.VENGEFUL); + private final List orderedTypes = Lists.newArrayList( + EnumDemonWillType.DEFAULT, + EnumDemonWillType.CORROSIVE, + EnumDemonWillType.STEADFAST, + EnumDemonWillType.DESTRUCTIVE, + EnumDemonWillType.VENGEFUL + ); + + public ElementDemonAura() { + super(80, 46); } @Override - public void render(Minecraft minecraft, ScaledResolution resolution, float partialTicks) { + public void draw(ScaledResolution resolution, float partialTicks, int drawX, int drawY) { + Minecraft minecraft = Minecraft.getMinecraft(); EntityPlayer player = minecraft.player; - if (!Utils.canPlayerSeeDemonWill(player)) { - return; - } - - minecraft.getTextureManager().bindTexture(new ResourceLocation(BloodMagic.MODID, "textures/hud/bars.png")); + minecraft.getTextureManager().bindTexture(BAR_LOCATION); GlStateManager.color(1.0F, 1.0F, 1.0F); - this.drawTexturedModalRect(getXOffset(), getYOffset(), 0, 105 * 2, 80, 46); + this.drawTexturedModalRect(drawX, drawY, 0, 210, 80, 46); double maxAmount = Utils.getDemonWillResolution(player); int i = 0; - for (EnumDemonWillType type : barOrder) { + for (EnumDemonWillType type : orderedTypes) { i++; GlStateManager.color(1.0F, 1.0F, 1.0F); - minecraft.getTextureManager().bindTexture(new ResourceLocation(BloodMagic.MODID, "textures/hud/bars.png")); + minecraft.getTextureManager().bindTexture(BAR_LOCATION); int textureXOffset = (i > 3) ? (i - 3) : (3 - i); int maxBarSize = 30 - 2 * textureXOffset; @@ -54,8 +53,8 @@ public class HUDElementDemonWillAura extends HUDElement { double width = maxBarSize * ratio * 2; double height = 2; - double x = getXOffset() + 2 * textureXOffset + 10; - double y = getYOffset() + 4 * i + 10; + double x = drawX + 2 * textureXOffset + 10; + double y = drawY + 4 * i + 10; double textureX = 2 * textureXOffset + 2 * 42; double textureY = 4 * i + 220; @@ -64,10 +63,9 @@ public class HUDElementDemonWillAura extends HUDElement { if (player.isSneaking()) { GlStateManager.pushMatrix(); - String value = "" + (int) amount; - GlStateManager.translate(x - 2 * textureXOffset - value.length() * 0 + 70, (y - 1), 0); + GlStateManager.translate(x - 2 * textureXOffset + 70, (y - 1), 0); GlStateManager.scale(0.5, 0.5, 1); - minecraft.fontRenderer.drawStringWithShadow("" + (int) amount, 0, 2, 0xffffff); + minecraft.fontRenderer.drawStringWithShadow(String.valueOf((int) amount), 0, 2, 0xffffff); GlStateManager.popMatrix(); } } @@ -75,6 +73,6 @@ public class HUDElementDemonWillAura extends HUDElement { @Override public boolean shouldRender(Minecraft minecraft) { - return true; + return Utils.canPlayerSeeDemonWill(Minecraft.getMinecraft().player); } } diff --git a/src/main/java/WayofTime/bloodmagic/client/hud/element/ElementDivinedInformation.java b/src/main/java/WayofTime/bloodmagic/client/hud/element/ElementDivinedInformation.java new file mode 100644 index 00000000..c8244775 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/client/hud/element/ElementDivinedInformation.java @@ -0,0 +1,46 @@ +package WayofTime.bloodmagic.client.hud.element; + +import WayofTime.bloodmagic.core.RegistrarBloodMagicItems; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumHand; + +public abstract class ElementDivinedInformation extends ElementTileInformation { + + private final boolean simple; + + public ElementDivinedInformation(int lines, boolean simple, Class tileClass) { + super(100, lines, tileClass); + this.simple = simple; + } + + @Override + public boolean shouldRender(Minecraft minecraft) { + EntityPlayer player = Minecraft.getMinecraft().player; + ItemStack sigilStack = player.getHeldItem(EnumHand.MAIN_HAND); + boolean flag = false; + if (simple) { + if (sigilStack.getItem() == RegistrarBloodMagicItems.SIGIL_DIVINATION) + flag = true; + + if (!flag) { + sigilStack = player.getHeldItem(EnumHand.OFF_HAND); + if (sigilStack.getItem() == RegistrarBloodMagicItems.SIGIL_DIVINATION) + flag = true; + } + } else { + if (sigilStack.getItem() == RegistrarBloodMagicItems.SIGIL_SEER) + flag = true; + + if (!flag) { + sigilStack = player.getHeldItem(EnumHand.OFF_HAND); + if (sigilStack.getItem() == RegistrarBloodMagicItems.SIGIL_SEER) + flag = true; + } + } + + return super.shouldRender(minecraft) && flag; + } +} diff --git a/src/main/java/WayofTime/bloodmagic/client/hud/HUDElementHolding.java b/src/main/java/WayofTime/bloodmagic/client/hud/element/ElementHolding.java similarity index 60% rename from src/main/java/WayofTime/bloodmagic/client/hud/HUDElementHolding.java rename to src/main/java/WayofTime/bloodmagic/client/hud/element/ElementHolding.java index 5524e074..d2656658 100644 --- a/src/main/java/WayofTime/bloodmagic/client/hud/HUDElementHolding.java +++ b/src/main/java/WayofTime/bloodmagic/client/hud/element/ElementHolding.java @@ -1,28 +1,34 @@ -package WayofTime.bloodmagic.client.hud; +package WayofTime.bloodmagic.client.hud.element; import WayofTime.bloodmagic.BloodMagic; +import WayofTime.bloodmagic.client.Sprite; import WayofTime.bloodmagic.core.RegistrarBloodMagicItems; import WayofTime.bloodmagic.item.sigil.ItemSigilHolding; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.event.RenderGameOverlayEvent; import java.util.List; -public class HUDElementHolding extends HUDElement { +public class ElementHolding extends HUDElement { - public HUDElementHolding() { - super(0, 0, RenderGameOverlayEvent.ElementType.HOTBAR); + private static final Sprite HOLDING_BAR = new Sprite(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png"), 0, 0, 102, 22); + private static final Sprite SELECTED_OVERLAY = new Sprite(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png"), 0, 22, 24, 24); + + public ElementHolding() { + super(HOLDING_BAR.getTextureWidth(), HOLDING_BAR.getTextureHeight()); } @Override - public void render(Minecraft minecraft, ScaledResolution resolution, float partialTicks) { + public void draw(ScaledResolution resolution, float partialTicks, int drawX, int drawY) { + GlStateManager.color(1.0F, 1.0F, 1.0F); + HOLDING_BAR.draw(drawX, drawY); + + Minecraft minecraft = Minecraft.getMinecraft(); ItemStack sigilHolding = minecraft.player.getHeldItemMainhand(); // Check mainhand for Sigil of Holding if (!(sigilHolding.getItem() == RegistrarBloodMagicItems.SIGIL_HOLDING)) @@ -31,27 +37,28 @@ public class HUDElementHolding extends HUDElement { if (!(sigilHolding.getItem() == RegistrarBloodMagicItems.SIGIL_HOLDING)) return; - Gui ingameGui = minecraft.ingameGUI; - - minecraft.getTextureManager().bindTexture(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png")); - GlStateManager.color(1.0F, 1.0F, 1.0F); - ingameGui.drawTexturedModalRect(resolution.getScaledWidth() / 2 + 100 + getXOffset(), resolution.getScaledHeight() - 22 + getYOffset(), 0, 0, 102, 22); int currentSlot = ItemSigilHolding.getCurrentItemOrdinal(sigilHolding); - ingameGui.drawTexturedModalRect(resolution.getScaledWidth() / 2 + 99 + (currentSlot * 20) + getXOffset(), resolution.getScaledHeight() - 23 + getYOffset(), 0, 22, 24, 24); + SELECTED_OVERLAY.draw(drawX - 1 + (currentSlot * 20), drawY - 1); RenderHelper.enableGUIStandardItemLighting(); - List holdingInv = ItemSigilHolding.getInternalInventory(sigilHolding); + List inventory = ItemSigilHolding.getInternalInventory(sigilHolding); int xOffset = 0; - for (ItemStack sigil : holdingInv) { - renderHotbarItem(resolution.getScaledWidth() / 2 + 103 + xOffset + getXOffset(), resolution.getScaledHeight() - 18 + getYOffset(), partialTicks, minecraft.player, sigil); + for (ItemStack stack : inventory) { + renderHotbarItem(drawX + 3 + xOffset, drawY - 4, partialTicks, minecraft.player, stack); xOffset += 20; } - - RenderHelper.disableStandardItemLighting(); } @Override public boolean shouldRender(Minecraft minecraft) { + ItemStack sigilHolding = minecraft.player.getHeldItemMainhand(); + // Check mainhand for Sigil of Holding + if (!(sigilHolding.getItem() == RegistrarBloodMagicItems.SIGIL_HOLDING)) + sigilHolding = minecraft.player.getHeldItemOffhand(); + // Check offhand for Sigil of Holding + if (!(sigilHolding.getItem() == RegistrarBloodMagicItems.SIGIL_HOLDING)) + return false; + return true; } diff --git a/src/main/java/WayofTime/bloodmagic/client/hud/element/ElementItemStack.java b/src/main/java/WayofTime/bloodmagic/client/hud/element/ElementItemStack.java new file mode 100644 index 00000000..5f783e55 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/client/hud/element/ElementItemStack.java @@ -0,0 +1,23 @@ +package WayofTime.bloodmagic.client.hud.element; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.item.ItemStack; + +public class ElementItemStack extends HUDElement { + private ItemStack stack; + + public ElementItemStack(ItemStack stack) { + super(16, 16); + + this.stack = stack; + } + + @Override + public void draw(ScaledResolution resolution, float partialTicks, int drawX, int drawY) { + RenderHelper.enableGUIStandardItemLighting(); + Minecraft.getMinecraft().getRenderItem().renderItemIntoGUI(stack, drawX, drawY); + RenderHelper.disableStandardItemLighting(); + } +} diff --git a/src/main/java/WayofTime/bloodmagic/client/hud/element/ElementSprite.java b/src/main/java/WayofTime/bloodmagic/client/hud/element/ElementSprite.java new file mode 100644 index 00000000..e574ffef --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/client/hud/element/ElementSprite.java @@ -0,0 +1,20 @@ +package WayofTime.bloodmagic.client.hud.element; + +import WayofTime.bloodmagic.client.Sprite; +import net.minecraft.client.gui.ScaledResolution; + +public class ElementSprite extends HUDElement { + + private final Sprite sprite; + + public ElementSprite(Sprite sprite) { + super(sprite.getTextureWidth(), sprite.getTextureHeight()); + + this.sprite = sprite; + } + + @Override + public void draw(ScaledResolution resolution, float partialTicks, int drawX, int drawY) { + sprite.draw(drawX, drawY); + } +} diff --git a/src/main/java/WayofTime/bloodmagic/client/hud/element/ElementString.java b/src/main/java/WayofTime/bloodmagic/client/hud/element/ElementString.java new file mode 100644 index 00000000..419ebe25 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/client/hud/element/ElementString.java @@ -0,0 +1,36 @@ +package WayofTime.bloodmagic.client.hud.element; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.util.text.ITextComponent; + +public class ElementString extends HUDElement { + + private ITextComponent[] display; + + public ElementString(ITextComponent... display) { + super(getMaxStringWidth(display), (Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT + 2) * display.length - 2); + + this.display = display; + } + + @Override + public void draw(ScaledResolution resolution, float partialTicks, int drawX, int drawY) { + FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer; + for (ITextComponent drawText : display) { + fontRenderer.drawStringWithShadow(drawText.getFormattedText(), drawX, drawY, 14737632); + drawY += fontRenderer.FONT_HEIGHT + 2; + } + } + + private static int getMaxStringWidth(ITextComponent... display) { + FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer; + int maxWidth = 0; + for (ITextComponent drawText : display) + if (fontRenderer.getStringWidth(drawText.getFormattedText()) > maxWidth) + maxWidth = fontRenderer.getStringWidth(drawText.getFormattedText()); + + return maxWidth; + } +} diff --git a/src/main/java/WayofTime/bloodmagic/client/hud/element/ElementTileInformation.java b/src/main/java/WayofTime/bloodmagic/client/hud/element/ElementTileInformation.java new file mode 100644 index 00000000..f8092cf6 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/client/hud/element/ElementTileInformation.java @@ -0,0 +1,57 @@ +package WayofTime.bloodmagic.client.hud.element; + +import WayofTime.bloodmagic.client.Sprite; +import com.google.common.collect.Lists; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.RayTraceResult; +import org.apache.commons.lang3.tuple.Pair; + +import java.awt.Color; +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Function; + +public abstract class ElementTileInformation extends HUDElement { + + protected final Class tileClass; + private final List>> information; + + public ElementTileInformation(int width, int lines, Class tileClass) { + super(width, 18 * lines - 2); + + this.tileClass = tileClass; + this.information = Lists.newArrayList(); + gatherInformation(information::add); + } + + public abstract void gatherInformation(Consumer>> information); + + @SuppressWarnings("unchecked") + @Override + public void draw(ScaledResolution resolution, float partialTicks, int drawX, int drawY) { + T tile = (T) Minecraft.getMinecraft().world.getTileEntity(Minecraft.getMinecraft().objectMouseOver.getBlockPos()); + + int yOffset = 0; + for (Pair> sprite : information) { + sprite.getLeft().draw(drawX, drawY + yOffset); + int textY = drawY + yOffset + (sprite.getLeft().getTextureHeight() / 4); + Minecraft.getMinecraft().fontRenderer.drawStringWithShadow((tile != null && tile.getClass() == tileClass) ? sprite.getRight().apply(tile) : "?", drawX + sprite.getLeft().getTextureWidth() + 2, textY, Color.WHITE.getRGB()); + yOffset += sprite.getLeft().getTextureHeight() + 2; + } + } + + @Override + public boolean shouldRender(Minecraft minecraft) { + RayTraceResult trace = Minecraft.getMinecraft().objectMouseOver; + if (trace == null || trace.typeOfHit != RayTraceResult.Type.BLOCK) + return false; + + TileEntity tile = Minecraft.getMinecraft().world.getTileEntity(trace.getBlockPos()); + if (tile == null || !tileClass.isAssignableFrom(tile.getClass())) + return false; + + return true; + } +} diff --git a/src/main/java/WayofTime/bloodmagic/client/hud/element/HUDElement.java b/src/main/java/WayofTime/bloodmagic/client/hud/element/HUDElement.java new file mode 100644 index 00000000..10eed1cd --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/client/hud/element/HUDElement.java @@ -0,0 +1,58 @@ +package WayofTime.bloodmagic.client.hud.element; + +import WayofTime.bloodmagic.client.hud.ElementRegistry; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import javax.vecmath.Vector2f; +import java.awt.Point; + +@SideOnly(Side.CLIENT) +public abstract class HUDElement { + + private int width; + private int height; + + public HUDElement(int width, int height) { + this.width = width; + this.height = height; + } + + public boolean shouldRender(Minecraft minecraft) { + return true; + } + + public abstract void draw(ScaledResolution resolution, float partialTicks, int drawX, int drawY); + + public final int getWidth() { + return width; + } + + public final int getHeight() { + return height; + } + + protected void drawTexturedModalRect(double x, double y, double textureX, double textureY, double width, double height) { + float f = 0.00390625F; + float f1 = 0.00390625F; + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buffer = tessellator.getBuffer(); + buffer.begin(7, DefaultVertexFormats.POSITION_TEX); + buffer.pos(x + 0, y + height, 0).tex((double) ((float) (textureX + 0) * f), (double) ((float) (textureY + height) * f1)).endVertex(); + buffer.pos(x + width, y + height, 0).tex((double) ((float) (textureX + width) * f), (double) ((float) (textureY + height) * f1)).endVertex(); + buffer.pos(x + width, y + 0, 0).tex((double) ((float) (textureX + width) * f), (double) ((float) (textureY + 0) * f1)).endVertex(); + buffer.pos(x + 0, y + 0, 0).tex((double) ((float) (textureX + 0) * f), (double) ((float) (textureY + 0) * f1)).endVertex(); + tessellator.draw(); + } + + @Override + public String toString() { + Vector2f point = ElementRegistry.getPosition(ElementRegistry.getKey(this)); + return ElementRegistry.getKey(this) + "@" + point.x + "," + point.y; + } +} diff --git a/src/main/java/WayofTime/bloodmagic/proxy/ClientProxy.java b/src/main/java/WayofTime/bloodmagic/proxy/ClientProxy.java index 87256a18..f8dd774e 100644 --- a/src/main/java/WayofTime/bloodmagic/proxy/ClientProxy.java +++ b/src/main/java/WayofTime/bloodmagic/proxy/ClientProxy.java @@ -132,7 +132,7 @@ public class ClientProxy extends CommonProxy @Override public void postInit() { - Elements.createHUDElements(); + Elements.registerElements(); } private void addElytraLayer() diff --git a/src/main/java/WayofTime/bloodmagic/util/handler/event/ClientHandler.java b/src/main/java/WayofTime/bloodmagic/util/handler/event/ClientHandler.java index ebc027cd..15575efb 100644 --- a/src/main/java/WayofTime/bloodmagic/util/handler/event/ClientHandler.java +++ b/src/main/java/WayofTime/bloodmagic/util/handler/event/ClientHandler.java @@ -7,7 +7,6 @@ import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.ritual.RitualRegistry; import WayofTime.bloodmagic.ritual.Ritual; import WayofTime.bloodmagic.ritual.RitualComponent; -import WayofTime.bloodmagic.client.hud.HUDElement; import WayofTime.bloodmagic.client.key.KeyBindings; import WayofTime.bloodmagic.client.render.block.RenderFakeBlocks; import WayofTime.bloodmagic.core.RegistrarBloodMagic; @@ -57,7 +56,6 @@ import java.util.*; public class ClientHandler { // Quick toggle for error suppression. Set to false if you wish to hide model errors. public static final boolean SUPPRESS_ASSET_ERRORS = true; - public static final List hudElements = new ArrayList<>(); public static TextureAtlasSprite ritualStoneBlank; public static TextureAtlasSprite ritualStoneWater; public static TextureAtlasSprite ritualStoneFire; @@ -175,13 +173,6 @@ public class ClientHandler { keyBinding.handleKeybind(); } - @SubscribeEvent - public static void onHudRender(RenderGameOverlayEvent.Pre event) { - for (HUDElement element : hudElements) - if (element.getElementType() == event.getType() && element.shouldRender(minecraft)) - element.render(minecraft, event.getResolution(), event.getPartialTicks()); - } - // Stolen from Chisel @SubscribeEvent public static void onModelBake(ModelBakeEvent event) { diff --git a/src/main/resources/assets/bloodmagic/lang/en_US.lang b/src/main/resources/assets/bloodmagic/lang/en_US.lang index b4b2e0b5..e9227fde 100644 --- a/src/main/resources/assets/bloodmagic/lang/en_US.lang +++ b/src/main/resources/assets/bloodmagic/lang/en_US.lang @@ -374,6 +374,9 @@ tile.bloodmagic.stairs3.steadfast.name=Steadfast Stone Stairs # Fluids fluid.lifeEssence=Life Essence +# HUD +hud.bloodmagic.inactive=Inactive + # Tooltips tooltip.bloodmagic.extraInfo=&9-Hold shift for more info- @@ -828,8 +831,6 @@ commands.bind.remove.success=Unbinding successful commands.orb.usage=/bloodmagic orb [set|get] player [tier] commands.orb.help=Used to set or get the Player's max Blood Orb tier. -commands.bind.usage=/bind -commands.bind.success=Item successfully bound! commands.bind.failed.noPlayer=There is no player specified commands.bind.failed.alreadyBound=Item is already bound; use /unbind to unbind it commands.bind.failed.notBindable=Item cannot be bound @@ -851,6 +852,11 @@ commands.soulnetwork.create.success=Successfully created %s's Soul Network (Orb # GUI tile.bloodmagic.inputNode.name=Input Node tile.bloodmagic.outputNode.name=Output Node +gui.bloodmagic.save=Save +gui.bloodmagic.cancel=Cancel +gui.bloodmagic.default=Default +gui.bloodmagic.toggle=Toggle +config.bloodmagic.edit_hud=Edit HUD Elements # Keybinds bloodmagic.keybind.open_holding=Open Sigil of Holding