From f5bc748171985a49ec05c37abaa9953c248eb059 Mon Sep 17 00:00:00 2001 From: DarkGuardsman Date: Mon, 4 Nov 2013 11:46:10 -0500 Subject: [PATCH] Worked on processor and toyed with a few things --- src/dark/api/energy/ExtraBlockData.java | 59 ++++++++++++- src/dark/api/energy/IHeatObject.java | 12 +-- .../api/{ => reciepes}/ProcessorRecipe.java | 2 +- .../api/{ => reciepes}/ProcessorRecipes.java | 88 +++++++++---------- src/dark/core/common/CoreRecipeLoader.java | 4 +- src/dark/core/common/DarkMain.java | 4 +- src/dark/core/interfaces/IInvBox.java | 4 +- src/dark/core/prefab/ModPrefab.java | 2 +- .../prefab/helpers/AutoCraftingManager.java | 8 +- src/dark/core/prefab/invgui/InvChest.java | 16 +++- 10 files changed, 129 insertions(+), 70 deletions(-) rename src/dark/api/{ => reciepes}/ProcessorRecipe.java (96%) rename src/dark/api/{ => reciepes}/ProcessorRecipes.java (86%) diff --git a/src/dark/api/energy/ExtraBlockData.java b/src/dark/api/energy/ExtraBlockData.java index 753880d6..fd5107d5 100644 --- a/src/dark/api/energy/ExtraBlockData.java +++ b/src/dark/api/energy/ExtraBlockData.java @@ -2,22 +2,56 @@ package dark.api.energy; import java.util.HashMap; +import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import universalelectricity.core.vector.Vector3; import com.builtbroken.common.Pair; +import com.builtbroken.common.science.ChemElement; /** Information about blocks not provided by minecraft such as density, mass, volume, heating values, * chemical properties, etc etc - * + * * @author DarkGuardsman */ public class ExtraBlockData { - HashMap, HeatEnergyData> blockTempature = new HashMap(); + private HashMap, HeatEnergyData> blockTempature = new HashMap(); + /** Map of blocks that can directly be linked to an element. This will be rare as most blocks are + * not one element type. */ + private HashMap, ChemElement> blockElement = new HashMap(); + /** Very basic list of default temp of blocks */ + private HashMap, Integer> blockTempDefaults = new HashMap(); + private static ExtraBlockData instance; + + static + { + + } + + public static ExtraBlockData instance() + { + if (instance == null) + { + instance = new ExtraBlockData(); + } + return instance; + } + + /** Returns a temp at the given location in kelvin + * + * @param world + * @param vec + * @return */ public static double getTempature(World world, Vector3 vec) { - return 0; + if (world != null && vec != null) + { + int blockID = vec.getBlockID(world); + int meta = vec.getBlockMetadata(world); + TileEntity entity = vec.getTileEntity(world); + } + return 270; } public static class HeatEnergyData @@ -25,4 +59,23 @@ public class ExtraBlockData public float maxTempature; public float defaultTempature; } + + public void onWorldUpdate() + { + /*TODO tap into the world update to allow a slow recalculation of heat level per location. + * Remember to keep CPU time very low for this as it should be passive letting machines + * control the heat level rather than the world. Though a small amount of the machines heat + * output can be managed by this class + */ + } + + public void loadMap() + { + + } + + public void saveMap() + { + //TODO tap into the chunk manager to save an extra layer of date for heat level for each block. + } } diff --git a/src/dark/api/energy/IHeatObject.java b/src/dark/api/energy/IHeatObject.java index 4a7d2e7f..c2094287 100644 --- a/src/dark/api/energy/IHeatObject.java +++ b/src/dark/api/energy/IHeatObject.java @@ -4,20 +4,20 @@ import net.minecraftforge.common.ForgeDirection; import dark.api.parts.ITileConnector; /** Used by TileEntities or Entities to show heat stored and cooling rate of the object - * + * * @author DarkGuardsman */ public interface IHeatObject extends ITileConnector { /** Amount of heat stored in the body of the object. Think of it as a battery for heat but - * remember that heat is lost very fast - * + * remember that heat should be lost rather than keep over time. + * * @return amount of heat in generic units */ public float getHeat(ForgeDirection side); - /** Sets the heat level of the object or increase it - * - * @param amount - amount to set or increase by + /** Sets the heat level of the object or increases it + * + * @param amount - amount to set or increase by. Can be neg to indicate a lose of heat * @param incrase - true if should increase the current heat level */ public void setHeat(double amount, boolean incrase); diff --git a/src/dark/api/ProcessorRecipe.java b/src/dark/api/reciepes/ProcessorRecipe.java similarity index 96% rename from src/dark/api/ProcessorRecipe.java rename to src/dark/api/reciepes/ProcessorRecipe.java index 57fbb952..83b35ff9 100644 --- a/src/dark/api/ProcessorRecipe.java +++ b/src/dark/api/reciepes/ProcessorRecipe.java @@ -1,4 +1,4 @@ -package dark.api; +package dark.api.reciepes; import net.minecraft.item.ItemStack; /** Processor Recipe output Container. Input is controlled by the processor recipes class. */ diff --git a/src/dark/api/ProcessorRecipes.java b/src/dark/api/reciepes/ProcessorRecipes.java similarity index 86% rename from src/dark/api/ProcessorRecipes.java rename to src/dark/api/reciepes/ProcessorRecipes.java index 74d782e9..546e1a72 100644 --- a/src/dark/api/ProcessorRecipes.java +++ b/src/dark/api/reciepes/ProcessorRecipes.java @@ -1,4 +1,4 @@ -package dark.api; +package dark.api.reciepes; import java.util.ArrayList; import java.util.HashMap; @@ -15,6 +15,7 @@ import net.minecraftforge.oredict.OreDictionary; import com.builtbroken.common.Pair; import cpw.mods.fml.common.registry.GameRegistry; +import dark.api.ColorCode; import dark.core.common.CoreRecipeLoader; import dark.core.common.items.EnumMaterial; import dark.core.common.items.EnumOrePart; @@ -157,15 +158,43 @@ public class ProcessorRecipes * @return array of itemStacks */ public static ItemStack[] getOuput(ProcessorType type, ItemStack stack, boolean damageSalvage) { - if (stack == null || type == null || stack.getItem() == null) + if (stack != null && type != null) { - return null; + ItemStack[] reList = getOuputNormal(type, stack); + if (reList == null) + { + reList = salvageItem(type, stack); + } + return reList; } - Pair blockSet = new Pair(stack.itemID, stack.getItemDamage()); + return null; + } - HashMap, ItemStack> altSalvageMap = type.altOutput; + public static ItemStack[] salvageItem(ProcessorType type, ItemStack stack) + { + //TODO find a way around having to force single output size salvaging + ItemStack[] recipeList = AutoCraftingManager.getReverseRecipe(stack.copy(), 1); + ItemStack[] reList = new ItemStack[recipeList.length]; + for (int i = 0; i < recipeList.length; i++) + { + if (recipeList[i] != null && random.nextFloat() >= .3f) + { + reList[i] = recipeList[i]; + if (recipeList[i].itemID < Block.blocksList.length && Block.blocksList[recipeList[i].itemID] != null && recipeList[i].getItemDamage() > 16) + { + reList[i].setItemDamage(0); + } + if (type.altOutput != null && type.altOutput.containsKey(new Pair(reList[i].itemID, reList[i].getItemDamage()))) + { + reList[i] = convert(type.altOutput.get(new Pair(reList[i].itemID, reList[i].getItemDamage()))); + } + } + } + return reList; + } - //Read normal recipe map for outputs + public static ItemStack[] getOuputNormal(ProcessorType type, ItemStack stack) + { if (type.itemRecipes != null) { ProcessorRecipe re = type.itemRecipes.get(new Pair(stack.itemID, -1)); @@ -173,6 +202,10 @@ public class ProcessorRecipes { re = type.itemRecipes.get(new Pair(stack.itemID, stack.getItemDamage())); } + if (type.altOutput != null && (re == null || re.output == null)) + { + return new ItemStack[] { type.altOutput.get(new Pair(stack.itemID, stack.getItemDamage())) }; + } if (re != null && re.output != null) { ItemStack output = re.output.copy(); @@ -185,48 +218,7 @@ public class ProcessorRecipes } } - //Read chance output map - Pair ree = mapChance.get(blockSet); - if (ree != null && random.nextFloat() >= ree.right()) - { - return new ItemStack[] { convert(ree.left()) }; - } - - //Start salvaging items - ItemStack[] recipeList = AutoCraftingManager.getReverseRecipe(stack.copy()); - ItemStack[] reList = null; - if (recipeList != null) - { - reList = new ItemStack[recipeList.length]; - for (int i = 0; i < recipeList.length; i++) - { - if (recipeList[i] != null && random.nextFloat() >= .3f) - { - int meta = recipeList[i].getItemDamage(); - reList[i] = recipeList[i]; - if (recipeList[i].itemID < Block.blocksList.length && Block.blocksList[recipeList[i].itemID] != null && recipeList[i].getItemDamage() > 16) - { - reList[i].setItemDamage(0); - } - if (damageSalvage && altSalvageMap != null && altSalvageMap.containsKey(new Pair(reList[i].itemID, reList[i].getItemDamage()))) - { - reList[i] = convert(altSalvageMap.get(new Pair(reList[i].itemID, reList[i].getItemDamage()))); - } - } - } - } - return reList; - } - - public static ItemStack[] getOuputNormal(ProcessorType type, ItemStack stack, boolean damageSalvage) - { - if (stack == null || type == null || stack.getItem() == null) - { - return null; - } - ItemStack[] reList = null; - - return reList; + return null; } public static void parseOreNames(Configuration config) diff --git a/src/dark/core/common/CoreRecipeLoader.java b/src/dark/core/common/CoreRecipeLoader.java index 8a9eed1d..41d79285 100644 --- a/src/dark/core/common/CoreRecipeLoader.java +++ b/src/dark/core/common/CoreRecipeLoader.java @@ -8,8 +8,8 @@ import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraftforge.oredict.ShapedOreRecipe; import cpw.mods.fml.common.registry.GameRegistry; import dark.api.ColorCode; -import dark.api.ProcessorRecipes; -import dark.api.ProcessorRecipes.ProcessorType; +import dark.api.reciepes.ProcessorRecipes; +import dark.api.reciepes.ProcessorRecipes.ProcessorType; import dark.core.common.blocks.BlockBasalt; import dark.core.common.blocks.BlockOre; import dark.core.common.blocks.BlockOre.OreData; diff --git a/src/dark/core/common/DarkMain.java b/src/dark/core/common/DarkMain.java index a367320b..5a627a18 100644 --- a/src/dark/core/common/DarkMain.java +++ b/src/dark/core/common/DarkMain.java @@ -33,8 +33,8 @@ import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.registry.TickRegistry; import cpw.mods.fml.relauncher.Side; -import dark.api.ProcessorRecipes; -import dark.api.ProcessorRecipes.ProcessorType; +import dark.api.reciepes.ProcessorRecipes; +import dark.api.reciepes.ProcessorRecipes.ProcessorType; import dark.core.common.RecipeLoader.RecipeGrid; import dark.core.common.blocks.BlockBasalt; import dark.core.common.blocks.BlockColorGlass; diff --git a/src/dark/core/interfaces/IInvBox.java b/src/dark/core/interfaces/IInvBox.java index 55a80302..23e9f6c1 100644 --- a/src/dark/core/interfaces/IInvBox.java +++ b/src/dark/core/interfaces/IInvBox.java @@ -9,7 +9,7 @@ import net.minecraft.nbt.NBTTagCompound; * automation. As well this is not designed to replace the need for IInventory support of a tile but * to make it easier to manage. Suggested use it to create a prefab manager for several tiles. Then * have those tiles use the prefab as an extermal inventory manager to reduce code size per class. - * + * * @author DarkGuardsman */ public interface IInvBox extends ISidedInventory { @@ -17,7 +17,7 @@ public interface IInvBox extends ISidedInventory public ItemStack[] getContainedItems(); /** Called to save the inventory array */ - public void saveInv(NBTTagCompound tag); + public NBTTagCompound saveInv(NBTTagCompound tag); /** Called to load the inventory array */ public void loadInv(NBTTagCompound tag); diff --git a/src/dark/core/prefab/ModPrefab.java b/src/dark/core/prefab/ModPrefab.java index 6b5b65ee..4113ede8 100644 --- a/src/dark/core/prefab/ModPrefab.java +++ b/src/dark/core/prefab/ModPrefab.java @@ -19,7 +19,7 @@ import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.relauncher.Side; -import dark.api.ProcessorRecipes; +import dark.api.reciepes.ProcessorRecipes; import dark.core.common.ExternalModHandler; import dark.core.prefab.helpers.FluidHelper; import dark.core.registration.ModObjectRegistry; diff --git a/src/dark/core/prefab/helpers/AutoCraftingManager.java b/src/dark/core/prefab/helpers/AutoCraftingManager.java index 92bd6b9c..8bae6b76 100644 --- a/src/dark/core/prefab/helpers/AutoCraftingManager.java +++ b/src/dark/core/prefab/helpers/AutoCraftingManager.java @@ -96,7 +96,7 @@ public class AutoCraftingManager { ShapelessOreRecipe oreRecipe = (ShapelessOreRecipe) recipe; ArrayList oreRecipeInput = (ArrayList) ReflectionHelper.getPrivateValue(ShapelessOreRecipe.class, oreRecipe, "input"); - for(Object obj : oreRecipeInput) + for (Object obj : oreRecipeInput) { System.out.println(obj); } @@ -194,7 +194,7 @@ public class AutoCraftingManager /** Gets a basic array containing all items that were used to craft the given item. Doesn't sort * threw the recipes and will return the first possible recipe */ - public static ItemStack[] getReverseRecipe(ItemStack outputItem) + public static ItemStack[] getReverseRecipe(ItemStack outputItem, int outputSize) { for (Object object : CraftingManager.getInstance().getRecipeList()) @@ -203,7 +203,7 @@ public class AutoCraftingManager { if (((IRecipe) object).getRecipeOutput() != null) { - if (((IRecipe) object).getRecipeOutput().isItemEqual(outputItem)) + if (((IRecipe) object).getRecipeOutput().isItemEqual(outputItem) && (outputSize == -1 || ((IRecipe) object).getRecipeOutput().stackSize == outputItem.stackSize)) { if (object instanceof ShapedRecipes) { @@ -239,7 +239,7 @@ public class AutoCraftingManager { ItemStack recipeItem = (ItemStack) ingredientsArray[x]; actualResources.add(recipeItem.copy()); - + break; } } } diff --git a/src/dark/core/prefab/invgui/InvChest.java b/src/dark/core/prefab/invgui/InvChest.java index 2d4ea44e..ab30875f 100644 --- a/src/dark/core/prefab/invgui/InvChest.java +++ b/src/dark/core/prefab/invgui/InvChest.java @@ -1,5 +1,6 @@ package dark.core.prefab.invgui; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -34,6 +35,12 @@ public class InvChest implements IInvBox this(chest, ((IExternalInv) chest), slots); } + public InvChest(Entity entity, int i) + { + this.slots = i; + this.inv = (IExternalInv) entity; + } + @Override public int getSizeInventory() { @@ -176,14 +183,20 @@ public class InvChest implements IInvBox @Override public void onInventoryChanged() { + if(this.hostTile != null){ this.hostTile.onInventoryChanged(); + } } @Override public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer) { + if(this.hostTile != null) + { return this.hostTile.worldObj.getBlockTileEntity(this.hostTile.xCoord, this.hostTile.yCoord, this.hostTile.zCoord) != this.hostTile ? false : par1EntityPlayer.getDistanceSq(this.hostTile.xCoord + 0.5D, this.hostTile.yCoord + 0.5D, this.hostTile.zCoord + 0.5D) <= 64.0D; } + return true; + } @Override public ItemStack[] getContainedItems() @@ -196,7 +209,7 @@ public class InvChest implements IInvBox } @Override - public void saveInv(NBTTagCompound nbt) + public NBTTagCompound saveInv(NBTTagCompound nbt) { NBTTagList itemList = new NBTTagList(); for (int s = 0; s < this.getContainedItems().length; ++s) @@ -210,6 +223,7 @@ public class InvChest implements IInvBox } } nbt.setTag("Items", itemList); + return nbt; } @Override