mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
pushing to prod without testing
woo!!
This commit is contained in:
parent
b64ab034c7
commit
b588919736
@ -1,5 +1,7 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.inventory.RecipesCommon.AStack;
|
||||
@ -11,6 +13,7 @@ import com.hbm.tileentity.IGUIProvider;
|
||||
import com.hbm.tileentity.TileEntityMachineBase;
|
||||
import com.hbm.tileentity.machine.storage.TileEntityCrateTemplate;
|
||||
import com.hbm.util.InventoryUtil;
|
||||
import com.hbm.util.ItemStackUtil;
|
||||
import com.hbm.util.fauxpointtwelve.DirPos;
|
||||
|
||||
import api.hbm.energymk2.IEnergyReceiverMK2;
|
||||
@ -27,13 +30,13 @@ public abstract class TileEntityMachineAssemblerBase extends TileEntityMachineBa
|
||||
public int[] maxProgress;
|
||||
public boolean isProgressing;
|
||||
public boolean[] needsTemplateSwitch;
|
||||
|
||||
|
||||
int consumption = 100;
|
||||
int speed = 100;
|
||||
|
||||
public TileEntityMachineAssemblerBase(int scount) {
|
||||
super(scount);
|
||||
|
||||
|
||||
int count = this.getRecipeCount();
|
||||
|
||||
progress = new int[count];
|
||||
@ -43,20 +46,20 @@ public abstract class TileEntityMachineAssemblerBase extends TileEntityMachineBa
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
|
||||
int count = this.getRecipeCount();
|
||||
|
||||
|
||||
this.isProgressing = false;
|
||||
this.power = Library.chargeTEFromItems(slots, getPowerSlot(), power, this.getMaxPower());
|
||||
|
||||
|
||||
for(int i = 0; i < count; i++) {
|
||||
unloadItems(i);
|
||||
loadItems(i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
for(int i = 0; i < count; i++) {
|
||||
if(!canProcess(i)) {
|
||||
this.progress[i] = 0;
|
||||
@ -67,53 +70,62 @@ public abstract class TileEntityMachineAssemblerBase extends TileEntityMachineBa
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected boolean canProcess(int index) {
|
||||
|
||||
|
||||
int template = getTemplateIndex(index);
|
||||
|
||||
|
||||
if(slots[template] == null || slots[template].getItem() != ModItems.assembly_template)
|
||||
return false;
|
||||
|
||||
List<AStack> recipe = AssemblerRecipes.getRecipeFromTempate(slots[template]);
|
||||
ItemStack output = AssemblerRecipes.getOutputFromTempate(slots[template]);
|
||||
|
||||
|
||||
if(recipe == null)
|
||||
return false;
|
||||
|
||||
|
||||
if(this.power < this.consumption) return false;
|
||||
if(!hasRequiredItems(recipe, index)) return false;
|
||||
if(!hasSpaceForItems(output, index)) return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public HashMap<ItemStack[], Boolean> cachedItems = new HashMap<>();
|
||||
|
||||
private boolean hasRequiredItems(List<AStack> recipe, int index) {
|
||||
int[] indices = getSlotIndicesFromIndex(index);
|
||||
return InventoryUtil.doesArrayHaveIngredients(slots, indices[0], indices[1], recipe.toArray(new AStack[0]));
|
||||
ItemStack[] copy = ItemStackUtil.carefulCopyArrayTruncate(slots, indices[0], indices[1]);
|
||||
if (cachedItems.get(copy) != null)
|
||||
return cachedItems.get(copy);
|
||||
else {
|
||||
boolean hasItems = InventoryUtil.doesArrayHaveIngredients(slots, indices[0], indices[1], recipe.toArray(new AStack[0]));
|
||||
cachedItems.put(copy, hasItems);
|
||||
return hasItems;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean hasSpaceForItems(ItemStack recipe, int index) {
|
||||
int[] indices = getSlotIndicesFromIndex(index);
|
||||
return InventoryUtil.doesArrayHaveSpace(slots, indices[2], indices[2], new ItemStack[] { recipe });
|
||||
}
|
||||
|
||||
|
||||
protected void process(int index) {
|
||||
|
||||
|
||||
this.power -= this.consumption;
|
||||
this.progress[index]++;
|
||||
|
||||
|
||||
if(slots[0] != null && slots[0].getItem() == ModItems.meteorite_sword_alloyed)
|
||||
slots[0] = new ItemStack(ModItems.meteorite_sword_machined); //fisfndmoivndlmgindgifgjfdnblfm
|
||||
|
||||
|
||||
int template = getTemplateIndex(index);
|
||||
|
||||
List<AStack> recipe = AssemblerRecipes.getRecipeFromTempate(slots[template]);
|
||||
ItemStack output = AssemblerRecipes.getOutputFromTempate(slots[template]);
|
||||
int time = ItemAssemblyTemplate.getProcessTime(slots[template]);
|
||||
|
||||
|
||||
this.maxProgress[index] = time * this.speed / 100;
|
||||
|
||||
|
||||
if(this.progress[index] >= this.maxProgress[index]) {
|
||||
consumeItems(recipe, index);
|
||||
produceItems(output, index);
|
||||
@ -122,28 +134,28 @@ public abstract class TileEntityMachineAssemblerBase extends TileEntityMachineBa
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void consumeItems(List<AStack> recipe, int index) {
|
||||
|
||||
|
||||
int[] indices = getSlotIndicesFromIndex(index);
|
||||
|
||||
|
||||
for(AStack in : recipe) {
|
||||
if(in != null)
|
||||
InventoryUtil.tryConsumeAStack(slots, indices[0], indices[1], in);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void produceItems(ItemStack out, int index) {
|
||||
|
||||
|
||||
int[] indices = getSlotIndicesFromIndex(index);
|
||||
|
||||
|
||||
if(out != null) {
|
||||
InventoryUtil.tryAddItemToInventory(slots, indices[2], indices[2], out.copy());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void loadItems(int index) {
|
||||
|
||||
|
||||
int template = getTemplateIndex(index);
|
||||
|
||||
DirPos[] positions = getInputPositions();
|
||||
@ -152,7 +164,7 @@ public abstract class TileEntityMachineAssemblerBase extends TileEntityMachineBa
|
||||
for(DirPos coord : positions) {
|
||||
|
||||
TileEntity te = worldObj.getTileEntity(coord.getX(), coord.getY(), coord.getZ());
|
||||
|
||||
|
||||
if(te instanceof IInventory) {
|
||||
|
||||
IInventory inv = (IInventory) te;
|
||||
@ -174,7 +186,7 @@ public abstract class TileEntityMachineAssemblerBase extends TileEntityMachineBa
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boolean noTemplate = slots[template] == null || slots[template].getItem() != ModItems.assembly_template;
|
||||
|
||||
if(!noTemplate) {
|
||||
@ -184,17 +196,17 @@ public abstract class TileEntityMachineAssemblerBase extends TileEntityMachineBa
|
||||
if(recipe != null) {
|
||||
|
||||
for(AStack ingredient : recipe) {
|
||||
|
||||
|
||||
int tracker = 0;
|
||||
|
||||
outer: while(!InventoryUtil.doesArrayHaveIngredients(slots, indices[0], indices[1], ingredient)) {
|
||||
|
||||
|
||||
if(tracker++ > 10) break;
|
||||
|
||||
boolean found = false;
|
||||
|
||||
for(int i = 0; i < (access != null ? access.length : inv.getSizeInventory()); i++) {
|
||||
|
||||
|
||||
int slot = access != null ? access[i] : i;
|
||||
ItemStack stack = inv.getStackInSlot(slot);
|
||||
if(ingredient.matchesRecipe(stack, true) && (sided == null || sided.canExtractItem(slot, stack, 0))) {
|
||||
@ -229,25 +241,25 @@ public abstract class TileEntityMachineAssemblerBase extends TileEntityMachineBa
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void unloadItems(int index) {
|
||||
|
||||
DirPos[] positions = getOutputPositions();
|
||||
int[] indices = getSlotIndicesFromIndex(index);
|
||||
|
||||
|
||||
for(DirPos coord : positions) {
|
||||
|
||||
|
||||
TileEntity te = worldObj.getTileEntity(coord.getX(), coord.getY(), coord.getZ());
|
||||
|
||||
|
||||
if(te instanceof IInventory) {
|
||||
|
||||
|
||||
IInventory inv = (IInventory) te;
|
||||
ISidedInventory sided = inv instanceof ISidedInventory ? (ISidedInventory) inv : null;
|
||||
int[] access = sided != null ? sided.getAccessibleSlotsFromSide(coord.getDir().ordinal()) : null;
|
||||
|
||||
|
||||
int i = indices[2];
|
||||
ItemStack out = slots[i];
|
||||
|
||||
|
||||
int template = getTemplateIndex(index);
|
||||
if(this.needsTemplateSwitch[index] && te instanceof TileEntityCrateTemplate && slots[template] != null) {
|
||||
out = slots[template];
|
||||
@ -259,10 +271,10 @@ public abstract class TileEntityMachineAssemblerBase extends TileEntityMachineBa
|
||||
for(int j = 0; j < (access != null ? access.length : inv.getSizeInventory()); j++) {
|
||||
|
||||
int slot = access != null ? access[j] : j;
|
||||
|
||||
|
||||
if(!(sided != null ? sided.canInsertItem(slot, out, coord.getDir().ordinal()) : inv.isItemValidForSlot(slot, out)))
|
||||
continue;
|
||||
|
||||
|
||||
ItemStack target = inv.getStackInSlot(slot);
|
||||
|
||||
if(InventoryUtil.doesStackDataMatch(out, target) && target.stackSize < target.getMaxStackSize() && target.stackSize < inv.getInventoryStackLimit()) {
|
||||
@ -275,7 +287,7 @@ public abstract class TileEntityMachineAssemblerBase extends TileEntityMachineBa
|
||||
for(int j = 0; j < (access != null ? access.length : inv.getSizeInventory()); j++) {
|
||||
|
||||
int slot = access != null ? access[j] : j;
|
||||
|
||||
|
||||
if(!inv.isItemValidForSlot(slot, out))
|
||||
continue;
|
||||
|
||||
@ -291,20 +303,20 @@ public abstract class TileEntityMachineAssemblerBase extends TileEntityMachineBa
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
|
||||
this.power = nbt.getLong("power");
|
||||
if(nbt.hasKey("progress")) this.progress = nbt.getIntArray("progress");
|
||||
if(nbt.hasKey("maxProgress")) this.maxProgress = nbt.getIntArray("maxProgress");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
|
||||
nbt.setLong("power", power);
|
||||
nbt.setIntArray("progress", progress);
|
||||
nbt.setIntArray("maxProgress", maxProgress);
|
||||
@ -322,7 +334,7 @@ public abstract class TileEntityMachineAssemblerBase extends TileEntityMachineBa
|
||||
|
||||
public abstract int getRecipeCount();
|
||||
public abstract int getTemplateIndex(int index);
|
||||
|
||||
|
||||
/**
|
||||
* @param index
|
||||
* @return A size 3 int array containing min input, max input and output indices in that order.
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.inventory.RecipesCommon.AStack;
|
||||
@ -14,6 +15,7 @@ import com.hbm.lib.Library;
|
||||
import com.hbm.tileentity.IGUIProvider;
|
||||
import com.hbm.tileentity.TileEntityMachineBase;
|
||||
import com.hbm.util.InventoryUtil;
|
||||
import com.hbm.util.ItemStackUtil;
|
||||
import com.hbm.util.fauxpointtwelve.DirPos;
|
||||
|
||||
import api.hbm.energymk2.IEnergyReceiverMK2;
|
||||
@ -38,20 +40,20 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa
|
||||
public int[] progress;
|
||||
public int[] maxProgress;
|
||||
public boolean isProgressing;
|
||||
|
||||
|
||||
public FluidTank[] tanks;
|
||||
|
||||
|
||||
int consumption = 100;
|
||||
int speed = 100;
|
||||
|
||||
public TileEntityMachineChemplantBase(int scount) {
|
||||
super(scount);
|
||||
|
||||
|
||||
int count = this.getRecipeCount();
|
||||
|
||||
progress = new int[count];
|
||||
maxProgress = new int[count];
|
||||
|
||||
|
||||
tanks = new FluidTank[4 * count];
|
||||
for(int i = 0; i < 4 * count; i++) {
|
||||
tanks[i] = new FluidTank(Fluids.NONE, getTankCapacity());
|
||||
@ -60,20 +62,20 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
|
||||
int count = this.getRecipeCount();
|
||||
|
||||
|
||||
this.isProgressing = false;
|
||||
this.power = Library.chargeTEFromItems(slots, 0, power, this.getMaxPower());
|
||||
|
||||
|
||||
for(int i = 0; i < count; i++) {
|
||||
loadItems(i);
|
||||
unloadItems(i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
for(int i = 0; i < count; i++) {
|
||||
if(!canProcess(i)) {
|
||||
this.progress[i] = 0;
|
||||
@ -84,74 +86,83 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected boolean canProcess(int index) {
|
||||
|
||||
|
||||
int template = getTemplateIndex(index);
|
||||
|
||||
|
||||
if(slots[template] == null || slots[template].getItem() != ModItems.chemistry_template)
|
||||
return false;
|
||||
|
||||
|
||||
ChemRecipe recipe = ChemplantRecipes.indexMapping.get(slots[template].getItemDamage());
|
||||
|
||||
|
||||
if(recipe == null)
|
||||
return false;
|
||||
|
||||
|
||||
setupTanks(recipe, index);
|
||||
|
||||
|
||||
if(this.power < this.consumption) return false;
|
||||
if(!hasRequiredFluids(recipe, index)) return false;
|
||||
if(!hasSpaceForFluids(recipe, index)) return false;
|
||||
if(!hasRequiredItems(recipe, index)) return false;
|
||||
if(!hasSpaceForItems(recipe, index)) return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void setupTanks(ChemRecipe recipe, int index) {
|
||||
if(recipe.inputFluids[0] != null) tanks[index * 4].withPressure(recipe.inputFluids[0].pressure).setTankType(recipe.inputFluids[0].type); else tanks[index * 4].setTankType(Fluids.NONE);
|
||||
if(recipe.inputFluids[1] != null) tanks[index * 4 + 1].withPressure(recipe.inputFluids[1].pressure).setTankType(recipe.inputFluids[1].type); else tanks[index * 4 + 1].setTankType(Fluids.NONE);
|
||||
if(recipe.outputFluids[0] != null) tanks[index * 4 + 2].withPressure(recipe.outputFluids[0].pressure).setTankType(recipe.outputFluids[0].type); else tanks[index * 4 + 2].setTankType(Fluids.NONE);
|
||||
if(recipe.outputFluids[1] != null) tanks[index * 4 + 3].withPressure(recipe.outputFluids[1].pressure).setTankType(recipe.outputFluids[1].type); else tanks[index * 4 + 3].setTankType(Fluids.NONE);
|
||||
}
|
||||
|
||||
|
||||
private boolean hasRequiredFluids(ChemRecipe recipe, int index) {
|
||||
if(recipe.inputFluids[0] != null && tanks[index * 4].getFill() < recipe.inputFluids[0].fill) return false;
|
||||
if(recipe.inputFluids[1] != null && tanks[index * 4 + 1].getFill() < recipe.inputFluids[1].fill) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private boolean hasSpaceForFluids(ChemRecipe recipe, int index) {
|
||||
if(recipe.outputFluids[0] != null && tanks[index * 4 + 2].getFill() + recipe.outputFluids[0].fill > tanks[index * 4 + 2].getMaxFill()) return false;
|
||||
if(recipe.outputFluids[1] != null && tanks[index * 4 + 3].getFill() + recipe.outputFluids[1].fill > tanks[index * 4 + 3].getMaxFill()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public HashMap<ItemStack[], Boolean> cachedItems = new HashMap<>();
|
||||
|
||||
private boolean hasRequiredItems(ChemRecipe recipe, int index) {
|
||||
int[] indices = getSlotIndicesFromIndex(index);
|
||||
return InventoryUtil.doesArrayHaveIngredients(slots, indices[0], indices[1], recipe.inputs);
|
||||
ItemStack[] copy = ItemStackUtil.carefulCopyArrayTruncate(slots, indices[0], indices[1]);
|
||||
if (cachedItems.get(copy) != null)
|
||||
return cachedItems.get(copy);
|
||||
else {
|
||||
boolean hasItems = InventoryUtil.doesArrayHaveIngredients(slots, indices[0], indices[1], recipe.inputs);
|
||||
cachedItems.put(copy, hasItems);
|
||||
return hasItems;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean hasSpaceForItems(ChemRecipe recipe, int index) {
|
||||
int[] indices = getSlotIndicesFromIndex(index);
|
||||
return InventoryUtil.doesArrayHaveSpace(slots, indices[2], indices[3], recipe.outputs);
|
||||
}
|
||||
|
||||
|
||||
protected void process(int index) {
|
||||
|
||||
|
||||
this.power -= this.consumption;
|
||||
this.progress[index]++;
|
||||
|
||||
|
||||
if(slots[0] != null && slots[0].getItem() == ModItems.meteorite_sword_machined)
|
||||
slots[0] = new ItemStack(ModItems.meteorite_sword_treated); //fisfndmoivndlmgindgifgjfdnblfm
|
||||
|
||||
|
||||
int template = getTemplateIndex(index);
|
||||
ChemRecipe recipe = ChemplantRecipes.indexMapping.get(slots[template].getItemDamage());
|
||||
|
||||
|
||||
this.maxProgress[index] = recipe.getDuration() * this.speed / 100;
|
||||
|
||||
|
||||
if(maxProgress[index] <= 0) maxProgress[index] = 1;
|
||||
|
||||
|
||||
if(this.progress[index] >= this.maxProgress[index]) {
|
||||
consumeFluids(recipe, index);
|
||||
produceFluids(recipe, index);
|
||||
@ -161,84 +172,84 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void consumeFluids(ChemRecipe recipe, int index) {
|
||||
if(recipe.inputFluids[0] != null) tanks[index * 4].setFill(tanks[index * 4].getFill() - recipe.inputFluids[0].fill);
|
||||
if(recipe.inputFluids[1] != null) tanks[index * 4 + 1].setFill(tanks[index * 4 + 1].getFill() - recipe.inputFluids[1].fill);
|
||||
}
|
||||
|
||||
|
||||
private void produceFluids(ChemRecipe recipe, int index) {
|
||||
if(recipe.outputFluids[0] != null) tanks[index * 4 + 2].setFill(tanks[index * 4 + 2].getFill() + recipe.outputFluids[0].fill);
|
||||
if(recipe.outputFluids[1] != null) tanks[index * 4 + 3].setFill(tanks[index * 4 + 3].getFill() + recipe.outputFluids[1].fill);
|
||||
}
|
||||
|
||||
|
||||
private void consumeItems(ChemRecipe recipe, int index) {
|
||||
|
||||
|
||||
int[] indices = getSlotIndicesFromIndex(index);
|
||||
|
||||
|
||||
for(AStack in : recipe.inputs) {
|
||||
if(in != null)
|
||||
InventoryUtil.tryConsumeAStack(slots, indices[0], indices[1], in);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void produceItems(ChemRecipe recipe, int index) {
|
||||
|
||||
|
||||
int[] indices = getSlotIndicesFromIndex(index);
|
||||
|
||||
|
||||
for(ItemStack out : recipe.outputs) {
|
||||
if(out != null)
|
||||
InventoryUtil.tryAddItemToInventory(slots, indices[2], indices[3], out.copy());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void loadItems(int index) {
|
||||
|
||||
|
||||
int template = getTemplateIndex(index);
|
||||
if(slots[template] == null || slots[template].getItem() != ModItems.chemistry_template)
|
||||
return;
|
||||
|
||||
|
||||
ChemRecipe recipe = ChemplantRecipes.indexMapping.get(slots[template].getItemDamage());
|
||||
|
||||
|
||||
if(recipe != null) {
|
||||
|
||||
|
||||
DirPos[] positions = getInputPositions();
|
||||
int[] indices = getSlotIndicesFromIndex(index);
|
||||
|
||||
|
||||
for(DirPos coord : positions) {
|
||||
|
||||
TileEntity te = worldObj.getTileEntity(coord.getX(), coord.getY(), coord.getZ());
|
||||
|
||||
|
||||
if(te instanceof IInventory) {
|
||||
|
||||
|
||||
IInventory inv = (IInventory) te;
|
||||
ISidedInventory sided = inv instanceof ISidedInventory ? (ISidedInventory) inv : null;
|
||||
int[] access = sided != null ? sided.getAccessibleSlotsFromSide(coord.getDir().ordinal()) : null;
|
||||
|
||||
|
||||
for(AStack ingredient : recipe.inputs) {
|
||||
|
||||
|
||||
outer:
|
||||
while(!InventoryUtil.doesArrayHaveIngredients(slots, indices[0], indices[1], ingredient)) {
|
||||
|
||||
|
||||
boolean found = false;
|
||||
|
||||
|
||||
for(int i = 0; i < (access != null ? access.length : inv.getSizeInventory()); i++) {
|
||||
|
||||
int slot = access != null ? access[i] : i;
|
||||
ItemStack stack = inv.getStackInSlot(slot);
|
||||
if(ingredient.matchesRecipe(stack, true) && (sided == null || sided.canExtractItem(slot, stack, 0))) {
|
||||
|
||||
|
||||
for(int j = indices[0]; j <= indices[1]; j++) {
|
||||
|
||||
|
||||
if(slots[j] != null && slots[j].stackSize < slots[j].getMaxStackSize() & InventoryUtil.doesStackDataMatch(slots[j], stack)) {
|
||||
inv.decrStackSize(slot, 1);
|
||||
slots[j].stackSize++;
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(int j = indices[0]; j <= indices[1]; j++) {
|
||||
|
||||
|
||||
if(slots[j] == null) {
|
||||
slots[j] = stack.copy();
|
||||
slots[j].stackSize = 1;
|
||||
@ -256,18 +267,18 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void unloadItems(int index) {
|
||||
|
||||
DirPos[] positions = getOutputPositions();
|
||||
int[] indices = getSlotIndicesFromIndex(index);
|
||||
|
||||
|
||||
for(DirPos coord : positions) {
|
||||
|
||||
TileEntity te = worldObj.getTileEntity(coord.getX(), coord.getY(), coord.getZ());
|
||||
|
||||
|
||||
if(te instanceof IInventory) {
|
||||
|
||||
|
||||
IInventory inv = (IInventory) te;
|
||||
ISidedInventory sided = inv instanceof ISidedInventory ? (ISidedInventory) inv : null;
|
||||
int[] access = sided != null ? sided.getAccessibleSlotsFromSide(coord.getDir().ordinal()) : null;
|
||||
@ -277,20 +288,20 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa
|
||||
shouldOutput = false;
|
||||
outer:
|
||||
for(int i = indices[2]; i <= indices[3]; i++) {
|
||||
|
||||
|
||||
ItemStack out = slots[i];
|
||||
|
||||
|
||||
if(out != null) {
|
||||
|
||||
|
||||
for(int j = 0; j < (access != null ? access.length : inv.getSizeInventory()); j++) {
|
||||
|
||||
|
||||
int slot = access != null ? access[j] : j;
|
||||
|
||||
|
||||
if(!inv.isItemValidForSlot(slot, out))
|
||||
continue;
|
||||
|
||||
|
||||
ItemStack target = inv.getStackInSlot(slot);
|
||||
|
||||
|
||||
if(InventoryUtil.doesStackDataMatch(out, target) && target.stackSize < target.getMaxStackSize() && target.stackSize < inv.getInventoryStackLimit()) {
|
||||
int toDec = Math.min(out.stackSize, Math.min(target.getMaxStackSize(), inv.getInventoryStackLimit()) - target.stackSize);
|
||||
this.decrStackSize(i, toDec);
|
||||
@ -299,14 +310,14 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(int j = 0; j < (access != null ? access.length : inv.getSizeInventory()); j++) {
|
||||
|
||||
|
||||
int slot = access != null ? access[j] : j;
|
||||
|
||||
|
||||
if(!inv.isItemValidForSlot(slot, out))
|
||||
continue;
|
||||
|
||||
|
||||
if(inv.getStackInSlot(slot) == null && (sided != null ? sided.canInsertItem(slot, out, coord.getDir().ordinal()) : inv.isItemValidForSlot(slot, out))) {
|
||||
ItemStack copy = out.copy();
|
||||
copy.stackSize = 1;
|
||||
@ -334,105 +345,105 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa
|
||||
}
|
||||
|
||||
/*public int getFluidFill(FluidType type) {
|
||||
|
||||
|
||||
int fill = 0;
|
||||
|
||||
|
||||
for(FluidTank tank : inTanks()) {
|
||||
if(tank.getTankType() == type) {
|
||||
fill += tank.getFill();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(FluidTank tank : outTanks()) {
|
||||
if(tank.getTankType() == type) {
|
||||
fill += tank.getFill();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return fill;
|
||||
}*/
|
||||
|
||||
/* For input only! */
|
||||
public int getMaxFluidFill(FluidType type) {
|
||||
|
||||
|
||||
int maxFill = 0;
|
||||
|
||||
|
||||
for(FluidTank tank : inTanks()) {
|
||||
if(tank.getTankType() == type) {
|
||||
maxFill += tank.getMaxFill();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return maxFill;
|
||||
}
|
||||
|
||||
|
||||
protected List<FluidTank> inTanks() {
|
||||
|
||||
List<FluidTank> inTanks = new ArrayList();
|
||||
|
||||
|
||||
for(int i = 0; i < tanks.length; i++) {
|
||||
FluidTank tank = tanks[i];
|
||||
if(i % 4 < 2) {
|
||||
inTanks.add(tank);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return inTanks;
|
||||
}
|
||||
|
||||
/*public void receiveFluid(int amount, FluidType type) {
|
||||
|
||||
|
||||
if(amount <= 0)
|
||||
return;
|
||||
|
||||
|
||||
List<FluidTank> rec = new ArrayList();
|
||||
|
||||
|
||||
for(FluidTank tank : inTanks()) {
|
||||
if(tank.getTankType() == type) {
|
||||
rec.add(tank);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(rec.size() == 0)
|
||||
return;
|
||||
|
||||
|
||||
int demand = 0;
|
||||
List<Integer> weight = new ArrayList();
|
||||
|
||||
|
||||
for(FluidTank tank : rec) {
|
||||
int fillWeight = tank.getMaxFill() - tank.getFill();
|
||||
demand += fillWeight;
|
||||
weight.add(fillWeight);
|
||||
}
|
||||
|
||||
|
||||
for(int i = 0; i < rec.size(); i++) {
|
||||
|
||||
|
||||
if(demand <= 0)
|
||||
break;
|
||||
|
||||
|
||||
FluidTank tank = rec.get(i);
|
||||
int fillWeight = weight.get(i);
|
||||
int part = (int) (Math.min((long)amount, (long)demand) * (long)fillWeight / (long)demand);
|
||||
|
||||
|
||||
tank.setFill(tank.getFill() + part);
|
||||
}
|
||||
}*/
|
||||
|
||||
public int getFluidFillForTransfer(FluidType type, int pressure) {
|
||||
|
||||
|
||||
int fill = 0;
|
||||
|
||||
|
||||
for(FluidTank tank : outTanks()) {
|
||||
if(tank.getTankType() == type && tank.getPressure() == pressure) {
|
||||
fill += tank.getFill();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return fill;
|
||||
}
|
||||
|
||||
|
||||
public void transferFluid(int amount, FluidType type, int pressure) {
|
||||
|
||||
|
||||
/*
|
||||
* this whole new fluid mumbo jumbo extra abstraction layer might just be a bandaid
|
||||
* on the gushing wound that is the current fluid systemm but i'll be damned if it
|
||||
@ -441,44 +452,44 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa
|
||||
*/
|
||||
if(amount <= 0)
|
||||
return;
|
||||
|
||||
|
||||
List<FluidTank> send = new ArrayList();
|
||||
|
||||
|
||||
for(FluidTank tank : outTanks()) {
|
||||
if(tank.getTankType() == type && tank.getPressure() == pressure) {
|
||||
send.add(tank);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(send.size() == 0)
|
||||
return;
|
||||
|
||||
|
||||
int offer = 0;
|
||||
List<Integer> weight = new ArrayList();
|
||||
|
||||
|
||||
for(FluidTank tank : send) {
|
||||
int fillWeight = tank.getFill();
|
||||
offer += fillWeight;
|
||||
weight.add(fillWeight);
|
||||
}
|
||||
|
||||
|
||||
int tracker = amount;
|
||||
|
||||
|
||||
for(int i = 0; i < send.size(); i++) {
|
||||
|
||||
|
||||
FluidTank tank = send.get(i);
|
||||
int fillWeight = weight.get(i);
|
||||
int part = amount * fillWeight / offer;
|
||||
|
||||
|
||||
tank.setFill(tank.getFill() - part);
|
||||
tracker -= part;
|
||||
}
|
||||
|
||||
|
||||
//making sure to properly deduct even the last mB lost by rounding errors
|
||||
for(int i = 0; i < 100 && tracker > 0; i++) {
|
||||
|
||||
|
||||
FluidTank tank = send.get(i % send.size());
|
||||
|
||||
|
||||
if(tank.getFill() > 0) {
|
||||
int total = Math.min(tank.getFill(), tracker);
|
||||
tracker -= total;
|
||||
@ -486,18 +497,18 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected List<FluidTank> outTanks() {
|
||||
|
||||
|
||||
List<FluidTank> outTanks = new ArrayList();
|
||||
|
||||
|
||||
for(int i = 0; i < tanks.length; i++) {
|
||||
FluidTank tank = tanks[i];
|
||||
if(i % 4 > 1) {
|
||||
outTanks.add(tank);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return outTanks;
|
||||
}
|
||||
|
||||
@ -509,43 +520,43 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa
|
||||
@Override
|
||||
public long transferFluid(FluidType type, int pressure, long fluid) {
|
||||
int amount = (int) fluid;
|
||||
|
||||
|
||||
if(amount <= 0)
|
||||
return 0;
|
||||
|
||||
|
||||
List<FluidTank> rec = new ArrayList();
|
||||
|
||||
|
||||
for(FluidTank tank : inTanks()) {
|
||||
if(tank.getTankType() == type && tank.getPressure() == pressure) {
|
||||
rec.add(tank);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(rec.size() == 0)
|
||||
return fluid;
|
||||
|
||||
|
||||
int demand = 0;
|
||||
List<Integer> weight = new ArrayList();
|
||||
|
||||
|
||||
for(FluidTank tank : rec) {
|
||||
int fillWeight = tank.getMaxFill() - tank.getFill();
|
||||
demand += fillWeight;
|
||||
weight.add(fillWeight);
|
||||
}
|
||||
|
||||
|
||||
for(int i = 0; i < rec.size(); i++) {
|
||||
|
||||
|
||||
if(demand <= 0)
|
||||
break;
|
||||
|
||||
|
||||
FluidTank tank = rec.get(i);
|
||||
int fillWeight = weight.get(i);
|
||||
int part = (int) (Math.min((long)amount, (long)demand) * (long)fillWeight / (long)demand);
|
||||
|
||||
|
||||
tank.setFill(tank.getFill() + part);
|
||||
fluid -= part;
|
||||
}
|
||||
|
||||
|
||||
return fluid;
|
||||
}
|
||||
|
||||
@ -563,29 +574,29 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa
|
||||
public void removeFluidForTransfer(FluidType type, int pressure, long amount) {
|
||||
this.transferFluid((int) amount, type, pressure);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
|
||||
this.power = nbt.getLong("power");
|
||||
this.progress = nbt.getIntArray("progress");
|
||||
|
||||
|
||||
if(progress.length == 0)
|
||||
progress = new int[this.getRecipeCount()];
|
||||
|
||||
|
||||
for(int i = 0; i < tanks.length; i++) {
|
||||
tanks[i].readFromNBT(nbt, "t" + i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
|
||||
nbt.setLong("power", power);
|
||||
nbt.setIntArray("progress", progress);
|
||||
|
||||
|
||||
for(int i = 0; i < tanks.length; i++) {
|
||||
tanks[i].writeToNBT(nbt, "t" + i);
|
||||
}
|
||||
@ -594,7 +605,7 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa
|
||||
public abstract int getRecipeCount();
|
||||
public abstract int getTankCapacity();
|
||||
public abstract int getTemplateIndex(int index);
|
||||
|
||||
|
||||
/**
|
||||
* @param index
|
||||
* @return A size 4 int array containing min input, max input, min output and max output indices in that order.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user