Skip to content

Commit

Permalink
update to 25w02a
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobsjo committed Jan 8, 2025
1 parent 0da45d2 commit a6558c3
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 18 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop/
minecraft_version=1.21.4
loader_version=0.16.9
minecraft_version=25w02a
loader_version=0.16.10

# Mod Properties
mod_version = 1.3.0
Expand All @@ -14,5 +14,5 @@ archives_base_name = worldgenDevtools

# Dependencies
# check this on https://fabricmc.net/develop/
fabric_version=0.112.2+1.21.4
fabric_version=0.114.1+1.21.5

Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ private static int showListResult(CommandSourceStack source, ResourceLocation lo
MutableComponent coordComponent = Component.empty().append(ComponentUtils.wrapInSquareBrackets(Component.translatable("chat.coordinates", pos.pos().getX(), pos.pos().getY(), pos.pos().getZ()))
.withStyle(
style -> style.withColor(ChatFormatting.GREEN)
.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/tp @s " + pos.pos().getX() + " " + pos.pos().getY() + " " + pos.pos().getZ()))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.translatable("chat.coordinates.tooltip")))
.withClickEvent(new ClickEvent.SuggestCommand("/tp @s " + pos.pos().getX() + " " + pos.pos().getY() + " " + pos.pos().getZ()))
.withHoverEvent(new HoverEvent.ShowText(Component.translatable("chat.coordinates.tooltip")))
)
);
if (pos.count() > 1) {
Expand Down Expand Up @@ -132,8 +132,8 @@ private static int showLocateResult(
Component component = ComponentUtils.wrapInSquareBrackets(Component.translatable("chat.coordinates", position.getX(), position.getY(), position.getZ()))
.withStyle(
style -> style.withColor(ChatFormatting.GREEN)
.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/tp @s " + position.getX() + " " + position.getY() + " " + position.getZ()))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.translatable("chat.coordinates.tooltip")))
.withClickEvent(new ClickEvent.SuggestCommand("/tp @s " + position.getX() + " " + position.getY() + " " + position.getZ()))
.withHoverEvent(new HoverEvent.ShowText(Component.translatable("chat.coordinates.tooltip")))
);
source.sendSuccess(() -> TextUtil.translatable("worldgendevtools.locatefeature.command.success.nearby", location.toString(), component, dist), false);
return dist;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package eu.jacobsjo.worldgendevtools.resetchunks.api;

public interface DeactivateableTicketStorage {
void worldgenDevtools$deactiveChunk(long pos);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@


import com.mojang.datafixers.DataFixer;
import eu.jacobsjo.worldgendevtools.resetchunks.api.DeactivateableTicketStorage;
import eu.jacobsjo.worldgendevtools.resetchunks.api.ResettableChunkMap;
import eu.jacobsjo.worldgendevtools.resetchunks.impl.ResetChunksCommand;
import eu.jacobsjo.worldgendevtools.worldgensettings.WorldgenSettingsInit;
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
import net.minecraft.server.level.*;
import net.minecraft.util.SortedArraySet;
import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.DistanceManager;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.TicketStorage;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.storage.ChunkStorage;
import net.minecraft.world.level.chunk.storage.RegionStorageInfo;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.nio.file.Path;
import java.util.stream.Collectors;

@Mixin(ChunkMap.class)
public abstract class ChunkMapMixin extends ChunkStorage implements ResettableChunkMap {
Expand All @@ -35,6 +37,8 @@ public ChunkMapMixin(RegionStorageInfo regionStorageInfo, Path path, DataFixer d

@Shadow @Final private Long2ObjectLinkedOpenHashMap<ChunkHolder> updatingChunkMap;

@Shadow @Final private TicketStorage ticketStorage;

@Inject(method="save", at=@At("HEAD"), cancellable = true)
private void save(ChunkAccess chunk, CallbackInfoReturnable<Boolean> cir){
if (!this.level.getGameRules().getBoolean(WorldgenSettingsInit.SAVE_CHUNKS)){
Expand All @@ -53,18 +57,21 @@ private void save(ChunkAccess chunk, CallbackInfoReturnable<Boolean> cir){
DistanceManager distanceManager = this.getDistanceManager();

try {
ResetChunksCommand.LOGGER.debug("Removing chunk {} with tickets {}", chunkPos, this.getTicketDebugString(chunkPos.toLong()));
//ResetChunksCommand.LOGGER.debug("Removing chunk {} with tickets {}", chunkPos, this.getTicketDebugString(chunkPos.toLong()));

// this forces the chunk to be unloaded, without regard to its saving status. But that doesn't matter, since we are resetting it anyway.
this.updatingChunkMap.remove(chunkPos.toLong());
distanceManager.tickets.remove(chunkPos.toLong()); // deletes tickets from unloaded chunks, to make sure they are reloaded before usage.
((DeactivateableTicketStorage) this.ticketStorage).worldgenDevtools$deactiveChunk(chunkPos.toLong()); // deactivate tickets from unloaded chunks, to make sure they are reloaded before usage.

// this removes the chunks from disk, so they are regenerated when reloading the chunk
this.write(chunkPos, () -> null);

// reactivate all deactivated tickets, so the chunk gets reloaded and sent to the client
this.ticketStorage.activateAllDeactivatedTickets();

// this makes the playerTicketManager readd the player tickets we just deleted, so the chunk gets reloaded and sent to the client.
int level = distanceManager.playerTicketManager.getLevel(chunkPos.toLong());
distanceManager.playerTicketManager.onLevelChange(chunkPos.toLong(), level, false, distanceManager.playerTicketManager.haveTicketFor(level));
//int level = distanceManager.playerTicketManager.getLevel(chunkPos.toLong());
//distanceManager.playerTicketManager.onLevelChange(chunkPos.toLong(), level, false, distanceManager.playerTicketManager.haveTicketFor(level));
// other tickets aren't readded, so some chunks (like in spawn-chunks) aren't reloaded after a reset. I don't think this matters though.

} catch (Exception e) {
Expand All @@ -75,6 +82,7 @@ private void save(ChunkAccess chunk, CallbackInfoReturnable<Boolean> cir){
return true;
}

/*
@Unique
private String getTicketDebugString(long chunkPos){
SortedArraySet<Ticket<?>> tickets = this.getDistanceManager().tickets.get(chunkPos);
Expand All @@ -83,4 +91,5 @@ private String getTicketDebugString(long chunkPos){
}
return "[ " + tickets.stream().map(Ticket::toString).collect(Collectors.joining(" | ")) + " ]";
}
*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package eu.jacobsjo.worldgendevtools.resetchunks.mixin;

import eu.jacobsjo.worldgendevtools.resetchunks.api.DeactivateableTicketStorage;
import it.unimi.dsi.fastutil.longs.Long2ObjectFunction;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minecraft.server.level.Ticket;
import net.minecraft.server.level.TicketType;
import net.minecraft.world.level.TicketStorage;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

import java.util.Iterator;
import java.util.List;

@Mixin(TicketStorage.class)
public abstract class TicketStorageMixin implements DeactivateableTicketStorage {
@Shadow @Final private Long2ObjectOpenHashMap<List<Ticket>> deactivatedTickets;
@Shadow @Final private Long2ObjectOpenHashMap<List<Ticket>> tickets;
@Shadow @Nullable private TicketStorage.@Nullable ChunkUpdated loadingChunkUpdatedListener;
@Shadow @Nullable private TicketStorage.@Nullable ChunkUpdated simulationChunkUpdatedListener;
@Shadow protected abstract void updateForcedChunks();

@Shadow public abstract int getTicketLevelAt(long l, boolean bl);

@Override
public void worldgenDevtools$deactiveChunk(long pos) {
List<Ticket> chunkTickets = this.tickets.get(pos);
Iterator<Ticket> iterator = chunkTickets.iterator();
boolean forced = false;
boolean simulating = false;
boolean loading = false;

while (iterator.hasNext()) {
Ticket ticket = (Ticket)iterator.next();
List<Ticket> list = this.deactivatedTickets.computeIfAbsent(
pos, (Long2ObjectFunction<? extends List<Ticket>>)(l -> new ObjectArrayList<>(chunkTickets.size()))
);
list.add(ticket);

iterator.remove();
if (ticket.getType().doesLoad()) {
loading = true;
}

if (ticket.getType().doesSimulate()) {
simulating = true;
}

if (ticket.getType().equals(TicketType.FORCED)) {
forced = true;
}
}

if (loading || simulating) {
if (loading && this.loadingChunkUpdatedListener != null) {
this.loadingChunkUpdatedListener.update(pos, getTicketLevelAt(pos, false), false);
}

if (simulating && this.simulationChunkUpdatedListener != null) {
this.simulationChunkUpdatedListener.update(pos, getTicketLevelAt(pos, true), false);
}

((TicketStorage)(Object)this).setDirty();
}

if (forced) {
this.updateForcedChunks();
}
}
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"depends": {
"fabricloader": "*",
"fabric-api": "*",
"minecraft": ">=1.21.4- <1.21.5-",
"minecraft": ">=1.21.5- <1.21.6-",
"java": ">=21"
}
}
1 change: 0 additions & 1 deletion src/main/resources/worldgendevtools.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ accessWidener v2 named
accessible method net/minecraft/resources/RegistryDataLoader loadContentsFromManager (Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/resources/RegistryOps$RegistryInfoLookup;Lnet/minecraft/core/WritableRegistry;Lcom/mojang/serialization/Decoder;Ljava/util/Map;)V
accessible method net/minecraft/core/Holder$Reference bindValue (Ljava/lang/Object;)V
accessible class net/minecraft/world/level/levelgen/DensityFunctions$EndIslandDensityFunction
accessible field net/minecraft/server/level/DistanceManager tickets Lit/unimi/dsi/fastutil/longs/Long2ObjectOpenHashMap;
accessible field net/minecraft/server/level/DistanceManager playerTicketManager Lnet/minecraft/server/level/DistanceManager$PlayerTicketTracker;
accessible method net/minecraft/server/level/DistanceManager$PlayerTicketTracker onLevelChange (JIZZ)V
accessible method net/minecraft/server/level/DistanceManager$FixedPlayerDistanceChunkTracker getLevel (J)I
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/worldgendevtools.resetchunks.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"package": "eu.jacobsjo.worldgendevtools.resetchunks.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"ChunkMapMixin"
"ChunkMapMixin",
"TicketStorageMixin"
],
"client": [
],
Expand Down

0 comments on commit a6558c3

Please sign in to comment.