Skip to content

Commit

Permalink
fix block facing
Browse files Browse the repository at this point in the history
compele behivor BrewingKegBlockEntity
  • Loading branch information
MEGATREX4 committed Jul 6, 2024
1 parent af925f8 commit 3904238
Showing 1 changed file with 46 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ public class BrewingKegBlockEntity extends BlockEntity implements ExtendedScreen
private ItemStack drinkContainer = ItemStack.EMPTY;
private float totalExperience = 0;


public final SingleVariantStorage<FluidVariant> fluidStorage = new SingleVariantStorage<FluidVariant>() {
@Override
protected FluidVariant getBlankVariant() {
return FluidVariant.blank();
}


@Override
protected long getCapacity(FluidVariant variant) {
return FluidStack.convertDropletsToMb(FluidConstants.BUCKET) * 15; // 5k mB
Expand All @@ -96,6 +98,7 @@ protected void onFinalCommit() {
}
};


public BrewingKegBlockEntity(BlockPos pos, BlockState state) {
super(ModBlockEntities.BREWING_KEG_BLOCK_ENTITY, pos, state);
this.propertyDelegate = new PropertyDelegate() {
Expand Down Expand Up @@ -132,6 +135,35 @@ public DefaultedList<ItemStack> getItems() {
return inventory;
}


public NbtCompound writeToNbtPublic(NbtCompound nbt) {
// Call the superclass method to ensure all necessary data is written
super.writeNbt(nbt); // Call super method to save base block entity data

// Save DRINKS_DISPLAY_SLOT to NBT
NbtCompound displaySlotTag = new NbtCompound();
this.getStack(DRINKS_DISPLAY_SLOT).writeNbt(displaySlotTag);
nbt.put("DisplaySlot", displaySlotTag);

// Save water amount
nbt.putLong("brewing_keg.fluid_amount", fluidStorage.amount);
nbt.put("brewing_keg.fluid_variant", fluidStorage.variant.toNbt());

// Save container
NbtCompound containerTag = new NbtCompound();
drinkContainer.writeNbt(containerTag);
nbt.put("Container", containerTag);

// Save experience
nbt.putFloat("TotalExperience", totalExperience);

// Return the modified NbtCompound
return nbt;
}




@Override
protected void writeNbt(NbtCompound nbt) {
super.writeNbt(nbt);
Expand All @@ -147,9 +179,14 @@ protected void writeNbt(NbtCompound nbt) {

// Save DRINKS_DISPLAY_SLOT
NbtCompound displaySlotTag = new NbtCompound();
getStack(DRINKS_DISPLAY_SLOT).writeNbt(displaySlotTag);
ItemStack displayStack = getStack(DRINKS_DISPLAY_SLOT);
if (!displayStack.isEmpty()) {
displayStack.writeNbt(displaySlotTag);
}
nbt.put("DisplaySlot", displaySlotTag);

// Save totalExperience
nbt.putFloat("TotalExperience", totalExperience);
}


Expand All @@ -171,14 +208,15 @@ public void readNbt(NbtCompound nbt) {
}

// Load DRINKS_DISPLAY_SLOT
NbtCompound displaySlotTag = nbt.getCompound("DisplaySlot");
setStack(DRINKS_DISPLAY_SLOT, ItemStack.fromNbt(displaySlotTag));

if (nbt.contains("DisplaySlot", NbtType.COMPOUND)) {
NbtCompound displaySlotTag = nbt.getCompound("DisplaySlot");
setStack(DRINKS_DISPLAY_SLOT, ItemStack.fromNbt(displaySlotTag));
} else {
setStack(DRINKS_DISPLAY_SLOT, ItemStack.EMPTY); // Ensure it's clear if no DisplaySlot is found
}
}




private void debugFluidLevel() {
System.out.println("Fluid: " + fluidStorage.variant.getFluid().toString());
System.out.println("Amount: " + fluidStorage.amount + " mB");
Expand Down Expand Up @@ -264,12 +302,6 @@ private void spawnExperienceOrb(World world, BlockPos pos, int xpAmount) {
}








private void processCrafting() {
Optional<BrewingRecipe> match = getCurrentRecipe();
if (match.isPresent()) {
Expand All @@ -295,9 +327,6 @@ private void processCrafting() {
}





private boolean hasValidIngredients(BrewingRecipe recipe) {
List<ItemStack> ingredients = new ArrayList<>();
for (int slot : INGREDIENT_SLOTS) {
Expand Down Expand Up @@ -489,9 +518,6 @@ private boolean craftItem(BrewingRecipe recipe, int craftedAmount) {
}





private void extractFluid(int amount) {
try (Transaction transaction = Transaction.openOuter()) {
this.fluidStorage.extract(FluidVariant.of(Fluids.WATER), amount, transaction);
Expand Down Expand Up @@ -534,5 +560,7 @@ public void markDirty() {

public void trackRecipeExperience(float totalExperience) {
this.totalExperience += totalExperience;
markDirty();
}

}

0 comments on commit 3904238

Please sign in to comment.