Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix plasma temp NPE for plasma-only materials #2306

Merged
merged 3 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {}
}
10 changes: 7 additions & 3 deletions src/main/java/gregtech/loaders/recipe/RecyclingRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ private static void registerExtractorRecycling(ItemStack input, List<MaterialSta
if (m.hasProperty(PropertyKey.INGOT) && m.getProperty(PropertyKey.INGOT).getMacerateInto() != m) {
m = m.getProperty(PropertyKey.INGOT).getMacerateInto();
}
if (!m.hasProperty(PropertyKey.FLUID) || (prefix == OrePrefix.dust && m.hasProperty(PropertyKey.BLAST))) {
if (!m.hasProperty(PropertyKey.FLUID) || m.getFluid() == null) {
return;
}
if (prefix == OrePrefix.dust && m.hasProperty(PropertyKey.BLAST)) {
return;
}
RecipeMaps.EXTRACTOR_RECIPES.recipeBuilder()
Expand All @@ -156,8 +159,9 @@ private static void registerExtractorRecycling(ItemStack input, List<MaterialSta

// Find the first Material which can create a Fluid.
// If no Material in the list can create a Fluid, return.
MaterialStack fluidMs = materials.stream().filter(ms -> ms.material.hasProperty(PropertyKey.FLUID)).findFirst()
.orElse(null);
MaterialStack fluidMs = materials.stream()
.filter(ms -> ms.material.hasProperty(PropertyKey.FLUID) && ms.material.getFluid() != null)
.findFirst().orElse(null);
if (fluidMs == null) return;

// Find the next MaterialStack, which will be the Item output.
Expand Down