mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-22 11:29:23 +01:00
Fluid Component safety.
This commit is contained in:
parent
9c6859cdd3
commit
2b8884da3e
6 changed files with 30 additions and 11 deletions
|
@ -161,24 +161,43 @@ public class ActuallyComponents {
|
|||
.build());
|
||||
|
||||
|
||||
public record FluidContents(FluidStack inner) {
|
||||
public static final Codec<FluidContents> CODEC = FluidStack.OPTIONAL_CODEC.xmap(FluidContents::new, FluidContents::inner);
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, FluidContents> STREAM_CODEC = FluidStack.OPTIONAL_STREAM_CODEC.map(FluidContents::new, FluidContents::inner);
|
||||
public static class FluidContents {
|
||||
private final FluidStack 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) {
|
||||
return new FluidContents(stack);
|
||||
}
|
||||
|
||||
private FluidStack inner() {
|
||||
return inner;
|
||||
}
|
||||
|
||||
private FluidContents(FluidStack inner) {
|
||||
this.inner = inner;
|
||||
}
|
||||
|
||||
public FluidStack get() {
|
||||
return inner.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof FluidStack other) {
|
||||
return FluidStack.matches(inner, other);
|
||||
}
|
||||
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.
|
||||
* 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
|
||||
|
|
|
@ -194,7 +194,7 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements Me
|
|||
super.applyImplicitComponents(componentInput);
|
||||
|
||||
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
|
||||
|
|
|
@ -264,7 +264,7 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
|
|||
super.applyImplicitComponents(componentInput);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -125,8 +125,8 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IShari
|
|||
protected void applyImplicitComponents(DataComponentInput componentInput) {
|
||||
super.applyImplicitComponents(componentInput);
|
||||
|
||||
tanks.inputTank.setFluid(componentInput.getOrDefault(ActuallyComponents.FLUID_A, ActuallyComponents.FluidContents.EMPTY).inner());
|
||||
tanks.outputTank.setFluid(componentInput.getOrDefault(ActuallyComponents.FLUID_B, 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).get());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -235,7 +235,7 @@ public class TileEntityFluidCollector extends TileEntityBase implements ISharing
|
|||
protected void applyImplicitComponents(@Nonnull DataComponentInput 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -237,7 +237,7 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn
|
|||
super.applyImplicitComponents(input);
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue