Move Divination output to a HUD element

RIP chat spam 2014-2018

:hype:
This commit is contained in:
Nicholas Ignoffo 2018-02-12 19:45:09 -08:00
parent 3286849309
commit 7167aba23c
6 changed files with 188 additions and 69 deletions

View file

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

View file

@ -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<T extends TileEntity> extends HUDElement {
protected final List<Pair<Sprite, Function<T, String>>> information;
public HUDElementCornerTile() {
super(5, 5, RenderGameOverlayEvent.ElementType.HOTBAR);
this.information = Lists.newArrayList();
addInformation(information);
}
protected abstract void addInformation(List<Pair<Sprite, Function<T, String>>> 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, Function<T, String>> 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<TileAltar> {
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;
}
}
}

View file

@ -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));
}
}
}
}

View file

@ -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));
}
}
}
}

View file

@ -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<Pair<Sprite, Function<TileAltar, String>>> 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<Pair<Sprite, Function<TileAltar, String>>> 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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 24 KiB