-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from FTBTeam/feature/unified-creative-tab
feat: unified creative tab
- Loading branch information
Showing
9 changed files
with
143 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
common/src/main/java/dev/ftb/mods/ftblibrary/items/ModItems.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Item> ITEMS = DeferredRegister.create(FTBLibrary.MOD_ID, Registries.ITEM); | ||
private static final DeferredSupplier<Item> ICON_ITEM = ITEMS.register("icon_item", () -> new Item(new Item.Properties())); | ||
|
||
private static final DeferredRegister<CreativeModeTab> CREATIVE_MODE_TABS = DeferredRegister.create(FTBLibrary.MOD_ID, Registries.CREATIVE_MODE_TAB); | ||
public static final DeferredSupplier<CreativeModeTab> 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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
common/src/main/resources/assets/ftblibrary/models/item/icon_item.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"textures": { | ||
"layer0": "ftblibrary:item/icon_item" | ||
} | ||
} |
Binary file added
BIN
+278 Bytes
common/src/main/resources/assets/ftblibrary/textures/item/icon_item.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions
38
fabric/src/main/java/dev/ftb/mods/ftblibrary/util/fabric/NetworkHelperImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ServerPlayer> 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 <T extends CustomPacketPayload> void sendToAll(MinecraftServer server, T packet) { | ||
List<ServerPlayer> players = server.getPlayerList().getPlayers(); | ||
for (ServerPlayer player : players) { | ||
sendTo(player, packet); | ||
} | ||
} | ||
|
||
public static <T extends CustomPacketPayload> void sendTo(ServerPlayer player, T packet) { | ||
if (ServerPlayNetworking.canSend(player, packet.type())) { | ||
NetworkManager.sendToPlayer(player, packet); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
neoforge/src/main/java/dev/ftb/mods/ftblibrary/util/neoforge/NetworkHelperImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ServerPlayer> 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 <T extends CustomPacketPayload> void sendToAll(MinecraftServer server, T packet) { | ||
List<ServerPlayer> players = server.getPlayerList().getPlayers(); | ||
for (ServerPlayer player : players) { | ||
sendTo(player, packet); | ||
} | ||
} | ||
|
||
public static <T extends CustomPacketPayload> void sendTo(ServerPlayer player, T packet) { | ||
if (player.connection.hasChannel(packet.type())) { | ||
NetworkManager.sendToPlayer(player, packet); | ||
} | ||
} | ||
} |