Skip to content

Commit

Permalink
Rollback to NeoForge 20.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhailTapio committed Jan 18, 2024
1 parent ff44a3e commit d33cef1
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 42 deletions.
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repositories {
}

base {
archivesName = mod_id
archivesName = "${mod_name}-NeoForge-${neo_version}"
}

// Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17.
Expand Down Expand Up @@ -78,8 +78,7 @@ sourceSets.main.resources { srcDir 'src/generated/resources' }

dependencies {
implementation "net.neoforged:neoforge:${neo_version}"
compileOnly "top.theillusivec4.curios:curios-neoforge:${project.curios_version}"
// Curios is not updated to nf 20.4.80
runtimeOnly "top.theillusivec4.curios:curios-neoforge:${project.curios_version}"
compileOnly "top.theillusivec4.curios:curios-neoforge:${project.curios_version}:api"
}

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ neogradle.subsystems.parchment.mappingsVersion=2023.12.31
# The Minecraft version must agree with the Neo version to get a valid artifact
minecraft_version=1.20.4
# The Neo version must agree with the Minecraft version to get a valid artifact
neo_version=20.4.80-beta
neo_version=20.4.2-beta
# The loader version range can only use the major version of FML as bounds
loader_version_range=[2,)
loader_version_range=[1,2)
## Mod Properties
# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63}
# Must match the String constant located in the main mod class annotated with @Mod.
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/team/dovecotmc/glasses/Glasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.neoforged.fml.common.Mod;
import org.slf4j.Logger;
import team.dovecotmc.glasses.common.init.RegistryHandler;
import team.dovecotmc.glasses.common.network.handler.NetworkHandler;

@Mod(Glasses.MODID)
public class Glasses {
Expand All @@ -16,6 +17,7 @@ public class Glasses {
public Glasses(IEventBus bus) {
curiosLoaded = ModList.get().isLoaded("curios");
RegistryHandler.init(bus);
NetworkHandler.registerMessage();
}

public static boolean isCuriosLoaded() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.neoforged.neoforge.client.settings.KeyModifier;
import team.dovecotmc.glasses.Glasses;
import team.dovecotmc.glasses.client.integration.curios.GlassesRenderer;
import team.dovecotmc.glasses.common.network.handler.NetworkHandler;
import team.dovecotmc.glasses.common.network.msg.GlassesUseMessage;
import team.dovecotmc.glasses.util.client.ClientUtilities;
import team.dovecotmc.glasses.util.common.CommonUtilities;
Expand All @@ -26,7 +27,7 @@ public enum KeyBindingRef implements Supplier<KeyMapping> {
final LocalPlayer player = mc.player;
if (player == null) return;
CommonUtilities.getMatchedWearingItem(player, CommonUtilities.GLASSES)
.ifPresent($ -> player.connection.send(new GlassesUseMessage()));
.ifPresent($ -> NetworkHandler.INSTANCE.sendToServer(new GlassesUseMessage()));
}, false),
GLASSES_OFFSET_X_PLUS(new KeyMapping("key.glasses.offset.x_plus",
KeyConflictContext.IN_GAME,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
package team.dovecotmc.glasses.common.network.handler;

import net.minecraft.server.level.ServerPlayer;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent;
import net.neoforged.neoforge.network.registration.IPayloadRegistrar;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.neoforge.network.NetworkRegistry;
import net.neoforged.neoforge.network.simple.SimpleChannel;
import team.dovecotmc.glasses.Glasses;
import team.dovecotmc.glasses.common.item.base.GlassesItem;
import team.dovecotmc.glasses.common.network.msg.GlassesUseMessage;
import team.dovecotmc.glasses.util.common.CommonUtilities;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class NetworkHandler {
@SubscribeEvent
public static void registerPayload(RegisterPayloadHandlerEvent event) {
final IPayloadRegistrar registrar = event.registrar(Glasses.MODID);
registrar.play(GlassesUseMessage.ID, GlassesUseMessage::new, h -> h
.server((d, ctx) -> ctx.workHandler().submitAsync(() -> ctx.player().ifPresent(p -> {
if (!(p instanceof ServerPlayer player)) return;
CommonUtilities.getMatchedWearingItem(player, CommonUtilities.GLASSES).ifPresent(m -> {
if (m.getItem() instanceof GlassesItem g
&& (g.getProperties().packetAction() != null
|| g.getProperties().canUse()))
g.onReceivePacket(player, m);
});
})).exceptionally(e -> {
Glasses.LOGGER.error("Error occurred while handling 'use' message for glasses", e);
return null;
}))
public static SimpleChannel INSTANCE;
public static final String VERSION = "1";
private static int id = 0;

public static int nextId() {
return id++;
}

public static void registerMessage() {
INSTANCE = NetworkRegistry.newSimpleChannel(
new ResourceLocation(Glasses.MODID, "use"),
() -> VERSION,
VERSION::equals,
VERSION::equals
);
INSTANCE.messageBuilder(GlassesUseMessage.class, nextId())
.encoder(GlassesUseMessage::toBytes)
.decoder(GlassesUseMessage::new)
.consumerMainThread(GlassesUseMessage::handler)
.add();
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
package team.dovecotmc.glasses.common.network.msg;

import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import team.dovecotmc.glasses.Glasses;

public class GlassesUseMessage implements CustomPacketPayload {
public static final ResourceLocation ID = new ResourceLocation(Glasses.MODID, "use");
import net.minecraft.server.level.ServerPlayer;
import net.neoforged.neoforge.network.NetworkEvent;
import team.dovecotmc.glasses.common.item.base.GlassesItem;
import team.dovecotmc.glasses.util.common.CommonUtilities;

public class GlassesUseMessage {
public GlassesUseMessage(FriendlyByteBuf buf) {
}

public GlassesUseMessage() {
}

@Override
public void write(FriendlyByteBuf pBuffer) {
public void toBytes(FriendlyByteBuf buf) {

}

@Override
public ResourceLocation id() {
return ID;
public void handler(NetworkEvent.Context ctx) {
ctx.enqueueWork(() -> {
final ServerPlayer player = ctx.getSender();
if (player == null) return;
CommonUtilities.getMatchedWearingItem(player, CommonUtilities.GLASSES).ifPresent(m -> {
if (m.getItem() instanceof GlassesItem g
&& (g.getProperties().packetAction() != null
|| g.getProperties().canUse()))
g.onReceivePacket(player, m);
});
});
ctx.setPacketHandled(true);
}
}

}

0 comments on commit d33cef1

Please sign in to comment.