Skip to content

Commit 42bc625

Browse files
committed
update
1 parent 8414f5b commit 42bc625

39 files changed

+495
-458
lines changed

README.md

Lines changed: 0 additions & 114 deletions
This file was deleted.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
plugins {
22
// see https://projects.neoforged.net/neoforged/moddevgradle for new versions
3-
id 'net.neoforged.moddev.legacyforge' version '2.0.106' apply false
3+
id 'net.neoforged.moddev.legacyforge' version '2.0.139' apply false
44
}

common/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ dependencies {
1818
compileOnly("org.spongepowered:mixin:0.8.5")
1919
compileOnly("org.ow2.asm:asm-tree:9.6")
2020
// fabric and neoforge both bundle mixinextras, so it is safe to use it in common
21-
compileOnly("io.github.llamalad7:mixinextras-common:0.3.5")
22-
annotationProcessor("io.github.llamalad7:mixinextras-common:0.3.5")
21+
compileOnly("io.github.llamalad7:mixinextras-common:0.5.2")
22+
annotationProcessor("io.github.llamalad7:mixinextras-common:0.5.2")
2323

2424
compileOnly("org.yaml:snakeyaml:2.4")
2525
implementation("one.pkg:sewlia-config:${config_api_version}") {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package one.pkg.kfnp.mixin.gui;
2+
3+
import com.llamalad7.mixinextras.sugar.Local;
4+
import net.minecraft.Util;
5+
import net.minecraft.client.gui.components.Button;
6+
import net.minecraft.client.gui.layouts.GridLayout;
7+
import net.minecraft.client.gui.screens.OptionsScreen;
8+
import net.minecraft.client.gui.screens.Screen;
9+
import net.minecraft.network.chat.Component;
10+
import one.pkg.loader.Loader;
11+
import org.spongepowered.asm.mixin.Mixin;
12+
import org.spongepowered.asm.mixin.injection.At;
13+
import org.spongepowered.asm.mixin.injection.Inject;
14+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
15+
16+
@Mixin(OptionsScreen.class)
17+
public abstract class OptionsScreenMixin extends Screen {
18+
19+
protected OptionsScreenMixin(Component title) {
20+
super(title);
21+
}
22+
23+
@Inject(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/layouts/GridLayout$RowHelper;addChild(Lnet/minecraft/client/gui/layouts/LayoutElement;)Lnet/minecraft/client/gui/layouts/LayoutElement;", shift = At.Shift.BEFORE, ordinal = 11))
24+
private void addConfigOption(CallbackInfo ci, @Local GridLayout.RowHelper gridlayout$rowhelper) {
25+
gridlayout$rowhelper.addChild(Button.builder(Component.literal("Config KryptonFNP"), (button) -> {
26+
Util.getPlatform().openUri(Loader.INSTANCE.getConfigPath().resolve("krypton_fnp.yaml").toUri());
27+
}).build());
28+
}
29+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package one.pkg.kfnp.mixin.network.experimental;
2+
3+
import io.netty.buffer.ByteBuf;
4+
import io.netty.buffer.ByteBufAllocator;
5+
import net.minecraft.server.rcon.thread.RconClient;
6+
import org.spongepowered.asm.mixin.*;
7+
8+
import java.io.IOException;
9+
import java.net.Socket;
10+
import java.nio.charset.StandardCharsets;
11+
12+
@Mixin(RconClient.class)
13+
public class RconClientMixin {
14+
@Unique
15+
private static final int CHUNK_SIZE = 4096;
16+
@Unique
17+
private static final int PACKET_OVERHEAD = 10;
18+
@Unique
19+
private final byte[] krypton_fnp$chunkBuffer = new byte[CHUNK_SIZE];
20+
21+
@Shadow
22+
@Final
23+
private Socket client;
24+
25+
@Shadow
26+
private void closeSocket() {
27+
}
28+
29+
/**
30+
* @author KryptonFNP
31+
* @reason Optimize send method to accept byte[] directly, reducing string conversions and allocations.
32+
*/
33+
@Overwrite
34+
private void send(int id, int type, String message) throws IOException {
35+
byte[] bytes = message.getBytes(StandardCharsets.UTF_8);
36+
this.send(id, type, bytes, bytes.length);
37+
}
38+
39+
@Unique
40+
private void send(int id, int type, byte[] messageBytes, int length) throws IOException {
41+
ByteBuf buf = ByteBufAllocator.DEFAULT.buffer(length + PACKET_OVERHEAD + 2);
42+
try {
43+
buf.writeIntLE(length + PACKET_OVERHEAD);
44+
buf.writeIntLE(id);
45+
buf.writeIntLE(type);
46+
buf.writeBytes(messageBytes, 0, length);
47+
buf.writeByte(0);
48+
buf.writeByte(0);
49+
50+
if (buf.hasArray()) {
51+
this.client.getOutputStream().write(buf.array(), buf.arrayOffset() + buf.readerIndex(), buf.readableBytes());
52+
} else {
53+
byte[] temp = new byte[buf.readableBytes()];
54+
buf.getBytes(buf.readerIndex(), temp);
55+
this.client.getOutputStream().write(temp);
56+
}
57+
} finally {
58+
buf.release();
59+
}
60+
}
61+
62+
/**
63+
* @author KryptonFNP
64+
* @reason Optimize sendCmdResponse to split on byte boundaries instead of characters, reducing allocations and fixing potential encoding issues.
65+
*/
66+
@Overwrite
67+
private void sendCmdResponse(int id, String message) throws IOException {
68+
byte[] fullBytes = message.getBytes(StandardCharsets.UTF_8);
69+
int len = fullBytes.length;
70+
71+
if (len <= CHUNK_SIZE) {
72+
this.send(id, 0, fullBytes, len);
73+
} else {
74+
int offset = 0;
75+
while (offset < len) {
76+
int chunkSize = Math.min(CHUNK_SIZE, len - offset);
77+
System.arraycopy(fullBytes, offset, krypton_fnp$chunkBuffer, 0, chunkSize);
78+
this.send(id, 0, krypton_fnp$chunkBuffer, chunkSize);
79+
offset += chunkSize;
80+
}
81+
}
82+
}
83+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package one.pkg.kfnp.mixin.network.microopt;
2+
3+
import io.netty.buffer.ByteBuf;
4+
import io.netty.buffer.ByteBufUtil;
5+
import io.netty.handler.codec.EncoderException;
6+
import net.minecraft.network.FriendlyByteBuf;
7+
import org.spongepowered.asm.mixin.Final;
8+
import org.spongepowered.asm.mixin.Mixin;
9+
import org.spongepowered.asm.mixin.Overwrite;
10+
import org.spongepowered.asm.mixin.Shadow;
11+
12+
import java.nio.charset.Charset;
13+
import java.nio.charset.StandardCharsets;
14+
15+
@Mixin(value = FriendlyByteBuf.class, priority = 900)
16+
public abstract class FriendlyByteBufUtfMixin extends ByteBuf {
17+
@Shadow
18+
@Final
19+
private ByteBuf source;
20+
21+
@Shadow
22+
public FriendlyByteBuf writeVarInt(int input) {
23+
throw new UnsupportedOperationException("Mixin method not implemented");
24+
}
25+
26+
/**
27+
* @author Andrew
28+
* @reason Use {@link ByteBuf#writeCharSequence(CharSequence, Charset)} instead for improved performance along with
29+
* computing the byte size ahead of time with {@link ByteBufUtil#utf8Bytes(CharSequence)}
30+
*/
31+
@Overwrite
32+
public FriendlyByteBuf writeUtf(String string, int maxLength) {
33+
if (string.length() > maxLength) {
34+
throw new EncoderException("String too big (was " + string.length() + " characters, max " + maxLength + ")");
35+
}
36+
int utf8Bytes = ByteBufUtil.utf8Bytes(string);
37+
if (utf8Bytes > maxLength * 3) {
38+
throw new EncoderException("String too big (was " + utf8Bytes + " bytes encoded, max " + (maxLength * 3) + ")");
39+
} else {
40+
this.writeVarInt(utf8Bytes);
41+
this.writeCharSequence(string, StandardCharsets.UTF_8);
42+
return (FriendlyByteBuf) (Object) this;
43+
}
44+
}
45+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package one.pkg.kfnp.mixin.network.microopt;
2+
3+
4+
import io.netty.buffer.ByteBuf;
5+
import net.minecraft.network.FriendlyByteBuf;
6+
import one.pkg.kfnp.shared.network.util.VarIntUtil;
7+
import org.spongepowered.asm.mixin.Final;
8+
import org.spongepowered.asm.mixin.Mixin;
9+
import org.spongepowered.asm.mixin.Overwrite;
10+
import org.spongepowered.asm.mixin.Shadow;
11+
12+
@Mixin(value = FriendlyByteBuf.class, priority = 900)
13+
public abstract class FriendlyByteBufVarIntMixin extends ByteBuf {
14+
@Shadow
15+
@Final
16+
private ByteBuf source;
17+
18+
/**
19+
* @author Andrew
20+
* @reason Use optimized VarInt byte size lookup table
21+
*/
22+
@Overwrite
23+
public static int getVarIntSize(int v) {
24+
return VarIntUtil.getVarIntLength(v);
25+
}
26+
27+
/**
28+
* @author Andrew
29+
* @reason optimized VarInt writing
30+
*/
31+
@Overwrite
32+
public FriendlyByteBuf writeVarInt(int value) {
33+
// Peel the one and two byte count cases explicitly as they are the most common VarInt sizes
34+
// that the server will send, to improve inlining.
35+
if ((value & VarIntUtil.MASK_7_BITS) == 0) {
36+
this.source.writeByte(value);
37+
} else if ((value & VarIntUtil.MASK_14_BITS) == 0) {
38+
this.source.writeShort((value & 0x7F | 0x80) << 8 | (value >>> 7));
39+
} else if ((value & VarIntUtil.MASK_21_BITS) == 0) {
40+
this.source.writeMedium((value & 0x7F | 0x80) << 16
41+
| ((value >>> 7) & 0x7F | 0x80) << 8
42+
| (value >>> 14));
43+
} else if ((value & VarIntUtil.MASK_28_BITS) == 0) {
44+
this.source.writeInt((value & 0x7F | 0x80) << 24
45+
| ((value >>> 7) & 0x7F | 0x80) << 16
46+
| ((value >>> 14) & 0x7F | 0x80) << 8
47+
| (value >>> 21));
48+
} else {
49+
this.source.writeInt((value & 0x7F | 0x80) << 24
50+
| ((value >>> 7) & 0x7F | 0x80) << 16
51+
| ((value >>> 14) & 0x7F | 0x80) << 8
52+
| ((value >>> 21) & 0x7F | 0x80));
53+
this.source.writeByte(value >>> 28);
54+
}
55+
return (FriendlyByteBuf) (Object) this;
56+
}
57+
58+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package one.pkg.kfnp.mixin.network.microopt;
2+
3+
import io.netty.buffer.ByteBuf;
4+
import net.minecraft.network.FriendlyByteBuf;
5+
import one.pkg.kfnp.shared.network.util.VarLongUtil;
6+
import org.spongepowered.asm.mixin.Final;
7+
import org.spongepowered.asm.mixin.Mixin;
8+
import org.spongepowered.asm.mixin.Overwrite;
9+
import org.spongepowered.asm.mixin.Shadow;
10+
11+
@Mixin(value = FriendlyByteBuf.class, priority = 900)
12+
public abstract class FriendlyByteBufVarLongMixin extends ByteBuf {
13+
@Shadow
14+
@Final
15+
private ByteBuf source;
16+
17+
/**
18+
* @author 404
19+
* @reason optimized version for VarLong
20+
*/
21+
@Overwrite
22+
public static int getVarLongSize(long data) {
23+
return VarLongUtil.getVarLongLength(data);
24+
}
25+
26+
/**
27+
* @author 404
28+
* @reason optimized version for VarLong
29+
*/
30+
@Overwrite
31+
public FriendlyByteBuf writeVarLong(long value) {
32+
VarLongUtil.writeVarLongFull(this, value);
33+
return (FriendlyByteBuf) (Object) this;
34+
}
35+
}

common/src/main/java/one/pkg/mod/krypton_fnp/mixin/network/microopt/ServerEntityMixin.java renamed to common/src/main/java/one/pkg/kfnp/mixin/network/microopt/ServerEntityMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package one.pkg.mod.krypton_fnp.mixin.network.microopt;
1+
package one.pkg.kfnp.mixin.network.microopt;
22

33
import com.google.common.collect.ImmutableList;
44
import net.minecraft.world.entity.Entity;

0 commit comments

Comments
 (0)