Update upstream (CraftBukkit)

This commit is contained in:
IzzelAliz 2021-11-07 20:42:35 +08:00
parent 4fafa3f88d
commit e1ab7d4566
No known key found for this signature in database
GPG Key ID: EE50E123A11D8338
3 changed files with 53 additions and 6 deletions

View File

@ -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<ItemStack> p_155293_, CallbackInfo ci) {
/**
* @author Izzel_Aliz
* @reason
*/
@Overwrite
private static void doBrew(Level level, BlockPos pos, NonNullList<ItemStack> stacks) {
if (ForgeEventFactory.onPotionAttemptBrew(stacks)) return;
ItemStack ing = stacks.get(3);
List<org.bukkit.inventory.ItemStack> 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

View File

@ -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<T extends EntityAccess
@Shadow public abstract void close() throws IOException;
@Shadow @Final private EntityPersistentStorage<T> permanentStorage;
@Shadow @Final EntitySectionStorage<T> sectionStorage;
@Shadow @Final private Long2ObjectMap<PersistentEntitySectionManager.ChunkLoadStatus> chunkLoadStatuses;
// @formatter:on
public void close(boolean save) throws IOException {
@ -49,6 +50,10 @@ public abstract class PersistentEntitySectionManagerMixin<T extends EntityAccess
.flatMap(EntitySection::getEntities).map(o -> (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,

View File

@ -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;