Skip to content

Commit

Permalink
24w20a, disable reset_chunk, relight, and chunk load events
Browse files Browse the repository at this point in the history
  • Loading branch information
gnembon committed May 15, 2024
1 parent 9fd313a commit c4f8c86
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 32 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/carpet/fakes/ChunkHolderInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@

public interface ChunkHolderInterface
{
CompletableFuture<ChunkResult<ChunkAccess>> setDefaultProtoChunk(ChunkPos chpos, BlockableEventLoop<Runnable> executor, ServerLevel world);
//CompletableFuture<ChunkResult<ChunkAccess>> setDefaultProtoChunk(ChunkPos chpos, BlockableEventLoop<Runnable> executor, ServerLevel world);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

public interface ThreadedAnvilChunkStorageInterface
{
Map<String, Integer> regenerateChunkRegion(List<ChunkPos> requestedChunks);
//Map<String, Integer> regenerateChunkRegion(List<ChunkPos> requestedChunks);

void relightChunk(ChunkPos pos);
//void relightChunk(ChunkPos pos);

void releaseRelightTicket(ChunkPos pos);
//void releaseRelightTicket(ChunkPos pos);

Iterable<ChunkHolder> getChunksCM();
//Iterable<ChunkHolder> getChunksCM();
}
4 changes: 2 additions & 2 deletions src/main/java/carpet/mixins/AbstractArrowMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<init>(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 = "<init>(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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
@Mixin(ChunkHolder.class)
public abstract class ChunkHolder_scarpetChunkCreationMixin implements ChunkHolderInterface
{
@Shadow protected abstract void updateChunkToSave(CompletableFuture<? extends ChunkResult<? extends ChunkAccess>> newChunkFuture, String type);
//@Shadow protected abstract void updateChunkToSave(CompletableFuture<? extends ChunkResult<? extends ChunkAccess>> newChunkFuture, String type);

@Shadow @Final private AtomicReferenceArray<CompletableFuture<ChunkResult<ChunkAccess>>> futures;
//@Shadow @Final private AtomicReferenceArray<CompletableFuture<ChunkResult<ChunkAccess>>> futures;

/*
@Override
public CompletableFuture<ChunkResult<ChunkAccess>> setDefaultProtoChunk(ChunkPos chpos, BlockableEventLoop<Runnable> executor, ServerLevel world)
{
Expand All @@ -37,4 +38,5 @@ public CompletableFuture<ChunkResult<ChunkAccess>> setDefaultProtoChunk(ChunkPos
futures.set(i, completableFuture2);
return completableFuture2;
}
*/
}
33 changes: 23 additions & 10 deletions src/main/java/carpet/mixins/ChunkMap_scarpetChunkCreationMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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;
Expand Down Expand Up @@ -64,10 +65,6 @@ public abstract class ChunkMap_scarpetChunkCreationMixin implements ThreadedAnvi
@Final
private ServerLevel level;

@Shadow
@Final
private LongSet entitiesInLevel;

@Shadow
@Final
private Long2ObjectLinkedOpenHashMap<ChunkHolder> updatingChunkMap;
Expand Down Expand Up @@ -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<ChunkAccess> cir)
{
Expand Down Expand Up @@ -146,6 +147,8 @@ private void onChunkGeneratedEnd(ChunkHolder chunkHolder, ChunkAccess chunk, Cal
}
}
*/

/* 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<CompletableFuture<ChunkResult<ChunkAccess>>> cir)
Expand All @@ -167,7 +170,7 @@ private void onChunkGeneratedEnd(ChunkHolder chunkHolder, CallbackInfoReturnable
@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
Expand All @@ -176,6 +179,8 @@ private void addTicket(ChunkPos pos)
this.addTicket(pos, ChunkStatus.EMPTY);
}


/*
@Unique
private void addRelightTicket(ChunkPos pos)
{
Expand All @@ -190,7 +195,7 @@ public void releaseRelightTicket(ChunkPos pos)
() -> "release relight ticket " + pos
));
}

*/
@Unique
private void tickTicketManager()
{
Expand All @@ -214,6 +219,8 @@ private Set<ChunkPos> getExistingChunks(Set<ChunkPos> requestedChunks)
return ret;
}


/*
@Unique
private Set<ChunkPos> loadExistingChunksFromDisk(Set<ChunkPos> requestedChunks)
{
Expand Down Expand Up @@ -329,6 +336,8 @@ public void relightChunk(ChunkPos pos)
this.waitFor(lightFuture);
}
/*
@Override
public Map<String, Integer> regenerateChunkRegion(List<ChunkPos> requestedChunksList)
{
Expand Down Expand Up @@ -385,7 +394,7 @@ public Map<String, Integer> regenerateChunkRegion(List<ChunkPos> requestedChunks
{
ChunkAccess chunk = this.getCurrentChunk(pos);
if (chunk.getStatus().isOrAfter(ChunkStatus.LIGHT.getParent()))
if (chunk.getPersistedStatus().isOrAfter(ChunkStatus.LIGHT.getParent()))
{
affectedNeighbors.add(chunk);
}
Expand All @@ -399,7 +408,7 @@ public Map<String, Integer> regenerateChunkRegion(List<ChunkPos> requestedChunks
// remove entities
long longPos = pos.toLong();
if (this.entitiesInLevel.contains(longPos) && chunk instanceof LevelChunk)
if (chunk instanceof LevelChunk)
{
((SimpleEntityLookupInterface<Entity>) ((ServerWorldInterface) level).getEntityLookupCMPublic()).getChunkEntities(pos).forEach(entity -> {
if (!(entity instanceof Player))
Expand All @@ -415,7 +424,7 @@ public Map<String, Integer> regenerateChunkRegion(List<ChunkPos> requestedChunks
((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
}
Expand Down Expand Up @@ -450,7 +459,7 @@ public Map<String, Integer> regenerateChunkRegion(List<ChunkPos> requestedChunks
// Also, this is needed to ensure chunks are saved to disk
Map<ChunkPos, ChunkStatus> targetGenerationStatus = affectedChunks.stream().collect(
Collectors.toMap(ChunkAccess::getPos, ChunkAccess::getStatus)
Collectors.toMap(ChunkAccess::getPos, ChunkAccess::getPersistedStatus)
);
for (Entry<ChunkPos, ChunkStatus> entry : targetGenerationStatus.entrySet())
Expand Down Expand Up @@ -548,9 +557,13 @@ public Map<String, Integer> regenerateChunkRegion(List<ChunkPos> requestedChunks
return report;
}
@Override
public Iterable<ChunkHolder> getChunksCM()
{
return getChunks();
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand Down Expand Up @@ -36,14 +37,14 @@ private void addRenderers(Minecraft minecraft, EntityRenderDispatcher entityRend
//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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand All @@ -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<ServerPlayer> cir)
private void onResp(ServerPlayer serverPlayer, boolean olive, Entity.RemovalReason removalReason, CallbackInfoReturnable<ServerPlayer> 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",
Expand All @@ -44,7 +45,7 @@ private void cancellableChatMessageEvent(PlayerChatMessage message, ServerPlayer
value = "INVOKE",
target = "Lnet/minecraft/server/level/ServerPlayer;initInventoryMenu()V"
))
private void invalidatePreviousInstance(ServerPlayer player, boolean alive, CallbackInfoReturnable<ServerPlayer> cir)
private void invalidatePreviousInstance(ServerPlayer player, boolean alive, Entity.RemovalReason removalReason, CallbackInfoReturnable<ServerPlayer> cir)
{
((ServerPlayerInterface)player).invalidateEntityObjectReference();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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;
Expand Down Expand Up @@ -96,18 +97,20 @@ private void setSneakingConditionally(ServerPlayer serverPlayerEntity, boolean s
private ResourceKey<Level> previousDimension;

@Inject(method = "changeDimension", at = @At("HEAD"))
private void logPreviousCoordinates(ServerLevel serverWorld, CallbackInfoReturnable<Entity> cir)
private void logPreviousCoordinates(DimensionTransitionSupplier serverWorld, CallbackInfoReturnable<Entity> cir)
{
previousLocation = position();
previousDimension = level().dimension(); //dimension type
}

@Inject(method = "changeDimension", at = @At("RETURN"))
private void atChangeDimension(ServerLevel destination, CallbackInfoReturnable<Entity> cir)
private void atChangeDimension(DimensionTransitionSupplier destinationP, CallbackInfoReturnable<Entity> 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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/carpet/patches/EntityPlayerMPFake.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ protected void checkFallDamage(double y, boolean onGround, BlockState state, Blo
}

@Override
public Entity changeDimension(ServerLevel serverLevel)
public Entity changeDimension(DimensionTransitionSupplier serverLevel)
{
super.changeDimension(serverLevel);
if (wonGame) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/carpet/script/api/Auxiliary.java
Original file line number Diff line number Diff line change
Expand Up @@ -804,13 +804,17 @@ else if (!interactable && targetBlock == null)

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();
ServerLevel world = cc.level();
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')?
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/carpet/script/api/WorldAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ else if (!("any".equals(statusString)))
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) ->
Expand Down Expand Up @@ -921,7 +921,7 @@ else if (item instanceof TridentItem || item instanceof SwordItem)
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;
Expand Down Expand Up @@ -1586,6 +1586,8 @@ LivingEntity getIndirectSourceEntity()
// todo maybe enable chunk blending?
expression.addContextFunction("reset_chunk", -1, (c, t, lv) ->
{
return Value.NULL;
/*
CarpetContext cc = (CarpetContext) c;
List<ChunkPos> requestedChunks = new ArrayList<>();
if (lv.size() == 1)
Expand Down Expand Up @@ -1643,6 +1645,8 @@ LivingEntity getIndirectSourceEntity()
)));
});
return result[0];
*/
});

expression.addContextFunction("inhabited_time", -1, (c, t, lv) ->
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/carpet/script/external/Vanilla.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ public static void MinecraftServer_forceTick(MinecraftServer server, BooleanSupp

public static void ChunkMap_relightChunk(ChunkMap chunkMap, ChunkPos pos)
{
((ThreadedAnvilChunkStorageInterface) chunkMap).relightChunk(pos);
//((ThreadedAnvilChunkStorageInterface) chunkMap).relightChunk(pos);
}

public static Map<String, Integer> ChunkMap_regenerateChunkRegion(ChunkMap chunkMap, List<ChunkPos> requestedChunks)
{
return ((ThreadedAnvilChunkStorageInterface) chunkMap).regenerateChunkRegion(requestedChunks);
return Map.of(); //return ((ThreadedAnvilChunkStorageInterface) chunkMap).regenerateChunkRegion(requestedChunks);
}

public static List<Collection<ItemStack>> Ingredient_getRecipeStacks(Ingredient ingredient)
Expand Down

0 comments on commit c4f8c86

Please sign in to comment.