aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java7
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java7
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/recipes/MobLootRecipe.java172
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/recipes/RecipeType.java3
-rw-r--r--src/main/resources/assets/notenoughupdates/textures/gui/mob_loot_tall.pngbin0 -> 9503 bytes
5 files changed, 185 insertions, 4 deletions
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 cf2f0300..cfce7207 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
@@ -143,19 +143,24 @@ public class EntityViewer extends GuiScreen {
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) {
- GuiInventory.drawEntityOnScreen(guiLeft + 90, (int) (guiTop + 75 - bottomOffset * scale), scale, guiLeft - mouseX + 80, guiTop + 60 - mouseY, stack);
+
+ 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;
}
+
}
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java
index 469a91f3..127fa911 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java
@@ -6,12 +6,15 @@ import io.github.moulberry.notenoughupdates.recipes.NeuRecipe;
import io.github.moulberry.notenoughupdates.recipes.RecipeSlot;
import io.github.moulberry.notenoughupdates.recipes.RecipeType;
import io.github.moulberry.notenoughupdates.util.Utils;
+import net.minecraft.block.state.BlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.InventoryPlayer;
+import net.minecraft.init.Blocks;
+import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.MathHelper;
@@ -234,8 +237,8 @@ public class GuiItemRecipe extends GuiScreen {
for (RecipeSlot slot : getAllRenderedSlots()) {
if (isWithinRect(mouseX, mouseY, slot.getX(this), slot.getY(this), SLOT_SIZE, SLOT_SIZE)) {
ItemStack itemStack = slot.getItemStack();
- if (keyPressed == manager.keybindViewRecipe.getKeyCode()) { // TODO: rework this so it doesnt skip recipe chains
- manager.displayGuiItemRecipe(manager.getInternalNameForItem(itemStack), "");
+ if (keyPressed == manager.keybindViewRecipe.getKeyCode()) {
+ manager.displayGuiItemRecipe(manager.getInternalNameForItem(itemStack), null);
} else if (keyPressed == manager.keybindViewUsages.getKeyCode()) {
manager.displayGuiItemUsages(manager.getInternalNameForItem(itemStack));
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/recipes/MobLootRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/recipes/MobLootRecipe.java
new file mode 100644
index 00000000..7d81c9c3
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/recipes/MobLootRecipe.java
@@ -0,0 +1,172 @@
+package io.github.moulberry.notenoughupdates.recipes;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import io.github.moulberry.notenoughupdates.NEUManager;
+import io.github.moulberry.notenoughupdates.miscfeatures.entityviewer.EntityViewer;
+import io.github.moulberry.notenoughupdates.miscgui.GuiItemRecipe;
+import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.util.ResourceLocation;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+public class MobLootRecipe implements NeuRecipe {
+
+ private static final int MOB_POS_X = 38, MOB_POS_Y = 100;
+ private static final int SLOT_POS_X = 82, SLOT_POS_Y = 23;
+
+ public static class MobDrop {
+ public final Ingredient drop;
+ public final String chance;
+ public final List<String> extra;
+
+ public MobDrop(Ingredient drop, String chance, List<String> extra) {
+ this.drop = drop;
+ this.chance = chance;
+ this.extra = extra;
+ }
+ }
+
+ public static ResourceLocation BACKGROUND = new ResourceLocation("notenoughupdates", "textures/gui/mob_loot_tall.png");
+ private final List<MobDrop> drops;
+ private final int coins;
+ private final int combatXp;
+ private final int xp;
+ private final String name;
+ private final String render;
+ private EntityLivingBase entityLivingBase;
+
+ public MobLootRecipe(List<MobDrop> drops, int coins, int xp, int combatXp, String name, String render) {
+ this.drops = drops;
+ this.coins = coins;
+ this.xp = xp;
+ this.combatXp = combatXp;
+ this.name = name;
+ this.render = render;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public List<MobDrop> getDrops() {
+ return drops;
+ }
+
+ public int getCoins() {
+ return coins;
+ }
+
+ public int getCombatXp() {
+ return combatXp;
+ }
+
+ public int getXp() {
+ return xp;
+ }
+
+ public String getRender() {
+ return render;
+ }
+
+ public synchronized EntityLivingBase getRenderEntity() {
+ if (entityLivingBase == null) {
+ if (render.startsWith("@")) {
+ entityLivingBase = EntityViewer.constructEntity(new ResourceLocation(render.substring(1)));
+ } else {
+ entityLivingBase = EntityViewer.constructEntity(render, Collections.emptyList());
+ }
+ }
+ return entityLivingBase;
+ }
+
+ @Override
+ public Set<Ingredient> getIngredients() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public Set<Ingredient> getOutputs() {
+ return drops.stream().map(it -> it.drop).collect(Collectors.toSet());
+ }
+
+ @Override
+ public List<RecipeSlot> getSlots() {
+ List<RecipeSlot> slots = new ArrayList<>();
+ for (int i = 0; i < drops.size(); i++) {
+ MobDrop mobDrop = drops.get(i);
+ int x = i % 5;
+ int y = i / 5;
+ slots.add(new RecipeSlot(
+ SLOT_POS_X + x * 16,
+ SLOT_POS_Y + y * 16,
+ mobDrop.drop.getItemStack()
+ ));
+ }
+ return slots;
+ }
+
+ @Override
+ public RecipeType getType() {
+ return RecipeType.MOB_LOOT;
+ }
+
+ @Override
+ public boolean shouldUseForCraftCost() {
+ return false;
+ }
+
+ @Override
+ public boolean hasVariableCost() {
+ return true;
+ }
+
+ @Override
+ public void drawExtraBackground(GuiItemRecipe gui, int mouseX, int mouseY) {
+ EntityViewer.renderEntity(getRenderEntity(), gui.guiLeft + MOB_POS_X, gui.guiLeft + MOB_POS_Y, mouseX, mouseY);
+ }
+
+ @Override
+ public JsonObject serialize() {
+ return null; //TODO
+ }
+
+ @Override
+ public ResourceLocation getBackground() {
+ return BACKGROUND;
+ }
+
+ public static MobLootRecipe parseRecipe(NEUManager manager, JsonObject recipe, JsonObject outputItemJson) {
+ List<MobDrop> drops = new ArrayList<>();
+ for (JsonElement jsonElement : recipe.getAsJsonArray("drops")) {
+ if (jsonElement.isJsonPrimitive()) {
+ drops.add(new MobDrop(new Ingredient(manager, jsonElement.getAsString()), null, Collections.emptyList()));
+ } else {
+ JsonObject jsonObject = jsonElement.getAsJsonObject();
+ drops.add(
+ new MobDrop(
+ new Ingredient(manager, jsonObject.get("id").getAsString()),
+ jsonObject.has("chance") ? jsonObject.get("chance").getAsString() : null,
+ jsonObject.has("extra") ?
+ StreamSupport.stream(jsonObject.getAsJsonArray("extra").spliterator(), false)
+ .map(JsonElement::getAsString)
+ .collect(Collectors.toList()) : Collections.emptyList()
+ ));
+ }
+ }
+
+ return new MobLootRecipe(
+ drops,
+ recipe.has("coins") ? recipe.get("coins").getAsInt() : 0,
+ recipe.has("xp") ? recipe.get("xp").getAsInt() : 0,
+ recipe.has("combat_xp") ? recipe.get("combat_xp").getAsInt() : 0,
+ recipe.get("name").getAsString(),
+ recipe.get("render").getAsString()
+ );
+ }
+}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/recipes/RecipeType.java b/src/main/java/io/github/moulberry/notenoughupdates/recipes/RecipeType.java
index ae00c316..6ef319cb 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/recipes/RecipeType.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/recipes/RecipeType.java
@@ -7,7 +7,8 @@ import net.minecraft.util.ResourceLocation;
public enum RecipeType {
CRAFTING("crafting", "Crafting", CraftingRecipe::parseCraftingRecipe),
FORGE("forge", "Forge", ForgeRecipe::parseForgeRecipe),
- TRADE("trade", "Trade", VillagerTradeRecipe::parseStaticRecipe);
+ TRADE("trade", "Trade", VillagerTradeRecipe::parseStaticRecipe),
+ MOB_LOOT("drops", "Mob Loot", MobLootRecipe::parseRecipe);
private final String id;
private final String label;
diff --git a/src/main/resources/assets/notenoughupdates/textures/gui/mob_loot_tall.png b/src/main/resources/assets/notenoughupdates/textures/gui/mob_loot_tall.png
new file mode 100644
index 00000000..facd6d6c
--- /dev/null
+++ b/src/main/resources/assets/notenoughupdates/textures/gui/mob_loot_tall.png
Binary files differ