Skip to content

Commit

Permalink
Port titration barrel pickblock fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Electro593 committed Dec 2, 2023
1 parent 87ae1e8 commit 27901e1
Showing 1 changed file with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ protected void writeNbt(NbtCompound nbt) {
nbt.putLong("SealTime", this.sealTime);
nbt.putLong("TapTime", this.tapTime);
nbt.putInt("ExtractedBottles", this.extractedBottles);
if (this.world != null) {
nbt.putString("BarrelState", this.world.getBlockState(this.pos).get(BARREL_STATE).name());
}
}

@Override
Expand All @@ -82,6 +85,14 @@ public void readNbt(NbtCompound nbt) {
if (nbt.contains("Inventory", NbtElement.LIST_TYPE)) {
this.inventory.readNbtList(nbt.getList("Inventory", NbtElement.COMPOUND_TYPE));
}

if (nbt.contains("BarrelState", NbtElement.STRING_TYPE) && world != null) {
BlockState blockState = world.getBlockState(pos);
if (blockState.isOf(SpectrumBlocks.TITRATION_BARREL)) {
BarrelState barrelState = BarrelState.valueOf(nbt.getString("BarrelState"));
world.setBlockState(this.pos, blockState.with(BARREL_STATE, barrelState));
}
}

this.fluidStorage.variant = FluidVariant.fromNbt(nbt.getCompound("FluidVariant"));
this.fluidStorage.amount = nbt.getLong("FluidAmount");
Expand All @@ -97,7 +108,6 @@ public Inventory getInventory() {
public void seal() {
this.sealTime = new Date().getTime();
this.markDirty();
world.getRecipeManager().getFirstMatch(SpectrumRecipeTypes.TITRATION_BARREL, this.inventory, world);
}

public void tap() {
Expand Down Expand Up @@ -254,11 +264,15 @@ public boolean canBeSealed(PlayerEntity player) {
if (itemCount == 0 && fluid == Fluids.EMPTY) {
return true; // tap empty barrel advancement
}

Optional<ITitrationBarrelRecipe> optionalRecipe = getRecipeForInventory(world);
return optionalRecipe.isPresent()
&& optionalRecipe.get().canPlayerCraft(player)
&& this.getFluidVariant().getFluid() == optionalRecipe.get().getFluidInput();

if (world != null) {
Optional<ITitrationBarrelRecipe> optionalRecipe = getRecipeForInventory(world);
return optionalRecipe.isPresent()
&& optionalRecipe.get().canPlayerCraft(player)
&& this.getFluidVariant().getFluid() == optionalRecipe.get().getFluidInput();
}

return false;
}

}

0 comments on commit 27901e1

Please sign in to comment.