Skip to content

Commit

Permalink
add missed constructors and methods to inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueWeabo committed Apr 17, 2024
1 parent 310577b commit aad71b5
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class FluidInventoryLogic implements InventoryLogic<IFluidTankLong> {
private UUID id = UUID.randomUUID();
private FluidTanksHandler handler;
private Object2LongMap<IFluidTankLong> quickAccess;

@Override
public String getName() {
return name;
Expand All @@ -38,7 +39,8 @@ public UUID getId() {
return drainedTank;
}
slot = findSlotFromFluidTank(request);
if (slot < 0) return null;
if (slot < 0)
return null;
long drained = handler.getTank(slot).drainLong(amount, doExtract);
IFluidTankLong drainedTank = request.copy();
drainedTank.setFluid(drainedTank.getRealFluid(), drained);
Expand All @@ -55,17 +57,31 @@ public UUID getId() {
return filledTank;
}
slot = findSlotFromFluidTank(request);
if (slot < 0) return null;
if (slot < 0) {
return null;
}
long filled = handler.getTank(slot).fillLong(request.getRealFluid(), amount, doInsert);
IFluidTankLong filledTank = request.copy();
filledTank.setFluid(filledTank.getRealFluid(), filled);
return filledTank;
}

@Override
public IFluidTankLong get(int slot) {
return handler.getTank(slot);
}

@Override
public int getSlots() {
return handler.getTanks();
}

@Nullable
protected int findSlotFromFluidTank(IFluidTankLong tank) {
for (int i = 0; i < handler.getTanks(); i++) {
if (tank.equals(handler.getTank(i))) return i;
if (tank.equals(handler.getTank(i))) {
return i;
}
}
return -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public class FuelPowerLogic implements PowerLogic {
private ItemInventoryLogic container;
private long burnTime;

public FuelPowerLogic(ItemInventoryLogic container) {
this.container = container;
}

@Override
public boolean consume(long tick) {
if (burnTime > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,54 @@ public UUID getId() {

@Override
public @Nullable IItemStackLong extract(IItemStackLong request, long amount, boolean doExtract) {
if (amount <= 0) return null;
if (amount <= 0)
return null;
request = request.copy();
request.setStackSize(1);
int slot = (int)quickAccess.getOrDefault(request, -1);
int slot = (int) quickAccess.getOrDefault(request, -1);
if (slot >= 0 && request.isItemEqual(handler.getStackInSlotLong(slot))) {
return handler.extractItemLong(slot, amount, doExtract);
return handler.extractItemLong(slot, amount, !doExtract);
}
slot = findSlotFromItem(request);
if (slot < 0) return null;
if (slot < 0)
return null;
quickAccess.put(request, slot);
return handler.extractItemLong(slot, amount, doExtract);
return handler.extractItemLong(slot, amount, !doExtract);
}

@Override
public @Nullable IItemStackLong insert(IItemStackLong request, long amount, boolean doInsert) {
if (amount <= 0) return null;
if (amount <= 0)
return null;
request.setStackSize(1);
int slot = (int) quickAccess.getOrDefault(request, -1);
IItemStackLong toInsert = request.copy();
toInsert.setStackSize(amount);
if (slot >= 0 && request.isItemEqual(handler.getStackInSlotLong(slot))) {
return handler.insertItemLong(slot, toInsert, doInsert);
return handler.insertItemLong(slot, toInsert, !doInsert);
}
slot = findSlotFromItem(request);
if (slot < 0) return null;
if (slot < 0)
return null;
quickAccess.put(request, slot);
return handler.insertItemLong(slot, toInsert, doInsert);
return handler.insertItemLong(slot, toInsert, !doInsert);
}

@Override
public @Nullable IItemStackLong get(int slot) {
return handler.getStackInSlotLong(slot);
}

@Override
public int getSlots() {
return handler.getSlots();
}

@Nullable
protected int findSlotFromItem(IItemStackLong item) {
for (int i = 0; i < handler.getSlots(); i++) {
if (item.isItemEqual(handler.getStackInSlotLong(i))) return i;
if (item.isItemEqual(handler.getStackInSlotLong(i)))
return i;
}
return -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ public class ItemPowerLogic implements PowerLogic {
private long startingBurnTime;
private long currentBurnTime;

public ItemPowerLogic(ItemInventoryLogic container, ItemStack itemToBurn, long startingBurnTime) {
this.container = container;
this.itemToBurn = itemToBurn;
this.startingBurnTime = startingBurnTime;
}

@Override
public boolean consume(long tick) {
if (currentBurnTime > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ public interface InventoryLogic<T> {
@Nullable T extract(T request, long amount, boolean doExtract);

@Nullable T insert(T request, long amount, boolean doInsert);

@Nullable T get(int slot);

int getSlots();
}

0 comments on commit aad71b5

Please sign in to comment.