mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-02-24 15:00:48 +00:00
finished new chemplant functionality, cleared up some fluid network code
This commit is contained in:
parent
05892abbe7
commit
50557e6d0a
@ -5,4 +5,15 @@ import com.hbm.inventory.fluid.FluidType;
|
|||||||
public interface IFluidAcceptor extends IFluidContainer {
|
public interface IFluidAcceptor extends IFluidContainer {
|
||||||
|
|
||||||
int getMaxFillForReceive(FluidType type);
|
int getMaxFillForReceive(FluidType type);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Behavior for overriding when a fluid container has matching types as in and outputs
|
||||||
|
* Only a temporary fix until the fluid system is rewritten
|
||||||
|
*/
|
||||||
|
default void setFillForTransferIncoming(int fill, FluidType type) {
|
||||||
|
this.setFillForTransfer(fill, type);
|
||||||
|
}
|
||||||
|
default int getFluidFillIncoming(FluidType type) {
|
||||||
|
return this.getFluidFill(type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,4 +14,15 @@ public interface IFluidSource extends IFluidContainer {
|
|||||||
List<IFluidAcceptor> getFluidList(FluidType type);
|
List<IFluidAcceptor> getFluidList(FluidType type);
|
||||||
void clearFluidList(FluidType type);
|
void clearFluidList(FluidType type);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Behavior for overriding when a fluid container has matching types as in and outputs
|
||||||
|
* Only a temporary fix until the fluid system is rewritten
|
||||||
|
*/
|
||||||
|
default void setFillForTransferOutgoing(int fill, FluidType type) {
|
||||||
|
this.setFillForTransfer(fill, type);
|
||||||
|
}
|
||||||
|
default int getFluidFillOutgoing(FluidType type) {
|
||||||
|
return this.getFluidFill(type);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import java.util.Map.Entry;
|
|||||||
import com.hbm.inventory.RecipesCommon.ComparableStack;
|
import com.hbm.inventory.RecipesCommon.ComparableStack;
|
||||||
import com.hbm.inventory.fluid.Fluids;
|
import com.hbm.inventory.fluid.Fluids;
|
||||||
import com.hbm.items.ModItems;
|
import com.hbm.items.ModItems;
|
||||||
|
import com.hbm.items.machine.ItemFELCrystal.EnumWavelengths;
|
||||||
import com.hbm.items.special.ItemWasteLong;
|
import com.hbm.items.special.ItemWasteLong;
|
||||||
import com.hbm.items.special.ItemWasteShort;
|
import com.hbm.items.special.ItemWasteShort;
|
||||||
import com.hbm.util.WeightedRandomObject;
|
import com.hbm.util.WeightedRandomObject;
|
||||||
@ -532,7 +533,7 @@ public class SILEXRecipes {
|
|||||||
.addOut(new WeightedRandomObject(new ItemStack(ModItems.nugget_au198), 1))
|
.addOut(new WeightedRandomObject(new ItemStack(ModItems.nugget_au198), 1))
|
||||||
);
|
);
|
||||||
|
|
||||||
recipes.put(new ComparableStack(Blocks.gravel, 1), new SILEXRecipe(1000, 250, 0)
|
recipes.put(new ComparableStack(Blocks.gravel, 1), new SILEXRecipe(1000, 250, EnumWavelengths.VISIBLE)
|
||||||
.addOut(new WeightedRandomObject(new ItemStack(Items.flint), 80))
|
.addOut(new WeightedRandomObject(new ItemStack(Items.flint), 80))
|
||||||
.addOut(new WeightedRandomObject(new ItemStack(ModItems.powder_boron), 5))
|
.addOut(new WeightedRandomObject(new ItemStack(ModItems.powder_boron), 5))
|
||||||
.addOut(new WeightedRandomObject(new ItemStack(ModItems.powder_lithium), 10))
|
.addOut(new WeightedRandomObject(new ItemStack(ModItems.powder_lithium), 10))
|
||||||
@ -627,15 +628,19 @@ public static class SILEXRecipe {
|
|||||||
|
|
||||||
public int fluidProduced;
|
public int fluidProduced;
|
||||||
public int fluidConsumed;
|
public int fluidConsumed;
|
||||||
public int laserStrength;
|
public EnumWavelengths laserStrength;
|
||||||
public List<WeightedRandomObject> outputs = new ArrayList();
|
public List<WeightedRandomObject> outputs = new ArrayList();
|
||||||
|
|
||||||
public SILEXRecipe(int fluidProduced, int fluidConsumed, int laserStrength) {
|
public SILEXRecipe(int fluidProduced, int fluidConsumed, EnumWavelengths laserStrength) {
|
||||||
this.fluidProduced = fluidProduced;
|
this.fluidProduced = fluidProduced;
|
||||||
this.fluidConsumed = fluidConsumed;
|
this.fluidConsumed = fluidConsumed;
|
||||||
this.laserStrength = laserStrength;
|
this.laserStrength = laserStrength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SILEXRecipe(int fluidProduced, int fluidConsumed, int laserStrength) {
|
||||||
|
this(fluidProduced, fluidConsumed, EnumWavelengths.values()[laserStrength]);
|
||||||
|
}
|
||||||
|
|
||||||
public SILEXRecipe addOut(WeightedRandomObject entry) {
|
public SILEXRecipe addOut(WeightedRandomObject entry) {
|
||||||
outputs.add(entry);
|
outputs.add(entry);
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@ -31,7 +31,7 @@ public class ItemFELCrystal extends Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static enum EnumWavelengths{
|
public static enum EnumWavelengths{
|
||||||
NULL("la creatura", "6 dollar", 0x010101, 0x010101, EnumChatFormatting.WHITE),
|
NULL("la creatura", "6 dollar", 0x010101, 0x010101, EnumChatFormatting.WHITE), //why do you exist?
|
||||||
|
|
||||||
IR("wavelengths.name.ir", "wavelengths.waveRange.ir", 0xBB1010, 0xCC4040, EnumChatFormatting.RED),
|
IR("wavelengths.name.ir", "wavelengths.waveRange.ir", 0xBB1010, 0xCC4040, EnumChatFormatting.RED),
|
||||||
VISIBLE("wavelengths.name.visible", "wavelengths.waveRange.visible", 0, 0, EnumChatFormatting.GREEN),
|
VISIBLE("wavelengths.name.visible", "wavelengths.waveRange.visible", 0, 0, EnumChatFormatting.GREEN),
|
||||||
|
|||||||
@ -619,7 +619,7 @@ public class Library {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(tileentity instanceof IFluidAcceptor && newTact && ((IFluidAcceptor)tileentity).getMaxFillForReceive(type) > 0 &&
|
if(tileentity instanceof IFluidAcceptor && newTact && ((IFluidAcceptor)tileentity).getMaxFillForReceive(type) > 0 &&
|
||||||
((IFluidAcceptor)tileentity).getMaxFillForReceive(type) - ((IFluidAcceptor)tileentity).getFluidFill(type) > 0) {
|
((IFluidAcceptor)tileentity).getMaxFillForReceive(type) - ((IFluidAcceptor)tileentity).getMaxFillForReceive(type) > 0) {
|
||||||
that.getFluidList(type).add((IFluidAcceptor)tileentity);
|
that.getFluidList(type).add((IFluidAcceptor)tileentity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -628,18 +628,18 @@ public class Library {
|
|||||||
int size = that.getFluidList(type).size();
|
int size = that.getFluidList(type).size();
|
||||||
if(size > 0)
|
if(size > 0)
|
||||||
{
|
{
|
||||||
int part = that.getFluidFill(type) / size;
|
int part = that.getFluidFillOutgoing(type) / size;
|
||||||
for(IFluidAcceptor consume : that.getFluidList(type))
|
for(IFluidAcceptor consume : that.getFluidList(type))
|
||||||
{
|
{
|
||||||
if(consume.getFluidFill(type) < consume.getMaxFillForReceive(type))
|
if(consume.getFluidFillIncoming(type) < consume.getMaxFillForReceive(type))
|
||||||
{
|
{
|
||||||
if(consume.getMaxFillForReceive(type) - consume.getFluidFill(type) >= part)
|
if(consume.getMaxFillForReceive(type) - consume.getFluidFillIncoming(type) >= part)
|
||||||
{
|
{
|
||||||
that.setFillForTransfer(that.getFluidFill(type) - part, type);
|
that.setFillForTransferOutgoing(that.getFluidFillOutgoing(type) - part, type);
|
||||||
consume.setFillForTransfer(consume.getFluidFill(type) + part, type);
|
consume.setFillForTransferIncoming(consume.getFluidFillIncoming(type) + part, type);
|
||||||
} else {
|
} else {
|
||||||
that.setFillForTransfer(that.getFluidFill(type) - (consume.getMaxFillForReceive(type) - consume.getFluidFill(type)), type);
|
that.setFillForTransferOutgoing(that.getFluidFillOutgoing(type) - (consume.getMaxFillForReceive(type) - consume.getFluidFillIncoming(type)), type);
|
||||||
consume.setFillForTransfer(consume.getMaxFillForReceive(type), type);
|
consume.setFillForTransferIncoming(consume.getMaxFillForReceive(type), type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,17 +1,26 @@
|
|||||||
package com.hbm.tileentity.machine;
|
package com.hbm.tileentity.machine;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.hbm.interfaces.IFluidAcceptor;
|
||||||
|
import com.hbm.interfaces.IFluidSource;
|
||||||
import com.hbm.inventory.FluidTank;
|
import com.hbm.inventory.FluidTank;
|
||||||
|
import com.hbm.inventory.RecipesCommon.AStack;
|
||||||
import com.hbm.inventory.UpgradeManager;
|
import com.hbm.inventory.UpgradeManager;
|
||||||
|
import com.hbm.inventory.fluid.FluidType;
|
||||||
import com.hbm.inventory.fluid.Fluids;
|
import com.hbm.inventory.fluid.Fluids;
|
||||||
import com.hbm.inventory.recipes.ChemplantRecipes;
|
import com.hbm.inventory.recipes.ChemplantRecipes;
|
||||||
import com.hbm.inventory.recipes.ChemplantRecipes.ChemRecipe;
|
import com.hbm.inventory.recipes.ChemplantRecipes.ChemRecipe;
|
||||||
import com.hbm.items.ModItems;
|
import com.hbm.items.ModItems;
|
||||||
import com.hbm.items.machine.ItemMachineUpgrade.UpgradeType;
|
import com.hbm.items.machine.ItemMachineUpgrade.UpgradeType;
|
||||||
import com.hbm.tileentity.TileEntityMachineBase;
|
import com.hbm.tileentity.TileEntityMachineBase;
|
||||||
|
import com.hbm.util.InventoryUtil;
|
||||||
|
|
||||||
|
import api.hbm.energy.IEnergyUser;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
public class TileEntityMachineChemplantNew extends TileEntityMachineBase {
|
public class TileEntityMachineChemplantNew extends TileEntityMachineBase implements IEnergyUser, IFluidSource, IFluidAcceptor {
|
||||||
|
|
||||||
public long power;
|
public long power;
|
||||||
public static final long maxPower = 100000;
|
public static final long maxPower = 100000;
|
||||||
@ -60,24 +69,39 @@ public class TileEntityMachineChemplantNew extends TileEntityMachineBase {
|
|||||||
int powerLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
|
int powerLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
|
||||||
int overLevel = UpgradeManager.getLevel(UpgradeType.OVERDRIVE);
|
int overLevel = UpgradeManager.getLevel(UpgradeType.OVERDRIVE);
|
||||||
|
|
||||||
speed -= speedLevel * 25;
|
this.speed -= speedLevel * 25;
|
||||||
consumption += speedLevel * 300;
|
this.consumption += speedLevel * 300;
|
||||||
speed += powerLevel * 5;
|
this.speed += powerLevel * 5;
|
||||||
consumption -= powerLevel * 30;
|
this.consumption -= powerLevel * 30;
|
||||||
speed /= (overLevel + 1);
|
this.speed /= (overLevel + 1);
|
||||||
consumption *= (overLevel + 1);
|
this.consumption *= (overLevel + 1);
|
||||||
|
|
||||||
if(!canProcess()) {
|
if(!canProcess()) {
|
||||||
this.progress = 0;
|
this.progress = 0;
|
||||||
} else {
|
} else {
|
||||||
process();
|
process();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NBTTagCompound data = new NBTTagCompound();
|
||||||
|
data.setLong("power", this.power);
|
||||||
|
data.setInteger("progress", this.progress);
|
||||||
|
data.setInteger("maxProgress", this.maxProgress);
|
||||||
|
|
||||||
|
for(int i = 0; i < tanks.length; i++) {
|
||||||
|
tanks[i].writeToNBT(data, "t" + i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void networkUnpack(NBTTagCompound nbt) {
|
public void networkUnpack(NBTTagCompound nbt) {
|
||||||
|
this.power = nbt.getLong("power");
|
||||||
|
this.progress = nbt.getInteger("progress");
|
||||||
|
this.maxProgress = nbt.getInteger("maxProgress");
|
||||||
|
|
||||||
|
for(int i = 0; i < tanks.length; i++) {
|
||||||
|
tanks[i].readFromNBT(nbt, "t" + i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canProcess() {
|
private boolean canProcess() {
|
||||||
@ -92,11 +116,11 @@ public class TileEntityMachineChemplantNew extends TileEntityMachineBase {
|
|||||||
|
|
||||||
setupTanks(recipe);
|
setupTanks(recipe);
|
||||||
|
|
||||||
if(!hasRequiredFluids(recipe))
|
if(this.power < this.consumption) return false;
|
||||||
return false;
|
if(!hasRequiredFluids(recipe)) return false;
|
||||||
|
if(!hasSpaceForFluids(recipe)) return false;
|
||||||
if(!hasSpaceForFluids(recipe))
|
if(!hasRequiredItems(recipe)) return false;
|
||||||
return false;
|
if(!hasSpaceForItems(recipe)) return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -121,10 +145,129 @@ public class TileEntityMachineChemplantNew extends TileEntityMachineBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasRequiredItems(ChemRecipe recipe) {
|
private boolean hasRequiredItems(ChemRecipe recipe) {
|
||||||
return false;
|
return InventoryUtil.doesArrayHaveIngredients(slots, 13, 16, recipe.inputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasSpaceForItems(ChemRecipe recipe) {
|
||||||
|
return InventoryUtil.doesArrayHaveSpace(slots, 5, 8, recipe.outputs);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void process() {
|
private void process() {
|
||||||
|
|
||||||
|
this.power -= this.consumption;
|
||||||
|
this.progress++;
|
||||||
|
|
||||||
|
ChemRecipe recipe = ChemplantRecipes.indexMapping.get(slots[4].getItemDamage());
|
||||||
|
|
||||||
|
this.maxProgress = recipe.getDuration() * this.speed / 100;
|
||||||
|
|
||||||
|
if(this.progress >= this.maxProgress) {
|
||||||
|
consumeFluids(recipe);
|
||||||
|
produceFluids(recipe);
|
||||||
|
consumeItems(recipe);
|
||||||
|
produceItems(recipe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void consumeFluids(ChemRecipe recipe) {
|
||||||
|
if(recipe.inputFluids.length > 0) tanks[0].setFill(tanks[0].getFill() - recipe.inputFluids[0].fill);
|
||||||
|
if(recipe.inputFluids.length > 1) tanks[1].setFill(tanks[1].getFill() - recipe.inputFluids[1].fill);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void produceFluids(ChemRecipe recipe) {
|
||||||
|
if(recipe.outputFluids.length > 0) tanks[2].setFill(tanks[2].getFill() + recipe.outputFluids[0].fill);
|
||||||
|
if(recipe.outputFluids.length > 1) tanks[3].setFill(tanks[3].getFill() + recipe.outputFluids[1].fill);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void consumeItems(ChemRecipe recipe) {
|
||||||
|
|
||||||
|
for(AStack in : recipe.inputs) {
|
||||||
|
InventoryUtil.tryConsumeAStack(slots, 13, 16, in);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void produceItems(ChemRecipe recipe) {
|
||||||
|
|
||||||
|
for(ItemStack out : recipe.outputs) {
|
||||||
|
InventoryUtil.tryAddItemToInventory(slots, 5, 8, out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getPower() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getMaxPower() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFillForSync(int fill, int index) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFillForTransfer(int fill, FluidType type) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTypeForSync(FluidType type, int index) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getFluidFill(FluidType type) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxFillForReceive(FluidType type) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fillFluidInit(FluidType type) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fillFluid(int x, int y, int z, boolean newTact, FluidType type) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getTact() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<IFluidAcceptor> getFluidList(FluidType type) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearFluidList(FluidType type) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPower(long power) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -185,7 +185,7 @@ public class TileEntitySILEX extends TileEntityMachineBase implements IFluidAcce
|
|||||||
if(recipe == null)
|
if(recipe == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(recipe.laserStrength > this.mode.ordinal())
|
if(recipe.laserStrength.ordinal() > this.mode.ordinal())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(currentFill < recipe.fluidConsumed)
|
if(currentFill < recipe.fluidConsumed)
|
||||||
@ -194,7 +194,7 @@ public class TileEntitySILEX extends TileEntityMachineBase implements IFluidAcce
|
|||||||
if(slots[4] != null)
|
if(slots[4] != null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
int progressSpeed = (int) Math.pow(2, this.mode.ordinal() - recipe.laserStrength + 1) / 2;
|
int progressSpeed = (int) Math.pow(2, this.mode.ordinal() - recipe.laserStrength.ordinal() + 1) / 2;
|
||||||
|
|
||||||
progress += progressSpeed;
|
progress += progressSpeed;
|
||||||
|
|
||||||
|
|||||||
@ -37,6 +37,10 @@ public class InventoryUtil {
|
|||||||
return rem;
|
return rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ItemStack tryAddItemToInventory(ItemStack[] inv, ItemStack stack) {
|
||||||
|
return tryAddItemToInventory(inv, 0, inv.length - 1, stack);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functionally equal to tryAddItemToInventory, but will not try to create new stacks in empty slots
|
* Functionally equal to tryAddItemToInventory, but will not try to create new stacks in empty slots
|
||||||
* @param inv
|
* @param inv
|
||||||
@ -156,6 +160,32 @@ public class InventoryUtil {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean tryConsumeAStack(ItemStack[] inv, int start, int end, AStack stack) {
|
||||||
|
|
||||||
|
if(stack == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
AStack copy = stack.copy();
|
||||||
|
|
||||||
|
for(int i = start; i <= end; i++) {
|
||||||
|
ItemStack in = inv[i];
|
||||||
|
|
||||||
|
if(stack.matchesRecipe(in, true)) {
|
||||||
|
int size = Math.min(copy.stacksize, in.stackSize);
|
||||||
|
|
||||||
|
in.stackSize -= size;
|
||||||
|
copy.stacksize -= size;
|
||||||
|
|
||||||
|
if(in.stackSize == 0)
|
||||||
|
inv[i] = null;
|
||||||
|
if(copy.stacksize == 0)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares item, metadata and NBT data of two stacks. Also handles null values!
|
* Compares item, metadata and NBT data of two stacks. Also handles null values!
|
||||||
* @param stack1
|
* @param stack1
|
||||||
@ -164,29 +194,14 @@ public class InventoryUtil {
|
|||||||
*/
|
*/
|
||||||
public static boolean doesStackDataMatch(ItemStack stack1, ItemStack stack2) {
|
public static boolean doesStackDataMatch(ItemStack stack1, ItemStack stack2) {
|
||||||
|
|
||||||
if(stack1 == null && stack2 == null)
|
if(stack1 == null && stack2 == null) return true;
|
||||||
return true;
|
if(stack1 == null && stack2 != null) return false;
|
||||||
|
if(stack1 != null && stack2 == null) return false;
|
||||||
if(stack1 == null && stack2 != null)
|
if(stack1.getItem() != stack2.getItem()) return false;
|
||||||
return false;
|
if(stack1.getItemDamage() != stack2.getItemDamage()) return false;
|
||||||
|
if(!stack1.hasTagCompound() && !stack2.hasTagCompound()) return true;
|
||||||
if(stack1 != null && stack2 == null)
|
if(stack1.hasTagCompound() && !stack2.hasTagCompound()) return false;
|
||||||
return false;
|
if(!stack1.hasTagCompound() && stack2.hasTagCompound()) return false;
|
||||||
|
|
||||||
if(stack1.getItem() != stack2.getItem())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if(stack1.getItemDamage() != stack2.getItemDamage())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if(!stack1.hasTagCompound() && !stack2.hasTagCompound())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if(stack1.hasTagCompound() && !stack2.hasTagCompound())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if(!stack1.hasTagCompound() && stack2.hasTagCompound())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return stack1.getTagCompound().equals(stack2.getTagCompound());
|
return stack1.getTagCompound().equals(stack2.getTagCompound());
|
||||||
}
|
}
|
||||||
@ -381,21 +396,47 @@ public class InventoryUtil {
|
|||||||
ItemStack[] copy = ItemStackUtil.carefulCopyArrayTruncate(array, start, end);
|
ItemStack[] copy = ItemStackUtil.carefulCopyArrayTruncate(array, start, end);
|
||||||
|
|
||||||
AStack[] req = new AStack[ingredients.length];
|
AStack[] req = new AStack[ingredients.length];
|
||||||
|
|
||||||
for(int i = 0; i < req.length; i++) {
|
for(int i = 0; i < req.length; i++) {
|
||||||
req[i] = ingredients[i] == null ? null : ingredients[i].copy();
|
req[i] = ingredients[i] == null ? null : ingredients[i].copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
for(AStack ingredient : req) {
|
for(AStack ingredient : req) {
|
||||||
|
|
||||||
|
if(ingredient == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
for(ItemStack input : copy) {
|
for(ItemStack input : copy) {
|
||||||
|
|
||||||
|
if(input == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
if(ingredient.matchesRecipe(input, true)) {
|
if(ingredient.matchesRecipe(input, true)) {
|
||||||
int size = Math.min(input.stackSize, ingredient.stacksize);
|
int size = Math.min(input.stackSize, ingredient.stacksize);
|
||||||
|
|
||||||
//TODO: yada yada yada
|
ingredient.stacksize -= size;
|
||||||
|
input.stackSize -= size;
|
||||||
|
|
||||||
|
if(ingredient.stacksize == 0)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
//we have iterated over the entire input array and removed all matching entries, yet the ingredient is still not exhausted, meaning the input wasn't enough
|
||||||
|
if(ingredient.stacksize > 0)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean doesArrayHaveSpace(ItemStack[] array, int start, int end, ItemStack[] items) {
|
||||||
|
ItemStack[] copy = ItemStackUtil.carefulCopyArrayTruncate(array, start, end);
|
||||||
|
|
||||||
|
for(ItemStack item : items) {
|
||||||
|
ItemStack remainder = tryAddItemToInventory(copy, item);
|
||||||
|
if(remainder != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user