Skip to content

Commit 9b5dcec

Browse files
committed
Fake block entities should have no level
1 parent 5b84700 commit 9b5dcec

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

paper-server/patches/sources/net/minecraft/world/level/block/entity/ContainerOpenersCounter.java.patch

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121

2222
protected abstract void onOpen(Level level, BlockPos pos, BlockState state);
2323

24-
@@ -26,7 +_,19 @@
24+
@@ -26,7 +_,20 @@
2525
public abstract boolean isOwnContainer(Player player);
2626

2727
public void incrementOpeners(LivingEntity entity, Level level, BlockPos pos, BlockState state, double interactionRange) {
2828
+ int oldPower = Math.max(0, Math.min(15, this.openCount)); // CraftBukkit - Get power before new viewer is added
2929
int i = this.openCount++;
30+
+ if (level == null) return; // Don't broadcast events for fake block entities
3031
+
3132
+ // CraftBukkit start - Call redstone event
3233
+ if (level.getBlockState(pos).is(net.minecraft.world.level.block.Blocks.TRAPPED_CHEST)) {
@@ -41,13 +42,14 @@
4142
if (i == 0) {
4243
this.onOpen(level, pos, state);
4344
level.gameEvent(entity, GameEvent.CONTAINER_OPEN, pos);
44-
@@ -38,7 +_,20 @@
45+
@@ -38,7 +_,21 @@
4546
}
4647

4748
public void decrementOpeners(LivingEntity entity, Level level, BlockPos pos, BlockState state) {
4849
+ int oldPower = Math.max(0, Math.min(15, this.openCount)); // CraftBukkit - Get power before new viewer is added
4950
+ if (this.openCount == 0) return; // Paper - Prevent ContainerOpenersCounter openCount from going negative
5051
int i = this.openCount--;
52+
+ if (level == null) return; // Don't broadcast events for fake block entities
5153
+
5254
+ // CraftBukkit start - Call redstone event
5355
+ if (level.getBlockState(pos).is(net.minecraft.world.level.block.Blocks.TRAPPED_CHEST)) {

paper-server/patches/sources/net/minecraft/world/level/block/entity/LecternBlockEntity.java.patch

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@
7676
}
7777

7878
@Override
79+
@@ -145,7 +_,7 @@
80+
void onBookItemRemove() {
81+
this.page = 0;
82+
this.pageCount = 0;
83+
- LecternBlock.resetBookState(null, this.getLevel(), this.getBlockPos(), this.getBlockState(), false);
84+
+ if (this.level != null) LecternBlock.resetBookState(null, this.getLevel(), this.getBlockPos(), this.getBlockState(), false); // Paper - don't broadcast for fake BLockEntity
85+
}
86+
87+
public void setBook(ItemStack stack, @Nullable Player player) {
7988
@@ -160,7 +_,7 @@
8089
if (i != this.page) {
8190
this.page = i;

paper-server/patches/sources/net/minecraft/world/level/block/entity/ShulkerBoxBlockEntity.java.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@
4747
}
4848

4949
this.openCount++;
50-
+ if (this.opened) return; // CraftBukkit - only animate if the ShulkerBox hasn't been forced open already by an API call
50+
+ if (this.opened || level == null) return; // CraftBukkit - only animate if the ShulkerBox hasn't been forced open already by an API call. Ensure level is non null
5151
this.level.blockEvent(this.worldPosition, this.getBlockState().getBlock(), 1, this.openCount);
5252
if (this.openCount == 1) {
5353
this.level.gameEvent(user.getLivingEntity(), GameEvent.CONTAINER_OPEN, this.worldPosition);
5454
@@ -184,6 +_,7 @@
5555
public void stopOpen(ContainerUser user) {
5656
if (!this.remove && !user.getLivingEntity().isSpectator()) {
5757
this.openCount--;
58-
+ if (this.opened) return; // CraftBukkit - only animate if the ShulkerBox hasn't been forced open already by an API call.
58+
+ if (this.opened || level == null) return; // CraftBukkit - only animate if the ShulkerBox hasn't been forced open already by an API call. Ensure level is non null
5959
this.level.blockEvent(this.worldPosition, this.getBlockState().getBlock(), 1, this.openCount);
6060
if (this.openCount <= 0) {
6161
this.level.gameEvent(user.getLivingEntity(), GameEvent.CONTAINER_CLOSE, this.worldPosition);

paper-server/src/main/java/org/bukkit/craftbukkit/inventory/view/builder/CraftBlockEntityInventoryViewBuilder.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,12 @@ protected AbstractContainerMenu buildContainer(final ServerPlayer player) {
7171
private AbstractContainerMenu buildFakeBlockEntity(final ServerPlayer player) {
7272
final MenuProvider inventory = this.builder.build(this.position, this.block.defaultBlockState());
7373
if (inventory instanceof final BlockEntity blockEntity) {
74-
blockEntity.setLevel(this.world);
7574
super.defaultTitle = inventory.getDisplayName();
7675
}
7776

78-
if (!this.useFakeBlockEntity) { // gets around open noise for chest
79-
return handle.create(player.nextContainerCounter(), player.getInventory());
80-
}
77+
// if (!this.useFakeBlockEntity) { // gets around open noise for chest
78+
// return handle.create(player.nextContainerCounter(), player.getInventory());
79+
// }
8180

8281
return inventory.createMenu(player.nextContainerCounter(), player.getInventory(), player);
8382
}

0 commit comments

Comments
 (0)