From b77bcef080ab0c3e311aff52acd05cca4526dc89 Mon Sep 17 00:00:00 2001 From: Yeregorix Date: Tue, 22 Oct 2024 17:41:39 +0200 Subject: [PATCH] Update to SpongeAPI 12 --- build.gradle | 26 ++++++++++++------ .../internal/InternalStructureResolver.java | 4 +-- .../mixin/block/PistonBaseBlockMixin.java | 23 +++++++++------- .../block/PistonStructureResolverMixin.java | 27 +++++++------------ .../resources/META-INF/sponge_plugins.json | 2 +- src/main/resources/mixins.superpiston.json | 4 +-- 6 files changed, 46 insertions(+), 40 deletions(-) diff --git a/build.gradle b/build.gradle index f1bc50d..d5fd3bb 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id 'java-library' - id 'io.github.goooler.shadow' version '8.1.7' + id 'com.gradleup.shadow' version '8.3.3' id 'org.spongepowered.gradle.vanilla' version '0.2.1-SNAPSHOT' id 'com.diffplug.spotless' version '6.25.0' } @@ -24,24 +24,26 @@ repositories { configurations { spongevanilla spongeforge + spongeneo } minecraft { - version '1.20.6' + version '1.21.1' } dependencies { - api 'org.spongepowered:spongeapi:11.0.0' + api 'org.spongepowered:spongeapi:12.0.0' - implementation 'org.spongepowered:sponge:1.20.6-11.0.0:dev' - implementation 'org.spongepowered:mixin:0.8.6' + implementation 'org.spongepowered:sponge:1.21.1-12.0.0-SNAPSHOT:dev' + implementation 'org.spongepowered:mixin:0.8.7' implementation 'org.ow2.asm:asm-util:9.7' - implementation 'net.smoofyuniverse:oreupdater:1.3.1' + implementation 'net.smoofyuniverse:oreupdater:1.4.0' implementation 'net.smoofyuniverse:worldmap:1.3.0' - spongevanilla('org.spongepowered:spongevanilla:1.20.6-11.0.0:universal') { transitive = false } - spongeforge('org.spongepowered:spongeforge:1.20.6-50.0.22-11.0.0:universal') { transitive = false } + spongevanilla('org.spongepowered:spongevanilla:1.21.1-12.0.0-RC1856:universal') { transitive = false } + spongeforge('org.spongepowered:spongeforge:1.21.1-52.0.3-12.0.0-RC1856:universal') { transitive = false } + spongeneo('org.spongepowered:spongeneo:1.21.1-21.1.35-12.0.0-RC1856:universal') { transitive = false } } jar { @@ -89,6 +91,14 @@ tasks.register('setupForgeServer', Copy) { from shadowJar } +tasks.register('setupNeoServer', Copy) { + into 'run/neoforge/mods' + + from configurations.spongeneo + rename('spongeneo-(.*).jar', 'spongeneo.jar') + + from shadowJar +} spotless { ratchetFrom 'origin/master' diff --git a/src/main/java/net/smoofyuniverse/superpiston/impl/internal/InternalStructureResolver.java b/src/main/java/net/smoofyuniverse/superpiston/impl/internal/InternalStructureResolver.java index 1d5c380..807be44 100644 --- a/src/main/java/net/smoofyuniverse/superpiston/impl/internal/InternalStructureResolver.java +++ b/src/main/java/net/smoofyuniverse/superpiston/impl/internal/InternalStructureResolver.java @@ -28,7 +28,5 @@ public interface InternalStructureResolver { - void resolveBlocksToRefresh(); - - Set getBlocksToRefresh(); + Set resolveBlocksToRefresh(); } diff --git a/src/main/java/net/smoofyuniverse/superpiston/mixin/block/PistonBaseBlockMixin.java b/src/main/java/net/smoofyuniverse/superpiston/mixin/block/PistonBaseBlockMixin.java index 8d655d8..a9276e2 100644 --- a/src/main/java/net/smoofyuniverse/superpiston/mixin/block/PistonBaseBlockMixin.java +++ b/src/main/java/net/smoofyuniverse/superpiston/mixin/block/PistonBaseBlockMixin.java @@ -37,10 +37,12 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import java.util.Set; @Mixin(PistonBaseBlock.class) public abstract class PistonBaseBlockMixin { + private Set blocksToRefresh; @Redirect(method = "triggerEvent", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;getPistonPushReaction()Lnet/minecraft/world/level/material/PushReaction;")) public PushReaction alwaysPushNormal(BlockState stateIn, BlockState state, Level level, BlockPos pos, int id, int param) { @@ -55,19 +57,22 @@ public boolean alwaysPushable(BlockState state, Level level, BlockPos pos, Direc @Redirect(method = "moveBlocks", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/piston/PistonStructureResolver;resolve()Z")) public boolean onMoveResolve(PistonStructureResolver resolver) { if (resolver.resolve()) { - ((InternalStructureResolver) resolver).resolveBlocksToRefresh(); + this.blocksToRefresh = ((InternalStructureResolver) resolver).resolveBlocksToRefresh(); return true; } return false; } - @Inject(method = "moveBlocks", at = @At(value = "RETURN"), locals = LocalCapture.CAPTURE_FAILHARD) - public void onMoveEnd(Level level, BlockPos piston, Direction facing, boolean extending, - CallbackInfoReturnable cir, BlockPos head, PistonStructureResolver resolver) { - if (level instanceof ServerLevel) { - ServerChunkCache cache = ((ServerLevel) level).getChunkSource(); - for (BlockPos pos : ((InternalStructureResolver) resolver).getBlocksToRefresh()) - cache.blockChanged(pos); + @Inject(method = "moveBlocks", at = @At("RETURN")) + public void onMoveEnd(Level level, BlockPos piston, Direction facing, boolean extending, CallbackInfoReturnable cir) { + if (this.blocksToRefresh != null) { + if (level instanceof ServerLevel) { + ServerChunkCache cache = ((ServerLevel) level).getChunkSource(); + for (BlockPos pos : this.blocksToRefresh) { + cache.blockChanged(pos); + } + } + this.blocksToRefresh = null; } } } diff --git a/src/main/java/net/smoofyuniverse/superpiston/mixin/block/PistonStructureResolverMixin.java b/src/main/java/net/smoofyuniverse/superpiston/mixin/block/PistonStructureResolverMixin.java index a44928b..cfe73fc 100644 --- a/src/main/java/net/smoofyuniverse/superpiston/mixin/block/PistonStructureResolverMixin.java +++ b/src/main/java/net/smoofyuniverse/superpiston/mixin/block/PistonStructureResolverMixin.java @@ -56,7 +56,6 @@ @Mixin(PistonStructureResolver.class) public abstract class PistonStructureResolverMixin implements InternalStructureResolver { - private final Set toRefresh = new HashSet<>(); @Final @Shadow private Level level; @@ -92,7 +91,6 @@ public void onInit(Level level, BlockPos pos, net.minecraft.core.Direction pisto private boolean resolveCustom() { this.toPush.clear(); this.toDestroy.clear(); - this.toRefresh.clear(); Cause cause = Sponge.server().causeStackManager().currentCause(); @@ -144,8 +142,8 @@ private void resolveVanilla() { public abstract boolean resolve(); @Override - public void resolveBlocksToRefresh() { - this.toRefresh.clear(); + public Set resolveBlocksToRefresh() { + Set toRefresh = new HashSet<>(); // Backup custom blocks List toPushCustom = this.toPush; @@ -154,31 +152,26 @@ public void resolveBlocksToRefresh() { this.toDestroy = new ArrayList<>(); // Resolve vanilla blocks - this.resolveCustom = false; - resolve(); - this.resolveCustom = true; + resolveVanilla(); // Difference between blocks updated by the client and blocks updated by the server for (BlockPos pos : this.toPush) { - this.toRefresh.add(pos); - this.toRefresh.add(pos.relative(this.pushDirection)); + toRefresh.add(pos); + toRefresh.add(pos.relative(this.pushDirection)); } - this.toRefresh.addAll(this.toDestroy); + toRefresh.addAll(this.toDestroy); for (BlockPos pos : toPushCustom) { - this.toRefresh.remove(pos); - this.toRefresh.remove(pos.relative(this.pushDirection)); + toRefresh.remove(pos); + toRefresh.remove(pos.relative(this.pushDirection)); } for (BlockPos pos : toDestroyCustom) { - this.toRefresh.remove(pos); + toRefresh.remove(pos); } // Restore custom blocks this.toPush = toPushCustom; this.toDestroy = toDestroyCustom; - } - @Override - public Set getBlocksToRefresh() { - return this.toRefresh; + return toRefresh; } } diff --git a/src/main/resources/META-INF/sponge_plugins.json b/src/main/resources/META-INF/sponge_plugins.json index 9dad711..e8e5f10 100644 --- a/src/main/resources/META-INF/sponge_plugins.json +++ b/src/main/resources/META-INF/sponge_plugins.json @@ -25,7 +25,7 @@ "dependencies": [ { "id": "spongeapi", - "version": "11.0.0", + "version": "12.0.0", "load-order": "AFTER", "optional": false } diff --git a/src/main/resources/mixins.superpiston.json b/src/main/resources/mixins.superpiston.json index 6f2ebf7..ad74bac 100644 --- a/src/main/resources/mixins.superpiston.json +++ b/src/main/resources/mixins.superpiston.json @@ -1,9 +1,9 @@ { "required": true, - "minVersion": "0.8", + "minVersion": "0.8.7", "package": "net.smoofyuniverse.superpiston.mixin", "target": "@env(DEFAULT)", - "compatibilityLevel": "JAVA_8", + "compatibilityLevel": "JAVA_21", "server": [ "block.PistonBaseBlockMixin", "block.PistonStructureResolverMixin"