Skip to content

Commit

Permalink
Fix fluid handling related crash
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenraven committed Aug 7, 2023
1 parent d626f37 commit d3e8c84
Showing 1 changed file with 6 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {

/**
* Calculates tank capacity based on the boosters
*
*
* @return
*/
abstract protected int getTankCapacity();
Expand Down Expand Up @@ -321,71 +321,31 @@ protected void processFluids() {

if (canister != null && this.isItemFuel(canister)) {
// attempt to drain it into the tank
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(canister);
// int spaceForFluid = this.fuelTank.getCapacity() -
/*
* if (this.fuelTank.getFluid() == null || this.fuelTank.getFluid().amount + liquid.amount <=
* this.fuelTank.getCapacity()) {
*/
final int fluidAmount = this.fuelTank.getFluid() == null ? 0 : this.fuelTank.getFluid().amount;
final int spaceForFluid = this.fuelTank.getCapacity() - fluidAmount;

// attempt to drain as much as we have space
if (canister.getItem() instanceof IFluidContainerItem) {
// try to do
final FluidStack drained = ((IFluidContainerItem) canister.getItem())
.drain(canister, spaceForFluid, true);
if (canister.getItem() instanceof IFluidContainerItem fluidCanister) {
// try to drain as much as we have space for
final FluidStack drained = fluidCanister.drain(canister, spaceForFluid, true);
if (drained != null && drained.amount > 0) {
//
this.fuelTank.fill(new FluidStack(this.fuel, drained.amount), true);
// check how much fluid remains in there
// getFluidForFilledItem doesn't work on IFluidContainerItem
liquid = ((IFluidContainerItem) canister.getItem()).getFluid(canister);
// liquid = FluidContainerRegistry.getFluidForFilledItem(canister);
if (liquid == null || liquid.amount == 0) {
// this should replace the container with it's empty version
final ItemStack canisterNew = FluidContainerRegistry.drainFluidContainer(canister);
if (canisterNew != null) {
this.containingItems[0] = canisterNew;
}
}
// if(((IFluidContainerItem)canister.getItem()).)
// FluidContainerRegistry.get
}
} else {
// attempt to drain it all at once
final int capacity = FluidContainerRegistry.getContainerCapacity(canister);

if (spaceForFluid >= capacity) {
// now drain it
this.fuelTank.fill(new FluidStack(this.fuel, capacity), true);
final ItemStack canisterNew = FluidContainerRegistry.drainFluidContainer(canister);
if (canisterNew != null) {
this.fuelTank.fill(new FluidStack(this.fuel, capacity), true);
this.containingItems[0] = canisterNew;
}
}
}

// }
}
/*
* if (this.containingItems[0].getItem() instanceof ItemCanisterGeneric) { if (this.containingItems[0].getItem()
* == GCItems.fuelCanister) { int originalDamage = this.containingItems[0].getItemDamage(); int used =
* this.fuelTank.fill(new FluidStack(GalacticraftCore.fluidFuel, ItemCanisterGeneric.EMPTY - originalDamage),
* true); if (originalDamage + used == ItemCanisterGeneric.EMPTY) this.containingItems[0] = new
* ItemStack(GCItems.oilCanister, 1, ItemCanisterGeneric.EMPTY); else this.containingItems[0] = new
* ItemStack(GCItems.fuelCanister, 1, originalDamage + used); } } else { final FluidStack liquid =
* FluidContainerRegistry.getFluidForFilledItem(this.containingItems[0]); if (liquid != null) { boolean isFuel =
* FluidUtil.testFuel(FluidRegistry.getFluidName(liquid)); if (isFuel) { if (this.fuelTank.getFluid() == null ||
* this.fuelTank.getFluid().amount + liquid.amount <= this.fuelTank.getCapacity()) { this.fuelTank.fill(new
* FluidStack(GalacticraftCore.fluidFuel, liquid.amount), true); if
* (FluidContainerRegistry.isBucket(this.containingItems[0]) &&
* FluidContainerRegistry.isFilledContainer(this.containingItems[0])) { final int amount =
* this.containingItems[0].stackSize; if (amount > 1) { this.fuelTank.fill(new
* FluidStack(GalacticraftCore.fluidFuel, (amount - 1) * FluidContainerRegistry.BUCKET_VOLUME), true); }
* this.containingItems[0] = new ItemStack(Items.bucket, amount); } else { this.containingItems[0].stackSize--;
* if (this.containingItems[0].stackSize == 0) { this.containingItems[0] = null; } } } } } }
*/
}

@Override
Expand Down Expand Up @@ -878,7 +838,7 @@ public void beginTransit(final long duration) {

/**
* This should return how much fuel units are consumed per AU travelled, in millibuckets
*
*
* @return
*/
// abstract public int getFuelUsagePerAU();
Expand Down

0 comments on commit d3e8c84

Please sign in to comment.