Skip to content

Commit

Permalink
feat: allow client to generate data
Browse files Browse the repository at this point in the history
for testing purpose, remove later
  • Loading branch information
rootEnginear committed Dec 11, 2023
1 parent 33efa8f commit ac145d2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package rootenginear.playground.mixin;

import net.minecraft.client.world.chunk.provider.ChunkProviderClient;
import net.minecraft.core.world.chunk.Chunk;
import net.minecraft.core.world.chunk.ChunkCoordIntPair;
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 rootenginear.playground.ChunkProcessor;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Mixin(value = ChunkProviderClient.class, remap = false)
public abstract class ChunkProviderClientMixin {
@Shadow
private Map chunkMapping;

@Unique
List<ChunkCoordIntPair> dumpedChunks = new ArrayList<>();

@Inject(method = "provideChunk", at = @At("TAIL"))
void joopChunk(int chunkX, int chunkZ, CallbackInfoReturnable<Chunk> cir) {
ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(chunkX, chunkZ);
Chunk chunk = (Chunk) this.chunkMapping.get(chunkcoordintpair);
if (dumpedChunks.contains(chunkcoordintpair) || chunk == null || !chunk.receivedFromServer) return;
System.out.println("Dumping " + chunkX + " " + chunkZ);
try {
dumpedChunks.add(chunkcoordintpair);
ChunkProcessor.readAndDumpChunkData(chunkX, chunkZ, chunk);
} catch (Exception ignored) {
}
}
}
5 changes: 4 additions & 1 deletion src/main/resources/playground.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
],
"injectors": {
"defaultRequire": 1
}
},
"client": [
"ChunkProviderClientMixin"
]
}

0 comments on commit ac145d2

Please sign in to comment.