Skip to content

Commit

Permalink
Fix plasma temp NPE for plasma-only materials
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss committed Dec 16, 2023
1 parent 2fb6af9 commit 118a731
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/java/gregtech/api/fluids/FluidBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ private void determineTemperature(@Nullable Material material) {
}
case GAS -> ROOM_TEMPERATURE;
case PLASMA -> {
if (material.hasFluid()) {
if (material.hasFluid() && material.getFluid() != null) {
yield BASE_PLASMA_TEMPERATURE + material.getFluid().getTemperature();
}
yield BASE_PLASMA_TEMPERATURE;
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/gregtech/api/fluids/store/FluidStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Comparator;
import java.util.Map;

public final class FluidStorage {
Expand Down Expand Up @@ -69,12 +70,14 @@ public void registerFluids(@NotNull Material material) {
enqueueRegistration(FluidStorageKeys.LIQUID, new FluidBuilder());
}

for (var entry : toRegister.entrySet()) {
Fluid fluid = entry.getValue().build(material.getModid(), material, entry.getKey());
if (!storeNoOverwrites(entry.getKey(), fluid)) {
GTLog.logger.error("{} already has an associated fluid for material {}", material);
}
}
toRegister.entrySet().stream()
.sorted(Comparator.comparingInt(e -> -e.getKey().getRegistrationPriority()))
.forEach(entry -> {
Fluid fluid = entry.getValue().build(material.getModid(), material, entry.getKey());
if (!storeNoOverwrites(entry.getKey(), fluid)) {
GTLog.logger.error("{} already has an associated fluid for material {}", material);
}
});
toRegister = null;
registered = true;
}
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/gregtech/api/fluids/store/FluidStorageKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public final class FluidStorageKey {
private final Function<Material, String> translationKeyFunction;
private final int hashCode;
private final FluidState defaultFluidState;
private final int registrationPriority;

public FluidStorageKey(@NotNull ResourceLocation resourceLocation, @NotNull MaterialIconType iconType,
@NotNull UnaryOperator<@NotNull String> registryNameOperator,
Expand All @@ -35,12 +36,20 @@ public FluidStorageKey(@NotNull ResourceLocation resourceLocation, @NotNull Mate
@NotNull UnaryOperator<@NotNull String> registryNameOperator,
@NotNull Function<@NotNull Material, @NotNull String> translationKeyFunction,
@Nullable FluidState defaultFluidState) {
this(resourceLocation, iconType, registryNameOperator, translationKeyFunction, defaultFluidState, 0);
}

public FluidStorageKey(@NotNull ResourceLocation resourceLocation, @NotNull MaterialIconType iconType,
@NotNull UnaryOperator<@NotNull String> registryNameOperator,
@NotNull Function<@NotNull Material, @NotNull String> translationKeyFunction,
@Nullable FluidState defaultFluidState, int registrationPriority) {
this.resourceLocation = resourceLocation;
this.iconType = iconType;
this.registryNameOperator = registryNameOperator;
this.translationKeyFunction = translationKeyFunction;
this.hashCode = resourceLocation.hashCode();
this.defaultFluidState = defaultFluidState;
this.registrationPriority = registrationPriority;
if (keys.containsKey(resourceLocation)) {
throw new IllegalArgumentException("Cannot create duplicate keys");
}
Expand Down Expand Up @@ -81,6 +90,14 @@ public FluidStorageKey(@NotNull ResourceLocation resourceLocation, @NotNull Mate
return defaultFluidState;
}

/**
* @return The registration priority for this fluid type, determining the build order for fluids.
* Useful for when your fluid building requires some properties from previous fluids.
*/
public int getRegistrationPriority() {
return registrationPriority;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class FluidStorageKeys {
public static final FluidStorageKey PLASMA = new FluidStorageKey(gregtechId("plasma"),
MaterialIconType.plasma,
s -> "plasma." + s, m -> "gregtech.fluid.plasma",
FluidState.PLASMA);
FluidState.PLASMA, -1);

private FluidStorageKeys() {}
}

0 comments on commit 118a731

Please sign in to comment.