Added NEI support for Soul Binder and added black list for powered spawner.

This commit is contained in:
CrazyPants committed 2014-09-05 22:27:54 +08:00
1 parent cb2c4f9bad
commit 2bd229f15a
11 files changed
+341 -18

No files matched your search

@@ -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);
@@ -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");
}
@@ -39,9 +39,4 @@ public class GuiSoulBinder extends GuiMachineBase {
super.drawGuiContainerBackgroundLayer(par1, par2, par3);
}
@Override
protected boolean showRecipeButton() {
return false;
}
}
@@ -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<String> getSupportedSouls();
int getEnergyRequired();
}
@@ -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<String> getSupportedSouls() {
return Collections.singletonList((String)EntityList.classToStringMapping.get(EntityZombie.class));
}
@Override
public int getEnergyRequired() {
return Config.soulBinderReanimationRF;
}
}
@@ -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<String> getSupportedSouls() {
return EntityUtil.getAllRegisteredMobNames(!Config.soulVesselCapturesBosses);
}
@Override
public int getEnergyRequired() {
return Config.soulBinderBrokenSpawnerRF;
}
}
@@ -93,7 +93,7 @@ public class BlockPoweredSpawner extends AbstractMachineBlock<TilePoweredSpawner
MobSpawnerBaseLogic logic = spawner.func_145881_a();
if(logic != null) {
String name = logic.getEntityNameToSpawn();
if(name != null) {
if(name != null && !isBlackListed(name)) {
ItemStack drop = ItemBrokenSpawner.createStackForMobType(name);
Util.dropItems(evt.getPlayer().worldObj, drop, evt.x, evt.y, evt.z, true);
}
@@ -109,16 +109,31 @@ public class BlockPoweredSpawner extends AbstractMachineBlock<TilePoweredSpawner
evt.right == null || ItemBrokenSpawner.getMobTypeFromStack(evt.right) == null) {
return;
}
String spawnerType = ItemBrokenSpawner.getMobTypeFromStack(evt.right);
if(isBlackListed(spawnerType)) {
return;
}
evt.cost = Config.powerSpawnerAddSpawnerCost;
evt.output = evt.left.copy();
if(evt.output.stackTagCompound == null) {
evt.output.stackTagCompound = new NBTTagCompound();
}
evt.output.stackTagCompound.setBoolean("eio.abstractMachine", true);
writeMobTypeToNBT(evt.output.stackTagCompound, ItemBrokenSpawner.getMobTypeFromStack(evt.right));
writeMobTypeToNBT(evt.output.stackTagCompound, spawnerType);
}
public boolean isBlackListed(String entityId) {
for(String str : Config.poweredSpawnerBlackList) {
if(str != null && str.equals(entityId)) {
return true;
}
}
return false;
}
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
@@ -26,6 +26,9 @@ public class NEIEnderIOConfig implements IConfigureNEI {
API.registerRecipeHandler(new SliceAndSpliceRecipeHandler());
API.registerUsageHandler(new SliceAndSpliceRecipeHandler());
API.registerRecipeHandler(new SoulBinderRecipeHandler());
API.registerUsageHandler(new SoulBinderRecipeHandler());
API.hideItem(new ItemStack(EnderIO.blockConduitFacade));
API.hideItem(new ItemStack(EnderIO.itemEnderface));
@@ -57,6 +57,7 @@ public class SagMillRecipeHandler extends TemplateRecipeHandler {
@Override
public void loadTransferRects() {
System.out.println("SagMillRecipeHandler.loadTransferRects: ");
//Set this up later to show all alloy recipes
transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(149, 32, 16, 16), "EnderIOSagMill", new Object[0]));
}
@@ -81,13 +82,11 @@ public class SagMillRecipeHandler extends TemplateRecipeHandler {
@Override
public void loadCraftingRecipes(String outputId, Object... results) {
if(outputId.equals("EnderIOSagMill") && getClass() == SagMillRecipeHandler.class) {
List<Recipe> 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<PositionedStack> otherOutputs;
private float[] outputChance;
private int energy;
// Possible energy cost in the future?
public int getEnergy() {
return energy;
}
@@ -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<? extends GuiContainer> 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<String, IMachineRecipe> 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<String, IMachineRecipe> 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<String, IMachineRecipe> 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<ItemStack> getInputs(RecipeInput input) {
// List<ItemStack> result = new ArrayList<ItemStack>();
// 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<PositionedStack> EMPTY_VIAL_OUTPUT = new ArrayList<PositionedStack>();
static {
EMPTY_VIAL_OUTPUT.add(new PositionedStack(new ItemStack(EnderIO.itemSoulVessel), 107, 23));
}
public class SoulBinderRecipeNEI extends TemplateRecipeHandler.CachedRecipe {
private final ArrayList<PositionedStack> input = new ArrayList<PositionedStack>();
private final PositionedStack output;
private int energy;
public int getEnergy() {
return energy;
}
@Override
public List<PositionedStack> getIngredients() {
return getCycledIngredients(cycleticks / 20, input);
}
@Override
public PositionedStack getResult() {
return output;
}
@Override
public List<PositionedStack> 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<String> 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<ItemStack> getSoulVialInputs(List<String> mobs) {
List<ItemStack> result = new ArrayList<ItemStack>(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;
}
}
}
@@ -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<String> getAllRegisteredMobNames(boolean excludeBosses) {
List<String> result = new ArrayList<String>();
Set<Map.Entry<Class, String>> entries = EntityList.classToStringMapping.entrySet();
for(Map.Entry<Class, String> entry : entries) {
if(EntityLiving.class.isAssignableFrom(entry.getKey()) ) {
if(!excludeBosses || !IBossDisplayData.class.isAssignableFrom(entry.getKey())) {
result.add(entry.getValue());
}
}
}
return result;
}
private EntityUtil() {
}
}