Skip to content

Commit

Permalink
Remove multi version stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev0Louis committed Jan 4, 2024
1 parent c574c3e commit b20ccba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 30 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.3
minecraft_version=1.19.4
yarn_mappings=1.19.4+build.2
loader_version=0.15.3
# Mod Properties
mod_version=4.0.3-beta.2
mod_version=4.0.3+1.19.4
maven_group=dev.louis
archives_base_name=Nebula
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.91.2+1.20.4
fabric_version=0.87.2+1.19.4
28 changes: 2 additions & 26 deletions src/main/java/dev/louis/nebula/NebulaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.Identifier;

import java.lang.reflect.InvocationTargetException;
import java.util.function.Consumer;
import java.util.function.Supplier;

public class NebulaClient implements ClientModInitializer {
public static final Consumer<PacketByteBuf> retainer = getConsumer("retain", () -> PacketByteBuf::retain);
public static final Consumer<PacketByteBuf> releaser = getConsumer("release", () -> PacketByteBuf::release);

@Override
public void onInitializeClient() {
Expand All @@ -30,32 +24,14 @@ private void registerPacketReceivers() {
}

public static void runSyncWithBuf(MinecraftClient client, PacketByteBuf buf, Runnable runnable) {
retainer.accept(buf);
buf.retain();
client.executeSync(() -> {
runnable.run();
releaser.accept(buf);
buf.release();
});
}

private void registerReceiver(Identifier id, ClientPlayNetworking.PlayChannelHandler playChannelHandler) {
ClientPlayNetworking.registerGlobalReceiver(id, playChannelHandler);
}

private static Consumer<PacketByteBuf> getConsumer(String methodName, Supplier<Consumer<PacketByteBuf>> defaultConsumer) {
try {
//Needed to throw NoSuchMethodException if the method doesn't exist.
PacketByteBuf.class.getMethod(methodName);
return buf -> invoke(buf, methodName);
} catch (NoSuchMethodException e) {
return defaultConsumer.get();
}
}

private static void invoke(PacketByteBuf buf, String methodName) {
try {
PacketByteBuf.class.getMethod(methodName).invoke(buf);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit b20ccba

Please sign in to comment.