diff --git a/src/main/java/WayofTime/bloodmagic/client/Sprite.java b/src/main/java/WayofTime/bloodmagic/client/Sprite.java new file mode 100644 index 00000000..795286a0 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/client/Sprite.java @@ -0,0 +1,56 @@ +package WayofTime.bloodmagic.client; + +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.util.ResourceLocation; + +public class Sprite { + + private final ResourceLocation textureLocation; + private final int textureX; + private final int textureY; + private final int textureWidth; + private final int textureHeight; + + public Sprite(ResourceLocation textureLocation, int textureX, int textureY, int textureWidth, int textureHeight) { + this.textureLocation = textureLocation; + this.textureX = textureX; + this.textureY = textureY; + this.textureWidth = textureWidth; + this.textureHeight = textureHeight; + } + + public ResourceLocation getTextureLocation() { + return textureLocation; + } + + public int getTextureX() { + return textureX; + } + + public int getTextureY() { + return textureY; + } + + public int getTextureWidth() { + return textureWidth; + } + + public int getTextureHeight() { + return textureHeight; + } + + public void draw(int x, int y) { + float f = 0.00390625F; + float f1 = 0.00390625F; + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buffer = tessellator.getBuffer(); + buffer.begin(7, DefaultVertexFormats.POSITION_TEX); + buffer.pos((double) x, (double) (y + getTextureHeight()), 1.0F).tex((double) ((float) (getTextureX()) * f), (double) ((float) (getTextureY() + getTextureHeight()) * f1)).endVertex(); + buffer.pos((double) (x + getTextureWidth()), (double) (y + getTextureHeight()), 1.0F).tex((double) ((float) (getTextureX() + getTextureWidth()) * f), (double) ((float) (getTextureY() + getTextureHeight()) * f1)).endVertex(); + buffer.pos((double) (x + getTextureWidth()), (double) (y), 1.0F).tex((double) ((float) (getTextureX() + getTextureWidth()) * f), (double) ((float) (getTextureY()) * f1)).endVertex(); + buffer.pos((double) x, (double) (y), 1.0F).tex((double) ((float) (getTextureX()) * f), (double) ((float) (getTextureY()) * f1)).endVertex(); + tessellator.draw(); + } +} diff --git a/src/main/java/WayofTime/bloodmagic/client/hud/HUDElementCornerTile.java b/src/main/java/WayofTime/bloodmagic/client/hud/HUDElementCornerTile.java new file mode 100644 index 00000000..207fde44 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/client/hud/HUDElementCornerTile.java @@ -0,0 +1,89 @@ +package WayofTime.bloodmagic.client.hud; + +import WayofTime.bloodmagic.client.Sprite; +import WayofTime.bloodmagic.item.sigil.ItemSigilDivination; +import WayofTime.bloodmagic.item.sigil.ItemSigilSeer; +import WayofTime.bloodmagic.tile.TileAltar; +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.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 BloodAltar extends HUDElementCornerTile { + + private final boolean simple; + + public BloodAltar(boolean simple) { + 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() instanceof ItemSigilSeer) + flag = true; + + if (!flag) { + sigilStack = player.getHeldItem(EnumHand.OFF_HAND); + if (sigilStack.getItem() instanceof ItemSigilSeer) + flag = true; + } + } + + TileEntity tile = Minecraft.getMinecraft().world.getTileEntity(Minecraft.getMinecraft().objectMouseOver.getBlockPos()); + if (!(tile instanceof TileAltar)) + flag = false; + + return flag; + } + } +} diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilDivination.java b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilDivination.java index 13f9c407..4f97fab1 100644 --- a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilDivination.java +++ b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilDivination.java @@ -1,17 +1,12 @@ package WayofTime.bloodmagic.item.sigil; -import WayofTime.bloodmagic.apibutnotreally.altar.IBloodAltar; import WayofTime.bloodmagic.apibutnotreally.iface.IAltarReader; import WayofTime.bloodmagic.apibutnotreally.iface.ISigil; import WayofTime.bloodmagic.apibutnotreally.util.helper.NetworkHelper; import WayofTime.bloodmagic.apibutnotreally.util.helper.PlayerHelper; -import WayofTime.bloodmagic.tile.TileIncenseAltar; -import WayofTime.bloodmagic.tile.TileInversionPillar; import WayofTime.bloodmagic.util.ChatUtil; -import WayofTime.bloodmagic.util.helper.NumeralHelper; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; @@ -63,33 +58,6 @@ public class ItemSigilDivination extends ItemSigilBase implements IAltarReader { toSend.add(new TextComponentTranslation(tooltipBase + "otherNetwork", getOwnerName(stack))); toSend.add(new TextComponentTranslation(tooltipBase + "currentEssence", currentEssence)); ChatUtil.sendNoSpam(player, toSend.toArray(new ITextComponent[toSend.size()])); - } else { - if (position.typeOfHit == RayTraceResult.Type.BLOCK) { - TileEntity tile = world.getTileEntity(position.getBlockPos()); - - if (tile != null && tile instanceof IBloodAltar) { - IBloodAltar altar = (IBloodAltar) tile; - int tier = altar.getTier().ordinal() + 1; - int currentEssence = altar.getCurrentBlood(); - int capacity = altar.getCapacity(); - altar.checkTier(); - ChatUtil.sendNoSpam(player, new TextComponentTranslation(tooltipBase + "currentAltarTier", NumeralHelper.toRoman(tier)), new TextComponentTranslation(tooltipBase + "currentEssence", currentEssence), new TextComponentTranslation(tooltipBase + "currentAltarCapacity", capacity)); - } else if (tile != null && tile instanceof TileIncenseAltar) { - TileIncenseAltar altar = (TileIncenseAltar) tile; - altar.recheckConstruction(); - double tranquility = altar.tranquility; - ChatUtil.sendNoSpam(player, new TextComponentTranslation(tooltipBase + "currentTranquility", (int) ((100D * (int) (100 * tranquility)) / 100d)), new TextComponentTranslation(tooltipBase + "currentBonus", (int) (100 * altar.incenseAddition))); - } else if (tile != null && tile instanceof TileInversionPillar) { - TileInversionPillar pillar = (TileInversionPillar) tile; - double inversion = pillar.getCurrentInversion(); - ChatUtil.sendNoSpam(player, new TextComponentTranslation(tooltipBase + "currentInversion", ((int) (10 * inversion)) / 10d)); - } else - - { - int currentEssence = NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).getCurrentEssence(); - ChatUtil.sendNoSpam(player, new TextComponentTranslation(tooltipBase + "currentEssence", currentEssence)); - } - } } } diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilSeer.java b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilSeer.java index fc2fb523..ffb2eb29 100644 --- a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilSeer.java +++ b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilSeer.java @@ -1,17 +1,12 @@ package WayofTime.bloodmagic.item.sigil; -import WayofTime.bloodmagic.apibutnotreally.altar.IBloodAltar; import WayofTime.bloodmagic.apibutnotreally.iface.IAltarReader; import WayofTime.bloodmagic.apibutnotreally.iface.ISigil; import WayofTime.bloodmagic.apibutnotreally.util.helper.NetworkHelper; import WayofTime.bloodmagic.apibutnotreally.util.helper.PlayerHelper; -import WayofTime.bloodmagic.tile.TileIncenseAltar; import WayofTime.bloodmagic.util.ChatUtil; -import WayofTime.bloodmagic.util.helper.NumeralHelper; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; @@ -48,38 +43,6 @@ public class ItemSigilSeer extends ItemSigilBase implements IAltarReader { toSend.add(new TextComponentTranslation(tooltipBase + "otherNetwork", getOwnerName(stack))); toSend.add(new TextComponentTranslation(tooltipBase + "currentEssence", currentEssence)); ChatUtil.sendNoSpam(player, toSend.toArray(new ITextComponent[toSend.size()])); - } else { - if (rayTrace.typeOfHit == RayTraceResult.Type.BLOCK) { - - TileEntity tile = world.getTileEntity(rayTrace.getBlockPos()); - - if (tile != null && tile instanceof IBloodAltar) { - IBloodAltar altar = (IBloodAltar) tile; - int tier = altar.getTier().ordinal() + 1; - int currentEssence = altar.getCurrentBlood(); - int capacity = altar.getCapacity(); - int charge = altar.getTotalCharge(); - altar.checkTier(); - if (tile instanceof IInventory) { - if (!((IInventory) tile).getStackInSlot(0).isEmpty()) { - int progress = altar.getProgress(); - int totalLiquidRequired = altar.getLiquidRequired() * ((IInventory) tile).getStackInSlot(0).getCount(); - int consumptionRate = (int) (altar.getConsumptionRate() * (altar.getConsumptionMultiplier() + 1)); - ChatUtil.sendNoSpam(player, new TextComponentTranslation(tooltipBase + "currentAltarProgress", progress, totalLiquidRequired), new TextComponentTranslation(tooltipBase + "currentAltarConsumptionRate", consumptionRate), new TextComponentTranslation(tooltipBase + "currentAltarTier", NumeralHelper.toRoman(tier)), new TextComponentTranslation(tooltipBase + "currentEssence", currentEssence), new TextComponentTranslation(tooltipBase + "currentAltarCapacity", capacity), new TextComponentTranslation(tooltipBase + "currentCharge", charge)); - } else { - ChatUtil.sendNoSpam(player, new TextComponentTranslation(tooltipBase + "currentAltarTier", NumeralHelper.toRoman(tier)), new TextComponentTranslation(tooltipBase + "currentEssence", currentEssence), new TextComponentTranslation(tooltipBase + "currentAltarCapacity", capacity), new TextComponentTranslation(tooltipBase + "currentCharge", charge)); - } - } - } else if (tile != null && tile instanceof TileIncenseAltar) { - TileIncenseAltar altar = (TileIncenseAltar) tile; - altar.recheckConstruction(); - double tranquility = altar.tranquility; - ChatUtil.sendNoSpam(player, new TextComponentTranslation(tooltipBase + "currentTranquility", (int) ((100D * (int) (100 * tranquility)) / 100d)), new TextComponentTranslation(tooltipBase + "currentBonus", (int) (100 * altar.incenseAddition))); - } else { - int currentEssence = NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).getCurrentEssence(); - ChatUtil.sendNoSpam(player, new TextComponentTranslation(tooltipBase + "currentEssence", currentEssence)); - } - } } } diff --git a/src/main/java/WayofTime/bloodmagic/proxy/ClientProxy.java b/src/main/java/WayofTime/bloodmagic/proxy/ClientProxy.java index 42ef7613..26a98d86 100644 --- a/src/main/java/WayofTime/bloodmagic/proxy/ClientProxy.java +++ b/src/main/java/WayofTime/bloodmagic/proxy/ClientProxy.java @@ -5,7 +5,9 @@ import WayofTime.bloodmagic.apibutnotreally.Constants; import WayofTime.bloodmagic.apibutnotreally.soul.DemonWillHolder; import WayofTime.bloodmagic.client.IMeshProvider; import WayofTime.bloodmagic.client.IVariantProvider; +import WayofTime.bloodmagic.client.Sprite; import WayofTime.bloodmagic.client.helper.ShaderHelper; +import WayofTime.bloodmagic.client.hud.HUDElementCornerTile; import WayofTime.bloodmagic.client.hud.HUDElementDemonWillAura; import WayofTime.bloodmagic.client.hud.HUDElementHolding; import WayofTime.bloodmagic.client.key.KeyBindings; @@ -20,6 +22,7 @@ import WayofTime.bloodmagic.entity.projectile.EntitySentientArrow; import WayofTime.bloodmagic.entity.projectile.EntitySoulSnare; import WayofTime.bloodmagic.tile.*; import WayofTime.bloodmagic.tile.routing.TileRoutingNode; +import WayofTime.bloodmagic.util.helper.NumeralHelper; import com.google.common.collect.ImmutableMap; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; @@ -42,7 +45,9 @@ import net.minecraftforge.fml.common.ObfuscationReflectionHelper; import org.apache.commons.lang3.tuple.Pair; import java.awt.Color; +import java.util.List; import java.util.Map; +import java.util.function.Function; public class ClientProxy extends CommonProxy { public static DemonWillHolder currentAura = new DemonWillHolder(); @@ -118,6 +123,44 @@ public class ClientProxy extends CommonProxy { public void postInit() { new HUDElementHolding(); new HUDElementDemonWillAura(); + new HUDElementCornerTile.BloodAltar(true) { // Divination Sigil + @Override + protected void addInformation(List>> information) { + information.add(Pair.of(new Sprite(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png"), 0, 46, 16, 16), altar -> NumeralHelper.toRoman(altar.getTier().toInt()))); + 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()))); + } + }; + new HUDElementCornerTile.BloodAltar(false) { // Seer Sigil + @Override + protected void addInformation(List>> information) { + information.add(Pair.of( + new Sprite(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png"), 0, 46, 16, 16), + altar -> NumeralHelper.toRoman(altar.getTier().toInt()) + )); + 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()) + )); + information.add(Pair.of( // Craft Progress + 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); + } + )); + 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))) + )); + information.add(Pair.of( + new Sprite(new ResourceLocation(BloodMagic.MODID, "textures/gui/widgets.png"), 64, 46, 16, 16), + altar -> String.valueOf(altar.getTotalCharge()) + )); + } + }; } @Override diff --git a/src/main/resources/assets/bloodmagic/textures/gui/widgets.png b/src/main/resources/assets/bloodmagic/textures/gui/widgets.png index 456166c9..6d8d9cfe 100644 Binary files a/src/main/resources/assets/bloodmagic/textures/gui/widgets.png and b/src/main/resources/assets/bloodmagic/textures/gui/widgets.png differ