Skip to content

Commit

Permalink
Update to SpongeAPI 12
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeregorix committed Oct 22, 2024
1 parent 311bb21 commit b77bcef
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 40 deletions.
26 changes: 18 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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'
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,5 @@

public interface InternalStructureResolver {

void resolveBlocksToRefresh();

Set<BlockPos> getBlocksToRefresh();
Set<BlockPos> resolveBlocksToRefresh();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlockPos> 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) {
Expand All @@ -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<Boolean> 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<Boolean> 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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@

@Mixin(PistonStructureResolver.class)
public abstract class PistonStructureResolverMixin implements InternalStructureResolver {
private final Set<BlockPos> toRefresh = new HashSet<>();
@Final
@Shadow
private Level level;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -144,8 +142,8 @@ private void resolveVanilla() {
public abstract boolean resolve();

@Override
public void resolveBlocksToRefresh() {
this.toRefresh.clear();
public Set<BlockPos> resolveBlocksToRefresh() {
Set<BlockPos> toRefresh = new HashSet<>();

// Backup custom blocks
List<BlockPos> toPushCustom = this.toPush;
Expand All @@ -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<BlockPos> getBlocksToRefresh() {
return this.toRefresh;
return toRefresh;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/sponge_plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"dependencies": [
{
"id": "spongeapi",
"version": "11.0.0",
"version": "12.0.0",
"load-order": "AFTER",
"optional": false
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/mixins.superpiston.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit b77bcef

Please sign in to comment.