Fluid Component safety.

This commit is contained in:
Flanks255 2024-11-07 15:20:30 -06:00
parent 9c6859cdd3
commit 2b8884da3e
6 changed files with 30 additions and 11 deletions

View file

@ -161,16 +161,29 @@ public class ActuallyComponents {
.build()); .build());
public record FluidContents(FluidStack inner) { public static class FluidContents {
public static final Codec<FluidContents> CODEC = FluidStack.OPTIONAL_CODEC.xmap(FluidContents::new, FluidContents::inner); private final FluidStack inner;
public static final StreamCodec<RegistryFriendlyByteBuf, FluidContents> STREAM_CODEC = FluidStack.OPTIONAL_STREAM_CODEC.map(FluidContents::new, FluidContents::inner); public static final Codec<FluidContents> CODEC = FluidStack.OPTIONAL_CODEC.xmap(FluidContents::of, FluidContents::inner);
public static final StreamCodec<RegistryFriendlyByteBuf, FluidContents> STREAM_CODEC = FluidStack.OPTIONAL_STREAM_CODEC.map(FluidContents::of, FluidContents::inner);
public static final FluidContents EMPTY = new FluidContents(FluidStack.EMPTY); public static final FluidContents EMPTY = FluidContents.of(FluidStack.EMPTY);
public static FluidContents of(FluidStack stack) { public static FluidContents of(FluidStack stack) {
return new FluidContents(stack); return new FluidContents(stack);
} }
private FluidStack inner() {
return inner;
}
private FluidContents(FluidStack inner) {
this.inner = inner;
}
public FluidStack get() {
return inner.copy();
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj instanceof FluidStack other) { if (obj instanceof FluidStack other) {
@ -178,7 +191,13 @@ public class ActuallyComponents {
} }
return false; return false;
} }
@Override
public int hashCode() {
return inner.hashCode();
} }
}
/* /*
* This is a supplier for an attachment type that can be used to attach an energy storage to an item. * This is a supplier for an attachment type that can be used to attach an energy storage to an item.
* Implementation is based on EnderIO's https://github.com/Team-EnderIO/EnderIO/blob/e1f022df745131ed5fea718bd860880a5785d4c7/src/core/java/com/enderio/core/common/attachment/AttachmentUtil.java#L47-L60 * Implementation is based on EnderIO's https://github.com/Team-EnderIO/EnderIO/blob/e1f022df745131ed5fea718bd860880a5785d4c7/src/core/java/com/enderio/core/common/attachment/AttachmentUtil.java#L47-L60

View file

@ -194,7 +194,7 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements Me
super.applyImplicitComponents(componentInput); super.applyImplicitComponents(componentInput);
storage.setEnergyStored(componentInput.getOrDefault(ActuallyComponents.ENERGY_STORAGE, 0)); storage.setEnergyStored(componentInput.getOrDefault(ActuallyComponents.ENERGY_STORAGE, 0));
tank.setFluid(componentInput.getOrDefault(ActuallyComponents.FLUID_A, ActuallyComponents.FluidContents.EMPTY).inner()); tank.setFluid(componentInput.getOrDefault(ActuallyComponents.FLUID_A, ActuallyComponents.FluidContents.EMPTY).get());
} }
@Override @Override

View file

@ -264,7 +264,7 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
super.applyImplicitComponents(componentInput); super.applyImplicitComponents(componentInput);
storage.setEnergyStored(componentInput.getOrDefault(ActuallyComponents.ENERGY_STORAGE, 0)); storage.setEnergyStored(componentInput.getOrDefault(ActuallyComponents.ENERGY_STORAGE, 0));
tank.setFluid(componentInput.getOrDefault(ActuallyComponents.FLUID_A, ActuallyComponents.FluidContents.EMPTY).inner()); tank.setFluid(componentInput.getOrDefault(ActuallyComponents.FLUID_A, ActuallyComponents.FluidContents.EMPTY).get());
this.coffeeCacheAmount = componentInput.getOrDefault(ActuallyComponents.MISC_INT, 0); this.coffeeCacheAmount = componentInput.getOrDefault(ActuallyComponents.MISC_INT, 0);
} }

View file

@ -125,8 +125,8 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IShari
protected void applyImplicitComponents(DataComponentInput componentInput) { protected void applyImplicitComponents(DataComponentInput componentInput) {
super.applyImplicitComponents(componentInput); super.applyImplicitComponents(componentInput);
tanks.inputTank.setFluid(componentInput.getOrDefault(ActuallyComponents.FLUID_A, ActuallyComponents.FluidContents.EMPTY).inner()); tanks.inputTank.setFluid(componentInput.getOrDefault(ActuallyComponents.FLUID_A, ActuallyComponents.FluidContents.EMPTY).get());
tanks.outputTank.setFluid(componentInput.getOrDefault(ActuallyComponents.FLUID_B, ActuallyComponents.FluidContents.EMPTY).inner()); tanks.outputTank.setFluid(componentInput.getOrDefault(ActuallyComponents.FLUID_B, ActuallyComponents.FluidContents.EMPTY).get());
} }
@Override @Override

View file

@ -235,7 +235,7 @@ public class TileEntityFluidCollector extends TileEntityBase implements ISharing
protected void applyImplicitComponents(@Nonnull DataComponentInput input) { protected void applyImplicitComponents(@Nonnull DataComponentInput input) {
super.applyImplicitComponents(input); super.applyImplicitComponents(input);
tank.setFluid(input.getOrDefault(ActuallyComponents.FLUID_A, ActuallyComponents.FluidContents.EMPTY).inner()); tank.setFluid(input.getOrDefault(ActuallyComponents.FLUID_A, ActuallyComponents.FluidContents.EMPTY).get());
this.isPulseMode = input.getOrDefault(ActuallyComponents.PULSE_MODE, false); this.isPulseMode = input.getOrDefault(ActuallyComponents.PULSE_MODE, false);
} }

View file

@ -237,7 +237,7 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn
super.applyImplicitComponents(input); super.applyImplicitComponents(input);
storage.setEnergyStored(input.getOrDefault(ActuallyComponents.ENERGY_STORAGE, 0)); storage.setEnergyStored(input.getOrDefault(ActuallyComponents.ENERGY_STORAGE, 0));
tank.setFluid(input.getOrDefault(ActuallyComponents.FLUID_A, ActuallyComponents.FluidContents.EMPTY).inner()); tank.setFluid(input.getOrDefault(ActuallyComponents.FLUID_A, ActuallyComponents.FluidContents.EMPTY).get());
} }
@Override @Override