diff --git a/src/main/java/net/anvilcraft/thaummach/RenderTicker.java b/src/main/java/net/anvilcraft/thaummach/RenderTicker.java index 7e97a4a..a5b2ac7 100644 --- a/src/main/java/net/anvilcraft/thaummach/RenderTicker.java +++ b/src/main/java/net/anvilcraft/thaummach/RenderTicker.java @@ -1,19 +1,124 @@ package net.anvilcraft.thaummach; +import java.util.Collection; + import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.TickEvent.Phase; import cpw.mods.fml.common.gameevent.TickEvent.RenderTickEvent; +import dev.tilera.auracore.client.AuraManagerClient; +import dev.tilera.auracore.client.AuraManagerClient.NodeStats; import net.anvilcraft.thaummach.render.PortalRenderer; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; public class RenderTicker { @SubscribeEvent public void onRenderTickEvent(RenderTickEvent ev) { - if (Minecraft.getMinecraft().theWorld == null) + if (Minecraft.getMinecraft().theWorld == null || ev.phase != Phase.END) return; for (PortalRenderer ren : PortalRenderer.INSTANCES) { // TODO: optimize ren.createPortalView(); } + + EntityPlayer pl = Minecraft.getMinecraft().thePlayer; + if (pl == null) + // WTF + return; + + int foundDetectorType = -1; + + for (int i = 0; i < pl.inventory.getSizeInventory(); i++) { + ItemStack stack = pl.inventory.getStackInSlot(i); + if (stack != null && stack.getItem() == TMItems.detector) { + foundDetectorType = stack.getItemDamage(); + break; + } + } + + if (foundDetectorType >= 0) { + GuiDetector.INSTANCE.render(foundDetectorType); + } + } + + public static class GuiDetector extends Gui { + public static final GuiDetector INSTANCE = new GuiDetector(); + + public NodeStats findNode() { + EntityPlayer player = Minecraft.getMinecraft().thePlayer; + NodeStats closest = null; + double closestDistance = Double.MAX_VALUE; + Collection col = AuraManagerClient.auraClientList.values(); + for (NodeStats stats : col) { + int dim = stats.dimension; + if (player.dimension != dim) + continue; + double px = stats.x; + double py = stats.y; + double pz = stats.z; + double xd = px - player.posX; + double yd = py - player.posY; + double zd = pz - player.posZ; + double distSq = xd * xd + yd * yd + zd * zd; + if (!(distSq < closestDistance)) + continue; + closestDistance = distSq; + closest = stats; + } + return closest; + } + + public void render(int type) { + NodeStats aura = this.findNode(); + if (aura == null) + return; + + Minecraft mc = Minecraft.getMinecraft(); + ScaledResolution scaledresolution + = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); + int k = scaledresolution.getScaledWidth(); + int l = scaledresolution.getScaledHeight(); + mc.entityRenderer.setupOverlayRendering(); + GL11.glEnable(3042); + GL11.glEnable(32826); + RenderHelper.enableStandardItemLighting(); + RenderHelper.disableStandardItemLighting(); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + mc.renderEngine.bindTexture( + new ResourceLocation("thaummach", "textures/guis/detector.png") + ); + super.zLevel = -90.0F; + int sv = 48 * (aura.base * 2 - aura.level) / (aura.base * 2); + int st = 48 * (aura.base * 2 - aura.taint) / (aura.base * 2); + if (type == 0 || type == 2 || type >= 3) { + //if (aura.goodVibes > 0) { + // this.drawTexturedModalRect(k - 34, l - 17, 0, 72, 16, 16); + //} + + this.drawTexturedModalRect(k - 30, l - 67 + sv, 0, 0 + sv, 8, 48 - sv); + + this.drawTexturedModalRect(k - 31, l - 71, 23, 0, 10, 74); + } + + if (type == 1 || type == 2 || type >= 3) { + //if (aura.badVibes > 0) { + // this.drawTexturedModalRect(k - 19, l - 17, 0, 72, 16, 16); + //} + + this.drawTexturedModalRect(k - 15, l - 67 + st, 8, 0 + st, 8, 48 - st); + + this.drawTexturedModalRect(k - 16, l - 71, 39, 0, 10, 74); + } + + GL11.glDisable(32826); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + } } } diff --git a/src/main/java/net/anvilcraft/thaummach/TMItems.java b/src/main/java/net/anvilcraft/thaummach/TMItems.java index 547fecb..620a02f 100644 --- a/src/main/java/net/anvilcraft/thaummach/TMItems.java +++ b/src/main/java/net/anvilcraft/thaummach/TMItems.java @@ -2,6 +2,7 @@ package net.anvilcraft.thaummach; import cpw.mods.fml.common.registry.GameRegistry; import net.anvilcraft.thaummach.items.ItemCrystallineBell; +import net.anvilcraft.thaummach.items.ItemDetector; import net.anvilcraft.thaummach.items.ItemFocus; import net.anvilcraft.thaummach.items.ItemRunicEssence; import net.anvilcraft.thaummach.items.ItemSingularity; @@ -11,6 +12,7 @@ import net.minecraft.item.Item; public class TMItems { public static Item crystallineBell; + public static Item detector; public static Item focus0; public static Item focus1; public static Item focus2; @@ -24,6 +26,8 @@ public class TMItems { public static void init() { crystallineBell = new ItemCrystallineBell(); + detector = new ItemDetector(); + focus0 = new ItemFocus(0); focus1 = new ItemFocus(1); focus2 = new ItemFocus(2); @@ -40,6 +44,8 @@ public class TMItems { GameRegistry.registerItem(crystallineBell, "crystalline_bell"); + GameRegistry.registerItem(detector, "detector"); + GameRegistry.registerItem(focus0, "focus0"); GameRegistry.registerItem(focus1, "focus1"); GameRegistry.registerItem(focus2, "focus2"); diff --git a/src/main/java/net/anvilcraft/thaummach/items/ItemDetector.java b/src/main/java/net/anvilcraft/thaummach/items/ItemDetector.java new file mode 100644 index 0000000..14ae298 --- /dev/null +++ b/src/main/java/net/anvilcraft/thaummach/items/ItemDetector.java @@ -0,0 +1,160 @@ +package net.anvilcraft.thaummach.items; + +import java.util.List; +import java.util.stream.IntStream; + +import dev.tilera.auracore.api.HelperLocation; +import dev.tilera.auracore.api.machine.IConnection; +import net.anvilcraft.thaummach.TMTab; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; + +public class ItemDetector extends Item { + public IIcon[] icons; + + public ItemDetector() { + super(); + super.maxStackSize = 1; + this.setHasSubtypes(true); + this.setMaxDamage(0); + this.setCreativeTab(TMTab.INSTANCE); + } + + @Override + public EnumRarity getRarity(ItemStack itemstack) { + return EnumRarity.uncommon; + } + + @Override + public void registerIcons(IIconRegister reg) { + this.icons = IntStream.rangeClosed(0, 2) + .mapToObj((i) -> "thaummach:detector_" + i) + .map(reg::registerIcon) + .toArray(IIcon[] ::new); + } + + @Override + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void getSubItems(Item alec1, CreativeTabs tab, List list) { + IntStream.rangeClosed(0, 2) + .mapToObj((i) -> new ItemStack(this, 1, i)) + .forEach(list::add); + } + + @Override + public IIcon getIconFromDamage(int meta) { + return this.icons[meta]; + } + + @Override + public String getUnlocalizedName(ItemStack stack) { + return "item.thaummach:detector_" + stack.getItemDamage(); + } + + @Override + public boolean onItemUseFirst( + ItemStack itemstack, + EntityPlayer entityplayer, + World world, + int x, + int y, + int z, + int l, + // useless parameters + float alec1, + float alec2, + float alec3 + ) { + TileEntity ent = world.getTileEntity(x, y, z); + if (ent instanceof IConnection) { + IConnection tet = (IConnection) ent; + if (itemstack.getItemDamage() == 0) { + if (world.isRemote) + return false; + entityplayer.addChatMessage(new ChatComponentText( + "Detected " + Math.round(tet.getPureVis()) + " Vis." + )); + world.playSoundEffect( + (double) x, (double) y, (double) z, "note.harp", 0.8F, 1.0F + ); + if (tet.getVisSuction((HelperLocation) null) > 0) { + entityplayer.addChatMessage(new ChatComponentText( + tet.getVisSuction((HelperLocation) null) + " Vis TCB" + )); + } + + return true; + } + + if (itemstack.getItemDamage() == 1) { + if (world.isRemote) + return false; + entityplayer.addChatMessage(new ChatComponentText( + "Detected " + Math.round(tet.getTaintedVis()) + " Taint." + )); + world.playSoundEffect( + (double) x, (double) y, (double) z, "note.harp", 0.8F, 1.0F + ); + if (tet.getTaintSuction((HelperLocation) null) > 0) { + entityplayer.addChatMessage(new ChatComponentText( + tet.getTaintSuction((HelperLocation) null) + " Taint TCB" + )); + } + + return true; + } + + if (itemstack.getItemDamage() == 2) { + if (world.isRemote) + return false; + int cap = Math.round( + (float) Math.round(tet.getPureVis() + tet.getTaintedVis()) + / tet.getMaxVis() * 100.0F + ); + int capp = Math.round( + (float) Math.round(tet.getPureVis()) / tet.getMaxVis() * 100.0F + ); + int capt = Math.round( + (float) Math.round(tet.getTaintedVis()) / tet.getMaxVis() * 100.0F + ); + entityplayer.addChatMessage(new ChatComponentText( + "Detected " + Math.round(tet.getPureVis()) + " Vis (" + capp + + "%) and " + Math.round(tet.getTaintedVis()) + " Taint (" + capt + + "%)." + )); + entityplayer.addChatMessage( + new ChatComponentText("The object is at " + cap + "% capacity.") + ); + world.playSoundEffect( + (double) x, + (double) y, + (double) z, + "note.harp", + 0.8F, + 1.0F + 1.0F * (float) cap / 100.0F + ); + if (tet.getTaintSuction((HelperLocation) null) > 0 + || tet.getVisSuction((HelperLocation) null) > 0) { + entityplayer.addChatMessage(new ChatComponentText( + "" + tet.getVisSuction((HelperLocation) null) + " Vis TCB, " + + tet.getTaintSuction((HelperLocation) null) + " Taint TCB" + )); + } + + return true; + } + } + + return super.onItemUseFirst( + itemstack, entityplayer, world, x, y, z, l, alec1, alec2, alec3 + ); + } +} diff --git a/src/main/resources/assets/thaummach/lang/en_US.lang b/src/main/resources/assets/thaummach/lang/en_US.lang index bb327cf..57a44e9 100644 --- a/src/main/resources/assets/thaummach/lang/en_US.lang +++ b/src/main/resources/assets/thaummach/lang/en_US.lang @@ -33,6 +33,10 @@ tile.thaummach:apparatus_wood_dusk_totem.name=Dusk Totem # ---- ITEMS ---- +item.thaummach:detector_0.name=Vis Detector +item.thaummach:detector_1.name=Taint Detector +item.thaummach:detector_2.name=Thaumic Detector + item.thaummach:focus_0.name=Arcane Focus item.thaummach:focus_1.name=Arcane Focus: Air item.thaummach:focus_2.name=Arcane Focus: Water diff --git a/src/main/resources/assets/thaummach/textures/guis/detector.png b/src/main/resources/assets/thaummach/textures/guis/detector.png new file mode 100644 index 0000000..f36dc62 Binary files /dev/null and b/src/main/resources/assets/thaummach/textures/guis/detector.png differ diff --git a/src/main/resources/assets/thaummach/textures/items/detector_0.png b/src/main/resources/assets/thaummach/textures/items/detector_0.png new file mode 100644 index 0000000..7c873aa Binary files /dev/null and b/src/main/resources/assets/thaummach/textures/items/detector_0.png differ diff --git a/src/main/resources/assets/thaummach/textures/items/detector_1.png b/src/main/resources/assets/thaummach/textures/items/detector_1.png new file mode 100644 index 0000000..dc4af9f Binary files /dev/null and b/src/main/resources/assets/thaummach/textures/items/detector_1.png differ diff --git a/src/main/resources/assets/thaummach/textures/items/detector_2.png b/src/main/resources/assets/thaummach/textures/items/detector_2.png new file mode 100644 index 0000000..f40f357 Binary files /dev/null and b/src/main/resources/assets/thaummach/textures/items/detector_2.png differ