Fix InventoryOpenEvent cancellation

This commit is contained in:
Tamion
2024-08-19 18:05:26 +02:00
parent be5187c2da
commit 2742ad6a9a
23 changed files with 325 additions and 64 deletions

View File

@@ -0,0 +1,13 @@
--- a/net/minecraft/world/level/block/AnvilBlock.java
+++ b/net/minecraft/world/level/block/AnvilBlock.java
@@ -62,8 +62,9 @@
@Override
protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
if (!world.isClientSide) {
- player.openMenu(state.getMenuProvider(world, pos));
+ if (player.openMenu(state.getMenuProvider(world, pos)).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
player.awardStat(Stats.INTERACT_WITH_ANVIL);
+ } // Paper - Fix InventoryOpenEvent cancellation
}
return InteractionResult.SUCCESS;

View File

@@ -0,0 +1,12 @@
--- a/net/minecraft/world/level/block/BarrelBlock.java
+++ b/net/minecraft/world/level/block/BarrelBlock.java
@@ -41,8 +41,7 @@
@Override
protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
- if (world instanceof ServerLevel serverLevel && world.getBlockEntity(pos) instanceof BarrelBlockEntity barrelBlockEntity) {
- player.openMenu(barrelBlockEntity);
+ if (world instanceof ServerLevel serverLevel && world.getBlockEntity(pos) instanceof BarrelBlockEntity barrelBlockEntity && player.openMenu(barrelBlockEntity).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
player.awardStat(Stats.OPEN_BARREL);
PiglinAi.angerNearbyPiglins(serverLevel, player, true);
}

View File

@@ -0,0 +1,12 @@
--- a/net/minecraft/world/level/block/BeaconBlock.java
+++ b/net/minecraft/world/level/block/BeaconBlock.java
@@ -46,8 +46,7 @@
@Override
protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
- if (!world.isClientSide && world.getBlockEntity(pos) instanceof BeaconBlockEntity beaconBlockEntity) {
- player.openMenu(beaconBlockEntity);
+ if (!world.isClientSide && world.getBlockEntity(pos) instanceof BeaconBlockEntity beaconBlockEntity && player.openMenu(beaconBlockEntity).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
player.awardStat(Stats.INTERACT_WITH_BEACON);
}

View File

@@ -0,0 +1,12 @@
--- a/net/minecraft/world/level/block/BlastFurnaceBlock.java
+++ b/net/minecraft/world/level/block/BlastFurnaceBlock.java
@@ -45,8 +45,7 @@
@Override
protected void openContainer(Level world, BlockPos pos, Player player) {
BlockEntity blockEntity = world.getBlockEntity(pos);
- if (blockEntity instanceof BlastFurnaceBlockEntity) {
- player.openMenu((MenuProvider)blockEntity);
+ if (blockEntity instanceof BlastFurnaceBlockEntity && player.openMenu((MenuProvider)blockEntity).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
player.awardStat(Stats.INTERACT_WITH_BLAST_FURNACE);
}
}

View File

@@ -0,0 +1,12 @@
--- a/net/minecraft/world/level/block/BrewingStandBlock.java
+++ b/net/minecraft/world/level/block/BrewingStandBlock.java
@@ -68,8 +68,7 @@
@Override
protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
- if (!world.isClientSide && world.getBlockEntity(pos) instanceof BrewingStandBlockEntity brewingStandBlockEntity) {
- player.openMenu(brewingStandBlockEntity);
+ if (!world.isClientSide && world.getBlockEntity(pos) instanceof BrewingStandBlockEntity brewingStandBlockEntity && player.openMenu(brewingStandBlockEntity).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
player.awardStat(Stats.INTERACT_WITH_BREWINGSTAND);
}

View File

@@ -0,0 +1,13 @@
--- a/net/minecraft/world/level/block/CartographyTableBlock.java
+++ b/net/minecraft/world/level/block/CartographyTableBlock.java
@@ -32,8 +32,9 @@
@Override
protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
if (!world.isClientSide) {
- player.openMenu(state.getMenuProvider(world, pos));
+ if (player.openMenu(state.getMenuProvider(world, pos)).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
player.awardStat(Stats.INTERACT_WITH_CARTOGRAPHY_TABLE);
+ } // Paper - Fix InventoryOpenEvent cancellation
}
return InteractionResult.SUCCESS;

View File

@@ -26,10 +26,13 @@
}
public Optional<MenuProvider> acceptSingle(ChestBlockEntity single) {
@@ -121,6 +104,38 @@
}
};
@@ -118,8 +101,40 @@
@Override
public Optional<MenuProvider> acceptNone() {
return Optional.empty();
+ }
+ };
+
+ // CraftBukkit start
+ public static class DoubleInventory implements MenuProvider {
+
@@ -53,19 +56,28 @@
+ } else {
+ return null;
+ }
+ }
}
+
+ @Override
+ public Component getDisplayName() {
+ return (Component) (this.tileentitychest.hasCustomName() ? this.tileentitychest.getDisplayName() : (this.tileentitychest1.hasCustomName() ? this.tileentitychest1.getDisplayName() : Component.translatable("container.chestDouble")));
+ }
+ };
};
+ // CraftBukkit end
+
@Override
public MapCodec<? extends ChestBlock> codec() {
return ChestBlock.CODEC;
@@ -257,7 +272,7 @@
@@ -232,8 +247,7 @@
if (world instanceof ServerLevel worldserver) {
MenuProvider itileinventory = this.getMenuProvider(state, world, pos);
- if (itileinventory != null) {
- player.openMenu(itileinventory);
+ if (itileinventory != null && player.openMenu(itileinventory).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
player.awardStat(this.getOpenChestStat());
PiglinAi.angerNearbyPiglins(worldserver, player, true);
}
@@ -257,7 +271,7 @@
@Override
public DoubleBlockCombiner.NeighborCombineResult<? extends ChestBlockEntity> combine(BlockState state, Level world, BlockPos pos, boolean ignoreBlocked) {
@@ -74,7 +86,7 @@
if (ignoreBlocked) {
bipredicate = (generatoraccess, blockposition1) -> {
@@ -273,9 +288,16 @@
@@ -273,9 +287,16 @@
@Nullable
@Override
public MenuProvider getMenuProvider(BlockState state, Level world, BlockPos pos) {
@@ -92,7 +104,7 @@
public static DoubleBlockCombiner.Combiner<ChestBlockEntity, Float2FloatFunction> opennessCombiner(final LidBlockEntity progress) {
return new DoubleBlockCombiner.Combiner<ChestBlockEntity, Float2FloatFunction>() {
public Float2FloatFunction acceptDouble(ChestBlockEntity first, ChestBlockEntity second) {
@@ -321,6 +343,11 @@
@@ -321,6 +342,11 @@
}
private static boolean isCatSittingOnChest(LevelAccessor world, BlockPos pos) {

View File

@@ -0,0 +1,13 @@
--- a/net/minecraft/world/level/block/CraftingTableBlock.java
+++ b/net/minecraft/world/level/block/CraftingTableBlock.java
@@ -31,8 +31,9 @@
@Override
protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
if (!world.isClientSide) {
- player.openMenu(state.getMenuProvider(world, pos));
+ if (player.openMenu(state.getMenuProvider(world, pos)).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
player.awardStat(Stats.INTERACT_WITH_CRAFTING_TABLE);
+ } // Paper - Fix InventoryOpenEvent cancellation
}
return InteractionResult.SUCCESS;

View File

@@ -8,7 +8,18 @@
@Override
public MapCodec<? extends DispenserBlock> codec() {
@@ -88,7 +89,7 @@
@@ -79,8 +80,9 @@
if (tileentity instanceof DispenserBlockEntity) {
DispenserBlockEntity tileentitydispenser = (DispenserBlockEntity) tileentity;
- player.openMenu(tileentitydispenser);
+ if (player.openMenu(tileentitydispenser).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
player.awardStat(tileentitydispenser instanceof DropperBlockEntity ? Stats.INSPECT_DROPPER : Stats.INSPECT_DISPENSER);
+ } // Paper - Fix InventoryOpenEvent cancellation
}
}
@@ -88,7 +90,7 @@
}
public void dispenseFrom(ServerLevel world, BlockState state, BlockPos pos) {
@@ -17,7 +28,7 @@
if (tileentitydispenser == null) {
DispenserBlock.LOGGER.warn("Ignoring dispensing attempt for Dispenser without matching block entity at {}", pos);
@@ -97,13 +98,17 @@
@@ -97,13 +99,17 @@
int i = tileentitydispenser.getRandomSlot(world.random);
if (i < 0) {
@@ -35,7 +46,7 @@
tileentitydispenser.setItem(i, idispensebehavior.dispense(sourceblock, itemstack));
}
@@ -111,6 +116,12 @@
@@ -111,6 +117,12 @@
}
}

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/world/level/block/EnderChestBlock.java
+++ b/net/minecraft/world/level/block/EnderChestBlock.java
@@ -78,7 +78,7 @@
@@ -78,14 +78,16 @@
PlayerEnderChestContainer playerEnderChestContainer = player.getEnderChestInventory();
if (playerEnderChestContainer != null && world.getBlockEntity(pos) instanceof EnderChestBlockEntity enderChestBlockEntity) {
BlockPos blockPos = pos.above();
@@ -8,4 +8,18 @@
+ if (world.getBlockState(blockPos).isRedstoneConductor(world, blockPos)) { // Paper - diff on change; make sure that EnderChest#isBlocked uses the same logic
return InteractionResult.SUCCESS;
} else {
if (world instanceof ServerLevel serverLevel) {
- if (world instanceof ServerLevel serverLevel) {
- playerEnderChestContainer.setActiveChest(enderChestBlockEntity);
- player.openMenu(
- new SimpleMenuProvider((i, inventory, playerx) -> ChestMenu.threeRows(i, inventory, playerEnderChestContainer), CONTAINER_TITLE)
- );
+ // Paper start - Fix InventoryOpenEvent cancellation - moved up;
+ playerEnderChestContainer.setActiveChest(enderChestBlockEntity); // Needs to happen before ChestMenu.threeRows as it is required for opening animations
+ if (world instanceof ServerLevel serverLevel && player.openMenu(
+ new SimpleMenuProvider((i, inventory, playerx) -> ChestMenu.threeRows(i, inventory, playerEnderChestContainer), CONTAINER_TITLE)
+ ).isPresent()) {
+ // Paper end - Fix InventoryOpenEvent cancellation - moved up;
+ // Paper - Fix InventoryOpenEvent cancellation - moved up;
player.awardStat(Stats.OPEN_ENDERCHEST);
PiglinAi.angerNearbyPiglins(serverLevel, player, true);
}

View File

@@ -0,0 +1,12 @@
--- a/net/minecraft/world/level/block/FurnaceBlock.java
+++ b/net/minecraft/world/level/block/FurnaceBlock.java
@@ -45,8 +45,7 @@
@Override
protected void openContainer(Level world, BlockPos pos, Player player) {
BlockEntity blockEntity = world.getBlockEntity(pos);
- if (blockEntity instanceof FurnaceBlockEntity) {
- player.openMenu((MenuProvider)blockEntity);
+ if (blockEntity instanceof FurnaceBlockEntity && player.openMenu((MenuProvider)blockEntity).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
player.awardStat(Stats.INTERACT_WITH_FURNACE);
}
}

View File

@@ -0,0 +1,13 @@
--- a/net/minecraft/world/level/block/GrindstoneBlock.java
+++ b/net/minecraft/world/level/block/GrindstoneBlock.java
@@ -152,8 +152,9 @@
@Override
protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
if (!world.isClientSide) {
- player.openMenu(state.getMenuProvider(world, pos));
+ if (player.openMenu(state.getMenuProvider(world, pos)).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
player.awardStat(Stats.INTERACT_WITH_GRINDSTONE);
+ } // Paper - Fix InventoryOpenEvent cancellation
}
return InteractionResult.SUCCESS;

View File

@@ -1,6 +1,16 @@
--- a/net/minecraft/world/level/block/HopperBlock.java
+++ b/net/minecraft/world/level/block/HopperBlock.java
@@ -178,6 +178,7 @@
@@ -125,8 +125,7 @@
@Override
protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
- if (!world.isClientSide && world.getBlockEntity(pos) instanceof HopperBlockEntity hopperBlockEntity) {
- player.openMenu(hopperBlockEntity);
+ if (!world.isClientSide && world.getBlockEntity(pos) instanceof HopperBlockEntity hopperBlockEntity && player.openMenu(hopperBlockEntity).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
player.awardStat(Stats.INSPECT_HOPPER);
}
@@ -178,6 +177,7 @@
@Override
protected void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) {

View File

@@ -31,3 +31,13 @@
float f = 0.25F * (float) enumdirection.getStepX();
float f1 = 0.25F * (float) enumdirection.getStepZ();
ItemEntity entityitem = new ItemEntity(world, (double) pos.getX() + 0.5D + (double) f, (double) (pos.getY() + 1), (double) pos.getZ() + 0.5D + (double) f1, itemstack);
@@ -282,8 +293,7 @@
private void openScreen(Level world, BlockPos pos, Player player) {
BlockEntity tileentity = world.getBlockEntity(pos);
- if (tileentity instanceof LecternBlockEntity) {
- player.openMenu((LecternBlockEntity) tileentity);
+ if (tileentity instanceof LecternBlockEntity && player.openMenu((LecternBlockEntity) tileentity).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
player.awardStat(Stats.INTERACT_WITH_LECTERN);
}

View File

@@ -0,0 +1,13 @@
--- a/net/minecraft/world/level/block/LoomBlock.java
+++ b/net/minecraft/world/level/block/LoomBlock.java
@@ -33,8 +33,9 @@
@Override
protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
if (!world.isClientSide) {
- player.openMenu(state.getMenuProvider(world, pos));
+ if (player.openMenu(state.getMenuProvider(world, pos)).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
player.awardStat(Stats.INTERACT_WITH_LOOM);
+ } // Paper - Fix InventoryOpenEvent cancellation
}
return InteractionResult.SUCCESS;

View File

@@ -1,5 +1,16 @@
--- a/net/minecraft/world/level/block/ShulkerBoxBlock.java
+++ b/net/minecraft/world/level/block/ShulkerBoxBlock.java
@@ -98,8 +98,8 @@
protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
if (world instanceof ServerLevel serverLevel
&& world.getBlockEntity(pos) instanceof ShulkerBoxBlockEntity shulkerBoxBlockEntity
- && canOpen(state, world, pos, shulkerBoxBlockEntity)) {
- player.openMenu(shulkerBoxBlockEntity);
+ && canOpen(state, world, pos, shulkerBoxBlockEntity) // Paper - Fix InventoryOpenEvent cancellation - expand if for belows check
+ && player.openMenu(shulkerBoxBlockEntity).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
player.awardStat(Stats.OPEN_SHULKER_BOX);
PiglinAi.angerNearbyPiglins(serverLevel, player, true);
}
@@ -137,7 +137,7 @@
itemEntity.setDefaultPickUpDelay();
world.addFreshEntity(itemEntity);

View File

@@ -0,0 +1,13 @@
--- a/net/minecraft/world/level/block/SmithingTableBlock.java
+++ b/net/minecraft/world/level/block/SmithingTableBlock.java
@@ -38,8 +38,9 @@
@Override
protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
if (!world.isClientSide) {
- player.openMenu(state.getMenuProvider(world, pos));
+ if (player.openMenu(state.getMenuProvider(world, pos)).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
player.awardStat(Stats.INTERACT_WITH_SMITHING_TABLE);
+ } // Paper - Fix InventoryOpenEvent cancellation
}
return InteractionResult.SUCCESS;

View File

@@ -0,0 +1,12 @@
--- a/net/minecraft/world/level/block/SmokerBlock.java
+++ b/net/minecraft/world/level/block/SmokerBlock.java
@@ -44,8 +44,7 @@
@Override
protected void openContainer(Level world, BlockPos pos, Player player) {
BlockEntity blockEntity = world.getBlockEntity(pos);
- if (blockEntity instanceof SmokerBlockEntity) {
- player.openMenu((MenuProvider)blockEntity);
+ if (blockEntity instanceof SmokerBlockEntity && player.openMenu((MenuProvider)blockEntity).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
player.awardStat(Stats.INTERACT_WITH_SMOKER);
}
}

View File

@@ -0,0 +1,13 @@
--- a/net/minecraft/world/level/block/StonecutterBlock.java
+++ b/net/minecraft/world/level/block/StonecutterBlock.java
@@ -48,8 +48,9 @@
@Override
protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
if (!world.isClientSide) {
- player.openMenu(state.getMenuProvider(world, pos));
+ if (player.openMenu(state.getMenuProvider(world, pos)).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
player.awardStat(Stats.INTERACT_WITH_STONECUTTER);
+ } // Paper - Fix InventoryOpenEvent cancellation
}
return InteractionResult.SUCCESS;