mirror of
https://github.com/lukasabbe/bookshelf-inspector.git
synced 2026-04-30 10:40:53 +00:00
29 lines
1.1 KiB
Java
29 lines
1.1 KiB
Java
package me.lukasabbe.bookshelfinspector.util;
|
|
|
|
import me.lukasabbe.bookshelfinspector.Bookshelfinspector;
|
|
import net.minecraft.block.entity.BlockEntityType;
|
|
import net.minecraft.block.entity.ChiseledBookshelfBlockEntity;
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.world.World;
|
|
|
|
import java.util.Optional;
|
|
|
|
public class BookshelfTools {
|
|
public static ItemStack getItemById(BlockPos pos, int slotNum, PlayerEntity player){
|
|
final World world = Bookshelfinspector.serverInstance.getPlayerManager().getPlayer(player.getUuid()).getWorld();
|
|
|
|
if(world == null) return null;
|
|
Optional<ChiseledBookshelfBlockEntity> blockEntityOptional = world.getBlockEntity(pos,BlockEntityType.CHISELED_BOOKSHELF);
|
|
if(blockEntityOptional.isEmpty()) return null;
|
|
|
|
ChiseledBookshelfBlockEntity blockEntity = blockEntityOptional.get();
|
|
|
|
final ItemStack stack = blockEntity.getStack(slotNum);
|
|
if(stack.isEmpty()) return null;
|
|
|
|
return stack;
|
|
}
|
|
}
|