Added __on_chunk_unloaded scarpet event (#1451)

* Fixes #1403

* Use concrete type
This commit is contained in:
Luca Bertozzi authored and GitHub committed 2022-05-27 20:24:25 +02:00
1 parent d088ee477e
commit 8c7dfa133e
3 files changed
+27

No files matched your search

@@ -26,6 +26,8 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import static carpet.script.CarpetEventServer.Event.EXPLOSION;
import static carpet.script.CarpetEventServer.Event.LIGHTNING;
import static carpet.script.CarpetEventServer.Event.CHUNK_UNLOADED;
@Mixin(ServerLevel.class)
public class ServerLevel_scarpetMixin implements ServerWorldInterface
@@ -50,6 +52,16 @@ public class ServerLevel_scarpetMixin implements ServerWorldInterface
EXPLOSION.onExplosion((ServerLevel) (Object)this, entity, null, d, e, f, g, bl, null, null, destructionType);
}
@Inject(method = "unload", at = @At("HEAD"))
private void handleChunkUnload(LevelChunk levelChunk, CallbackInfo ci)
{
if (CHUNK_UNLOADED.isNeeded())
{
ServerLevel level = (ServerLevel)((Object)this);
CHUNK_UNLOADED.onChunkEvent(level, levelChunk.getPos(), false);
}
}
@Final
@Shadow
private ServerLevelData serverLevelData;
@@ -467,6 +467,18 @@ public class CarpetEventServer
}
};
public static final Event CHUNK_UNLOADED = new Event("chunk_unloaded", 2, true)
{
@Override
public void onChunkEvent(ServerLevel world, ChunkPos chPos, boolean generated)
{
handler.call(
() -> Arrays.asList(new NumericValue(chPos.x << 4), new NumericValue(chPos.z << 4)),
() -> CarpetServer.minecraft_server.createCommandSourceStack().withLevel(world)
);
}
};
public static final Event PLAYER_JUMPS = new Event("player_jumps", 1, false)
{
@Override