From 380fb13635bfae713ca124522b507e91921d18d7 Mon Sep 17 00:00:00 2001 From: lukasabbe <67807954+lukasabbe@users.noreply.github.com> Date: Mon, 1 Sep 2025 18:57:26 +0200 Subject: [PATCH] Added support for securitycraft bookshelfs and lecterns --- .../BookshelfInspector.java | 1 - .../BookshelfInspectorClient.java | 1 - .../bookshelfinspector/Constants.java | 1 - .../bookshelfinspector/data/Tags.java | 1 + ...fInventoryRequestServerPayloadHandler.java | 6 ++-- ...nInventoryRequestServerPayloadHandler.java | 5 ++-- .../bookshelfinspector/platform/Services.java | 10 ------- .../renderer/Inspector.java | 3 +- .../bookshelfinspector/util/BlockTools.java | 26 +++++++++++++++++ .../util/BookshelfTools.java | 28 ------------------- .../bookshelfinspector/util/LecternTools.java | 24 ---------------- .../c/tags/block/chiseled_bookshelves.json | 6 +++- .../resources/data/c/tags/block/lectern.json | 10 +++++++ settings.gradle | 2 ++ 14 files changed, 52 insertions(+), 72 deletions(-) create mode 100644 common/src/main/java/com/lukasabbe/bookshelfinspector/util/BlockTools.java delete mode 100644 common/src/main/java/com/lukasabbe/bookshelfinspector/util/BookshelfTools.java delete mode 100644 common/src/main/java/com/lukasabbe/bookshelfinspector/util/LecternTools.java create mode 100644 common/src/main/resources/data/c/tags/block/lectern.json diff --git a/common/src/main/java/com/lukasabbe/bookshelfinspector/BookshelfInspector.java b/common/src/main/java/com/lukasabbe/bookshelfinspector/BookshelfInspector.java index e41689d..dc7789d 100644 --- a/common/src/main/java/com/lukasabbe/bookshelfinspector/BookshelfInspector.java +++ b/common/src/main/java/com/lukasabbe/bookshelfinspector/BookshelfInspector.java @@ -20,5 +20,4 @@ public class BookshelfInspector { Services.NETWORK_HELPER.sendPacketFromServer(player, new ModCheckPayload(true)); }); } - } \ No newline at end of file diff --git a/common/src/main/java/com/lukasabbe/bookshelfinspector/BookshelfInspectorClient.java b/common/src/main/java/com/lukasabbe/bookshelfinspector/BookshelfInspectorClient.java index ac978db..338e3c3 100644 --- a/common/src/main/java/com/lukasabbe/bookshelfinspector/BookshelfInspectorClient.java +++ b/common/src/main/java/com/lukasabbe/bookshelfinspector/BookshelfInspectorClient.java @@ -18,6 +18,5 @@ public class BookshelfInspectorClient { modAvailable = false; bookShelfData = new BookShelfData(); }); - } } diff --git a/common/src/main/java/com/lukasabbe/bookshelfinspector/Constants.java b/common/src/main/java/com/lukasabbe/bookshelfinspector/Constants.java index 33c9951..ce9ed3a 100644 --- a/common/src/main/java/com/lukasabbe/bookshelfinspector/Constants.java +++ b/common/src/main/java/com/lukasabbe/bookshelfinspector/Constants.java @@ -9,7 +9,6 @@ public class Constants { public static final String MOD_NAME = "Bookshelf Inspector"; public static final Logger LOG = LoggerFactory.getLogger(MOD_NAME); - //Packets public static final ResourceLocation BOOK_SHELF_INVENTORY_REQUEST_PACKET_ID = ResourceLocation.fromNamespaceAndPath(MOD_ID,"book_shelf_inventory_request"); public static final ResourceLocation BOOK_SHELF_INVENTORY_PACKET_ID = ResourceLocation.fromNamespaceAndPath(MOD_ID,"book_shelf_inventory"); public static final ResourceLocation MOD_CHECK_PACKET_ID = ResourceLocation.fromNamespaceAndPath(MOD_ID,"mod_check"); diff --git a/common/src/main/java/com/lukasabbe/bookshelfinspector/data/Tags.java b/common/src/main/java/com/lukasabbe/bookshelfinspector/data/Tags.java index ca64b70..77d2cbb 100644 --- a/common/src/main/java/com/lukasabbe/bookshelfinspector/data/Tags.java +++ b/common/src/main/java/com/lukasabbe/bookshelfinspector/data/Tags.java @@ -7,4 +7,5 @@ import net.minecraft.world.level.block.Block; public class Tags { public static final TagKey CHISELED_BOOKSHELVES = TagKey.create(Registries.BLOCK, ResourceLocation.fromNamespaceAndPath("c", "chiseled_bookshelves")); + public static final TagKey LECTERNS = TagKey.create(Registries.BLOCK, ResourceLocation.fromNamespaceAndPath("c", "lectern")); } diff --git a/common/src/main/java/com/lukasabbe/bookshelfinspector/network/server/BookShelfInventoryRequestServerPayloadHandler.java b/common/src/main/java/com/lukasabbe/bookshelfinspector/network/server/BookShelfInventoryRequestServerPayloadHandler.java index 98d752a..4d81a47 100644 --- a/common/src/main/java/com/lukasabbe/bookshelfinspector/network/server/BookShelfInventoryRequestServerPayloadHandler.java +++ b/common/src/main/java/com/lukasabbe/bookshelfinspector/network/server/BookShelfInventoryRequestServerPayloadHandler.java @@ -5,7 +5,7 @@ import com.lukasabbe.bookshelfinspector.network.packets.BookShelfInventoryPayloa import com.lukasabbe.bookshelfinspector.network.packets.BookShelfInventoryRequestPayload; import com.lukasabbe.bookshelfinspector.platform.Services; import com.lukasabbe.bookshelfinspector.platform.handlers.ServerPayloadHandler; -import com.lukasabbe.bookshelfinspector.util.BookshelfTools; +import com.lukasabbe.bookshelfinspector.util.BlockTools; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; @@ -15,11 +15,13 @@ public class BookShelfInventoryRequestServerPayloadHandler implements ServerPayl public void receive(BookShelfInventoryRequestPayload bookShelfInventoryRequestPayload, ServerPlayer player) { if(BookshelfInspector.serverInstance == null) return; - ItemStack stack = BookshelfTools.getItemById(bookShelfInventoryRequestPayload.pos(),bookShelfInventoryRequestPayload.slotNum(), player); + ItemStack stack = BlockTools.getBookInChiseledBookShelf(bookShelfInventoryRequestPayload.pos(),bookShelfInventoryRequestPayload.slotNum(), player.level()); + if(stack == null){ Services.NETWORK_HELPER.sendPacketFromServer(player, new BookShelfInventoryPayload(Items.AIR.getDefaultInstance(), bookShelfInventoryRequestPayload.pos(), bookShelfInventoryRequestPayload.slotNum())); return; } + Services.NETWORK_HELPER.sendPacketFromServer(player, new BookShelfInventoryPayload(stack, bookShelfInventoryRequestPayload.pos(), bookShelfInventoryRequestPayload.slotNum())); } } diff --git a/common/src/main/java/com/lukasabbe/bookshelfinspector/network/server/LecternInventoryRequestServerPayloadHandler.java b/common/src/main/java/com/lukasabbe/bookshelfinspector/network/server/LecternInventoryRequestServerPayloadHandler.java index f54d602..29b823f 100644 --- a/common/src/main/java/com/lukasabbe/bookshelfinspector/network/server/LecternInventoryRequestServerPayloadHandler.java +++ b/common/src/main/java/com/lukasabbe/bookshelfinspector/network/server/LecternInventoryRequestServerPayloadHandler.java @@ -5,7 +5,7 @@ import com.lukasabbe.bookshelfinspector.network.packets.BookShelfInventoryPayloa import com.lukasabbe.bookshelfinspector.network.packets.LecternInventoryRequestPayload; import com.lukasabbe.bookshelfinspector.platform.Services; import com.lukasabbe.bookshelfinspector.platform.handlers.ServerPayloadHandler; -import com.lukasabbe.bookshelfinspector.util.LecternTools; +import com.lukasabbe.bookshelfinspector.util.BlockTools; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; @@ -15,12 +15,13 @@ public class LecternInventoryRequestServerPayloadHandler implements ServerPayloa public void receive(LecternInventoryRequestPayload lecternInventoryRequestPayload, ServerPlayer player) { if(BookshelfInspector.serverInstance == null) return; - ItemStack stack = LecternTools.getItemStack(lecternInventoryRequestPayload.pos(), player); + ItemStack stack = BlockTools.getBookInLectern(lecternInventoryRequestPayload.pos(), player.level()); if(stack == null){ Services.NETWORK_HELPER.sendPacketFromServer(player, new BookShelfInventoryPayload(Items.AIR.getDefaultInstance(), lecternInventoryRequestPayload.pos(), 0)); return; } + Services.NETWORK_HELPER.sendPacketFromServer(player, new BookShelfInventoryPayload(stack, lecternInventoryRequestPayload.pos(), 0)); } } diff --git a/common/src/main/java/com/lukasabbe/bookshelfinspector/platform/Services.java b/common/src/main/java/com/lukasabbe/bookshelfinspector/platform/Services.java index 037104b..1fda1bc 100644 --- a/common/src/main/java/com/lukasabbe/bookshelfinspector/platform/Services.java +++ b/common/src/main/java/com/lukasabbe/bookshelfinspector/platform/Services.java @@ -7,22 +7,12 @@ import com.lukasabbe.bookshelfinspector.platform.services.IPlatformHelper; import java.util.ServiceLoader; -// Service loaders are a built-in Java feature that allow us to locate implementations of an interface that vary from one -// environment to another. In the context of MultiLoader we use this feature to access a mock API in the common code that -// is swapped out for the platform specific implementation at runtime. public class Services { - // In this example we provide a platform helper which provides information about what platform the mod is running on. - // For example this can be used to check if the code is running on Forge vs Fabric, or to ask the modloader if another - // mod is loaded. public static final IPlatformHelper PLATFORM = load(IPlatformHelper.class); public static final INetworkHelper NETWORK_HELPER = load(INetworkHelper.class); public static final IEventHelper EVENTS_HELPER = load(IEventHelper.class); - // This code is used to load a service for the current environment. Your implementation of the service must be defined - // manually by including a text file in META-INF/services named with the fully qualified class name of the service. - // Inside the file you should write the fully qualified class name of the implementation to load for the platform. For - // example our file on Forge points to ForgePlatformHelper while Fabric points to FabricPlatformHelper. public static T load(Class clazz) { final T loadedService = ServiceLoader.load(clazz) diff --git a/common/src/main/java/com/lukasabbe/bookshelfinspector/renderer/Inspector.java b/common/src/main/java/com/lukasabbe/bookshelfinspector/renderer/Inspector.java index a936ba3..0156875 100644 --- a/common/src/main/java/com/lukasabbe/bookshelfinspector/renderer/Inspector.java +++ b/common/src/main/java/com/lukasabbe/bookshelfinspector/renderer/Inspector.java @@ -25,7 +25,6 @@ public class Inspector { if(client.cameraEntity == null || client.player == null) return; - //Send raycast max 5 blocks HitResult hit = client.cameraEntity.pick(5f,0f,false); //find block hit, if not found block returns @@ -51,7 +50,7 @@ public class Inspector { if(client.player.level().getBlockState(pos).is(Tags.CHISELED_BOOKSHELVES)){ bookShelfInspect(pos, blockHitResult, client); - }else if(client.player.level().getBlockState(pos).is(Blocks.LECTERN) && config.lecternToggle){ + }else if(client.player.level().getBlockState(pos).is(Tags.LECTERNS) && config.lecternToggle){ lecternInspect(pos); }else{ diff --git a/common/src/main/java/com/lukasabbe/bookshelfinspector/util/BlockTools.java b/common/src/main/java/com/lukasabbe/bookshelfinspector/util/BlockTools.java new file mode 100644 index 0000000..e22be58 --- /dev/null +++ b/common/src/main/java/com/lukasabbe/bookshelfinspector/util/BlockTools.java @@ -0,0 +1,26 @@ +package com.lukasabbe.bookshelfinspector.util; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.ChiseledBookShelfBlockEntity; +import net.minecraft.world.level.block.entity.LecternBlockEntity; + +public class BlockTools { + public static ItemStack getBookInChiseledBookShelf(BlockPos pos, int slotNum, Level world){ + final BlockEntity blockEntity = world.getBlockEntity(pos); + if(blockEntity instanceof ChiseledBookShelfBlockEntity chiseledBookShelf) { + final ItemStack stack = chiseledBookShelf.getItem(slotNum); + if(stack.isEmpty()) return null; + return stack; + } + return null; + } + + public static ItemStack getBookInLectern(BlockPos pos, Level world){ + final BlockEntity blockEntity = world.getBlockEntity(pos); + if(blockEntity instanceof LecternBlockEntity lecternBlockEntity) return lecternBlockEntity.getBook(); + return null; + } +} diff --git a/common/src/main/java/com/lukasabbe/bookshelfinspector/util/BookshelfTools.java b/common/src/main/java/com/lukasabbe/bookshelfinspector/util/BookshelfTools.java deleted file mode 100644 index 6f84817..0000000 --- a/common/src/main/java/com/lukasabbe/bookshelfinspector/util/BookshelfTools.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.lukasabbe.bookshelfinspector.util; - -import com.lukasabbe.bookshelfinspector.BookshelfInspector; -import net.minecraft.core.BlockPos; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.entity.ChiseledBookShelfBlockEntity; - -import java.util.Optional; - -public class BookshelfTools { - public static ItemStack getItemById(BlockPos pos, int slotNum, Player player){ - final Level world = BookshelfInspector.serverInstance.getPlayerList().getPlayer(player.getUUID()).level(); - - final Optional blockEntityOptional = world.getBlockEntity(pos, BlockEntityType.CHISELED_BOOKSHELF); - - if(blockEntityOptional.isEmpty()) return null; - - final ChiseledBookShelfBlockEntity blockEntity = blockEntityOptional.get(); - final ItemStack stack = blockEntity.getItem(slotNum); - - if(stack.isEmpty()) return null; - - return stack; - } -} diff --git a/common/src/main/java/com/lukasabbe/bookshelfinspector/util/LecternTools.java b/common/src/main/java/com/lukasabbe/bookshelfinspector/util/LecternTools.java deleted file mode 100644 index 0ef640e..0000000 --- a/common/src/main/java/com/lukasabbe/bookshelfinspector/util/LecternTools.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.lukasabbe.bookshelfinspector.util; - -import com.lukasabbe.bookshelfinspector.BookshelfInspector; -import net.minecraft.core.BlockPos; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.entity.LecternBlockEntity; - -import java.util.Optional; - -public class LecternTools { - public static ItemStack getItemStack(BlockPos pos, Player player){ - final Level world = BookshelfInspector.serverInstance.getPlayerList().getPlayer(player.getUUID()).level(); - - Optional blockEntityOptional = world.getBlockEntity(pos, BlockEntityType.LECTERN); - if(blockEntityOptional.isEmpty()) return null; - - LecternBlockEntity lecternBlock = blockEntityOptional.get(); - - return lecternBlock.getBook(); - } -} diff --git a/common/src/main/resources/data/c/tags/block/chiseled_bookshelves.json b/common/src/main/resources/data/c/tags/block/chiseled_bookshelves.json index fe20353..c3cfe98 100644 --- a/common/src/main/resources/data/c/tags/block/chiseled_bookshelves.json +++ b/common/src/main/resources/data/c/tags/block/chiseled_bookshelves.json @@ -1,6 +1,10 @@ { "replace": false, "values": [ - "minecraft:chiseled_bookshelf" + "minecraft:chiseled_bookshelf", + { + "id": "securitycraft:reinforced_chiseled_bookshelf", + "required": false + } ] } \ No newline at end of file diff --git a/common/src/main/resources/data/c/tags/block/lectern.json b/common/src/main/resources/data/c/tags/block/lectern.json new file mode 100644 index 0000000..7972076 --- /dev/null +++ b/common/src/main/resources/data/c/tags/block/lectern.json @@ -0,0 +1,10 @@ +{ + "replace": false, + "values": [ + "minecraft:lectern", + { + "id": "securitycraft:reinforced_lectern", + "required": false + } + ] +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 0236d8e..358a557 100644 --- a/settings.gradle +++ b/settings.gradle @@ -49,3 +49,5 @@ rootProject.name = 'BookshelfInspectorMultiloader' include('common') include('fabric') include('neoforge') + +include 'spigot' \ No newline at end of file