Skip to content

Commit

Permalink
Fix addFluid expansion method for GrS/CT (#2287)
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss committed Dec 16, 2023
1 parent d09b517 commit 34408eb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected static FluidState validateFluidState(String fluidTypeName) {
if (fluidTypeName.equals("gas")) return FluidState.GAS;
if (fluidTypeName.equals("plasma")) return FluidState.PLASMA;

String message = "Fluid Type must be either \"liquid\", \"gas\", or \"acid\"!";
String message = "Fluid Type must be either \"liquid\", \"gas\", or \"plasma\"!";
CraftTweakerAPI.logError(message);
throw new IllegalArgumentException(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,27 @@ public static void addFluid(Material m) {
public static void addFluid(Material m, @Optional String fluidTypeName, @Optional boolean hasBlock) {
if (checkFrozen("add a Fluid to a material")) return;
FluidState type = validateFluidState(fluidTypeName);
if (m.hasProperty(PropertyKey.FLUID)) {
FluidStorage storage = m.getProperty(PropertyKey.FLUID).getStorage();
FluidBuilder builder = new FluidBuilder();
if (hasBlock) builder.block();
FluidProperty property = m.getProperty(PropertyKey.FLUID);
if (property == null) {
property = new FluidProperty();
m.setProperty(PropertyKey.FLUID, property);
}

FluidStorage storage = property.getStorage();
FluidBuilder builder = switch (type) {
case LIQUID -> storage.getQueuedBuilder(FluidStorageKeys.LIQUID);
case GAS -> storage.getQueuedBuilder(FluidStorageKeys.GAS);
case PLASMA -> storage.getQueuedBuilder(FluidStorageKeys.PLASMA);
};
if (builder == null) {
builder = new FluidBuilder();
switch (type) {
case LIQUID -> storage.enqueueRegistration(FluidStorageKeys.LIQUID, builder);
case GAS -> storage.enqueueRegistration(FluidStorageKeys.GAS, builder.state(FluidState.GAS));
case PLASMA -> storage.enqueueRegistration(FluidStorageKeys.PLASMA, builder.state(FluidState.PLASMA));
}
} else {
FluidProperty property = new FluidProperty();
property.getStorage().enqueueRegistration(FluidStorageKeys.LIQUID, new FluidBuilder());
m.setProperty(PropertyKey.FLUID, property);
}
if (hasBlock) builder.block();
}

@ZenMethod
Expand Down

0 comments on commit 34408eb

Please sign in to comment.