Worked on processor and toyed with a few things

This commit is contained in:
DarkGuardsman 2013-11-04 11:46:10 -05:00
parent 21af3b9d6d
commit f5bc748171
10 changed files with 129 additions and 70 deletions

View file

@ -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<Pair<Integer, Integer>, HeatEnergyData> blockTempature = new HashMap();
private HashMap<Pair<Integer, Integer>, 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<Pair<Integer, Integer>, ChemElement> blockElement = new HashMap();
/** Very basic list of default temp of blocks */
private HashMap<Pair<Integer, Integer>, 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.
}
}

View file

@ -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);

View file

@ -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. */

View file

@ -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<Integer, Integer> blockSet = new Pair<Integer, Integer>(stack.itemID, stack.getItemDamage());
return null;
}
HashMap<Pair<Integer, Integer>, 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<Integer, Integer>(reList[i].itemID, reList[i].getItemDamage())))
{
reList[i] = convert(type.altOutput.get(new Pair<Integer, Integer>(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<Integer, Integer>(stack.itemID, -1));
@ -173,6 +202,10 @@ public class ProcessorRecipes
{
re = type.itemRecipes.get(new Pair<Integer, Integer>(stack.itemID, stack.getItemDamage()));
}
if (type.altOutput != null && (re == null || re.output == null))
{
return new ItemStack[] { type.altOutput.get(new Pair<Integer, Integer>(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<ItemStack, Float> 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<Integer, Integer>(reList[i].itemID, reList[i].getItemDamage())))
{
reList[i] = convert(altSalvageMap.get(new Pair<Integer, Integer>(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)

View file

@ -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;

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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;
}
}
}

View file

@ -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