Skip to content

Commit

Permalink
well it "loads"
Browse files Browse the repository at this point in the history
  • Loading branch information
ferriarnus committed Jun 3, 2024
1 parent 12bdaa5 commit b8e1a0a
Show file tree
Hide file tree
Showing 31 changed files with 212 additions and 138 deletions.
13 changes: 8 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
plugins {
id 'dev.architectury.loom' version '1.4-SNAPSHOT'
id 'dev.architectury.loom' version '1.6-SNAPSHOT'
id 'maven-publish'
id "com.github.johnrengelman.shadow" version "8.1.1"
}

version = project.mod_version
group = project.maven_group

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

loom {
runs {
it.configureEach {
vmArgs("-Xmx8G", "-XX:+UseZGC")
}
}
mixin {
useLegacyMixinAp = false
}

silentMojangMappingsLicense()
}
Expand All @@ -31,7 +34,7 @@ configurations {
processResources {
inputs.property "version", project.version
archivesBaseName = "reforgedplaymod-${project.minecraft_version}"
filesMatching("META-INF/mods.toml") {
filesMatching("META-INF/neoforge.mods.toml") {
expand "version": project.version
}
}
Expand Down Expand Up @@ -68,7 +71,7 @@ dependencies {

mappings loom.layered() {
it.mappings("net.fabricmc:yarn:${project.yarn_mappings}:v2")
it.mappings file("mappings/yarnpatch.tiny")
it.mappings("dev.architectury:yarn-mappings-patch-neoforge:1.20.5+build.3")
}
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx3G
# Fabric Properties
# check these on https://modmuss50.me/fabric.html

minecraft_version=1.20.4
yarn_mappings=1.20.4+build.1
minecraft_version=1.20.6
yarn_mappings=1.20.6+build.2
loader_version=0.15.0

#Fabric api
fabric_version=0.91.1+1.20.4
fabric_version=0.91.1+1.20.6

# Mod Properties
mod_version=0.1
Expand All @@ -17,4 +17,4 @@ archives_base_name=replaymod
# Dependencies
# check this on https://modmuss50.me/fabric.html
loom.platform=neoforge
neoforge_version=20.4.234
neoforge_version=20.6.100-beta
3 changes: 2 additions & 1 deletion src/main/java/com/replaymod/core/KeyBindingRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.minecraft.util.Identifier;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent;

Expand All @@ -42,7 +43,7 @@
import java.util.function.Consumer;
import java.util.function.Supplier;

@Mod.EventBusSubscriber(modid = MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
@EventBusSubscriber(modid = MOD_ID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public class KeyBindingRegistry extends EventRegistrations {
private static final String CATEGORY = "replaymod.title";
//#if FABRIC>=1 && MC<11600
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/com/replaymod/core/ReplayMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.replaymod.simplepathing.ReplayModSimplePathing;
import net.minecraft.client.MinecraftClient;
import net.minecraft.resource.DirectoryResourcePack;
import net.minecraft.resource.ResourcePackInfo;
import net.minecraft.resource.ResourcePackSource;
import net.minecraft.text.PlainTextContent;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
Expand All @@ -33,6 +35,7 @@
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

Expand Down Expand Up @@ -85,7 +88,7 @@ public ReplayMod(ReplayModBackend backend) {

// Check Minecraft protocol version for compatibility
if (!ProtocolVersion.isRegistered(MCVer.getProtocolVersion()) && !Boolean.parseBoolean(System.getProperty("replaymod.skipversioncheck", "false"))) {
minimalMode = true;
//minimalMode = true;
}

// Register all RM modules
Expand Down Expand Up @@ -121,13 +124,13 @@ private static DirectoryResourcePack createJGuiResourcePack() {
}
}
//#if MC>=11903
return new DirectoryResourcePack(JGUI_RESOURCE_PACK_NAME, folder.toPath(), true) {
return new DirectoryResourcePack(new ResourcePackInfo(JGUI_RESOURCE_PACK_NAME, Text.literal(JGUI_RESOURCE_PACK_NAME), ResourcePackSource.BUILTIN, Optional.empty()), folder.toPath()) {
//#else
//$$ return new DirectoryResourcePack(folder) {
//#endif
@Override
//#if MC>=11400
public String getName() {
public String getId() {
//#else
//$$ public String getPackName() {
//#endif
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/replaymod/core/ReplayModBackend.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import net.minecraft.SharedConstants;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
import net.neoforged.fml.event.lifecycle.FMLConstructModEvent;
import net.neoforged.fml.loading.LoadingModList;

import static com.replaymod.core.ReplayMod.MOD_ID;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, modid = MOD_ID, value = Dist.CLIENT)
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD, modid = MOD_ID, value = Dist.CLIENT)
@Mod(MOD_ID)
public class ReplayModBackend {
private final ReplayMod mod = new ReplayMod(this);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/replaymod/core/mixin/MixinGameRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.util.math.MatrixStack;
import org.joml.Matrix4f;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -24,22 +25,21 @@ private void postRenderWorld(
float partialTicks,
long nanoTime,
//#if MC>=11500
MatrixStack matrixStack,
//#endif
CallbackInfo ci) {
//#if MC<11500
//$$ MatrixStack matrixStack = new MatrixStack();
//#endif
PostRenderWorldCallback.EVENT.invoker().postRenderWorld(matrixStack);
PostRenderWorldCallback.EVENT.invoker().postRenderWorld(new MatrixStack());
}

@Inject(method = "renderHand", at = @At("HEAD"), cancellable = true)
private void preRenderHand(
//#if MC>=11500
MatrixStack matrixStack,
//#endif
Camera camera,
//#if MC>=11500
float partialTicks,
Matrix4f matrixStack,
//#endif
CallbackInfo ci) {
if (PreRenderHandCallback.EVENT.invoker().preRenderHand()) {
ci.cancel();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/replaymod/core/utils/Restrictions.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Restrictions {
public String handle(CustomPayloadS2CPacket packet) {
//#if MC>=12002
PacketByteBuf buffer = new PacketByteBuf(Unpooled.buffer());
packet.write(buffer);
CustomPayloadS2CPacket.CONFIGURATION_CODEC.encode(buffer, packet);
//#elseif MC>=10800
//$$ PacketByteBuf buffer = packet.getData();
//#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import com.google.gson.Gson;
import com.replaymod.core.ReplayMod;
import net.minecraft.resource.AbstractFileResourcePack;
import net.minecraft.resource.ResourcePackInfo;
import net.minecraft.resource.ResourcePackSource;
import net.minecraft.resource.ResourceType;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.neoforged.fml.loading.LoadingModList;
import net.neoforged.fml.loading.moddiscovery.ModFileInfo;
Expand All @@ -23,6 +26,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Predicate;
Expand Down Expand Up @@ -65,7 +69,7 @@ public class LangResourcePack extends AbstractFileResourcePack {
private final Path basePath;
public LangResourcePack() {
//#if MC>=11903
super(NAME, true);
super(new ResourcePackInfo(NAME, Text.literal("NAME"), ResourcePackSource.BUILTIN, Optional.empty()));
//#else
//$$ super(new File(NAME));
//#endif
Expand Down
25 changes: 17 additions & 8 deletions src/main/java/com/replaymod/core/versions/MCVer.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.network.NetworkState;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.state.ConfigurationStates;
import net.minecraft.network.state.HandshakeStates;
import net.minecraft.network.state.LoginStates;
import net.minecraft.network.state.PlayStateFactories;
import net.minecraft.network.state.QueryStates;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import net.minecraft.util.math.Vec3d;
Expand Down Expand Up @@ -86,6 +94,7 @@
//$$ import static org.lwjgl.opengl.GL11.*;
//#endif

import javax.net.ssl.SSLEngineResult;
import java.io.File;
import java.net.URI;
import java.util.List;
Expand All @@ -106,19 +115,19 @@ public static int getProtocolVersion() {

public static NetworkState asMc(State state) {
switch (state) {
case HANDSHAKE: return NetworkState.HANDSHAKING;
case STATUS: return NetworkState.STATUS;
case LOGIN: return NetworkState.LOGIN;
case HANDSHAKE: return HandshakeStates.C2S;
case STATUS: return QueryStates.S2C;
case LOGIN: return LoginStates.S2C;
//#if MC>=12002
case CONFIGURATION: return NetworkState.CONFIGURATION;
case CONFIGURATION: return ConfigurationStates.S2C;
//#endif
case PLAY: return NetworkState.PLAY;
case PLAY: return PlayStateFactories.S2C.bind(RegistryByteBuf.makeFactory(DynamicRegistryManager.of(Registries.REGISTRIES)));
}
throw new IllegalArgumentException("Unexpected value: " + state);
}

public static State fromMc(NetworkState mcState) {
switch (mcState) {
switch (mcState.id()) {
case HANDSHAKING: return State.HANDSHAKE;
case STATUS: return State.STATUS;
case LOGIN: return State.LOGIN;
Expand Down Expand Up @@ -398,15 +407,15 @@ public static void openURL(URI url) {

public static void pushMatrix() {
//#if MC>=11700
RenderSystem.getModelViewStack().push();
RenderSystem.getModelViewStack().pushMatrix();
//#else
//$$ GlStateManager.pushMatrix();
//#endif
}

public static void popMatrix() {
//#if MC>=11700
RenderSystem.getModelViewStack().pop();
RenderSystem.getModelViewStack().popMatrix();
RenderSystem.applyModelViewMatrix();
//#else
//$$ GlStateManager.popMatrix();
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/replaymod/core/versions/Patterns.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.network.NetworkSide;
import net.minecraft.network.NetworkState;
import net.minecraft.network.handler.PacketCodecDispatcher;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket;
import net.minecraft.resource.Resource;
Expand Down Expand Up @@ -575,7 +576,7 @@ private static void GL11_glTranslatef(float x, float y, float z) {
@Pattern
private static void GL11_glRotatef(float angle, float x, float y, float z) {
//#if MC>=11700
com.mojang.blaze3d.systems.RenderSystem.getModelViewStack().multiply(com.replaymod.core.versions.MCVer.quaternion(angle, new org.joml.Vector3f(x, y, z)));
com.mojang.blaze3d.systems.RenderSystem.getModelViewStack().rotate(com.replaymod.core.versions.MCVer.quaternion(angle, new org.joml.Vector3f(x, y, z)));
//#else
//$$ GL11.glRotatef(angle, x, y, z);
//#endif
Expand Down Expand Up @@ -916,7 +917,7 @@ public World getWorld(Entity entity) {
@Pattern
public Object channel(CustomPayloadS2CPacket packet) {
//#if MC>=12002
return packet.payload().id();
return packet.payload().getId().id();
//#else
//$$ return packet.getChannel();
//#endif
Expand All @@ -926,7 +927,7 @@ public Object channel(CustomPayloadS2CPacket packet) {
@Pattern
public Integer getPacketId(NetworkState state, NetworkSide side, Packet<?> packet) throws Exception {
//#if MC>=12002
return state.getHandler(side).getId(packet);
return ((PacketCodecDispatcher) state.codec()).typeToIndex.get(packet);
//#else
//$$ return state.getPacketId(side, packet);
//#endif
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/com/replaymod/recording/ReplayModRecording.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
import io.netty.channel.Channel;
import io.netty.util.AttributeKey;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.codec.PacketCodecs;
import net.minecraft.network.packet.CustomPayload;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent;
import net.neoforged.neoforge.network.registration.IPayloadRegistrar;
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -34,7 +37,7 @@
//$$ import io.netty.channel.ChannelHandler;
//#endif

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, modid = ReplayMod.MOD_ID)
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD, modid = ReplayMod.MOD_ID)
public class ReplayModRecording implements Module {

private static final Logger LOGGER = LogManager.getLogger();
Expand Down Expand Up @@ -110,8 +113,8 @@ public ConnectionEventHandler getConnectionEventHandler() {
}

@SubscribeEvent
public static void registerNetwork(RegisterPayloadHandlerEvent event) {
final IPayloadRegistrar registrar = event.registrar(ReplayMod.MOD_ID).optional();
registrar.play(Restrictions.PLUGIN_CHANNEL, packetByteBuf -> null, (arg, playPayloadContext) -> {});
public static void registerNetwork(RegisterPayloadHandlersEvent event) {
final var registrar = event.registrar(ReplayMod.MOD_ID).optional();
registrar.playToClient(new CustomPayload.Id(Restrictions.PLUGIN_CHANNEL), PacketCodec.ofStatic((buf, value) -> {}, buf -> null), (arg, playPayloadContext) -> {});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import com.replaymod.replaystudio.lib.viaversion.api.protocol.packet.State;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.packet.s2c.play.PlayerRespawnS2CPacket;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.Registries;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand Down Expand Up @@ -72,8 +75,7 @@ public void recordOwnJoin(PlayerListS2CPacket packet, CallbackInfo ci) {
// to parse it instead.
ByteBuf byteBuf = Unpooled.buffer();
try {
packet.write(new PacketByteBuf(byteBuf));

PlayerListS2CPacket.CODEC.encode(new RegistryByteBuf(byteBuf, DynamicRegistryManager.of(Registries.REGISTRIES)), packet);
byteBuf.readerIndex(0);
byte[] array = new byte[byteBuf.readableBytes()];
byteBuf.readBytes(array);
Expand Down
Loading

0 comments on commit b8e1a0a

Please sign in to comment.