diff --git a/common/src/main/java/dev/ftb/mods/ftblibrary/FTBLibrary.java b/common/src/main/java/dev/ftb/mods/ftblibrary/FTBLibrary.java index 5a046d9f..55a1ef19 100644 --- a/common/src/main/java/dev/ftb/mods/ftblibrary/FTBLibrary.java +++ b/common/src/main/java/dev/ftb/mods/ftblibrary/FTBLibrary.java @@ -3,15 +3,18 @@ import dev.architectury.event.events.common.CommandRegistrationEvent; import dev.architectury.event.events.common.LifecycleEvent; import dev.architectury.event.events.common.PlayerEvent; -import dev.architectury.networking.NetworkManager; +import dev.architectury.registry.registries.DeferredSupplier; import dev.architectury.utils.Env; import dev.architectury.utils.EnvExecutor; +import dev.ftb.mods.ftblibrary.items.ModItems; import dev.ftb.mods.ftblibrary.net.FTBLibraryNet; import dev.ftb.mods.ftblibrary.net.SyncKnownServerRegistriesPacket; import dev.ftb.mods.ftblibrary.util.KnownServerRegistries; +import dev.ftb.mods.ftblibrary.util.NetworkHelper; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.CreativeModeTab; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -27,6 +30,8 @@ public FTBLibrary() { LifecycleEvent.SERVER_STOPPED.register(this::serverStopped); PlayerEvent.PLAYER_JOIN.register(this::playerJoined); + ModItems.init(); + EnvExecutor.runInEnv(Env.CLIENT, () -> FTBLibraryClient::init); } @@ -43,6 +48,10 @@ private void serverStopped(MinecraftServer server) { } private void playerJoined(ServerPlayer player) { - NetworkManager.sendToPlayer(player, new SyncKnownServerRegistriesPacket(KnownServerRegistries.server)); + NetworkHelper.sendTo(player, new SyncKnownServerRegistriesPacket(KnownServerRegistries.server)); + } + + public static DeferredSupplier getCreativeModeTab() { + return ModItems.FTB_LIBRARY_TAB; } -} \ No newline at end of file +} diff --git a/common/src/main/java/dev/ftb/mods/ftblibrary/items/ModItems.java b/common/src/main/java/dev/ftb/mods/ftblibrary/items/ModItems.java new file mode 100644 index 00000000..7be55fd5 --- /dev/null +++ b/common/src/main/java/dev/ftb/mods/ftblibrary/items/ModItems.java @@ -0,0 +1,26 @@ +package dev.ftb.mods.ftblibrary.items; + +import dev.architectury.registry.registries.DeferredRegister; +import dev.architectury.registry.registries.DeferredSupplier; +import dev.ftb.mods.ftblibrary.FTBLibrary; +import net.minecraft.core.registries.Registries; +import net.minecraft.network.chat.Component; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; + +public class ModItems { + private static final DeferredRegister ITEMS = DeferredRegister.create(FTBLibrary.MOD_ID, Registries.ITEM); + private static final DeferredSupplier ICON_ITEM = ITEMS.register("icon_item", () -> new Item(new Item.Properties())); + + private static final DeferredRegister CREATIVE_MODE_TABS = DeferredRegister.create(FTBLibrary.MOD_ID, Registries.CREATIVE_MODE_TAB); + public static final DeferredSupplier FTB_LIBRARY_TAB = CREATIVE_MODE_TABS.register("ftb_library", () -> CreativeModeTab.builder(CreativeModeTab.Row.TOP, 0) + .title(Component.translatable("itemGroup.ftbsuite.creative_tab")) + .icon(() -> new ItemStack(ICON_ITEM.get())) + .build()); + + public static void init() { + CREATIVE_MODE_TABS.register(); + ITEMS.register(); + } +} diff --git a/common/src/main/java/dev/ftb/mods/ftblibrary/util/NetworkHelper.java b/common/src/main/java/dev/ftb/mods/ftblibrary/util/NetworkHelper.java index 40a5d4c7..a8b6d135 100644 --- a/common/src/main/java/dev/ftb/mods/ftblibrary/util/NetworkHelper.java +++ b/common/src/main/java/dev/ftb/mods/ftblibrary/util/NetworkHelper.java @@ -1,13 +1,16 @@ package dev.ftb.mods.ftblibrary.util; +import dev.architectury.injectables.annotations.ExpectPlatform; import dev.architectury.networking.NetworkManager; import dev.architectury.platform.Platform; import dev.architectury.utils.Env; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; public class NetworkHelper { public static void registerC2S(CustomPacketPayload.Type type, StreamCodec codec, NetworkManager.NetworkReceiver handler) { @@ -22,8 +25,24 @@ public static void registerS2C(CustomPacketPaylo } } + @ExpectPlatform + public static void sendToAll(CustomPacketPayload.Type type, MinecraftServer server, Packet packet) { + throw new AssertionError(); + } + + @ExpectPlatform + public static void sendTo(CustomPacketPayload.Type type, ServerPlayer player, Packet packet) { + throw new AssertionError(); + } + + @ExpectPlatform public static void sendToAll(MinecraftServer server, T packet) { - NetworkManager.sendToPlayers(server.getPlayerList().getPlayers(), packet); + throw new AssertionError(); + } + + @ExpectPlatform + public static void sendTo(ServerPlayer player, T packet) { + throw new AssertionError(); } public static > StreamCodec enumStreamCodec(Class enumClass) { diff --git a/common/src/main/resources/assets/ftblibrary/lang/en_us.json b/common/src/main/resources/assets/ftblibrary/lang/en_us.json index 8d3f7d76..c539bb2c 100644 --- a/common/src/main/resources/assets/ftblibrary/lang/en_us.json +++ b/common/src/main/resources/assets/ftblibrary/lang/en_us.json @@ -98,5 +98,7 @@ "dimension.minecraft.the_nether": "The Nether", "dimension.minecraft.the_end": "The End", "dimension.hyperbox.hyperbox": "Hyperbox", - "dimension.ae2.spatial_storage": "AE2 Spatial Storage" + "dimension.ae2.spatial_storage": "AE2 Spatial Storage", + "itemGroup.ftbsuite.creative_tab": "FTB Suite", + "item.ftblibrary.icon_item": "FTB Icon" } diff --git a/common/src/main/resources/assets/ftblibrary/models/item/icon_item.json b/common/src/main/resources/assets/ftblibrary/models/item/icon_item.json new file mode 100644 index 00000000..49be866a --- /dev/null +++ b/common/src/main/resources/assets/ftblibrary/models/item/icon_item.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "ftblibrary:item/icon_item" + } +} diff --git a/common/src/main/resources/assets/ftblibrary/textures/item/icon_item.png b/common/src/main/resources/assets/ftblibrary/textures/item/icon_item.png new file mode 100644 index 00000000..228274a5 Binary files /dev/null and b/common/src/main/resources/assets/ftblibrary/textures/item/icon_item.png differ diff --git a/fabric/src/main/java/dev/ftb/mods/ftblibrary/util/fabric/NetworkHelperImpl.java b/fabric/src/main/java/dev/ftb/mods/ftblibrary/util/fabric/NetworkHelperImpl.java new file mode 100644 index 00000000..f27a7f4b --- /dev/null +++ b/fabric/src/main/java/dev/ftb/mods/ftblibrary/util/fabric/NetworkHelperImpl.java @@ -0,0 +1,38 @@ +package dev.ftb.mods.ftblibrary.util.fabric; + +import dev.architectury.networking.NetworkManager; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; + +import java.util.List; + +public class NetworkHelperImpl { + public static void sendToAll(CustomPacketPayload.Type type, MinecraftServer server, Packet packet) { + List players = server.getPlayerList().getPlayers(); + for (ServerPlayer player : players) { + sendTo(type, player, packet); + } + } + + public static void sendTo(CustomPacketPayload.Type type, ServerPlayer player, Packet packet) { + if (ServerPlayNetworking.canSend(player, type)) { + player.connection.send(packet); + } + } + + public static void sendToAll(MinecraftServer server, T packet) { + List players = server.getPlayerList().getPlayers(); + for (ServerPlayer player : players) { + sendTo(player, packet); + } + } + + public static void sendTo(ServerPlayer player, T packet) { + if (ServerPlayNetworking.canSend(player, packet.type())) { + NetworkManager.sendToPlayer(player, packet); + } + } +} diff --git a/gradle.properties b/gradle.properties index ad511ad3..579602e7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.daemon=false # Mod mod_id=ftblibrary readable_name=FTB Library -mod_version=2100.1.3 +mod_version=2100.1.4 mod_author=FTB Team # Maven diff --git a/neoforge/src/main/java/dev/ftb/mods/ftblibrary/util/neoforge/NetworkHelperImpl.java b/neoforge/src/main/java/dev/ftb/mods/ftblibrary/util/neoforge/NetworkHelperImpl.java new file mode 100644 index 00000000..19effc5d --- /dev/null +++ b/neoforge/src/main/java/dev/ftb/mods/ftblibrary/util/neoforge/NetworkHelperImpl.java @@ -0,0 +1,37 @@ +package dev.ftb.mods.ftblibrary.util.neoforge; + +import dev.architectury.networking.NetworkManager; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; + +import java.util.List; + +public class NetworkHelperImpl { + public static void sendToAll(CustomPacketPayload.Type type, MinecraftServer server, Packet packet) { + List players = server.getPlayerList().getPlayers(); + for (ServerPlayer player : players) { + sendTo(type, player, packet); + } + } + + public static void sendTo(CustomPacketPayload.Type type, ServerPlayer player, Packet packet) { + if (player.connection.hasChannel(type)) { + player.connection.send(packet); + } + } + + public static void sendToAll(MinecraftServer server, T packet) { + List players = server.getPlayerList().getPlayers(); + for (ServerPlayer player : players) { + sendTo(player, packet); + } + } + + public static void sendTo(ServerPlayer player, T packet) { + if (player.connection.hasChannel(packet.type())) { + NetworkManager.sendToPlayer(player, packet); + } + } +}