Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@

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

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

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

public void decrementOpeners(LivingEntity entity, Level level, BlockPos pos, BlockState state) {
+ int oldPower = Math.max(0, Math.min(15, this.openCount)); // CraftBukkit - Get power before new viewer is added
+ if (this.openCount == 0) return; // Paper - Prevent ContainerOpenersCounter openCount from going negative
int i = this.openCount--;
+ if (level == null) return; // Don't broadcast events for fake block entities
+
+ // CraftBukkit start - Call redstone event
+ if (level.getBlockState(pos).is(net.minecraft.world.level.block.Blocks.TRAPPED_CHEST)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@
}

@Override
@@ -145,7 +_,7 @@
void onBookItemRemove() {
this.page = 0;
this.pageCount = 0;
- LecternBlock.resetBookState(null, this.getLevel(), this.getBlockPos(), this.getBlockState(), false);
+ if (this.level != null) LecternBlock.resetBookState(null, this.getLevel(), this.getBlockPos(), this.getBlockState(), false); // Paper - don't broadcast for fake BLockEntity
}

public void setBook(ItemStack stack, @Nullable Player player) {
@@ -160,7 +_,7 @@
if (i != this.page) {
this.page = i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@
}

this.openCount++;
+ if (this.opened) return; // CraftBukkit - only animate if the ShulkerBox hasn't been forced open already by an API call
+ 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
this.level.blockEvent(this.worldPosition, this.getBlockState().getBlock(), 1, this.openCount);
if (this.openCount == 1) {
this.level.gameEvent(user.getLivingEntity(), GameEvent.CONTAINER_OPEN, this.worldPosition);
@@ -184,6 +_,7 @@
public void stopOpen(ContainerUser user) {
if (!this.remove && !user.getLivingEntity().isSpectator()) {
this.openCount--;
+ if (this.opened) return; // CraftBukkit - only animate if the ShulkerBox hasn't been forced open already by an API call.
+ 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
this.level.blockEvent(this.worldPosition, this.getBlockState().getBlock(), 1, this.openCount);
if (this.openCount <= 0) {
this.level.gameEvent(user.getLivingEntity(), GameEvent.CONTAINER_CLOSE, this.worldPosition);
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,9 @@ protected AbstractContainerMenu buildContainer(final ServerPlayer player) {
private AbstractContainerMenu buildFakeBlockEntity(final ServerPlayer player) {
final MenuProvider inventory = this.builder.build(this.position, this.block.defaultBlockState());
if (inventory instanceof final BlockEntity blockEntity) {
blockEntity.setLevel(this.world);
super.defaultTitle = inventory.getDisplayName();
}

if (!this.useFakeBlockEntity) { // gets around open noise for chest
return handle.create(player.nextContainerCounter(), player.getInventory());
}

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

Expand Down
Loading