diff --git a/src/main/java/crazypants/enderio/config/Config.java b/src/main/java/crazypants/enderio/config/Config.java index 26c72e3d..75a6ff84 100644 --- a/src/main/java/crazypants/enderio/config/Config.java +++ b/src/main/java/crazypants/enderio/config/Config.java @@ -224,6 +224,9 @@ public final class Config { public static int capacitorBankMaxIoRF = 5000; public static int capacitorBankMaxStorageRF = 5000000; + public static String[] poweredSpawnerBlackList = new String[] { + "VillagerGolem" + }; public static int poweredSpawnerMinDelayTicks = 200; public static int poweredSpawnerMaxDelayTicks = 800; public static int poweredSpawnerLevelOnePowerPerTickRF = 250; @@ -697,6 +700,8 @@ public final class Config { "The chance a brokne spawner will be dropped when a spawner is broken. 1 = 100% chance, 0 = 0% chance").getDouble(brokenSpawnerDropChance); powerSpawnerAddSpawnerCost = config.get(sectionSpawner.name, "powerSpawnerAddSpawnerCost", powerSpawnerAddSpawnerCost, "The number of levels it costs to add a broken spawner").getInt(powerSpawnerAddSpawnerCost); + poweredSpawnerBlackList = config.getStringList("poweredSpawnerBlackList", sectionSpawner.name, poweredSpawnerBlackList, + "Lists mobs that can not be used to create a powered spawner"); useModMetals = config.get(sectionRecipe.name, "useModMetals", useModMetals, "If true copper and tin will be used in recipes when registered in the ore dictionary").getBoolean(useModMetals); diff --git a/src/main/java/crazypants/enderio/item/ItemSoulVessel.java b/src/main/java/crazypants/enderio/item/ItemSoulVessel.java index 30e0fa46..34200f30 100644 --- a/src/main/java/crazypants/enderio/item/ItemSoulVessel.java +++ b/src/main/java/crazypants/enderio/item/ItemSoulVessel.java @@ -14,6 +14,7 @@ import crazypants.enderio.gui.IResourceTooltipProvider; import crazypants.enderio.gui.TooltipAddera; import crazypants.enderio.material.Material; import crazypants.enderio.network.PacketHandler; +import crazypants.util.EntityUtil; import net.minecraft.block.Block; import net.minecraft.block.BlockFence; import net.minecraft.block.BlockWall; @@ -162,6 +163,7 @@ public class ItemSoulVessel extends Item implements IResourceTooltipProvider { } String entityId = EntityList.getEntityString(entity); + System.out.println("ItemSoulVessel.itemInteractionForEntity: " + entityId); if(isBlackListed(entityId)) { return false; } @@ -228,7 +230,7 @@ public class ItemSoulVessel extends Item implements IResourceTooltipProvider { if(par1ItemStack != null) { String mobName = getMobTypeFromStack(par1ItemStack); if(mobName != null) { - par3List.add(StatCollector.translateToLocal("entity." + mobName + ".name")); + par3List.add(EntityUtil.getDisplayNameForEntity(mobName)); } else { par3List.add("Empty"); } diff --git a/src/main/java/crazypants/enderio/machine/soul/GuiSoulBinder.java b/src/main/java/crazypants/enderio/machine/soul/GuiSoulBinder.java index 464fa7fd..49b6cb6b 100644 --- a/src/main/java/crazypants/enderio/machine/soul/GuiSoulBinder.java +++ b/src/main/java/crazypants/enderio/machine/soul/GuiSoulBinder.java @@ -39,9 +39,4 @@ public class GuiSoulBinder extends GuiMachineBase { super.drawGuiContainerBackgroundLayer(par1, par2, par3); } - @Override - protected boolean showRecipeButton() { - return false; - } - } diff --git a/src/main/java/crazypants/enderio/machine/soul/ISoulBinderRecipe.java b/src/main/java/crazypants/enderio/machine/soul/ISoulBinderRecipe.java new file mode 100644 index 00000000..5f9fe1b5 --- /dev/null +++ b/src/main/java/crazypants/enderio/machine/soul/ISoulBinderRecipe.java @@ -0,0 +1,17 @@ +package crazypants.enderio.machine.soul; + +import java.util.List; + +import net.minecraft.item.ItemStack; + +public interface ISoulBinderRecipe { + + ItemStack getInputStack(); + + ItemStack getOutputStack(); + + List getSupportedSouls(); + + int getEnergyRequired(); + +} diff --git a/src/main/java/crazypants/enderio/machine/soul/SoulBinderReanimationRecipe.java b/src/main/java/crazypants/enderio/machine/soul/SoulBinderReanimationRecipe.java index ee7deda7..bdcc8967 100644 --- a/src/main/java/crazypants/enderio/machine/soul/SoulBinderReanimationRecipe.java +++ b/src/main/java/crazypants/enderio/machine/soul/SoulBinderReanimationRecipe.java @@ -1,19 +1,20 @@ package crazypants.enderio.machine.soul; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import net.minecraft.entity.EntityList; +import net.minecraft.entity.monster.EntityZombie; import net.minecraft.item.ItemStack; import crazypants.enderio.EnderIO; import crazypants.enderio.ModObject; import crazypants.enderio.config.Config; -import crazypants.enderio.item.ItemSoulVessel; import crazypants.enderio.machine.IMachineRecipe; import crazypants.enderio.machine.MachineRecipeInput; -import crazypants.enderio.machine.IMachineRecipe.ResultStack; import crazypants.enderio.material.FrankenSkull; -public class SoulBinderReanimationRecipe implements IMachineRecipe { +public class SoulBinderReanimationRecipe implements IMachineRecipe, ISoulBinderRecipe { public static SoulBinderReanimationRecipe instance = new SoulBinderReanimationRecipe(); @@ -97,7 +98,28 @@ public class SoulBinderReanimationRecipe implements IMachineRecipe { } boolean isZombie(String mobType) { - return mobType != null && mobType.equals("Zombie"); + //return mobType != null && mobType.equals("Zombie"); + return mobType != null && mobType.equals(EntityList.classToStringMapping.get(EntityZombie.class)); + } + + @Override + public ItemStack getInputStack() { + return new ItemStack(EnderIO.itemFrankenSkull, 1, FrankenSkull.ZOMBIE_CONTROLLER.ordinal()); + } + + @Override + public ItemStack getOutputStack() { + return new ItemStack(EnderIO.itemFrankenSkull, 1, FrankenSkull.FRANKEN_ZOMBIE.ordinal()); + } + + @Override + public List getSupportedSouls() { + return Collections.singletonList((String)EntityList.classToStringMapping.get(EntityZombie.class)); + } + + @Override + public int getEnergyRequired() { + return Config.soulBinderReanimationRF; } } diff --git a/src/main/java/crazypants/enderio/machine/soul/SoulBinderSpawnerRecipe.java b/src/main/java/crazypants/enderio/machine/soul/SoulBinderSpawnerRecipe.java index 1bc9f891..eee20a36 100644 --- a/src/main/java/crazypants/enderio/machine/soul/SoulBinderSpawnerRecipe.java +++ b/src/main/java/crazypants/enderio/machine/soul/SoulBinderSpawnerRecipe.java @@ -2,15 +2,20 @@ package crazypants.enderio.machine.soul; import java.util.ArrayList; import java.util.List; +import java.util.Set; +import cpw.mods.fml.common.registry.EntityRegistry; + +import net.minecraft.entity.EntityList; import net.minecraft.item.ItemStack; import crazypants.enderio.EnderIO; import crazypants.enderio.ModObject; import crazypants.enderio.config.Config; import crazypants.enderio.machine.IMachineRecipe; import crazypants.enderio.machine.MachineRecipeInput; +import crazypants.util.EntityUtil; -public class SoulBinderSpawnerRecipe implements IMachineRecipe { +public class SoulBinderSpawnerRecipe implements IMachineRecipe, ISoulBinderRecipe { public static SoulBinderSpawnerRecipe instance = new SoulBinderSpawnerRecipe(); @@ -69,7 +74,8 @@ public class SoulBinderSpawnerRecipe implements IMachineRecipe { int slot = input.slotNumber; ItemStack item = input.item; if(slot == 0) { - return EnderIO.itemSoulVessel.containsSoul(item); + String mobType = EnderIO.itemSoulVessel.getMobTypeFromStack(item); + return mobType != null && !EnderIO.blockPoweredSpawner.isBlackListed(mobType); } if(slot == 1) { return item.getItem() == EnderIO.itemBrokenSpawner; @@ -77,6 +83,15 @@ public class SoulBinderSpawnerRecipe implements IMachineRecipe { return false; } + private boolean isBlackListed(String entityId) { + for(String str : Config.poweredSpawnerBlackList) { + if(str != null && str.equals(entityId)) { + return true; + } + } + return false; + } + @Override public String getMachineName() { return ModObject.blockSoulBinder.unlocalisedName; @@ -96,4 +111,25 @@ public class SoulBinderSpawnerRecipe implements IMachineRecipe { return result; } + @Override + public ItemStack getInputStack() { + return new ItemStack(EnderIO.itemBrokenSpawner); + } + + @Override + public ItemStack getOutputStack() { + return new ItemStack(EnderIO.itemBrokenSpawner); + } + + @Override + public List getSupportedSouls() { + return EntityUtil.getAllRegisteredMobNames(!Config.soulVesselCapturesBosses); + } + + @Override + public int getEnergyRequired() { + return Config.soulBinderBrokenSpawnerRF; + } + + } diff --git a/src/main/java/crazypants/enderio/machine/spawner/BlockPoweredSpawner.java b/src/main/java/crazypants/enderio/machine/spawner/BlockPoweredSpawner.java index 26e5ea24..0613e11b 100644 --- a/src/main/java/crazypants/enderio/machine/spawner/BlockPoweredSpawner.java +++ b/src/main/java/crazypants/enderio/machine/spawner/BlockPoweredSpawner.java @@ -93,7 +93,7 @@ public class BlockPoweredSpawner extends AbstractMachineBlock recipes = CrusherRecipeManager.getInstance().getRecipes(); for (Recipe recipe : recipes) { MillRecipe res = new MillRecipe(recipe.getEnergyRequired(), recipe.getInputs()[0], recipe.getOutputs()); arecipes.add(res); } - } else { super.loadCraftingRecipes(outputId, results); } @@ -178,8 +177,7 @@ public class SagMillRecipeHandler extends TemplateRecipeHandler { private ArrayList otherOutputs; private float[] outputChance; private int energy; - - // Possible energy cost in the future? + public int getEnergy() { return energy; } diff --git a/src/main/java/crazypants/enderio/nei/SoulBinderRecipeHandler.java b/src/main/java/crazypants/enderio/nei/SoulBinderRecipeHandler.java new file mode 100644 index 00000000..6a19a6e8 --- /dev/null +++ b/src/main/java/crazypants/enderio/nei/SoulBinderRecipeHandler.java @@ -0,0 +1,195 @@ +package crazypants.enderio.nei; + +import java.awt.Rectangle; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.resources.I18n; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentData; +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import codechicken.nei.PositionedStack; +import codechicken.nei.recipe.TemplateRecipeHandler; +import crazypants.enderio.EnderIO; +import crazypants.enderio.ModObject; +import crazypants.enderio.machine.IMachineRecipe; +import crazypants.enderio.machine.MachineRecipeInput; +import crazypants.enderio.machine.MachineRecipeRegistry; +import crazypants.enderio.machine.enchanter.EnchanterRecipe; +import crazypants.enderio.machine.enchanter.EnchanterRecipeManager; +import crazypants.enderio.machine.enchanter.GuiEnchanter; +import crazypants.enderio.machine.enchanter.TileEnchanter; +import crazypants.enderio.machine.recipe.RecipeInput; +import crazypants.enderio.machine.soul.GuiSoulBinder; +import crazypants.enderio.machine.soul.ISoulBinderRecipe; +import crazypants.enderio.nei.EnchanterRecipeHandler.EnchanterRecipeNEI; + +public class SoulBinderRecipeHandler extends TemplateRecipeHandler { + + @Override + public String getRecipeName() { + return "Soul Binder"; + } + + @Override + public String getGuiTexture() { + return "enderio:textures/gui/soulFuser.png"; + } + + @Override + public Class getGuiClass() { + return GuiSoulBinder.class; + } + + @Override + public String getOverlayIdentifier() { + return "EnderIOSoulBinder"; + } + + @Override + public void loadTransferRects() { + transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(149, 32, 16, 16), "EnderIOSoulBinder", new Object[0])); + } + + @Override + public void loadCraftingRecipes(ItemStack result) { + if(result == null || result.getItem() == null) { + return; + } + + Map recipes = MachineRecipeRegistry.instance.getRecipesForMachine(ModObject.blockSoulBinder.unlocalisedName); + if(recipes.isEmpty()) { + return; + } + for (IMachineRecipe recipe : recipes.values()) { + if(recipe instanceof ISoulBinderRecipe) { + ISoulBinderRecipe sbr = (ISoulBinderRecipe) recipe; + if(sbr.getOutputStack().isItemEqual(result)) { + arecipes.add(new SoulBinderRecipeNEI((ISoulBinderRecipe) recipe)); + } + } + } + } + + @Override + public void loadCraftingRecipes(String outputId, Object... results) { + + if(outputId.equals("EnderIOSoulBinder") && getClass() == SoulBinderRecipeHandler.class) { + Map recipes = MachineRecipeRegistry.instance.getRecipesForMachine(ModObject.blockSoulBinder.unlocalisedName); + if(recipes.isEmpty()) { + return; + } + for (IMachineRecipe recipe : recipes.values()) { + if(recipe instanceof ISoulBinderRecipe) { + arecipes.add(new SoulBinderRecipeNEI((ISoulBinderRecipe) recipe)); + } + } + } else { + super.loadCraftingRecipes(outputId, results); + } + } + + @Override + public void loadUsageRecipes(ItemStack ingredient) { + + if(ingredient == null || ingredient.getItem() == null) { + return; + } + + Map recipes = MachineRecipeRegistry.instance.getRecipesForMachine(ModObject.blockSoulBinder.unlocalisedName); + if(recipes.isEmpty()) { + return; + } + for (IMachineRecipe recipe : recipes.values()) { + if(recipe instanceof ISoulBinderRecipe) { + ISoulBinderRecipe sbr = (ISoulBinderRecipe) recipe; + if(sbr.getInputStack().isItemEqual(ingredient)) { + arecipes.add(new SoulBinderRecipeNEI((ISoulBinderRecipe) recipe)); + } + } + } + + } + + @Override + public void drawExtras(int recipeIndex) { + } + + // public List getInputs(RecipeInput input) { + // List result = new ArrayList(); + // result.add(input.getInput()); + // ItemStack[] equivs = input.getEquivelentInputs(); + // if(equivs != null && equivs.length > 0) { + // result.addAll(Arrays.asList(equivs)); + // } + // return result; + // } + + private static final ArrayList EMPTY_VIAL_OUTPUT = new ArrayList(); + static { + EMPTY_VIAL_OUTPUT.add(new PositionedStack(new ItemStack(EnderIO.itemSoulVessel), 107, 23)); + } + + public class SoulBinderRecipeNEI extends TemplateRecipeHandler.CachedRecipe { + + private final ArrayList input = new ArrayList(); + + private final PositionedStack output; + + private int energy; + + public int getEnergy() { + return energy; + } + + @Override + public List getIngredients() { + return getCycledIngredients(cycleticks / 20, input); + } + + @Override + public PositionedStack getResult() { + return output; + } + + @Override + public List getOtherStacks() { + return EMPTY_VIAL_OUTPUT; + } + + public SoulBinderRecipeNEI(ISoulBinderRecipe recipe) { + this(recipe.getInputStack(), recipe.getOutputStack(), recipe.getEnergyRequired(), recipe.getSupportedSouls()); + } + + public SoulBinderRecipeNEI(ItemStack inputStack, ItemStack result, int energy, List list) { + + int yOff = 11; + int xOff = 6; + + input.add(new PositionedStack(getSoulVialInputs(list), 38 - xOff, 34 - yOff)); + input.add(new PositionedStack(inputStack, 60 - xOff, 34 - yOff)); + output = new PositionedStack(result, 134 - xOff, 34 - yOff); + + } + + private List getSoulVialInputs(List mobs) { + List result = new ArrayList(mobs.size()); + for (String mobName : mobs) { + ItemStack sv = new ItemStack(EnderIO.itemSoulVessel); + sv.stackTagCompound = new NBTTagCompound(); + sv.stackTagCompound.setString("id", mobName); + result.add(sv); + } + return result; + } + } + +} diff --git a/src/main/java/crazypants/util/EntityUtil.java b/src/main/java/crazypants/util/EntityUtil.java new file mode 100644 index 00000000..02ac8299 --- /dev/null +++ b/src/main/java/crazypants/util/EntityUtil.java @@ -0,0 +1,35 @@ +package crazypants.util; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import net.minecraft.entity.EntityList; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.boss.IBossDisplayData; +import net.minecraft.util.StatCollector; + +public class EntityUtil { + + public static String getDisplayNameForEntity(String mobName) { + return StatCollector.translateToLocal("entity." + mobName + ".name"); + } + + public static List getAllRegisteredMobNames(boolean excludeBosses) { + List result = new ArrayList(); + Set> entries = EntityList.classToStringMapping.entrySet(); + for(Map.Entry entry : entries) { + if(EntityLiving.class.isAssignableFrom(entry.getKey()) ) { + if(!excludeBosses || !IBossDisplayData.class.isAssignableFrom(entry.getKey())) { + result.add(entry.getValue()); + } + } + } + return result; + } + + private EntityUtil() { + } + +}