generated from Turnip-Labs/bta-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb75368
commit dc45b32
Showing
4 changed files
with
98 additions
and
8 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/main/java/rootenginear/playground/mixin/ChunkProviderMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/rootenginear/playground/mixin/NetServerHandlerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/rootenginear/playground/mixin/accessor/ChunkProviderServerInvoker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |