Skip to content

Commit

Permalink
fix: brewing stand lagging animation & fast brew
Browse files Browse the repository at this point in the history
  • Loading branch information
IWareQ committed Jan 13, 2025
1 parent 948bb3a commit 1e0c8b1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Unless otherwise specified, any version comparison below is the comparison of se
- Fixed the bug that interacting with door doesn't have any sound.
- Waxing copper-made block using honeycomb won't call `BlockFadeEvent` now.
- Fixed the bug that player can still open enchant table even if he is sneaking.
- Fixed the bug that brewing stand fast brew and lagging brew animation.

## [0.1.2](https://github.com/AllayMC/Allay/releases/tag/0.1.2) (API 0.3.0) - 2024-12-31

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,33 +67,38 @@ public void onInitFinish(BlockEntityInitInfo initInfo) {

container.addOnSlotChangeListener(BrewingStandContainer.REAGENT_SLOT, item -> {
brewTime = item == ItemAirStack.AIR_STACK ? 0 : MAX_BREW_TIME;
sendBrewingStandContainerData(true);
});
}

@Override
public void tick(long currentTick) {
tickBrewingStand();
sendBrewingStandContainerData(brewTime % 40 == 0);
BrewingStandContainer container = containerHolderComponent.getContainer();
tickBrewingStand(container);
container.sendContainerData(ContainerSetDataPacket.BREWING_STAND_FUEL_AMOUNT, fuelAmount);
container.sendContainerData(ContainerSetDataPacket.BREWING_STAND_FUEL_TOTAL, fuelTotal);
}

protected void tickBrewingStand() {
if (!checkFuel()) {
protected void tickBrewingStand(BrewingStandContainer container) {
if (!checkFuel(container)) {
return;
}

BrewingStandContainer container = containerHolderComponent.getContainer();
var reagent = container.getReagent();
var a = findRecipe(container.getResult(0), reagent);
var b = findRecipe(container.getResult(1), reagent);
var c = findRecipe(container.getResult(2), reagent);

if (a == null && b == null && c == null) {
brewTime = 0;
brewTime = MAX_BREW_TIME;
container.sendContainerData(ContainerSetDataPacket.BREWING_STAND_BREW_TIME, 0); // We should reset brew animation
return;
}

if (brewTime > 0) {
if (brewTime % 40 == 0) {
container.sendContainerData(ContainerSetDataPacket.BREWING_STAND_BREW_TIME, brewTime);
}

brewTime--;
return;
}
Expand Down Expand Up @@ -123,13 +128,11 @@ protected void tickBrewingStand() {
getDimension().addSound(position, Sound.RANDOM_POTION_BREWED);
}

protected boolean checkFuel() {
protected boolean checkFuel(BrewingStandContainer container) {
if (fuelAmount > 0) {
return true;
}

BrewingStandContainer container = containerHolderComponent.getContainer();

var fuel = container.getFuel();
if (fuel.getItemType() != ItemTypes.BLAZE_POWDER) {
return false;
Expand All @@ -151,15 +154,6 @@ protected PotionMixRecipe findRecipe(ItemStack ingredient, ItemStack reagent) {
return Registries.POTION_MIX_RECIPES.get(PotionMixRecipe.buildIdentifier(ingredient, reagent));
}

protected void sendBrewingStandContainerData(boolean sendBrewTime) {
var container = containerHolderComponent.getContainer();
if (sendBrewTime) {
container.sendContainerData(ContainerSetDataPacket.BREWING_STAND_BREW_TIME, brewTime);
}
container.sendContainerData(ContainerSetDataPacket.BREWING_STAND_FUEL_AMOUNT, fuelAmount);
container.sendContainerData(ContainerSetDataPacket.BREWING_STAND_FUEL_TOTAL, fuelTotal);
}

@Override
public NbtMap saveNBT() {
return super.saveNBT()
Expand Down

0 comments on commit 1e0c8b1

Please sign in to comment.