diff --git a/src/main/java/com/oitsjustjose/criss_cross/Blocks/BlockCropomator.java b/src/main/java/com/oitsjustjose/criss_cross/Blocks/BlockCropomator.java index ae59551..8bd05cc 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/Blocks/BlockCropomator.java +++ b/src/main/java/com/oitsjustjose/criss_cross/Blocks/BlockCropomator.java @@ -108,7 +108,8 @@ public class BlockCropomator extends BlockMachineBase if (world.isRemote) { return true; - } else + } + else { TileEntityCropomator tilecropomator = (TileEntityCropomator) world.getTileEntity(x, y, z); if (tilecropomator != null) diff --git a/src/main/java/com/oitsjustjose/criss_cross/Blocks/BlockElectroextractor.java b/src/main/java/com/oitsjustjose/criss_cross/Blocks/BlockElectroextractor.java index 3a97e0a..af77d58 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/Blocks/BlockElectroextractor.java +++ b/src/main/java/com/oitsjustjose/criss_cross/Blocks/BlockElectroextractor.java @@ -108,7 +108,8 @@ public class BlockElectroextractor extends BlockMachineBase if (world.isRemote) { return true; - } else + } + else { TileEntityElectroextractor tileext = (TileEntityElectroextractor) world.getTileEntity(x, y, z); if (tileext != null) diff --git a/src/main/java/com/oitsjustjose/criss_cross/Blocks/BlockWoodchipper.java b/src/main/java/com/oitsjustjose/criss_cross/Blocks/BlockWoodchipper.java index da06b3a..1efba26 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/Blocks/BlockWoodchipper.java +++ b/src/main/java/com/oitsjustjose/criss_cross/Blocks/BlockWoodchipper.java @@ -107,7 +107,8 @@ public class BlockWoodchipper extends BlockMachineBase if (world.isRemote) { return true; - } else + } + else { TileEntityWoodchipper tileext = (TileEntityWoodchipper) world.getTileEntity(x, y, z); if (tileext != null) diff --git a/src/main/java/com/oitsjustjose/criss_cross/Blocks/CCBlocks.java b/src/main/java/com/oitsjustjose/criss_cross/Blocks/CCBlocks.java index 7a31fd9..9ea20ac 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/Blocks/CCBlocks.java +++ b/src/main/java/com/oitsjustjose/criss_cross/Blocks/CCBlocks.java @@ -4,10 +4,18 @@ import com.oitsjustjose.criss_cross.CrissCross; import com.oitsjustjose.criss_cross.GUI.GUIHandler; import com.oitsjustjose.criss_cross.Recipes.CropomatorRecipes; import com.oitsjustjose.criss_cross.Recipes.ElectroextractorRecipes; +import com.oitsjustjose.criss_cross.Recipes.CCMachineRecipes; import com.oitsjustjose.criss_cross.Recipes.WoodchipperRecipes; +import com.oitsjustjose.criss_cross.TileEntity.TileEntityElectroextractor; +import com.oitsjustjose.criss_cross.Util.CCLog; +import com.oitsjustjose.criss_cross.Util.ConfigHandler; import cpw.mods.fml.common.network.NetworkRegistry; +import cpw.mods.fml.common.registry.GameRegistry; import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; public class CCBlocks { @@ -18,16 +26,8 @@ public class CCBlocks public static void init() { cropomator = new BlockCropomator(); - CropomatorRecipes.initRecipes(); - CropomatorRecipes.initCatalysts(); - electroextractor = new BlockElectroextractor(); - ElectroextractorRecipes.initRecipes(); - ElectroextractorRecipes.initFuels(); - woodchipper = new BlockWoodchipper(); - WoodchipperRecipes.initRecipes(); - WoodchipperRecipes.initFuels(); NetworkRegistry.INSTANCE.registerGuiHandler(CrissCross.instance, new GUIHandler()); } diff --git a/src/main/java/com/oitsjustjose/criss_cross/Container/ContainerCropomator.java b/src/main/java/com/oitsjustjose/criss_cross/Container/ContainerCropomator.java index 4fac611..5e07189 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/Container/ContainerCropomator.java +++ b/src/main/java/com/oitsjustjose/criss_cross/Container/ContainerCropomator.java @@ -104,39 +104,50 @@ public class ContainerCropomator extends Container } slot.onSlotChange(itemstack1, itemstack); - } else if (slotID != 1 && slotID != 0) - { - if (TileEntityCropomator.isValidForCropomator(itemstack1)) - { - if (!this.mergeItemStack(itemstack1, 0, 1, false)) - { - return null; - } - } else if (TileEntityCropomator.isItemCatalyst(itemstack1)) - { - if (!this.mergeItemStack(itemstack1, 1, 2, false)) - { - return null; - } - } else if (slotID >= 3 && slotID < 30) - { - if (!this.mergeItemStack(itemstack1, 30, 39, false)) - { - return null; - } - } else if (slotID >= 30 && slotID < 39 && !this.mergeItemStack(itemstack1, 3, 30, false)) - { - return null; - } - } else if (!this.mergeItemStack(itemstack1, 3, 39, false)) - { - return null; } + else + if (slotID != 1 && slotID != 0) + { + if (TileEntityCropomator.isValid(itemstack1)) + { + if (!this.mergeItemStack(itemstack1, 0, 1, false)) + { + return null; + } + } + else + if (TileEntityCropomator.isItemCatalyst(itemstack1)) + { + if (!this.mergeItemStack(itemstack1, 1, 2, false)) + { + return null; + } + } + else + if (slotID >= 3 && slotID < 30) + { + if (!this.mergeItemStack(itemstack1, 30, 39, false)) + { + return null; + } + } + else + if (slotID >= 30 && slotID < 39 && !this.mergeItemStack(itemstack1, 3, 30, false)) + { + return null; + } + } + else + if (!this.mergeItemStack(itemstack1, 3, 39, false)) + { + return null; + } if (itemstack1.stackSize == 0) { slot.putStack((ItemStack) null); - } else + } + else { slot.onSlotChanged(); } diff --git a/src/main/java/com/oitsjustjose/criss_cross/Container/ContainerElectroextractor.java b/src/main/java/com/oitsjustjose/criss_cross/Container/ContainerElectroextractor.java index 835257e..05da943 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/Container/ContainerElectroextractor.java +++ b/src/main/java/com/oitsjustjose/criss_cross/Container/ContainerElectroextractor.java @@ -102,39 +102,50 @@ public class ContainerElectroextractor extends Container } slot.onSlotChange(itemstack1, itemstack); - } else if (slotID != 1 && slotID != 0) - { - if (TileEntityElectroextractor.isValidForElectroextractor(itemstack1)) - { - if (!this.mergeItemStack(itemstack1, 0, 1, false)) - { - return null; - } - } else if (TileEntityElectroextractor.isItemEnergetic(itemstack1)) - { - if (!this.mergeItemStack(itemstack1, 1, 2, false)) - { - return null; - } - } else if (slotID >= 3 && slotID < 30) - { - if (!this.mergeItemStack(itemstack1, 30, 39, false)) - { - return null; - } - } else if (slotID >= 30 && slotID < 39 && !this.mergeItemStack(itemstack1, 3, 30, false)) - { - return null; - } - } else if (!this.mergeItemStack(itemstack1, 3, 39, false)) - { - return null; } + else + if (slotID != 1 && slotID != 0) + { + if (TileEntityElectroextractor.isValid(itemstack1)) + { + if (!this.mergeItemStack(itemstack1, 0, 1, false)) + { + return null; + } + } + else + if (TileEntityElectroextractor.isItemEnergetic(itemstack1)) + { + if (!this.mergeItemStack(itemstack1, 1, 2, false)) + { + return null; + } + } + else + if (slotID >= 3 && slotID < 30) + { + if (!this.mergeItemStack(itemstack1, 30, 39, false)) + { + return null; + } + } + else + if (slotID >= 30 && slotID < 39 && !this.mergeItemStack(itemstack1, 3, 30, false)) + { + return null; + } + } + else + if (!this.mergeItemStack(itemstack1, 3, 39, false)) + { + return null; + } if (itemstack1.stackSize == 0) { slot.putStack((ItemStack) null); - } else + } + else { slot.onSlotChanged(); } diff --git a/src/main/java/com/oitsjustjose/criss_cross/Container/ContainerWoodchipper.java b/src/main/java/com/oitsjustjose/criss_cross/Container/ContainerWoodchipper.java index b59438f..e8b319b 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/Container/ContainerWoodchipper.java +++ b/src/main/java/com/oitsjustjose/criss_cross/Container/ContainerWoodchipper.java @@ -100,39 +100,50 @@ public class ContainerWoodchipper extends Container } slot.onSlotChange(itemstack1, itemstack); - } else if (slotID != 1 && slotID != 0) - { - if (TileEntityWoodchipper.isValidForWoodchipper(itemstack1)) - { - if (!this.mergeItemStack(itemstack1, 0, 1, false)) - { - return null; - } - } else if (TileEntityWoodchipper.isItemFuel(itemstack1)) - { - if (!this.mergeItemStack(itemstack1, 1, 2, false)) - { - return null; - } - } else if (slotID >= 3 && slotID < 30) - { - if (!this.mergeItemStack(itemstack1, 30, 39, false)) - { - return null; - } - } else if (slotID >= 30 && slotID < 39 && !this.mergeItemStack(itemstack1, 3, 30, false)) - { - return null; - } - } else if (!this.mergeItemStack(itemstack1, 3, 39, false)) - { - return null; } + else + if (slotID != 1 && slotID != 0) + { + if (TileEntityWoodchipper.isValidForWoodchipper(itemstack1)) + { + if (!this.mergeItemStack(itemstack1, 0, 1, false)) + { + return null; + } + } + else + if (TileEntityWoodchipper.isItemFuel(itemstack1)) + { + if (!this.mergeItemStack(itemstack1, 1, 2, false)) + { + return null; + } + } + else + if (slotID >= 3 && slotID < 30) + { + if (!this.mergeItemStack(itemstack1, 30, 39, false)) + { + return null; + } + } + else + if (slotID >= 30 && slotID < 39 && !this.mergeItemStack(itemstack1, 3, 30, false)) + { + return null; + } + } + else + if (!this.mergeItemStack(itemstack1, 3, 39, false)) + { + return null; + } if (itemstack1.stackSize == 0) { slot.putStack((ItemStack) null); - } else + } + else { slot.onSlotChanged(); } diff --git a/src/main/java/com/oitsjustjose/criss_cross/CrissCross.java b/src/main/java/com/oitsjustjose/criss_cross/CrissCross.java index 98e8a45..c691133 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/CrissCross.java +++ b/src/main/java/com/oitsjustjose/criss_cross/CrissCross.java @@ -2,20 +2,22 @@ package com.oitsjustjose.criss_cross; import com.oitsjustjose.criss_cross.Blocks.CCBlocks; import com.oitsjustjose.criss_cross.Items.CCItems; -import com.oitsjustjose.criss_cross.Recipes.CCRecipes; +import com.oitsjustjose.criss_cross.Recipes.CCCraftingRecipes; +import com.oitsjustjose.criss_cross.Recipes.CCMachineRecipes; +import com.oitsjustjose.criss_cross.Util.CCTab; import com.oitsjustjose.criss_cross.Util.CommonProxy; import com.oitsjustjose.criss_cross.Util.ConfigHandler; import com.oitsjustjose.criss_cross.Util.OreDictionaryAdder; import com.oitsjustjose.criss_cross.Util.Reference; import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; -import com.oitsjustjose.criss_cross.Util.CCTab; import net.minecraft.creativetab.CreativeTabs; @Mod(modid = Reference.modid, version = Reference.version, guiFactory = Reference.guifactory) @@ -43,8 +45,9 @@ public class CrissCross { CCBlocks.init(); CCItems.init(); - CCRecipes.init(); + CCCraftingRecipes.init(); OreDictionaryAdder.init(); + CCMachineRecipes.init(); proxy.init(); } } \ No newline at end of file diff --git a/src/main/java/com/oitsjustjose/criss_cross/Items/ItemDust.java b/src/main/java/com/oitsjustjose/criss_cross/Items/ItemDust.java index d9d257a..d368f1d 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/Items/ItemDust.java +++ b/src/main/java/com/oitsjustjose/criss_cross/Items/ItemDust.java @@ -88,7 +88,8 @@ public class ItemDust extends Item if (stack.getItemDamage() >= colors.size()) return 0; return colors.get(stack.getItemDamage()); - } else + } + else return 16777215; } diff --git a/src/main/java/com/oitsjustjose/criss_cross/NEI/CCNEIIntegration.java b/src/main/java/com/oitsjustjose/criss_cross/NEI/CCNEIIntegration.java deleted file mode 100644 index 7e0f1b2..0000000 --- a/src/main/java/com/oitsjustjose/criss_cross/NEI/CCNEIIntegration.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.oitsjustjose.criss_cross.NEI; - -import com.oitsjustjose.criss_cross.Util.Reference; - -import codechicken.nei.api.API; -import codechicken.nei.api.IConfigureNEI; -import codechicken.nei.recipe.TemplateRecipeHandler; - -public class CCNEIIntegration implements IConfigureNEI -{ - @Override - public void loadConfig() - { - registerHandler(new RecipeHandlerWoodchipper()); - } - - @Override - public String getName() - { - return Reference.modid + " built-in NEI plugin."; - } - - @Override - public String getVersion() - { - return Reference.version; - } - - public void registerHandler(RecipeHandlerBase handler) - { - API.registerRecipeHandler(handler); - API.registerUsageHandler(handler); - } -} \ No newline at end of file diff --git a/src/main/java/com/oitsjustjose/criss_cross/NEI/RecipeHandlerBase.java b/src/main/java/com/oitsjustjose/criss_cross/NEI/RecipeHandlerBase.java deleted file mode 100644 index 2be8661..0000000 --- a/src/main/java/com/oitsjustjose/criss_cross/NEI/RecipeHandlerBase.java +++ /dev/null @@ -1,358 +0,0 @@ -package com.oitsjustjose.criss_cross.NEI; - -import java.awt.Point; -import java.awt.Rectangle; -import java.util.ArrayList; -import java.util.List; - -import org.lwjgl.opengl.GL11; - -import codechicken.lib.gui.GuiDraw; -import codechicken.nei.NEIClientConfig; -import codechicken.nei.guihook.GuiContainerManager; -import codechicken.nei.recipe.GuiCraftingRecipe; -import codechicken.nei.recipe.GuiRecipe; -import codechicken.nei.recipe.GuiUsageRecipe; -import codechicken.nei.recipe.TemplateRecipeHandler; -import net.minecraft.block.Block; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.IIcon; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidContainerRegistry; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.IFluidBlock; -import net.minecraftforge.fluids.IFluidContainerItem; - -public abstract class RecipeHandlerBase extends TemplateRecipeHandler -{ - - public abstract class CachedBaseRecipe extends CachedRecipe - { - public List getFluidTanks() - { - return null; - } - } - - public abstract String getRecipeID(); - - public void loadCraftingRecipes(FluidStack result) - { - } - - public void loadUsageRecipes(FluidStack ingredient) - { - } - - @Override - public void drawForeground(int recipe) - { - super.drawForeground(recipe); - this.drawFluidTanks(recipe); - } - - @Override - public void loadCraftingRecipes(String outputId, Object... results) - { - try - { - if (outputId.equals("liquid") && results.length == 1 && results[0] instanceof FluidStack) - { - this.loadCraftingRecipes((FluidStack) results[0]); - } else - { - super.loadCraftingRecipes(outputId, results); - } - } catch (Throwable ex) - { - ex.printStackTrace(); - } - } - - @Override - public void loadCraftingRecipes(ItemStack result) - { - FluidStack fluid = getFluidStack(result); - if (fluid != null) - { - this.loadCraftingRecipes(fluid); - } - } - - @Override - public void loadUsageRecipes(String inputId, Object... ingredients) - { - try - { - if (inputId.equals("liquid") && ingredients.length == 1 && ingredients[0] instanceof FluidStack) - { - this.loadUsageRecipes((FluidStack) ingredients[0]); - } else - { - super.loadUsageRecipes(inputId, ingredients); - } - } catch (Throwable ex) - { - ex.printStackTrace(); - } - } - - @Override - public void loadUsageRecipes(ItemStack ingred) - { - FluidStack fluid = getFluidStack(ingred); - if (fluid != null) - { - this.loadUsageRecipes(fluid); - } - } - - @Override - public List handleTooltip(GuiRecipe guiRecipe, List currenttip, int recipe) - { - super.handleTooltip(guiRecipe, currenttip, recipe); - CachedBaseRecipe crecipe = (CachedBaseRecipe) this.arecipes.get(recipe); - if (GuiContainerManager.shouldShowTooltip(guiRecipe)) - { - Point mouse = GuiDraw.getMousePosition(); - Point offset = guiRecipe.getRecipePosition(recipe); - Point relMouse = new Point(mouse.x - ((guiRecipe.width - 176) / 2) - offset.x, - mouse.y - ((guiRecipe.height - 166) / 2) - offset.y); - - if (crecipe.getFluidTanks() != null) - { - for (FluidTankElement tank : crecipe.getFluidTanks()) - { - if (tank.position.contains(relMouse)) - { - tank.handleTooltip(currenttip); - } - } - } - } - return currenttip; - } - - @Override - public boolean keyTyped(GuiRecipe gui, char keyChar, int keyCode, int recipe) - { - if (keyCode == NEIClientConfig.getKeyBinding("gui.recipe")) - { - if (this.transferFluidTank(gui, recipe, false)) - { - return true; - } - } else if (keyCode == NEIClientConfig.getKeyBinding("gui.usage")) - { - if (this.transferFluidTank(gui, recipe, true)) - { - return true; - } - } - return super.keyTyped(gui, keyChar, keyCode, recipe); - } - - @Override - public boolean mouseClicked(GuiRecipe gui, int button, int recipe) - { - if (button == 0) - { - if (this.transferFluidTank(gui, recipe, false)) - { - return true; - } - } else if (button == 1) - { - if (this.transferFluidTank(gui, recipe, true)) - { - return true; - } - } - return super.mouseClicked(gui, button, recipe); - } - - protected boolean transferFluidTank(GuiRecipe guiRecipe, int recipe, boolean usage) - { - CachedBaseRecipe crecipe = (CachedBaseRecipe) this.arecipes.get(recipe); - Point mousepos = GuiDraw.getMousePosition(); - Point offset = guiRecipe.getRecipePosition(recipe); - Point relMouse = new Point(mousepos.x - ((guiRecipe.width - 176) / 2) - offset.x, - mousepos.y - ((guiRecipe.height - 166) / 2) - offset.y); - - if (crecipe.getFluidTanks() != null) - { - for (FluidTankElement tank : crecipe.getFluidTanks()) - { - if (tank.position.contains(relMouse)) - { - if ((tank.fluid != null) && tank.fluid.amount > 0) - { - if (usage) - { - if (!GuiUsageRecipe.openRecipeGui("liquid", new Object[] - { tank.fluid })) - { - return false; - } - } else - { - if (!GuiCraftingRecipe.openRecipeGui("liquid", new Object[] - { tank.fluid })) - { - return false; - } - } - return true; - } - } - } - } - - return false; - } - - public void drawFluidTanks(int recipe) - { - CachedBaseRecipe crecipe = (CachedBaseRecipe) this.arecipes.get(recipe); - if (crecipe.getFluidTanks() != null) - { - for (FluidTankElement fluidTank : crecipe.getFluidTanks()) - { - fluidTank.draw(); - } - } - } - - public static List getSingleList(Object o) - { - List list = new ArrayList(); - list.add(o); - return list; - } - - public static FluidStack getFluidStack(ItemStack stack) - { - if (stack == null) - { - return null; - } - Item item = stack.getItem(); - FluidStack fluidStack = null; - if ((item instanceof IFluidContainerItem)) - { - fluidStack = ((IFluidContainerItem) item).getFluid(stack); - } - if (fluidStack == null) - { - fluidStack = FluidContainerRegistry.getFluidForFilledItem(stack); - } - if ((fluidStack == null) && (Block.getBlockFromItem(stack.getItem()) instanceof IFluidBlock)) - { - Fluid fluid = ((IFluidBlock) Block.getBlockFromItem(stack.getItem())).getFluid(); - if (fluid != null) - { - return new FluidStack(fluid, 1000); - } - } - return fluidStack; - } - - public static boolean areFluidsEqual(FluidStack fluidStack1, FluidStack fluidStack2) - { - if (fluidStack1 == null || fluidStack2 == null) - { - return false; - } - return fluidStack1.isFluidEqual(fluidStack2); - } - - public static class FluidTankElement - { - public Rectangle position; - public FluidStack fluid; - public int capacity; - public boolean flowingTexture = false; - - public FluidTankElement(Rectangle position, int capacity, FluidStack fluid) - { - this.position = position; - this.capacity = capacity; - this.fluid = fluid; - } - - public List handleTooltip(List currenttip) - { - if (this.fluid == null || this.fluid.getFluid() == null || this.fluid.amount <= 0) - { - return currenttip; - } - currenttip.add(this.fluid.getLocalizedName()); - currenttip.add(EnumChatFormatting.GRAY.toString() + this.fluid.amount + " mB"); - return currenttip; - } - - public void draw() - { - if (this.fluid == null || this.fluid.getFluid() == null || this.fluid.amount <= 0) - { - return; - } - IIcon fluidIcon = null; - if (this.flowingTexture && this.fluid.getFluid().getFlowingIcon() != null) - { - fluidIcon = this.fluid.getFluid().getFlowingIcon(); - } else if (this.fluid.getFluid().getStillIcon() != null) - { - fluidIcon = this.fluid.getFluid().getStillIcon(); - } else - { - return; - } - - GuiDraw.changeTexture(TextureMap.locationBlocksTexture); - int color = this.fluid.getFluid().getColor(this.fluid); - GL11.glColor3ub((byte) (color >> 16 & 0xFF), (byte) (color >> 8 & 0xFF), (byte) (color & 0xFF)); - GL11.glDisable(GL11.GL_BLEND); - - int amount = Math - .max(Math.min(this.position.height, this.fluid.amount * this.position.height / this.capacity), 1); - int posY = this.position.y + this.position.height - amount; - - for (int i = 0; i < this.position.width; i += 16) - { - for (int j = 0; j < amount; j += 16) - { - int drawWidth = Math.min(this.position.width - i, 16); - int drawHeight = Math.min(amount - j, 16); - - int drawX = this.position.x + i; - int drawY = posY + j; - - double minU = fluidIcon.getMinU(); - double maxU = fluidIcon.getMaxU(); - double minV = fluidIcon.getMinV(); - double maxV = fluidIcon.getMaxV(); - - Tessellator tessellator = Tessellator.instance; - tessellator.startDrawingQuads(); - tessellator.addVertexWithUV(drawX, drawY + drawHeight, 0, minU, - minV + (maxV - minV) * drawHeight / 16F); - tessellator.addVertexWithUV(drawX + drawWidth, drawY + drawHeight, 0, - minU + (maxU - minU) * drawWidth / 16F, minV + (maxV - minV) * drawHeight / 16F); - tessellator.addVertexWithUV(drawX + drawWidth, drawY, 0, minU + (maxU - minU) * drawWidth / 16F, - minV); - tessellator.addVertexWithUV(drawX, drawY, 0, minU, minV); - tessellator.draw(); - } - } - - GL11.glEnable(GL11.GL_BLEND); - } - - } - -} \ No newline at end of file diff --git a/src/main/java/com/oitsjustjose/criss_cross/NEI/RecipeHandlerCropomator.java b/src/main/java/com/oitsjustjose/criss_cross/NEI/RecipeHandlerCropomator.java deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/com/oitsjustjose/criss_cross/NEI/RecipeHandlerElectroextractor.java b/src/main/java/com/oitsjustjose/criss_cross/NEI/RecipeHandlerElectroextractor.java deleted file mode 100644 index b0d58cb..0000000 --- a/src/main/java/com/oitsjustjose/criss_cross/NEI/RecipeHandlerElectroextractor.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.oitsjustjose.criss_cross.NEI; - -public class RecipeHandlerElectroextractor -{ - -} diff --git a/src/main/java/com/oitsjustjose/criss_cross/NEI/RecipeHandlerWoodchipper.java b/src/main/java/com/oitsjustjose/criss_cross/NEI/RecipeHandlerWoodchipper.java deleted file mode 100644 index 8c641e5..0000000 --- a/src/main/java/com/oitsjustjose/criss_cross/NEI/RecipeHandlerWoodchipper.java +++ /dev/null @@ -1,130 +0,0 @@ -package com.oitsjustjose.criss_cross.NEI; - -import java.awt.Rectangle; -import java.util.ArrayList; - -import org.lwjgl.opengl.GL11; - -import com.oitsjustjose.criss_cross.TileEntity.TileEntityWoodchipper; -import com.oitsjustjose.criss_cross.TileEntity.TileEntityWoodchipper.WoodchipperRecipe; -import com.oitsjustjose.criss_cross.Util.ConfigHandler; - -import codechicken.lib.gui.GuiDraw; -import codechicken.nei.NEIServerUtils; -import codechicken.nei.PositionedStack; -import net.minecraft.item.ItemStack; -import net.minecraft.util.StatCollector; - -public class RecipeHandlerWoodchipper extends RecipeHandlerBase -{ - - public class CachedWoodchipperRecipe extends CachedBaseRecipe - { - - public PositionedStack input; - public PositionedStack output; - public int time = ConfigHandler.woodchipperProcessTime; - - public CachedWoodchipperRecipe(WoodchipperRecipe chipper) - { - this.input = new PositionedStack(chipper.input, 44, 18); - this.output = new PositionedStack(chipper.result, 98, 18); - } - - @Override - public PositionedStack getIngredient() - { - return this.input; - } - - @Override - public PositionedStack getResult() - { - return this.output; - } - - } - - @Override - public String getRecipeName() - { - return StatCollector.translateToLocal("crisscross.nei.woodchipper"); - } - - @Override - public String getRecipeID() - { - return "crisscross.woodchipper"; - } - - @Override - public void loadTransferRects() - { - this.transferRects - .add(new RecipeTransferRect(new Rectangle(68, 20, 22, 15), this.getRecipeID(), new Object[0])); - } - - @Override - public String getGuiTexture() - { - return "crisscross:textures/gui/woodchipper.png"; - } - - @Override - public void drawBackground(int recipe) - { - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - GuiDraw.changeTexture(this.getGuiTexture()); - GuiDraw.drawTexturedModalRect(0, 0, 0, 0, 160, 65); - } - - @Override - public void drawExtras(int recipe) - { - int time = ((CachedWoodchipperRecipe) this.arecipes.get(recipe)).time; - int seconds = time / 20; - GuiDraw.drawStringC(time + " ticks (" + seconds + " secs)", 81, 40, 0x808080, false); - } - - @Override - public void loadCraftingRecipes(String outputId, Object... results) - { - if (outputId.equals(this.getRecipeID())) - { - ArrayList inputs = TileEntityWoodchipper.getInputs(); - ArrayList outputs = TileEntityWoodchipper.getOutputs(); - - for (int i = 0; i < inputs.size(); i++) - { - WoodchipperRecipe recipe = new WoodchipperRecipe(inputs.get(i), outputs.get(i)); - this.arecipes.add(new CachedWoodchipperRecipe(recipe)); - } - } else - { - super.loadCraftingRecipes(outputId, results); - } - } - - @Override - public void loadCraftingRecipes(ItemStack result) - { - WoodchipperRecipe recipe = new WoodchipperRecipe(TileEntityWoodchipper.getItemFromResult(result), result); - - if (NEIServerUtils.areStacksSameTypeCrafting(recipe.result, result)) - { - this.arecipes.add(new CachedWoodchipperRecipe(recipe)); - } - } - - @Override - public void loadUsageRecipes(ItemStack ingred) - { - WoodchipperRecipe recipe = new WoodchipperRecipe(ingred, TileEntityWoodchipper.getResult(ingred)); - - if (NEIServerUtils.areStacksSameTypeCrafting(recipe.input, ingred)) - { - this.arecipes.add(new CachedWoodchipperRecipe(recipe)); - } - } - -} \ No newline at end of file diff --git a/src/main/java/com/oitsjustjose/criss_cross/Recipes/CCRecipes.java b/src/main/java/com/oitsjustjose/criss_cross/Recipes/CCCraftingRecipes.java similarity index 83% rename from src/main/java/com/oitsjustjose/criss_cross/Recipes/CCRecipes.java rename to src/main/java/com/oitsjustjose/criss_cross/Recipes/CCCraftingRecipes.java index e84cb16..c31cd18 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/Recipes/CCRecipes.java +++ b/src/main/java/com/oitsjustjose/criss_cross/Recipes/CCCraftingRecipes.java @@ -13,7 +13,7 @@ import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.FurnaceRecipes; -public class CCRecipes +public class CCCraftingRecipes { public static void init() { @@ -34,15 +34,17 @@ public class CCRecipes centerItem = newStack; if (unlocItem.length == 3) centerItem = new ItemStack(newStack.getItem(), 1, Integer.parseInt(unlocItem[2])); - } else + } + else { CCLog.warn("Item " + ConfigHandler.woodchipperRecipeItem + "could not be added as part of the recipe of the Woodchipper."); CCLog.warn("Please confirm you have the name and formatting correct."); } - GameRegistry.addRecipe(new ItemStack(CCBlocks.woodchipper), new Object[] - { "I#I", "SCS", "I#I", '#', Items.diamond_axe, 'I', Blocks.iron_bars, 'S', Items.golden_axe, 'C', centerItem }); + GameRegistry.addRecipe(new ItemStack(CCBlocks.woodchipper), + new Object[] { "I#I", "SCS", "I#I", '#', Items.diamond_axe, 'I', Blocks.iron_bars, 'S', + Items.golden_axe, 'C', centerItem }); } static void electroextractorRecipe() @@ -57,7 +59,8 @@ public class CCRecipes centerItem = newStack; if (unlocItem.length == 3) centerItem = new ItemStack(newStack.getItem(), 1, Integer.parseInt(unlocItem[2])); - } else + } + else { CCLog.warn("Item " + ConfigHandler.electroextractorRecipeItem + " could not be added as part of the recipe of the electroextractor."); @@ -65,8 +68,9 @@ public class CCRecipes } - GameRegistry.addRecipe(new ItemStack(CCBlocks.electroextractor), new Object[] - { "I#I", "SCS", "I#I", '#', Blocks.piston, 'I', Blocks.iron_bars, 'S', Items.golden_pickaxe, 'C', centerItem }); + GameRegistry.addRecipe(new ItemStack(CCBlocks.electroextractor), + new Object[] { "I#I", "SCS", "I#I", '#', Blocks.piston, 'I', Blocks.iron_bars, 'S', + Items.golden_pickaxe, 'C', centerItem }); } static void cropomatorRecipe() @@ -81,14 +85,16 @@ public class CCRecipes centerItem = newStack; if (unlocItem.length == 3) centerItem = new ItemStack(newStack.getItem(), 1, Integer.parseInt(unlocItem[2])); - } else + } + else { CCLog.warn("Item " + ConfigHandler.cropomatorRecipeItem + " could not be added as part of the recipe of the cropomator."); CCLog.warn("Please confirm you have the name and formatting correct."); } - GameRegistry.addRecipe(new ItemStack(CCBlocks.cropomator), new Object[] - { "I#I", "SCS", "I#I", '#', Blocks.hay_block, 'I', Items.iron_ingot, 'S', Items.golden_hoe, 'C', centerItem }); + GameRegistry.addRecipe(new ItemStack(CCBlocks.cropomator), + new Object[] { "I#I", "SCS", "I#I", '#', Blocks.hay_block, 'I', Items.iron_ingot, 'S', Items.golden_hoe, + 'C', centerItem }); } } \ No newline at end of file diff --git a/src/main/java/com/oitsjustjose/criss_cross/Recipes/CCMachineRecipes.java b/src/main/java/com/oitsjustjose/criss_cross/Recipes/CCMachineRecipes.java new file mode 100644 index 0000000..397bbb1 --- /dev/null +++ b/src/main/java/com/oitsjustjose/criss_cross/Recipes/CCMachineRecipes.java @@ -0,0 +1,287 @@ +package com.oitsjustjose.criss_cross.Recipes; + +import java.util.ArrayList; + +import com.oitsjustjose.criss_cross.Items.CCItems; +import com.oitsjustjose.criss_cross.Items.ItemDust; +import com.oitsjustjose.criss_cross.TileEntity.TileEntityCropomator; +import com.oitsjustjose.criss_cross.TileEntity.TileEntityElectroextractor; +import com.oitsjustjose.criss_cross.TileEntity.TileEntityWoodchipper; +import com.oitsjustjose.criss_cross.Util.CCLog; +import com.oitsjustjose.criss_cross.Util.ConfigHandler; + +import cpw.mods.fml.common.registry.GameRegistry; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; + +public class CCMachineRecipes +{ + public static int cropomatorQTY = ConfigHandler.cropomatorOutput; + public static int electroQTY = ConfigHandler.electroextractorOutput; + public static int woodchipperQTY = ConfigHandler.woodchipperOutput; + public static void init() + { + initCropomatorRecipes(); + initCropomatorFuels(); + initElectroextractorFuels(); + initElectroextractorOreDictionary(); + initWoodchipperFuels(); + initWoodchipperOreDictionary(); + + ElectroextractorRecipes.getInstance().addRecipe(new ItemStack(Blocks.diamond_ore), new ItemStack(Items.diamond, electroQTY)); + ElectroextractorRecipes.getInstance().addRecipe(new ItemStack(Blocks.emerald_ore), new ItemStack(Items.emerald, electroQTY)); + ElectroextractorRecipes.getInstance().addRecipe(new ItemStack(Blocks.coal_ore), new ItemStack(Items.coal, electroQTY)); + } + + public static void initCropomatorRecipes() + { + for (int i = 0; i < ConfigHandler.cropomatorInputs.length; i++) + { + try + { + String[] unlocStack = ConfigHandler.cropomatorInputs[i].split(":"); + if (unlocStack.length == 2) + { + if (GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1) != null) + { + ItemStack newStack = GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1); + newStack.stackSize = cropomatorQTY; + CropomatorRecipes.getInstance().addRecipe(newStack, newStack); + } + else + { + CCLog.warn("Item " + ConfigHandler.cropomatorInputs[i] + " could not be added to the Cropomator's recipe list."); + CCLog.warn("Please confirm you have the name and formatting correct."); + + } + } + if (unlocStack.length == 3) + { + if (GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1) != null) + { + ItemStack newStack = new ItemStack(GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1).getItem(), 1, Integer.parseInt(unlocStack[2])); + newStack.stackSize = cropomatorQTY; + CropomatorRecipes.getInstance().addRecipe(newStack, newStack); + } + else + { + CCLog.warn("Item " + ConfigHandler.cropomatorInputs[i] + " could not be added to the Cropomator's recipe list."); + CCLog.warn("Please confirm you have the name and formatting correct."); + } + } + } + catch (Exception e) + { + CCLog.warn("[CrissCross]: Error reading itemstack for inputs from input file at item: " + (i + 1)); + } + + } + } + + public static void initCropomatorFuels() + { + for (int i = 0; i < ConfigHandler.cropomatorCatalysts.length; i++) + { + try + { + String[] unlocStack = ConfigHandler.cropomatorCatalysts[i].split(":"); + if (unlocStack.length == 2) + { + if (GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1) != null) + TileEntityCropomator + .addFuel(GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1)); + else + { + CCLog.warn("Item " + ConfigHandler.cropomatorInputs[i] + + " could not be added to the Cropomator's catalyst list."); + CCLog.warn("Please confirm you have the name and formatting correct."); + } + } + + if (unlocStack.length == 3) + { + if (GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1) != null) + { + ItemStack newStack = new ItemStack( + GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1).getItem(), 1, + Integer.parseInt(unlocStack[2])); + TileEntityCropomator.addFuel(newStack); + } + else + { + CCLog.warn("Item " + ConfigHandler.cropomatorInputs[i] + + " could not be added to the Cropomator's catalyst list."); + CCLog.warn("Please confirm you have the name and formatting correct."); + } + } + } + catch (Exception e) + { + CCLog.warn("Error reading itemstack for catalysts from input file at item: " + (i + 1)); + } + } + } + + public static void initWoodchipperOreDictionary() + { + ArrayList logs = OreDictionary.getOres("logWood"); + ArrayList planks = OreDictionary.getOres("plankWood"); + + String logName; + String plankName; + + for (int i = 0; i < logs.size(); i++) + { + for (int logMeta = 0; logMeta < 16; logMeta++) + { + ItemStack log = new ItemStack(logs.get(i).getItem(), 1, logMeta); + logName = log.getDisplayName(); + logName = logName.replace("Wood", ""); + logName = logName.trim(); + + for (int j = 0; j < planks.size(); j++) + { + for (int plankMeta = 0; plankMeta < 16; plankMeta++) + { + ItemStack plank = new ItemStack(planks.get(j).getItem(), 1, plankMeta); + plankName = plank.getDisplayName(); + plankName = plankName.replace("Wood", ""); + plankName = plankName.replace("Planks", ""); + plankName = plankName.trim(); + plank.stackSize = woodchipperQTY; + if (plankName.contains(logName)) + { + WoodchipperRecipes.getInstance().addRecipe(log, plank); + break; + } + } + } + } + } + } + + public static void initWoodchipperFuels() + { + for (int i = 0; i < ConfigHandler.woodchipperFuels.length; i++) + { + try + { + String[] unlocStack = ConfigHandler.woodchipperFuels[i].split(":"); + if (unlocStack.length == 2) + { + if (GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1) != null) + TileEntityWoodchipper.addFuel(GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 0)); + else + { + CCLog.warn("Item " + ConfigHandler.woodchipperFuels[i] + + " could not be added to the Woodchipper's fuel list."); + CCLog.warn("Please confirm you have the name and formatting correct."); + } + } + + if (unlocStack.length == 3) + { + if (GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1) != null) + { + ItemStack newStack = new ItemStack( + GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1).getItem(), 1, + Integer.parseInt(unlocStack[2])); + TileEntityWoodchipper.addFuel(newStack); + } + else + { + CCLog.warn("Item " + ConfigHandler.woodchipperFuels[i] + + " could not be added to the Woodchipper's fuel list."); + CCLog.warn("Please confirm you have the name and formatting correct."); + } + } + } + catch (Exception e) + { + CCLog.warn("Error reading itemstack for Woodchipper's energy sources at item: " + (i + 1)); + } + } + } + + static void initElectroextractorFuels() + { + for (int i = 0; i < ConfigHandler.electroextractorEnergySources.length; i++) + { + try + { + String[] unlocStack = ConfigHandler.electroextractorEnergySources[i].split(":"); + if (unlocStack.length == 2) + { + if (GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1) != null) + TileEntityElectroextractor.addFuel(GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 0)); + else + { + CCLog.warn("Item " + ConfigHandler.electroextractorEnergySources[i] + + " could not be added to the Electroextractor's fuel list."); + CCLog.warn("Please confirm you have the name and formatting correct."); + } + } + + if (unlocStack.length == 3) + { + if (GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1) != null) + { + ItemStack newStack = new ItemStack( + GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1).getItem(), 1, + Integer.parseInt(unlocStack[2])); + TileEntityElectroextractor.addFuel(newStack); + } + else + { + CCLog.warn("Item " + ConfigHandler.electroextractorEnergySources[i] + + " could not be added to the Electroextractor's fuel list."); + CCLog.warn("Please confirm you have the name and formatting correct."); + } + } + } + catch (Exception e) + { + CCLog.warn("Error reading itemstack for electroextractor's energy sources at item: " + (i + 1)); + } + } + } + + static void initElectroextractorOreDictionary() + { + ArrayList dustNames = ItemDust.getDusts(); + for (int i = 0; i < ConfigHandler.electroextractorOreDictInputs.length; i++) + { + String[] entry = ConfigHandler.electroextractorOreDictInputs[i].split(":"); + if (OreDictionary.doesOreNameExist("ore" + entry[0]) && OreDictionary.doesOreNameExist("ingot" + entry[0])) + { + ArrayList ores = OreDictionary.getOres("ore" + entry[0]); + ItemDust.addDustType(entry[0], Integer.parseInt(entry[1])); + for (int j = 0; j < ores.size(); j++) + ElectroextractorRecipes.getInstance().addRecipe(ores.get(j), new ItemStack(CCItems.dusts, electroQTY, dustNames.size() - 1)); + } + else + { + CCLog.warn("Your oreDictionary Entry " + ConfigHandler.electroextractorOreDictInputs[i] + + " could not be registered."); + if (!OreDictionary.doesOreNameExist("ore" + entry[0])) + CCLog.warn("This is because your oreDictionary Entry was not valid or registered as " + entry[0] + + "."); + else + if (!OreDictionary.doesOreNameExist("ingot" + entry[0])) + CCLog.warn("This is because your oreDictionary Entry does not have an ingot for " + entry[0] + + "."); + } + } + + for (int i = 0; i < dustNames.size(); i++) + { + ItemStack ingot = null; + if (OreDictionary.doesOreNameExist("ingot" + dustNames.get(i))) + ingot = OreDictionary.getOres("ingot" + dustNames.get(i)).get(0); + if (ingot != null) + GameRegistry.addSmelting(new ItemStack(CCItems.dusts, 1, i), ingot, 0.0F); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/oitsjustjose/criss_cross/Recipes/CropomatorRecipes.java b/src/main/java/com/oitsjustjose/criss_cross/Recipes/CropomatorRecipes.java index 58f6fc6..d82e01e 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/Recipes/CropomatorRecipes.java +++ b/src/main/java/com/oitsjustjose/criss_cross/Recipes/CropomatorRecipes.java @@ -1,98 +1,56 @@ package com.oitsjustjose.criss_cross.Recipes; -import com.oitsjustjose.criss_cross.CrissCross; -import com.oitsjustjose.criss_cross.TileEntity.TileEntityCropomator; -import com.oitsjustjose.criss_cross.Util.CCLog; -import com.oitsjustjose.criss_cross.Util.ConfigHandler; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; -import cpw.mods.fml.common.registry.GameRegistry; +import com.google.common.collect.Maps; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; public class CropomatorRecipes { - public static void initRecipes() + private static final CropomatorRecipes recipeBase = new CropomatorRecipes(); + private Map recipes = Maps.newHashMap(); + + public static CropomatorRecipes getInstance() { - for (int i = 0; i < ConfigHandler.cropomatorInputs.length; i++) - { - try - { - String[] unlocStack = ConfigHandler.cropomatorInputs[i].split(":"); - if (unlocStack.length == 2) - { - if (GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1) != null) - TileEntityCropomator - .addItemStackToOutputs(GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1)); - else - { - CCLog.warn("Item " + ConfigHandler.cropomatorInputs[i] - + " could not be added to the Cropomator's recipe list."); - CCLog.warn("Please confirm you have the name and formatting correct."); - - } - } - if (unlocStack.length == 3) - { - if (GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1) != null) - { - ItemStack newStack = new ItemStack( - GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1).getItem(), 1, - Integer.parseInt(unlocStack[2])); - TileEntityCropomator.addItemStackToOutputs(newStack); - } else - { - CCLog.warn("Item " + ConfigHandler.cropomatorInputs[i] - + " could not be added to the Cropomator's recipe list."); - CCLog.warn("Please confirm you have the name and formatting correct."); - } - } - - } catch (Exception e) - { - CCLog.warn("[CrissCross]: Error reading itemstack for inputs from input file at item: " + (i + 1)); - } - - } + return recipeBase; } - - public static void initCatalysts() + + public void addRecipe(ItemStack input, ItemStack stack) { - for (int i = 0; i < ConfigHandler.cropomatorCatalysts.length; i++) - { - try - { - String[] unlocStack = ConfigHandler.cropomatorCatalysts[i].split(":"); - if (unlocStack.length == 2) - { - if (GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1) != null) - TileEntityCropomator - .addItemStackToCatalysts(GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1)); - else - { - CCLog.warn("Item " + ConfigHandler.cropomatorInputs[i] - + " could not be added to the Cropomator's catalyst list."); - CCLog.warn("Please confirm you have the name and formatting correct."); - } - } - - if (unlocStack.length == 3) - { - if (GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1) != null) - { - ItemStack newStack = new ItemStack( - GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1).getItem(), 1, - Integer.parseInt(unlocStack[2])); - TileEntityCropomator.addItemStackToCatalysts(newStack); - } else - { - CCLog.warn("Item " + ConfigHandler.cropomatorInputs[i] - + " could not be added to the Cropomator's catalyst list."); - CCLog.warn("Please confirm you have the name and formatting correct."); - } - } - } catch (Exception e) - { - CCLog.warn("Error reading itemstack for catalysts from input file at item: " + (i + 1)); - } - } + this.recipes.put(input, stack); } -} + + public ItemStack getResult(ItemStack stack) + { + Iterator iterator = this.recipes.entrySet().iterator(); + Entry entry; + + do + { + if (!iterator.hasNext()) + return null; + + entry = (Entry) iterator.next(); + } + while (!this.compareItemStacks(stack, (ItemStack) entry.getKey())); + + return (ItemStack) entry.getValue(); + } + + private boolean compareItemStacks(ItemStack stack1, ItemStack stack2) + { + return stack2.getItem() == stack1.getItem() && (stack2.getItemDamage() == 32767 || stack2.getItemDamage() == stack1.getItemDamage()); + } + + public Map getRecipeList() + { + return this.recipes; + } +} \ No newline at end of file diff --git a/src/main/java/com/oitsjustjose/criss_cross/Recipes/ElectroextractorRecipes.java b/src/main/java/com/oitsjustjose/criss_cross/Recipes/ElectroextractorRecipes.java index 798cda0..3235229 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/Recipes/ElectroextractorRecipes.java +++ b/src/main/java/com/oitsjustjose/criss_cross/Recipes/ElectroextractorRecipes.java @@ -1,103 +1,56 @@ package com.oitsjustjose.criss_cross.Recipes; -import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; -import com.oitsjustjose.criss_cross.CrissCross; -import com.oitsjustjose.criss_cross.Items.CCItems; -import com.oitsjustjose.criss_cross.Items.ItemDust; -import com.oitsjustjose.criss_cross.TileEntity.TileEntityElectroextractor; -import com.oitsjustjose.criss_cross.Util.CCLog; -import com.oitsjustjose.criss_cross.Util.ConfigHandler; +import com.google.common.collect.Maps; -import cpw.mods.fml.common.registry.GameRegistry; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; +import net.minecraft.block.Block; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; public class ElectroextractorRecipes { - public static void initRecipes() + private static final ElectroextractorRecipes recipeBase = new ElectroextractorRecipes(); + private Map recipes = Maps.newHashMap(); + + public static ElectroextractorRecipes getInstance() { - oreDictionaryInit(); - TileEntityElectroextractor.addRecipe(Blocks.diamond_ore, new ItemStack(Items.diamond)); - TileEntityElectroextractor.addRecipe(Blocks.emerald_ore, new ItemStack(Items.emerald)); - TileEntityElectroextractor.addRecipe(Blocks.coal_ore, new ItemStack(Items.coal)); + return recipeBase; } - - public static void oreDictionaryInit() + + public void addRecipe(ItemStack input, ItemStack stack) { - ArrayList dustNames = ItemDust.getDusts(); - for (int i = 0; i < ConfigHandler.electroextractorOreDictInputs.length; i++) - { - String[] entry = ConfigHandler.electroextractorOreDictInputs[i].split(":"); - if (OreDictionary.doesOreNameExist("ore" + entry[0]) && OreDictionary.doesOreNameExist("ingot" + entry[0])) - { - ArrayList ores = OreDictionary.getOres("ore" + entry[0]); - ItemDust.addDustType(entry[0], Integer.parseInt(entry[1])); - for (int j = 0; j < ores.size(); j++) - TileEntityElectroextractor.addRecipe(ores.get(j), - new ItemStack(CCItems.dusts, 1, dustNames.size() - 1)); - } else - { - CCLog.warn("Your oreDictionary Entry " + ConfigHandler.electroextractorOreDictInputs[i] - + " could not be registered."); - if (!OreDictionary.doesOreNameExist("ore" + entry[0])) - CCLog.warn("This is because your oreDictionary Entry was not valid or registered as " + entry[0] - + "."); - else if (!OreDictionary.doesOreNameExist("ingot" + entry[0])) - CCLog.warn("This is because your oreDictionary Entry does not have an ingot for " + entry[0] + "."); - } - } - - for (int i = 0; i < dustNames.size(); i++) - { - ItemStack ingot = null; - if (OreDictionary.doesOreNameExist("ingot" + dustNames.get(i))) - ingot = OreDictionary.getOres("ingot" + dustNames.get(i)).get(0); - if (ingot != null) - GameRegistry.addSmelting(new ItemStack(CCItems.dusts, 1, i), ingot, 0.0F); - } + this.recipes.put(input, stack); } - - public static void initFuels() + + public ItemStack getResult(ItemStack stack) { - for (int i = 0; i < ConfigHandler.electroextractorEnergySources.length; i++) + Iterator iterator = this.recipes.entrySet().iterator(); + Entry entry; + + do { - try - { - String[] unlocStack = ConfigHandler.electroextractorEnergySources[i].split(":"); - if (unlocStack.length == 2) - { - if (GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1) != null) - TileEntityElectroextractor.addFuel(GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 0)); - else - { - CCLog.warn("Item " + ConfigHandler.electroextractorEnergySources[i] - + " could not be added to the Electroextractor's fuel list."); - CCLog.warn("Please confirm you have the name and formatting correct."); - } - } - - if (unlocStack.length == 3) - { - if (GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1) != null) - { - ItemStack newStack = new ItemStack( - GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1).getItem(), 1, - Integer.parseInt(unlocStack[2])); - TileEntityElectroextractor.addFuel(newStack); - } else - { - CCLog.warn("Item " + ConfigHandler.electroextractorEnergySources[i] - + " could not be added to the Electroextractor's fuel list."); - CCLog.warn("Please confirm you have the name and formatting correct."); - } - } - } catch (Exception e) - { - CCLog.warn("Error reading itemstack for electroextractor's energy sources at item: " + (i + 1)); - } + if (!iterator.hasNext()) + return null; + + entry = (Entry) iterator.next(); } + while (!this.compareItemStacks(stack, (ItemStack) entry.getKey())); + + return (ItemStack) entry.getValue(); + } + + private boolean compareItemStacks(ItemStack stack1, ItemStack stack2) + { + return stack2.getItem() == stack1.getItem() && (stack2.getItemDamage() == 32767 || stack2.getItemDamage() == stack1.getItemDamage()); + } + + public Map getRecipeList() + { + return this.recipes; } } \ No newline at end of file diff --git a/src/main/java/com/oitsjustjose/criss_cross/Recipes/WoodchipperRecipes.java b/src/main/java/com/oitsjustjose/criss_cross/Recipes/WoodchipperRecipes.java index dd55077..334b6d6 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/Recipes/WoodchipperRecipes.java +++ b/src/main/java/com/oitsjustjose/criss_cross/Recipes/WoodchipperRecipes.java @@ -1,94 +1,56 @@ package com.oitsjustjose.criss_cross.Recipes; -import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; -import com.oitsjustjose.criss_cross.CrissCross; -import com.oitsjustjose.criss_cross.TileEntity.TileEntityWoodchipper; -import com.oitsjustjose.criss_cross.Util.CCLog; -import com.oitsjustjose.criss_cross.Util.ConfigHandler; +import com.google.common.collect.Maps; -import cpw.mods.fml.common.registry.GameRegistry; -import net.minecraft.init.Blocks; +import net.minecraft.block.Block; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; public class WoodchipperRecipes { - public static void initRecipes() + private static final WoodchipperRecipes recipeBase = new WoodchipperRecipes(); + private Map recipes = Maps.newHashMap(); + + public static WoodchipperRecipes getInstance() { - ArrayList logs = OreDictionary.getOres("logWood"); - ArrayList planks = OreDictionary.getOres("plankWood"); - - String logName; - String plankName; - - for (int i = 0; i < logs.size(); i++) - { - for (int logMeta = 0; logMeta < 16; logMeta++) - { - ItemStack log = new ItemStack(logs.get(i).getItem(), 1, logMeta); - logName = log.getDisplayName(); - logName = logName.replace("Wood", ""); - logName = logName.trim(); - - for (int j = 0; j < planks.size(); j++) - { - for (int plankMeta = 0; plankMeta < 16; plankMeta++) - { - ItemStack plank = new ItemStack(planks.get(j).getItem(), 1, plankMeta); - plankName = plank.getDisplayName(); - plankName = plankName.replace("Wood", ""); - plankName = plankName.replace("Planks", ""); - plankName = plankName.trim(); - if (plankName.contains(logName)) - { - TileEntityWoodchipper.addRecipe(log, plank); - break; - } - } - } - } - } + return recipeBase; } - - public static void initFuels() + + public void addRecipe(ItemStack input, ItemStack stack) { - for (int i = 0; i < ConfigHandler.woodchipperFuels.length; i++) - { - try - { - String[] unlocStack = ConfigHandler.woodchipperFuels[i].split(":"); - if (unlocStack.length == 2) - { - if (GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1) != null) - TileEntityWoodchipper.addFuel(GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 0)); - else - { - CCLog.warn("Item " + ConfigHandler.woodchipperFuels[i] - + " could not be added to the Woodchipper's fuel list."); - CCLog.warn("Please confirm you have the name and formatting correct."); - } - } - - if (unlocStack.length == 3) - { - if (GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1) != null) - { - ItemStack newStack = new ItemStack( - GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1).getItem(), 1, - Integer.parseInt(unlocStack[2])); - TileEntityWoodchipper.addFuel(newStack); - } else - { - CCLog.warn("Item " + ConfigHandler.woodchipperFuels[i] - + " could not be added to the Woodchipper's fuel list."); - CCLog.warn("Please confirm you have the name and formatting correct."); - } - } - } catch (Exception e) - { - CCLog.warn("Error reading itemstack for Woodchipper's energy sources at item: " + (i + 1)); - } - } + this.recipes.put(input, stack); } -} + + public ItemStack getResult(ItemStack stack) + { + Iterator iterator = this.recipes.entrySet().iterator(); + Entry entry; + + do + { + if (!iterator.hasNext()) + return null; + + entry = (Entry) iterator.next(); + } + while (!this.compareItemStacks(stack, (ItemStack) entry.getKey())); + + return (ItemStack) entry.getValue(); + } + + private boolean compareItemStacks(ItemStack stack1, ItemStack stack2) + { + return stack2.getItem() == stack1.getItem() && (stack2.getItemDamage() == 32767 || stack2.getItemDamage() == stack1.getItemDamage()); + } + + public Map getRecipeList() + { + return this.recipes; + } +} \ No newline at end of file diff --git a/src/main/java/com/oitsjustjose/criss_cross/TileEntity/TileEntityCropomator.java b/src/main/java/com/oitsjustjose/criss_cross/TileEntity/TileEntityCropomator.java index 98410f8..f42aab6 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/TileEntity/TileEntityCropomator.java +++ b/src/main/java/com/oitsjustjose/criss_cross/TileEntity/TileEntityCropomator.java @@ -3,14 +3,14 @@ package com.oitsjustjose.criss_cross.TileEntity; import java.util.ArrayList; import com.oitsjustjose.criss_cross.Blocks.BlockCropomator; +import com.oitsjustjose.criss_cross.Recipes.CropomatorRecipes; +import com.oitsjustjose.criss_cross.Recipes.ElectroextractorRecipes; import com.oitsjustjose.criss_cross.Util.ConfigHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ISidedInventory; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; @@ -20,14 +20,10 @@ public class TileEntityCropomator extends TileEntity implements ISidedInventory { private static int proTicks = ConfigHandler.cropomatorProcessTime; private static int qty = ConfigHandler.cropomatorOutput; - private static final int[] slotsTop = new int[] - { 0 }; - private static final int[] slotsBottom = new int[] - { 2, 1 }; - private static final int[] slotsSides = new int[] - { 1 }; - private static ArrayList recipeItems = new ArrayList(); - private static ArrayList catalystItems = new ArrayList(); + private static final int[] slotsTop = new int[] { 0 }; + private static final int[] slotsBottom = new int[] { 2, 1 }; + private static final int[] slotsSides = new int[] { 1 }; + private static ArrayList fuelItems = new ArrayList(); private ItemStack[] ItemStacks = new ItemStack[3]; @@ -35,17 +31,6 @@ public class TileEntityCropomator extends TileEntity implements ISidedInventory public int processTime; public int catalystInUseTime; - public static ItemStack getResult(ItemStack input) - { - for (int i = 0; i < recipeItems.size(); i++) - { - ItemStack temp = recipeItems.get(i); - if (ItemStack.areItemStacksEqual(temp, input)) - return new ItemStack(temp.getItem(), qty, temp.getItemDamage()); - } - return null; - } - @Override public int getSizeInventory() { @@ -70,7 +55,8 @@ public class TileEntityCropomator extends TileEntity implements ISidedInventory itemstack = this.ItemStacks[slot]; this.ItemStacks[slot] = null; return itemstack; - } else + } + else { itemstack = this.ItemStacks[slot].splitStack(qtyToDecr); @@ -81,7 +67,8 @@ public class TileEntityCropomator extends TileEntity implements ISidedInventory return itemstack; } - } else + } + else { return null; } @@ -95,7 +82,8 @@ public class TileEntityCropomator extends TileEntity implements ISidedInventory ItemStack itemstack = this.ItemStacks[slot]; this.ItemStacks[slot] = null; return itemstack; - } else + } + else { return null; } @@ -238,10 +226,11 @@ public class TileEntityCropomator extends TileEntity implements ISidedInventory if (this.processTime == proTicks) { this.processTime = 0; - this.fertilizeItem(); + this.processItem(); flag1 = true; } - } else + } + else { this.processTime = 0; } @@ -263,100 +252,69 @@ public class TileEntityCropomator extends TileEntity implements ISidedInventory private boolean canProcess() { - if (this.ItemStacks[0] == null) + ItemStack input = this.ItemStacks[0]; + if (input != null) { - return false; - } else - { - ItemStack itemstack = new ItemStack(this.ItemStacks[0].getItem(), qty, this.ItemStacks[0].getItemDamage()); - - if (this.ItemStacks[2] == null) - return true; - if (!this.ItemStacks[2].isItemEqual(itemstack)) + ItemStack output = CropomatorRecipes.getInstance().getResult(input); + if (output == null) return false; - int result = ItemStacks[2].stackSize + itemstack.stackSize; - - return result <= getInventoryStackLimit() && result <= this.ItemStacks[2].getMaxStackSize(); + ItemStack outputSlot = this.ItemStacks[2]; + if (outputSlot == null) + return true; + if (!outputSlot.isItemEqual(output)) + return false; + int result = outputSlot.stackSize + output.stackSize; + return result <= output.getMaxStackSize(); } + return false; } - public static boolean removeItemStackFromOutputs(ItemStack itemstack) + public static void addFuel(ItemStack itemstack) { - for (int i = 0; i < recipeItems.size(); i++) + fuelItems.add(itemstack); + } + + public static boolean removeFuel(ItemStack itemstack) + { + for (int i = 0; i < fuelItems.size(); i++) { - if (recipeItems.get(i) == itemstack) + if (fuelItems.get(i) == itemstack) { - recipeItems.remove(i); + fuelItems.remove(i); return true; } } return false; } - public static void addItemStackToOutputs(ItemStack itemstack) + public static boolean isValid(ItemStack itemstack) { - recipeItems.add(itemstack); - } - - public static void addItemToOutputs(Item item) - { - recipeItems.add(new ItemStack(item)); - } - - public static void addBlockToOutputs(Block block) - { - recipeItems.add(new ItemStack(block)); - } - - public static void addItemStackToCatalysts(ItemStack itemstack) - { - catalystItems.add(itemstack); - } - - public static boolean removeItemStackFromCatalysts(ItemStack itemstack) - { - for (int i = 0; i < catalystItems.size(); i++) - { - if (catalystItems.get(i) == itemstack) - { - catalystItems.remove(i); - return true; - } - } + if(CropomatorRecipes.getInstance().getResult(itemstack) != null) + return true; return false; } - public static boolean isValidForCropomator(ItemStack itemstack) - { - for (int i = 0; i < recipeItems.size(); i++) - { - ItemStack temp = recipeItems.get(i); - if (temp.getItem() == itemstack.getItem() && temp.getItemDamage() == itemstack.getItemDamage()) - return true; - } - - return false; - } - - public void fertilizeItem() + public void processItem() { if (this.canProcess()) { - ItemStack output = new ItemStack(this.ItemStacks[0].getItem(), qty, this.ItemStacks[0].getItemDamage()); - - if (this.ItemStacks[2] == null) + + ItemStack input = ItemStacks[0]; + ItemStack output = CropomatorRecipes.getInstance().getResult(input); + ItemStack outputSlot = ItemStacks[2]; + if (outputSlot == null) { - this.ItemStacks[2] = output.copy(); - } else if (this.ItemStacks[2].getItem() == output.getItem()) - { - this.ItemStacks[2].stackSize += output.stackSize; + ItemStacks[2] = output.copy(); } - - --this.ItemStacks[0].stackSize; - - if (this.ItemStacks[0].stackSize <= 0) + else if (outputSlot.isItemEqual(output)) { - this.ItemStacks[0] = null; + outputSlot.stackSize += output.stackSize; + } + + --input.stackSize; + if (input.stackSize <= 0) + { + ItemStacks[0] = null; } } } @@ -368,9 +326,9 @@ public class TileEntityCropomator extends TileEntity implements ISidedInventory public static boolean isItemCatalyst(ItemStack itemstack) { - for (int i = 0; i < catalystItems.size(); i++) + for (int i = 0; i < fuelItems.size(); i++) { - ItemStack temp = catalystItems.get(i); + ItemStack temp = fuelItems.get(i); if (temp.getItem() == itemstack.getItem() && temp.getItemDamage() == itemstack.getItemDamage()) return true; } diff --git a/src/main/java/com/oitsjustjose/criss_cross/TileEntity/TileEntityElectroextractor.java b/src/main/java/com/oitsjustjose/criss_cross/TileEntity/TileEntityElectroextractor.java index 9891b41..d7acf2c 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/TileEntity/TileEntityElectroextractor.java +++ b/src/main/java/com/oitsjustjose/criss_cross/TileEntity/TileEntityElectroextractor.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import com.oitsjustjose.criss_cross.Blocks.BlockElectroextractor; import com.oitsjustjose.criss_cross.Items.ItemDust; +import com.oitsjustjose.criss_cross.Recipes.ElectroextractorRecipes; import com.oitsjustjose.criss_cross.Util.ConfigHandler; import cpw.mods.fml.relauncher.Side; @@ -21,14 +22,9 @@ public class TileEntityElectroextractor extends TileEntity implements ISidedInve { private static int proTicks = ConfigHandler.electroextractorProcessTime; private static int qty = ConfigHandler.electroextractorOutput; - private static final int[] slotsTop = new int[] - { 0 }; - private static final int[] slotsBottom = new int[] - { 2, 1 }; - private static final int[] slotsSides = new int[] - { 1 }; - private static ArrayList inputItems = new ArrayList(); - private static ArrayList outputItems = new ArrayList(); + private static final int[] slotsTop = new int[] { 0 }; + private static final int[] slotsBottom = new int[] { 2, 1 }; + private static final int[] slotsSides = new int[] { 1 }; private static ArrayList fuelItems = new ArrayList(); private ItemStack[] ItemStacks = new ItemStack[3]; @@ -37,17 +33,6 @@ public class TileEntityElectroextractor extends TileEntity implements ISidedInve public int crushTime; public int fuelInUseTime; - public static ItemStack getResult(ItemStack input) - { - for (int i = 0; i < inputItems.size(); i++) - { - ItemStack temp = inputItems.get(i); - if (ItemStack.areItemStacksEqual(temp, input)) - return new ItemStack(outputItems.get(i).getItem(), qty, outputItems.get(i).getItemDamage()); - } - return null; - } - @Override public int getSizeInventory() { @@ -72,7 +57,8 @@ public class TileEntityElectroextractor extends TileEntity implements ISidedInve itemstack = this.ItemStacks[slot]; this.ItemStacks[slot] = null; return itemstack; - } else + } + else { itemstack = this.ItemStacks[slot].splitStack(qtyToDecr); @@ -83,7 +69,8 @@ public class TileEntityElectroextractor extends TileEntity implements ISidedInve return itemstack; } - } else + } + else { return null; } @@ -97,7 +84,8 @@ public class TileEntityElectroextractor extends TileEntity implements ISidedInve ItemStack itemstack = this.ItemStacks[slot]; this.ItemStacks[slot] = null; return itemstack; - } else + } + else { return null; } @@ -240,10 +228,11 @@ public class TileEntityElectroextractor extends TileEntity implements ISidedInve if (this.crushTime == proTicks) { this.crushTime = 0; - this.crushItem(); + this.processItem(); flag1 = true; } - } else + } + else { this.crushTime = 0; } @@ -265,66 +254,23 @@ public class TileEntityElectroextractor extends TileEntity implements ISidedInve private boolean canProcess() { - if (this.ItemStacks[0] == null) + ItemStack input = this.ItemStacks[0]; + if (input != null) { - return false; - } else - { - ItemStack output = null; - for (int i = 0; i < inputItems.size(); i++) - { - if (inputItems.get(i).getItem() == ItemStacks[0].getItem() - && inputItems.get(i).getItemDamage() == ItemStacks[0].getItemDamage()) - { - output = new ItemStack(outputItems.get(i).getItem(), qty, outputItems.get(i).getItemDamage()); - } - } - + ItemStack output = ElectroextractorRecipes.getInstance().getResult(input); if (output == null) return false; - - if (this.ItemStacks[2] == null) + ItemStack outputSlot = this.ItemStacks[2]; + if (outputSlot == null) return true; - if (!this.ItemStacks[2].isItemEqual(output)) + if (!outputSlot.isItemEqual(output)) return false; - int result = ItemStacks[2].stackSize + output.stackSize; - - return result <= getInventoryStackLimit() && result <= this.ItemStacks[2].getMaxStackSize(); - } - } - - public static boolean removeRecipe(ItemStack itemstack) - { - for (int i = 0; i < inputItems.size(); i++) - { - if (inputItems.get(i) == itemstack) - { - inputItems.remove(i); - outputItems.remove(i); - return true; - } + int result = outputSlot.stackSize + output.stackSize; + return result <= output.getMaxStackSize(); } return false; } - public static void addRecipe(ItemStack input, ItemStack output) - { - inputItems.add(input); - outputItems.add(output); - } - - public static void addRecipe(Item item, ItemStack output) - { - inputItems.add(new ItemStack(item)); - outputItems.add(output); - } - - public static void addRecipe(Block block, ItemStack output) - { - inputItems.add(new ItemStack(block)); - outputItems.add(output); - } - public static void addFuel(ItemStack itemstack) { fuelItems.add(itemstack); @@ -343,52 +289,34 @@ public class TileEntityElectroextractor extends TileEntity implements ISidedInve return false; } - public static boolean isValidForElectroextractor(ItemStack itemstack) + public static boolean isValid(ItemStack itemstack) { - for (int i = 0; i < inputItems.size(); i++) - { - ItemStack temp = inputItems.get(i); - if (temp.getItem() == itemstack.getItem() && temp.getItemDamage() == itemstack.getItemDamage()) - return true; - } - + if(ElectroextractorRecipes.getInstance().getResult(itemstack) != null) + return true; return false; } - public void crushItem() + public void processItem() { if (this.canProcess()) { - ItemStack output = null; - - for (int i = 0; i < inputItems.size(); i++) + + ItemStack input = ItemStacks[0]; + ItemStack output = ElectroextractorRecipes.getInstance().getResult(input); + ItemStack outputSlot = ItemStacks[2]; + if (outputSlot == null) { - if (inputItems.get(i).getItem() == ItemStacks[0].getItem() - && inputItems.get(i).getItemDamage() == ItemStacks[0].getItemDamage()) - { - output = new ItemStack(outputItems.get(i).getItem(), qty, outputItems.get(i).getItemDamage()); - if (output.getItem() instanceof ItemDust) - output.setStackDisplayName( - "Electrolytic " + ItemDust.getName(outputItems.get(i).getItemDamage()) + " Dust"); - } + ItemStacks[2] = output.copy(); } - - if (output == null) - return; - - if (this.ItemStacks[2] == null) + else if (outputSlot.isItemEqual(output)) { - this.ItemStacks[2] = output.copy(); - } else if (this.ItemStacks[2].getItem() == output.getItem()) - { - this.ItemStacks[2].stackSize += output.stackSize; + outputSlot.stackSize += output.stackSize; } - - --this.ItemStacks[0].stackSize; - - if (this.ItemStacks[0].stackSize <= 0) + + --input.stackSize; + if (input.stackSize <= 0) { - this.ItemStacks[0] = null; + ItemStacks[0] = null; } } } diff --git a/src/main/java/com/oitsjustjose/criss_cross/TileEntity/TileEntityWoodchipper.java b/src/main/java/com/oitsjustjose/criss_cross/TileEntity/TileEntityWoodchipper.java index 2852f4e..876ee29 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/TileEntity/TileEntityWoodchipper.java +++ b/src/main/java/com/oitsjustjose/criss_cross/TileEntity/TileEntityWoodchipper.java @@ -3,14 +3,13 @@ package com.oitsjustjose.criss_cross.TileEntity; import java.util.ArrayList; import com.oitsjustjose.criss_cross.Blocks.BlockWoodchipper; +import com.oitsjustjose.criss_cross.Recipes.WoodchipperRecipes; import com.oitsjustjose.criss_cross.Util.ConfigHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ISidedInventory; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; @@ -20,14 +19,9 @@ public class TileEntityWoodchipper extends TileEntity implements ISidedInventory { private static int proTicks = ConfigHandler.woodchipperProcessTime; private static int qty = ConfigHandler.woodchipperOutput; - private static final int[] slotsTop = new int[] - { 0 }; - private static final int[] slotsBottom = new int[] - { 2, 1 }; - private static final int[] slotsSides = new int[] - { 1 }; - private static ArrayList inputItems = new ArrayList(); - private static ArrayList outputItems = new ArrayList(); + private static final int[] slotsTop = new int[] { 0 }; + private static final int[] slotsBottom = new int[] { 2, 1 }; + private static final int[] slotsSides = new int[] { 1 }; private static ArrayList fuelItems = new ArrayList(); private ItemStack[] ItemStacks = new ItemStack[3]; @@ -36,38 +30,6 @@ public class TileEntityWoodchipper extends TileEntity implements ISidedInventory public int processTime; public int fuelUsetime; - public static ItemStack getItemFromResult(ItemStack output) - { - for (int i = 0; i < outputItems.size(); i++) - { - ItemStack temp = outputItems.get(i); - if (ItemStack.areItemStacksEqual(temp, output)) - return new ItemStack(inputItems.get(i).getItem(), qty, inputItems.get(i).getItemDamage()); - } - return null; - } - - public static ItemStack getResult(ItemStack input) - { - for (int i = 0; i < inputItems.size(); i++) - { - ItemStack temp = inputItems.get(i); - if (ItemStack.areItemStacksEqual(temp, input)) - return new ItemStack(outputItems.get(i).getItem(), qty, outputItems.get(i).getItemDamage()); - } - return null; - } - - public static ArrayList getInputs() - { - return inputItems; - } - - public static ArrayList getOutputs() - { - return outputItems; - } - public static ArrayList getFuels() { return fuelItems; @@ -97,7 +59,8 @@ public class TileEntityWoodchipper extends TileEntity implements ISidedInventory itemstack = this.ItemStacks[slot]; this.ItemStacks[slot] = null; return itemstack; - } else + } + else { itemstack = this.ItemStacks[slot].splitStack(qtyToDecr); @@ -108,7 +71,8 @@ public class TileEntityWoodchipper extends TileEntity implements ISidedInventory return itemstack; } - } else + } + else { return null; } @@ -122,7 +86,8 @@ public class TileEntityWoodchipper extends TileEntity implements ISidedInventory ItemStack itemstack = this.ItemStacks[slot]; this.ItemStacks[slot] = null; return itemstack; - } else + } + else { return null; } @@ -268,7 +233,8 @@ public class TileEntityWoodchipper extends TileEntity implements ISidedInventory this.processItem(); flag1 = true; } - } else + } + else { this.processTime = 0; } @@ -290,66 +256,23 @@ public class TileEntityWoodchipper extends TileEntity implements ISidedInventory private boolean canProcess() { - if (this.ItemStacks[0] == null) + ItemStack input = this.ItemStacks[0]; + if (input != null) { - return false; - } else - { - ItemStack output = null; - for (int i = 0; i < inputItems.size(); i++) - { - if (inputItems.get(i).getItem() == ItemStacks[0].getItem() - && inputItems.get(i).getItemDamage() == ItemStacks[0].getItemDamage()) - { - output = new ItemStack(outputItems.get(i).getItem(), qty, outputItems.get(i).getItemDamage()); - } - } - + ItemStack output = WoodchipperRecipes.getInstance().getResult(input); if (output == null) return false; - - if (this.ItemStacks[2] == null) + ItemStack outputSlot = this.ItemStacks[2]; + if (outputSlot == null) return true; - if (!this.ItemStacks[2].isItemEqual(output)) + if (!outputSlot.isItemEqual(output)) return false; - int result = ItemStacks[2].stackSize + output.stackSize; - - return result <= getInventoryStackLimit() && result <= this.ItemStacks[2].getMaxStackSize(); - } - } - - public static boolean removeRecipe(ItemStack itemstack) - { - for (int i = 0; i < inputItems.size(); i++) - { - if (inputItems.get(i) == itemstack) - { - inputItems.remove(i); - outputItems.remove(i); - return true; - } + int result = outputSlot.stackSize + output.stackSize; + return result <= output.getMaxStackSize(); } return false; } - public static void addRecipe(ItemStack input, ItemStack output) - { - inputItems.add(input); - outputItems.add(output); - } - - public static void addRecipe(Item item, ItemStack output) - { - inputItems.add(new ItemStack(item)); - outputItems.add(output); - } - - public static void addRecipe(Block block, ItemStack output) - { - inputItems.add(new ItemStack(block)); - outputItems.add(output); - } - public static void addFuel(ItemStack itemstack) { fuelItems.add(itemstack); @@ -370,13 +293,8 @@ public class TileEntityWoodchipper extends TileEntity implements ISidedInventory public static boolean isValidForWoodchipper(ItemStack itemstack) { - for (int i = 0; i < inputItems.size(); i++) - { - ItemStack temp = inputItems.get(i); - if (temp.getItem() == itemstack.getItem() && temp.getItemDamage() == itemstack.getItemDamage()) - return true; - } - + if(WoodchipperRecipes.getInstance().getResult(itemstack) != null) + return true; return false; } @@ -384,32 +302,23 @@ public class TileEntityWoodchipper extends TileEntity implements ISidedInventory { if (this.canProcess()) { - ItemStack output = null; - for (int i = 0; i < inputItems.size(); i++) + + ItemStack input = ItemStacks[0]; + ItemStack output = WoodchipperRecipes.getInstance().getResult(input); + ItemStack outputSlot = ItemStacks[2]; + if (outputSlot == null) { - if (inputItems.get(i).getItem() == ItemStacks[0].getItem() - && inputItems.get(i).getItemDamage() == ItemStacks[0].getItemDamage()) - { - output = new ItemStack(outputItems.get(i).getItem(), qty, outputItems.get(i).getItemDamage()); - } + ItemStacks[2] = output.copy(); } - - if (output == null) - return; - - if (this.ItemStacks[2] == null) + else if (outputSlot.isItemEqual(output)) { - this.ItemStacks[2] = output.copy(); - } else if (this.ItemStacks[2].getItem() == output.getItem()) - { - this.ItemStacks[2].stackSize += output.stackSize; + outputSlot.stackSize += output.stackSize; } - - --this.ItemStacks[0].stackSize; - - if (this.ItemStacks[0].stackSize <= 0) + + --input.stackSize; + if (input.stackSize <= 0) { - this.ItemStacks[0] = null; + ItemStacks[0] = null; } } } diff --git a/src/main/java/com/oitsjustjose/criss_cross/Util/ConfigHandler.java b/src/main/java/com/oitsjustjose/criss_cross/Util/ConfigHandler.java index c5e786e..89b5b0c 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/Util/ConfigHandler.java +++ b/src/main/java/com/oitsjustjose/criss_cross/Util/ConfigHandler.java @@ -15,33 +15,28 @@ public class ConfigHandler public static String cropomatorRecipeItem; public static String[] cropomatorInputs; public static String[] cropomatorCatalysts; - public static String[] defaultCropomatorInputs = new String[] - { "minecraft:apple", "minecraft:reeds", "minecraft:nether_wart", "minecraft:carrot", "minecraft:cactus", - "minecraft:potato", "minecraft:sapling:0", "minecraft:sapling:1", "minecraft:sapling:2", - "minecraft:sapling:3", "minecraft:sapling:4", "minecraft:sapling:5", "minecraft:melon", - "minecraft:brown_mushroom", "minecraft:red_mushroom", "minecraft:cocoa", "minecraft:pumpkin", - "minecraft:wheat", "minecraft:wheat_seeds" }; - public static String[] defaultCropomatorCatalystItems = new String[] - { "minecraft:dye:15" }; + public static String[] defaultCropomatorInputs = new String[] { "minecraft:apple", "minecraft:reeds", + "minecraft:nether_wart", "minecraft:carrot", "minecraft:cactus", "minecraft:potato", "minecraft:sapling:0", + "minecraft:sapling:1", "minecraft:sapling:2", "minecraft:sapling:3", "minecraft:sapling:4", + "minecraft:sapling:5", "minecraft:melon", "minecraft:brown_mushroom", "minecraft:red_mushroom", + "minecraft:cocoa", "minecraft:pumpkin", "minecraft:wheat", "minecraft:wheat_seeds" }; + public static String[] defaultCropomatorCatalystItems = new String[] { "minecraft:dye:15" }; public static int electroextractorProcessTime; public static int electroextractorOutput; public static String electroextractorRecipeItem; public static String[] electroextractorEnergySources; public static String[] electroextractorOreDictInputs; - public static String[] defaultElectroextractorOreDictInputs = new String[] - { "Iron:12428902", "Gold:15400704", "Aluminum:15987699", "Cobalt:17663", "Ardite:13938485", "Copper:16751872", - "Tin:15132390", "Silver:13297640", "Lead:5722979", "Platinum:11067903", "Mithril:4433113", - "Nickel:16580553" }; - public static String[] defaultElectroextractorEnergySources = new String[] - { "minecraft:redstone_block" }; + public static String[] defaultElectroextractorOreDictInputs = new String[] { "Iron:12428902", "Gold:15400704", + "Aluminum:15987699", "Cobalt:17663", "Ardite:13938485", "Copper:16751872", "Tin:15132390", + "Silver:13297640", "Lead:5722979", "Platinum:11067903", "Mithril:4433113", "Nickel:16580553" }; + public static String[] defaultElectroextractorEnergySources = new String[] { "minecraft:redstone_block" }; public static int woodchipperProcessTime; public static int woodchipperOutput; public static String woodchipperRecipeItem; public static String[] woodchipperFuels; - public static String[] defaultWoodchipperFuels = new String[] - { "minecraft:water_bucket", "minecraft:potion:0" }; + public static String[] defaultWoodchipperFuels = new String[] { "minecraft:water_bucket", "minecraft:potion:0" }; public static void init(File configFile) {