From ad71e20d528341e9abbb53804dafa228f4cdcf2a Mon Sep 17 00:00:00 2001 From: MrHell228 Date: Wed, 5 Jun 2024 01:19:05 +0300 Subject: [PATCH 1/4] Add BlockEntity tick methods --- SpongeAPI | 2 +- .../common/event/tracking/TrackingUtil.java | 3 ++ .../block/entity/BlockEntityMixin_API.java | 33 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/SpongeAPI b/SpongeAPI index 289329afbd9..54ec5946b7a 160000 --- a/SpongeAPI +++ b/SpongeAPI @@ -1 +1 @@ -Subproject commit 289329afbd94666c5ee2fcf2127e2a58c6d84767 +Subproject commit 54ec5946b7a3e57188b7dfe68292a05731a34e58 diff --git a/src/main/java/org/spongepowered/common/event/tracking/TrackingUtil.java b/src/main/java/org/spongepowered/common/event/tracking/TrackingUtil.java index be7eb9e437f..c005fd920f5 100644 --- a/src/main/java/org/spongepowered/common/event/tracking/TrackingUtil.java +++ b/src/main/java/org/spongepowered/common/event/tracking/TrackingUtil.java @@ -150,6 +150,9 @@ public static void tickTileEntity(final TrackedWorldBridge mixinWorldServer, fin return; } final net.minecraft.world.level.block.entity.BlockEntity blockEntity = tickingBlockEntity.get(); + if (!((org.spongepowered.api.block.entity.BlockEntity) blockEntity).isTicking()) { + return; + } final BlockEntityBridge mixinTileEntity = (BlockEntityBridge) tickingBlockEntity.get(); final BlockPos pos = blockEntity.getBlockPos(); final @Nullable LevelChunkBridge chunk = ((ActiveChunkReferantBridge) blockEntity).bridge$getActiveChunk(); diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/level/block/entity/BlockEntityMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/level/block/entity/BlockEntityMixin_API.java index e17fe5ef9a8..712f250987f 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/level/block/entity/BlockEntityMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/level/block/entity/BlockEntityMixin_API.java @@ -69,7 +69,12 @@ public abstract class BlockEntityMixin_API implements BlockEntity { //@formatter:on @Shadow @Final protected BlockPos worldPosition; + @Shadow private net.minecraft.world.level.block.state.BlockState blockState; + @Nullable private LocatableBlock api$LocatableBlock; + private boolean api$canTickRequested = false; + private boolean api$canTick; + private boolean api$isTicking = true; public ServerLocation location() { return ServerLocation.of((ServerWorld) this.level, VecHelper.toVector3i(this.shadow$getBlockPos())); @@ -143,6 +148,34 @@ public void remove() { } } + @Override + public boolean canTick() { + if (!this.api$canTickRequested) { + this.api$canTick = this.blockState.getTicker(this.level, this.type) != null; + this.api$canTickRequested = true; + } + + return api$canTick; + } + + @Override + public boolean isTicking() { + return !this.remove && this.canTick() && this.api$isTicking; + } + + @Override + public void setTicking(final boolean ticking) { + if (this.remove) { + throw new IllegalStateException("BlockEntity is removed"); + } + + if (!this.canTick()) { + throw new IllegalStateException("BlockEntity cannot tick"); + } + + this.api$isTicking = ticking; + } + @Override public final BlockEntityType type() { return (BlockEntityType) this.type; From 74038fc071233e061b3ab08108d06ad814f464c4 Mon Sep 17 00:00:00 2001 From: MrHell228 Date: Sat, 29 Jun 2024 01:46:20 +0300 Subject: [PATCH 2/4] Bump API --- SpongeAPI | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpongeAPI b/SpongeAPI index 54ec5946b7a..645af7daed9 160000 --- a/SpongeAPI +++ b/SpongeAPI @@ -1 +1 @@ -Subproject commit 54ec5946b7a3e57188b7dfe68292a05731a34e58 +Subproject commit 645af7daed9ca6d5e43b3572b084e384f383130f From e93a3409c6c98c85e3a0b4955acbd97e31503698 Mon Sep 17 00:00:00 2001 From: MrHell228 Date: Mon, 23 Sep 2024 19:28:15 +0300 Subject: [PATCH 3/4] Update verification-metadata.xml --- gradle/verification-metadata.xml | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 7a0e8d0074b..4af7b96a5e2 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -485,6 +485,14 @@ + + + + + + + + @@ -508,6 +516,11 @@ + + + + + @@ -587,6 +600,14 @@ + + + + + + + + @@ -665,6 +686,11 @@ + + + + + @@ -2255,6 +2281,14 @@ + + + + + + + + From 28ffa1085941c9b0198b640f455905b5395dc9df Mon Sep 17 00:00:00 2001 From: MrHell228 Date: Mon, 23 Sep 2024 19:49:56 +0300 Subject: [PATCH 4/4] Change BlockEntity#setTicking() --- SpongeAPI | 2 +- .../level/block/entity/BlockEntityMixin_API.java | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/SpongeAPI b/SpongeAPI index 645af7daed9..b016dd98de4 160000 --- a/SpongeAPI +++ b/SpongeAPI @@ -1 +1 @@ -Subproject commit 645af7daed9ca6d5e43b3572b084e384f383130f +Subproject commit b016dd98de4da1bce9a7e09864967d1a44a133f8 diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/level/block/entity/BlockEntityMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/level/block/entity/BlockEntityMixin_API.java index 712f250987f..c0b9d1a267a 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/level/block/entity/BlockEntityMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/level/block/entity/BlockEntityMixin_API.java @@ -164,16 +164,13 @@ public boolean isTicking() { } @Override - public void setTicking(final boolean ticking) { - if (this.remove) { - throw new IllegalStateException("BlockEntity is removed"); - } - - if (!this.canTick()) { - throw new IllegalStateException("BlockEntity cannot tick"); + public boolean setTicking(final boolean ticking) { + if (this.isRemoved() || !this.canTick()) { + return false; } this.api$isTicking = ticking; + return true; } @Override