From c4f8c865205b4f80a2d3eed5647841779e95bc8f Mon Sep 17 00:00:00 2001 From: gnembon <41132274+gnembon@users.noreply.github.com> Date: Wed, 15 May 2024 23:13:40 +0200 Subject: [PATCH] 24w20a, disable reset_chunk, relight, and chunk load events --- gradle.properties | 2 +- .../carpet/fakes/ChunkHolderInterface.java | 2 +- .../ThreadedAnvilChunkStorageInterface.java | 8 ++--- .../carpet/mixins/AbstractArrowMixin.java | 4 +-- ...ChunkHolder_scarpetChunkCreationMixin.java | 6 ++-- .../ChunkMap_scarpetChunkCreationMixin.java | 33 +++++++++++++------ .../LevelRenderer_scarpetRenderMixin.java | 5 +-- .../mixins/PlayerList_scarpetEventsMixin.java | 7 ++-- .../ServerPlayer_scarpetEventMixin.java | 7 ++-- .../carpet/patches/EntityPlayerMPFake.java | 2 +- .../java/carpet/script/api/Auxiliary.java | 4 +++ .../java/carpet/script/api/WorldAccess.java | 8 +++-- .../java/carpet/script/external/Vanilla.java | 4 +-- 13 files changed, 60 insertions(+), 32 deletions(-) diff --git a/gradle.properties b/gradle.properties index 9217f178..93d392c7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check https://fabricmc.net/develop/ - minecraft_version=24w18a + minecraft_version=24w20a loader_version=0.15.11 jsr305_version=3.0.2 fabric_version=0.97.8+1.20.6 diff --git a/src/main/java/carpet/fakes/ChunkHolderInterface.java b/src/main/java/carpet/fakes/ChunkHolderInterface.java index d0c633b9..6c5464ac 100644 --- a/src/main/java/carpet/fakes/ChunkHolderInterface.java +++ b/src/main/java/carpet/fakes/ChunkHolderInterface.java @@ -9,5 +9,5 @@ import net.minecraft.world.level.chunk.ChunkAccess; public interface ChunkHolderInterface { - CompletableFuture> setDefaultProtoChunk(ChunkPos chpos, BlockableEventLoop executor, ServerLevel world); + //CompletableFuture> setDefaultProtoChunk(ChunkPos chpos, BlockableEventLoop executor, ServerLevel world); } diff --git a/src/main/java/carpet/fakes/ThreadedAnvilChunkStorageInterface.java b/src/main/java/carpet/fakes/ThreadedAnvilChunkStorageInterface.java index fd1fa762..a46c128e 100644 --- a/src/main/java/carpet/fakes/ThreadedAnvilChunkStorageInterface.java +++ b/src/main/java/carpet/fakes/ThreadedAnvilChunkStorageInterface.java @@ -7,11 +7,11 @@ import net.minecraft.world.level.ChunkPos; public interface ThreadedAnvilChunkStorageInterface { - Map regenerateChunkRegion(List requestedChunks); + //Map regenerateChunkRegion(List requestedChunks); - void relightChunk(ChunkPos pos); + //void relightChunk(ChunkPos pos); - void releaseRelightTicket(ChunkPos pos); + //void releaseRelightTicket(ChunkPos pos); - Iterable getChunksCM(); + //Iterable getChunksCM(); } diff --git a/src/main/java/carpet/mixins/AbstractArrowMixin.java b/src/main/java/carpet/mixins/AbstractArrowMixin.java index bf324297..e3008597 100644 --- a/src/main/java/carpet/mixins/AbstractArrowMixin.java +++ b/src/main/java/carpet/mixins/AbstractArrowMixin.java @@ -20,8 +20,8 @@ public abstract class AbstractArrowMixin extends Entity private TrajectoryLogHelper logHelper; public AbstractArrowMixin(EntityType entityType_1, Level world_1) { super(entityType_1, world_1); } - @Inject(method = "(Lnet/minecraft/world/entity/EntityType;Lnet/minecraft/world/level/Level;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/item/ItemStack;)V", at = @At("RETURN")) - private void addLogger(final EntityType entityType, final Level level, final ItemStack itemStack, final ItemStack weapon, final CallbackInfo ci) + @Inject(method = "(Lnet/minecraft/world/entity/EntityType;DDDLnet/minecraft/world/level/Level;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/item/ItemStack;)V", at = @At("RETURN")) + private void addLogger(final EntityType entityType, final double x, final double y, final double z, final Level level, final ItemStack itemStack, final ItemStack weapon, final CallbackInfo ci) { if (LoggerRegistry.__projectiles && !level.isClientSide) logHelper = new TrajectoryLogHelper("projectiles"); diff --git a/src/main/java/carpet/mixins/ChunkHolder_scarpetChunkCreationMixin.java b/src/main/java/carpet/mixins/ChunkHolder_scarpetChunkCreationMixin.java index da82d0dd..1727b83e 100644 --- a/src/main/java/carpet/mixins/ChunkHolder_scarpetChunkCreationMixin.java +++ b/src/main/java/carpet/mixins/ChunkHolder_scarpetChunkCreationMixin.java @@ -21,10 +21,11 @@ import net.minecraft.world.level.chunk.UpgradeData; @Mixin(ChunkHolder.class) public abstract class ChunkHolder_scarpetChunkCreationMixin implements ChunkHolderInterface { - @Shadow protected abstract void updateChunkToSave(CompletableFuture> newChunkFuture, String type); + //@Shadow protected abstract void updateChunkToSave(CompletableFuture> newChunkFuture, String type); - @Shadow @Final private AtomicReferenceArray>> futures; + //@Shadow @Final private AtomicReferenceArray>> futures; + /* @Override public CompletableFuture> setDefaultProtoChunk(ChunkPos chpos, BlockableEventLoop executor, ServerLevel world) { @@ -37,4 +38,5 @@ public abstract class ChunkHolder_scarpetChunkCreationMixin implements ChunkHold futures.set(i, completableFuture2); return completableFuture2; } + */ } diff --git a/src/main/java/carpet/mixins/ChunkMap_scarpetChunkCreationMixin.java b/src/main/java/carpet/mixins/ChunkMap_scarpetChunkCreationMixin.java index ff7e9a3d..fc300dbb 100644 --- a/src/main/java/carpet/mixins/ChunkMap_scarpetChunkCreationMixin.java +++ b/src/main/java/carpet/mixins/ChunkMap_scarpetChunkCreationMixin.java @@ -19,6 +19,7 @@ import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.server.MinecraftServer; import net.minecraft.server.TickTask; import net.minecraft.server.level.ChunkHolder; +import net.minecraft.server.level.ChunkLevel; import net.minecraft.server.level.ChunkMap; import net.minecraft.server.level.ChunkMap.DistanceManager; import net.minecraft.server.level.ChunkResult; @@ -64,10 +65,6 @@ public abstract class ChunkMap_scarpetChunkCreationMixin implements ThreadedAnvi @Final private ServerLevel level; - @Shadow - @Final - private LongSet entitiesInLevel; - @Shadow @Final private Long2ObjectLinkedOpenHashMap updatingChunkMap; @@ -111,6 +108,10 @@ public abstract class ChunkMap_scarpetChunkCreationMixin implements ThreadedAnvi // in protoChunkToFullChunk // fancier version of the one below, ensuring that the event is triggered when the chunk is actually loaded. + + /* + + @Inject(method = "method_17227", at = @At("HEAD"), remap = false) private void onChunkGeneratedStart(ChunkHolder chunkHolder, ChunkAccess chunkAccess, CallbackInfoReturnable cir) { @@ -146,6 +147,8 @@ public abstract class ChunkMap_scarpetChunkCreationMixin implements ThreadedAnvi } } + */ + /* simple but a version that doesn't guarantee that the chunk is actually loaded @Inject(method = "convertToFullChunk", at = @At("HEAD")) private void onChunkGeneratedEnd(ChunkHolder chunkHolder, CallbackInfoReturnable>> cir) @@ -167,7 +170,7 @@ public abstract class ChunkMap_scarpetChunkCreationMixin implements ThreadedAnvi @Unique private void addTicket(ChunkPos pos, ChunkStatus status) { // UNKNOWN - this.distanceManager.addTicket(TicketType.UNKNOWN, pos, 33 + ChunkStatus.getDistance(status), pos); + this.distanceManager.addTicket(TicketType.UNKNOWN, pos, 33 + ChunkLevel.byStatus(status), pos); } @Unique @@ -176,6 +179,8 @@ public abstract class ChunkMap_scarpetChunkCreationMixin implements ThreadedAnvi this.addTicket(pos, ChunkStatus.EMPTY); } + + /* @Unique private void addRelightTicket(ChunkPos pos) { @@ -190,7 +195,7 @@ public abstract class ChunkMap_scarpetChunkCreationMixin implements ThreadedAnvi () -> "release relight ticket " + pos )); } - + */ @Unique private void tickTicketManager() { @@ -214,6 +219,8 @@ public abstract class ChunkMap_scarpetChunkCreationMixin implements ThreadedAnvi return ret; } + + /* @Unique private Set loadExistingChunksFromDisk(Set requestedChunks) { @@ -329,6 +336,8 @@ public abstract class ChunkMap_scarpetChunkCreationMixin implements ThreadedAnvi this.waitFor(lightFuture); } + /* + @Override public Map regenerateChunkRegion(List requestedChunksList) { @@ -385,7 +394,7 @@ public abstract class ChunkMap_scarpetChunkCreationMixin implements ThreadedAnvi { ChunkAccess chunk = this.getCurrentChunk(pos); - if (chunk.getStatus().isOrAfter(ChunkStatus.LIGHT.getParent())) + if (chunk.getPersistedStatus().isOrAfter(ChunkStatus.LIGHT.getParent())) { affectedNeighbors.add(chunk); } @@ -399,7 +408,7 @@ public abstract class ChunkMap_scarpetChunkCreationMixin implements ThreadedAnvi // remove entities long longPos = pos.toLong(); - if (this.entitiesInLevel.contains(longPos) && chunk instanceof LevelChunk) + if (chunk instanceof LevelChunk) { ((SimpleEntityLookupInterface) ((ServerWorldInterface) level).getEntityLookupCMPublic()).getChunkEntities(pos).forEach(entity -> { if (!(entity instanceof Player)) @@ -415,7 +424,7 @@ public abstract class ChunkMap_scarpetChunkCreationMixin implements ThreadedAnvi ((LevelChunk) chunk).setLoaded(false); } - if (this.entitiesInLevel.remove(pos.toLong()) && chunk instanceof LevelChunk) + if (chunk instanceof LevelChunk) { this.level.unload((LevelChunk) chunk); // block entities only } @@ -450,7 +459,7 @@ public abstract class ChunkMap_scarpetChunkCreationMixin implements ThreadedAnvi // Also, this is needed to ensure chunks are saved to disk Map targetGenerationStatus = affectedChunks.stream().collect( - Collectors.toMap(ChunkAccess::getPos, ChunkAccess::getStatus) + Collectors.toMap(ChunkAccess::getPos, ChunkAccess::getPersistedStatus) ); for (Entry entry : targetGenerationStatus.entrySet()) @@ -548,9 +557,13 @@ public abstract class ChunkMap_scarpetChunkCreationMixin implements ThreadedAnvi return report; } + + @Override public Iterable getChunksCM() { return getChunks(); } + + */ } diff --git a/src/main/java/carpet/mixins/LevelRenderer_scarpetRenderMixin.java b/src/main/java/carpet/mixins/LevelRenderer_scarpetRenderMixin.java index 67119c30..f2a71f2b 100644 --- a/src/main/java/carpet/mixins/LevelRenderer_scarpetRenderMixin.java +++ b/src/main/java/carpet/mixins/LevelRenderer_scarpetRenderMixin.java @@ -4,6 +4,7 @@ import carpet.network.CarpetClient; import carpet.script.utils.ShapesRenderer; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Camera; +import net.minecraft.client.DeltaTracker; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.LevelRenderer; @@ -36,14 +37,14 @@ public class LevelRenderer_scarpetRenderMixin //target = "Lnet/minecraft/client/render/BufferBuilderStorage;getEntityVertexConsumers()Lnet/minecraft/client/render/VertexConsumerProvider$Immediate;", shift = At.Shift.AFTER //target = "Lnet/minecraft/client/render/WorldRenderer;renderChunkDebugInfo(Lnet/minecraft/client/render/Camera;)V", shift = At.Shift.AFTER // before return )) - private void renderScarpetThings(float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightmapTextureManager, Matrix4f modelViewMatrix, Matrix4f matrix4f, CallbackInfo ci) + private void renderScarpetThings(final DeltaTracker deltaTracker, final boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightmapTextureManager, Matrix4f modelViewMatrix, Matrix4f matrix4f, CallbackInfo ci) { // in normal circumstances we want to render shapes at the very end so it appears correctly behind stuff. // we might actually not need to play with render hooks here. //if (!FabricAPIHooks.WORLD_RENDER_EVENTS && CarpetClient.shapes != null ) if (CarpetClient.shapes != null) { - CarpetClient.shapes.render(modelViewMatrix, camera, tickDelta); + CarpetClient.shapes.render(modelViewMatrix, camera, deltaTracker.getGameTimeDeltaPartialTick(false)); } } } diff --git a/src/main/java/carpet/mixins/PlayerList_scarpetEventsMixin.java b/src/main/java/carpet/mixins/PlayerList_scarpetEventsMixin.java index 06192215..8178a76a 100644 --- a/src/main/java/carpet/mixins/PlayerList_scarpetEventsMixin.java +++ b/src/main/java/carpet/mixins/PlayerList_scarpetEventsMixin.java @@ -7,6 +7,7 @@ import net.minecraft.network.chat.PlayerChatMessage; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.players.PlayerList; +import net.minecraft.world.entity.Entity; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -24,9 +25,9 @@ public class PlayerList_scarpetEventsMixin @Shadow @Final private MinecraftServer server; @Inject(method = "respawn", at = @At("HEAD")) - private void onRespawn(ServerPlayer player, boolean olive, CallbackInfoReturnable cir) + private void onResp(ServerPlayer serverPlayer, boolean olive, Entity.RemovalReason removalReason, CallbackInfoReturnable cir) { - PLAYER_RESPAWNS.onPlayerEvent(player); + PLAYER_RESPAWNS.onPlayerEvent(serverPlayer); } @Inject(method = "broadcastChatMessage(Lnet/minecraft/network/chat/PlayerChatMessage;Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/network/chat/ChatType$Bound;)V", @@ -44,7 +45,7 @@ public class PlayerList_scarpetEventsMixin value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;initInventoryMenu()V" )) - private void invalidatePreviousInstance(ServerPlayer player, boolean alive, CallbackInfoReturnable cir) + private void invalidatePreviousInstance(ServerPlayer player, boolean alive, Entity.RemovalReason removalReason, CallbackInfoReturnable cir) { ((ServerPlayerInterface)player).invalidateEntityObjectReference(); } diff --git a/src/main/java/carpet/mixins/ServerPlayer_scarpetEventMixin.java b/src/main/java/carpet/mixins/ServerPlayer_scarpetEventMixin.java index afba6cde..1c04d02d 100644 --- a/src/main/java/carpet/mixins/ServerPlayer_scarpetEventMixin.java +++ b/src/main/java/carpet/mixins/ServerPlayer_scarpetEventMixin.java @@ -14,6 +14,7 @@ import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; +import net.minecraft.world.level.portal.DimensionTransition; import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -96,18 +97,20 @@ public abstract class ServerPlayer_scarpetEventMixin extends Player implements S private ResourceKey previousDimension; @Inject(method = "changeDimension", at = @At("HEAD")) - private void logPreviousCoordinates(ServerLevel serverWorld, CallbackInfoReturnable cir) + private void logPreviousCoordinates(DimensionTransitionSupplier serverWorld, CallbackInfoReturnable cir) { previousLocation = position(); previousDimension = level().dimension(); //dimension type } @Inject(method = "changeDimension", at = @At("RETURN")) - private void atChangeDimension(ServerLevel destination, CallbackInfoReturnable cir) + private void atChangeDimension(DimensionTransitionSupplier destinationP, CallbackInfoReturnable cir) { if (PLAYER_CHANGES_DIMENSION.isNeeded()) { ServerPlayer player = (ServerPlayer) (Object)this; + DimensionTransition destinationTransition = destinationP.get(); + ServerLevel destination = destinationTransition.newDimension(); Vec3 to = null; if (!wonGame || previousDimension != Level.END || destination.dimension() != Level.OVERWORLD) { diff --git a/src/main/java/carpet/patches/EntityPlayerMPFake.java b/src/main/java/carpet/patches/EntityPlayerMPFake.java index 563d1a3a..55fb5633 100644 --- a/src/main/java/carpet/patches/EntityPlayerMPFake.java +++ b/src/main/java/carpet/patches/EntityPlayerMPFake.java @@ -213,7 +213,7 @@ public class EntityPlayerMPFake extends ServerPlayer } @Override - public Entity changeDimension(ServerLevel serverLevel) + public Entity changeDimension(DimensionTransitionSupplier serverLevel) { super.changeDimension(serverLevel); if (wonGame) { diff --git a/src/main/java/carpet/script/api/Auxiliary.java b/src/main/java/carpet/script/api/Auxiliary.java index 8d917113..ca3c22b4 100644 --- a/src/main/java/carpet/script/api/Auxiliary.java +++ b/src/main/java/carpet/script/api/Auxiliary.java @@ -804,6 +804,8 @@ public class Auxiliary expression.addContextFunction("relight", -1, (c, t, lv) -> { + return Value.NULL; + /* CarpetContext cc = (CarpetContext) c; BlockArgument locator = BlockArgument.findIn(cc, lv, 0); BlockPos pos = locator.block.getPos(); @@ -811,6 +813,8 @@ public class Auxiliary Vanilla.ChunkMap_relightChunk(world.getChunkSource().chunkMap, new ChunkPos(pos)); WorldTools.forceChunkUpdate(pos, world); return Value.TRUE; + + */ }); // Should this be deprecated for system_info('source_dimension')? diff --git a/src/main/java/carpet/script/api/WorldAccess.java b/src/main/java/carpet/script/api/WorldAccess.java index 8fb2c09b..ae60ed0d 100644 --- a/src/main/java/carpet/script/api/WorldAccess.java +++ b/src/main/java/carpet/script/api/WorldAccess.java @@ -637,7 +637,7 @@ public class WorldAccess forceLoad = lv.get(blockArgument.offset).getBoolean(); } ChunkAccess chunk = ((CarpetContext) c).level().getChunk(pos.getX() >> 4, pos.getZ() >> 4, ChunkStatus.EMPTY, forceLoad); - return chunk == null ? Value.NULL : ValueConversions.of(BuiltInRegistries.CHUNK_STATUS.getKey(chunk.getStatus())); + return chunk == null ? Value.NULL : ValueConversions.of(BuiltInRegistries.CHUNK_STATUS.getKey(chunk.getPersistedStatus())); }); expression.addContextFunction("chunk_tickets", -1, (c, t, lv) -> @@ -921,7 +921,7 @@ public class WorldAccess damageAmount = 2; } final int finalDamageAmount = damageAmount; - tool.hurtAndBreak(damageAmount, world, null, () -> { if (finalDamageAmount > 0) toolBroke.setTrue(); } ); + tool.hurtAndBreak(damageAmount, world, null, (i) -> { if (finalDamageAmount > 0) toolBroke.setTrue(); } ); if (!isUsingEffectiveTool) { dropLoot = false; @@ -1586,6 +1586,8 @@ public class WorldAccess // todo maybe enable chunk blending? expression.addContextFunction("reset_chunk", -1, (c, t, lv) -> { + return Value.NULL; + /* CarpetContext cc = (CarpetContext) c; List requestedChunks = new ArrayList<>(); if (lv.size() == 1) @@ -1643,6 +1645,8 @@ public class WorldAccess ))); }); return result[0]; + + */ }); expression.addContextFunction("inhabited_time", -1, (c, t, lv) -> diff --git a/src/main/java/carpet/script/external/Vanilla.java b/src/main/java/carpet/script/external/Vanilla.java index 75ee9ab9..76d2508b 100644 --- a/src/main/java/carpet/script/external/Vanilla.java +++ b/src/main/java/carpet/script/external/Vanilla.java @@ -100,12 +100,12 @@ public class Vanilla public static void ChunkMap_relightChunk(ChunkMap chunkMap, ChunkPos pos) { - ((ThreadedAnvilChunkStorageInterface) chunkMap).relightChunk(pos); + //((ThreadedAnvilChunkStorageInterface) chunkMap).relightChunk(pos); } public static Map ChunkMap_regenerateChunkRegion(ChunkMap chunkMap, List requestedChunks) { - return ((ThreadedAnvilChunkStorageInterface) chunkMap).regenerateChunkRegion(requestedChunks); + return Map.of(); //return ((ThreadedAnvilChunkStorageInterface) chunkMap).regenerateChunkRegion(requestedChunks); } public static List> Ingredient_getRecipeStacks(Ingredient ingredient)