Skip to content

Commit

Permalink
feat: first proto
Browse files Browse the repository at this point in the history
  • Loading branch information
rootEnginear committed Dec 6, 2023
1 parent fb75368 commit dc45b32
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package rootenginear.playground.mixin;

import net.minecraft.core.world.chunk.Chunk;
import net.minecraft.server.world.WorldServer;
import net.minecraft.server.world.chunk.provider.ChunkProviderServer;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import rootenginear.playground.mixin.accessor.ChunkProviderServerInvoker;

import java.io.FileOutputStream;
import java.io.IOException;

@Mixin(value = ChunkProviderServer.class, remap = false)
public abstract class ChunkProviderMixin {
@Shadow
@Final
private WorldServer world;

@Redirect(method = "prepareChunk", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/chunk/provider/ChunkProviderServer;loadChunkFromFile(II)Lnet/minecraft/core/world/chunk/Chunk;"))
private Chunk readTopOpaqueBlockData(ChunkProviderServer cps, int chunkX, int chunkZ) throws IOException {
Chunk chunk = ((ChunkProviderServerInvoker) cps).invokeLoadChunkFromFile(chunkX, chunkZ);
if (chunk == null) return null;
if (this.world.dimension.id == 0) {
try (FileOutputStream chunkData = new FileOutputStream(String.format("livemap/chunks/%d.%d.txt", chunkX, chunkZ))) {
for (int shiftZ = 0; shiftZ < 16; shiftZ++) {
for (int shiftX = 0; shiftX < 16; shiftX++) {
short blockData = 0;
for (int y = chunk.getHeightValue(shiftX, shiftZ); y > -1; y--) {
int blockId = chunk.getBlockID(shiftX, y, shiftZ);
if (blockId != 0) {
int metadata = chunk.getBlockMetadata(shiftX, y, shiftZ);
blockData = (short) ((blockId & 0x3FF) | ((metadata & 0xF) << 10));
break;
}
}
chunkData.write(blockData & 0xFF);
chunkData.write((blockData >> 8) & 0xFF);
}
}
}
}
return chunk;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package rootenginear.playground.mixin;

import net.minecraft.core.net.packet.Packet10Flying;
import net.minecraft.server.entity.player.EntityPlayerMP;
import net.minecraft.server.net.handler.NetServerHandler;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.io.FileWriter;
import java.io.IOException;

@Mixin(value = NetServerHandler.class, remap = false)
public class NetServerHandlerMixin {
@Shadow
private EntityPlayerMP playerEntity;

@Inject(method = "handleFlying", at = @At("HEAD"))
private void trackLocation(Packet10Flying packet, CallbackInfo ci) throws IOException {
if (packet.moving) {
try (FileWriter chunkData = new FileWriter(String.format("livemap/players/%s.txt", this.playerEntity.username))) {
chunkData.write(String.format("%f %f", this.playerEntity.x, this.playerEntity.z));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package rootenginear.playground.mixin.accessor;

import net.minecraft.core.world.chunk.Chunk;
import net.minecraft.server.world.chunk.provider.ChunkProviderServer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(value = ChunkProviderServer.class, remap = false)
public interface ChunkProviderServerInvoker {
@Invoker("loadChunkFromFile")
Chunk invokeLoadChunkFromFile(int chunkX, int chunkZ);
}
19 changes: 11 additions & 8 deletions src/main/resources/playground.mixins.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"required": true,
"minVersion": "0.8",
"package": "rootenginear.playground.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
],
"injectors": {
"defaultRequire": 1
"required": true,
"minVersion": "0.8",
"package": "rootenginear.playground.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"ChunkProviderMixin",
"NetServerHandlerMixin",
"accessor.ChunkProviderServerInvoker"
],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit dc45b32

Please sign in to comment.