Skip to content

Commit 94925fe

Browse files
committed
LookingGlass compat
1 parent d1bdb76 commit 94925fe

File tree

4 files changed

+125
-0
lines changed

4 files changed

+125
-0
lines changed

build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,13 @@ minecraft_fp {
5151
}
5252

5353
repositories {
54+
cursemavenEX()
5455
exclusive(maven("mavenpattern", "https://mvn.falsepattern.com/releases/"), "com.falsepattern")
5556
}
5657

5758
dependencies {
5859
apiSplit("com.falsepattern:falsepatternlib-mc1.7.10:1.5.9")
60+
61+
//LookingGlass 0.2.0.01
62+
compileOnly(deobfCurse("lookingglass-230541:2321557"))
5963
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* ChunkAPI
3+
*
4+
* Copyright (C) 2023-2025 FalsePattern, The MEGA Team, LegacyModdingMC contributors
5+
* All Rights Reserved
6+
*
7+
* The above copyright notice and this permission notice shall be included
8+
* in all copies or substantial portions of the Software.
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Lesser General Public License as published by
12+
* the Free Software Foundation, only version 3 of the License.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
21+
*/
22+
23+
package com.falsepattern.chunk.internal.mixin.mixins.common.lookingglass;
24+
25+
import com.xcompwiz.lookingglass.log.LoggerUtils;
26+
import com.xcompwiz.lookingglass.network.LookingGlassPacketManager;
27+
import com.xcompwiz.lookingglass.network.packet.PacketChunkInfo;
28+
import com.xcompwiz.lookingglass.network.packet.PacketHandlerBase;
29+
import com.xcompwiz.lookingglass.network.packet.PacketRequestChunk;
30+
import io.netty.buffer.ByteBuf;
31+
import org.spongepowered.asm.mixin.Mixin;
32+
import org.spongepowered.asm.mixin.Overwrite;
33+
import org.spongepowered.asm.mixin.Shadow;
34+
35+
import net.minecraft.entity.player.EntityPlayer;
36+
import net.minecraft.network.play.server.S21PacketChunkData;
37+
import net.minecraft.world.chunk.Chunk;
38+
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
39+
40+
import java.util.concurrent.Semaphore;
41+
42+
@Mixin(PacketChunkInfo.class)
43+
public abstract class PacketChunkInfoMixin extends PacketHandlerBase {
44+
@Shadow(remap = false) private static Semaphore deflateGate;
45+
46+
@Shadow(remap = false)
47+
private static int deflate(byte[] chunkData, byte[] compressedChunkData) {
48+
return 0;
49+
}
50+
51+
@Shadow(remap = false) public abstract void handle(EntityPlayer player, byte[] chunkData, int dim, int xPos, int zPos, boolean reqinit, short yPos, short yMSBPos);
52+
53+
@Shadow(remap = false) protected abstract byte[] inflateChunkData(ByteBuf in, int compressedsize, int uncompressedsize);
54+
55+
/**
56+
* @author FalsePattern
57+
* @reason This class was just copied vanilla code.
58+
*/
59+
@Overwrite(remap = false)
60+
public static S21PacketChunkData.Extracted getMapChunkData(Chunk chunk, boolean forceUpdate, int subChunkMask) {
61+
return S21PacketChunkData.func_149269_a(chunk, forceUpdate, subChunkMask);
62+
}
63+
64+
/**
65+
* @author FalsePattern
66+
* @reason Wired up to ChunkAPI
67+
*/
68+
@Overwrite(remap = false)
69+
public static FMLProxyPacket createPacket(Chunk chunk, boolean forceUpdate, int subChunkMask, int dim) {
70+
int xPos = chunk.xPosition;
71+
int zPos = chunk.zPosition;
72+
S21PacketChunkData.Extracted extracted = getMapChunkData(chunk, forceUpdate, subChunkMask);
73+
int realSubChunkMask = extracted.field_150280_b;
74+
byte[] chunkData = extracted.field_150282_a;
75+
deflateGate.acquireUninterruptibly();
76+
byte[] compressedChunkData = new byte[chunkData.length];
77+
int len = deflate(chunkData, compressedChunkData);
78+
deflateGate.release();
79+
ByteBuf data = PacketHandlerBase.createDataBuffer(PacketChunkInfo.class);
80+
data.writeInt(dim);
81+
data.writeInt(xPos);
82+
data.writeInt(zPos);
83+
data.writeBoolean(forceUpdate);
84+
data.writeShort((short)(realSubChunkMask & 0xFFFF));
85+
data.writeInt(len);
86+
data.writeInt(chunkData.length);
87+
data.ensureWritable(len);
88+
data.writeBytes(compressedChunkData, 0, len);
89+
return buildPacket(data);
90+
}
91+
92+
/**
93+
* @author FalsePattern
94+
* @reason Wired up to ChunkAPI
95+
*/
96+
@Overwrite(remap = false)
97+
public void handle(ByteBuf in, EntityPlayer player) {
98+
int dim = in.readInt();
99+
int xPos = in.readInt();
100+
int zPos = in.readInt();
101+
boolean forceUpdate = in.readBoolean();
102+
int subChunkMask = in.readShort() & 0xFFFF;
103+
int compressedSize = in.readInt();
104+
int uncompressedSize = in.readInt();
105+
byte[] chunkData = this.inflateChunkData(in, compressedSize, uncompressedSize);
106+
if (chunkData == null) {
107+
LookingGlassPacketManager.bus.sendToServer(PacketRequestChunk.createPacket(xPos, subChunkMask, zPos, dim));
108+
LoggerUtils.error("Chunk decompression failed: \t%d\t\t%d : %d\n", subChunkMask, compressedSize, uncompressedSize);
109+
} else {
110+
this.handle(player, chunkData, dim, xPos, zPos, forceUpdate, (short) subChunkMask, (short)0);
111+
}
112+
}
113+
}

src/main/java/com/falsepattern/chunk/internal/mixin/plugin/Mixin.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.function.Predicate;
3232

3333
import static com.falsepattern.lib.mixin.IMixin.PredicateHelpers.always;
34+
import static com.falsepattern.lib.mixin.IMixin.PredicateHelpers.require;
3435

3536
@RequiredArgsConstructor
3637
public enum Mixin implements IMixin {
@@ -44,6 +45,10 @@ public enum Mixin implements IMixin {
4445

4546
ChunkMixin(Side.CLIENT, always(), "vanilla.ChunkMixin"),
4647
NetHandlerPlayClientMixin(Side.CLIENT, always(), "vanilla.NetHandlerPlayClientMixin"),
48+
49+
//region Looking Glass
50+
PacketChunkInfoMixin(Side.COMMON, require(TargetedMod.LOOKINGGLASS), "lookingglass.PacketChunkInfoMixin"),
51+
//endregion
4752
;
4853
// @formatter:on
4954

src/main/java/com/falsepattern/chunk/internal/mixin/plugin/TargetedMod.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@
2828

2929
import java.util.function.Predicate;
3030

31+
import static com.falsepattern.lib.mixin.ITargetedMod.PredicateHelpers.contains;
32+
3133
@RequiredArgsConstructor
3234
public enum TargetedMod implements ITargetedMod {
35+
LOOKINGGLASS("Looking Glass", false, contains("lookingglass-"))
3336
;
3437

3538
@Getter

0 commit comments

Comments
 (0)