From fea26a22cd73cf15081f6cc8fd1cefa1edb380c0 Mon Sep 17 00:00:00 2001 From: Hendrix-Shen Date: Fri, 9 Aug 2024 23:45:32 +0800 Subject: [PATCH] MagicLib 0.8.593+ Signed-off-by: Hendrix-Shen --- gradle.properties | 4 ++-- .../com/plusls/MasaGadget/game/Configs.java | 4 ++-- .../feature/entityInfo/EntityInfoRenderer.java | 7 ++++++- .../VillageTradeEnchantedBookInfo.java | 4 ++-- .../entityInfo/VillagerNextRestockTimeInfo.java | 12 ++++++++---- .../ZombieVillagerConvertTimeInfo.java | 6 +++--- .../ComparatorInfo.java | 2 +- .../MixinZombieVillagerEntity.java | 2 +- .../plusls/MasaGadget/util/PcaSyncProtocol.java | 4 ++-- .../util/SearchMobSpawnPointUtil.java | 17 +++++++++-------- .../com/plusls/MasaGadget/util/SyncUtil.java | 2 +- 11 files changed, 37 insertions(+), 27 deletions(-) diff --git a/gradle.properties b/gradle.properties index 36807f2..a612df0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,8 +18,8 @@ mod.version=4.0 ## Annotation processor dependencies.lombok_version=1.18.34 ## MagicLib -dependencies.magiclib_dependency=0.8.576 -dependencies.magiclib_version=0.8.585-beta +dependencies.magiclib_dependency=0.8.596 +dependencies.magiclib_version=0.8.596-beta # Gradle Plugins architectury_loom_version=1.7-SNAPSHOT diff --git a/src/main/java/com/plusls/MasaGadget/game/Configs.java b/src/main/java/com/plusls/MasaGadget/game/Configs.java index d75c379..3f6a0bc 100644 --- a/src/main/java/com/plusls/MasaGadget/game/Configs.java +++ b/src/main/java/com/plusls/MasaGadget/game/Configs.java @@ -223,8 +223,8 @@ public static void init() { PcaSyncProtocol.syncEntity(entity.getId()); } - InfoUtil.displayChatMessage(ComponentUtil.tr("masa_gadget_mod.message.syncAllEntityDataSuccess") - .withStyle(ChatFormatting.GREEN).get()); + InfoUtil.displayChatMessage(ComponentUtil.trCompat("masa_gadget_mod.message.syncAllEntityDataSuccess") + .withStyle(ChatFormatting.GREEN)); return true; }); diff --git a/src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/EntityInfoRenderer.java b/src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/EntityInfoRenderer.java index 7d91d2b..eea2ec5 100644 --- a/src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/EntityInfoRenderer.java +++ b/src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/EntityInfoRenderer.java @@ -7,6 +7,7 @@ import lombok.Getter; import net.minecraft.client.Minecraft; import net.minecraft.core.Position; +import net.minecraft.network.chat.Component; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.monster.ZombieVillager; @@ -67,7 +68,11 @@ public void postRenderLevel(Level level, RenderContext renderContext, float part TextRenderer renderer = TextRenderer.create(); if (Configs.renderNextRestockTime.getBooleanValue()) { - renderer.addLine(VillagerNextRestockTimeInfo.getInfo(villager)); + Component info = VillagerNextRestockTimeInfo.getInfo(villager); + + if (info != null) { + renderer.addLine(info); + } } if (Configs.renderTradeEnchantedBook.getBooleanValue()) { diff --git a/src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/VillageTradeEnchantedBookInfo.java b/src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/VillageTradeEnchantedBookInfo.java index 6f20e1b..8da9b56 100644 --- a/src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/VillageTradeEnchantedBookInfo.java +++ b/src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/VillageTradeEnchantedBookInfo.java @@ -38,7 +38,7 @@ public class VillageTradeEnchantedBookInfo { } if (!Minecraft.getInstance().hasSingleplayerServer() && !PcaSyncProtocol.enable) { - return Lists.newArrayList(ComponentUtil.tr("masa_gadget_mod.message.no_data").withStyle(ChatFormatting.YELLOW).get()); + return Lists.newArrayList(ComponentUtil.tr("masa_gadget_mod.message.no_data").withStyle(ChatFormatting.YELLOW)); } List ret = Lists.newArrayList(); @@ -121,7 +121,7 @@ public class VillageTradeEnchantedBookInfo { //#else //$$ ret.add(((BaseComponent) entry.getKey().getFullname(entry.getValue())).withStyle(enchantment_level_color)); //#endif - ret.add(ComponentUtil.simple(String.format("%d(%d-%d)", cost, minCost, maxCost)).withStyle(cast_color).get()); + ret.add(ComponentUtil.simple(String.format("%d(%d-%d)", cost, minCost, maxCost)).withStyle(cast_color)); } break; diff --git a/src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/VillagerNextRestockTimeInfo.java b/src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/VillagerNextRestockTimeInfo.java index 2666ba0..46728f3 100644 --- a/src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/VillagerNextRestockTimeInfo.java +++ b/src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/VillagerNextRestockTimeInfo.java @@ -12,13 +12,17 @@ import top.hendrixshen.magiclib.util.minecraft.ComponentUtil; public class VillagerNextRestockTimeInfo { - public static @NotNull Component getInfo(@NotNull Villager villager) { + public static Component getInfo(@NotNull Villager villager) { long nextRestockTime; long nextWorkTime; long timeOfDay = villager.getLevel().getDayTime() % 24000; + if (villager.getVillagerData().getProfession() != VillagerProfession.LIBRARIAN) { + return null; + } + if (!Minecraft.getInstance().hasSingleplayerServer() && !PcaSyncProtocol.enable) { - return ComponentUtil.tr("masa_gadget_mod.message.no_data").withStyle(ChatFormatting.YELLOW).get(); + return ComponentUtil.tr("masa_gadget_mod.message.no_data").withStyle(ChatFormatting.YELLOW); } if (timeOfDay >= 2000 && timeOfDay <= 9000) { @@ -52,10 +56,10 @@ public class VillagerNextRestockTimeInfo { } if (nextRestockTime == 0) { - return ComponentUtil.simple("OK").withStyle(ChatFormatting.GREEN).get(); + return ComponentUtil.simple("OK").withStyle(ChatFormatting.GREEN); } - return ComponentUtil.simple(String.format("%d", nextRestockTime)).get(); + return ComponentUtil.simple(String.format("%d", nextRestockTime)); } // 因为刁民的需要补货的函数,会检查当前货物是否被消耗,从使用的角度只需要关心当前货物是否用完 diff --git a/src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/ZombieVillagerConvertTimeInfo.java b/src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/ZombieVillagerConvertTimeInfo.java index 8dc6690..7688ef4 100644 --- a/src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/ZombieVillagerConvertTimeInfo.java +++ b/src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/ZombieVillagerConvertTimeInfo.java @@ -12,15 +12,15 @@ public class ZombieVillagerConvertTimeInfo { public static @NotNull Component getInfo(ZombieVillager zombieVillager) { if (!Minecraft.getInstance().hasSingleplayerServer() && !PcaSyncProtocol.enable) { - return ComponentUtil.tr("masa_gadget_mod.message.no_data").withStyle(ChatFormatting.YELLOW).get(); + return ComponentUtil.tr("masa_gadget_mod.message.no_data").withStyle(ChatFormatting.YELLOW); } int villagerConversionTime = ((AccessorZombieVillager) zombieVillager).masa_gadget_mod$$getVillagerConversionTime(); if (villagerConversionTime > 0) { - return ComponentUtil.simple(String.format("%d", villagerConversionTime)).get(); + return ComponentUtil.simple(String.format("%d", villagerConversionTime)); } - return ComponentUtil.simple("-1").get(); + return ComponentUtil.simple("-1"); } } diff --git a/src/main/java/com/plusls/MasaGadget/impl/mod_tweak/tweakeroo/inventoryPreviewSupportComparator/ComparatorInfo.java b/src/main/java/com/plusls/MasaGadget/impl/mod_tweak/tweakeroo/inventoryPreviewSupportComparator/ComparatorInfo.java index 3a3643c..7f2ef9d 100644 --- a/src/main/java/com/plusls/MasaGadget/impl/mod_tweak/tweakeroo/inventoryPreviewSupportComparator/ComparatorInfo.java +++ b/src/main/java/com/plusls/MasaGadget/impl/mod_tweak/tweakeroo/inventoryPreviewSupportComparator/ComparatorInfo.java @@ -48,7 +48,7 @@ public void postRenderLevel(Level entity, RenderContext renderContext, float par if (pos.isPresent() && blockEntity instanceof ComparatorBlockEntity) { TextRenderer.create() .text(ComponentUtil.simple(((ComparatorBlockEntity) blockEntity).getOutputSignal()) - .withStyle(ChatFormatting.GREEN).get()) + .withStyle(ChatFormatting.GREEN)) .atCenter(pos.get()) .seeThrough() .render(); diff --git a/src/main/java/com/plusls/MasaGadget/mixin/feature/autoSyncEntityData/MixinZombieVillagerEntity.java b/src/main/java/com/plusls/MasaGadget/mixin/feature/autoSyncEntityData/MixinZombieVillagerEntity.java index bb826d6..bbec892 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/feature/autoSyncEntityData/MixinZombieVillagerEntity.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/feature/autoSyncEntityData/MixinZombieVillagerEntity.java @@ -45,7 +45,7 @@ private void syncVillagerData(byte status, CallbackInfo ci) { @Inject(method = "tick", at = @At("RETURN")) private void syncConvertingData(CallbackInfo ci) { - if (EntityCompat.of(this).getLevelCompat().get().get().isClientSide() && this.isAlive() && this.isConverting()) { + if (EntityCompat.of(this).getLevel().isClientSide() && this.isAlive() && this.isConverting()) { int i = this.getConversionProgress(); this.villagerConversionTime -= i; diff --git a/src/main/java/com/plusls/MasaGadget/util/PcaSyncProtocol.java b/src/main/java/com/plusls/MasaGadget/util/PcaSyncProtocol.java index 1e9752d..3490ec9 100644 --- a/src/main/java/com/plusls/MasaGadget/util/PcaSyncProtocol.java +++ b/src/main/java/com/plusls/MasaGadget/util/PcaSyncProtocol.java @@ -154,7 +154,7 @@ public static void updateEntityHandler( } PlayerCompat playerCompat = PlayerCompat.of(player); - LevelCompat levelCompat = playerCompat.getLevel(); + LevelCompat levelCompat = playerCompat.getLevelCompat(); Level level = levelCompat.get(); if (!levelCompat.getDimensionLocation().equals( @@ -274,7 +274,7 @@ public static void updateBlockEntityHandler( return; } - LevelCompat levelCompat = PlayerCompat.of(player).getLevel(); + LevelCompat levelCompat = PlayerCompat.of(player).getLevelCompat(); Level level = levelCompat.get(); if (!levelCompat.getDimensionLocation().equals( diff --git a/src/main/java/com/plusls/MasaGadget/util/SearchMobSpawnPointUtil.java b/src/main/java/com/plusls/MasaGadget/util/SearchMobSpawnPointUtil.java index 85ea894..c5ae9d1 100644 --- a/src/main/java/com/plusls/MasaGadget/util/SearchMobSpawnPointUtil.java +++ b/src/main/java/com/plusls/MasaGadget/util/SearchMobSpawnPointUtil.java @@ -21,6 +21,7 @@ import org.jetbrains.annotations.Nullable; import top.hendrixshen.magiclib.MagicLib; import top.hendrixshen.magiclib.api.compat.minecraft.network.chat.ComponentCompat; +import top.hendrixshen.magiclib.api.compat.minecraft.network.chat.MutableComponentCompat; import top.hendrixshen.magiclib.api.compat.minecraft.resources.ResourceLocationCompat; import top.hendrixshen.magiclib.api.compat.minecraft.world.level.LevelCompat; import top.hendrixshen.magiclib.util.minecraft.ComponentUtil; @@ -46,16 +47,16 @@ private static ShapeDespawnSphere getShapeDespawnSphere() { if (ret == null) { ret = (ShapeDespawnSphere) shapeBase; } else { - InfoUtil.displayChatMessage(ComponentUtil.tr("masa_gadget_mod.message.onlySupportOneDespawnShape") - .withStyle(ChatFormatting.RED).get()); + InfoUtil.displayChatMessage(ComponentUtil.trCompat("masa_gadget_mod.message.onlySupportOneDespawnShape") + .withStyle(ChatFormatting.RED)); return null; } } } if (ret == null) { - InfoUtil.displayChatMessage(ComponentUtil.tr("masa_gadget_mod.message.canNotFindDespawnShape") - .withStyle(ChatFormatting.RED).get()); + InfoUtil.displayChatMessage(ComponentUtil.trCompat("masa_gadget_mod.message.canNotFindDespawnShape") + .withStyle(ChatFormatting.RED)); } return ret; @@ -155,21 +156,21 @@ public static void search() { } } - ComponentCompat text; + MutableComponentCompat text; if (spawnPos == null) { - text = ComponentUtil.tr("masa_gadget_mod.message.noBlockCanSpawn") + text = ComponentUtil.trCompat("masa_gadget_mod.message.noBlockCanSpawn") .withStyle(ChatFormatting.GREEN); } else { // for ommc parser - text = ComponentUtil.tr("masa_gadget_mod.message.spawnPos", spawnPos.getX(), spawnPos.getY(), spawnPos.getZ()); + text = ComponentUtil.trCompat("masa_gadget_mod.message.spawnPos", spawnPos.getX(), spawnPos.getY(), spawnPos.getZ()); if (MagicLib.getInstance().getCurrentPlatform().isModLoaded(ModId.oh_my_minecraft_client)) { InfoUtil.sendCommand(String.format("highlightWaypoint %d %d %d", spawnPos.getX(), spawnPos.getY(), spawnPos.getZ())); } } - InfoUtil.displayChatMessage(text.get()); + InfoUtil.displayChatMessage(text); } private static double squaredDistanceTo(int x, int y, int z, Vec3 vec3d) { diff --git a/src/main/java/com/plusls/MasaGadget/util/SyncUtil.java b/src/main/java/com/plusls/MasaGadget/util/SyncUtil.java index 5d7a721..88b2d8e 100644 --- a/src/main/java/com/plusls/MasaGadget/util/SyncUtil.java +++ b/src/main/java/com/plusls/MasaGadget/util/SyncUtil.java @@ -23,7 +23,7 @@ public static Entity syncEntityDataFromIntegratedServer(Entity entity) { ServerLevel level = server.getLevel( //#if MC > 11502 - entityCompat.getLevel().get().dimension() + entityCompat.getLevel().dimension() //#else //$$ entity.dimension //#endif