mirror of
https://github.com/lukasabbe/bookshelf-inspector.git
synced 2026-04-30 10:40:53 +00:00
Added support for securitycraft bookshelfs and lecterns
This commit is contained in:
@@ -20,5 +20,4 @@ public class BookshelfInspector {
|
|||||||
Services.NETWORK_HELPER.sendPacketFromServer(player, new ModCheckPayload(true));
|
Services.NETWORK_HELPER.sendPacketFromServer(player, new ModCheckPayload(true));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -18,6 +18,5 @@ public class BookshelfInspectorClient {
|
|||||||
modAvailable = false;
|
modAvailable = false;
|
||||||
bookShelfData = new BookShelfData();
|
bookShelfData = new BookShelfData();
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ public class Constants {
|
|||||||
public static final String MOD_NAME = "Bookshelf Inspector";
|
public static final String MOD_NAME = "Bookshelf Inspector";
|
||||||
public static final Logger LOG = LoggerFactory.getLogger(MOD_NAME);
|
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_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 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");
|
public static final ResourceLocation MOD_CHECK_PACKET_ID = ResourceLocation.fromNamespaceAndPath(MOD_ID,"mod_check");
|
||||||
|
|||||||
@@ -7,4 +7,5 @@ import net.minecraft.world.level.block.Block;
|
|||||||
|
|
||||||
public class Tags {
|
public class Tags {
|
||||||
public static final TagKey<Block> CHISELED_BOOKSHELVES = TagKey.create(Registries.BLOCK, ResourceLocation.fromNamespaceAndPath("c", "chiseled_bookshelves"));
|
public static final TagKey<Block> CHISELED_BOOKSHELVES = TagKey.create(Registries.BLOCK, ResourceLocation.fromNamespaceAndPath("c", "chiseled_bookshelves"));
|
||||||
|
public static final TagKey<Block> LECTERNS = TagKey.create(Registries.BLOCK, ResourceLocation.fromNamespaceAndPath("c", "lectern"));
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -5,7 +5,7 @@ import com.lukasabbe.bookshelfinspector.network.packets.BookShelfInventoryPayloa
|
|||||||
import com.lukasabbe.bookshelfinspector.network.packets.BookShelfInventoryRequestPayload;
|
import com.lukasabbe.bookshelfinspector.network.packets.BookShelfInventoryRequestPayload;
|
||||||
import com.lukasabbe.bookshelfinspector.platform.Services;
|
import com.lukasabbe.bookshelfinspector.platform.Services;
|
||||||
import com.lukasabbe.bookshelfinspector.platform.handlers.ServerPayloadHandler;
|
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.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.Items;
|
import net.minecraft.world.item.Items;
|
||||||
@@ -15,11 +15,13 @@ public class BookShelfInventoryRequestServerPayloadHandler implements ServerPayl
|
|||||||
public void receive(BookShelfInventoryRequestPayload bookShelfInventoryRequestPayload, ServerPlayer player) {
|
public void receive(BookShelfInventoryRequestPayload bookShelfInventoryRequestPayload, ServerPlayer player) {
|
||||||
if(BookshelfInspector.serverInstance == null) return;
|
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){
|
if(stack == null){
|
||||||
Services.NETWORK_HELPER.sendPacketFromServer(player, new BookShelfInventoryPayload(Items.AIR.getDefaultInstance(), bookShelfInventoryRequestPayload.pos(), bookShelfInventoryRequestPayload.slotNum()));
|
Services.NETWORK_HELPER.sendPacketFromServer(player, new BookShelfInventoryPayload(Items.AIR.getDefaultInstance(), bookShelfInventoryRequestPayload.pos(), bookShelfInventoryRequestPayload.slotNum()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Services.NETWORK_HELPER.sendPacketFromServer(player, new BookShelfInventoryPayload(stack, bookShelfInventoryRequestPayload.pos(), bookShelfInventoryRequestPayload.slotNum()));
|
Services.NETWORK_HELPER.sendPacketFromServer(player, new BookShelfInventoryPayload(stack, bookShelfInventoryRequestPayload.pos(), bookShelfInventoryRequestPayload.slotNum()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -5,7 +5,7 @@ import com.lukasabbe.bookshelfinspector.network.packets.BookShelfInventoryPayloa
|
|||||||
import com.lukasabbe.bookshelfinspector.network.packets.LecternInventoryRequestPayload;
|
import com.lukasabbe.bookshelfinspector.network.packets.LecternInventoryRequestPayload;
|
||||||
import com.lukasabbe.bookshelfinspector.platform.Services;
|
import com.lukasabbe.bookshelfinspector.platform.Services;
|
||||||
import com.lukasabbe.bookshelfinspector.platform.handlers.ServerPayloadHandler;
|
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.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.Items;
|
import net.minecraft.world.item.Items;
|
||||||
@@ -15,12 +15,13 @@ public class LecternInventoryRequestServerPayloadHandler implements ServerPayloa
|
|||||||
public void receive(LecternInventoryRequestPayload lecternInventoryRequestPayload, ServerPlayer player) {
|
public void receive(LecternInventoryRequestPayload lecternInventoryRequestPayload, ServerPlayer player) {
|
||||||
if(BookshelfInspector.serverInstance == null) return;
|
if(BookshelfInspector.serverInstance == null) return;
|
||||||
|
|
||||||
ItemStack stack = LecternTools.getItemStack(lecternInventoryRequestPayload.pos(), player);
|
ItemStack stack = BlockTools.getBookInLectern(lecternInventoryRequestPayload.pos(), player.level());
|
||||||
|
|
||||||
if(stack == null){
|
if(stack == null){
|
||||||
Services.NETWORK_HELPER.sendPacketFromServer(player, new BookShelfInventoryPayload(Items.AIR.getDefaultInstance(), lecternInventoryRequestPayload.pos(), 0));
|
Services.NETWORK_HELPER.sendPacketFromServer(player, new BookShelfInventoryPayload(Items.AIR.getDefaultInstance(), lecternInventoryRequestPayload.pos(), 0));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Services.NETWORK_HELPER.sendPacketFromServer(player, new BookShelfInventoryPayload(stack, lecternInventoryRequestPayload.pos(), 0));
|
Services.NETWORK_HELPER.sendPacketFromServer(player, new BookShelfInventoryPayload(stack, lecternInventoryRequestPayload.pos(), 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,22 +7,12 @@ import com.lukasabbe.bookshelfinspector.platform.services.IPlatformHelper;
|
|||||||
|
|
||||||
import java.util.ServiceLoader;
|
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 {
|
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 IPlatformHelper PLATFORM = load(IPlatformHelper.class);
|
||||||
public static final INetworkHelper NETWORK_HELPER = load(INetworkHelper.class);
|
public static final INetworkHelper NETWORK_HELPER = load(INetworkHelper.class);
|
||||||
public static final IEventHelper EVENTS_HELPER = load(IEventHelper.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> T load(Class<T> clazz) {
|
public static <T> T load(Class<T> clazz) {
|
||||||
|
|
||||||
final T loadedService = ServiceLoader.load(clazz)
|
final T loadedService = ServiceLoader.load(clazz)
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ public class Inspector {
|
|||||||
|
|
||||||
if(client.cameraEntity == null || client.player == null) return;
|
if(client.cameraEntity == null || client.player == null) return;
|
||||||
|
|
||||||
//Send raycast max 5 blocks
|
|
||||||
HitResult hit = client.cameraEntity.pick(5f,0f,false);
|
HitResult hit = client.cameraEntity.pick(5f,0f,false);
|
||||||
|
|
||||||
//find block hit, if not found block returns
|
//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)){
|
if(client.player.level().getBlockState(pos).is(Tags.CHISELED_BOOKSHELVES)){
|
||||||
bookShelfInspect(pos, blockHitResult, client);
|
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);
|
lecternInspect(pos);
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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<ChiseledBookShelfBlockEntity> 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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<LecternBlockEntity> blockEntityOptional = world.getBlockEntity(pos, BlockEntityType.LECTERN);
|
|
||||||
if(blockEntityOptional.isEmpty()) return null;
|
|
||||||
|
|
||||||
LecternBlockEntity lecternBlock = blockEntityOptional.get();
|
|
||||||
|
|
||||||
return lecternBlock.getBook();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
{
|
{
|
||||||
"replace": false,
|
"replace": false,
|
||||||
"values": [
|
"values": [
|
||||||
"minecraft:chiseled_bookshelf"
|
"minecraft:chiseled_bookshelf",
|
||||||
|
{
|
||||||
|
"id": "securitycraft:reinforced_chiseled_bookshelf",
|
||||||
|
"required": false
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"replace": false,
|
||||||
|
"values": [
|
||||||
|
"minecraft:lectern",
|
||||||
|
{
|
||||||
|
"id": "securitycraft:reinforced_lectern",
|
||||||
|
"required": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -49,3 +49,5 @@ rootProject.name = 'BookshelfInspectorMultiloader'
|
|||||||
include('common')
|
include('common')
|
||||||
include('fabric')
|
include('fabric')
|
||||||
include('neoforge')
|
include('neoforge')
|
||||||
|
|
||||||
|
include 'spigot'
|
||||||
Reference in New Issue
Block a user