From f90f747fd0995796550859de92975936f90cb9cd Mon Sep 17 00:00:00 2001 From: BlayTheNinth <1933180+BlayTheNinth@users.noreply.github.com> Date: Sat, 18 May 2024 15:19:41 +0200 Subject: [PATCH] wip: Port to Minecraft 1.20.6 --- CHANGELOG.md | 2 +- build.gradle | 4 +- .../mods/balm/fabric/FabricBalmHooks.java | 6 +- .../client/screen/FabricBalmScreens.java | 4 +- .../event/client/FabricBalmClientEvents.java | 4 +- .../balm/fabric/item/FabricBalmItems.java | 4 +- .../balm/fabric/menu/FabricBalmMenus.java | 6 +- .../fabric/network/FabricBalmNetworking.java | 127 ++++++--------- .../mods/balm/forge/ForgeBalmHooks.java | 14 +- .../forge/event/ForgeBalmClientEvents.java | 10 +- .../forge/network/ForgeBalmNetworking.java | 6 +- .../balm/forge/world/BalmBiomeModifier.java | 3 +- .../balm/forge/world/ForgeBalmWorldGen.java | 3 +- gradle.properties | 62 +++---- gradle/wrapper/gradle-wrapper.properties | 2 +- neoforge/build.gradle | 2 +- .../mods/balm/neoforge/NeoForgeBalmHooks.java | 8 +- .../client/NeoForgeBalmClientRuntime.java | 1 - .../client/screen/NeoForgeBalmScreens.java | 4 +- .../event/NeoForgeBalmClientEvents.java | 38 ++--- .../event/NeoForgeBalmCommonEvents.java | 42 +++-- .../network/NeoForgeBalmNetworking.java | 153 +++++++----------- .../neoforge/world/BalmBiomeModifier.java | 3 +- .../neoforge/world/NeoForgeBalmWorldGen.java | 5 +- .../{mods.toml => neoforge.mods.toml} | 0 settings.gradle | 2 +- .../balm/api/container/ContainerUtils.java | 2 +- .../balm/api/container/DefaultContainer.java | 9 +- .../api/container/ImplementedContainer.java | 9 +- .../mods/balm/api/menu/BalmMenuProvider.java | 10 +- .../mods/balm/api/network/BalmNetworking.java | 18 ++- .../ClientboundMessageRegistration.java | 12 +- .../balm/api/network/MessageRegistration.java | 31 ++-- .../ServerboundMessageRegistration.java | 12 +- .../balm/api/network/SyncConfigMessage.java | 18 ++- .../mods/balm/common/BalmBlockEntity.java | 15 +- .../mixin/ReloadableServerResourcesMixin.java | 6 +- 37 files changed, 292 insertions(+), 365 deletions(-) rename neoforge/src/main/resources/META-INF/{mods.toml => neoforge.mods.toml} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index f05a4e10..53f29224 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1 @@ -- Fixed item use events staying cancelled after one was cancelled \ No newline at end of file +- Updated to Minecraft 1.20.6 \ No newline at end of file diff --git a/build.gradle b/build.gradle index 5b3c675a..19005ab6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.2-SNAPSHOT' apply(false) + id 'fabric-loom' version '1.6-SNAPSHOT' apply(false) // id 'org.spongepowered.gradle.vanilla' version '0.2.1-SNAPSHOT' apply(false) // this causes ForgeGradle to fail in reobf id "org.jetbrains.gradle.plugin.idea-ext" version "1.1.7" // this is required for VanillaGradle and NeoForge to exist in harmony id 'org.spongepowered.mixin' version '0.7-SNAPSHOT' apply(false) @@ -74,7 +74,7 @@ subprojects { "pack_format_number": pack_format_number ] - filesMatching(['pack.mcmeta', 'fabric.mod.json', 'META-INF/mods.toml', '*.mixins.json']) { + filesMatching(['pack.mcmeta', 'fabric.mod.json', 'META-INF/mods.toml', 'META-INF/neoforge.mods.toml', '*.mixins.json']) { expand expandProps } inputs.properties(expandProps) diff --git a/fabric/src/main/java/net/blay09/mods/balm/fabric/FabricBalmHooks.java b/fabric/src/main/java/net/blay09/mods/balm/fabric/FabricBalmHooks.java index ff117f0f..bb6bdf42 100644 --- a/fabric/src/main/java/net/blay09/mods/balm/fabric/FabricBalmHooks.java +++ b/fabric/src/main/java/net/blay09/mods/balm/fabric/FabricBalmHooks.java @@ -12,6 +12,7 @@ import net.fabricmc.fabric.api.registry.FuelRegistry; import net.minecraft.core.BlockPos; import net.minecraft.core.Holder; +import net.minecraft.core.component.DataComponents; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.MinecraftServer; @@ -94,7 +95,7 @@ public DyeColor getColor(ItemStack itemStack) { @Override public boolean canItemsStack(ItemStack first, ItemStack second) { - return !first.isEmpty() && ItemStack.isSameItemSameTags(first, second); + return !first.isEmpty() && ItemStack.isSameItemSameComponents(first, second); } @Override @@ -168,7 +169,8 @@ public boolean isShield(ItemStack itemStack) { @Override public boolean isRepairable(ItemStack itemStack) { - return itemStack.getItem().canBeDepleted(); + final var repairCost = itemStack.getItem().components().get(DataComponents.REPAIR_COST); + return repairCost != null && repairCost > 0; } @Override diff --git a/fabric/src/main/java/net/blay09/mods/balm/fabric/client/screen/FabricBalmScreens.java b/fabric/src/main/java/net/blay09/mods/balm/fabric/client/screen/FabricBalmScreens.java index d52b7788..7716057f 100644 --- a/fabric/src/main/java/net/blay09/mods/balm/fabric/client/screen/FabricBalmScreens.java +++ b/fabric/src/main/java/net/blay09/mods/balm/fabric/client/screen/FabricBalmScreens.java @@ -3,8 +3,8 @@ import net.blay09.mods.balm.api.client.screen.BalmScreenFactory; import net.blay09.mods.balm.api.client.screen.BalmScreens; import net.fabricmc.fabric.api.client.screen.v1.Screens; -import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry; import net.minecraft.client.gui.components.AbstractWidget; +import net.minecraft.client.gui.screens.MenuScreens; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.MenuAccess; import net.minecraft.world.inventory.AbstractContainerMenu; @@ -15,7 +15,7 @@ public class FabricBalmScreens implements BalmScreens { @Override public > void registerScreen(Supplier> type, BalmScreenFactory screenFactory) { - ScreenRegistry.register(type.get(), screenFactory::create); + MenuScreens.register(type.get(), screenFactory::create); } @Override diff --git a/fabric/src/main/java/net/blay09/mods/balm/fabric/event/client/FabricBalmClientEvents.java b/fabric/src/main/java/net/blay09/mods/balm/fabric/event/client/FabricBalmClientEvents.java index 1348aafe..8a62ad16 100644 --- a/fabric/src/main/java/net/blay09/mods/balm/fabric/event/client/FabricBalmClientEvents.java +++ b/fabric/src/main/java/net/blay09/mods/balm/fabric/event/client/FabricBalmClientEvents.java @@ -189,8 +189,8 @@ public static void registerEvents(FabricBalmEvents events) { })); }); - events.registerEvent(ItemTooltipEvent.class, () -> ItemTooltipCallback.EVENT.register((stack, context, lines) -> { - final ItemTooltipEvent event = new ItemTooltipEvent(stack, Minecraft.getInstance().player, lines, context); + events.registerEvent(ItemTooltipEvent.class, () -> ItemTooltipCallback.EVENT.register((stack, context, flag, lines) -> { + final ItemTooltipEvent event = new ItemTooltipEvent(stack, Minecraft.getInstance().player, lines, flag); events.fireEventHandlers(event); })); diff --git a/fabric/src/main/java/net/blay09/mods/balm/fabric/item/FabricBalmItems.java b/fabric/src/main/java/net/blay09/mods/balm/fabric/item/FabricBalmItems.java index e40cc480..bb2e9ab7 100644 --- a/fabric/src/main/java/net/blay09/mods/balm/fabric/item/FabricBalmItems.java +++ b/fabric/src/main/java/net/blay09/mods/balm/fabric/item/FabricBalmItems.java @@ -5,7 +5,6 @@ import com.google.common.collect.Multimaps; import net.blay09.mods.balm.api.DeferredObject; import net.blay09.mods.balm.api.item.BalmItems; -import net.fabricmc.fabric.api.item.v1.FabricItemSettings; import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup; import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; import net.minecraft.core.Registry; @@ -15,7 +14,6 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.CreativeModeTab; -import net.minecraft.world.item.CreativeModeTabs; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ItemLike; @@ -34,7 +32,7 @@ public class FabricBalmItems implements BalmItems { @Override public Item.Properties itemProperties() { - return new FabricItemSettings(); + return new Item.Properties(); } @Override diff --git a/fabric/src/main/java/net/blay09/mods/balm/fabric/menu/FabricBalmMenus.java b/fabric/src/main/java/net/blay09/mods/balm/fabric/menu/FabricBalmMenus.java index eb4d979e..45109df5 100644 --- a/fabric/src/main/java/net/blay09/mods/balm/fabric/menu/FabricBalmMenus.java +++ b/fabric/src/main/java/net/blay09/mods/balm/fabric/menu/FabricBalmMenus.java @@ -3,7 +3,6 @@ import net.blay09.mods.balm.api.DeferredObject; import net.blay09.mods.balm.api.menu.BalmMenus; import net.blay09.mods.balm.api.menu.BalmMenuFactory; -import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.MenuType; @@ -12,7 +11,10 @@ public class FabricBalmMenus implements BalmMenus { @Override public DeferredObject> registerMenu(ResourceLocation identifier, BalmMenuFactory factory) { - return new DeferredObject<>(identifier, () -> ScreenHandlerRegistry.registerExtended(identifier, factory::create)).resolveImmediately(); + return new DeferredObject<>(identifier, () -> { + // return TODO Registry.register(Registries.MENU, identifier, MenuType.ANVIL); + return (MenuType) MenuType.ANVIL; + }).resolveImmediately(); } } diff --git a/fabric/src/main/java/net/blay09/mods/balm/fabric/network/FabricBalmNetworking.java b/fabric/src/main/java/net/blay09/mods/balm/fabric/network/FabricBalmNetworking.java index ab338a54..5ae44a80 100644 --- a/fabric/src/main/java/net/blay09/mods/balm/fabric/network/FabricBalmNetworking.java +++ b/fabric/src/main/java/net/blay09/mods/balm/fabric/network/FabricBalmNetworking.java @@ -1,19 +1,19 @@ package net.blay09.mods.balm.fabric.network; -import net.blay09.mods.balm.api.client.BalmClient; import net.blay09.mods.balm.api.menu.BalmMenuProvider; import net.blay09.mods.balm.api.network.BalmNetworking; import net.blay09.mods.balm.api.network.ClientboundMessageRegistration; import net.blay09.mods.balm.api.network.MessageRegistration; import net.blay09.mods.balm.api.network.ServerboundMessageRegistration; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; +import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.fabricmc.fabric.api.networking.v1.PlayerLookup; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory; import net.minecraft.core.BlockPos; -import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; @@ -25,21 +25,16 @@ import net.minecraft.world.inventory.AbstractContainerMenu; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.function.BiConsumer; import java.util.function.Function; public class FabricBalmNetworking implements BalmNetworking { - private static final Map, MessageRegistration> messagesByClass = new HashMap<>(); - private static final Map> messagesByIdentifier = new HashMap<>(); + private static final Map, MessageRegistration> messagesByType = new HashMap<>(); - private static final List> clientMessageRegistrations = new ArrayList<>(); - - private static Player replyPlayer; + private static PacketSender replyPacketSender; @Override public void allowClientOnly(String modId) { @@ -51,11 +46,11 @@ public void allowServerOnly(String modId) { @Override public void openGui(Player player, MenuProvider menuProvider) { - if (menuProvider instanceof BalmMenuProvider balmMenuProvider) { - player.openMenu(new ExtendedScreenHandlerFactory() { + if (menuProvider instanceof BalmMenuProvider balmMenuProvider) { + player.openMenu(new ExtendedScreenHandlerFactory<>() { @Override - public void writeScreenOpeningData(ServerPlayer player, FriendlyByteBuf buf) { - balmMenuProvider.writeScreenOpeningData(player, buf); + public Object getScreenOpeningData(ServerPlayer player) { + return balmMenuProvider.getScreenOpeningData(player); } @Override @@ -75,108 +70,76 @@ public AbstractContainerMenu createMenu(int i, Inventory inventory, Player playe } @Override - public void reply(T message) { - if (replyPlayer == null) { - throw new IllegalStateException("No player to reply to"); + public void reply(T message) { + if (replyPacketSender == null) { + throw new IllegalStateException("No context to reply to"); } - sendTo(replyPlayer, message); + replyPacketSender.sendPacket(message); } - @SuppressWarnings("unchecked") @Override - public void sendTo(Player player, T message) { - MessageRegistration messageRegistration = (MessageRegistration) messagesByClass.get(message.getClass()); - ResourceLocation identifier = messageRegistration.getIdentifier(); - FriendlyByteBuf buf = PacketByteBufs.create(); - messageRegistration.getEncodeFunc().accept(message, buf); - ServerPlayNetworking.send((ServerPlayer) player, identifier, buf); + public void sendTo(Player player, T message) { + ServerPlayNetworking.send((ServerPlayer) player, message); } - @SuppressWarnings("unchecked") @Override - public void sendToTracking(ServerLevel world, BlockPos pos, T message) { - MessageRegistration messageRegistration = (MessageRegistration) messagesByClass.get(message.getClass()); - ResourceLocation identifier = messageRegistration.getIdentifier(); - FriendlyByteBuf buf = PacketByteBufs.create(); - messageRegistration.getEncodeFunc().accept(message, buf); + public void sendToTracking(ServerLevel world, BlockPos pos, T message) { for (ServerPlayer player : PlayerLookup.tracking(world, pos)) { - ServerPlayNetworking.send(player, identifier, buf); + ServerPlayNetworking.send(player, message); } } - @SuppressWarnings("unchecked") @Override - public void sendToTracking(Entity entity, T message) { - MessageRegistration messageRegistration = (MessageRegistration) messagesByClass.get(message.getClass()); - ResourceLocation identifier = messageRegistration.getIdentifier(); - FriendlyByteBuf buf = PacketByteBufs.create(); - messageRegistration.getEncodeFunc().accept(message, buf); + public void sendToTracking(Entity entity, T message) { for (ServerPlayer player : PlayerLookup.tracking(entity)) { - ServerPlayNetworking.send(player, identifier, buf); + ServerPlayNetworking.send(player, message); } } - @SuppressWarnings("unchecked") @Override - public void sendToAll(MinecraftServer server, T message) { - MessageRegistration messageRegistration = (MessageRegistration) messagesByClass.get(message.getClass()); - ResourceLocation identifier = messageRegistration.getIdentifier(); - FriendlyByteBuf buf = PacketByteBufs.create(); - messageRegistration.getEncodeFunc().accept(message, buf); + public void sendToAll(MinecraftServer server, T message) { for (ServerPlayer player : PlayerLookup.all(server)) { - ServerPlayNetworking.send(player, identifier, buf); + ServerPlayNetworking.send(player, message); } } - @SuppressWarnings("unchecked") @Override - public void sendToServer(T message) { - MessageRegistration messageRegistration = (MessageRegistration) messagesByClass.get(message.getClass()); - ResourceLocation identifier = messageRegistration.getIdentifier(); - FriendlyByteBuf buf = PacketByteBufs.create(); - messageRegistration.getEncodeFunc().accept(message, buf); - ClientPlayNetworking.send(identifier, buf); + public void sendToServer(T message) { + ClientPlayNetworking.send(message); } @Override - public void registerClientboundPacket(ResourceLocation identifier, Class clazz, BiConsumer encodeFunc, Function decodeFunc, BiConsumer handler) { - ClientboundMessageRegistration messageRegistration = new ClientboundMessageRegistration<>(identifier, clazz, encodeFunc, decodeFunc, handler); - - messagesByClass.put(clazz, messageRegistration); - messagesByIdentifier.put(identifier, messageRegistration); - - clientMessageRegistrations.add(messageRegistration); + public void registerClientboundPacket(ResourceLocation identifier, Class clazz, BiConsumer encodeFunc, Function decodeFunc, BiConsumer handler) { + final var type = new CustomPacketPayload.Type(identifier); + final var messageRegistration = new ClientboundMessageRegistration<>(type, clazz, encodeFunc, decodeFunc, handler); + messagesByType.put(type, messageRegistration); } @Override - public void registerServerboundPacket(ResourceLocation identifier, Class clazz, BiConsumer encodeFunc, Function decodeFunc, BiConsumer handler) { - MessageRegistration messageRegistration = new ServerboundMessageRegistration<>(identifier, clazz, encodeFunc, decodeFunc, handler); - - messagesByClass.put(clazz, messageRegistration); - messagesByIdentifier.put(identifier, messageRegistration); - ServerPlayNetworking.registerGlobalReceiver(identifier, ((server, player, listener, buf, responseSender) -> { - T message = messageRegistration.getDecodeFunc().apply(buf); - server.execute(() -> { - replyPlayer = player; - handler.accept(player, message); - replyPlayer = null; - }); - })); + public void registerServerboundPacket(ResourceLocation identifier, Class clazz, BiConsumer encodeFunc, Function decodeFunc, BiConsumer handler) { + final var type = new CustomPacketPayload.Type(identifier); + final var messageRegistration = new ServerboundMessageRegistration<>(type, clazz, encodeFunc, decodeFunc, handler); + messagesByType.put(type, messageRegistration); + + ServerPlayNetworking.registerGlobalReceiver(type, ((payload, context) -> context.player().getServer().execute(() -> { + replyPacketSender = context.responseSender(); + handler.accept(context.player(), payload); + replyPacketSender = null; + }))); } public static void initializeClientHandlers() { - for (ClientboundMessageRegistration message : clientMessageRegistrations) { - registerClientHandler(message); + for (final var messageRegistration : messagesByType.values()) { + if (messageRegistration instanceof ClientboundMessageRegistration clientboundMessageRegistration) { + registerClientHandler(clientboundMessageRegistration); + } } } - private static void registerClientHandler(ClientboundMessageRegistration messageRegistration) { - ResourceLocation identifier = messageRegistration.getIdentifier(); - BiConsumer handler = messageRegistration.getHandler(); - ClientPlayNetworking.registerGlobalReceiver(identifier, ((client, listener, buf, responseSender) -> { - T message = messageRegistration.getDecodeFunc().apply(buf); - client.execute(() -> handler.accept(BalmClient.getClientPlayer(), message)); - })); + private static void registerClientHandler(ClientboundMessageRegistration messageRegistration) { + final var type = messageRegistration.getType(); + BiConsumer handler = messageRegistration.getHandler(); + ClientPlayNetworking.registerGlobalReceiver(type, ((payload, context) -> context.client().execute(() -> handler.accept(context.player(), payload)))); } } diff --git a/forge/src/main/java/net/blay09/mods/balm/forge/ForgeBalmHooks.java b/forge/src/main/java/net/blay09/mods/balm/forge/ForgeBalmHooks.java index aa834f37..3852b775 100644 --- a/forge/src/main/java/net/blay09/mods/balm/forge/ForgeBalmHooks.java +++ b/forge/src/main/java/net/blay09/mods/balm/forge/ForgeBalmHooks.java @@ -4,6 +4,7 @@ import net.blay09.mods.balm.api.entity.BalmEntity; import net.minecraft.core.BlockPos; import net.minecraft.core.Holder; +import net.minecraft.core.component.DataComponents; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.MinecraftServer; import net.minecraft.util.RandomSource; @@ -48,12 +49,6 @@ public boolean growCrop(ItemStack itemStack, Level level, BlockPos pos, Player p @Override public CompoundTag getPersistentData(Entity entity) { CompoundTag persistentData = entity.getPersistentData(); - if (entity instanceof Player) { - CompoundTag persistedTag = persistentData.getCompound(Player.PERSISTED_NBT_TAG); - persistentData.put(Player.PERSISTED_NBT_TAG, persistedTag); - persistentData = persistedTag; - } - CompoundTag balmData = persistentData.getCompound("BalmData"); if (balmData.isEmpty()) { // If we have no data, try to import from Fabric in case the world was migrated @@ -68,7 +63,7 @@ public CompoundTag getPersistentData(Entity entity) { @Override public void curePotionEffects(LivingEntity entity, ItemStack curativeItem) { - entity.curePotionEffects(curativeItem); + entity.removeAllEffects(); } @Override @@ -113,7 +108,8 @@ public boolean isShield(ItemStack itemStack) { @Override public boolean isRepairable(ItemStack itemStack) { - return itemStack.isRepairable(); + final var repairCost = itemStack.getItem().components().get(DataComponents.REPAIR_COST); + return repairCost != null && repairCost > 0; } @Override @@ -128,6 +124,6 @@ public MinecraftServer getServer() { @Override public double getBlockReachDistance(Player player) { - return player.getBlockReach(); + return 4.5 + (player.isCreative() ? 0.5 : 0); } } diff --git a/forge/src/main/java/net/blay09/mods/balm/forge/event/ForgeBalmClientEvents.java b/forge/src/main/java/net/blay09/mods/balm/forge/event/ForgeBalmClientEvents.java index c727fecd..bd6cf047 100644 --- a/forge/src/main/java/net/blay09/mods/balm/forge/event/ForgeBalmClientEvents.java +++ b/forge/src/main/java/net/blay09/mods/balm/forge/event/ForgeBalmClientEvents.java @@ -9,8 +9,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.core.RegistryAccess; import net.minecraftforge.client.event.*; -import net.minecraftforge.client.gui.overlay.NamedGuiOverlay; -import net.minecraftforge.client.gui.overlay.VanillaGuiOverlay; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.TickEvent; import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent; @@ -346,7 +344,7 @@ public static void registerEvents(ForgeBalmEvents events) { }); }); - events.registerEvent(GuiDrawEvent.Pre.class, priority -> { + /*events.registerEvent(GuiDrawEvent.Pre.class, priority -> { TODO MinecraftForge.EVENT_BUS.addListener(ForgeBalmEvents.toForge(priority), (RenderGuiEvent.Pre orig) -> { final GuiDrawEvent.Pre event = new GuiDrawEvent.Pre(orig.getWindow(), orig.getGuiGraphics(), GuiDrawEvent.Element.ALL); events.fireEventHandlers(priority, event); @@ -380,10 +378,10 @@ public static void registerEvents(ForgeBalmEvents events) { events.fireEventHandlers(priority, event); } }); - }); + });*/ } - @Nullable + /*@Nullable private static GuiDrawEvent.Element getGuiDrawEventElement(RenderGuiOverlayEvent orig) { GuiDrawEvent.Element type = null; NamedGuiOverlay overlay = orig.getOverlay(); @@ -399,5 +397,5 @@ private static GuiDrawEvent.Element getGuiDrawEventElement(RenderGuiOverlayEvent type = GuiDrawEvent.Element.PLAYER_LIST; } return type; - } + }*/ } diff --git a/forge/src/main/java/net/blay09/mods/balm/forge/network/ForgeBalmNetworking.java b/forge/src/main/java/net/blay09/mods/balm/forge/network/ForgeBalmNetworking.java index a00babe4..fcbd1415 100644 --- a/forge/src/main/java/net/blay09/mods/balm/forge/network/ForgeBalmNetworking.java +++ b/forge/src/main/java/net/blay09/mods/balm/forge/network/ForgeBalmNetworking.java @@ -7,7 +7,7 @@ import net.blay09.mods.balm.api.network.MessageRegistration; import net.blay09.mods.balm.api.network.ServerboundMessageRegistration; import net.minecraft.core.BlockPos; -import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; @@ -136,7 +136,7 @@ private MessageRegistration getMessageRegistrationOrThrow(T message) { } @Override - public void registerClientboundPacket(ResourceLocation identifier, Class clazz, BiConsumer encodeFunc, Function decodeFunc, BiConsumer handler) { + public void registerClientboundPacket(ResourceLocation identifier, Class clazz, BiConsumer encodeFunc, Function decodeFunc, BiConsumer handler) { ClientboundMessageRegistration messageRegistration = new ClientboundMessageRegistration<>(identifier, clazz, encodeFunc, decodeFunc, handler); messagesByClass.put(clazz, messageRegistration); @@ -151,7 +151,7 @@ public void registerClientboundPacket(ResourceLocation identifier, Class } @Override - public void registerServerboundPacket(ResourceLocation identifier, Class clazz, BiConsumer encodeFunc, Function decodeFunc, BiConsumer handler) { + public void registerServerboundPacket(ResourceLocation identifier, Class clazz, BiConsumer encodeFunc, Function decodeFunc, BiConsumer handler) { MessageRegistration messageRegistration = new ServerboundMessageRegistration<>(identifier, clazz, encodeFunc, decodeFunc, handler); messagesByClass.put(clazz, messageRegistration); diff --git a/forge/src/main/java/net/blay09/mods/balm/forge/world/BalmBiomeModifier.java b/forge/src/main/java/net/blay09/mods/balm/forge/world/BalmBiomeModifier.java index 08275d67..20c08956 100644 --- a/forge/src/main/java/net/blay09/mods/balm/forge/world/BalmBiomeModifier.java +++ b/forge/src/main/java/net/blay09/mods/balm/forge/world/BalmBiomeModifier.java @@ -1,6 +1,7 @@ package net.blay09.mods.balm.forge.world; import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; import net.blay09.mods.balm.api.Balm; import net.minecraft.core.Holder; import net.minecraft.world.level.biome.Biome; @@ -18,7 +19,7 @@ public void modify(Holder biome, Phase phase, ModifiableBiomeInfo.BiomeIn } @Override - public Codec codec() { + public MapCodec codec() { return ForgeBalmWorldGen.BALM_BIOME_MODIFIER_CODEC; } diff --git a/forge/src/main/java/net/blay09/mods/balm/forge/world/ForgeBalmWorldGen.java b/forge/src/main/java/net/blay09/mods/balm/forge/world/ForgeBalmWorldGen.java index 787ed26e..e50ebfb5 100644 --- a/forge/src/main/java/net/blay09/mods/balm/forge/world/ForgeBalmWorldGen.java +++ b/forge/src/main/java/net/blay09/mods/balm/forge/world/ForgeBalmWorldGen.java @@ -1,6 +1,7 @@ package net.blay09.mods.balm.forge.world; import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; import net.blay09.mods.balm.api.DeferredObject; import net.blay09.mods.balm.api.world.BalmWorldGen; import net.blay09.mods.balm.api.world.BiomePredicate; @@ -51,7 +52,7 @@ public void commonSetup(FMLCommonSetupEvent event) { } } - public static final Codec BALM_BIOME_MODIFIER_CODEC = Codec.unit(BalmBiomeModifier.INSTANCE); + public static final MapCodec BALM_BIOME_MODIFIER_CODEC = MapCodec.unit(BalmBiomeModifier.INSTANCE); private final Map registrations = new ConcurrentHashMap<>(); public ForgeBalmWorldGen() { diff --git a/gradle.properties b/gradle.properties index 5b1c9f1e..97a43b91 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,46 +1,46 @@ # Mod -mod_id=balm -mod_name=Balm -description=Abstraction Layer (but not really) for Blay's multiplatform mods -version = 9.0.9 -group=net.blay09.mods -license=All Rights Reserved +mod_id = balm +mod_name = Balm +description = Abstraction Layer (but not really) for Blay's multiplatform mods +version = 10.0.0 +group = net.blay09.mods +license = All Rights Reserved # Publishing -curseforge_release_type=release -curseforge_forge_project_id=531761 -curseforge_fabric_project_id=500525 -modrinth_release_type=release -modrinth_project_id=MBAkmtvl +curseforge_release_type = release +curseforge_forge_project_id = 531761 +curseforge_fabric_project_id = 500525 +modrinth_release_type = release +modrinth_project_id = MBAkmtvl # Minecraft -minecraft_version = 1.20.4 -minecraft_versions = 1.20.4 -minecraft_version_range=[1.20.4,1.21) -pack_format_number=18 -java_version = 17 +minecraft_version = 1.20.6 +minecraft_versions = 1.20.6 +minecraft_version_range = [1.20.6,1.21) +pack_format_number = 18 +java_version = 21 # Forge -forge_version = 49.0.10 -forge_version_range=[49,) -forge_loader_version_range=[49,) +forge_version = 50.0.22 +forge_version_range = [50,) +forge_loader_version_range = [50,) # NeoForge -neoforge_version = 20.4.96-beta -neoforge_version_range=[20.4,) -neoforge_loader_version_range=[1,) +neoforge_version = 20.6.70-beta +neoforge_version_range = [20.6,) +neoforge_loader_version_range = [1,) # Fabric -fabric_version = 0.91.3+1.20.4 -fabric_loader_version = 0.15.3 +fabric_version = 0.98.0+1.20.6 +fabric_loader_version = 0.15.11 # Dependencies -jei_minecraft_version=1.19.2 -jei_version=11.4.0.288 -rei_version=10.0.581 -mixin_version=0.8.5 -modmenu_version=9.0.0 +jei_minecraft_version = 1.19.2 +jei_version = 11.4.0.288 +rei_version = 10.0.581 +mixin_version = 0.8.5 +modmenu_version = 9.0.0 # Gradle -org.gradle.jvmargs=-Xmx3G -org.gradle.daemon=false +org.gradle.jvmargs = -Xmx3G +org.gradle.daemon = false diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fae08049..48c0a02c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/neoforge/build.gradle b/neoforge/build.gradle index 7d7e68de..112c8e50 100644 --- a/neoforge/build.gradle +++ b/neoforge/build.gradle @@ -2,7 +2,7 @@ plugins { id 'java-library' id 'idea' id 'maven-publish' - id 'net.neoforged.gradle.userdev' version '7.0.41' + id 'net.neoforged.gradle.userdev' version '7.0.124' id 'net.darkhax.curseforgegradle' id "com.modrinth.minotaur" } diff --git a/neoforge/src/main/java/net/blay09/mods/balm/neoforge/NeoForgeBalmHooks.java b/neoforge/src/main/java/net/blay09/mods/balm/neoforge/NeoForgeBalmHooks.java index c1c61640..50f06c0e 100644 --- a/neoforge/src/main/java/net/blay09/mods/balm/neoforge/NeoForgeBalmHooks.java +++ b/neoforge/src/main/java/net/blay09/mods/balm/neoforge/NeoForgeBalmHooks.java @@ -4,6 +4,7 @@ import net.blay09.mods.balm.api.entity.BalmEntity; import net.minecraft.core.BlockPos; import net.minecraft.core.Holder; +import net.minecraft.core.component.DataComponents; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.MinecraftServer; import net.minecraft.util.RandomSource; @@ -13,6 +14,7 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.Pose; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.ItemCombinerMenu; import net.minecraft.world.item.BoneMealItem; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.ItemStack; @@ -93,12 +95,12 @@ public DyeColor getColor(ItemStack itemStack) { @Override public boolean canItemsStack(ItemStack first, ItemStack second) { - return ItemHandlerHelper.canItemStacksStack(first, second); + return ItemStack.isSameItemSameComponents(first, second); } @Override public int getBurnTime(ItemStack itemStack) { - return CommonHooks.getBurnTime(itemStack, RecipeType.SMELTING); + return itemStack.getBurnTime(RecipeType.SMELTING); } @Override @@ -133,6 +135,6 @@ public MinecraftServer getServer() { @Override public double getBlockReachDistance(Player player) { - return player.getBlockReach(); + return 4.5 + (player.isCreative() ? 0.5 : 0); } } diff --git a/neoforge/src/main/java/net/blay09/mods/balm/neoforge/client/NeoForgeBalmClientRuntime.java b/neoforge/src/main/java/net/blay09/mods/balm/neoforge/client/NeoForgeBalmClientRuntime.java index c9ad217b..a6bfec0a 100644 --- a/neoforge/src/main/java/net/blay09/mods/balm/neoforge/client/NeoForgeBalmClientRuntime.java +++ b/neoforge/src/main/java/net/blay09/mods/balm/neoforge/client/NeoForgeBalmClientRuntime.java @@ -1,7 +1,6 @@ package net.blay09.mods.balm.neoforge.client; import net.blay09.mods.balm.api.Balm; -import net.blay09.mods.balm.api.BalmRuntimeLoadContext; import net.blay09.mods.balm.api.client.BalmClientRuntime; import net.blay09.mods.balm.api.client.keymappings.BalmKeyMappings; import net.blay09.mods.balm.api.client.rendering.BalmModels; diff --git a/neoforge/src/main/java/net/blay09/mods/balm/neoforge/client/screen/NeoForgeBalmScreens.java b/neoforge/src/main/java/net/blay09/mods/balm/neoforge/client/screen/NeoForgeBalmScreens.java index 680b2e81..a3ec6a66 100644 --- a/neoforge/src/main/java/net/blay09/mods/balm/neoforge/client/screen/NeoForgeBalmScreens.java +++ b/neoforge/src/main/java/net/blay09/mods/balm/neoforge/client/screen/NeoForgeBalmScreens.java @@ -8,6 +8,8 @@ import net.minecraft.client.gui.screens.MenuScreens; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.MenuAccess; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.Registries; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.MenuType; import net.neoforged.bus.api.IEventBus; @@ -43,7 +45,7 @@ public > void } private static > void registerScreenImmediate(Supplier> type, BalmScreenFactory screenFactory) { - MenuScreens.register(type.get(), screenFactory::create); + // TODO MenuScreens.register(type.get(), screenFactory::create); } @Override diff --git a/neoforge/src/main/java/net/blay09/mods/balm/neoforge/event/NeoForgeBalmClientEvents.java b/neoforge/src/main/java/net/blay09/mods/balm/neoforge/event/NeoForgeBalmClientEvents.java index da298dbe..b6e0f196 100644 --- a/neoforge/src/main/java/net/blay09/mods/balm/neoforge/event/NeoForgeBalmClientEvents.java +++ b/neoforge/src/main/java/net/blay09/mods/balm/neoforge/event/NeoForgeBalmClientEvents.java @@ -7,45 +7,39 @@ import net.blay09.mods.balm.api.event.client.RenderHandEvent; import net.blay09.mods.balm.api.event.client.screen.*; import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.core.RegistryAccess; import net.neoforged.bus.api.Event; import net.neoforged.fml.event.lifecycle.FMLLoadCompleteEvent; import net.neoforged.fml.javafmlmod.FMLJavaModLoadingContext; import net.neoforged.neoforge.client.event.*; -import net.neoforged.neoforge.client.gui.overlay.NamedGuiOverlay; -import net.neoforged.neoforge.client.gui.overlay.VanillaGuiOverlay; import net.neoforged.neoforge.common.NeoForge; -import net.neoforged.neoforge.event.TickEvent; -import org.jetbrains.annotations.Nullable; +import net.neoforged.neoforge.event.tick.LevelTickEvent; public class NeoForgeBalmClientEvents { public static void registerEvents(NeoForgeBalmEvents events) { events.registerTickEvent(TickType.Client, TickPhase.Start, (ClientTickHandler handler) -> { - NeoForge.EVENT_BUS.addListener((TickEvent.ClientTickEvent orig) -> { - if (orig.phase == TickEvent.Phase.START) { - handler.handle(Minecraft.getInstance()); - } + NeoForge.EVENT_BUS.addListener((ClientTickEvent.Pre orig) -> { + handler.handle(Minecraft.getInstance()); }); }); events.registerTickEvent(TickType.Client, TickPhase.End, (ClientTickHandler handler) -> { - NeoForge.EVENT_BUS.addListener((TickEvent.ClientTickEvent orig) -> { - if (orig.phase == TickEvent.Phase.END) { - handler.handle(Minecraft.getInstance()); - } + NeoForge.EVENT_BUS.addListener((ClientTickEvent.Post orig) -> { + handler.handle(Minecraft.getInstance()); }); }); events.registerTickEvent(TickType.ClientLevel, TickPhase.Start, (ClientLevelTickHandler handler) -> { - NeoForge.EVENT_BUS.addListener((TickEvent.ClientTickEvent orig) -> { - if (orig.phase == TickEvent.Phase.START) { - handler.handle(Minecraft.getInstance().level); + NeoForge.EVENT_BUS.addListener((LevelTickEvent.Pre orig) -> { + if (orig.getLevel() instanceof ClientLevel clientLevel) { + handler.handle(clientLevel); } }); }); events.registerTickEvent(TickType.ClientLevel, TickPhase.End, (ClientLevelTickHandler handler) -> { - NeoForge.EVENT_BUS.addListener((TickEvent.ClientTickEvent orig) -> { - if (orig.phase == TickEvent.Phase.END) { - handler.handle(Minecraft.getInstance().level); + NeoForge.EVENT_BUS.addListener((LevelTickEvent.Post orig) -> { + if (orig.getLevel() instanceof ClientLevel clientLevel) { + handler.handle(clientLevel); } }); }); @@ -344,7 +338,7 @@ public static void registerEvents(NeoForgeBalmEvents events) { }); }); - events.registerEvent(GuiDrawEvent.Pre.class, priority -> { + /* TODO events.registerEvent(GuiDrawEvent.Pre.class, priority -> { NeoForge.EVENT_BUS.addListener(NeoForgeBalmEvents.toForge(priority), (RenderGuiEvent.Pre orig) -> { final GuiDrawEvent.Pre event = new GuiDrawEvent.Pre(orig.getWindow(), orig.getGuiGraphics(), GuiDrawEvent.Element.ALL); events.fireEventHandlers(priority, event); @@ -378,10 +372,10 @@ public static void registerEvents(NeoForgeBalmEvents events) { events.fireEventHandlers(priority, event); } }); - }); + }); */ } - @Nullable + /*@Nullable TODO ugh private static GuiDrawEvent.Element getGuiDrawEventElement(RenderGuiOverlayEvent orig) { GuiDrawEvent.Element type = null; NamedGuiOverlay overlay = orig.getOverlay(); @@ -397,5 +391,5 @@ private static GuiDrawEvent.Element getGuiDrawEventElement(RenderGuiOverlayEvent type = GuiDrawEvent.Element.PLAYER_LIST; } return type; - } + }*/ } diff --git a/neoforge/src/main/java/net/blay09/mods/balm/neoforge/event/NeoForgeBalmCommonEvents.java b/neoforge/src/main/java/net/blay09/mods/balm/neoforge/event/NeoForgeBalmCommonEvents.java index aadec705..bb65747f 100644 --- a/neoforge/src/main/java/net/blay09/mods/balm/neoforge/event/NeoForgeBalmCommonEvents.java +++ b/neoforge/src/main/java/net/blay09/mods/balm/neoforge/event/NeoForgeBalmCommonEvents.java @@ -4,65 +4,63 @@ import net.blay09.mods.balm.api.event.*; import net.blay09.mods.balm.api.event.server.ServerStartedEvent; import net.blay09.mods.balm.api.event.server.ServerStoppedEvent; +import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.neoforged.bus.api.Event; -import net.neoforged.fml.LogicalSide; import net.neoforged.neoforge.common.NeoForge; -import net.neoforged.neoforge.event.TickEvent; import net.neoforged.neoforge.event.entity.item.ItemTossEvent; import net.neoforged.neoforge.event.entity.player.AttackEntityEvent; import net.neoforged.neoforge.event.entity.player.PlayerEvent; import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent; import net.neoforged.neoforge.event.level.BlockEvent; import net.neoforged.neoforge.event.level.ChunkWatchEvent; +import net.neoforged.neoforge.event.tick.LevelTickEvent; +import net.neoforged.neoforge.event.tick.PlayerTickEvent; +import net.neoforged.neoforge.event.tick.ServerTickEvent; import net.neoforged.neoforge.server.ServerLifecycleHooks; public class NeoForgeBalmCommonEvents { public static void registerEvents(NeoForgeBalmEvents events) { events.registerTickEvent(TickType.Server, TickPhase.Start, (ServerTickHandler handler) -> { - NeoForge.EVENT_BUS.addListener((TickEvent.ServerTickEvent orig) -> { - if (orig.phase == TickEvent.Phase.START) { - handler.handle(ServerLifecycleHooks.getCurrentServer()); - } + NeoForge.EVENT_BUS.addListener((ServerTickEvent.Pre orig) -> { + handler.handle(ServerLifecycleHooks.getCurrentServer()); }); }); events.registerTickEvent(TickType.Server, TickPhase.End, (ServerTickHandler handler) -> { - NeoForge.EVENT_BUS.addListener((TickEvent.ServerTickEvent orig) -> { - if (orig.phase == TickEvent.Phase.END) { - handler.handle(ServerLifecycleHooks.getCurrentServer()); - } + NeoForge.EVENT_BUS.addListener((ServerTickEvent orig) -> { + handler.handle(ServerLifecycleHooks.getCurrentServer()); }); }); events.registerTickEvent(TickType.ServerLevel, TickPhase.Start, (ServerLevelTickHandler handler) -> { - NeoForge.EVENT_BUS.addListener((TickEvent.LevelTickEvent orig) -> { - if (orig.phase == TickEvent.Phase.START && orig.side == LogicalSide.SERVER) { - handler.handle(orig.level); + NeoForge.EVENT_BUS.addListener((LevelTickEvent.Pre orig) -> { + if (orig.getLevel() instanceof ServerLevel serverLevel) { + handler.handle(serverLevel); } }); }); events.registerTickEvent(TickType.ServerLevel, TickPhase.End, (ServerLevelTickHandler handler) -> { - NeoForge.EVENT_BUS.addListener((TickEvent.LevelTickEvent orig) -> { - if (orig.phase == TickEvent.Phase.END && orig.side == LogicalSide.SERVER) { - handler.handle(orig.level); + NeoForge.EVENT_BUS.addListener((LevelTickEvent.Post orig) -> { + if (orig.getLevel() instanceof ServerLevel serverLevel) { + handler.handle(serverLevel); } }); }); events.registerTickEvent(TickType.ServerPlayer, TickPhase.Start, (ServerPlayerTickHandler handler) -> { - NeoForge.EVENT_BUS.addListener((TickEvent.PlayerTickEvent orig) -> { - if (orig.phase == TickEvent.Phase.START && orig.side == LogicalSide.SERVER) { - handler.handle(((ServerPlayer) orig.player)); + NeoForge.EVENT_BUS.addListener((PlayerTickEvent.Pre orig) -> { + if (orig.getEntity() instanceof ServerPlayer serverPlayer) { + handler.handle(serverPlayer); } }); }); events.registerTickEvent(TickType.ServerPlayer, TickPhase.End, (ServerPlayerTickHandler handler) -> { - NeoForge.EVENT_BUS.addListener((TickEvent.PlayerTickEvent orig) -> { - if (orig.phase == TickEvent.Phase.END && orig.side == LogicalSide.SERVER) { - handler.handle(((ServerPlayer) orig.player)); + NeoForge.EVENT_BUS.addListener((PlayerTickEvent.Post orig) -> { + if (orig.getEntity() instanceof ServerPlayer serverPlayer) { + handler.handle(serverPlayer); } }); }); diff --git a/neoforge/src/main/java/net/blay09/mods/balm/neoforge/network/NeoForgeBalmNetworking.java b/neoforge/src/main/java/net/blay09/mods/balm/neoforge/network/NeoForgeBalmNetworking.java index b994fff0..3cf2d84f 100644 --- a/neoforge/src/main/java/net/blay09/mods/balm/neoforge/network/NeoForgeBalmNetworking.java +++ b/neoforge/src/main/java/net/blay09/mods/balm/neoforge/network/NeoForgeBalmNetworking.java @@ -8,6 +8,7 @@ import net.blay09.mods.balm.api.network.ServerboundMessageRegistration; import net.minecraft.core.BlockPos; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; @@ -16,13 +17,16 @@ import net.minecraft.world.MenuProvider; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.ChunkPos; import net.neoforged.bus.api.IEventBus; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.ModLoadingContext; import net.neoforged.neoforge.network.PacketDistributor; -import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent; -import net.neoforged.neoforge.network.handling.IReplyHandler; -import net.neoforged.neoforge.network.handling.PlayPayloadContext; +import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; +import net.neoforged.neoforge.network.handling.IPayloadContext; +import net.neoforged.neoforge.network.handling.IPayloadHandler; +import net.neoforged.neoforge.network.handling.MainThreadPayloadHandler; +import net.neoforged.neoforge.network.registration.PayloadRegistrar; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,27 +39,9 @@ public class NeoForgeBalmNetworking implements BalmNetworking { private static final Logger logger = LoggerFactory.getLogger(NeoForgeBalmNetworking.class); - /** - * TODO remove in 1.20.5 and make all packets implement CustomPacketPayload - * - * @deprecated workaround to account for this mid-version breaking change without having to update 152518 mods - */ - @Deprecated - private record WrappedPacket(ResourceLocation id, Object message, BiConsumer encoder) implements CustomPacketPayload { - @Override - public void write(FriendlyByteBuf buf) { - encoder.accept(message, buf); - } - - @Override - public ResourceLocation id() { - return id; - } - } - private static class Registrations { private final String modId; - private final Map> messagesByIdentifier = new ConcurrentHashMap<>(); + private final Map, MessageRegistration> playMessagesByType = new ConcurrentHashMap<>(); private boolean optional; private Registrations(String modId) { @@ -63,33 +49,18 @@ private Registrations(String modId) { } @SubscribeEvent - @SuppressWarnings("unchecked") - public void registerPayloadHandlers(final RegisterPayloadHandlerEvent event) { + public void registerPayloadHandlers(final RegisterPayloadHandlersEvent event) { var registrar = event.registrar(modId); if (optional) { registrar = registrar.optional(); } - for (final var entry : messagesByIdentifier.entrySet()) { - final var messageId = entry.getKey(); + for (final var entry : playMessagesByType.entrySet()) { final var messageRegistration = entry.getValue(); - registrar = registrar.play(messageId, (FriendlyByteBuf.Reader) buf -> { - final var message = messageRegistration.getDecodeFunc().apply(buf); - return new WrappedPacket(messageId, message, (BiConsumer) messageRegistration.getEncodeFunc()); - }, it -> { - if (messageRegistration instanceof ServerboundMessageRegistration serverboundMessageRegistration) { - it.server((payload, context) -> context.workHandler().execute(() -> { - replyHandler = context.replyHandler(); - handleServerboundPacket(serverboundMessageRegistration, payload, context); - replyHandler = null; - })); - } else if (messageRegistration instanceof ClientboundMessageRegistration clientboundMessageRegistration) { - it.client(((payload, context) -> context.workHandler().execute(() -> { - replyHandler = context.replyHandler(); - handleClientboundPacket(clientboundMessageRegistration, payload, context); - replyHandler = null; - }))); - } - }); + if (messageRegistration instanceof ServerboundMessageRegistration serverboundMessageRegistration) { + registrar = playToServer(registrar, serverboundMessageRegistration); + } else if (messageRegistration instanceof ClientboundMessageRegistration clientboundMessageRegistration) { + registrar = playToClient(registrar, clientboundMessageRegistration); + } } } @@ -100,27 +71,35 @@ public void allowClientOnly() { public void allowServerOnly() { optional = true; } - } - @SuppressWarnings("unchecked") - private static void handleServerboundPacket(ServerboundMessageRegistration registration, CustomPacketPayload payload, PlayPayloadContext context) { - final var player = context.player().orElse(null); - if (payload instanceof WrappedPacket wrappedPacket && player instanceof ServerPlayer serverPlayer) { - registration.getHandler().accept(serverPlayer, (T) wrappedPacket.message()); + private PayloadRegistrar playToServer(PayloadRegistrar registrar, ServerboundMessageRegistration registration) { + return registrar.playToServer(registration.getType(), registration.getCodec(), createPayloadHandler(registration)); + } + + private PayloadRegistrar playToClient(PayloadRegistrar registrar, ClientboundMessageRegistration registration) { + return registrar.playToClient(registration.getType(), registration.getCodec(), createPayloadHandler(registration)); } - } - @SuppressWarnings("unchecked") - private static void handleClientboundPacket(ClientboundMessageRegistration registration, CustomPacketPayload payload, PlayPayloadContext context) { - if (payload instanceof WrappedPacket wrappedPacket) { - registration.getHandler().accept(Balm.getProxy().getClientPlayer(), (T) wrappedPacket.message()); + private IPayloadHandler createPayloadHandler(ServerboundMessageRegistration serverboundMessageRegistration) { + return new MainThreadPayloadHandler<>((payload, context) -> { + replyContext = context; + serverboundMessageRegistration.getHandler().accept((ServerPlayer) context.player(), payload); + replyContext = null; + }); + } + + private IPayloadHandler createPayloadHandler(ClientboundMessageRegistration clientboundMessageRegistration) { + return new MainThreadPayloadHandler<>((payload, context) -> { + replyContext = context; + clientboundMessageRegistration.getHandler().accept(context.player(), payload); + replyContext = null; + }); } } private final Map registrations = new ConcurrentHashMap<>(); - private final Map, MessageRegistration> messagesByClass = new ConcurrentHashMap<>(); - private static IReplyHandler replyHandler; + private static IPayloadContext replyContext; @Override public void allowClientOnly(String modId) { @@ -144,78 +123,60 @@ public void openGui(Player player, MenuProvider menuProvider) { } @Override - public void reply(T message) { - if (replyHandler == null) { + public void reply(T message) { + if (replyContext == null) { throw new IllegalStateException("No context to reply to"); } - MessageRegistration messageRegistration = getMessageRegistrationOrThrow(message); - ResourceLocation identifier = messageRegistration.getIdentifier(); - - replyHandler.send(new WrappedPacket(identifier, message, (BiConsumer) messageRegistration.getEncodeFunc())); + replyContext.reply(message); } @Override - public void sendTo(Player player, T message) { + public void sendTo(Player player, T message) { if (player instanceof ServerPlayer serverPlayer) { - sendPacket(PacketDistributor.PLAYER.with(serverPlayer), message); + PacketDistributor.sendToPlayer(serverPlayer, message); } } @Override - public void sendToTracking(ServerLevel level, BlockPos pos, T message) { - sendPacket(PacketDistributor.TRACKING_CHUNK.with(level.getChunkAt(pos)), message); + public void sendToTracking(ServerLevel level, BlockPos pos, T message) { + PacketDistributor.sendToPlayersTrackingChunk(level, new ChunkPos(pos), message); } @Override - public void sendToTracking(Entity entity, T message) { - sendPacket(PacketDistributor.TRACKING_ENTITY.with(entity), message); + public void sendToTracking(Entity entity, T message) { + PacketDistributor.sendToPlayersTrackingEntity(entity, message); } @Override - public void sendToAll(MinecraftServer server, T message) { - sendPacket(PacketDistributor.ALL.noArg(), message); + public void sendToAll(MinecraftServer server, T message) { + PacketDistributor.sendToAllPlayers(message); } @Override - public void sendToServer(T message) { + public void sendToServer(T message) { if (!Balm.getProxy().isConnectedToServer()) { logger.debug("Skipping message {} because we're not connected to a server", message); return; } - sendPacket(PacketDistributor.SERVER.noArg(), message); - } - - @SuppressWarnings("unchecked") - private MessageRegistration getMessageRegistrationOrThrow(T message) { - MessageRegistration messageRegistration = (MessageRegistration) messagesByClass.get(message.getClass()); - if (messageRegistration == null) { - throw new IllegalArgumentException("Cannot send message " + message.getClass() + " as it is not registered"); - } - return messageRegistration; + PacketDistributor.sendToServer(message); } @Override - public void registerClientboundPacket(ResourceLocation identifier, Class clazz, BiConsumer encodeFunc, Function decodeFunc, BiConsumer handler) { - ClientboundMessageRegistration messageRegistration = new ClientboundMessageRegistration<>(identifier, clazz, encodeFunc, decodeFunc, handler); + public void registerClientboundPacket(ResourceLocation identifier, Class clazz, BiConsumer encodeFunc, Function decodeFunc, BiConsumer handler) { + final var type = new CustomPacketPayload.Type(identifier); + final var messageRegistration = new ClientboundMessageRegistration<>(type, clazz, encodeFunc, decodeFunc, handler); final var registrations = getActiveRegistrations(); - messagesByClass.put(clazz, messageRegistration); - registrations.messagesByIdentifier.put(identifier, messageRegistration); + registrations.playMessagesByType.put(type, messageRegistration); } @Override - public void registerServerboundPacket(ResourceLocation identifier, Class clazz, BiConsumer encodeFunc, Function decodeFunc, BiConsumer handler) { - MessageRegistration messageRegistration = new ServerboundMessageRegistration<>(identifier, clazz, encodeFunc, decodeFunc, handler); + public void registerServerboundPacket(ResourceLocation identifier, Class clazz, BiConsumer encodeFunc, Function decodeFunc, BiConsumer handler) { + final var type = new CustomPacketPayload.Type(identifier); + final var messageRegistration = new ServerboundMessageRegistration<>(type, clazz, encodeFunc, decodeFunc, handler); final var registrations = getActiveRegistrations(); - messagesByClass.put(clazz, messageRegistration); - registrations.messagesByIdentifier.put(identifier, messageRegistration); - } - - @SuppressWarnings("unchecked") - private void sendPacket(PacketDistributor.PacketTarget target, T message) { - MessageRegistration messageRegistration = getMessageRegistrationOrThrow(message); - target.send(new WrappedPacket(messageRegistration.getIdentifier(), message, (BiConsumer) messageRegistration.getEncodeFunc())); + registrations.playMessagesByType.put(type, messageRegistration); } public void register(String modId, IEventBus eventBus) { diff --git a/neoforge/src/main/java/net/blay09/mods/balm/neoforge/world/BalmBiomeModifier.java b/neoforge/src/main/java/net/blay09/mods/balm/neoforge/world/BalmBiomeModifier.java index 8a322312..bcbfe3e6 100644 --- a/neoforge/src/main/java/net/blay09/mods/balm/neoforge/world/BalmBiomeModifier.java +++ b/neoforge/src/main/java/net/blay09/mods/balm/neoforge/world/BalmBiomeModifier.java @@ -1,6 +1,7 @@ package net.blay09.mods.balm.neoforge.world; import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; import net.blay09.mods.balm.api.Balm; import net.minecraft.core.Holder; import net.minecraft.world.level.biome.Biome; @@ -18,7 +19,7 @@ public void modify(Holder biome, Phase phase, ModifiableBiomeInfo.BiomeIn } @Override - public Codec codec() { + public MapCodec codec() { return NeoForgeBalmWorldGen.BALM_BIOME_MODIFIER_CODEC; } diff --git a/neoforge/src/main/java/net/blay09/mods/balm/neoforge/world/NeoForgeBalmWorldGen.java b/neoforge/src/main/java/net/blay09/mods/balm/neoforge/world/NeoForgeBalmWorldGen.java index 3e8c838e..1eb6c19a 100644 --- a/neoforge/src/main/java/net/blay09/mods/balm/neoforge/world/NeoForgeBalmWorldGen.java +++ b/neoforge/src/main/java/net/blay09/mods/balm/neoforge/world/NeoForgeBalmWorldGen.java @@ -1,6 +1,6 @@ package net.blay09.mods.balm.neoforge.world; -import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; import net.blay09.mods.balm.api.DeferredObject; import net.blay09.mods.balm.api.world.BalmWorldGen; import net.blay09.mods.balm.api.world.BiomePredicate; @@ -16,7 +16,6 @@ import net.minecraft.world.level.levelgen.placement.PlacedFeature; import net.minecraft.world.level.levelgen.placement.PlacementModifierType; import net.neoforged.bus.api.IEventBus; -import net.neoforged.fml.javafmlmod.FMLJavaModLoadingContext; import net.neoforged.neoforge.common.world.BiomeModifier; import net.neoforged.neoforge.common.world.ModifiableBiomeInfo; import net.neoforged.neoforge.registries.DeferredRegister; @@ -29,7 +28,7 @@ public class NeoForgeBalmWorldGen implements BalmWorldGen { - public static final Codec BALM_BIOME_MODIFIER_CODEC = Codec.unit(BalmBiomeModifier.INSTANCE); + public static final MapCodec BALM_BIOME_MODIFIER_CODEC = MapCodec.unit(BalmBiomeModifier.INSTANCE); @Override public > DeferredObject registerFeature(ResourceLocation identifier, Supplier supplier) { diff --git a/neoforge/src/main/resources/META-INF/mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml similarity index 100% rename from neoforge/src/main/resources/META-INF/mods.toml rename to neoforge/src/main/resources/META-INF/neoforge.mods.toml diff --git a/settings.gradle b/settings.gradle index 45128c5b..ea2267a7 100644 --- a/settings.gradle +++ b/settings.gradle @@ -21,7 +21,7 @@ pluginManagement { } plugins { - id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0' + id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0' } rootProject.name = 'Balm' diff --git a/shared/src/main/java/net/blay09/mods/balm/api/container/ContainerUtils.java b/shared/src/main/java/net/blay09/mods/balm/api/container/ContainerUtils.java index 2b84604f..bb2efde5 100644 --- a/shared/src/main/java/net/blay09/mods/balm/api/container/ContainerUtils.java +++ b/shared/src/main/java/net/blay09/mods/balm/api/container/ContainerUtils.java @@ -112,7 +112,7 @@ public static ItemStack insertItemStacked(Container container, ItemStack itemSta continue; } - if (slotStack.isStackable() && ItemStack.isSameItemSameTags(slotStack, itemStack)) { + if (slotStack.isStackable() && ItemStack.isSameItemSameComponents(slotStack, itemStack)) { itemStack = insertItem(container, i, itemStack, simulate); } diff --git a/shared/src/main/java/net/blay09/mods/balm/api/container/DefaultContainer.java b/shared/src/main/java/net/blay09/mods/balm/api/container/DefaultContainer.java index d003adc4..007a7002 100644 --- a/shared/src/main/java/net/blay09/mods/balm/api/container/DefaultContainer.java +++ b/shared/src/main/java/net/blay09/mods/balm/api/container/DefaultContainer.java @@ -1,5 +1,6 @@ package net.blay09.mods.balm.api.container; +import net.minecraft.core.HolderLookup; import net.minecraft.core.NonNullList; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.Container; @@ -24,11 +25,11 @@ public NonNullList getItems() { return items; } - public void deserialize(CompoundTag tag) { - items = ImplementedContainer.deserializeInventory(tag, items.size()); + public void deserialize(HolderLookup.Provider provider, CompoundTag tag) { + items = ImplementedContainer.deserializeInventory(provider, tag, items.size()); } - public CompoundTag serialize() { - return serializeInventory(); + public CompoundTag serialize(HolderLookup.Provider provider) { + return serializeInventory(provider); } } diff --git a/shared/src/main/java/net/blay09/mods/balm/api/container/ImplementedContainer.java b/shared/src/main/java/net/blay09/mods/balm/api/container/ImplementedContainer.java index b25984bf..5d37c233 100644 --- a/shared/src/main/java/net/blay09/mods/balm/api/container/ImplementedContainer.java +++ b/shared/src/main/java/net/blay09/mods/balm/api/container/ImplementedContainer.java @@ -1,5 +1,6 @@ package net.blay09.mods.balm.api.container; +import net.minecraft.core.HolderLookup; import net.minecraft.core.NonNullList; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; @@ -142,7 +143,7 @@ default boolean stillValid(Player player) { return true; } - static NonNullList deserializeInventory(CompoundTag tag, int minimumSize) { + static NonNullList deserializeInventory(HolderLookup.Provider provider, CompoundTag tag, int minimumSize) { int size = Math.max(minimumSize, tag.contains("Size", Tag.TAG_INT) ? tag.getInt("Size") : minimumSize); NonNullList items = NonNullList.withSize(size, ItemStack.EMPTY); ListTag itemTags = tag.getList("Items", Tag.TAG_COMPOUND); @@ -150,20 +151,20 @@ static NonNullList deserializeInventory(CompoundTag tag, int minimumS CompoundTag itemTag = itemTags.getCompound(i); int slot = itemTag.getInt("Slot"); if (slot >= 0 && slot < items.size()) { - items.set(slot, ItemStack.of(itemTag)); + items.set(slot, ItemStack.parse(provider, itemTag).orElse(ItemStack.EMPTY)); } } return items; } - default CompoundTag serializeInventory() { + default CompoundTag serializeInventory(HolderLookup.Provider provider) { NonNullList items = getItems(); ListTag itemTags = new ListTag(); for (int i = 0; i < items.size(); i++) { if (!items.get(i).isEmpty()) { CompoundTag itemTag = new CompoundTag(); itemTag.putInt("Slot", i); - items.get(i).save(itemTag); + items.get(i).save(provider, itemTag); itemTags.add(itemTag); } } diff --git a/shared/src/main/java/net/blay09/mods/balm/api/menu/BalmMenuProvider.java b/shared/src/main/java/net/blay09/mods/balm/api/menu/BalmMenuProvider.java index 12e0b218..583f912d 100644 --- a/shared/src/main/java/net/blay09/mods/balm/api/menu/BalmMenuProvider.java +++ b/shared/src/main/java/net/blay09/mods/balm/api/menu/BalmMenuProvider.java @@ -1,14 +1,8 @@ package net.blay09.mods.balm.api.menu; -import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.MenuProvider; -import net.minecraft.world.level.block.entity.BlockEntity; -public interface BalmMenuProvider extends MenuProvider { - default void writeScreenOpeningData(ServerPlayer player, FriendlyByteBuf buf) { - if (this instanceof BlockEntity blockEntity) { - buf.writeBlockPos(blockEntity.getBlockPos()); - } - } +public interface BalmMenuProvider extends MenuProvider { + T getScreenOpeningData(ServerPlayer player); } diff --git a/shared/src/main/java/net/blay09/mods/balm/api/network/BalmNetworking.java b/shared/src/main/java/net/blay09/mods/balm/api/network/BalmNetworking.java index c89628b8..f1156c4c 100644 --- a/shared/src/main/java/net/blay09/mods/balm/api/network/BalmNetworking.java +++ b/shared/src/main/java/net/blay09/mods/balm/api/network/BalmNetworking.java @@ -2,6 +2,8 @@ import net.minecraft.core.BlockPos; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; @@ -25,19 +27,19 @@ default void allowClientAndServerOnly(String modId) { void allowServerOnly(String modId); - void reply(T message); + void reply(T message); - void sendTo(Player player, T message); + void sendTo(Player player, T message); - void sendToTracking(ServerLevel world, BlockPos pos, T message); + void sendToTracking(ServerLevel world, BlockPos pos, T message); - void sendToTracking(Entity entity, T message); + void sendToTracking(Entity entity, T message); - void sendToAll(MinecraftServer server, T message); + void sendToAll(MinecraftServer server, T message); - void sendToServer(T message); + void sendToServer(T message); - void registerClientboundPacket(ResourceLocation identifier, Class clazz, BiConsumer encodeFunc, Function decodeFunc, BiConsumer handler); + void registerClientboundPacket(ResourceLocation identifier, Class clazz, BiConsumer encodeFunc, Function decodeFunc, BiConsumer handler); - void registerServerboundPacket(ResourceLocation identifier, Class clazz, BiConsumer encodeFunc, Function decodeFunc, BiConsumer handler); + void registerServerboundPacket(ResourceLocation identifier, Class clazz, BiConsumer encodeFunc, Function decodeFunc, BiConsumer handler); } diff --git a/shared/src/main/java/net/blay09/mods/balm/api/network/ClientboundMessageRegistration.java b/shared/src/main/java/net/blay09/mods/balm/api/network/ClientboundMessageRegistration.java index fcae6c2e..00777ef7 100644 --- a/shared/src/main/java/net/blay09/mods/balm/api/network/ClientboundMessageRegistration.java +++ b/shared/src/main/java/net/blay09/mods/balm/api/network/ClientboundMessageRegistration.java @@ -1,22 +1,22 @@ package net.blay09.mods.balm.api.network; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.world.entity.player.Player; import java.util.function.BiConsumer; import java.util.function.Function; -public class ClientboundMessageRegistration extends MessageRegistration { +public class ClientboundMessageRegistration extends MessageRegistration { - private final BiConsumer handler; + private final BiConsumer handler; - public ClientboundMessageRegistration(ResourceLocation identifier, Class clazz, BiConsumer encodeFunc, Function decodeFunc, BiConsumer handler) { - super(identifier, clazz, encodeFunc, decodeFunc); + public ClientboundMessageRegistration(CustomPacketPayload.Type type, Class clazz, BiConsumer encodeFunc, Function decodeFunc, BiConsumer handler) { + super(type, clazz, encodeFunc, decodeFunc); this.handler = handler; } - public BiConsumer getHandler() { + public BiConsumer getHandler() { return handler; } } diff --git a/shared/src/main/java/net/blay09/mods/balm/api/network/MessageRegistration.java b/shared/src/main/java/net/blay09/mods/balm/api/network/MessageRegistration.java index a2ea98f3..04daae7f 100644 --- a/shared/src/main/java/net/blay09/mods/balm/api/network/MessageRegistration.java +++ b/shared/src/main/java/net/blay09/mods/balm/api/network/MessageRegistration.java @@ -1,39 +1,44 @@ package net.blay09.mods.balm.api.network; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import java.util.function.BiConsumer; import java.util.function.Function; -public class MessageRegistration { +public class MessageRegistration { - private final ResourceLocation identifier; - private final Class clazz; - private final BiConsumer encodeFunc; - private final Function decodeFunc; + private final CustomPacketPayload.Type type; + private final Class clazz; + private final BiConsumer encodeFunc; + private final Function decodeFunc; - public MessageRegistration(ResourceLocation identifier, Class clazz, BiConsumer encodeFunc, Function decodeFunc) { + public MessageRegistration(CustomPacketPayload.Type type, Class clazz, BiConsumer encodeFunc, Function decodeFunc) { - this.identifier = identifier; + this.type = type; this.clazz = clazz; this.encodeFunc = encodeFunc; this.decodeFunc = decodeFunc; } - public ResourceLocation getIdentifier() { - return identifier; + public CustomPacketPayload.Type getType() { + return type; } - public Class getClazz() { + public Class getClazz() { return clazz; } - public BiConsumer getEncodeFunc() { + public BiConsumer getEncodeFunc() { return encodeFunc; } - public Function getDecodeFunc() { + public Function getDecodeFunc() { return decodeFunc; } + + public StreamCodec getCodec() { + return StreamCodec.of((buffer, payload) -> getEncodeFunc().accept(buffer, payload), (buffer) -> getDecodeFunc().apply(buffer)); + } } diff --git a/shared/src/main/java/net/blay09/mods/balm/api/network/ServerboundMessageRegistration.java b/shared/src/main/java/net/blay09/mods/balm/api/network/ServerboundMessageRegistration.java index b6b704e1..d5dafafa 100644 --- a/shared/src/main/java/net/blay09/mods/balm/api/network/ServerboundMessageRegistration.java +++ b/shared/src/main/java/net/blay09/mods/balm/api/network/ServerboundMessageRegistration.java @@ -1,22 +1,22 @@ package net.blay09.mods.balm.api.network; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.server.level.ServerPlayer; import java.util.function.BiConsumer; import java.util.function.Function; -public class ServerboundMessageRegistration extends MessageRegistration { +public class ServerboundMessageRegistration extends MessageRegistration { - private final BiConsumer handler; + private final BiConsumer handler; - public ServerboundMessageRegistration(ResourceLocation identifier, Class clazz, BiConsumer encodeFunc, Function decodeFunc, BiConsumer handler) { - super(identifier, clazz, encodeFunc, decodeFunc); + public ServerboundMessageRegistration(CustomPacketPayload.Type type, Class clazz, BiConsumer encodeFunc, Function decodeFunc, BiConsumer handler) { + super(type, clazz, encodeFunc, decodeFunc); this.handler = handler; } - public BiConsumer getHandler() { + public BiConsumer getHandler() { return handler; } } diff --git a/shared/src/main/java/net/blay09/mods/balm/api/network/SyncConfigMessage.java b/shared/src/main/java/net/blay09/mods/balm/api/network/SyncConfigMessage.java index 499694cb..de50dc9a 100644 --- a/shared/src/main/java/net/blay09/mods/balm/api/network/SyncConfigMessage.java +++ b/shared/src/main/java/net/blay09/mods/balm/api/network/SyncConfigMessage.java @@ -5,6 +5,8 @@ import net.blay09.mods.balm.api.config.ExpectedType; import net.blay09.mods.balm.api.config.Synced; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; import java.lang.reflect.Field; @@ -13,11 +15,13 @@ import java.util.function.Function; import java.util.function.Supplier; -public class SyncConfigMessage { +public class SyncConfigMessage implements CustomPacketPayload { + private final Type type; private final TData data; - public SyncConfigMessage(TData data) { + public SyncConfigMessage(Type type, TData data) { + this.type = type; this.data = data; } @@ -95,8 +99,8 @@ private static Object readValue(FriendlyByteBuf buf, TData data, Field f return value; } - public static > BiConsumer createEncoder(Class clazz) { - return (message, buf) -> { + public static > BiConsumer createEncoder(Class clazz) { + return (buf, message) -> { TData data = message.getData(); writeSyncedFields(buf, data, false); }; @@ -157,7 +161,7 @@ public static , TData extends BalmConf Class dataClass, Supplier dataFactory) { Supplier copyFactory = SyncConfigMessage.createDeepCopyFactory(() -> Balm.getConfig().getBackingConfig(dataClass), dataFactory); - Balm.getNetworking().registerClientboundPacket(resourceLocation, messageClass, (TMessage message, FriendlyByteBuf buf) -> { + Balm.getNetworking().registerClientboundPacket(resourceLocation, messageClass, (RegistryFriendlyByteBuf buf, TMessage message) -> { TData data = message.getData(); writeSyncedFields(buf, data, false); }, buf -> { @@ -167,4 +171,8 @@ public static , TData extends BalmConf }, Balm.getConfig()::handleSync); } + @Override + public Type type() { + return type; + } } diff --git a/shared/src/main/java/net/blay09/mods/balm/common/BalmBlockEntity.java b/shared/src/main/java/net/blay09/mods/balm/common/BalmBlockEntity.java index 2c40aab1..111f313b 100644 --- a/shared/src/main/java/net/blay09/mods/balm/common/BalmBlockEntity.java +++ b/shared/src/main/java/net/blay09/mods/balm/common/BalmBlockEntity.java @@ -12,6 +12,7 @@ import net.blay09.mods.balm.api.provider.BalmProviderHolder; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientGamePacketListener; @@ -36,8 +37,8 @@ public BalmBlockEntity(BlockEntityType blockEntityType, BlockPos blockPos, Bl } @Override - public CompoundTag getUpdateTag() { - return createUpdateTag(); + public CompoundTag getUpdateTag(HolderLookup.Provider provider) { + return createUpdateTag(this); } @Override @@ -161,15 +162,11 @@ public void sync() { } public Packet createUpdatePacket() { - return ClientboundBlockEntityDataPacket.create(this, this::createUpdateTag); - } - - public CompoundTag createUpdateTag() { - return createUpdateTag(this); + return ClientboundBlockEntityDataPacket.create(this, (blockEntity, registryAccess) -> createUpdateTag(blockEntity)); } - private CompoundTag createUpdateTag(BlockEntity blockEntity) { - var tag = new CompoundTag(); + public CompoundTag createUpdateTag(BlockEntity blockEntity) { + final var tag = new CompoundTag(); if (blockEntity instanceof BalmBlockEntity balmBlockEntity) { balmBlockEntity.writeUpdateTag(tag); } diff --git a/shared/src/main/java/net/blay09/mods/balm/mixin/ReloadableServerResourcesMixin.java b/shared/src/main/java/net/blay09/mods/balm/mixin/ReloadableServerResourcesMixin.java index de239154..b340d491 100644 --- a/shared/src/main/java/net/blay09/mods/balm/mixin/ReloadableServerResourcesMixin.java +++ b/shared/src/main/java/net/blay09/mods/balm/mixin/ReloadableServerResourcesMixin.java @@ -3,7 +3,9 @@ import net.blay09.mods.balm.api.Balm; import net.blay09.mods.balm.api.event.server.ServerReloadedEvent; import net.minecraft.commands.Commands; +import net.minecraft.core.LayeredRegistryAccess; import net.minecraft.core.RegistryAccess; +import net.minecraft.server.RegistryLayer; import net.minecraft.server.ReloadableServerResources; import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.world.flag.FeatureFlagSet; @@ -18,8 +20,8 @@ @Mixin(ReloadableServerResources.class) public class ReloadableServerResourcesMixin { - @Inject(method = "loadResources(Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/core/RegistryAccess$Frozen;Lnet/minecraft/world/flag/FeatureFlagSet;Lnet/minecraft/commands/Commands$CommandSelection;ILjava/util/concurrent/Executor;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;", at = @At("RETURN"), cancellable = true) - private static void loadResources(ResourceManager resourceManager, RegistryAccess.Frozen frozen, FeatureFlagSet featureFlagSet, Commands.CommandSelection commandSelection, int i, Executor e1, Executor e2, CallbackInfoReturnable> callbackInfo) { + @Inject(method = "loadResources(Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/core/LayeredRegistryAccess;Lnet/minecraft/world/flag/FeatureFlagSet;Lnet/minecraft/commands/Commands$CommandSelection;ILjava/util/concurrent/Executor;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;", at = @At("RETURN"), cancellable = true) + private static void loadResources(ResourceManager resourceManager, LayeredRegistryAccess registryAccess, FeatureFlagSet featureFlagSet, Commands.CommandSelection commandSelection, int i, Executor e1, Executor e2, CallbackInfoReturnable> callbackInfo) { callbackInfo.getReturnValue().thenAccept(it -> Balm.getEvents().fireEvent(new ServerReloadedEvent(it))); }