mirror of
https://github.com/lukasabbe/bookshelf-inspector.git
synced 2026-04-30 10:40:53 +00:00
Merge branch '1.21.6' into Temp-main
This commit is contained in:
@@ -15,25 +15,27 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Bookshelfinspector implements ModInitializer {
|
||||
|
||||
public static MinecraftServer serverInstance;
|
||||
public final static String MOD_ID = "bookshelfinspector";
|
||||
|
||||
public static Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
//Registers request types
|
||||
//Registers client-to-server payloads
|
||||
PayloadTypeRegistry.playC2S().register(BookShelfInventoryRequestPayload.ID,BookShelfInventoryRequestPayload.CODEC);
|
||||
PayloadTypeRegistry.playC2S().register(LecternInventoryRequestPayload.ID, LecternInventoryRequestPayload.CODEC);
|
||||
PayloadTypeRegistry.playS2C().register(BookShelfInventoryPayload.ID,BookShelfInventoryPayload.CODEC);
|
||||
PayloadTypeRegistry.playS2C().register(ModCheckPayload.ID, ModCheckPayload.CODEC);
|
||||
|
||||
//Registers server-to-client receivers
|
||||
ServerPlayNetworking.registerGlobalReceiver(BookShelfInventoryRequestPayload.ID, new BookShelfInventoryRequestPayloadHandler());
|
||||
ServerPlayNetworking.registerGlobalReceiver(LecternInventoryRequestPayload.ID, new LecternInventoryRequestPayloadHandler());
|
||||
|
||||
ServerPlayConnectionEvents.JOIN.register(((handler, sender, server) -> {
|
||||
serverInstance = server;
|
||||
ServerPlayNetworking.send(handler.player, new ModCheckPayload(true));
|
||||
LOGGER.info("[" + MOD_ID + "] {} has Bookshelf Inspector and is now turned on!", handler.player.getName());
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ public class BookshelfinspectorClient implements ClientModInitializer {
|
||||
|
||||
config.loadConfig();
|
||||
|
||||
//Registers server-to-client receivers
|
||||
ClientPlayNetworking.registerGlobalReceiver(BookShelfInventoryPayload.ID, new BookShelfInventoryHandler());
|
||||
ClientPlayNetworking.registerGlobalReceiver(ModCheckPayload.ID,new ModPayloadHandler());
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/*
|
||||
package me.lukasabbe.bookshelfinspector.config;
|
||||
|
||||
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||
@@ -44,3 +45,4 @@ public class ModMenu implements ModMenuApi {
|
||||
};
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -11,7 +11,7 @@ import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
public class ModPayloadHandler implements ClientPlayNetworking.PlayPayloadHandler<ModCheckPayload> {
|
||||
@Override
|
||||
public void receive(ModCheckPayload modCheckPayload, ClientPlayNetworking.Context context) {
|
||||
context.client().execute(() ->{
|
||||
context.client().execute(() -> {
|
||||
Bookshelfinspector.LOGGER.info("[bookshelfinspector] Connected to server");
|
||||
BookshelfinspectorClient.modAvailable = true;
|
||||
});
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
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;
|
||||
@@ -12,7 +11,7 @@ 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();
|
||||
final World world = player.getWorld();
|
||||
|
||||
if(world == null) return null;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.client.gui.GuiLayer;
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.component.type.ItemEnchantmentsComponent;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
@@ -19,6 +19,7 @@ import net.minecraft.text.Style;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.Texts;
|
||||
import net.minecraft.util.Formatting;
|
||||
import org.joml.Matrix3x2fStack;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class HudRenderer {
|
||||
@@ -27,6 +28,7 @@ public class HudRenderer {
|
||||
if(client.options.hudHidden) return;
|
||||
if(!BookshelfinspectorClient.bookShelfData.isCurrentBookDataToggled) return;
|
||||
|
||||
context.pushGuiLayer(GuiLayer.HUD);
|
||||
final BookData currentBookData = BookshelfinspectorClient.currentBookData;
|
||||
final int screenWidth = client.getWindow().getScaledWidth();
|
||||
final int screenHeight = client.getWindow().getScaledHeight();
|
||||
@@ -78,15 +80,17 @@ public class HudRenderer {
|
||||
drawScaledText(context, Text.translatable("book.byAuthor",writtenBookContentComponent.author()), x,y+(int)(20*scaleFactor), 0xFFFFFFFF,client.textRenderer);
|
||||
}
|
||||
|
||||
context.popGuiLayer();
|
||||
|
||||
}
|
||||
private static void drawScaledText(DrawContext context, Text text, int centerX, int y, int color, TextRenderer textRenderer){
|
||||
MatrixStack stack = context.getMatrices();
|
||||
stack.push();
|
||||
stack.translate(centerX,y,0);
|
||||
Matrix3x2fStack stack = context.getMatrices();
|
||||
stack.pushMatrix();
|
||||
stack.translate(centerX,y);
|
||||
final float scale = (float) BookshelfinspectorClient.config.scale / 10;
|
||||
stack.scale(scale, scale, scale);
|
||||
stack.translate(-centerX,-y,0);
|
||||
stack.scale(scale, scale);
|
||||
stack.translate(-centerX,-y);
|
||||
context.drawCenteredTextWithShadow(textRenderer,text,centerX,y,color);
|
||||
stack.pop();
|
||||
stack.popMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package me.lukasabbe.bookshelfinspector.util;
|
||||
|
||||
import me.lukasabbe.bookshelfinspector.Bookshelfinspector;
|
||||
import me.lukasabbe.bookshelfinspector.BookshelfinspectorClient;
|
||||
import me.lukasabbe.bookshelfinspector.data.BookData;
|
||||
import me.lukasabbe.bookshelfinspector.data.Tags;
|
||||
@@ -28,10 +29,10 @@ public class Inspector {
|
||||
|
||||
if(client.cameraEntity == null || client.player == null) return;
|
||||
|
||||
//Send raycast max 5 blocks
|
||||
//Send ray-cast max 5 blocks
|
||||
HitResult hit = client.cameraEntity.raycast(5f,0f,false);
|
||||
|
||||
//find block hit, if not found block returns
|
||||
//Find block hit, if not found block returns
|
||||
final HitResult.Type type = hit.getType();
|
||||
if(type != HitResult.Type.BLOCK) {
|
||||
resetBookShelfData();
|
||||
@@ -41,6 +42,7 @@ public class Inspector {
|
||||
final BlockHitResult blockHitResult = (BlockHitResult) hit;
|
||||
BlockPos pos = blockHitResult.getBlockPos();
|
||||
|
||||
|
||||
if(bookShelfData.latestPos == null)
|
||||
bookShelfData.latestPos = pos;
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package me.lukasabbe.bookshelfinspector.util;
|
||||
|
||||
import me.lukasabbe.bookshelfinspector.Bookshelfinspector;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.block.entity.LecternBlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
@@ -12,14 +11,14 @@ import java.util.Optional;
|
||||
|
||||
public class LecternTools {
|
||||
public static ItemStack getItemStack(BlockPos pos, PlayerEntity player){
|
||||
final World world = Bookshelfinspector.serverInstance.getPlayerManager().getPlayer(player.getUuid()).getWorld();
|
||||
|
||||
final World world = player.getWorld();
|
||||
if(world == null) return null;
|
||||
|
||||
Optional<LecternBlockEntity> blockEntityOptional = world.getBlockEntity(pos, BlockEntityType.LECTERN);
|
||||
if(blockEntityOptional.isEmpty()) return null;
|
||||
|
||||
LecternBlockEntity lecternBlock = blockEntityOptional.get();
|
||||
|
||||
return lecternBlock.getBook();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@ import java.util.TreeMap;
|
||||
|
||||
//https://stackoverflow.com/questions/12967896/converting-integers-to-roman-numerals-java
|
||||
public class RomanNumerals {
|
||||
|
||||
private final static TreeMap<Integer, String> map = new TreeMap<>();
|
||||
|
||||
static {
|
||||
map.put(1000, "M");
|
||||
map.put(900, "CM");
|
||||
@@ -21,7 +23,6 @@ public class RomanNumerals {
|
||||
map.put(1, "I");
|
||||
}
|
||||
|
||||
|
||||
public static String toRoman(int number){
|
||||
int key = map.floorKey(number);
|
||||
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
],
|
||||
"main": [
|
||||
"me.lukasabbe.bookshelfinspector.Bookshelfinspector"
|
||||
],
|
||||
"modmenu": [
|
||||
"me.lukasabbe.bookshelfinspector.config.ModMenu"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
@@ -25,7 +22,7 @@
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=${loader_version}",
|
||||
"minecraft": ">=1.21.5",
|
||||
"minecraft": ">=1.21.6-alpha.25.15.a",
|
||||
"fabric-api-base": "*",
|
||||
"fabric-networking-api-v1": "*",
|
||||
"fabric-lifecycle-events-v1": "*",
|
||||
|
||||
Reference in New Issue
Block a user