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