From 2692193e54e4dd6c0117dcdb85368dc83bb04f1a Mon Sep 17 00:00:00 2001 From: Roman / Nea Date: Mon, 18 Apr 2022 17:33:32 +0200 Subject: Mob loot recipe PR (#81) * entity renderer (somewhat functionaL) * more modifiers and entities * Fix cookie fuckup * add neu repo as resource pack, cause why not at this point * add tabs, because i can * add extra skin parts and make less tabs * hot tall men * fix texture offsets and also parts:true * some untested changes * still broken, but better (just like me (stop being edgy nea ( no u )))) * stuff (with er skeletons * niceities * skytils interop * horseys * horseys ouch * panos * stupid tests :angery: * NPE * add drop chance * colored leather armo * finish off * move shit into hover cause items look pretty terrible * Update 2.1.md * better recipe display name * always show mobs toggle * moving parts --- .../miscfeatures/entityviewer/EntityViewer.java | 177 +++++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java new file mode 100644 index 00000000..e9075e47 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java @@ -0,0 +1,177 @@ +package io.github.moulberry.notenoughupdates.miscfeatures.entityviewer; + +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.inventory.GuiInventory; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.boss.EntityDragon; +import net.minecraft.entity.boss.EntityWither; +import net.minecraft.entity.item.EntityArmorStand; +import net.minecraft.entity.monster.*; +import net.minecraft.entity.passive.*; +import net.minecraft.util.ResourceLocation; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.function.Supplier; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + +public class EntityViewer extends GuiScreen { + + public static Map> validEntities = new HashMap>() {{ + put("Zombie", () -> new EntityZombie(null)); + put("Chicken", () -> new EntityChicken(null)); + put("Slime", () -> new EntitySlime(null)); + put("Wolf", () -> new EntityWolf(null)); + put("Skeleton", () -> new EntitySkeleton(null)); + put("Creeper", () -> new EntityCreeper(null)); + put("Ocelot", () -> new EntityOcelot(null)); + put("Blaze", () -> new EntityBlaze(null)); + put("Rabbit", () -> new EntityRabbit(null)); + put("Sheep", () -> new EntitySheep(null)); + put("Horse", () -> new EntityHorse(null)); + put("Eisengolem", () -> new EntityIronGolem(null)); + put("Silverfish", () -> new EntitySilverfish(null)); + put("Witch", () -> new EntityWitch(null)); + put("Endermite", () -> new EntityEndermite(null)); + put("Snowman", () -> new EntitySnowman(null)); + put("Villager", () -> new EntityVillager(null)); + put("Guardian", () -> new EntityGuardian(null)); + put("ArmorStand", () -> new EntityArmorStand(null)); + put("Squid", () -> new EntitySquid(null)); + put("Bat", () -> new EntityBat(null)); + put("Spider", () -> new EntitySpider(null)); + put("CaveSpider", () -> new EntityCaveSpider(null)); + put("Pigman", () -> new EntityPigZombie(null)); + put("Ghast", () -> new EntityGhast(null)); + put("MagmaCube", () -> new EntityMagmaCube(null)); + put("Wither", () -> new EntityWither(null)); + put("Enderman", () -> new EntityEnderman(null)); + put("Mooshroom", ()-> new EntityMooshroom(null)); + put("WitherSkeleton", () -> { + EntitySkeleton skeleton = new EntitySkeleton(null); + skeleton.setSkeletonType(1); + return skeleton; + }); + put("Cow", () -> new EntityCow(null)); + put("Dragon", ()-> new EntityDragon(null)); + put("Player", () -> new GUIClientPlayer()); + }}; + + public static Map validModifiers = new HashMap() {{ + put("playerdata", new SkinModifier()); + put("equipment", new EquipmentModifier()); + put("riding", new RidingModifier()); + put("charged", new ChargedModifier()); + put("witherdata", new WitherModifier()); + put("invisible", new InvisibleModifier()); + put("age", new AgeModifier()); + put("horse", new HorseModifier()); + }}; + + public int guiLeft = 0; + public int guiTop = 0; + public int xSize = 176; + public int ySize = 166; + + private final String label; + private final EntityLivingBase entity; + private static final ResourceLocation BACKGROUND = new ResourceLocation("notenoughupdates", "textures/gui/entity_viewer.png"); + + public EntityViewer(String label, EntityLivingBase entity) { + this.label = label; + this.entity = entity; + } + + public static EntityLivingBase constructEntity(ResourceLocation resourceLocation) { + Gson gson = NotEnoughUpdates.INSTANCE.manager.gson; + try (Reader is = new InputStreamReader( + Minecraft.getMinecraft().getResourceManager().getResource(resourceLocation).getInputStream(), StandardCharsets.UTF_8)) { + return constructEntity(gson.fromJson(is, JsonObject.class)); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + public static EntityLivingBase constructEntity(JsonObject info) { + List modifiers = info.has("modifiers") ? + StreamSupport.stream(info.get("modifiers").getAsJsonArray().spliterator(), false) + .map(JsonElement::getAsJsonObject).collect(Collectors.toList()) + : Collections.emptyList(); + return EntityViewer.constructEntity(info.get("entity").getAsString(), modifiers); + } + + public static EntityLivingBase constructEntity(String string, String[] modifiers) { + Gson gson = NotEnoughUpdates.INSTANCE.manager.gson; + return constructEntity(string, Arrays.stream(modifiers).map(it -> gson.fromJson(it, JsonObject.class)).collect(Collectors.toList())); + } + + public static EntityLivingBase constructEntity(String string, List modifiers) { + Supplier aClass = validEntities.get(string); + if (aClass == null) { + System.err.println("Could not find entity of type: " + string); + return null; + } + try { + EntityLivingBase entity = aClass.get(); + for (JsonObject modifier : modifiers) { + String type = modifier.get("type").getAsString(); + EntityViewerModifier entityViewerModifier = validModifiers.get(type); + entity = entityViewerModifier.applyModifier(entity, modifier); + if (entity == null) break; + } + return entity; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + drawDefaultBackground(); + FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; + + this.guiLeft = (width - this.xSize) / 2; + this.guiTop = (height - this.ySize) / 2; + + + Minecraft.getMinecraft().getTextureManager().bindTexture(BACKGROUND); + drawTexturedModalRect(guiLeft, guiTop, 0, 0, this.xSize, this.ySize); + + + Utils.drawStringScaledMaxWidth(label, fontRenderer, guiLeft + 10, guiTop + 10, false, 100, 0xFF00FF); + renderEntity(entity, guiLeft + 90, guiTop + 75, mouseX, mouseY); + } + + public static void renderEntity(EntityLivingBase entity, int posX, int posY, int mouseX, int mouseY) { + GlStateManager.color(1F, 1F, 1F, 1F); + + int scale = 30; + float bottomOffset = 0F; + EntityLivingBase stack = entity; + while (true) { + + stack.ticksExisted = Minecraft.getMinecraft().thePlayer.ticksExisted; + GuiInventory.drawEntityOnScreen(posX, (int) (posY - bottomOffset * scale), scale, posX - mouseX, (int) (posY - stack.getEyeHeight() * scale - mouseY), stack); + bottomOffset += stack.getMountedYOffset(); + if (!(stack.riddenByEntity instanceof EntityLivingBase)) { + break; + } + stack = (EntityLivingBase) stack.riddenByEntity; + } + + } +} -- cgit From 0d194f9596525b973e4da1fa6f86dac9accf6a52 Mon Sep 17 00:00:00 2001 From: Lulonaut <67191924+Lulonaut@users.noreply.github.com> Date: Sun, 8 May 2022 18:19:38 +0200 Subject: Add pig to EntityViewer (#132) * add pig to EntityViewer * git my beloved --- .../notenoughupdates/miscfeatures/entityviewer/EntityViewer.java | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java index e9075e47..130f6ee7 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java @@ -67,6 +67,7 @@ public class EntityViewer extends GuiScreen { put("Cow", () -> new EntityCow(null)); put("Dragon", ()-> new EntityDragon(null)); put("Player", () -> new GUIClientPlayer()); + put("Pig", () -> new EntityPig(null)); }}; public static Map validModifiers = new HashMap() {{ -- cgit From dfdc2d9519556dfec528ab9d1732cdf32aab0639 Mon Sep 17 00:00:00 2001 From: Roman / Nea Date: Tue, 31 May 2022 20:53:26 +0200 Subject: Move repository related configuration to GUI. (#151) --- .../notenoughupdates/miscfeatures/entityviewer/EntityViewer.java | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java index 130f6ee7..78d035ac 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java @@ -79,6 +79,7 @@ public class EntityViewer extends GuiScreen { put("invisible", new InvisibleModifier()); put("age", new AgeModifier()); put("horse", new HorseModifier()); + put("name", new NameModifier()); }}; public int guiLeft = 0; -- cgit From 50dc2122462642a0c3a00b3a3ae6389825dc04df Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Thu, 9 Jun 2022 18:04:22 -0400 Subject: Re-license project as LGPL (#157) * add licence files & a few misc chores * add license notices & run auto formatter --- .../miscfeatures/entityviewer/EntityViewer.java | 366 ++++++++++++--------- 1 file changed, 216 insertions(+), 150 deletions(-) (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java index 78d035ac..367d62d3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java @@ -1,3 +1,22 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + package io.github.moulberry.notenoughupdates.miscfeatures.entityviewer; import com.google.gson.Gson; @@ -14,166 +33,213 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.boss.EntityDragon; import net.minecraft.entity.boss.EntityWither; import net.minecraft.entity.item.EntityArmorStand; -import net.minecraft.entity.monster.*; -import net.minecraft.entity.passive.*; +import net.minecraft.entity.monster.EntityBlaze; +import net.minecraft.entity.monster.EntityCaveSpider; +import net.minecraft.entity.monster.EntityCreeper; +import net.minecraft.entity.monster.EntityEnderman; +import net.minecraft.entity.monster.EntityEndermite; +import net.minecraft.entity.monster.EntityGhast; +import net.minecraft.entity.monster.EntityGuardian; +import net.minecraft.entity.monster.EntityIronGolem; +import net.minecraft.entity.monster.EntityMagmaCube; +import net.minecraft.entity.monster.EntityPigZombie; +import net.minecraft.entity.monster.EntitySilverfish; +import net.minecraft.entity.monster.EntitySkeleton; +import net.minecraft.entity.monster.EntitySlime; +import net.minecraft.entity.monster.EntitySnowman; +import net.minecraft.entity.monster.EntitySpider; +import net.minecraft.entity.monster.EntityWitch; +import net.minecraft.entity.monster.EntityZombie; +import net.minecraft.entity.passive.EntityBat; +import net.minecraft.entity.passive.EntityChicken; +import net.minecraft.entity.passive.EntityCow; +import net.minecraft.entity.passive.EntityHorse; +import net.minecraft.entity.passive.EntityMooshroom; +import net.minecraft.entity.passive.EntityOcelot; +import net.minecraft.entity.passive.EntityPig; +import net.minecraft.entity.passive.EntityRabbit; +import net.minecraft.entity.passive.EntitySheep; +import net.minecraft.entity.passive.EntitySquid; +import net.minecraft.entity.passive.EntityVillager; +import net.minecraft.entity.passive.EntityWolf; import net.minecraft.util.ResourceLocation; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.StreamSupport; public class EntityViewer extends GuiScreen { - public static Map> validEntities = new HashMap>() {{ - put("Zombie", () -> new EntityZombie(null)); - put("Chicken", () -> new EntityChicken(null)); - put("Slime", () -> new EntitySlime(null)); - put("Wolf", () -> new EntityWolf(null)); - put("Skeleton", () -> new EntitySkeleton(null)); - put("Creeper", () -> new EntityCreeper(null)); - put("Ocelot", () -> new EntityOcelot(null)); - put("Blaze", () -> new EntityBlaze(null)); - put("Rabbit", () -> new EntityRabbit(null)); - put("Sheep", () -> new EntitySheep(null)); - put("Horse", () -> new EntityHorse(null)); - put("Eisengolem", () -> new EntityIronGolem(null)); - put("Silverfish", () -> new EntitySilverfish(null)); - put("Witch", () -> new EntityWitch(null)); - put("Endermite", () -> new EntityEndermite(null)); - put("Snowman", () -> new EntitySnowman(null)); - put("Villager", () -> new EntityVillager(null)); - put("Guardian", () -> new EntityGuardian(null)); - put("ArmorStand", () -> new EntityArmorStand(null)); - put("Squid", () -> new EntitySquid(null)); - put("Bat", () -> new EntityBat(null)); - put("Spider", () -> new EntitySpider(null)); - put("CaveSpider", () -> new EntityCaveSpider(null)); - put("Pigman", () -> new EntityPigZombie(null)); - put("Ghast", () -> new EntityGhast(null)); - put("MagmaCube", () -> new EntityMagmaCube(null)); - put("Wither", () -> new EntityWither(null)); - put("Enderman", () -> new EntityEnderman(null)); - put("Mooshroom", ()-> new EntityMooshroom(null)); - put("WitherSkeleton", () -> { - EntitySkeleton skeleton = new EntitySkeleton(null); - skeleton.setSkeletonType(1); - return skeleton; - }); - put("Cow", () -> new EntityCow(null)); - put("Dragon", ()-> new EntityDragon(null)); - put("Player", () -> new GUIClientPlayer()); - put("Pig", () -> new EntityPig(null)); - }}; - - public static Map validModifiers = new HashMap() {{ - put("playerdata", new SkinModifier()); - put("equipment", new EquipmentModifier()); - put("riding", new RidingModifier()); - put("charged", new ChargedModifier()); - put("witherdata", new WitherModifier()); - put("invisible", new InvisibleModifier()); - put("age", new AgeModifier()); - put("horse", new HorseModifier()); - put("name", new NameModifier()); - }}; - - public int guiLeft = 0; - public int guiTop = 0; - public int xSize = 176; - public int ySize = 166; - - private final String label; - private final EntityLivingBase entity; - private static final ResourceLocation BACKGROUND = new ResourceLocation("notenoughupdates", "textures/gui/entity_viewer.png"); - - public EntityViewer(String label, EntityLivingBase entity) { - this.label = label; - this.entity = entity; - } - - public static EntityLivingBase constructEntity(ResourceLocation resourceLocation) { - Gson gson = NotEnoughUpdates.INSTANCE.manager.gson; - try (Reader is = new InputStreamReader( - Minecraft.getMinecraft().getResourceManager().getResource(resourceLocation).getInputStream(), StandardCharsets.UTF_8)) { - return constructEntity(gson.fromJson(is, JsonObject.class)); - } catch (IOException e) { - e.printStackTrace(); - } - return null; - } - - public static EntityLivingBase constructEntity(JsonObject info) { - List modifiers = info.has("modifiers") ? - StreamSupport.stream(info.get("modifiers").getAsJsonArray().spliterator(), false) - .map(JsonElement::getAsJsonObject).collect(Collectors.toList()) - : Collections.emptyList(); - return EntityViewer.constructEntity(info.get("entity").getAsString(), modifiers); - } - - public static EntityLivingBase constructEntity(String string, String[] modifiers) { - Gson gson = NotEnoughUpdates.INSTANCE.manager.gson; - return constructEntity(string, Arrays.stream(modifiers).map(it -> gson.fromJson(it, JsonObject.class)).collect(Collectors.toList())); - } - - public static EntityLivingBase constructEntity(String string, List modifiers) { - Supplier aClass = validEntities.get(string); - if (aClass == null) { - System.err.println("Could not find entity of type: " + string); - return null; - } - try { - EntityLivingBase entity = aClass.get(); - for (JsonObject modifier : modifiers) { - String type = modifier.get("type").getAsString(); - EntityViewerModifier entityViewerModifier = validModifiers.get(type); - entity = entityViewerModifier.applyModifier(entity, modifier); - if (entity == null) break; - } - return entity; - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) { - drawDefaultBackground(); - FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; - - this.guiLeft = (width - this.xSize) / 2; - this.guiTop = (height - this.ySize) / 2; - - - Minecraft.getMinecraft().getTextureManager().bindTexture(BACKGROUND); - drawTexturedModalRect(guiLeft, guiTop, 0, 0, this.xSize, this.ySize); - - - Utils.drawStringScaledMaxWidth(label, fontRenderer, guiLeft + 10, guiTop + 10, false, 100, 0xFF00FF); - renderEntity(entity, guiLeft + 90, guiTop + 75, mouseX, mouseY); - } - - public static void renderEntity(EntityLivingBase entity, int posX, int posY, int mouseX, int mouseY) { - GlStateManager.color(1F, 1F, 1F, 1F); - - int scale = 30; - float bottomOffset = 0F; - EntityLivingBase stack = entity; - while (true) { - - stack.ticksExisted = Minecraft.getMinecraft().thePlayer.ticksExisted; - GuiInventory.drawEntityOnScreen(posX, (int) (posY - bottomOffset * scale), scale, posX - mouseX, (int) (posY - stack.getEyeHeight() * scale - mouseY), stack); - bottomOffset += stack.getMountedYOffset(); - if (!(stack.riddenByEntity instanceof EntityLivingBase)) { - break; - } - stack = (EntityLivingBase) stack.riddenByEntity; - } - - } + public static Map> validEntities = + new HashMap>() {{ + put("Zombie", () -> new EntityZombie(null)); + put("Chicken", () -> new EntityChicken(null)); + put("Slime", () -> new EntitySlime(null)); + put("Wolf", () -> new EntityWolf(null)); + put("Skeleton", () -> new EntitySkeleton(null)); + put("Creeper", () -> new EntityCreeper(null)); + put("Ocelot", () -> new EntityOcelot(null)); + put("Blaze", () -> new EntityBlaze(null)); + put("Rabbit", () -> new EntityRabbit(null)); + put("Sheep", () -> new EntitySheep(null)); + put("Horse", () -> new EntityHorse(null)); + put("Eisengolem", () -> new EntityIronGolem(null)); + put("Silverfish", () -> new EntitySilverfish(null)); + put("Witch", () -> new EntityWitch(null)); + put("Endermite", () -> new EntityEndermite(null)); + put("Snowman", () -> new EntitySnowman(null)); + put("Villager", () -> new EntityVillager(null)); + put("Guardian", () -> new EntityGuardian(null)); + put("ArmorStand", () -> new EntityArmorStand(null)); + put("Squid", () -> new EntitySquid(null)); + put("Bat", () -> new EntityBat(null)); + put("Spider", () -> new EntitySpider(null)); + put("CaveSpider", () -> new EntityCaveSpider(null)); + put("Pigman", () -> new EntityPigZombie(null)); + put("Ghast", () -> new EntityGhast(null)); + put("MagmaCube", () -> new EntityMagmaCube(null)); + put("Wither", () -> new EntityWither(null)); + put("Enderman", () -> new EntityEnderman(null)); + put("Mooshroom", () -> new EntityMooshroom(null)); + put("WitherSkeleton", () -> { + EntitySkeleton skeleton = new EntitySkeleton(null); + skeleton.setSkeletonType(1); + return skeleton; + }); + put("Cow", () -> new EntityCow(null)); + put("Dragon", () -> new EntityDragon(null)); + put("Player", () -> new GUIClientPlayer()); + put("Pig", () -> new EntityPig(null)); + }}; + + public static Map validModifiers = new HashMap() {{ + put("playerdata", new SkinModifier()); + put("equipment", new EquipmentModifier()); + put("riding", new RidingModifier()); + put("charged", new ChargedModifier()); + put("witherdata", new WitherModifier()); + put("invisible", new InvisibleModifier()); + put("age", new AgeModifier()); + put("horse", new HorseModifier()); + put("name", new NameModifier()); + }}; + + public int guiLeft = 0; + public int guiTop = 0; + public int xSize = 176; + public int ySize = 166; + + private final String label; + private final EntityLivingBase entity; + private static final ResourceLocation BACKGROUND = new ResourceLocation( + "notenoughupdates", + "textures/gui/entity_viewer.png" + ); + + public EntityViewer(String label, EntityLivingBase entity) { + this.label = label; + this.entity = entity; + } + + public static EntityLivingBase constructEntity(ResourceLocation resourceLocation) { + Gson gson = NotEnoughUpdates.INSTANCE.manager.gson; + try ( + Reader is = new InputStreamReader( + Minecraft.getMinecraft().getResourceManager().getResource(resourceLocation).getInputStream(), + StandardCharsets.UTF_8 + ) + ) { + return constructEntity(gson.fromJson(is, JsonObject.class)); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + public static EntityLivingBase constructEntity(JsonObject info) { + List modifiers = info.has("modifiers") ? + StreamSupport.stream(info.get("modifiers").getAsJsonArray().spliterator(), false) + .map(JsonElement::getAsJsonObject).collect(Collectors.toList()) + : Collections.emptyList(); + return EntityViewer.constructEntity(info.get("entity").getAsString(), modifiers); + } + + public static EntityLivingBase constructEntity(String string, String[] modifiers) { + Gson gson = NotEnoughUpdates.INSTANCE.manager.gson; + return constructEntity( + string, + Arrays.stream(modifiers).map(it -> gson.fromJson(it, JsonObject.class)).collect(Collectors.toList()) + ); + } + + public static EntityLivingBase constructEntity(String string, List modifiers) { + Supplier aClass = validEntities.get(string); + if (aClass == null) { + System.err.println("Could not find entity of type: " + string); + return null; + } + try { + EntityLivingBase entity = aClass.get(); + for (JsonObject modifier : modifiers) { + String type = modifier.get("type").getAsString(); + EntityViewerModifier entityViewerModifier = validModifiers.get(type); + entity = entityViewerModifier.applyModifier(entity, modifier); + if (entity == null) break; + } + return entity; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + drawDefaultBackground(); + FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; + + this.guiLeft = (width - this.xSize) / 2; + this.guiTop = (height - this.ySize) / 2; + + Minecraft.getMinecraft().getTextureManager().bindTexture(BACKGROUND); + drawTexturedModalRect(guiLeft, guiTop, 0, 0, this.xSize, this.ySize); + + Utils.drawStringScaledMaxWidth(label, fontRenderer, guiLeft + 10, guiTop + 10, false, 100, 0xFF00FF); + renderEntity(entity, guiLeft + 90, guiTop + 75, mouseX, mouseY); + } + + public static void renderEntity(EntityLivingBase entity, int posX, int posY, int mouseX, int mouseY) { + GlStateManager.color(1F, 1F, 1F, 1F); + + int scale = 30; + float bottomOffset = 0F; + EntityLivingBase stack = entity; + while (true) { + + stack.ticksExisted = Minecraft.getMinecraft().thePlayer.ticksExisted; + GuiInventory.drawEntityOnScreen( + posX, + (int) (posY - bottomOffset * scale), + scale, + posX - mouseX, + (int) (posY - stack.getEyeHeight() * scale - mouseY), + stack + ); + bottomOffset += stack.getMountedYOffset(); + if (!(stack.riddenByEntity instanceof EntityLivingBase)) { + break; + } + stack = (EntityLivingBase) stack.riddenByEntity; + } + + } } -- cgit