From e1ab7d4566b0a7d586948385bfabaa36d4699b74 Mon Sep 17 00:00:00 2001 From: IzzelAliz Date: Sun, 7 Nov 2021 20:42:35 +0800 Subject: [PATCH] Update upstream (CraftBukkit) --- .../entity/BrewingStandBlockEntityMixin.java | 49 +++++++++++++++++-- .../PersistentEntitySectionManagerMixin.java | 7 ++- .../resources/META-INF/accesstransformer.cfg | 3 ++ 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/entity/BrewingStandBlockEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/entity/BrewingStandBlockEntityMixin.java index 5035502e..b0dafcf3 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/entity/BrewingStandBlockEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/entity/BrewingStandBlockEntityMixin.java @@ -5,10 +5,13 @@ import io.izzel.arclight.common.mod.util.ArclightCaptures; import io.izzel.arclight.mixin.Eject; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; +import net.minecraft.world.Containers; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BrewingStandBlockEntity; import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.common.brewing.BrewingRecipeRegistry; +import net.minecraftforge.event.ForgeEventFactory; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; @@ -19,9 +22,9 @@ import org.bukkit.event.inventory.BrewingStandFuelEvent; import org.bukkit.inventory.BrewerInventory; import org.bukkit.inventory.InventoryHolder; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.ArrayList; @@ -52,17 +55,53 @@ public abstract class BrewingStandBlockEntityMixin extends LockableBlockEntityMi } } - @Inject(method = "doBrew", cancellable = true, at = @At("HEAD")) - private static void arclight$brewPotion(Level level, BlockPos pos, NonNullList p_155293_, CallbackInfo ci) { + /** + * @author Izzel_Aliz + * @reason + */ + @Overwrite + private static void doBrew(Level level, BlockPos pos, NonNullList stacks) { + if (ForgeEventFactory.onPotionAttemptBrew(stacks)) return; + ItemStack ing = stacks.get(3); + + List brewResults = new ArrayList<>(3); + for (int i = 0; i < 3; ++i) { + var input = stacks.get(i); + var output = BrewingRecipeRegistry.getOutput(input, ing); + brewResults.add(i, CraftItemStack.asCraftMirror(output.isEmpty() ? input : output)); + } BrewingStandBlockEntity entity = ArclightCaptures.getTickingBlockEntity(); InventoryHolder owner = entity == null ? null : ((TileEntityBridge) entity).bridge$getOwner(); if (owner != null) { - BrewEvent event = new BrewEvent(CraftBlock.at(level, pos), (BrewerInventory) owner.getInventory(), entity.fuel); + BrewEvent event = new BrewEvent(CraftBlock.at(level, pos), (BrewerInventory) owner.getInventory(), brewResults, entity.fuel); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { - ci.cancel(); + return; + } else { + for (int i = 0; i < 3; ++i) { + if (i < brewResults.size()) { + stacks.set(i, CraftItemStack.asNMSCopy(brewResults.get(i))); + } else { + stacks.set(i, ItemStack.EMPTY); + } + } } } + + // BrewingRecipeRegistry.brewPotions(stacks, ing, SLOTS_FOR_SIDES); + ForgeEventFactory.onPotionBrewed(stacks); + if (ing.hasContainerItem()) { + ItemStack containerItem = ing.getContainerItem(); + ing.shrink(1); + if (ing.isEmpty()) { + ing = containerItem; + } else { + Containers.dropItemStack(level, (double) pos.getX(), (double) pos.getY(), (double) pos.getZ(), containerItem); + } + } else ing.shrink(1); + + stacks.set(3, ing); + level.levelEvent(1035, pos, 0); } @Override diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/entity/PersistentEntitySectionManagerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/entity/PersistentEntitySectionManagerMixin.java index a746105a..36605b6b 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/entity/PersistentEntitySectionManagerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/entity/PersistentEntitySectionManagerMixin.java @@ -1,6 +1,6 @@ package io.izzel.arclight.common.mixin.core.world.level.entity; -import com.google.common.collect.ImmutableList; +import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.chunk.storage.EntityStorage; @@ -34,6 +34,7 @@ public abstract class PersistentEntitySectionManagerMixin permanentStorage; @Shadow @Final EntitySectionStorage sectionStorage; + @Shadow @Final private Long2ObjectMap chunkLoadStatuses; // @formatter:on public void close(boolean save) throws IOException { @@ -49,6 +50,10 @@ public abstract class PersistentEntitySectionManagerMixin (Entity) o).collect(Collectors.toList()); } + public boolean isPending(long cord) { + return this.chunkLoadStatuses.get(cord) == PersistentEntitySectionManager.ChunkLoadStatus.PENDING; + } + @Unique private boolean arclight$fireEvent = false; @Inject(method = "storeChunkSections", locals = LocalCapture.CAPTURE_FAILHARD, diff --git a/arclight-common/src/main/resources/META-INF/accesstransformer.cfg b/arclight-common/src/main/resources/META-INF/accesstransformer.cfg index c5788578..fcd54c79 100644 --- a/arclight-common/src/main/resources/META-INF/accesstransformer.cfg +++ b/arclight-common/src/main/resources/META-INF/accesstransformer.cfg @@ -14,6 +14,9 @@ public net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemp public net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate f_74483_ # entityInfoList public net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager f_74326_ # structureRepository public net.minecraft.world.level.block.entity.LecternBlockEntity$1 +public net.minecraft.world.level.chunk.storage.EntityStorage f_182485_ # entityDeserializerQueue +public net.minecraft.world.level.entity.PersistentEntitySectionManager f_157493_ # permanentStorage +public net.minecraft.world.level.entity.PersistentEntitySectionManager$ChunkLoadStatus # Misc public net.minecraft.server.PlayerAdvancements f_135964_ public net.minecraft.server.level.PlayerRespawnLogic m_8264_(Lnet/minecraft/server/level/ServerLevel;IIZ)Lnet/minecraft/core/BlockPos;