Skip to content

Commit

Permalink
Merge pull request #28 from GTNewHorizons/fluid-crash
Browse files Browse the repository at this point in the history
Fix fluid handling related crash
  • Loading branch information
boubou19 authored Aug 7, 2023
2 parents b6a2503 + d3e8c84 commit 9de95e2
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 56 deletions.
7 changes: 5 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//version: 1690907958
//version: 1691351470
/*
DO NOT CHANGE THIS FILE!
Also, you may replace this file at any time if there is an update available.
Expand Down Expand Up @@ -1152,7 +1152,10 @@ tasks.named("processIdeaSettings").configure {

tasks.named("ideVirtualMainClasses").configure {
// Make IntelliJ "Build project" build the mod jars
dependsOn("jar", "reobfJar", "spotlessCheck")
dependsOn("jar", "reobfJar")
if (!disableSpotless) {
dependsOn("spotlessCheck")
}
}

// workaround variable hiding in pom processing
Expand Down
8 changes: 4 additions & 4 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
dependencies {
implementation('com.github.GTNewHorizons:Galacticraft:3.0.68-GTNH:dev')
implementation('com.github.GTNewHorizons:NotEnoughItems:2.3.45-GTNH:dev')
implementation('com.github.GTNewHorizons:Galacticraft:3.0.73-GTNH:dev')
implementation('com.github.GTNewHorizons:NotEnoughItems:2.3.81-GTNH:dev')
implementation('net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev')

compileOnly('com.github.GTNewHorizons:BuildCraft:7.1.33:api')
compileOnly('com.github.GTNewHorizons:EnderIO:2.4.10:api')
compileOnly('com.github.GTNewHorizons:BuildCraft:7.1.36:api')
compileOnly('com.github.GTNewHorizons:EnderIO:2.4.24:api')
compileOnly('curse.maven:cofh-lib-220333:2388748')
compileOnly(deobf('https://s3.amazonaws.com/aidancbrady/mekanism/281-recommended/Mekanism-1.7.10-9.1.0.281.jar'))
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
7 changes: 4 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ done
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum

Expand Down Expand Up @@ -197,6 +194,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down
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 9de95e2

Please sign in to comment.