Resource generator now generates only when ore and ingot are present

This commit is contained in:
Calclavia 2014-03-14 18:23:16 +08:00
parent 3f122cd2dd
commit 4ed2a4b424
4 changed files with 144 additions and 135 deletions

View file

@ -88,92 +88,90 @@ public class FluidPressureNode extends Node<IPressureNodeProvider, TickingGrid,
public void distribute()
{
synchronized (getConnections())
Iterator<Entry<Object, ForgeDirection>> it = getConnections().entrySet().iterator();
while (it.hasNext())
{
Iterator<Entry<Object, ForgeDirection>> it = getConnections().entrySet().iterator();
Entry<?, ForgeDirection> entry = it.next();
Object obj = entry.getKey();
ForgeDirection dir = entry.getValue();
while (it.hasNext())
if (obj instanceof FluidPressureNode)
{
Entry<?, ForgeDirection> entry = it.next();
Object obj = entry.getKey();
ForgeDirection dir = entry.getValue();
/**
* Move fluid from higher pressure to lower. In this case, move from tankA to
* tankB.
*/
FluidPressureNode otherNode = (FluidPressureNode) obj;
if (obj instanceof FluidPressureNode)
// A is the pressure in the current node while B is the pressure in the node we
// are iterating through.
int pressureA = getPressure(dir);
int pressureB = otherNode.getPressure(dir.getOpposite());
if (pressureA >= pressureB)
{
/**
* Move fluid from higher pressure to lower. In this case, move from tankA to
* tankB.
*/
FluidPressureNode otherNode = (FluidPressureNode) obj;
FluidTank tankA = parent.getPressureTank();
// A is the pressure in the current node while B is the pressure in the node we
// are iterating through.
int pressureA = getPressure(dir);
int pressureB = otherNode.getPressure(dir.getOpposite());
if (pressureA >= pressureB)
if (tankA != null)
{
FluidTank tankA = parent.getPressureTank();
FluidStack fluidA = tankA.getFluid();
if (tankA != null)
if (fluidA != null)
{
FluidStack fluidA = tankA.getFluid();
int amountA = fluidA.amount;
if (fluidA != null)
if (amountA > 0)
{
int amountA = fluidA.amount;
FluidTank tankB = otherNode.parent.getPressureTank();
if (amountA > 0)
if (tankB != null)
{
FluidTank tankB = otherNode.parent.getPressureTank();
int amountB = tankB.getFluidAmount();
if (tankB != null)
int quantity = Math.max(pressureA > pressureB ? (pressureA - pressureB) * getMaxFlowRate() : 0, Math.min((amountA - amountB) / 2, getMaxFlowRate()));
quantity = Math.min(Math.min(quantity, tankB.getCapacity() - amountB), amountA);
if (quantity > 0)
{
int amountB = tankB.getFluidAmount();
FluidStack drainStack = parent.drain(dir.getOpposite(), quantity, false);
int quantity = Math.max(pressureA > pressureB ? (pressureA - pressureB) * getMaxFlowRate() : 0, Math.min((amountA - amountB) / 2, getMaxFlowRate()));
quantity = Math.min(Math.min(quantity, tankB.getCapacity() - amountB), amountA);
if (quantity > 0)
{
FluidStack drainStack = parent.drain(dir.getOpposite(), quantity, false);
if (drainStack != null && drainStack.amount > 0)
parent.drain(dir.getOpposite(), otherNode.parent.fill(dir, drainStack, true), true);
}
if (drainStack != null && drainStack.amount > 0)
parent.drain(dir.getOpposite(), otherNode.parent.fill(dir, drainStack, true), true);
}
}
}
}
}
}
else if (obj instanceof IFluidHandler)
}
else if (obj instanceof IFluidHandler)
{
IFluidHandler fluidHandler = (IFluidHandler) obj;
int pressure = getPressure(dir);
int tankPressure = fluidHandler instanceof IPressureNodeProvider ? ((IPressureNodeProvider) fluidHandler).getNode(FluidPressureNode.class, dir.getOpposite()).getPressure(dir.getOpposite()) : 0;
FluidTank sourceTank = parent.getPressureTank();
int transferAmount = (Math.max(pressure, tankPressure) - Math.min(pressure, tankPressure)) * getMaxFlowRate();
if (pressure > tankPressure)
{
IFluidHandler fluidHandler = (IFluidHandler) obj;
int pressure = getPressure(dir);
int tankPressure = fluidHandler instanceof IPressureNodeProvider ? ((IPressureNodeProvider) fluidHandler).getNode(FluidPressureNode.class, dir.getOpposite()).getPressure(dir.getOpposite()) : 0;
FluidTank sourceTank = parent.getPressureTank();
int transferAmount = (Math.max(pressure, tankPressure) - Math.min(pressure, tankPressure)) * getMaxFlowRate();
if (pressure > tankPressure)
if (sourceTank.getFluidAmount() > 0 && transferAmount > 0)
{
if (sourceTank.getFluidAmount() > 0 && transferAmount > 0)
{
FluidStack drainStack = parent.drain(dir.getOpposite(), transferAmount, false);
parent.drain(dir.getOpposite(), fluidHandler.fill(dir.getOpposite(), drainStack, true), true);
}
FluidStack drainStack = parent.drain(dir.getOpposite(), transferAmount, false);
parent.drain(dir.getOpposite(), fluidHandler.fill(dir.getOpposite(), drainStack, true), true);
}
else if (pressure < tankPressure)
}
else if (pressure < tankPressure)
{
if (transferAmount > 0)
{
if (transferAmount > 0)
{
FluidStack drainStack = fluidHandler.drain(dir.getOpposite(), transferAmount, false);
FluidStack drainStack = fluidHandler.drain(dir.getOpposite(), transferAmount, false);
if (drainStack != null)
{
fluidHandler.drain(dir.getOpposite(), parent.fill(dir.getOpposite(), drainStack, true), true);
}
if (drainStack != null)
{
fluidHandler.drain(dir.getOpposite(), parent.fill(dir.getOpposite(), drainStack, true), true);
}
}
}

View file

@ -176,7 +176,7 @@ public class ItemOreResource extends Item
@Override
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (String materialName : ResourceGenerator.getMaterials())
for (String materialName : ResourceGenerator.materials.keySet())
{
par3List.add(getStackFromMaterial(materialName));
}

View file

@ -6,6 +6,7 @@ import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
@ -65,7 +66,7 @@ public class ResourceGenerator implements IVirtualObject
* Name, ID
*/
static int maxID = 0;
static final HashBiMap<String, Integer> materials = HashBiMap.create();
public static final HashBiMap<String, Integer> materials = HashBiMap.create();
static final HashMap<String, Integer> materialColorCache = new HashMap<String, Integer>();
static final HashMap<Icon, Integer> iconColorCache = new HashMap<Icon, Integer>();
@ -73,11 +74,12 @@ public class ResourceGenerator implements IVirtualObject
static
{
OreDetectionBlackList.addIngot("ingotRefinedIron");
OreDetectionBlackList.addIngot("uranium");
OreDetectionBlackList.addIngot("ingotUranium");
SaveManager.registerClass("resourceGenerator", ResourceGenerator.class);
SaveManager.register(INSTANCE);
}
// TODO: Generate teh resource here instead of elsewhere...
@ForgeSubscribe
public void oreRegisterEvent(OreRegisterEvent evt)
{
@ -100,6 +102,79 @@ public class ResourceGenerator implements IVirtualObject
}
}
public static void generate(String materialName)
{
// Caps version of the name
String nameCaps = LanguageUtility.capitalizeFirst(materialName);
String localizedName = materialName;
List<ItemStack> list = OreDictionary.getOres("ingot" + nameCaps);
if (list.size() > 0)
{
ItemStack type = list.get(0);
localizedName = type.getDisplayName().trim();
if (LanguageUtility.getLocal(localizedName) != null && LanguageUtility.getLocal(localizedName) != "")
{
localizedName = LanguageUtility.getLocal(localizedName);
}
localizedName.replace(LanguageUtility.getLocal("misc.resonantinduction.ingot"), "").replaceAll("^ ", "").replaceAll(" $", "");
}
/** Generate molten fluids */
FluidColored fluidMolten = new FluidColored(materialNameToMolten(materialName));
fluidMolten.setDensity(7);
fluidMolten.setViscosity(5000);
fluidMolten.setTemperature(273 + 1538);
FluidRegistry.registerFluid(fluidMolten);
LanguageRegistry.instance().addStringLocalization(fluidMolten.getUnlocalizedName(), LanguageUtility.getLocal("tooltip.molten") + " " + localizedName);
BlockFluidMaterial blockFluidMaterial = new BlockFluidMaterial(fluidMolten);
GameRegistry.registerBlock(blockFluidMaterial, "molten" + nameCaps);
ResonantInduction.blockMoltenFluid.put(getID(materialName), blockFluidMaterial);
FluidContainerRegistry.registerFluidContainer(fluidMolten, ResonantInduction.itemBucketMolten.getStackFromMaterial(materialName));
/** Generate dust mixture fluids */
FluidColored fluidMixture = new FluidColored(materialNameToMixture(materialName));
FluidRegistry.registerFluid(fluidMixture);
BlockFluidMixture blockFluidMixture = new BlockFluidMixture(fluidMixture);
LanguageRegistry.instance().addStringLocalization(fluidMixture.getUnlocalizedName(), localizedName + " " + LanguageUtility.getLocal("tooltip.mixture"));
GameRegistry.registerBlock(blockFluidMixture, "mixture" + nameCaps);
ResonantInduction.blockMixtureFluids.put(getID(materialName), blockFluidMixture);
FluidContainerRegistry.registerFluidContainer(fluidMixture, ResonantInduction.itemBucketMixture.getStackFromMaterial(materialName));
ItemStack dust = ResonantInduction.itemDust.getStackFromMaterial(materialName);
ItemStack rubble = ResonantInduction.itemRubble.getStackFromMaterial(materialName);
ItemStack refinedDust = ResonantInduction.itemRefinedDust.getStackFromMaterial(materialName);
if (allowOreDictCompatibility)
{
OreDictionary.registerOre("dust" + nameCaps, ResonantInduction.itemDust.getStackFromMaterial(materialName));
OreDictionary.registerOre("rubble" + nameCaps, ResonantInduction.itemRubble.getStackFromMaterial(materialName));
OreDictionary.registerOre("dustRefined" + nameCaps, ResonantInduction.itemRefinedDust.getStackFromMaterial(materialName));
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER, "rubble" + nameCaps, dust, dust);
MachineRecipes.INSTANCE.addRecipe(RecipeType.MIXER, "dust" + nameCaps, refinedDust);
MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER, new FluidStack(fluidMolten, FluidContainerRegistry.BUCKET_VOLUME), "ingot" + nameCaps);
}
else
{
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER, rubble, dust, dust);
MachineRecipes.INSTANCE.addRecipe(RecipeType.MIXER, dust, refinedDust);
MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER, new FluidStack(fluidMolten, FluidContainerRegistry.BUCKET_VOLUME), "ingot" + nameCaps);
}
FurnaceRecipes.smelting().addSmelting(dust.itemID, dust.getItemDamage(), OreDictionary.getOres("ingot" + nameCaps).get(0).copy(), 0.7f);
ItemStack smeltResult = OreDictionary.getOres("ingot" + nameCaps).get(0).copy();
FurnaceRecipes.smelting().addSmelting(refinedDust.itemID, refinedDust.getItemDamage(), smeltResult, 0.7f);
if (OreDictionary.getOres("ore" + nameCaps).size() > 0)
{
MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER, "ore" + nameCaps, "rubble" + nameCaps);
}
}
public static void generateOreResources()
{
OreDictionary.registerOre("ingotGold", Item.ingotGold);
@ -108,11 +183,7 @@ public class ResourceGenerator implements IVirtualObject
OreDictionary.registerOre("oreGold", Block.oreGold);
OreDictionary.registerOre("oreIron", Block.oreIron);
OreDictionary.registerOre("oreLapis", Block.oreLapis);
regenerateOreResources();
}
public static void regenerateOreResources()
{
// Vanilla fluid recipes
MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER, new FluidStack(FluidRegistry.LAVA, FluidContainerRegistry.BUCKET_VOLUME), new ItemStack(Block.stone));
@ -126,77 +197,16 @@ public class ResourceGenerator implements IVirtualObject
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER, Block.gravel, Block.sand);
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER, Block.glass, Block.sand);
for (String materialName : materials.keySet())
Iterator<String> it = materials.keySet().iterator();
while (it.hasNext())
{
// Caps version of the name
String materialName = it.next();
String nameCaps = LanguageUtility.capitalizeFirst(materialName);
String localizedName = materialName;
List<ItemStack> list = OreDictionary.getOres("ingot" + materialName.substring(0, 1).toUpperCase() + materialName.substring(1));
if (list.size() > 0)
{
ItemStack type = list.get(0);
localizedName = type.getDisplayName();
if (LanguageUtility.getLocal(localizedName) != null && LanguageUtility.getLocal(localizedName) != "")
{
localizedName = LanguageUtility.getLocal(localizedName);
}
localizedName.replace(LanguageUtility.getLocal("misc.resonantinduction.ingot"), "").replaceAll("^ ", "").replaceAll(" $", "");
}
/** Generate molten fluids */
FluidColored fluidMolten = new FluidColored(materialNameToMolten(materialName));
fluidMolten.setDensity(7);
fluidMolten.setViscosity(5000);
fluidMolten.setTemperature(273 + 1538);
FluidRegistry.registerFluid(fluidMolten);
LanguageRegistry.instance().addStringLocalization(fluidMolten.getUnlocalizedName(), LanguageUtility.getLocal("tooltip.molten") + " " + localizedName);
BlockFluidMaterial blockFluidMaterial = new BlockFluidMaterial(fluidMolten);
GameRegistry.registerBlock(blockFluidMaterial, "molten" + nameCaps);
ResonantInduction.blockMoltenFluid.put(getID(materialName), blockFluidMaterial);
FluidContainerRegistry.registerFluidContainer(fluidMolten, ResonantInduction.itemBucketMolten.getStackFromMaterial(materialName));
/** Generate dust mixture fluids */
FluidColored fluidMixture = new FluidColored(materialNameToMixture(materialName));
FluidRegistry.registerFluid(fluidMixture);
BlockFluidMixture blockFluidMixture = new BlockFluidMixture(fluidMixture);
LanguageRegistry.instance().addStringLocalization(fluidMixture.getUnlocalizedName(), localizedName + " " + LanguageUtility.getLocal("tooltip.mixture"));
GameRegistry.registerBlock(blockFluidMixture, "mixture" + nameCaps);
ResonantInduction.blockMixtureFluids.put(getID(materialName), blockFluidMixture);
FluidContainerRegistry.registerFluidContainer(fluidMixture, ResonantInduction.itemBucketMixture.getStackFromMaterial(materialName));
ItemStack dust = ResonantInduction.itemDust.getStackFromMaterial(materialName);
ItemStack rubble = ResonantInduction.itemRubble.getStackFromMaterial(materialName);
ItemStack refinedDust = ResonantInduction.itemRefinedDust.getStackFromMaterial(materialName);
if (allowOreDictCompatibility)
{
OreDictionary.registerOre("dust" + nameCaps, ResonantInduction.itemDust.getStackFromMaterial(materialName));
OreDictionary.registerOre("rubble" + nameCaps, ResonantInduction.itemRubble.getStackFromMaterial(materialName));
OreDictionary.registerOre("dustRefined" + nameCaps, ResonantInduction.itemRefinedDust.getStackFromMaterial(materialName));
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER, "rubble" + nameCaps, dust, dust);
MachineRecipes.INSTANCE.addRecipe(RecipeType.MIXER, "dust" + nameCaps, refinedDust);
MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER, new FluidStack(fluidMolten, FluidContainerRegistry.BUCKET_VOLUME), "ingot" + nameCaps);
}
else
{
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER, rubble, dust, dust);
MachineRecipes.INSTANCE.addRecipe(RecipeType.MIXER, dust, refinedDust);
MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER, new FluidStack(fluidMolten, FluidContainerRegistry.BUCKET_VOLUME), "ingot" + nameCaps);
}
FurnaceRecipes.smelting().addSmelting(dust.itemID, dust.getItemDamage(), OreDictionary.getOres("ingot" + nameCaps).get(0).copy(), 0.7f);
ItemStack smeltResult = OreDictionary.getOres("ingot" + nameCaps).get(0).copy();
FurnaceRecipes.smelting().addSmelting(refinedDust.itemID, refinedDust.getItemDamage(), smeltResult, 0.7f);
if (OreDictionary.getOres("ore" + nameCaps).size() > 0)
{
MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER, "ore" + nameCaps, "rubble" + nameCaps);
}
generate(materialName);
else
it.remove();
}
}
@ -380,6 +390,7 @@ public class ResourceGenerator implements IVirtualObject
return 0xFFFFFF;
}
@Deprecated
public static List<String> getMaterials()
{
List<String> returnMaterials = new ArrayList<String>();

View file

@ -57,7 +57,7 @@ public class ItemOreResourceBucket extends Item
String fluidName = FluidRegistry.getFluid(fluidID).getLocalizedName();
return (LanguageUtility.getLocal(this.getUnlocalizedName() + ".name")).replace("%v", fluidName).replace(" ", " ");
}
return material;
}
@ -271,7 +271,7 @@ public class ItemOreResourceBucket extends Item
@Override
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (String materialName : ResourceGenerator.getMaterials())
for (String materialName : ResourceGenerator.materials.keySet())
{
par3List.add(getStackFromMaterial(materialName));
}