From e3c09ddf931f084753f4d30fb799ce460725697e Mon Sep 17 00:00:00 2001 From: Hendrix-Shen Date: Fri, 28 Jun 2024 16:39:58 +0800 Subject: [PATCH] Support MC 1.20.6 - Migrant to MagicLib 0.8 - Refactored package structure Signed-off-by: Hendrix-Shen --- build.gradle | 32 +- .../src/main/resources/fabric.mod.json | 2 +- gradle.properties | 18 +- gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle | 43 +- settings.json | 16 + .../com/plusls/MasaGadget/MasaGadgetMod.java | 100 +++-- .../java/com/plusls/MasaGadget/ModInfo.java | 32 +- .../plusls/MasaGadget/SharedConstants.java | 32 ++ .../api/event/DisconnectListener.java | 7 + .../api/gui/MasaGadgetDropdownList.java | 19 + .../api/network/packet/PCAPacket.java | 4 + .../compat/modmenu/ModMenuApiImpl.java | 25 -- .../compat/modmenu/WrapperModMenuApiImpl.java | 10 - .../com/plusls/MasaGadget/config/Configs.java | 298 ------------- .../MasaGadget/event/DisconnectEvent.java | 23 - .../com/plusls/MasaGadget/game/ConfigGui.java | 52 +++ .../com/plusls/MasaGadget/game/Configs.java | 243 +++++++++++ .../entityInfo/EntityInfoRenderer.java | 80 ---- .../VillageTradeEnchantedBookInfo.java | 77 ---- .../entityTrace/EntityTraceRenderer.java | 71 --- .../com/plusls/MasaGadget/gui/GuiConfigs.java | 16 - .../MasaGadget/gui/IDropdownRenderer.java | 17 - .../MasaGadget/gui/MyWidgetDropDownList.java | 56 --- .../MasaGadget/gui/ScalableWidgetLabel.java | 53 --- .../gui/WidgetIconToggleButton.java | 87 ---- .../impl/compat/modmenu/ModMenuApiImpl.java | 25 ++ .../compat/modmenu/WrapperModMenuApiImpl.java | 10 + .../impl/event/DisconnectEvent.java | 19 + .../CacheContainerMenuHandler.java | 57 ++- .../entityInfo/EntityInfoRenderer.java | 102 +++++ .../VillageTradeEnchantedBookInfo.java | 120 +++++ .../VillagerNextRestockTimeInfo.java | 10 +- .../ZombieVillagerConvertTimeInfo.java | 8 +- .../entityTrace/EntityTraceRenderer.java | 90 ++++ .../generic/HitResultHandler.java} | 192 ++++---- .../{ => impl}/gui/MasaGadgetIcons.java | 4 +- .../impl/gui/ScalableWidgetLabel.java | 100 +++++ .../FastMasaGuiSwitcher.java | 159 +++++++ .../MalilibFavoritesButton.java | 69 +++ .../MalilibFavoritesData.java | 57 +++ .../ComparatorInfo.java | 57 +++ .../InventoryOverlayRenderHandler.java | 410 ++++++++++++++++++ .../MouseScrollInputHandler.java | 76 ++++ .../MasaGadget/impl/network/NoopCodec.java | 4 + ...ientboundDisablePcaSyncProtocolPacket.java | 4 + ...lientboundEnablePcaSyncProtocolPacket.java | 4 + .../ClientboundUpdateBlockEntityPacket.java | 4 + .../packet/ClientboundUpdateEntityPacket.java | 4 + ...erverboundCancelSyncBlockEntityPacket.java | 4 + .../ServerboundCancelSyncEntityPacket.java | 4 + .../ServerboundSyncBlockEntityPacket.java | 4 + .../packet/ServerboundSyncEntityPacket.java | 4 + .../fastSwitchMasaConfigGui/MasaGuiUtil.java | 149 ------- .../MasaGadget/mixin/MixinConnection.java | 18 +- .../mixin/accessor/AccessorGuiComponent.java | 8 + .../disconnect/MixinMinecraftClient.java | 13 +- .../MixinClientPlayNetworkHandler.java | 6 +- .../MixinVillagerEntity.java | 8 +- .../MixinZombieVillagerEntity.java | 8 +- .../MixinClientPacketListener.java | 57 ++- .../cacheContainerMenu/MixinLocalPlayer.java | 13 +- .../MixinMultiPlayerGameMode.java | 26 +- .../MixinWorldUtils.java | 23 - .../backportI18nSupport/MixinConfigBase.java | 52 --- .../MixinConfigBooleanClient.java | 28 -- .../MixinFeatureToggle.java | 35 -- .../backportI18nSupport/MixinInfoToggle.java | 35 -- .../MixinRendererToggle.java | 35 -- .../MixinGuiConfigBase.java | 88 ---- .../MixinWidgetDropDownList.java | 61 --- .../MixinWidgetListBase.java | 112 ----- .../malilib/favorites/MixinGuiConfigBase.java | 60 --- .../MixinWidgetListConfigOptions.java | 27 -- .../betterEasyPlaceMode/MixinWorldUtils.java | 39 +- .../MixinWorldUtils.java | 30 ++ .../MixinBlockItem.java | 19 +- .../MixinWorldUtils.java | 178 +++++--- .../MixinInputHandler.java | 20 +- .../MixinSchematicUtils.java | 16 +- .../MixinSchematicPlacement.java | 22 +- .../backportI18nSupport/MixinConfigBase.java | 65 +++ .../MixinGuiConfigBase.java | 93 ++++ .../MixinWidgetListBase.java | 148 +++++++ .../favoritesSupport/MixinGuiConfigBase.java | 57 +++ .../MixinWidgetConfigOption.java | 47 +- .../MixinWidgetListConfigOptions.java | 38 +- .../MixinWidgetListConfigOptions.java | 74 ++++ .../MixinInventoryOverlay.java | 47 +- .../fixSearchbarHotkeyInput/MixinGuiBase.java | 33 +- .../MixinWidgetListConfigOptions.java | 22 +- .../MixinWidgetConfigOption.java | 27 +- .../MixinWidgetListConfigOptions.java | 36 +- .../backportI18nSupport/MixinInfoToggle.java | 57 +++ .../MixinRendererToggle.java | 55 +++ .../minihudI18n/MixinRenderHandler.java | 39 +- .../MixinConfigBooleanClient.java | 35 ++ .../MixinFeatureToggle.java | 56 +++ .../MixinInventoryUtils.java | 53 +++ .../MixinRenderUtils.java | 62 ++- .../MixinInGameHud.java | 47 ++ .../MixinInventoryOverlay.java | 44 ++ .../MixinRenderUtils.java | 86 ++++ .../MixinRenderUtils.java | 63 ++- .../MixinClientPacketListener.java | 24 +- .../MixinMixinRenderUtils.java | 52 ++- .../MixinInventoryUtils.java | 38 -- .../MixinGameRenderer.java | 14 - .../MixinWorldRenderer.java | 58 --- .../MixinInGameHud.java | 42 -- .../MixinInventoryOverlay.java | 33 -- .../MixinRenderUtils.java | 55 --- .../InventoryOverlayRenderHandler.java | 378 ---------------- .../MouseScrollInputHandler.java | 64 --- .../BlockPlacer.java | 2 +- ...nventoryPreviewSyncDataClientOnlyUtil.java | 24 +- .../InventoryPreviewSyncDataUtil.java | 49 ++- .../com/plusls/MasaGadget/util/MiscUtil.java | 4 +- .../MasaGadget/util/PcaSyncProtocol.java | 208 +++++++-- .../PcaSyncUtil.java | 3 +- .../plusls/MasaGadget/util/RenderUtil.java | 80 +--- .../RestockUtil.java | 39 +- .../util/SearchMobSpawnPointUtil.java | 119 +++-- .../com/plusls/MasaGadget/util/SyncUtil.java | 15 +- .../assets/masa_gadget_mod/lang/en_us.json | 175 ++++---- .../assets/masa_gadget_mod/lang/zh_cn.json | 175 ++++---- .../assets/masa_gadget_mod/lang/zh_tw.json | 12 +- src/main/resources/fabric.mod.json | 4 +- .../resources/masa_gadget_mod.mixins.json | 86 ++-- common.gradle => versions/1.14.4/build.gradle | 102 ++--- .../MixinGameRenderer.java | 57 --- .../mixin/accessor/AccessorGuiComponent.java | 25 ++ versions/1.20.6/gradle.properties | 9 + .../api/network/packet/PCAPacket.java | 12 + .../MasaGadget/impl/network/NoopCodec.java | 24 + ...ientboundDisablePcaSyncProtocolPacket.java | 34 ++ ...lientboundEnablePcaSyncProtocolPacket.java | 34 ++ .../ClientboundUpdateBlockEntityPacket.java | 34 ++ .../packet/ClientboundUpdateEntityPacket.java | 34 ++ ...erverboundCancelSyncBlockEntityPacket.java | 15 + .../ServerboundCancelSyncEntityPacket.java | 15 + .../ServerboundSyncBlockEntityPacket.java | 15 + .../packet/ServerboundSyncEntityPacket.java | 15 + 143 files changed, 4305 insertions(+), 3359 deletions(-) create mode 100644 settings.json create mode 100644 src/main/java/com/plusls/MasaGadget/SharedConstants.java create mode 100644 src/main/java/com/plusls/MasaGadget/api/event/DisconnectListener.java create mode 100644 src/main/java/com/plusls/MasaGadget/api/gui/MasaGadgetDropdownList.java create mode 100644 src/main/java/com/plusls/MasaGadget/api/network/packet/PCAPacket.java delete mode 100644 src/main/java/com/plusls/MasaGadget/compat/modmenu/ModMenuApiImpl.java delete mode 100644 src/main/java/com/plusls/MasaGadget/compat/modmenu/WrapperModMenuApiImpl.java delete mode 100644 src/main/java/com/plusls/MasaGadget/config/Configs.java delete mode 100644 src/main/java/com/plusls/MasaGadget/event/DisconnectEvent.java create mode 100644 src/main/java/com/plusls/MasaGadget/game/ConfigGui.java create mode 100644 src/main/java/com/plusls/MasaGadget/game/Configs.java delete mode 100644 src/main/java/com/plusls/MasaGadget/generic/entityInfo/EntityInfoRenderer.java delete mode 100644 src/main/java/com/plusls/MasaGadget/generic/entityInfo/VillageTradeEnchantedBookInfo.java delete mode 100644 src/main/java/com/plusls/MasaGadget/generic/entityTrace/EntityTraceRenderer.java delete mode 100644 src/main/java/com/plusls/MasaGadget/gui/GuiConfigs.java delete mode 100644 src/main/java/com/plusls/MasaGadget/gui/IDropdownRenderer.java delete mode 100644 src/main/java/com/plusls/MasaGadget/gui/MyWidgetDropDownList.java delete mode 100644 src/main/java/com/plusls/MasaGadget/gui/ScalableWidgetLabel.java delete mode 100644 src/main/java/com/plusls/MasaGadget/gui/WidgetIconToggleButton.java create mode 100644 src/main/java/com/plusls/MasaGadget/impl/compat/modmenu/ModMenuApiImpl.java create mode 100644 src/main/java/com/plusls/MasaGadget/impl/compat/modmenu/WrapperModMenuApiImpl.java create mode 100644 src/main/java/com/plusls/MasaGadget/impl/event/DisconnectEvent.java rename src/main/java/com/plusls/MasaGadget/{generic/cacheContainerMenu => impl/feature}/cacheContainerMenu/CacheContainerMenuHandler.java (53%) create mode 100644 src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/EntityInfoRenderer.java create mode 100644 src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/VillageTradeEnchantedBookInfo.java rename src/main/java/com/plusls/MasaGadget/{generic => impl/feature}/entityInfo/VillagerNextRestockTimeInfo.java (86%) rename src/main/java/com/plusls/MasaGadget/{generic => impl/feature}/entityInfo/ZombieVillagerConvertTimeInfo.java (64%) create mode 100644 src/main/java/com/plusls/MasaGadget/impl/feature/entityTrace/EntityTraceRenderer.java rename src/main/java/com/plusls/MasaGadget/{util/HitResultUtil.java => impl/generic/HitResultHandler.java} (50%) rename src/main/java/com/plusls/MasaGadget/{ => impl}/gui/MasaGadgetIcons.java (94%) create mode 100644 src/main/java/com/plusls/MasaGadget/impl/gui/ScalableWidgetLabel.java create mode 100644 src/main/java/com/plusls/MasaGadget/impl/mod_tweak/malilib/fastSwitchMasaConfigGui/FastMasaGuiSwitcher.java create mode 100644 src/main/java/com/plusls/MasaGadget/impl/mod_tweak/malilib/favoritesSupport/MalilibFavoritesButton.java create mode 100644 src/main/java/com/plusls/MasaGadget/impl/mod_tweak/malilib/favoritesSupport/MalilibFavoritesData.java create mode 100644 src/main/java/com/plusls/MasaGadget/impl/mod_tweak/tweakeroo/inventoryPreviewSupportComparator/ComparatorInfo.java create mode 100644 src/main/java/com/plusls/MasaGadget/impl/mod_tweak/tweakeroo/inventoryPreviewSupportSelect/InventoryOverlayRenderHandler.java create mode 100644 src/main/java/com/plusls/MasaGadget/impl/mod_tweak/tweakeroo/inventoryPreviewSupportSelect/MouseScrollInputHandler.java create mode 100644 src/main/java/com/plusls/MasaGadget/impl/network/NoopCodec.java create mode 100644 src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundDisablePcaSyncProtocolPacket.java create mode 100644 src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundEnablePcaSyncProtocolPacket.java create mode 100644 src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundUpdateBlockEntityPacket.java create mode 100644 src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundUpdateEntityPacket.java create mode 100644 src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundCancelSyncBlockEntityPacket.java create mode 100644 src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundCancelSyncEntityPacket.java create mode 100644 src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundSyncBlockEntityPacket.java create mode 100644 src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundSyncEntityPacket.java delete mode 100644 src/main/java/com/plusls/MasaGadget/malilib/fastSwitchMasaConfigGui/MasaGuiUtil.java create mode 100644 src/main/java/com/plusls/MasaGadget/mixin/accessor/AccessorGuiComponent.java rename src/main/java/com/plusls/MasaGadget/mixin/{generic => feature}/autoSyncEntityData/MixinClientPlayNetworkHandler.java (94%) rename src/main/java/com/plusls/MasaGadget/mixin/{generic => feature}/autoSyncEntityData/MixinVillagerEntity.java (88%) rename src/main/java/com/plusls/MasaGadget/mixin/{generic => feature}/autoSyncEntityData/MixinZombieVillagerEntity.java (90%) rename src/main/java/com/plusls/MasaGadget/mixin/{generic => feature}/cacheContainerMenu/MixinClientPacketListener.java (70%) rename src/main/java/com/plusls/MasaGadget/mixin/{generic => feature}/cacheContainerMenu/MixinLocalPlayer.java (52%) rename src/main/java/com/plusls/MasaGadget/mixin/{generic => feature}/cacheContainerMenu/MixinMultiPlayerGameMode.java (52%) delete mode 100644 src/main/java/com/plusls/MasaGadget/mixin/litematica/disableLitematicaEasyPlaceFailTip/MixinWorldUtils.java delete mode 100644 src/main/java/com/plusls/MasaGadget/mixin/malilib/backportI18nSupport/MixinConfigBase.java delete mode 100644 src/main/java/com/plusls/MasaGadget/mixin/malilib/backportI18nSupport/MixinConfigBooleanClient.java delete mode 100644 src/main/java/com/plusls/MasaGadget/mixin/malilib/backportI18nSupport/MixinFeatureToggle.java delete mode 100644 src/main/java/com/plusls/MasaGadget/mixin/malilib/backportI18nSupport/MixinInfoToggle.java delete mode 100644 src/main/java/com/plusls/MasaGadget/mixin/malilib/backportI18nSupport/MixinRendererToggle.java delete mode 100644 src/main/java/com/plusls/MasaGadget/mixin/malilib/fastSwitchMasaConfigGui/MixinGuiConfigBase.java delete mode 100644 src/main/java/com/plusls/MasaGadget/mixin/malilib/fastSwitchMasaConfigGui/MixinWidgetDropDownList.java delete mode 100644 src/main/java/com/plusls/MasaGadget/mixin/malilib/fastSwitchMasaConfigGui/MixinWidgetListBase.java delete mode 100644 src/main/java/com/plusls/MasaGadget/mixin/malilib/favorites/MixinGuiConfigBase.java delete mode 100644 src/main/java/com/plusls/MasaGadget/mixin/malilib/fixConfigWidgetWidth/MixinWidgetListConfigOptions.java rename src/main/java/com/plusls/MasaGadget/mixin/{ => mod_tweak}/litematica/betterEasyPlaceMode/MixinWorldUtils.java (64%) create mode 100644 src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/litematica/disableLitematicaEasyPlaceFailTip/MixinWorldUtils.java rename src/main/java/com/plusls/MasaGadget/mixin/{ => mod_tweak}/litematica/fixCarpetAccurateProtocol/MixinBlockItem.java (78%) rename src/main/java/com/plusls/MasaGadget/mixin/{ => mod_tweak}/litematica/fixCarpetAccurateProtocol/MixinWorldUtils.java (56%) rename src/main/java/com/plusls/MasaGadget/mixin/{ => mod_tweak}/litematica/nudgeSelectionSupportFreeCamera/MixinInputHandler.java (60%) rename src/main/java/com/plusls/MasaGadget/mixin/{ => mod_tweak}/litematica/saveInventoryToSchematicInServer/MixinSchematicUtils.java (73%) rename src/main/java/com/plusls/MasaGadget/mixin/{ => mod_tweak}/litematica/useRelativePath/MixinSchematicPlacement.java (58%) create mode 100644 src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/backportI18nSupport/MixinConfigBase.java create mode 100644 src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/fastSwitchMasaConfigGui/MixinGuiConfigBase.java create mode 100644 src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/fastSwitchMasaConfigGui/MixinWidgetListBase.java create mode 100644 src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/favoritesSupport/MixinGuiConfigBase.java rename src/main/java/com/plusls/MasaGadget/mixin/{malilib/favorites => mod_tweak/malilib/favoritesSupport}/MixinWidgetConfigOption.java (53%) rename src/main/java/com/plusls/MasaGadget/mixin/{malilib/favorites => mod_tweak/malilib/favoritesSupport}/MixinWidgetListConfigOptions.java (64%) create mode 100644 src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/fixConfigWidgetWidth/MixinWidgetListConfigOptions.java rename src/main/java/com/plusls/MasaGadget/mixin/{ => mod_tweak}/malilib/fixGetInventoryType/MixinInventoryOverlay.java (51%) rename src/main/java/com/plusls/MasaGadget/mixin/{ => mod_tweak}/malilib/fixSearchbarHotkeyInput/MixinGuiBase.java (56%) rename src/main/java/com/plusls/MasaGadget/mixin/{ => mod_tweak}/malilib/optimizeConfigWidgetSearch/MixinWidgetListConfigOptions.java (80%) rename src/main/java/com/plusls/MasaGadget/mixin/{ => mod_tweak}/malilib/showOriginalConfigName/MixinWidgetConfigOption.java (63%) rename src/main/java/com/plusls/MasaGadget/mixin/{ => mod_tweak}/malilib/showOriginalConfigName/MixinWidgetListConfigOptions.java (54%) create mode 100644 src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/minihud/backportI18nSupport/MixinInfoToggle.java create mode 100644 src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/minihud/backportI18nSupport/MixinRendererToggle.java rename src/main/java/com/plusls/MasaGadget/mixin/{ => mod_tweak}/minihud/minihudI18n/MixinRenderHandler.java (55%) create mode 100644 src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/backportI18nSupport/MixinConfigBooleanClient.java create mode 100644 src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/backportI18nSupport/MixinFeatureToggle.java create mode 100644 src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/handRestockCrafting/MixinInventoryUtils.java rename src/main/java/com/plusls/MasaGadget/mixin/{ => mod_tweak}/tweakeroo/inventoryPreviewSupportPlayer/MixinRenderUtils.java (54%) create mode 100644 src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/inventoryPreviewSupportSelect/MixinInGameHud.java create mode 100644 src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/inventoryPreviewSupportSelect/MixinInventoryOverlay.java create mode 100644 src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/inventoryPreviewSupportShulkerBoxItemEntity/MixinRenderUtils.java rename src/main/java/com/plusls/MasaGadget/mixin/{ => mod_tweak}/tweakeroo/inventoryPreviewSupportTradeOfferList/MixinRenderUtils.java (64%) rename src/main/java/com/plusls/MasaGadget/mixin/{ => mod_tweak}/tweakeroo/inventoryPreviewSyncDataClientOnly/MixinClientPacketListener.java (63%) rename src/main/java/com/plusls/MasaGadget/mixin/{ => mod_tweak}/tweakeroo/inventoryPreviewUseCache/MixinMixinRenderUtils.java (60%) delete mode 100644 src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/handRestockCrafting/MixinInventoryUtils.java delete mode 100644 src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportComparator/MixinGameRenderer.java delete mode 100644 src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportComparator/MixinWorldRenderer.java delete mode 100644 src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportSelect/MixinInGameHud.java delete mode 100644 src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportSelect/MixinInventoryOverlay.java delete mode 100644 src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportShulkerBoxItemEntity/MixinRenderUtils.java delete mode 100644 src/main/java/com/plusls/MasaGadget/tweakeroo/inventoryPreviewSupportSelect/InventoryOverlayRenderHandler.java delete mode 100644 src/main/java/com/plusls/MasaGadget/tweakeroo/inventoryPreviewSupportSelect/MouseScrollInputHandler.java rename src/main/java/com/plusls/MasaGadget/{litematica/fixCarpetAccurateProtocol => util}/BlockPlacer.java (98%) rename src/main/java/com/plusls/MasaGadget/{tweakeroo/inventoryPreviewSyncDataClientOnly => util}/InventoryPreviewSyncDataClientOnlyUtil.java (78%) rename src/main/java/com/plusls/MasaGadget/{tweakeroo/inventoryPreviewSyncData => util}/InventoryPreviewSyncDataUtil.java (72%) rename src/main/java/com/plusls/MasaGadget/{litematica/saveInventoryToSchematicInServer => util}/PcaSyncUtil.java (95%) rename src/main/java/com/plusls/MasaGadget/{tweakeroo/handRestockCrafting => util}/RestockUtil.java (73%) rename common.gradle => versions/1.14.4/build.gradle (70%) delete mode 100644 versions/1.14.4/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportComparator/MixinGameRenderer.java create mode 100644 versions/1.19.4/src/main/java/com/plusls/MasaGadget/mixin/accessor/AccessorGuiComponent.java create mode 100644 versions/1.20.6/gradle.properties create mode 100644 versions/1.20.6/src/main/java/com/plusls/MasaGadget/api/network/packet/PCAPacket.java create mode 100644 versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/NoopCodec.java create mode 100644 versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundDisablePcaSyncProtocolPacket.java create mode 100644 versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundEnablePcaSyncProtocolPacket.java create mode 100644 versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundUpdateBlockEntityPacket.java create mode 100644 versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundUpdateEntityPacket.java create mode 100644 versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundCancelSyncBlockEntityPacket.java create mode 100644 versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundCancelSyncEntityPacket.java create mode 100644 versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundSyncBlockEntityPacket.java create mode 100644 versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundSyncEntityPacket.java diff --git a/build.gradle b/build.gradle index 56b9031a..db5ff1f6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,22 +1,25 @@ +import com.replaymod.gradle.preprocess.Node + plugins { - id("fabric-loom").version("1.4-SNAPSHOT").apply(false) + id("fabric-loom").version("${fabric_loom_version}").apply(false) id("maven-publish") - id("org.ajoberstar.grgit").version("5.2.0") - id("com.replaymod.preprocess").version("SNAPSHOT") + id("org.ajoberstar.grgit").version("${grgit_version}") + id("com.replaymod.preprocess").version("${preprocessor_version}") } preprocess { - def mc1144 = createNode("1.14.4", 1_14_04, "mojang") - def mc1152 = createNode("1.15.2", 1_15_02, "mojang") - def mc1165 = createNode("1.16.5", 1_16_05, "mojang") - def mc1171 = createNode("1.17.1", 1_17_01, "mojang") - def mc1182 = createNode("1.18.2", 1_18_02, "mojang") - def mc1192 = createNode("1.19.2", 1_19_02, "mojang") - def mc1193 = createNode("1.19.3", 1_19_03, "mojang") - def mc1194 = createNode("1.19.4", 1_19_04, "mojang") - def mc1201 = createNode("1.20.1", 1_20_01, "mojang") - def mc1202 = createNode("1.20.2", 1_20_02, "mojang") - def mc1204 = createNode("1.20.4", 1_20_04, "mojang") + Node mc1144 = createNode("1.14.4", 1_14_04, "mojang") + Node mc1152 = createNode("1.15.2", 1_15_02, "mojang") + Node mc1165 = createNode("1.16.5", 1_16_05, "mojang") + Node mc1171 = createNode("1.17.1", 1_17_01, "mojang") + Node mc1182 = createNode("1.18.2", 1_18_02, "mojang") + Node mc1192 = createNode("1.19.2", 1_19_02, "mojang") + Node mc1193 = createNode("1.19.3", 1_19_03, "mojang") + Node mc1194 = createNode("1.19.4", 1_19_04, "mojang") + Node mc1201 = createNode("1.20.1", 1_20_01, "mojang") + Node mc1202 = createNode("1.20.2", 1_20_02, "mojang") + Node mc1204 = createNode("1.20.4", 1_20_04, "mojang") + Node mc1206 = createNode("1.20.6", 1_20_06, "mojang") mc1144.link(mc1152, null) mc1152.link(mc1165, file("versions/mapping-1.15.2-1.16.5.txt")) @@ -28,6 +31,7 @@ preprocess { mc1194.link(mc1201, null) mc1201.link(mc1202, null) mc1202.link(mc1204, null) + mc1204.link(mc1206, null) } ext { diff --git a/fabricWrapper/src/main/resources/fabric.mod.json b/fabricWrapper/src/main/resources/fabric.mod.json index 26f162d2..41801ff4 100644 --- a/fabricWrapper/src/main/resources/fabric.mod.json +++ b/fabricWrapper/src/main/resources/fabric.mod.json @@ -28,7 +28,7 @@ "environment": "client", "entrypoints": { "modmenu": [ - "com.plusls.MasaGadget.compat.modmenu.WrapperModMenuApiImpl" + "com.plusls.MasaGadget.impl.compat.modmenu.WrapperModMenuApiImpl" ] }, "depends": { diff --git a/gradle.properties b/gradle.properties index 45eee661..cec771db 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,5 @@ # Gradle properties -org.gradle.cache.cleanup=false org.gradle.jvmargs=-Xmx6G -org.gradle.parallel=true # Mod Properties mod_archives_base_name=MasaGadget @@ -11,13 +9,19 @@ mod_maven_group=com.plusls mod_name=Masa Gadget mod_homepage=https://blog.plusls.com/ mod_sources=https://github.com/plusls/MasaGadget -mod_version=3.2 +mod_version=4.0 mod_license=LGPL-3.0 # Required Libraries -# MagicLib - 0.7.398 -magiclib_dependency=0.7.398 -magiclib_version=0.7.398 +# MagicLib - 0.8.562 +magiclib_dependency=0.8.562 +magiclib_version=0.8.562 # Annotation processor -lombok_version=1.18.30 \ No newline at end of file +lombok_version=1.18.30 + +# Gradle Plugins +fabric_loom_version=1.6-SNAPSHOT +grgit_version=5.2.2 +preprocessor_version=ce1aeb2b +replace_token_version=1.1.2 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a5952066..28f5fcf9 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle index 35f39d6a..91c82a04 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,5 @@ +import groovy.json.JsonSlurper + pluginManagement { repositories { mavenLocal() @@ -13,38 +15,29 @@ pluginManagement { name("Jitpack") url("https://jitpack.io") } + } - maven { - name("Nyan Maven") - url("https://maven.hendrixshen.top") - } - - maven { - name("Cotton") - url("https://server.bbkr.space/artifactory/libs-release") + resolutionStrategy { + eachPlugin { + switch (requested.id.id) { + case "com.replaymod.preprocess": { + useModule("com.github.Fallen-Breath:preprocessor:${requested.version}") + break + } + } } } } -def versions = Arrays.asList( - "1.14.4", - "1.15.2", - "1.16.5", - "1.17.1", - "1.18.2", - "1.19.2", - "1.19.3", - "1.19.4", - "1.20.1", - "1.20.2", - "1.20.4", -) +Map> settings = file("settings.json").withReader { + new JsonSlurper().parse(it) as Map> +} -for (String version : versions) { +for (String version : settings.get("versions")) { include(":$version") - def proj = project(":$version") - proj.projectDir = file("versions/$version") - proj.buildFileName = "../../common.gradle" + ProjectDescriptor proj = project(":$version") + proj.setProjectDir(file("versions/$version")) + proj.setBuildFileName("../${settings.versions.get(0)}/build.gradle") } include(":fabricWrapper") diff --git a/settings.json b/settings.json new file mode 100644 index 00000000..73dcf4e1 --- /dev/null +++ b/settings.json @@ -0,0 +1,16 @@ +{ + "versions": [ + "1.14.4", + "1.15.2", + "1.16.5", + "1.17.1", + "1.18.2", + "1.19.2", + "1.19.3", + "1.19.4", + "1.20.1", + "1.20.2", + "1.20.4", + "1.20.6" + ] +} \ No newline at end of file diff --git a/src/main/java/com/plusls/MasaGadget/MasaGadgetMod.java b/src/main/java/com/plusls/MasaGadget/MasaGadgetMod.java index 431d8db3..1224531c 100644 --- a/src/main/java/com/plusls/MasaGadget/MasaGadgetMod.java +++ b/src/main/java/com/plusls/MasaGadget/MasaGadgetMod.java @@ -1,61 +1,73 @@ package com.plusls.MasaGadget; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.generic.entityInfo.EntityInfoRenderer; -import com.plusls.MasaGadget.generic.entityTrace.EntityTraceRenderer; -import com.plusls.MasaGadget.util.HitResultUtil; -import com.plusls.MasaGadget.tweakeroo.inventoryPreviewSupportSelect.MouseScrollInputHandler; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.impl.feature.entityInfo.EntityInfoRenderer; +import com.plusls.MasaGadget.impl.feature.entityTrace.EntityTraceRenderer; +import com.plusls.MasaGadget.impl.mod_tweak.malilib.fastSwitchMasaConfigGui.FastMasaGuiSwitcher; +import com.plusls.MasaGadget.impl.mod_tweak.malilib.favoritesSupport.MalilibFavoritesData; +import com.plusls.MasaGadget.impl.generic.HitResultHandler; +import com.plusls.MasaGadget.impl.mod_tweak.tweakeroo.inventoryPreviewSupportComparator.ComparatorInfo; +import com.plusls.MasaGadget.impl.mod_tweak.tweakeroo.inventoryPreviewSupportSelect.MouseScrollInputHandler; import com.plusls.MasaGadget.util.PcaSyncProtocol; +import fi.dy.masa.malilib.config.ConfigManager; +import fi.dy.masa.malilib.event.InitializationHandler; +import fi.dy.masa.malilib.event.InputEventHandler; +import fi.dy.masa.malilib.hotkeys.IKeybindProvider; import net.fabricmc.api.ClientModInitializer; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; -import top.hendrixshen.magiclib.malilib.impl.ConfigHandler; -import top.hendrixshen.magiclib.malilib.impl.ConfigManager; +import top.hendrixshen.magiclib.MagicLib; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; +import top.hendrixshen.magiclib.api.event.minecraft.MinecraftListener; -public class MasaGadgetMod implements ClientModInitializer { - private static final int CONFIG_VERSION = 1; - - @Dependencies(and = { +public class MasaGadgetMod implements ClientModInitializer, MinecraftListener { + @Dependencies(require = { //#if MC > 11701 - @Dependency(value = "itemscoller", versionPredicate = ">=0.16.0", optional = true), - @Dependency(value = "litematica", versionPredicate = ">=0.11.0", optional = true), - @Dependency(value = "minihud", versionPredicate = ">=0.22.0", optional = true), - @Dependency(value = "tweakeroo", versionPredicate = ">=0.13.1", optional = true) + @Dependency(value = "itemscroller", versionPredicates = ">=0.16.0", optional = true), + @Dependency(value = "litematica", versionPredicates = ">=0.11.0", optional = true), + @Dependency(value = "minihud", versionPredicates = ">=0.22.0", optional = true), + @Dependency(value = "tweakeroo", versionPredicates = ">=0.13.1", optional = true) //#elseif MC > 11605 - //$$ @Dependency(value = "itemscoller", versionPredicate = ">=0.15.0-dev.20211201.010054", optional = true), - //$$ @Dependency(value = "litematica", versionPredicate = ">=0.9.0", optional = true), - //$$ @Dependency(value = "minihud", versionPredicate = ">=0.20.0", optional = true), - //$$ @Dependency(value = "tweakeroo", versionPredicate = ">=0.11.0", optional = true) + //$$ @Dependency(value = "itemscroller", versionPredicates = ">=0.15.0-dev.20211201.010054", optional = true), + //$$ @Dependency(value = "litematica", versionPredicates = ">=0.9.0", optional = true), + //$$ @Dependency(value = "minihud", versionPredicates = ">=0.20.0", optional = true), + //$$ @Dependency(value = "tweakeroo", versionPredicates = ">=0.11.0", optional = true) //#elseif MC > 11502 - //$$ @Dependency(value = "itemscoller", versionPredicate = ">=0.15.0-dev.20210917.191808", optional = true), - //$$ @Dependency(value = "litematica", versionPredicate = ">=0.0.0-dev.20210917.192300", optional = true), - //$$ @Dependency(value = "minihud", versionPredicate = ">=0.19.0-dev.20210917.191825", optional = true), - //$$ @Dependency(value = "tweakeroo", versionPredicate = ">=0.10.0-dev.20210917.191839", optional = true) + //$$ @Dependency(value = "itemscroller", versionPredicates = ">=0.15.0-dev.20210917.191808", optional = true), + //$$ @Dependency(value = "litematica", versionPredicates = ">=0.0.0-dev.20210917.192300", optional = true), + //$$ @Dependency(value = "minihud", versionPredicates = ">=0.19.0-dev.20210917.191825", optional = true), + //$$ @Dependency(value = "tweakeroo", versionPredicates = ">=0.10.0-dev.20210917.191839", optional = true) //#elseif MC > 11404 - //$$ @Dependency(value = "itemscoller", versionPredicate = ">=0.15.0-dev.20200212.183513", optional = true), - //$$ @Dependency(value = "litematica", versionPredicate = ">=0.0.0-dev.20200515.184506", optional = true), - //$$ @Dependency(value = "minihud", versionPredicate = ">=0.19.0-dev.20200427.222110", optional = true), - //$$ @Dependency(value = "tweakeroo", versionPredicate = ">=0.10.0-dev.20200424.222527", optional = true) + //$$ @Dependency(value = "itemscroller", versionPredicates = ">=0.15.0-dev.20200212.183513", optional = true), + //$$ @Dependency(value = "litematica", versionPredicates = ">=0.0.0-dev.20200515.184506", optional = true), + //$$ @Dependency(value = "minihud", versionPredicates = ">=0.19.0-dev.20200427.222110", optional = true), + //$$ @Dependency(value = "tweakeroo", versionPredicates = ">=0.10.0-dev.20200424.222527", optional = true) //#else - //$$ @Dependency(value = "itemscoller", versionPredicate = ">=0.15.0-dev.20190720.190250", optional = true), - //$$ @Dependency(value = "litematica", versionPredicate = ">=0.0.0-dev.20191222.014040", optional = true), - //$$ @Dependency(value = "minihud", versionPredicate = ">=0.19.0-dev.20191007.003640", optional = true), - //$$ @Dependency(value = "tweakeroo", versionPredicate = ">=0.10.0-dev.20190903.193019", optional = true) + //$$ @Dependency(value = "itemscroller", versionPredicates = ">=0.15.0-dev.20190720.190250", optional = true), + //$$ @Dependency(value = "litematica", versionPredicates = ">=0.0.0-dev.20191222.014040", optional = true), + //$$ @Dependency(value = "minihud", versionPredicates = ">=0.19.0-dev.20191007.003640", optional = true), + //$$ @Dependency(value = "tweakeroo", versionPredicates = ">=0.10.0-dev.20190903.193019", optional = true) //#endif }) @Override public void onInitializeClient() { - ConfigManager cm = ConfigManager.get(ModInfo.MOD_ID); - cm.parseConfigClass(Configs.class); - ModInfo.configHandler = new ConfigHandler(ModInfo.MOD_ID, cm, CONFIG_VERSION); - ModInfo.configHandler.preDeserializeCallback = Configs::preDeserialize; - ModInfo.configHandler.postSerializeCallback = Configs::postSerialize; - ConfigHandler.register(ModInfo.configHandler); - Configs.init(cm); + InitializationHandler.getInstance().registerInitializationHandler(() -> + ConfigManager.getInstance().registerConfigHandler(SharedConstants.getModIdentifier(), + SharedConstants.getConfigHandler())); + Configs.init(); + InputEventHandler.getKeybindManager().registerKeybindProvider( + (IKeybindProvider) SharedConstants.getConfigManager()); PcaSyncProtocol.init(); - MouseScrollInputHandler.register(); - EntityInfoRenderer.init(); - EntityTraceRenderer.init(); - HitResultUtil.init(); + MouseScrollInputHandler.getInstance().init(); + EntityInfoRenderer.getInstance().init(); + EntityTraceRenderer.getInstance().init(); + HitResultHandler.getInstance().init(); + ComparatorInfo.getInstance().init(); + MagicLib.getInstance().getEventManager().register(MinecraftListener.class, this); + } + + @Override + public void postInit() { + FastMasaGuiSwitcher.getInstance().init(); + SharedConstants.getConfigHandler().registerExternalData("malilib_favorites", MalilibFavoritesData.getInstance()); } } diff --git a/src/main/java/com/plusls/MasaGadget/ModInfo.java b/src/main/java/com/plusls/MasaGadget/ModInfo.java index cecfe288..889d838a 100644 --- a/src/main/java/com/plusls/MasaGadget/ModInfo.java +++ b/src/main/java/com/plusls/MasaGadget/ModInfo.java @@ -1,20 +1,10 @@ package com.plusls.MasaGadget; -import net.fabricmc.loader.api.FabricLoader; import net.minecraft.resources.ResourceLocation; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -import top.hendrixshen.magiclib.compat.minecraft.api.network.chat.ComponentCompatApi; -import top.hendrixshen.magiclib.malilib.impl.ConfigHandler; -import top.hendrixshen.magiclib.language.api.I18n; - -//#if MC > 11502 -import net.minecraft.network.chat.MutableComponent; -//#else -//$$ import net.minecraft.network.chat.BaseComponent; -//#endif public class ModInfo { public static final String ITEMSCROLLER_MOD_ID = "itemscroller"; @@ -23,28 +13,8 @@ public class ModInfo { public static final String MODMENU_MOD_ID = "modmenu"; public static final String OMMC_MOD_ID = "ommc"; public static final String TWEAKEROO_MOD_ID = "tweakeroo"; - public static String MOD_ID = "@MOD_IDENTIFIER@"; - public static final String CURRENT_MOD_ID = "@MOD_IDENTIFIER@-@MINECRAFT_VERSION_IDENTIFY@"; - public static final String MOD_NAME = FabricLoader.getInstance().getModContainer(CURRENT_MOD_ID) - .orElseThrow(RuntimeException::new).getMetadata().getName(); - public static final String MOD_VERSION = FabricLoader.getInstance().getModContainer(CURRENT_MOD_ID) - .orElseThrow(RuntimeException::new).getMetadata().getVersion().getFriendlyString(); + public static String MOD_ID = "masa_gadget_mod"; public static final Logger LOGGER = LogManager.getLogger(MOD_ID); - public static ConfigHandler configHandler; - - public static String translate(String key, Object... objects) { - return I18n.get(ModInfo.MOD_ID + "." + key, objects); - } - - public static @NotNull - //#if MC > 11502 - MutableComponent - //#else - //$$ BaseComponent - //#endif - translatable(String key, Object... objects) { - return ComponentCompatApi.translatable(ModInfo.MOD_ID + "." + key, objects); - } @Contract("_ -> new") public static @NotNull ResourceLocation id(String path) { diff --git a/src/main/java/com/plusls/MasaGadget/SharedConstants.java b/src/main/java/com/plusls/MasaGadget/SharedConstants.java new file mode 100644 index 00000000..86bd39d6 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/SharedConstants.java @@ -0,0 +1,32 @@ +package com.plusls.MasaGadget; + +import lombok.Getter; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.NotNull; +import top.hendrixshen.magiclib.api.malilib.config.MagicConfigManager; +import top.hendrixshen.magiclib.impl.malilib.config.GlobalConfigManager; +import top.hendrixshen.magiclib.impl.malilib.config.MagicConfigHandler; +import top.hendrixshen.magiclib.util.VersionUtil; + +public class SharedConstants { + @Getter + private static final String modIdentifier = "@MOD_IDENTIFIER@"; + @Getter + private static final String modName = "@MOD_NAME@"; + @Getter + private static final String modVersion = "@MOD_VERSION@"; + @Getter + private static final String modVersionType = VersionUtil.getVersionType(SharedConstants.modVersion); + @Getter + private static final MagicConfigManager configManager = GlobalConfigManager + .getConfigManager(SharedConstants.getModIdentifier()); + @Getter + private static final MagicConfigHandler configHandler = new MagicConfigHandler(configManager, 1); + @Getter + private static final Logger logger = LogManager.getLogger(SharedConstants.modIdentifier); + + public static @NotNull String getTranslatedModVersionType() { + return VersionUtil.translateVersionType(SharedConstants.modVersion); + } +} diff --git a/src/main/java/com/plusls/MasaGadget/api/event/DisconnectListener.java b/src/main/java/com/plusls/MasaGadget/api/event/DisconnectListener.java new file mode 100644 index 00000000..95f98e14 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/api/event/DisconnectListener.java @@ -0,0 +1,7 @@ +package com.plusls.MasaGadget.api.event; + +import top.hendrixshen.magiclib.api.event.Listener; + +public interface DisconnectListener extends Listener { + void onDisconnect(); +} diff --git a/src/main/java/com/plusls/MasaGadget/api/gui/MasaGadgetDropdownList.java b/src/main/java/com/plusls/MasaGadget/api/gui/MasaGadgetDropdownList.java new file mode 100644 index 00000000..39822b52 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/api/gui/MasaGadgetDropdownList.java @@ -0,0 +1,19 @@ +package com.plusls.MasaGadget.api.gui; + +//#if MC > 11904 +import net.minecraft.client.gui.GuiGraphics; +//#elseif MC > 11502 +//$$ import com.mojang.blaze3d.vertex.PoseStack; +//#endif + +public interface MasaGadgetDropdownList { + void masa_gad_get$renderHovered( + //#if MC > 11904 + GuiGraphics poseStackOrGuiGraphics, + //#elseif MC > 11502 + //$$ PoseStack poseStackOrGuiGraphics, + //#endif + int mouseX, + int mouseY + ); +} diff --git a/src/main/java/com/plusls/MasaGadget/api/network/packet/PCAPacket.java b/src/main/java/com/plusls/MasaGadget/api/network/packet/PCAPacket.java new file mode 100644 index 00000000..394546b5 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/api/network/packet/PCAPacket.java @@ -0,0 +1,4 @@ +package com.plusls.MasaGadget.api.network.packet; + +public class PCAPacket { +} diff --git a/src/main/java/com/plusls/MasaGadget/compat/modmenu/ModMenuApiImpl.java b/src/main/java/com/plusls/MasaGadget/compat/modmenu/ModMenuApiImpl.java deleted file mode 100644 index 03675868..00000000 --- a/src/main/java/com/plusls/MasaGadget/compat/modmenu/ModMenuApiImpl.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.plusls.MasaGadget.compat.modmenu; - -import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.gui.GuiConfigs; -import top.hendrixshen.magiclib.compat.modmenu.ModMenuCompatApi; - -public class ModMenuApiImpl implements ModMenuCompatApi { - @Override - public ConfigScreenFactoryCompat getConfigScreenFactoryCompat() { - return (screen) -> { - GuiConfigs gui = GuiConfigs.getInstance(); - //#if MC > 11903 - gui.setParent(screen); - //#else - //$$ gui.setParentGui(screen); - //#endif - return gui; - }; - } - - @Override - public String getModIdCompat() { - return ModInfo.CURRENT_MOD_ID; - } -} diff --git a/src/main/java/com/plusls/MasaGadget/compat/modmenu/WrapperModMenuApiImpl.java b/src/main/java/com/plusls/MasaGadget/compat/modmenu/WrapperModMenuApiImpl.java deleted file mode 100644 index 6b8d564c..00000000 --- a/src/main/java/com/plusls/MasaGadget/compat/modmenu/WrapperModMenuApiImpl.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.plusls.MasaGadget.compat.modmenu; - -import com.plusls.MasaGadget.ModInfo; - -public class WrapperModMenuApiImpl extends ModMenuApiImpl { - @Override - public String getModIdCompat() { - return ModInfo.MOD_ID; - } -} diff --git a/src/main/java/com/plusls/MasaGadget/config/Configs.java b/src/main/java/com/plusls/MasaGadget/config/Configs.java deleted file mode 100644 index 630faf18..00000000 --- a/src/main/java/com/plusls/MasaGadget/config/Configs.java +++ /dev/null @@ -1,298 +0,0 @@ -package com.plusls.MasaGadget.config; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.gui.GuiConfigs; -import com.plusls.MasaGadget.mixin.accessor.AccessorGuiListBase; -import com.plusls.MasaGadget.util.PcaSyncProtocol; -import com.plusls.MasaGadget.util.SearchMobSpawnPointUtil; -import fi.dy.masa.malilib.config.options.ConfigHotkey; -import fi.dy.masa.malilib.gui.GuiConfigsBase; -import fi.dy.masa.malilib.gui.widgets.WidgetListConfigOptions; -import fi.dy.masa.malilib.util.Color4f; -import fi.dy.masa.malilib.util.JsonUtils; -import fi.dy.masa.malilib.util.StringUtils; -import net.minecraft.ChatFormatting; -import net.minecraft.client.Minecraft; -import net.minecraft.world.entity.Entity; -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.core.config.Configurator; -import org.jetbrains.annotations.NotNull; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; -import top.hendrixshen.magiclib.malilib.api.annotation.Config; -import top.hendrixshen.magiclib.malilib.api.annotation.Hotkey; -import top.hendrixshen.magiclib.malilib.api.annotation.Numeric; -import top.hendrixshen.magiclib.malilib.impl.ConfigHandler; -import top.hendrixshen.magiclib.malilib.impl.ConfigManager; -import top.hendrixshen.magiclib.malilib.impl.ConfigOption; -import top.hendrixshen.magiclib.util.FabricUtil; - -import java.util.*; - -public class Configs { - public static final HashMap> FAVORITES = new HashMap<>(); - public static boolean favoritesFilter = false; - - // GENERIC - @Config(category = ConfigCategory.GENERIC) - public static boolean autoSyncEntityData = true; - - @Hotkey - @Config(category = ConfigCategory.GENERIC) - public static boolean cacheContainerMenu = true; - - @Config(category = ConfigCategory.GENERIC) - public static boolean debug = false; - - @Hotkey(hotkey = "G,C") - @Config(category = ConfigCategory.GENERIC) - public static ConfigHotkey openConfigGui; - - @Hotkey - @Config(category = ConfigCategory.GENERIC) - public static boolean renderNextRestockTime = true; - - @Hotkey - @Config(category = ConfigCategory.GENERIC) - public static boolean renderTradeEnchantedBook = true; - - @Hotkey - @Config(category = ConfigCategory.GENERIC) - public static boolean renderVillageHomeTracer = false; - - @Config(category = ConfigCategory.GENERIC) - public static Color4f renderVillageHomeTracerColor = Color4f.fromColor(StringUtils.getColor("#500000FF", 0)); - - @Hotkey - @Config(category = ConfigCategory.GENERIC) - public static boolean renderVillageJobSiteTracer = false; - - @Config(category = ConfigCategory.GENERIC) - public static Color4f renderVillageJobSiteTracerColor = Color4f.fromColor(StringUtils.getColor("#50FF0000", 0)); - - @Hotkey - @Config(category = ConfigCategory.GENERIC) - public static boolean renderZombieVillagerConvertTime = true; - - @Hotkey - @Config(category = ConfigCategory.GENERIC, dependencies = @Dependencies(and = @Dependency(ModInfo.MINIHUD_MOD_ID))) - public static ConfigHotkey searchMobSpawnPoint; - - @Config(category = ConfigCategory.GENERIC, dependencies = @Dependencies(and = @Dependency(ModInfo.MINIHUD_MOD_ID))) - public static ArrayList searchMobSpawnPointBlackList = new ArrayList<>(); - - @Hotkey - @Config(category = ConfigCategory.GENERIC) - public static ConfigHotkey syncAllEntityData; - - // LITEMATICA - @Hotkey - @Config(category = ConfigCategory.LITEMATICA, dependencies = @Dependencies(and = @Dependency(ModInfo.LITEMATICA_MOD_ID))) - public static boolean betterEasyPlaceMode = false; - - @Hotkey - @Config(category = ConfigCategory.LITEMATICA, dependencies = @Dependencies(and = @Dependency(ModInfo.LITEMATICA_MOD_ID))) - public static boolean disableLitematicaEasyPlaceFailTip = false; - - @Hotkey - @Config(category = ConfigCategory.LITEMATICA, dependencies = @Dependencies(and = @Dependency(ModInfo.LITEMATICA_MOD_ID))) - public static boolean fixAccurateProtocol = false; - - @Config(category = ConfigCategory.LITEMATICA, dependencies = @Dependencies(and = { - @Dependency(ModInfo.LITEMATICA_MOD_ID), - @Dependency(ModInfo.TWEAKEROO_MOD_ID), - @Dependency(value = "minecraft", versionPredicate = "<=1.15.2")})) - public static boolean nudgeSelectionSupportFreeCamera = true; - - @Config(category = ConfigCategory.LITEMATICA, dependencies = @Dependencies(and = @Dependency(ModInfo.LITEMATICA_MOD_ID))) - public static boolean saveInventoryToSchematicInServer = false; - - @Config(category = ConfigCategory.LITEMATICA, dependencies = @Dependencies(and = @Dependency(ModInfo.LITEMATICA_MOD_ID))) - public static boolean useRelativePath = false; - // MALILIB - - @Config(category = ConfigCategory.MALILIB, dependencies = @Dependencies(and = @Dependency(value = "minecraft", versionPredicate = "<=1.17.1"))) - public static boolean backportI18nSupport = true; - - @Hotkey - @Config(category = ConfigCategory.MALILIB, dependencies = @Dependencies(and = @Dependency(ModInfo.MODMENU_MOD_ID))) - public static boolean fastSwitchMasaConfigGui = true; - - @Hotkey - @Config(category = ConfigCategory.MALILIB) - public static boolean favoritesSupport = false; - - @Config(category = ConfigCategory.MALILIB, dependencies = @Dependencies(and = @Dependency(value = "minecraft", versionPredicate = "<=1.17.1"))) - public static boolean fixConfigWidgetWidth = true; - - @Config(category = ConfigCategory.MALILIB, dependencies = @Dependencies(and = @Dependency(value = "minecraft", versionPredicate = "<=1.17.1"))) - public static boolean fixGetInventoryType = true; - - @Config(category = ConfigCategory.MALILIB) - public static boolean fixSearchbarHotkeyInput = true; - - @Config(category = ConfigCategory.MALILIB, dependencies = @Dependencies(and = @Dependency(value = "minecraft", versionPredicate = "<=1.17.1"))) - public static boolean optimizeConfigWidgetSearch = true; - - @Hotkey - @Config(category = ConfigCategory.MALILIB) - public static boolean showOriginalConfigName = false; - - @Numeric(maxValue = 2, minValue = 0) - @Config(category = ConfigCategory.MALILIB) - public static double showOriginalConfigNameScale = 0.65; - - // MINIHUD - @Hotkey - @Config(category = ConfigCategory.MINIHUD, dependencies = @Dependencies(and = @Dependency(ModInfo.MINIHUD_MOD_ID))) - public static boolean minihudI18n = true; - - @Config(category = ConfigCategory.MINIHUD, dependencies = @Dependencies(and = { - @Dependency(ModInfo.MINIHUD_MOD_ID), - @Dependency(ModInfo.TWEAKEROO_MOD_ID), - @Dependency(value = "minecraft", versionPredicate = ">1.14.4") - })) - public static boolean pcaSyncProtocolSyncBeehive = true; - - // TWEAKEROO - @Config(category = ConfigCategory.TWEAKEROO, dependencies = @Dependencies(and = @Dependency(ModInfo.TWEAKEROO_MOD_ID))) - public static boolean inventoryPreviewSupportComparator = true; - - @Config(category = ConfigCategory.TWEAKEROO, dependencies = @Dependencies(and = @Dependency(ModInfo.TWEAKEROO_MOD_ID))) - public static boolean inventoryPreviewSupportPlayer = true; - - @Hotkey - @Config(category = ConfigCategory.TWEAKEROO, dependencies = @Dependencies(and = @Dependency(ModInfo.TWEAKEROO_MOD_ID))) - public static boolean inventoryPreviewSupportSelect = true; - - @Config(category = ConfigCategory.TWEAKEROO, dependencies = @Dependencies(and = @Dependency(ModInfo.TWEAKEROO_MOD_ID))) - public static boolean inventoryPreviewSupportShulkerBoxItemEntity = true; - - @Config(category = ConfigCategory.TWEAKEROO, dependencies = @Dependencies(and = @Dependency(ModInfo.TWEAKEROO_MOD_ID))) - public static boolean inventoryPreviewSupportTradeOfferList = true; - - @Hotkey - @Config(category = ConfigCategory.TWEAKEROO, dependencies = @Dependencies(and = @Dependency(ModInfo.TWEAKEROO_MOD_ID))) - public static boolean inventoryPreviewSyncData = true; - - @Hotkey - @Config(category = ConfigCategory.TWEAKEROO, dependencies = @Dependencies(and = @Dependency(ModInfo.TWEAKEROO_MOD_ID))) - public static boolean inventoryPreviewSyncDataClientOnly = false; - - @Config(category = ConfigCategory.TWEAKEROO, dependencies = @Dependencies(and = @Dependency(ModInfo.TWEAKEROO_MOD_ID))) - public static boolean inventoryPreviewUseCache = true; - - @Hotkey - @Config(category = ConfigCategory.TWEAKEROO, dependencies = @Dependencies(and = {@Dependency(ModInfo.TWEAKEROO_MOD_ID), @Dependency(ModInfo.ITEMSCROLLER_MOD_ID)})) - public static boolean restockWithCrafting = true; - - @Config(category = ConfigCategory.TWEAKEROO, dependencies = @Dependencies(and = {@Dependency(ModInfo.TWEAKEROO_MOD_ID), @Dependency(ModInfo.ITEMSCROLLER_MOD_ID)})) - public static ArrayList restockWithCraftingRecipes = new ArrayList<>(); - - public static void preDeserialize(@NotNull ConfigHandler configHandler) { - JsonObject obj = Objects.requireNonNull(JsonUtils.getNestedObject(configHandler.jsonObject, - ConfigCategory.MALILIB, true)); - JsonObject favoriteObj = Objects.requireNonNull(JsonUtils.getNestedObject(obj, "favorites", true)); - for (Map.Entry favoriteEntry : favoriteObj.entrySet()) { - HashSet modFavorites = new HashSet<>(); - favoriteEntry.getValue().getAsJsonArray().forEach(jsonElement -> modFavorites.add(jsonElement.getAsString())); - FAVORITES.put(favoriteEntry.getKey(), modFavorites); - } - favoritesFilter = JsonUtils.getBooleanOrDefault(obj, "favoritesFilter", false); - } - - public static void postSerialize(@NotNull ConfigHandler configHandler) { - JsonObject obj = Objects.requireNonNull(JsonUtils.getNestedObject(configHandler.jsonObject, - ConfigCategory.MALILIB, true)); - JsonObject favoriteObj = new JsonObject(); - for (Map.Entry> favoriteEntry : FAVORITES.entrySet()) { - JsonArray modFavoriteObj = new JsonArray(); - if (!favoriteEntry.getValue().isEmpty()) { - for (String modFavoriteConfigName : favoriteEntry.getValue()) { - modFavoriteObj.add(modFavoriteConfigName); - } - favoriteObj.add(favoriteEntry.getKey(), modFavoriteObj); - } - } - obj.add("favorites", favoriteObj); - obj.add("favoritesFilter", new JsonPrimitive(favoritesFilter)); - } - - public static void init(ConfigManager cm) { - // GENERIC - cm.setValueChangeCallback("debug", option -> { - if (debug) { - Configurator.setLevel(ModInfo.MOD_ID, Level.toLevel("DEBUG")); - } else { - Configurator.setLevel(ModInfo.MOD_ID, Level.toLevel("INFO")); - } - GuiConfigs.getInstance().reDraw(); - }); - - if (debug) { - Configurator.setLevel(ModInfo.MOD_ID, Level.toLevel("DEBUG")); - } - - openConfigGui.getKeybind().setCallback((keyAction, iKeybind) -> { - GuiConfigs screen = GuiConfigs.getInstance(); - //#if MC > 11903 - screen.setParent(Minecraft.getInstance().screen); - //#else - //$$ screen.setParentGui(Minecraft.getInstance().screen); - //#endif - Minecraft.getInstance().setScreen(screen); - return true; - }); - - searchMobSpawnPoint.getKeybind().setCallback((keyAction, iKeybind) -> { - if (FabricUtil.isModLoaded(ModInfo.MINIHUD_MOD_ID)) { - SearchMobSpawnPointUtil.search(); - } - return true; - }); - - // LITEMATICA - syncAllEntityData.getKeybind().setCallback((keyAction, iKeybind) -> { - if (!PcaSyncProtocol.enable) { - return true; - } - Minecraft mc = Minecraft.getInstance(); - for (Entity entity : Objects.requireNonNull(mc.level).entitiesForRendering()) { - PcaSyncProtocol.syncEntity(entity.getId()); - } - Objects.requireNonNull(mc.player).displayClientMessage( - ModInfo.translatable("message.syncAllEntityDataSuccess") - .withStyle(ChatFormatting.GREEN), false); - return true; - }); - - // MALILIB - cm.setValueChangeCallback("favoritesSupport", Configs::refreshOptions); - cm.setValueChangeCallback("showOriginalConfigName", Configs::refreshOptions); - cm.setValueChangeCallback("showOriginalConfigNameScale", Configs::refreshOptions); - } - - private static void refreshOptions(ConfigOption option) { - if (Minecraft.getInstance().screen instanceof GuiConfigsBase) { - GuiConfigsBase guiConfigsBase = (GuiConfigsBase) Minecraft.getInstance().screen; - WidgetListConfigOptions widgetListConfigOptions = - (WidgetListConfigOptions) ((AccessorGuiListBase) guiConfigsBase).invokeGetListWidget(); - if (widgetListConfigOptions != null) { - widgetListConfigOptions.getScrollbar().setValue(0); - widgetListConfigOptions.refreshEntries(); - } - } - } - - public static class ConfigCategory { - public static final String GENERIC = "generic"; - public static final String LITEMATICA = "litematica"; - public static final String MALILIB = "malilib"; - public static final String MINIHUD = "minihud"; - public static final String TWEAKEROO = "tweakeroo"; - } -} \ No newline at end of file diff --git a/src/main/java/com/plusls/MasaGadget/event/DisconnectEvent.java b/src/main/java/com/plusls/MasaGadget/event/DisconnectEvent.java deleted file mode 100644 index 00cca93e..00000000 --- a/src/main/java/com/plusls/MasaGadget/event/DisconnectEvent.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.plusls.MasaGadget.event; - -import java.util.ArrayList; -import java.util.List; - -public class DisconnectEvent { - private static final List funList = new ArrayList<>(); - - public static void register(Disconnect fun) { - funList.add(fun); - } - - public static void onDisconnect() { - for (Disconnect fun : funList) { - fun.onPlayDisconnect(); - } - } - - @FunctionalInterface - public interface Disconnect { - void onPlayDisconnect(); - } -} diff --git a/src/main/java/com/plusls/MasaGadget/game/ConfigGui.java b/src/main/java/com/plusls/MasaGadget/game/ConfigGui.java new file mode 100644 index 00000000..228f689a --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/game/ConfigGui.java @@ -0,0 +1,52 @@ +package com.plusls.MasaGadget.game; + +import com.plusls.MasaGadget.SharedConstants; +import fi.dy.masa.malilib.gui.GuiBase; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import top.hendrixshen.magiclib.api.i18n.I18n; +import top.hendrixshen.magiclib.impl.malilib.config.gui.MagicConfigGui; +import top.hendrixshen.magiclib.util.collect.ValueContainer; + +public class ConfigGui extends MagicConfigGui { + @Nullable + private static ConfigGui currentInstance = null; + + public ConfigGui() { + super( + SharedConstants.getModIdentifier(), + SharedConstants.getConfigManager(), + I18n.tr("masa_gadget_mod.gui.title.configs", SharedConstants.getModVersion()) + ); + } + + @Override + public void init() { + super.init(); + ConfigGui.currentInstance = this; + } + + @Override + public void removed() { + super.removed(); + ConfigGui.currentInstance = null; + } + + @Override + public boolean isDebug() { + return Configs.debug.getBooleanValue(); + } + + public static void openGui() { + GuiBase.openGui(new ConfigGui()); + } + + @Override + public boolean hideUnAvailableConfigs() { + return top.hendrixshen.magiclib.game.malilib.Configs.hideUnavailableConfigs.getBooleanValue(); + } + + public static @NotNull ValueContainer getCurrentInstance() { + return ValueContainer.ofNullable(ConfigGui.currentInstance); + } +} diff --git a/src/main/java/com/plusls/MasaGadget/game/Configs.java b/src/main/java/com/plusls/MasaGadget/game/Configs.java new file mode 100644 index 00000000..ce934337 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/game/Configs.java @@ -0,0 +1,243 @@ +package com.plusls.MasaGadget.game; + +import com.google.common.collect.ImmutableList; +import com.plusls.MasaGadget.ModInfo; +import com.plusls.MasaGadget.SharedConstants; +import com.plusls.MasaGadget.util.PcaSyncProtocol; +import com.plusls.MasaGadget.util.SearchMobSpawnPointUtil; +import net.minecraft.ChatFormatting; +import net.minecraft.client.Minecraft; +import net.minecraft.world.entity.Entity; +import top.hendrixshen.magiclib.MagicLib; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; +import top.hendrixshen.magiclib.api.malilib.annotation.Config; +import top.hendrixshen.magiclib.api.malilib.config.MagicConfigManager; +import top.hendrixshen.magiclib.impl.malilib.config.MagicConfigFactory; +import top.hendrixshen.magiclib.impl.malilib.config.option.*; +import top.hendrixshen.magiclib.util.minecraft.ComponentUtil; +import top.hendrixshen.magiclib.util.minecraft.InfoUtil; + +import java.util.*; + +public class Configs { + private static final MagicConfigManager cm = SharedConstants.getConfigManager(); + private static final MagicConfigFactory cf = Configs.cm.getConfigFactory(); + + // GENERIC + @Config(category = ConfigCategory.GENERIC) + public static MagicConfigBoolean autoSyncEntityData = Configs.cf.newConfigBoolean("autoSyncEntityData", false); + + @Config(category = ConfigCategory.GENERIC) + public static MagicConfigBoolean cacheContainerMenu = Configs.cf.newConfigBoolean("cacheContainerMenu", true); + + @Config(category = ConfigCategory.GENERIC) + public static MagicConfigBoolean debug = Configs.cf.newConfigBoolean("debug", false); + + @Config(category = ConfigCategory.GENERIC) + public static MagicConfigHotkey openConfigGui = Configs.cf.newConfigHotkey("openConfigGui", "G,C"); + + @Config(category = ConfigCategory.GENERIC) + public static MagicConfigBooleanHotkeyed renderNextRestockTime = Configs.cf.newConfigBooleanHotkeyed("renderNextRestockTime", false); + + @Config(category = ConfigCategory.GENERIC) + public static MagicConfigBooleanHotkeyed renderTradeEnchantedBook = Configs.cf.newConfigBooleanHotkeyed("renderTradeEnchantedBook", false); + + @Config(category = ConfigCategory.GENERIC) + public static MagicConfigBooleanHotkeyed renderVillageHomeTracer = Configs.cf.newConfigBooleanHotkeyed("renderVillageHomeTracer", false); + + @Config(category = ConfigCategory.GENERIC) + public static MagicConfigColor renderVillageHomeTracerColor = Configs.cf.newConfigColor("renderVillageHomeTracerColor", "#500000FF"); + + @Config(category = ConfigCategory.GENERIC) + public static MagicConfigBooleanHotkeyed renderVillageJobSiteTracer = Configs.cf.newConfigBooleanHotkeyed("renderVillageJobSiteTracer", false); + + @Config(category = ConfigCategory.GENERIC) + public static MagicConfigColor renderVillageJobSiteTracerColor = Configs.cf.newConfigColor("renderVillageJobSiteTracerColor", "#5000FF00"); + + @Config(category = ConfigCategory.GENERIC) + public static MagicConfigBooleanHotkeyed renderZombieVillagerConvertTime = Configs.cf.newConfigBooleanHotkeyed("renderZombieVillagerConvertTime", false); + + @Dependencies(require = @Dependency(ModInfo.MINIHUD_MOD_ID)) + @Config(category = ConfigCategory.GENERIC) + public static MagicConfigHotkey searchMobSpawnPoint = Configs.cf.newConfigHotkey("searchMobSpawnPoint"); + + @Dependencies(require = @Dependency(ModInfo.MINIHUD_MOD_ID)) + @Config(category = ConfigCategory.GENERIC) + public static MagicConfigStringList searchMobSpawnPointBlackList = Configs.cf.newConfigStringList("searchMobSpawnPointBlackList", ImmutableList.of()); + + @Config(category = ConfigCategory.GENERIC) + public static MagicConfigHotkey syncAllEntityData = Configs.cf.newConfigHotkey("syncAllEntityData"); + + // Litematica + @Dependencies(require = @Dependency(ModInfo.LITEMATICA_MOD_ID)) + @Config(category = ConfigCategory.LITEMATICA) + public static boolean betterEasyPlaceMode = false; + + @Dependencies(require = @Dependency(ModInfo.LITEMATICA_MOD_ID)) + @Config(category = ConfigCategory.LITEMATICA) + public static MagicConfigBooleanHotkeyed disableLitematicaEasyPlaceFailTip = Configs.cf.newConfigBooleanHotkeyed("disableLitematicaEasyPlaceFailTip", false); + + @Dependencies(require = @Dependency(ModInfo.LITEMATICA_MOD_ID)) + @Config(category = ConfigCategory.LITEMATICA) + public static MagicConfigBooleanHotkeyed fixAccurateProtocol = Configs.cf.newConfigBooleanHotkeyed("fixAccurateProtocol", false); + + @Dependencies(require = { + @Dependency(ModInfo.LITEMATICA_MOD_ID), + @Dependency(ModInfo.TWEAKEROO_MOD_ID), + @Dependency(value = "minecraft", versionPredicates = "<=1.15.2") + }) + @Config(category = ConfigCategory.LITEMATICA) + public static MagicConfigBoolean nudgeSelectionSupportFreeCamera = Configs.cf.newConfigBoolean("nudgeSelectionSupportFreeCamera", false); + + @Dependencies(require = @Dependency(ModInfo.LITEMATICA_MOD_ID)) + @Config(category = ConfigCategory.LITEMATICA) + public static MagicConfigBoolean saveInventoryToSchematicInServer = Configs.cf.newConfigBoolean("saveInventoryToSchematicInServer", false); + + @Dependencies(require = @Dependency(ModInfo.LITEMATICA_MOD_ID)) + @Config(category = ConfigCategory.LITEMATICA) + public static MagicConfigBoolean useRelativePath = Configs.cf.newConfigBoolean("useRelativePath", false); + + // MALILIB + @Dependencies(require = @Dependency(value = "minecraft", versionPredicates = "<=1.17.1")) + @Config(category = ConfigCategory.MALILIB) + public static MagicConfigBoolean backportI18nSupport = Configs.cf.newConfigBoolean("backportI18nSupport", false); + + @Dependencies(require = @Dependency(ModInfo.MODMENU_MOD_ID)) + @Config(category = ConfigCategory.MALILIB) + public static MagicConfigBoolean fastSwitchMasaConfigGui = Configs.cf.newConfigBoolean("fastSwitchMasaConfigGui", false); + + @Config(category = ConfigCategory.MALILIB) + public static MagicConfigBooleanHotkeyed favoritesSupport = Configs.cf.newConfigBooleanHotkeyed("favoritesSupport", false); + + @Dependencies(require = @Dependency(value = "minecraft", versionPredicates = "<=1.17.1")) + @Config(category = ConfigCategory.MALILIB) + public static MagicConfigBoolean fixConfigWidgetWidth = Configs.cf.newConfigBoolean("fixConfigWidgetWidth", false); + + @Dependencies(require = @Dependency(value = "minecraft", versionPredicates = "<=1.17.1")) + @Config(category = ConfigCategory.MALILIB) + public static MagicConfigBoolean fixGetInventoryType = Configs.cf.newConfigBoolean("fixGetInventoryType", false); + + @Dependencies(require = @Dependency(value = "minecraft", versionPredicates = "<=1.17.1")) + @Config(category = ConfigCategory.MALILIB) + public static MagicConfigBoolean fixSearchbarHotkeyInput = Configs.cf.newConfigBoolean("fixSearchbarHotkeyInput", false); + + @Dependencies(require = @Dependency(value = "minecraft", versionPredicates = "<=1.17.1")) + @Config(category = ConfigCategory.MALILIB) + public static MagicConfigBoolean optimizeConfigWidgetSearch = Configs.cf.newConfigBoolean("optimizeConfigWidgetSearch", false); + + @Config(category = ConfigCategory.MALILIB) + public static MagicConfigBoolean showOriginalConfigName = Configs.cf.newConfigBoolean("showOriginalConfigName", false); + + @Config(category = ConfigCategory.MALILIB) + public static MagicConfigDouble showOriginalConfigNameScale = Configs.cf.newConfigDouble("showOriginalConfigNameScale", 0.65, 0, 2); + + // MiniHUD + @Dependencies(require = @Dependency(ModInfo.MINIHUD_MOD_ID)) + @Config(category = ConfigCategory.MINIHUD) + public static MagicConfigBoolean minihudI18n = Configs.cf.newConfigBoolean("minihudI18n", false); + + @Dependencies(require = { + @Dependency(ModInfo.MINIHUD_MOD_ID), + @Dependency(ModInfo.TWEAKEROO_MOD_ID), + @Dependency(value = "minecraft", versionPredicates = ">1.14.4") + }) + @Config(category = ConfigCategory.MINIHUD) + public static MagicConfigBoolean pcaSyncProtocolSyncBeehive = Configs.cf.newConfigBoolean("pcaSyncProtocolSyncBeehive", false); + + // Tweakeroo + @Dependencies(require = @Dependency(ModInfo.TWEAKEROO_MOD_ID)) + @Config(category = ConfigCategory.TWEAKEROO) + public static MagicConfigBoolean inventoryPreviewSupportComparator = Configs.cf.newConfigBoolean("inventoryPreviewSupportComparator", false); + + @Dependencies(require = @Dependency(ModInfo.TWEAKEROO_MOD_ID)) + @Config(category = ConfigCategory.TWEAKEROO) + public static MagicConfigBoolean inventoryPreviewSupportPlayer = Configs.cf.newConfigBoolean("inventoryPreviewSupportPlayer", false); + + @Dependencies(require = @Dependency(ModInfo.TWEAKEROO_MOD_ID)) + @Config(category = ConfigCategory.TWEAKEROO) + public static MagicConfigBoolean inventoryPreviewSupportSelect = Configs.cf.newConfigBoolean("inventoryPreviewSupportSelect", false); + + @Dependencies(require = @Dependency(ModInfo.TWEAKEROO_MOD_ID)) + @Config(category = ConfigCategory.TWEAKEROO) + public static MagicConfigBoolean inventoryPreviewSupportShulkerBoxItemEntity = Configs.cf.newConfigBoolean("inventoryPreviewSupportShulkerBoxItemEntity", false); + + @Dependencies(require = @Dependency(ModInfo.TWEAKEROO_MOD_ID)) + @Config(category = ConfigCategory.TWEAKEROO) + public static MagicConfigBoolean inventoryPreviewSupportTradeOfferList = Configs.cf.newConfigBoolean("inventoryPreviewSupportTradeOfferList", false); + + @Dependencies(require = @Dependency(ModInfo.TWEAKEROO_MOD_ID)) + @Config(category = ConfigCategory.TWEAKEROO) + public static MagicConfigBoolean inventoryPreviewSyncData = Configs.cf.newConfigBoolean("inventoryPreviewSyncData", false); + + @Dependencies(require = @Dependency(ModInfo.TWEAKEROO_MOD_ID)) + @Config(category = ConfigCategory.TWEAKEROO) + public static MagicConfigBoolean inventoryPreviewSyncDataClientOnly = Configs.cf.newConfigBoolean("inventoryPreviewSyncDataClientOnly", false); + + @Dependencies(require = @Dependency(ModInfo.TWEAKEROO_MOD_ID)) + @Config(category = ConfigCategory.TWEAKEROO) + public static MagicConfigBoolean inventoryPreviewUseCache = Configs.cf.newConfigBoolean("inventoryPreviewUseCache", false); + + @Dependencies(require = { + @Dependency(ModInfo.TWEAKEROO_MOD_ID), + @Dependency(ModInfo.ITEMSCROLLER_MOD_ID) + }) + @Config(category = ConfigCategory.TWEAKEROO) + public static MagicConfigBoolean restockWithCrafting = Configs.cf.newConfigBoolean("restockWithCrafting", false); + + @Dependencies(require = { + @Dependency(ModInfo.TWEAKEROO_MOD_ID), + @Dependency(ModInfo.ITEMSCROLLER_MOD_ID) + }) + @Config(category = ConfigCategory.TWEAKEROO) + public static MagicConfigStringList restockWithCraftingRecipes = Configs.cf.newConfigStringList("restockWithCraftingRecipes", ImmutableList.of()); + + public static void init() { + Configs.cm.parseConfigClass(Configs.class); + + // Generic + MagicConfigManager.setHotkeyCallback(openConfigGui, ConfigGui::openGui, true); + + Configs.searchMobSpawnPoint.getKeybind().setCallback((keyAction, iKeybind) -> { + if (MagicLib.getInstance().getCurrentPlatform().isModLoaded(ModInfo.MINIHUD_MOD_ID)) { + SearchMobSpawnPointUtil.search(); + } + + return true; + }); + + // Litematica + Configs.syncAllEntityData.getKeybind().setCallback((keyAction, iKeybind) -> { + if (!PcaSyncProtocol.enable) { + return true; + } + + Minecraft mc = Minecraft.getInstance(); + + for (Entity entity : Objects.requireNonNull(mc.level).entitiesForRendering()) { + PcaSyncProtocol.syncEntity(entity.getId()); + } + + InfoUtil.displayChatMessage(ComponentUtil.tr("masa_gadget_mod.message.syncAllEntityDataSuccess") + .withStyle(ChatFormatting.GREEN).get()); + return true; + }); + + // Malilib + Configs.favoritesSupport.setValueChangeCallback(Configs::redrawConfigGui); + Configs.showOriginalConfigName.setValueChangeCallback(Configs::redrawConfigGui); + Configs.showOriginalConfigNameScale.setValueChangeCallback(Configs::redrawConfigGui); + } + + private static void redrawConfigGui(Object object) { + ConfigGui.getCurrentInstance().ifPresent(ConfigGui::reDraw); + } + + public static class ConfigCategory { + public static final String GENERIC = "generic"; + public static final String LITEMATICA = "litematica"; + public static final String MALILIB = "malilib"; + public static final String MINIHUD = "minihud"; + public static final String TWEAKEROO = "tweakeroo"; + } +} diff --git a/src/main/java/com/plusls/MasaGadget/generic/entityInfo/EntityInfoRenderer.java b/src/main/java/com/plusls/MasaGadget/generic/entityInfo/EntityInfoRenderer.java deleted file mode 100644 index c3c9b0f5..00000000 --- a/src/main/java/com/plusls/MasaGadget/generic/entityInfo/EntityInfoRenderer.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.plusls.MasaGadget.generic.entityInfo; - -import com.google.common.collect.Lists; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.util.MiscUtil; -import com.plusls.MasaGadget.util.SyncUtil; -import net.minecraft.client.Minecraft; -import net.minecraft.core.Position; -import net.minecraft.util.Mth; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.monster.ZombieVillager; -import net.minecraft.world.entity.npc.Villager; -import net.minecraft.world.level.Level; -import org.jetbrains.annotations.NotNull; -import top.hendrixshen.magiclib.event.render.impl.RenderContext; -import top.hendrixshen.magiclib.event.render.impl.RenderEventHandler; -import top.hendrixshen.magiclib.render.impl.TextRenderer; - -import java.util.List; - -public class EntityInfoRenderer { - private static final List list = Lists.newArrayList(); - - public static void init() { - // TODO: Temp impl - RenderEventHandler.registerPostRenderEntityEvent(EntityInfoRenderer::collect); - RenderEventHandler.registerPostRenderLevelEvent(EntityInfoRenderer::render); - } - - private static void collect(Entity entity, RenderContext context, float tickDelta) { - if ((entity instanceof Villager && (Configs.renderNextRestockTime || Configs.renderTradeEnchantedBook)) || - (entity instanceof ZombieVillager && (Configs.renderZombieVillagerConvertTime))) { - EntityInfoRenderer.list.add(entity); - } - } - - public static void render(Level level, RenderContext context, float tickDelta) { - for (Entity entity : EntityInfoRenderer.list) { - if (entity instanceof Villager) { - Villager villager = MiscUtil.cast(SyncUtil.syncEntityDataFromIntegratedServer(entity)); - TextRenderer renderer = TextRenderer.create(); - - if (Configs.renderNextRestockTime) { - renderer.addLine(VillagerNextRestockTimeInfo.getInfo(villager)); - } - - if (Configs.renderTradeEnchantedBook) { - VillageTradeEnchantedBookInfo.getInfo(villager).forEach(renderer::addLine); - } - - if (villager.isSleeping()) { - Position position = entity.getEyePosition(tickDelta); - renderer.pos(position.x(), position.y() + 0.4F, position.z()); - } else { - EntityInfoRenderer.rotationAround(renderer, entity.getEyePosition(tickDelta), 0.6); - } - - renderer.bgColor((int) (Minecraft.getInstance().options.getBackgroundOpacity(0.25F) * 255.0F) << 24) - .fontScale(0.015F) - .render(context); - } else if (entity instanceof ZombieVillager) { - ZombieVillager zombieVillager = MiscUtil.cast(SyncUtil.syncEntityDataFromIntegratedServer(entity)); - EntityInfoRenderer.rotationAround(TextRenderer.create(), entity.getEyePosition(tickDelta), 0.6) - .text(ZombieVillagerConvertTimeInfo.getInfo(zombieVillager)) - .bgColor((int) (Minecraft.getInstance().options.getBackgroundOpacity(0.25F) * 255.0F) << 24) - .fontScale(0.015F) - .render(context); - } - } - - EntityInfoRenderer.list.clear(); - } - - private static TextRenderer rotationAround(@NotNull TextRenderer renderer, @NotNull Position centerPos, double range) { - Position camPos = Minecraft.getInstance().gameRenderer.getMainCamera().getPosition(); - float xAngle = (float) Mth.atan2(camPos.z() - centerPos.z(), camPos.x() - centerPos.x()); - float yAngle = (float) Mth.atan2(camPos.x() - centerPos.x(), camPos.z() - centerPos.z()); - return renderer.pos(range * Mth.cos(xAngle) + centerPos.x(), centerPos.y(), range * Mth.cos(yAngle) + centerPos.z()); - } -} diff --git a/src/main/java/com/plusls/MasaGadget/generic/entityInfo/VillageTradeEnchantedBookInfo.java b/src/main/java/com/plusls/MasaGadget/generic/entityInfo/VillageTradeEnchantedBookInfo.java deleted file mode 100644 index cd32956a..00000000 --- a/src/main/java/com/plusls/MasaGadget/generic/entityInfo/VillageTradeEnchantedBookInfo.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.plusls.MasaGadget.generic.entityInfo; - -import com.google.common.collect.Lists; -import net.minecraft.ChatFormatting; -import net.minecraft.network.chat.*; -import net.minecraft.world.entity.npc.Villager; -import net.minecraft.world.entity.npc.VillagerProfession; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; -import net.minecraft.world.item.enchantment.Enchantment; -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.item.trading.MerchantOffer; -import org.jetbrains.annotations.NotNull; -import top.hendrixshen.magiclib.compat.minecraft.api.network.chat.ComponentCompatApi; - -import java.util.List; -import java.util.Map; - -public class VillageTradeEnchantedBookInfo { - public static @NotNull List getInfo(@NotNull Villager villager) { - List ret = Lists.newArrayList(); - - if (villager.getVillagerData().getProfession() != VillagerProfession.LIBRARIAN) { - return ret; - } - - for (MerchantOffer tradeOffer : villager.getOffers()) { - ItemStack sellItem = tradeOffer.getResult(); - - if (sellItem.is(Items.ENCHANTED_BOOK)) { - Map enchantmentData = EnchantmentHelper.getEnchantments(sellItem); - - for (Map.Entry entry : enchantmentData.entrySet()) { - int level = entry.getValue(); - int cost = tradeOffer.getBaseCostA().getCount(); - int minCost = 2 + 3 * level; - int maxCost = minCost + 4 + level * 10; - - if (entry.getKey().isTreasureOnly()) { - minCost *= 2; - maxCost *= 2; - } - - ChatFormatting color; - - if (cost <= (maxCost - minCost) / 3 + minCost) { - color = ChatFormatting.GREEN; - } else if (cost <= (maxCost - minCost) / 3 * 2 + minCost) { - color = ChatFormatting.WHITE; - } else { - color = ChatFormatting.RED; - } - - if (level == entry.getKey().getMaxLevel()) { - //#if MC > 11502 - ret.add(((MutableComponent) entry.getKey().getFullname(entry.getValue())).withStyle(ChatFormatting.GOLD)); - //#else - //$$ ret.add(((BaseComponent) entry.getKey().getFullname(entry.getValue())).withStyle(ChatFormatting.GOLD)); - //#endif - } else { - //#if MC > 11502 - ret.add(((MutableComponent) entry.getKey().getFullname(entry.getValue())).withStyle(ChatFormatting.WHITE)); - //#else - //$$ ret.add(((BaseComponent) entry.getKey().getFullname(entry.getValue())).withStyle(ChatFormatting.GOLD)); - //#endif - } - - ret.add(ComponentCompatApi.literal(String.format("%d(%d-%d)", cost, minCost, maxCost)).withStyle(color)); - } - - break; - } - } - - return ret; - } -} diff --git a/src/main/java/com/plusls/MasaGadget/generic/entityTrace/EntityTraceRenderer.java b/src/main/java/com/plusls/MasaGadget/generic/entityTrace/EntityTraceRenderer.java deleted file mode 100644 index f5a61689..00000000 --- a/src/main/java/com/plusls/MasaGadget/generic/entityTrace/EntityTraceRenderer.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.plusls.MasaGadget.generic.entityTrace; - -import com.google.common.collect.Lists; -import com.mojang.blaze3d.systems.RenderSystem; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.util.MiscUtil; -import com.plusls.MasaGadget.util.RenderUtil; -import com.plusls.MasaGadget.util.SyncUtil; -import fi.dy.masa.malilib.util.Color4f; -import fi.dy.masa.malilib.util.StringUtils; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.ai.memory.MemoryModuleType; -import net.minecraft.world.entity.npc.Villager; -import net.minecraft.world.level.Level; -import net.minecraft.world.phys.Vec3; -import org.spongepowered.asm.mixin.transformer.Config; -import top.hendrixshen.magiclib.event.render.impl.RenderContext; -import top.hendrixshen.magiclib.event.render.impl.RenderEventHandler; - -import java.util.List; - -public class EntityTraceRenderer { - private static final List list = Lists.newArrayList(); - - public static void init() { - RenderEventHandler.registerPostRenderEntityEvent(EntityTraceRenderer::collect); - RenderEventHandler.registerPostRenderLevelEvent(EntityTraceRenderer::render); - } - - private static void collect(Entity entity, RenderContext context, float tickDelta) { - if (entity instanceof Villager && Configs.renderVillageHomeTracer || Configs.renderVillageJobSiteTracer) { - EntityTraceRenderer.list.add(entity); - } - } - - private static void render(Level level, RenderContext context, float tickDelta) { - for (Entity entity : EntityTraceRenderer.list) { - if (entity instanceof Villager) { - Villager villager = MiscUtil.cast(SyncUtil.syncEntityDataFromIntegratedServer(entity)); - - if (Configs.renderVillageHomeTracer) { - villager.getBrain().getMemory(MemoryModuleType.HOME).ifPresent(globalPos -> { - Vec3 eyeVec3 = entity.getEyePosition(tickDelta); - Vec3 bedVec3 = new Vec3(globalPos.pos().getX() + 0.5, globalPos.pos().getY() + 0.5, globalPos.pos().getZ() + 0.5); - RenderSystem.disableDepthTest(); - RenderUtil.drawConnectLine(eyeVec3, bedVec3, 0.05, - new Color4f(1, 1, 1), - Color4f.fromColor(Configs.renderVillageHomeTracerColor, 1.0F), - Configs.renderVillageHomeTracerColor); - RenderSystem.enableDepthTest(); - }); - } - - if (Configs.renderVillageJobSiteTracer) { - villager.getBrain().getMemory(MemoryModuleType.JOB_SITE).ifPresent(globalPos -> { - Vec3 eyeVec3 = entity.getEyePosition(tickDelta); - Vec3 jobVev3 = new Vec3(globalPos.pos().getX() + 0.5, globalPos.pos().getY() + 0.5, globalPos.pos().getZ() + 0.5); - RenderSystem.disableDepthTest(); - RenderUtil.drawConnectLine(eyeVec3, jobVev3, 0.05, - new Color4f(1, 1, 1), - Color4f.fromColor(Configs.renderVillageJobSiteTracerColor, 1.0F), - Configs.renderVillageJobSiteTracerColor); - RenderSystem.enableDepthTest(); - }); - } - } - } - - EntityTraceRenderer.list.clear(); - } -} diff --git a/src/main/java/com/plusls/MasaGadget/gui/GuiConfigs.java b/src/main/java/com/plusls/MasaGadget/gui/GuiConfigs.java deleted file mode 100644 index cf760cb3..00000000 --- a/src/main/java/com/plusls/MasaGadget/gui/GuiConfigs.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.plusls.MasaGadget.gui; - -import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; -import lombok.Getter; -import top.hendrixshen.magiclib.malilib.impl.ConfigManager; -import top.hendrixshen.magiclib.malilib.impl.gui.ConfigGui; - -public class GuiConfigs extends ConfigGui { - @Getter(lazy = true) - private static final GuiConfigs instance = new GuiConfigs(ModInfo.MOD_ID, Configs.ConfigCategory.GENERIC, ConfigManager.get(ModInfo.MOD_ID)); - - private GuiConfigs(String identifier, String defaultTab, ConfigManager configManager) { - super(identifier, defaultTab, configManager, () -> ModInfo.translate("gui.title.configs", ModInfo.MOD_VERSION)); - } -} \ No newline at end of file diff --git a/src/main/java/com/plusls/MasaGadget/gui/IDropdownRenderer.java b/src/main/java/com/plusls/MasaGadget/gui/IDropdownRenderer.java deleted file mode 100644 index 06b0bce8..00000000 --- a/src/main/java/com/plusls/MasaGadget/gui/IDropdownRenderer.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.plusls.MasaGadget.gui; - -//#if MC > 11904 -import net.minecraft.client.gui.GuiGraphics; -//#elseif MC > 11502 -//$$ import com.mojang.blaze3d.vertex.PoseStack; -//#endif - -public interface IDropdownRenderer { - //#if MC > 11904 - void masa_gad_get$renderHovered(GuiGraphics gui, int mouseX, int mouseY); - //#elseif MC > 11502 - //$$ void masa_gad_get$renderHovered(PoseStack poseStack, int mouseX, int mouseY); - //#else - //$$ void masa_gad_get$renderHovered(int mouseX, int mouseY); - //#endif -} diff --git a/src/main/java/com/plusls/MasaGadget/gui/MyWidgetDropDownList.java b/src/main/java/com/plusls/MasaGadget/gui/MyWidgetDropDownList.java deleted file mode 100644 index c11a1d29..00000000 --- a/src/main/java/com/plusls/MasaGadget/gui/MyWidgetDropDownList.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.plusls.MasaGadget.gui; - -import fi.dy.masa.malilib.gui.widgets.WidgetDropDownList; -import fi.dy.masa.malilib.interfaces.IStringRetriever; -import org.jetbrains.annotations.Nullable; - -import java.util.List; -import java.util.function.Consumer; -import java.util.function.Predicate; - -//#if MC > 11904 -import net.minecraft.client.gui.GuiGraphics; -//#else -//$$ import com.mojang.blaze3d.vertex.PoseStack; -//#endif - -public class MyWidgetDropDownList extends WidgetDropDownList { - private final Consumer selectedCallback; - private final Predicate shouldEnable; - - public MyWidgetDropDownList(int x, int y, int width, int height, int maxHeight, int maxVisibleEntries, - List entries, @Nullable IStringRetriever stringRetriever, - Consumer selectedCallback, Predicate shouldEnable) { - super(x, y, width, height, maxHeight, maxVisibleEntries, entries, stringRetriever); - this.selectedCallback = selectedCallback; - this.shouldEnable = shouldEnable; - } - - @Override - protected void setSelectedEntry(int index) { - if (shouldEnable.test(this.getSelectedEntry())) { - super.setSelectedEntry(index); - selectedCallback.accept(this.getSelectedEntry()); - } - } - - @Override - //#if MC > 11904 - public void render(int mouseX, int mouseY, boolean selected, GuiGraphics gui) { - //#elseif MC > 11502 - //$$ public void render(int mouseX, int mouseY, boolean selected, PoseStack poseStack) { - //#else - //$$ public void render(int mouseX, int mouseY, boolean selected) { - //#endif - if (shouldEnable.test(this.getSelectedEntry())) { - //#if MC > 11904 - super.render(mouseX, mouseY, selected, gui); - //#elseif MC > 11502 - //$$ super.render(mouseX, mouseY, selected, poseStack); - //#else - //$$ super.render(mouseX, mouseY, selected); - //#endif - } - } - -} \ No newline at end of file diff --git a/src/main/java/com/plusls/MasaGadget/gui/ScalableWidgetLabel.java b/src/main/java/com/plusls/MasaGadget/gui/ScalableWidgetLabel.java deleted file mode 100644 index a9b52125..00000000 --- a/src/main/java/com/plusls/MasaGadget/gui/ScalableWidgetLabel.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.plusls.MasaGadget.gui; - -import com.mojang.blaze3d.vertex.PoseStack; -import fi.dy.masa.malilib.gui.widgets.WidgetLabel; -import fi.dy.masa.malilib.render.RenderUtils; -import net.minecraft.client.Minecraft; - -//#if MC > 11904 -import net.minecraft.client.gui.GuiGraphics; -//#endif - -public class ScalableWidgetLabel extends WidgetLabel { - public float scale; - - public ScalableWidgetLabel(int x, int y, int width, int height, int textColor, float scale, String... text) { - super(x, y, width, height, textColor, text); - this.scale = scale; - } - - @Override - //#if MC > 11904 - public void render(int mouseX, int mouseY, boolean selected, GuiGraphics gui) { - PoseStack poseStack = gui.pose(); - //#elseif MC > 11502 - //$$ public void render(int mouseX, int mouseY, boolean selected, PoseStack poseStack) { - //#else - //$$ public void render(int mouseX, int mouseY, boolean selected) { - //$$ PoseStack poseStack = new PoseStack(); - //#endif - if (this.visible) { - poseStack.pushPose(); - RenderUtils.setupBlend(); - this.drawLabelBackground(); - - int fontHeight = this.fontHeight; - int yCenter = this.y + this.height / 2 + this.borderSize / 2; - int yTextStart = yCenter - 1 - this.labels.size() * fontHeight / 2; - - for (int i = 0; i < this.labels.size(); ++i) { - String text = this.labels.get(i); - if (this.centered) { - poseStack.translate(this.x + this.width / 2.0f - this.getStringWidth(text) / 2.0f, yTextStart + i * fontHeight, 0); - } else { - poseStack.translate(this.x, yTextStart + i * fontHeight, 0); - } - poseStack.scale(scale, scale, scale); - Minecraft.getInstance().font.drawInBatch(text, 0, 0, this.textColor, true, poseStack.last().pose(), - false, 0, 0xf000f0); - } - poseStack.popPose(); - } - } -} diff --git a/src/main/java/com/plusls/MasaGadget/gui/WidgetIconToggleButton.java b/src/main/java/com/plusls/MasaGadget/gui/WidgetIconToggleButton.java deleted file mode 100644 index e630469c..00000000 --- a/src/main/java/com/plusls/MasaGadget/gui/WidgetIconToggleButton.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.plusls.MasaGadget.gui; - -import com.mojang.blaze3d.vertex.PoseStack; -import fi.dy.masa.malilib.gui.interfaces.IGuiIcon; -import fi.dy.masa.malilib.gui.widgets.WidgetHoverInfo; -import fi.dy.masa.malilib.render.RenderUtils; - -import java.util.function.Consumer; -import java.util.function.Predicate; - -//#if MC > 11904 -import net.minecraft.client.gui.GuiGraphics; -//#endif - -public class WidgetIconToggleButton extends WidgetHoverInfo { - protected final TooltipSupplier tooltipSupplier; - protected final Consumer onPress; - protected final Predicate shouldEnable; - protected final IGuiIcon icon; - protected boolean status; - - public WidgetIconToggleButton(int x, int y, IGuiIcon icon, boolean defaultStatus, - Consumer onPress, TooltipSupplier tooltipSupplier, - Predicate shouldEnable, Object... args) { - super(x, y, icon.getWidth(), icon.getHeight(), tooltipSupplier.onTooltip(defaultStatus), args); - this.status = defaultStatus; - this.tooltipSupplier = tooltipSupplier; - this.onPress = onPress; - this.shouldEnable = shouldEnable; - this.icon = icon; - } - - @Override - //#if MC > 11904 - public void render(int mouseX, int mouseY, boolean selected, GuiGraphics gui) { - //#elseif MC > 11502 - //$$ public void render(int mouseX, int mouseY, boolean selected, PoseStack poseStack) { - //#else - //$$ public void render(int mouseX, int mouseY, boolean selected) { - //$$ PoseStack poseStack = new PoseStack(); - //#endif - if (!shouldEnable.test(this)) { - return; - } - RenderUtils.color(1.0F, 1.0F, 1.0F, 1.0F); - this.bindTexture(icon.getTexture()); - icon.renderAt(this.x, this.y, (float) this.zLevel, this.status, this.isMouseOver(mouseX, mouseY)); - - if (this.isMouseOver(mouseX, mouseY)) { - RenderUtils.drawOutlinedBox(this.x, this.y, this.width, this.height, 0x20C0C0C0, -520093697); - } - } - - protected boolean onMouseClickedImpl(int mouseX, int mouseY, int mouseButton) { - if (!shouldEnable.test(this)) { - return false; - } - this.status = !this.status; - this.getLines().clear(); - this.setInfoLines(this.tooltipSupplier.onTooltip(this.status)); - this.onPress.accept(this.status); - return true; - } - - @Override - //#if MC > 11904 - public void postRenderHovered(int mouseX, int mouseY, boolean selected, GuiGraphics gui) { - //#elseif MC > 11502 - //$$ public void postRenderHovered(int mouseX, int mouseY, boolean selected, PoseStack poseStack) { - //#else - //$$ public void postRenderHovered(int mouseX, int mouseY, boolean selected) { - //#endif - if (shouldEnable.test(this)) { - //#if MC > 11904 - super.postRenderHovered(mouseX, mouseY, selected, gui); - //#elseif MC > 11502 - //$$ super.postRenderHovered(mouseX, mouseY, selected, poseStack); - //#else - //$$ super.postRenderHovered(mouseX, mouseY, selected); - //#endif - } - } - - public interface TooltipSupplier { - String onTooltip(boolean status); - } -} diff --git a/src/main/java/com/plusls/MasaGadget/impl/compat/modmenu/ModMenuApiImpl.java b/src/main/java/com/plusls/MasaGadget/impl/compat/modmenu/ModMenuApiImpl.java new file mode 100644 index 00000000..92542474 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/impl/compat/modmenu/ModMenuApiImpl.java @@ -0,0 +1,25 @@ +package com.plusls.MasaGadget.impl.compat.modmenu; + +import com.plusls.MasaGadget.SharedConstants; +import com.plusls.MasaGadget.game.ConfigGui; +import top.hendrixshen.magiclib.api.compat.modmenu.ModMenuApiCompat; + +public class ModMenuApiImpl implements ModMenuApiCompat { + @Override + public ConfigScreenFactoryCompat getConfigScreenFactoryCompat() { + return (screen) -> { + ConfigGui configGui = new ConfigGui(); + //#if MC > 11903 + configGui.setParent(screen); + //#else + //$$ configGui.setParentGui(screen); + //#endif + return configGui; + }; + } + + @Override + public String getModIdCompat() { + return SharedConstants.getModIdentifier(); + } +} diff --git a/src/main/java/com/plusls/MasaGadget/impl/compat/modmenu/WrapperModMenuApiImpl.java b/src/main/java/com/plusls/MasaGadget/impl/compat/modmenu/WrapperModMenuApiImpl.java new file mode 100644 index 00000000..d9af1a9b --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/impl/compat/modmenu/WrapperModMenuApiImpl.java @@ -0,0 +1,10 @@ +package com.plusls.MasaGadget.impl.compat.modmenu; + +import com.plusls.MasaGadget.SharedConstants; + +public class WrapperModMenuApiImpl extends ModMenuApiImpl { + @Override + public String getModIdCompat() { + return SharedConstants.getModIdentifier(); + } +} diff --git a/src/main/java/com/plusls/MasaGadget/impl/event/DisconnectEvent.java b/src/main/java/com/plusls/MasaGadget/impl/event/DisconnectEvent.java new file mode 100644 index 00000000..a0c5c552 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/impl/event/DisconnectEvent.java @@ -0,0 +1,19 @@ +package com.plusls.MasaGadget.impl.event; + +import com.plusls.MasaGadget.api.event.DisconnectListener; +import org.jetbrains.annotations.NotNull; +import top.hendrixshen.magiclib.api.event.Event; + +import java.util.List; + +public class DisconnectEvent implements Event { + @Override + public void dispatch(@NotNull List listeners) { + listeners.forEach(DisconnectListener::onDisconnect); + } + + @Override + public Class getListenerType() { + return DisconnectListener.class; + } +} diff --git a/src/main/java/com/plusls/MasaGadget/generic/cacheContainerMenu/cacheContainerMenu/CacheContainerMenuHandler.java b/src/main/java/com/plusls/MasaGadget/impl/feature/cacheContainerMenu/CacheContainerMenuHandler.java similarity index 53% rename from src/main/java/com/plusls/MasaGadget/generic/cacheContainerMenu/cacheContainerMenu/CacheContainerMenuHandler.java rename to src/main/java/com/plusls/MasaGadget/impl/feature/cacheContainerMenu/CacheContainerMenuHandler.java index 2eea3232..7aa73d58 100644 --- a/src/main/java/com/plusls/MasaGadget/generic/cacheContainerMenu/cacheContainerMenu/CacheContainerMenuHandler.java +++ b/src/main/java/com/plusls/MasaGadget/impl/feature/cacheContainerMenu/CacheContainerMenuHandler.java @@ -1,6 +1,10 @@ -package com.plusls.MasaGadget.generic.cacheContainerMenu.cacheContainerMenu; +package com.plusls.MasaGadget.impl.feature.cacheContainerMenu; import com.plusls.MasaGadget.util.MiscUtil; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; import net.minecraft.world.Container; @@ -10,46 +14,56 @@ import java.util.Objects; +@Getter +@Setter +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class CacheContainerMenuHandler { - @Nullable - public static BlockPos lastClickBlockPos = null; - - private static long lastClickTime = System.nanoTime(); + @Getter + private static final CacheContainerMenuHandler instance = new CacheContainerMenuHandler(); + @Nullable + @Getter + private BlockPos lastClickBlockPos = null; + private long lastClickTime = System.nanoTime(); - public static void setLastClickBlockPos(BlockPos blockPos) { - lastClickBlockPos = blockPos; - lastClickTime = System.nanoTime(); + public void setLastClickBlockPos(BlockPos blockPos) { + this.lastClickBlockPos = blockPos; + this.lastClickTime = System.nanoTime(); } - public static void updateLastClickBlockPos() { + public void checkLastClickBlockPos() { long currentTime = System.nanoTime(); - // 延迟超过 1 s 才打开的容器则会被忽略 - if (lastClickBlockPos == null || currentTime - lastClickTime > 1000000000 || !checkContainerMenu()) { - clearLastClickData(); + + if (lastClickBlockPos == null || + // Containers opened with a delay of more than 1s are ignored. + currentTime - this.lastClickTime > 1E9 || + !this.isAvailableMenu()) { + this.clearLastClickData(); } } - public static void clearLastClickData() { - lastClickBlockPos = null; + public void clearLastClickData() { + this.lastClickBlockPos = null; } @Nullable - public static Container getLastClickContainer() { - if (lastClickBlockPos != null) { - return MiscUtil.getContainer(Objects.requireNonNull(Minecraft.getInstance().level), lastClickBlockPos); + public Container getLastClickContainer() { + if (this.lastClickBlockPos != null) { + return MiscUtil.getContainer(Objects.requireNonNull(Minecraft.getInstance().level), this.lastClickBlockPos); } + return null; } - - public static boolean checkContainerMenu() { + public boolean isAvailableMenu() { Minecraft minecraft = Minecraft.getInstance(); AbstractContainerMenu containerMenu = Objects.requireNonNull(minecraft.player).containerMenu; - if (lastClickBlockPos == null) { + + if (this.lastClickBlockPos == null) { return false; } - Block block = Objects.requireNonNull(minecraft.level).getBlockState(lastClickBlockPos).getBlock(); + + Block block = Objects.requireNonNull(minecraft.level).getBlockState(this.lastClickBlockPos).getBlock(); return (containerMenu instanceof AbstractFurnaceMenu && block instanceof AbstractFurnaceBlock) || (containerMenu instanceof HopperMenu && block instanceof HopperBlock) || (containerMenu instanceof ShulkerBoxMenu && block instanceof ShulkerBoxBlock) || @@ -57,5 +71,4 @@ public static boolean checkContainerMenu() { (containerMenu instanceof DispenserMenu && block instanceof DispenserBlock) || (containerMenu instanceof ChestMenu && (block instanceof ChestBlock || block instanceof BarrelBlock)); } - } 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 new file mode 100644 index 00000000..2e4dfead --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/EntityInfoRenderer.java @@ -0,0 +1,102 @@ +package com.plusls.MasaGadget.impl.feature.entityInfo; + +import com.google.common.collect.Lists; +import com.google.common.collect.Queues; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.util.MiscUtil; +import com.plusls.MasaGadget.util.SyncUtil; +import lombok.Getter; +import net.minecraft.client.Minecraft; +import net.minecraft.core.Position; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.monster.ZombieVillager; +import net.minecraft.world.entity.npc.Villager; +import net.minecraft.world.level.Level; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; +import top.hendrixshen.magiclib.MagicLib; +import top.hendrixshen.magiclib.api.event.minecraft.render.RenderEntityListener; +import top.hendrixshen.magiclib.api.event.minecraft.render.RenderLevelListener; +import top.hendrixshen.magiclib.api.render.context.RenderContext; +import top.hendrixshen.magiclib.impl.render.TextRenderer; + +import java.util.Queue; + +public class EntityInfoRenderer implements RenderEntityListener, RenderLevelListener { + @Getter + private static final EntityInfoRenderer instance = new EntityInfoRenderer(); + private final Queue queue = Queues.newConcurrentLinkedQueue(); + + @ApiStatus.Internal + public void init() { + MagicLib.getInstance().getEventManager().register(RenderEntityListener.class, this); + MagicLib.getInstance().getEventManager().register(RenderLevelListener.class, this); + } + + private static TextRenderer rotationAround(@NotNull TextRenderer renderer, @NotNull Position centerPos, double range) { + Position camPos = Minecraft.getInstance().gameRenderer.getMainCamera().getPosition(); + float xAngle = (float) Mth.atan2(camPos.z() - centerPos.z(), camPos.x() - centerPos.x()); + float zAngle = (float) Mth.atan2(camPos.x() - centerPos.x(), camPos.z() - centerPos.z()); + return renderer.at(range * Mth.cos(xAngle) + centerPos.x(), centerPos.y(), range * Mth.cos(zAngle) + centerPos.z()); + } + + @Override + public void preRenderEntity(Entity entity, RenderContext renderContext, float partialTicks) { + // NO-OP + } + + @Override + public void postRenderEntity(Entity entity, RenderContext renderContext, float partialTicks) { + if ((entity instanceof Villager && + (Configs.renderNextRestockTime.getBooleanValue() || Configs.renderTradeEnchantedBook.getBooleanValue())) || + (entity instanceof ZombieVillager && (Configs.renderZombieVillagerConvertTime.getBooleanValue()))) { + this.queue.add(entity); + } + } + + @Override + public void preRenderLevel(Level level, RenderContext renderContext, float partialTicks) { + // NO-OP + } + + @Override + public void postRenderLevel(Level level, RenderContext renderContext, float partialTicks) { + for (Entity entity : this.queue) { + if (entity instanceof Villager) { + Villager villager = MiscUtil.cast(SyncUtil.syncEntityDataFromIntegratedServer(entity)); + TextRenderer renderer = TextRenderer.create(); + + if (Configs.renderNextRestockTime.getBooleanValue()) { + renderer.addLine(VillagerNextRestockTimeInfo.getInfo(villager)); + } + + if (Configs.renderTradeEnchantedBook.getBooleanValue()) { + VillageTradeEnchantedBookInfo.getInfo(villager).forEach(renderer::addLine); + } + + if (villager.isSleeping()) { + Position position = entity.getEyePosition(partialTicks); + renderer.at(position.x(), position.y() + 0.4F, position.z()); + } else { + EntityInfoRenderer.rotationAround(renderer, entity.getEyePosition(partialTicks), 0.6); + } + + renderer.bgColor((int) (Minecraft.getInstance().options.getBackgroundOpacity(0.25F) * 255.0F) << 24) + .fontScale(0.015F) + .seeThrough() + .render(); + } else if (entity instanceof ZombieVillager) { + ZombieVillager zombieVillager = MiscUtil.cast(SyncUtil.syncEntityDataFromIntegratedServer(entity)); + EntityInfoRenderer.rotationAround(TextRenderer.create(), entity.getEyePosition(partialTicks), 0.6) + .text(ZombieVillagerConvertTimeInfo.getInfo(zombieVillager)) + .bgColor((int) (Minecraft.getInstance().options.getBackgroundOpacity(0.25F) * 255.0F) << 24) + .fontScale(0.015F) + .seeThrough() + .render(); + } + } + + this.queue.clear(); + } +} 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 new file mode 100644 index 00000000..33ab7adc --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/VillageTradeEnchantedBookInfo.java @@ -0,0 +1,120 @@ +package com.plusls.MasaGadget.impl.feature.entityInfo; + +import com.google.common.collect.Lists; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.*; +import net.minecraft.world.entity.npc.Villager; +import net.minecraft.world.entity.npc.VillagerProfession; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.enchantment.Enchantment; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.trading.MerchantOffer; +import org.jetbrains.annotations.NotNull; +import top.hendrixshen.magiclib.api.compat.minecraft.world.item.ItemStackCompat; +import top.hendrixshen.magiclib.util.minecraft.ComponentUtil; + +import java.util.List; + +//#if MC > 12004 +//$$ import it.unimi.dsi.fastutil.objects.Object2IntMap; +//$$ import net.minecraft.core.Holder; +//$$ import net.minecraft.world.item.enchantment.ItemEnchantments; +//#else +import java.util.Map; +//#endif + +public class VillageTradeEnchantedBookInfo { + public static @NotNull List getInfo(@NotNull Villager villager) { + List ret = Lists.newArrayList(); + + if (villager.getVillagerData().getProfession() != VillagerProfession.LIBRARIAN) { + return ret; + } + + for (MerchantOffer tradeOffer : villager.getOffers()) { + ItemStack sellItem = tradeOffer.getResult(); + ItemStackCompat sellItemCompat = ItemStackCompat.of(sellItem); + + if (!sellItemCompat.is(Items.ENCHANTED_BOOK)) { + continue; + } + + //#if MC > 12004 + //$$ ItemEnchantments enchantmentData = EnchantmentHelper.getEnchantmentsForCrafting(sellItem); + //#else + Map enchantmentData = EnchantmentHelper.getEnchantments(sellItem); + //#endif + + for ( + //#if MC > 12004 + //$$ Object2IntMap.Entry> entry + //#else + Map.Entry entry + //#endif + : enchantmentData.entrySet() + ) { + //#if MC > 12004 + //$$ int level = entry.getIntValue(); + //#else + int level = entry.getValue(); + //#endif + int cost = tradeOffer.getBaseCostA().getCount(); + int minCost = 2 + 3 * level; + int maxCost = minCost + 4 + level * 10; + + if ( + //#if MC > 12004 + //$$ entry.getKey().value().isTreasureOnly() + //#else + entry.getKey().isTreasureOnly() + //#endif + ) { + minCost *= 2; + maxCost *= 2; + } + + ChatFormatting color; + int one_third = (maxCost - minCost) / 3; + + if (cost <= one_third + minCost) { + color = ChatFormatting.GREEN; + } else if (cost <= one_third * 2 + minCost) { + color = ChatFormatting.WHITE; + } else { + color = ChatFormatting.RED; + } + + if ( + //#if MC > 12004 + //$$ level == entry.getKey().value().getMaxLevel() + //#else + level == entry.getKey().getMaxLevel() + //#endif + ) { + //#if MC > 12004 + //$$ ret.add(((MutableComponent) entry.getKey().value().getFullname(entry.getIntValue())).withStyle(ChatFormatting.GOLD)); + //#elseif MC > 11502 + ret.add(((MutableComponent) entry.getKey().getFullname(entry.getValue())).withStyle(ChatFormatting.GOLD)); + //#else + //$$ ret.add(((BaseComponent) entry.getKey().getFullname(entry.getValue())).withStyle(ChatFormatting.GOLD)); + //#endif + } else { + //#if MC > 12004 + //$$ ret.add(((MutableComponent) entry.getKey().value().getFullname(entry.getIntValue())).withStyle(ChatFormatting.WHITE)); + //#elseif MC > 11502 + ret.add(((MutableComponent) entry.getKey().getFullname(entry.getValue())).withStyle(ChatFormatting.WHITE)); + //#else + //$$ ret.add(((BaseComponent) entry.getKey().getFullname(entry.getValue())).withStyle(ChatFormatting.GOLD)); + //#endif + } + + ret.add(ComponentUtil.simple(String.format("%d(%d-%d)", cost, minCost, maxCost)).withStyle(color).get()); + } + + break; + } + + return ret; + } +} diff --git a/src/main/java/com/plusls/MasaGadget/generic/entityInfo/VillagerNextRestockTimeInfo.java b/src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/VillagerNextRestockTimeInfo.java similarity index 86% rename from src/main/java/com/plusls/MasaGadget/generic/entityInfo/VillagerNextRestockTimeInfo.java rename to src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/VillagerNextRestockTimeInfo.java index b7c30d61..e9be861e 100644 --- a/src/main/java/com/plusls/MasaGadget/generic/entityInfo/VillagerNextRestockTimeInfo.java +++ b/src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/VillagerNextRestockTimeInfo.java @@ -1,4 +1,4 @@ -package com.plusls.MasaGadget.generic.entityInfo; +package com.plusls.MasaGadget.impl.feature.entityInfo; import com.plusls.MasaGadget.mixin.accessor.AccessorVillager; import net.minecraft.ChatFormatting; @@ -7,10 +7,10 @@ import net.minecraft.world.entity.npc.VillagerProfession; import net.minecraft.world.item.trading.MerchantOffer; import org.jetbrains.annotations.NotNull; -import top.hendrixshen.magiclib.compat.minecraft.api.network.chat.ComponentCompatApi; +import top.hendrixshen.magiclib.util.minecraft.ComponentUtil; public class VillagerNextRestockTimeInfo { - public static Component getInfo(@NotNull Villager villager) { + public static @NotNull Component getInfo(@NotNull Villager villager) { long nextRestockTime; long nextWorkTime; long timeOfDay = villager.level().getDayTime() % 24000; @@ -46,10 +46,10 @@ public static Component getInfo(@NotNull Villager villager) { } if (nextRestockTime == 0) { - return ComponentCompatApi.literal("OK").withStyle(ChatFormatting.GREEN); + return ComponentUtil.simple("OK").withStyle(ChatFormatting.GREEN).get(); } - return ComponentCompatApi.literal(String.format("%d", nextRestockTime)); + return ComponentUtil.simple(String.format("%d", nextRestockTime)).get(); } // 因为刁民的需要补货的函数,会检查当前货物是否被消耗,从使用的角度只需要关心当前货物是否用完 diff --git a/src/main/java/com/plusls/MasaGadget/generic/entityInfo/ZombieVillagerConvertTimeInfo.java b/src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/ZombieVillagerConvertTimeInfo.java similarity index 64% rename from src/main/java/com/plusls/MasaGadget/generic/entityInfo/ZombieVillagerConvertTimeInfo.java rename to src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/ZombieVillagerConvertTimeInfo.java index 7863f521..38f7a158 100644 --- a/src/main/java/com/plusls/MasaGadget/generic/entityInfo/ZombieVillagerConvertTimeInfo.java +++ b/src/main/java/com/plusls/MasaGadget/impl/feature/entityInfo/ZombieVillagerConvertTimeInfo.java @@ -1,19 +1,19 @@ -package com.plusls.MasaGadget.generic.entityInfo; +package com.plusls.MasaGadget.impl.feature.entityInfo; import com.plusls.MasaGadget.mixin.accessor.AccessorZombieVillager; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.monster.ZombieVillager; import org.jetbrains.annotations.NotNull; -import top.hendrixshen.magiclib.compat.minecraft.api.network.chat.ComponentCompatApi; +import top.hendrixshen.magiclib.util.minecraft.ComponentUtil; public class ZombieVillagerConvertTimeInfo { public static @NotNull Component getInfo(ZombieVillager zombieVillager) { int villagerConversionTime = ((AccessorZombieVillager) zombieVillager).getVillagerConversionTime(); if (villagerConversionTime > 0) { - return ComponentCompatApi.literal(String.format("%d", villagerConversionTime)); + return ComponentUtil.simple(String.format("%d", villagerConversionTime)).get(); } - return ComponentCompatApi.literal("-1"); + return ComponentUtil.simple("-1").get(); } } diff --git a/src/main/java/com/plusls/MasaGadget/impl/feature/entityTrace/EntityTraceRenderer.java b/src/main/java/com/plusls/MasaGadget/impl/feature/entityTrace/EntityTraceRenderer.java new file mode 100644 index 00000000..5620251c --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/impl/feature/entityTrace/EntityTraceRenderer.java @@ -0,0 +1,90 @@ +package com.plusls.MasaGadget.impl.feature.entityTrace; + +import com.google.common.collect.Queues; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.util.MiscUtil; +import com.plusls.MasaGadget.util.RenderUtil; +import com.plusls.MasaGadget.util.SyncUtil; +import fi.dy.masa.malilib.util.Color4f; +import lombok.Getter; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.ai.memory.MemoryModuleType; +import net.minecraft.world.entity.npc.Villager; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.ApiStatus; +import top.hendrixshen.magiclib.MagicLib; +import top.hendrixshen.magiclib.api.event.minecraft.render.RenderEntityListener; +import top.hendrixshen.magiclib.api.event.minecraft.render.RenderLevelListener; +import top.hendrixshen.magiclib.api.render.context.RenderContext; +import top.hendrixshen.magiclib.impl.render.context.RenderGlobal; + +import java.util.Queue; + +public class EntityTraceRenderer implements RenderEntityListener, RenderLevelListener { + @Getter + private static final EntityTraceRenderer instance = new EntityTraceRenderer(); + private final Queue queue = Queues.newConcurrentLinkedQueue(); + + @ApiStatus.Internal + public void init() { + MagicLib.getInstance().getEventManager().register(RenderEntityListener.class, this); + MagicLib.getInstance().getEventManager().register(RenderLevelListener.class, this); + } + + @Override + public void preRenderEntity(Entity entity, RenderContext renderContext, float partialTicks) { + // NO-OP + } + + @Override + public void postRenderEntity(Entity entity, RenderContext renderContext, float partialTicks) { + if (entity instanceof Villager && + Configs.renderVillageHomeTracer.getBooleanValue() || + Configs.renderVillageJobSiteTracer.getBooleanValue()) { + this.queue.add(entity); + } + } + + @Override + public void preRenderLevel(Level level, RenderContext renderContext, float partialTicks) { + // NO-OP + } + + @Override + public void postRenderLevel(Level level, RenderContext renderContext, float partialTicks) { + for (Entity entity : this.queue) { + if (entity instanceof Villager) { + Villager villager = MiscUtil.cast(SyncUtil.syncEntityDataFromIntegratedServer(entity)); + + if (Configs.renderVillageHomeTracer.getBooleanValue()) { + villager.getBrain().getMemory(MemoryModuleType.HOME).ifPresent(globalPos -> { + Vec3 eyeVec3 = entity.getEyePosition(partialTicks); + Vec3 bedVec3 = new Vec3(globalPos.pos().getX() + 0.5, globalPos.pos().getY() + 0.5, globalPos.pos().getZ() + 0.5); + RenderGlobal.disableDepthTest(); + RenderUtil.drawConnectLine(eyeVec3, bedVec3, 0.05, + new Color4f(1, 1, 1), + Color4f.fromColor(Configs.renderVillageHomeTracerColor.getColor(), 1.0F), + Configs.renderVillageHomeTracerColor.getColor()); + RenderGlobal.enableDepthTest(); + }); + } + + if (Configs.renderVillageJobSiteTracer.getBooleanValue()) { + villager.getBrain().getMemory(MemoryModuleType.JOB_SITE).ifPresent(globalPos -> { + Vec3 eyeVec3 = entity.getEyePosition(partialTicks); + Vec3 jobVev3 = new Vec3(globalPos.pos().getX() + 0.5, globalPos.pos().getY() + 0.5, globalPos.pos().getZ() + 0.5); + RenderGlobal.disableDepthTest(); + RenderUtil.drawConnectLine(eyeVec3, jobVev3, 0.05, + new Color4f(1, 1, 1), + Color4f.fromColor(Configs.renderVillageJobSiteTracerColor.getColor(), 1.0F), + Configs.renderVillageJobSiteTracerColor.getColor()); + RenderGlobal.enableDepthTest(); + }); + } + } + } + + this.queue.clear(); + } +} diff --git a/src/main/java/com/plusls/MasaGadget/util/HitResultUtil.java b/src/main/java/com/plusls/MasaGadget/impl/generic/HitResultHandler.java similarity index 50% rename from src/main/java/com/plusls/MasaGadget/util/HitResultUtil.java rename to src/main/java/com/plusls/MasaGadget/impl/generic/HitResultHandler.java index 5f82d1c8..e718e98e 100644 --- a/src/main/java/com/plusls/MasaGadget/util/HitResultUtil.java +++ b/src/main/java/com/plusls/MasaGadget/impl/generic/HitResultHandler.java @@ -1,12 +1,15 @@ -package com.plusls.MasaGadget.util; +package com.plusls.MasaGadget.impl.generic; +import com.google.common.collect.Sets; import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.tweakeroo.inventoryPreviewSupportSelect.InventoryOverlayRenderHandler; -import com.plusls.MasaGadget.tweakeroo.inventoryPreviewSyncData.InventoryPreviewSyncDataUtil; -import com.plusls.MasaGadget.tweakeroo.inventoryPreviewSyncDataClientOnly.InventoryPreviewSyncDataClientOnlyUtil; +import com.plusls.MasaGadget.impl.mod_tweak.tweakeroo.inventoryPreviewSupportSelect.InventoryOverlayRenderHandler; +import com.plusls.MasaGadget.util.InventoryPreviewSyncDataClientOnlyUtil; +import com.plusls.MasaGadget.util.InventoryPreviewSyncDataUtil; +import com.plusls.MasaGadget.util.MiscUtil; import fi.dy.masa.malilib.util.WorldUtils; import fi.dy.masa.tweakeroo.config.FeatureToggle; import fi.dy.masa.tweakeroo.config.Hotkeys; +import lombok.Getter; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; @@ -18,119 +21,139 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.phys.*; -import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import top.hendrixshen.magiclib.util.FabricUtil; +import top.hendrixshen.magiclib.MagicLib; +import top.hendrixshen.magiclib.api.compat.minecraft.world.entity.EntityCompat; +import top.hendrixshen.magiclib.util.collect.ValueContainer; import java.util.*; -public class HitResultUtil { - - private static final Set hitCallbacks = new HashSet<>(); - private static boolean lastInventoryPreviewStatus = false; +public class HitResultHandler { + @Getter + private static final HitResultHandler instance = new HitResultHandler(); + private final Set hitCallbacks = Sets.newHashSet(); + private boolean lastInventoryPreviewStatus = false; @Nullable - private static HitResult lastHitResult = null; - + private HitResult lastHitResult = null; @Nullable - private static Object lastHitBlockEntity = null; + private Object lastHitBlockEntity = null; - @Nullable - public static Object getLastHitBlockEntity() { - return lastHitBlockEntity; + @ApiStatus.Internal + public void init() { + ClientTickEvents.END_CLIENT_TICK.register(minecraft -> HitResultHandler.getInstance().endClientTickCallback()); + + if (MagicLib.getInstance().getCurrentPlatform().isModLoaded(ModInfo.TWEAKEROO_MOD_ID)) { + this.registerOnHitCallback(InventoryPreviewSyncDataUtil::onHitCallback); + this.registerOnHitCallback(InventoryPreviewSyncDataClientOnlyUtil::onHitCallback); + this.registerOnHitCallback(InventoryOverlayRenderHandler::onHitCallback); + } } - @Nullable - public static HitResult getLastHitResult() { - return lastHitResult; + public ValueContainer getLastHitBlockEntity() { + return ValueContainer.ofNullable(this.lastHitBlockEntity); } - @Nullable - public static Entity getCameraEntity() { + public ValueContainer getLastHitResult() { + return ValueContainer.ofNullable(this.lastHitResult); + } + + public ValueContainer getCameraEntity() { Minecraft mc = Minecraft.getInstance(); + if (mc.player == null) { return null; } + Player player = mc.player; Entity cameraEntity = mc.getCameraEntity(); - if (!FabricUtil.isModLoaded(ModInfo.TWEAKEROO_MOD_ID) || !FeatureToggle.TWEAK_FREE_CAMERA.getBooleanValue() || cameraEntity == null) { + + if (!MagicLib.getInstance().getCurrentPlatform().isModLoaded(ModInfo.TWEAKEROO_MOD_ID) || + !FeatureToggle.TWEAK_FREE_CAMERA.getBooleanValue() || cameraEntity == null) { cameraEntity = player; } - return cameraEntity; + return ValueContainer.of(cameraEntity); } - @Nullable - public static Entity getHitEntity() { - HitResult hitResult = lastHitResult; + public ValueContainer getHitEntity() { + HitResult hitResult = this.lastHitResult; + if (hitResult == null) { - return null; + return ValueContainer.empty(); } + if (hitResult.getType() != HitResult.Type.ENTITY) { - return null; + return ValueContainer.empty(); } - return ((EntityHitResult) hitResult).getEntity(); + + return ValueContainer.of(((EntityHitResult) hitResult).getEntity()); } - @Nullable - public static HitResult getHitResult() { + public ValueContainer getHitResult() { Minecraft mc = Minecraft.getInstance(); - Level world = mc.level; + Level level = mc.level; - if (world == null) { - return null; + if (level == null) { + return ValueContainer.empty(); } - Entity cameraEntity = getCameraEntity(); - if (cameraEntity == null) { - return null; + ValueContainer cameraEntity = this.getCameraEntity(); + + if (cameraEntity.isEmpty()) { + return ValueContainer.empty(); } try { - HitResult hitResult; - hitResult = getRayTraceFromEntity(world, cameraEntity, false); + HitResult hitResult = this.getRayTraceFromEntity(level, cameraEntity.get(), false); + if (hitResult.getType() == HitResult.Type.MISS) { - return null; - } else if (hitResult.getType() == HitResult.Type.ENTITY) { + return ValueContainer.empty(); + } + + if (hitResult.getType() == HitResult.Type.ENTITY) { EntityHitResult entityHitResult = (EntityHitResult) hitResult; hitResult = new EntityHitResult(MiscUtil.getBestEntity(entityHitResult.getEntity()), entityHitResult.getLocation()); } - return hitResult; + + return ValueContainer.of(hitResult); } catch (ConcurrentModificationException e) { // 不知道为啥,在容器预览时调用该函数有概率崩溃(在实体频繁生成死亡的时候,比如刷石机) - return null; + return ValueContainer.empty(); } } - @Nullable - public static BlockPos getHitBlockPos() { - HitResult hitResult = lastHitResult; + public ValueContainer getHitBlockPos() { + HitResult hitResult = this.lastHitResult; + if (hitResult == null) { - return null; + return ValueContainer.empty(); } + if (hitResult.getType() != HitResult.Type.BLOCK) { - return null; + return ValueContainer.empty(); } - return ((BlockHitResult) hitResult).getBlockPos(); - } + return ValueContainer.of(((BlockHitResult) hitResult).getBlockPos()); + } // code from tweakeroo RayTraceUtils.getRayTraceFromEntity - @NotNull - public static HitResult getRayTraceFromEntity(Level worldIn, Entity entityIn, boolean useLiquids) { + public HitResult getRayTraceFromEntity(Level worldIn, Entity entityIn, boolean useLiquids) { double reach = 5.0; - return getRayTraceFromEntity(worldIn, entityIn, useLiquids, reach); + return this.getRayTraceFromEntity(worldIn, entityIn, useLiquids, reach); } - @NotNull - public static HitResult getRayTraceFromEntity(Level worldIn, Entity entityIn, boolean useLiquids, double range) { - Vec3 eyesVec = new Vec3(entityIn.getX(), entityIn.getY() + (double) entityIn.getEyeHeight(), entityIn.getZ()); + public HitResult getRayTraceFromEntity(Level worldIn, Entity entityIn, boolean useLiquids, double range) { + EntityCompat entityInCompat = EntityCompat.of(entityIn); + Vec3 eyesVec = new Vec3(entityInCompat.getX(), entityInCompat.getY() + (double) entityIn.getEyeHeight(), entityInCompat.getZ()); Vec3 rangedLookRot = entityIn.getViewVector(1.0F).scale(range); Vec3 lookVec = eyesVec.add(rangedLookRot); ClipContext.Fluid fluidMode = useLiquids ? ClipContext.Fluid.SOURCE_ONLY : ClipContext.Fluid.NONE; ClipContext context = new ClipContext(eyesVec, lookVec, ClipContext.Block.COLLIDER, fluidMode, entityIn); HitResult result = worldIn.clip(context); + if (result == null) { result = BlockHitResult.miss(Vec3.ZERO, Direction.UP, BlockPos.ZERO); } @@ -144,8 +167,10 @@ public static HitResult getRayTraceFromEntity(Level worldIn, Entity entityIn, bo for (Entity entity : list) { bb = entity.getBoundingBox(); Optional traceTmp = bb.clip(lookVec, eyesVec); + if (traceTmp.isPresent()) { double distance = eyesVec.distanceTo(traceTmp.get()); + if (distance <= closest) { targetEntity = entity; entityTrace = traceTmp; @@ -161,63 +186,64 @@ public static HitResult getRayTraceFromEntity(Level worldIn, Entity entityIn, bo return result; } - public static void init() { - ClientTickEvents.END_CLIENT_TICK.register(minecraft -> HitResultUtil.endClientTickCallback()); - if (FabricUtil.isModLoaded(ModInfo.TWEAKEROO_MOD_ID)) { - registerOnHitCallback(InventoryPreviewSyncDataUtil::onHitCallback); - registerOnHitCallback(InventoryPreviewSyncDataClientOnlyUtil::onHitCallback); - registerOnHitCallback(InventoryOverlayRenderHandler::onHitCallback); - } + public boolean getLastInventoryPreviewStatus() { + return this.lastHitResult != null && this.lastInventoryPreviewStatus; } - public static boolean getLastInventoryPreviewStatus() { - return lastHitResult != null && lastInventoryPreviewStatus; - } + public void endClientTickCallback() { + ProfilerFiller profiler = Minecraft.getInstance().getProfiler(); + Level level = WorldUtils.getBestWorld(Minecraft.getInstance()); - public static void endClientTickCallback() { - final ProfilerFiller profiler = Minecraft.getInstance().getProfiler(); - Level world = WorldUtils.getBestWorld(Minecraft.getInstance()); - if (world == null) { + if (level == null) { return; } + boolean currentStatus = false; - if (FabricUtil.isModLoaded(ModInfo.TWEAKEROO_MOD_ID)) { + + if (MagicLib.getInstance().getCurrentPlatform().isModLoaded(ModInfo.TWEAKEROO_MOD_ID)) { currentStatus = Hotkeys.INVENTORY_PREVIEW.getKeybind().isKeybindHeld(); } + profiler.push("HitResultUtil.getHitResult"); - lastHitResult = getHitResult(); + this.lastHitResult = this.getHitResult().orElse(null); profiler.pop(); - lastHitBlockEntity = null; + this.lastHitBlockEntity = null; + if (lastHitResult != null && lastHitResult.getType() == HitResult.Type.BLOCK && currentStatus) { - BlockPos pos = getHitBlockPos(); - if (pos != null) { + ValueContainer pos = this.getHitBlockPos(); + + if (pos.isPresent()) { // 绕过线程检查 profiler.push("MiscUtil.getContainer"); - lastHitBlockEntity = MiscUtil.getContainer(world, pos); + this.lastHitBlockEntity = MiscUtil.getContainer(level, pos.get()); profiler.pop(); + if (lastHitBlockEntity == null) { profiler.push("world.getChunkAt"); - LevelChunk levelChunk = world.getChunkAt(pos); + LevelChunk levelChunk = level.getChunkAt(pos.get()); profiler.pop(); + if (levelChunk != null) { profiler.push("levelChunk.getBlockEntity"); - lastHitBlockEntity = levelChunk.getBlockEntity(pos); + lastHitBlockEntity = levelChunk.getBlockEntity(pos.get()); profiler.pop(); } } } } profiler.push("MiscUtil: run callbacks"); + for (HitResultCallback callback : hitCallbacks) { - callback.onHit(lastHitResult, lastInventoryPreviewStatus, - currentStatus != lastInventoryPreviewStatus); + callback.onHit(this.lastHitResult, this.lastInventoryPreviewStatus, + currentStatus != this.lastInventoryPreviewStatus); } + profiler.pop(); - lastInventoryPreviewStatus = currentStatus; + this.lastInventoryPreviewStatus = currentStatus; } - public static void registerOnHitCallback(HitResultCallback callback) { - hitCallbacks.add(callback); + public void registerOnHitCallback(HitResultCallback callback) { + this.hitCallbacks.add(callback); } @FunctionalInterface diff --git a/src/main/java/com/plusls/MasaGadget/gui/MasaGadgetIcons.java b/src/main/java/com/plusls/MasaGadget/impl/gui/MasaGadgetIcons.java similarity index 94% rename from src/main/java/com/plusls/MasaGadget/gui/MasaGadgetIcons.java rename to src/main/java/com/plusls/MasaGadget/impl/gui/MasaGadgetIcons.java index e9709fdb..531a1ade 100644 --- a/src/main/java/com/plusls/MasaGadget/gui/MasaGadgetIcons.java +++ b/src/main/java/com/plusls/MasaGadget/impl/gui/MasaGadgetIcons.java @@ -1,4 +1,4 @@ -package com.plusls.MasaGadget.gui; +package com.plusls.MasaGadget.impl.gui; import com.plusls.MasaGadget.ModInfo; import fi.dy.masa.malilib.gui.interfaces.IGuiIcon; @@ -64,6 +64,6 @@ public void renderAt(int x, int y, float zLevel, boolean enabled, boolean select @Override public ResourceLocation getTexture() { - return TEXTURE; + return MasaGadgetIcons.TEXTURE; } } \ No newline at end of file diff --git a/src/main/java/com/plusls/MasaGadget/impl/gui/ScalableWidgetLabel.java b/src/main/java/com/plusls/MasaGadget/impl/gui/ScalableWidgetLabel.java new file mode 100644 index 00000000..363ae79e --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/impl/gui/ScalableWidgetLabel.java @@ -0,0 +1,100 @@ +package com.plusls.MasaGadget.impl.gui; + +import fi.dy.masa.malilib.gui.widgets.WidgetLabel; +import fi.dy.masa.malilib.render.RenderUtils; +import lombok.Getter; +import lombok.Setter; +import net.minecraft.client.Minecraft; +import top.hendrixshen.magiclib.api.compat.minecraft.client.gui.FontCompat; +import top.hendrixshen.magiclib.api.render.context.RenderContext; + +//#if MC > 11904 +import net.minecraft.client.gui.GuiGraphics; +//#elseif MC > 11404 +//$$ import com.mojang.blaze3d.vertex.PoseStack; +//#endif + +//#if MC < 12000 && MC > 11404 +//$$ import com.mojang.blaze3d.vertex.Tesselator; +//$$ import net.minecraft.client.renderer.MultiBufferSource; +//#endif + +@Getter +@Setter +public class ScalableWidgetLabel extends WidgetLabel { + private float scale; + + public ScalableWidgetLabel(int x, int y, int width, int height, int textColor, float scale, String... text) { + super(x, y, width, height, textColor, text); + this.scale = scale; + } + + @Override + public void render( + int mouseX, + int mouseY, + boolean selected + //#if MC > 11904 + , GuiGraphics guiGraphicsOrPoseStack + //#elseif MC > 11502 + //$$ , PoseStack guiGraphicsOrPoseStack + //#endif + ) { + RenderContext renderContext = RenderContext.of( + //#if MC > 11502 + guiGraphicsOrPoseStack + //#endif + ); + + if (this.visible) { + renderContext.pushPose(); + RenderUtils.setupBlend(); + this.drawLabelBackground(); + + int fontHeight = this.fontHeight; + int yCenter = this.y + this.height / 2 + this.borderSize / 2; + int yTextStart = yCenter - 1 - this.labels.size() * fontHeight / 2; + + for (int i = 0; i < this.labels.size(); i++) { + String text = this.labels.get(i); + + if (this.centered) { + renderContext.translate( + this.x + this.width / 2.0f - this.getStringWidth(text) / 2.0f, + yTextStart + i * fontHeight, + 0 + ); + } else { + renderContext.translate(this.x, yTextStart + i * fontHeight, 0); + } + + renderContext.scale(scale, scale, scale); + FontCompat.of(Minecraft.getInstance().font) + .drawInBatch( + text, + 0.0F, + 0.0F, + this.textColor, + true, + //#if MC > 11404 + //#if MC > 11502 + renderContext.getPoseStack().last().pose(), + //#else + //$$ new PoseStack().last().pose(), + //#endif + //#if MC > 11904 + renderContext.getGuiComponent().bufferSource(), + //#else + //$$ MultiBufferSource.immediate(Tesselator.getInstance().getBuilder()), + //#endif + //#endif + FontCompat.DisplayMode.NORMAL, + 0, + 0xf000f0 + ); + } + + renderContext.popPose(); + } + } +} diff --git a/src/main/java/com/plusls/MasaGadget/impl/mod_tweak/malilib/fastSwitchMasaConfigGui/FastMasaGuiSwitcher.java b/src/main/java/com/plusls/MasaGadget/impl/mod_tweak/malilib/fastSwitchMasaConfigGui/FastMasaGuiSwitcher.java new file mode 100644 index 00000000..d676b292 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/impl/mod_tweak/malilib/fastSwitchMasaConfigGui/FastMasaGuiSwitcher.java @@ -0,0 +1,159 @@ +package com.plusls.MasaGadget.impl.mod_tweak.malilib.fastSwitchMasaConfigGui; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.plusls.MasaGadget.ModInfo; +import com.plusls.MasaGadget.util.MiscUtil; +import fi.dy.masa.malilib.gui.GuiConfigsBase; +import fi.dy.masa.malilib.interfaces.IStringValue; +import lombok.Getter; +import net.fabricmc.loader.api.FabricLoader; +import net.fabricmc.loader.api.metadata.ModMetadata; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.Screen; +import org.jetbrains.annotations.ApiStatus; +import top.hendrixshen.magiclib.MagicLib; +import top.hendrixshen.magiclib.api.compat.modmenu.ModMenuApiCompat; +import top.hendrixshen.magiclib.util.ReflectionUtil; +import top.hendrixshen.magiclib.util.collect.ValueContainer; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Function; +import java.util.stream.Collectors; + +public class FastMasaGuiSwitcher { + @Getter(lazy = true) + private static final FastMasaGuiSwitcher instance = new FastMasaGuiSwitcher(); + + private final BiMap, IStringValue> guiModName = HashBiMap.create(); + private final Map, ModMenuApiCompat.ConfigScreenFactoryCompat> guiClass = Maps.newHashMap(); + + private final ValueContainer> modMenuApiClass; + private final ValueContainer getModConfigScreenFactoryMethod; + private final ValueContainer createMethod; + private final ValueContainer> legacyModMenuApiClass; + private final ValueContainer legacyGetModConfigScreenFactoryMethod; + private final ValueContainer legacyCreateMethod; + private final ValueContainer legacyGetConfigScreenFactory; + private final AtomicBoolean initialized = new AtomicBoolean(false); + + private FastMasaGuiSwitcher() { + this.modMenuApiClass = ReflectionUtil.getClass("com.terraformersmc.modmenu.api.ModMenuApi"); + this.getModConfigScreenFactoryMethod = ReflectionUtil.getMethod(this.modMenuApiClass, "getModConfigScreenFactory"); + this.createMethod = ReflectionUtil.getMethod("com.terraformersmc.modmenu.api.ConfigScreenFactory", "create", Screen.class); + this.legacyModMenuApiClass = ReflectionUtil.getClass("io.github.prospector.modmenu.api.ModMenuApi"); + this.legacyGetConfigScreenFactory = ReflectionUtil.getMethod(this.legacyModMenuApiClass, "getModConfigScreenFactory"); + this.legacyCreateMethod = ReflectionUtil.getMethod("io.github.prospector.modmenu.api.ConfigScreenFactory", "create", Screen.class); + this.legacyGetModConfigScreenFactoryMethod = ReflectionUtil.getMethod(this.legacyModMenuApiClass, "getConfigScreenFactory"); + } + + @ApiStatus.Internal + public void init() { + if (this.initialized.get()) { + throw new IllegalStateException("Re-trigger initialize."); + } + + if (!MagicLib.getInstance().getCurrentPlatform().isModLoaded(ModInfo.MODMENU_MOD_ID)) { + return; + } + + Minecraft client = Minecraft.getInstance(); + + // TODO: Platform api + FabricLoader.getInstance().getEntrypointContainers("modmenu", Object.class).forEach(entrypoint -> { + ModMetadata metadata = entrypoint.getProvider().getMetadata(); + try { + Object api = entrypoint.getEntrypoint(); + ModMenuApiCompat.ConfigScreenFactoryCompat configScreenFactoryCompat; + + if (this.modMenuApiClass.isPresent() && this.modMenuApiClass.get().isAssignableFrom(api.getClass()) && + this.getModConfigScreenFactoryMethod.isPresent() && this.createMethod.isPresent()) { + // >= 1.16 + Object modConfigScreenFactory = this.getModConfigScreenFactoryMethod.get().invoke(api); + + configScreenFactoryCompat = screen -> { + try { + return (Screen) this.createMethod.get().invoke(modConfigScreenFactory, screen); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException(e); + } + }; + } else if (this.legacyModMenuApiClass.isPresent() && this.legacyModMenuApiClass.get().isAssignableFrom(api.getClass())) { + if (this.legacyGetModConfigScreenFactoryMethod.isPresent()) { + // 1.15 and 1.16 legacy + Object legacyModConfigScreenFactory = this.legacyGetModConfigScreenFactoryMethod.get().invoke(api); + + configScreenFactoryCompat = screen -> { + try { + return (Screen) this.legacyCreateMethod.get().invoke(legacyModConfigScreenFactory, screen); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException(e); + } + }; + } else { + // 1.14 + Function f = MiscUtil.cast(this.legacyGetConfigScreenFactory.get().invoke(api)); + configScreenFactoryCompat = f::apply; + } + } else { + ModInfo.LOGGER.error("Mod {} provides a unknown type {} of ModMenuApi", metadata.getId(), api.getClass()); + return; + } + + Screen screen = configScreenFactoryCompat.create(client.screen); + + if (!(screen instanceof GuiConfigsBase)) { + return; + } + + String modName = metadata.getName(); + + if (!this.guiClass.containsKey(screen.getClass())) { + this.guiModName.put(configScreenFactoryCompat, () -> modName); + this.guiClass.put(screen.getClass(), configScreenFactoryCompat); + } else { + ModMenuApiCompat.ConfigScreenFactoryCompat savedConfigScreenFactoryCompat = this.guiClass.get(screen.getClass()); + String savedName = guiModName.get(savedConfigScreenFactoryCompat).getStringValue(); + + if (savedName.length() > modName.length()) { + this.guiModName.put(savedConfigScreenFactoryCompat, () -> modName); + } + } + } catch (Throwable e) { + ModInfo.LOGGER.error("Mod {} provides a broken implementation of ModMenuApi", metadata.getId(), e); + } + }); + + this.initialized.set(true); + } + + public List getModNameList() { + return this.guiModName.values() + .stream() + .sorted(Comparator.comparing(IStringValue::getStringValue)) + .collect(Collectors.toList()); + } + + public IStringValue getModName(Class clazz) { + return this.getModName(this.getConfigScreenFactory(clazz)); + } + + public IStringValue getModName(ModMenuApiCompat.ConfigScreenFactoryCompat configScreenFactory) { + return this.guiModName.get(configScreenFactory); + } + + public ModMenuApiCompat.ConfigScreenFactoryCompat getConfigScreenFactory(Class clazz) { + return this.guiClass.get(clazz); + } + + public ModMenuApiCompat.ConfigScreenFactoryCompat getConfigScreenFactory(IStringValue modName) { + return this.guiModName.inverse().get(modName); + } +} diff --git a/src/main/java/com/plusls/MasaGadget/impl/mod_tweak/malilib/favoritesSupport/MalilibFavoritesButton.java b/src/main/java/com/plusls/MasaGadget/impl/mod_tweak/malilib/favoritesSupport/MalilibFavoritesButton.java new file mode 100644 index 00000000..68ed3f21 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/impl/mod_tweak/malilib/favoritesSupport/MalilibFavoritesButton.java @@ -0,0 +1,69 @@ +package com.plusls.MasaGadget.impl.mod_tweak.malilib.favoritesSupport; + +import com.plusls.MasaGadget.impl.gui.MasaGadgetIcons; +import fi.dy.masa.malilib.gui.interfaces.IGuiIcon; +import fi.dy.masa.malilib.gui.widgets.WidgetHoverInfo; +import fi.dy.masa.malilib.render.RenderUtils; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Consumer; + +//#if MC > 11904 +import net.minecraft.client.gui.GuiGraphics; +//#elseif MC > 11502 +//$$ import com.mojang.blaze3d.vertex.PoseStack; +//#endif + +public class MalilibFavoritesButton extends WidgetHoverInfo { + private final TooltipSupplier tooltipSupplier; + private final Consumer onPress; + private final IGuiIcon icon; + private boolean status; + + private MalilibFavoritesButton(int x, int y, @NotNull IGuiIcon icon, boolean defaultStatus, + Consumer onPress, @NotNull TooltipSupplier tooltipSupplier, Object... args) { + super(x, y, icon.getWidth(), icon.getHeight(), tooltipSupplier.onTooltip(defaultStatus), args); + this.status = defaultStatus; + this.tooltipSupplier = tooltipSupplier; + this.onPress = onPress; + this.icon = icon; + } + + public static @NotNull MalilibFavoritesButton create(int x, int y, boolean defaultStatus, + Consumer onPress, TooltipSupplier tooltipSupplier) { + return new MalilibFavoritesButton(x, y, MasaGadgetIcons.FAVORITE, defaultStatus, onPress, tooltipSupplier); + } + + @Override + public void render( + int mouseX, + int mouseY, + boolean selected + //#if MC > 11904 + , GuiGraphics gui + //#elseif MC > 11502 + //$$ , PoseStack poseStack + //#endif + ) { + RenderUtils.color(1.0F, 1.0F, 1.0F, 1.0F); + this.bindTexture(icon.getTexture()); + icon.renderAt(this.x, this.y, (float) this.zLevel, this.status, this.isMouseOver(mouseX, mouseY)); + + if (this.isMouseOver(mouseX, mouseY)) { + RenderUtils.drawOutlinedBox(this.x, this.y, this.width, this.height, 0x20C0C0C0, -520093697); + } + } + + protected boolean onMouseClickedImpl(int mouseX, int mouseY, int mouseButton) { + this.status = !this.status; + this.getLines().clear(); + this.setInfoLines(this.tooltipSupplier.onTooltip(this.status)); + this.onPress.accept(this.status); + return true; + } + + @FunctionalInterface + public interface TooltipSupplier { + String onTooltip(boolean status); + } +} diff --git a/src/main/java/com/plusls/MasaGadget/impl/mod_tweak/malilib/favoritesSupport/MalilibFavoritesData.java b/src/main/java/com/plusls/MasaGadget/impl/mod_tweak/malilib/favoritesSupport/MalilibFavoritesData.java new file mode 100644 index 00000000..e47aae90 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/impl/mod_tweak/malilib/favoritesSupport/MalilibFavoritesData.java @@ -0,0 +1,57 @@ +package com.plusls.MasaGadget.impl.mod_tweak.malilib.favoritesSupport; + +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import fi.dy.masa.malilib.util.JsonUtils; +import lombok.Getter; +import lombok.Setter; +import org.jetbrains.annotations.NotNull; +import top.hendrixshen.magiclib.util.serializable.JsonSaveAble; + +import java.util.*; + +@Getter +@Setter +public class MalilibFavoritesData implements JsonSaveAble { + @Getter + private static final MalilibFavoritesData instance = new MalilibFavoritesData(); + + private final Map> favorites = Maps.newHashMap(); + private boolean filterSwitch; + + @Override + public void dumpToJson(@NotNull JsonObject jsonObject) { + jsonObject.addProperty("filter_switch", this.filterSwitch); + JsonObject dataObj = new JsonObject(); + + for (Map.Entry> entry : this.favorites.entrySet()) { + JsonArray modFavoriteObj = new JsonArray(); + + if (!entry.getValue().isEmpty()) { + for (String configName : entry.getValue()) { + modFavoriteObj.add(configName); + } + + dataObj.add(entry.getKey(), modFavoriteObj); + } + } + + jsonObject.add("data", dataObj); + } + + @Override + public void loadFromJson(@NotNull JsonObject jsonObject) { + this.filterSwitch = jsonObject.get("filter_switch").getAsBoolean(); + JsonObject dataObj = JsonUtils.getNestedObject(jsonObject, "data", false); + this.favorites.clear(); + + for (Map.Entry entry : Objects.requireNonNull(dataObj).entrySet()) { + Set modFavoriteObj = Sets.newHashSet(); + entry.getValue().getAsJsonArray().forEach(e -> modFavoriteObj.add(e.getAsString())); + this.favorites.put(entry.getKey(), modFavoriteObj); + } + } +} 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 new file mode 100644 index 00000000..889754e6 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/impl/mod_tweak/tweakeroo/inventoryPreviewSupportComparator/ComparatorInfo.java @@ -0,0 +1,57 @@ +package com.plusls.MasaGadget.impl.mod_tweak.tweakeroo.inventoryPreviewSupportComparator; + +import com.plusls.MasaGadget.ModInfo; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.impl.feature.entityInfo.EntityInfoRenderer; +import com.plusls.MasaGadget.impl.generic.HitResultHandler; +import fi.dy.masa.tweakeroo.config.FeatureToggle; +import fi.dy.masa.tweakeroo.config.Hotkeys; +import lombok.Getter; +import net.minecraft.ChatFormatting; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.ComparatorBlockEntity; +import org.jetbrains.annotations.ApiStatus; +import top.hendrixshen.magiclib.MagicLib; +import top.hendrixshen.magiclib.api.event.minecraft.render.RenderLevelListener; +import top.hendrixshen.magiclib.api.render.context.RenderContext; +import top.hendrixshen.magiclib.impl.render.TextRenderer; +import top.hendrixshen.magiclib.util.collect.ValueContainer; +import top.hendrixshen.magiclib.util.minecraft.ComponentUtil; + +public class ComparatorInfo implements RenderLevelListener { + @Getter + private static final EntityInfoRenderer instance = new EntityInfoRenderer(); + + @ApiStatus.Internal + public void init() { + MagicLib.getInstance().getEventManager().register(RenderLevelListener.class, this); + } + + @Override + public void preRenderLevel(Level entity, RenderContext renderContext, float partialTicks) { + // NO-OP + } + + @Override + public void postRenderLevel(Level entity, RenderContext renderContext, float partialTicks) { + if ( + !MagicLib.getInstance().getCurrentPlatform().isModLoaded(ModInfo.TWEAKEROO_MOD_ID) || + !FeatureToggle.TWEAK_INVENTORY_PREVIEW.getBooleanValue() || + !Hotkeys.INVENTORY_PREVIEW.getKeybind().isKeybindHeld() || + !Configs.inventoryPreviewSupportComparator.getBooleanValue()) { + return; + } + + ValueContainer pos = HitResultHandler.getInstance().getHitBlockPos(); + Object blockEntity = HitResultHandler.getInstance().getLastHitBlockEntity().orElse(null); + + if (pos.isPresent() && blockEntity instanceof ComparatorBlockEntity) { + TextRenderer.create() + .text(ComponentUtil.simple(((ComparatorBlockEntity) blockEntity).getOutputSignal()) + .withStyle(ChatFormatting.GREEN).get()) + .atCenter(pos.get()) + .seeThrough(); + } + } +} diff --git a/src/main/java/com/plusls/MasaGadget/impl/mod_tweak/tweakeroo/inventoryPreviewSupportSelect/InventoryOverlayRenderHandler.java b/src/main/java/com/plusls/MasaGadget/impl/mod_tweak/tweakeroo/inventoryPreviewSupportSelect/InventoryOverlayRenderHandler.java new file mode 100644 index 00000000..931d78f3 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/impl/mod_tweak/tweakeroo/inventoryPreviewSupportSelect/InventoryOverlayRenderHandler.java @@ -0,0 +1,410 @@ +package com.plusls.MasaGadget.impl.mod_tweak.tweakeroo.inventoryPreviewSupportSelect; + +import com.plusls.MasaGadget.game.Configs; +import fi.dy.masa.malilib.render.RenderUtils; +import fi.dy.masa.malilib.util.GuiUtils; +import fi.dy.masa.tweakeroo.config.FeatureToggle; +import lombok.Getter; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.ShulkerBoxBlock; +import net.minecraft.world.phys.HitResult; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import top.hendrixshen.magiclib.api.render.context.RenderContext; + +//#if MC < 12000 +//$$ import com.plusls.MasaGadget.mixin.accessor.AccessorGuiComponent; +//$$ import net.minecraft.network.chat.Component; +//$$ import net.minecraft.world.item.TooltipFlag; +//$$ import top.hendrixshen.magiclib.api.compat.minecraft.client.gui.FontCompat; +//$$ import top.hendrixshen.magiclib.impl.render.context.RenderGlobal; +//$$ import java.util.List; +//#endif + +//#if MC > 11904 +import net.minecraft.client.gui.GuiGraphics; +//#endif + +//#if MC < 11700 +//$$ import org.lwjgl.opengl.GL11; +//#endif + +//#if MC > 11404 +//$$ import com.mojang.blaze3d.vertex.PoseStack; +//$$ import com.mojang.blaze3d.vertex.Tesselator; +//$$ import com.mojang.blaze3d.systems.RenderSystem; +//$$ import net.minecraft.client.renderer.MultiBufferSource; +//#endif + +public class InventoryOverlayRenderHandler { + @Getter(lazy = true) + private static final InventoryOverlayRenderHandler instance = new InventoryOverlayRenderHandler(); + private static final int UN_SELECTED = 114514; + + private int selectedIdx = InventoryOverlayRenderHandler.UN_SELECTED; + private int currentIdx = -1; + private int renderX = -1; + private int renderY = -1; + private ItemStack itemStack = null; + // 支持显示盒子在箱子里 + private boolean selectInventory = false; + private boolean renderingSubInventory = false; + private int subSelectedIdx = UN_SELECTED; + private int subCurrentIdx = -1; + private int subRenderX = -1; + private int subRenderY = -1; + private ItemStack subItemStack = null; + + public static void onHitCallback(@Nullable HitResult hitResult, boolean oldStatus, boolean stateChanged) { + if (!FeatureToggle.TWEAK_INVENTORY_PREVIEW.getBooleanValue() || + !Configs.inventoryPreviewSupportSelect.getBooleanValue()) { + return; + } + + if (!oldStatus) { + // Reset preview selection slot. + InventoryOverlayRenderHandler.getInstance().resetSelectedIdx(); + } + } + + public void render(@NotNull RenderContext renderContext) { + //#if MC > 11904 + GuiGraphics gui = renderContext.getGuiComponent(); + //#elseif MC > 11502 + //#endif + + //#if MC > 11605 && MC < 12000 + //$$ RenderSystem.applyModelViewMatrix(); + //#endif + + if (this.currentIdx == 0) { + return; + } + + if (this.selectedIdx != InventoryOverlayRenderHandler.UN_SELECTED) { + if (this.selectedIdx >= this.currentIdx) { + this.selectedIdx %= this.currentIdx; + } else if (this.selectedIdx < 0) { + while (this.selectedIdx < 0) { + this.selectedIdx += this.currentIdx; + } + } else if (this.itemStack != null) { + if (this.selectInventory) { + if (this.itemStack.getItem() instanceof BlockItem && + ((BlockItem) this.itemStack.getItem()).getBlock() instanceof ShulkerBoxBlock) { + this.renderSelectedRect(renderContext, this.renderX, this.renderY); + // 盒子预览 + this.renderingSubInventory = true; + RenderUtils.renderShulkerBoxPreview(this.itemStack, + GuiUtils.getScaledWindowWidth() / 2 - 96, + GuiUtils.getScaledWindowHeight() / 2 + 30, + true + //#if MC > 11904 + , gui + //#endif + ); + this.renderingSubInventory = false; + + if (this.subSelectedIdx != InventoryOverlayRenderHandler.UN_SELECTED) { + if (this.subCurrentIdx != 0) { + if (this.subSelectedIdx >= this.subCurrentIdx) { + this.subSelectedIdx %= this.subCurrentIdx; + } else if (this.subSelectedIdx < 0) { + while (this.subSelectedIdx < 0) { + this.subSelectedIdx += this.subCurrentIdx; + } + } else if (this.subItemStack != null) { + this.renderSelectedRect(renderContext, this.renderX, this.renderY); + } + } + } + } else { + // 激活预览但是被预览的物品不是盒子 + this.switchSelectInventory(); + } + } + + if (!this.selectInventory) { + this.renderSelectedRect(renderContext, this.renderX, this.renderY); + this.renderTooltip(renderContext, this.itemStack, this.renderX, this.renderY); + } + } + } + + this.currentIdx = 0; + this.itemStack = null; + this.renderX = -1; + this.renderY = -1; + this.subCurrentIdx = 0; + this.subItemStack = null; + this.subRenderX = -1; + this.subRenderY = -1; + } + + // for 1.14 + public void updateState(int x, int y, ItemStack stack) { + if (this.renderingSubInventory) { + if (this.subCurrentIdx++ == this.subSelectedIdx) { + this.subRenderX = x; + this.subRenderY = y; + this.subItemStack = stack; + } + } else { + if (this.currentIdx++ == this.selectedIdx) { + this.renderX = x; + this.renderY = y; + this.itemStack = stack; + } + } + } + + public void switchSelectInventory() { + this.selectInventory = !this.selectInventory; + this.subSelectedIdx = InventoryOverlayRenderHandler.UN_SELECTED; + } + + public void resetSelectedIdx() { + this.selectedIdx = InventoryOverlayRenderHandler.UN_SELECTED; + + if (this.selectInventory) { + this.switchSelectInventory(); + } + } + + public void addSelectedIdx(int n) { + if (this.selectInventory) { + if (this.subSelectedIdx == InventoryOverlayRenderHandler.UN_SELECTED) { + this.subSelectedIdx = 0; + } else { + this.subSelectedIdx += n; + } + } else { + if (this.selectedIdx == InventoryOverlayRenderHandler.UN_SELECTED) { + this.selectedIdx = 0; + } else { + this.selectedIdx += n; + } + } + } + + public void renderSelectedRect(RenderContext renderContext, int x, int y) { + //#if MC > 11605 + AbstractContainerScreen.renderSlotHighlight( + //#if MC > 11904 + renderContext.getGuiComponent(), + //#else + //$$ renderContext.getPoseStack(), + //#endif + x, + y, + 400 + ); + //#else + //$$ RenderGlobal.disableLighting(); + //$$ RenderGlobal.disableDepthTest(); + //$$ RenderGlobal.colorMask(true, true, true, false); + //$$ renderContext.pushPose(); + //$$ renderContext.translate(x, y, 1); + //$$ ((AccessorGuiComponent) renderContext.getGuiComponent()).masa_gadget_mod$fillGradient( + //#if MC > 11502 + //$$ renderContext.getPoseStack(), + //#endif + //$$ x, + //$$ y, + //$$ x + 16, + //$$ y + 16, + //$$ 0x80FFFFFF, + //$$ 0x80FFFFFF + //$$ ); + //$$ renderContext.popPose(); + //$$ RenderGlobal.colorMask(true, true, true, true); + //$$ RenderGlobal.enableLighting(); + //$$ RenderGlobal.enableDepthTest(); + //#endif + } + + private void renderTooltip(RenderContext renderContext, ItemStack itemStack, int x, int y) { + //#if MC > 11904 + renderContext.getGuiComponent().renderTooltip(Minecraft.getInstance().font, itemStack, x, y); + //#else + //$$ Minecraft mc = Minecraft.getInstance(); + //$$ List tooltipLines = itemStack.getTooltipLines(mc.player, mc.options.advancedItemTooltips ? + //$$ TooltipFlag.Default.ADVANCED : TooltipFlag.Default.NORMAL); + //$$ + //$$ if (tooltipLines.isEmpty()) { + //$$ return; + //$$ } + //$$ + //$$ int xOffset = 0; + //$$ int yOffset = tooltipLines.size() == 1 ? -2 : 0; + //$$ + //$$ for (Component line : tooltipLines) { + //$$ int lineWidth = FontCompat.of(Minecraft.getInstance().font).width(line); + //$$ + //$$ if (lineWidth > xOffset) { + //$$ xOffset = lineWidth; + //$$ } + //$$ + //$$ yOffset += 10; + //$$ } + //$$ + //$$ int renderX = x + 12; + //$$ int renderY = y - 12; + //$$ + //$$ if (renderX + xOffset > GuiUtils.getScaledWindowWidth()) { + //$$ renderX -= 28 + xOffset; + //$$ } + //$$ + //$$ if (renderY + yOffset + 6 > GuiUtils.getScaledWindowHeight()) { + //$$ renderY = GuiUtils.getScaledWindowHeight() - yOffset - 6; + //$$ } + //$$ + //$$ renderContext.pushPose(); + //$$ renderContext.translate(0, 0, 1); + //$$ + //#if MC < 11904 + //$$ float backupBlitOffset = mc.getItemRenderer().blitOffset; + //$$ mc.getItemRenderer().blitOffset = 400.0F; + //$$ RenderGlobal.disableTexture(); + //#endif + //$$ + //$$ RenderGlobal.enableBlend(); + //$$ RenderGlobal.defaultBlendFunc(); + //$$ + //$$ AccessorGuiComponent guiComponent = (AccessorGuiComponent) renderContext.getGuiComponent(); + //$$ guiComponent.masa_gadget_mod$fillGradient( + //#if MC > 11502 + //$$ renderContext.getPoseStack(), + //#endif + //$$ renderX - 3, + //$$ renderY - 4, + //$$ renderX + xOffset + 3, + //$$ renderY - 3, 0xF0100010, + //$$ 0xF0100010 + //$$ ); + //$$ guiComponent.masa_gadget_mod$fillGradient( + //#if MC > 11502 + //$$ renderContext.getPoseStack(), + //#endif + //$$ renderX - 3, + //$$ renderY + yOffset + 3, + //$$ renderX + xOffset + 3, + //$$ renderY + yOffset + 4, + //$$ 0xF0100010, + //$$ 0xF0100010 + //$$ ); + //$$ guiComponent.masa_gadget_mod$fillGradient( + //#if MC > 11502 + //$$ renderContext.getPoseStack(), + //#endif + //$$ renderX - 3, + //$$ renderY - 3, + //$$ renderX + xOffset + 3, + //$$ renderY + yOffset + 3, + //$$ 0xF0100010, + //$$ 0xF0100010 + //$$ ); + //$$ guiComponent.masa_gadget_mod$fillGradient( + //#if MC > 11502 + //$$ renderContext.getPoseStack(), + //#endif + //$$ renderX - 4, + //$$ renderY - 3, + //$$ renderX - xOffset, + //$$ renderY + yOffset + 3, + //$$ 0xF0100010, + //$$ 0xF0100010 + //$$ ); + //$$ guiComponent.masa_gadget_mod$fillGradient( + //#if MC > 11502 + //$$ renderContext.getPoseStack(), + //#endif + //$$ renderX + xOffset + 3, + //$$ renderY - 3, + //$$ renderX + xOffset + 4, + //$$ renderY + yOffset + 3, + //$$ 0xF0100010, + //$$ 0xF0100010 + //$$ ); + //$$ guiComponent.masa_gadget_mod$fillGradient( + //#if MC > 11502 + //$$ renderContext.getPoseStack(), + //#endif + //$$ renderX - 3, + //$$ renderY - 3 + 1, + //$$ renderX - 3 + 1, + //$$ renderY + yOffset + 3 - 1, + //$$ 0x505000FF, + //$$ 0x5028007F + //$$ ); + //$$ guiComponent.masa_gadget_mod$fillGradient( + //#if MC > 11502 + //$$ renderContext.getPoseStack(), + //#endif + //$$ renderX + xOffset + 2, + //$$ renderY - 3 + 1, + //$$ renderX + xOffset + 3, + //$$ renderY + yOffset + 3 - 1, + //$$ 0x505000FF, + //$$ 0x5028007F + //$$ ); + //$$ guiComponent.masa_gadget_mod$fillGradient( + //#if MC > 11502 + //$$ renderContext.getPoseStack(), + //#endif + //$$ renderX - 3, + //$$ renderY - 3, + //$$ renderX + xOffset + 3, + //$$ renderY - 3 + 1, + //$$ 0x505000FF, + //$$ 0x505000FF + //$$ ); + //$$ guiComponent.masa_gadget_mod$fillGradient( + //#if MC > 11502 + //$$ renderContext.getPoseStack(), + //#endif + //$$ renderX - 3, + //$$ renderY + yOffset + 2, + //$$ renderX + xOffset + 3, + //$$ renderY + yOffset + 3, + //$$ 0x5028007F, + //$$ 0x5028007F + //$$ ); + //$$ RenderGlobal.disableBlend(); + //$$ + //#if MC < 11904 + //$$ RenderGlobal.enableTexture(); + //#endif + //$$ + //$$ renderContext.translate(0, 0, 1); + //$$ FontCompat fontCompat = FontCompat.of(mc.font); + //$$ + //$$ for (int i = 0; i < tooltipLines.size(); i++) { + //$$ fontCompat.drawInBatch( + //$$ tooltipLines.get(i), + //$$ renderX, + //$$ renderY, + //$$ 0xFFFFFFFF, + //$$ true, + //#if MC > 11404 + //$$ new PoseStack().last().pose(), + //$$ MultiBufferSource.immediate(Tesselator.getInstance().getBuilder()), + //#endif + //$$ FontCompat.DisplayMode.NORMAL, + //$$ 0, + //$$ 0xF000F0 + //$$ ); + //$$ renderY += 10 + ((i == 0) ? 2 : 0); + //$$ } + //$$ + //$$ renderContext.popPose(); + //#if MC < 11904 + //$$ mc.getItemRenderer().blitOffset = backupBlitOffset; + //#endif + //$$ RenderGlobal.enableDepthTest(); + //#endif + } +} diff --git a/src/main/java/com/plusls/MasaGadget/impl/mod_tweak/tweakeroo/inventoryPreviewSupportSelect/MouseScrollInputHandler.java b/src/main/java/com/plusls/MasaGadget/impl/mod_tweak/tweakeroo/inventoryPreviewSupportSelect/MouseScrollInputHandler.java new file mode 100644 index 00000000..5b6b975d --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/impl/mod_tweak/tweakeroo/inventoryPreviewSupportSelect/MouseScrollInputHandler.java @@ -0,0 +1,76 @@ +package com.plusls.MasaGadget.impl.mod_tweak.tweakeroo.inventoryPreviewSupportSelect; + +import com.plusls.MasaGadget.ModInfo; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.impl.generic.HitResultHandler; +import fi.dy.masa.malilib.event.InputEventHandler; +import fi.dy.masa.malilib.hotkeys.IMouseInputHandler; +import fi.dy.masa.tweakeroo.config.FeatureToggle; +import fi.dy.masa.tweakeroo.config.Hotkeys; +import lombok.Getter; +import net.minecraft.client.Minecraft; +import net.minecraft.world.entity.player.Player; +import org.jetbrains.annotations.ApiStatus; +import top.hendrixshen.magiclib.MagicLib; + +//#if MC >= 11903 +import net.minecraft.core.registries.BuiltInRegistries; +//#else +//$$ import net.minecraft.core.Registry; +//#endif + +public class MouseScrollInputHandler implements IMouseInputHandler { + @Getter + private static final MouseScrollInputHandler instance = new MouseScrollInputHandler(); + + @ApiStatus.Internal + public void init() { + MouseScrollInputHandler handler = new MouseScrollInputHandler(); + InputEventHandler.getInputManager().registerMouseInputHandler(handler); + } + + @Override + public boolean onMouseScroll(int mouseX, int mouseY, double amount) { + Player player = Minecraft.getInstance().player; + + if (MagicLib.getInstance().getCurrentPlatform().isModLoaded(ModInfo.TWEAKEROO_MOD_ID) && + Configs.inventoryPreviewSupportSelect.getBooleanValue() && + FeatureToggle.TWEAK_INVENTORY_PREVIEW.getBooleanValue() && + HitResultHandler.getInstance().getLastInventoryPreviewStatus()) { + if (amount < 0) { + InventoryOverlayRenderHandler.getInstance().addSelectedIdx(1); + } else if (amount > 0) { + InventoryOverlayRenderHandler.getInstance().addSelectedIdx(-1); + } + + if (MagicLib.getInstance().getCurrentPlatform().isModLoaded(ModInfo.LITEMATICA_MOD_ID) && + fi.dy.masa.litematica.config.Configs.Generic.TOOL_ITEM_ENABLED.getBooleanValue() && + player != null && + //#if MC > 11902 + BuiltInRegistries.ITEM.getKey(player.getMainHandItem().getItem()).toString().contains(fi.dy.masa.litematica.config.Configs.Generic.TOOL_ITEM.getStringValue())) { + //#else + //$$ Registry.ITEM.getKey(player.getMainHandItem().getItem()).toString().contains(fi.dy.masa.litematica.config.Configs.Generic.TOOL_ITEM.getStringValue())) { + //#endif + return false; + } + + return true; + } + + return false; + } + + @Override + public boolean onMouseClick(int mouseX, int mouseY, int eventButton, boolean eventButtonState) { + if (MagicLib.getInstance().getCurrentPlatform().isModLoaded(ModInfo.TWEAKEROO_MOD_ID) && + Configs.inventoryPreviewSupportSelect.getBooleanValue() && + FeatureToggle.TWEAK_INVENTORY_PREVIEW.getBooleanValue() && + Hotkeys.INVENTORY_PREVIEW.getKeybind().isKeybindHeld() && + eventButton == 2 && + eventButtonState) { + InventoryOverlayRenderHandler.getInstance().switchSelectInventory(); + } + + return false; + } +} diff --git a/src/main/java/com/plusls/MasaGadget/impl/network/NoopCodec.java b/src/main/java/com/plusls/MasaGadget/impl/network/NoopCodec.java new file mode 100644 index 00000000..42ea35e9 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/impl/network/NoopCodec.java @@ -0,0 +1,4 @@ +package com.plusls.MasaGadget.impl.network; + +public class NoopCodec { +} diff --git a/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundDisablePcaSyncProtocolPacket.java b/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundDisablePcaSyncProtocolPacket.java new file mode 100644 index 00000000..9191e29b --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundDisablePcaSyncProtocolPacket.java @@ -0,0 +1,4 @@ +package com.plusls.MasaGadget.impl.network.packet; + +public class ClientboundDisablePcaSyncProtocolPacket { +} diff --git a/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundEnablePcaSyncProtocolPacket.java b/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundEnablePcaSyncProtocolPacket.java new file mode 100644 index 00000000..626d0d00 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundEnablePcaSyncProtocolPacket.java @@ -0,0 +1,4 @@ +package com.plusls.MasaGadget.impl.network.packet; + +public class ClientboundEnablePcaSyncProtocolPacket { +} diff --git a/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundUpdateBlockEntityPacket.java b/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundUpdateBlockEntityPacket.java new file mode 100644 index 00000000..afbf126a --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundUpdateBlockEntityPacket.java @@ -0,0 +1,4 @@ +package com.plusls.MasaGadget.impl.network.packet; + +public class ClientboundUpdateBlockEntityPacket { +} diff --git a/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundUpdateEntityPacket.java b/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundUpdateEntityPacket.java new file mode 100644 index 00000000..51d65a98 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundUpdateEntityPacket.java @@ -0,0 +1,4 @@ +package com.plusls.MasaGadget.impl.network.packet; + +public class ClientboundUpdateEntityPacket { +} diff --git a/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundCancelSyncBlockEntityPacket.java b/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundCancelSyncBlockEntityPacket.java new file mode 100644 index 00000000..dba2eeaf --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundCancelSyncBlockEntityPacket.java @@ -0,0 +1,4 @@ +package com.plusls.MasaGadget.impl.network.packet; + +public class ServerboundCancelSyncBlockEntityPacket { +} diff --git a/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundCancelSyncEntityPacket.java b/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundCancelSyncEntityPacket.java new file mode 100644 index 00000000..ef563e84 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundCancelSyncEntityPacket.java @@ -0,0 +1,4 @@ +package com.plusls.MasaGadget.impl.network.packet; + +public class ServerboundCancelSyncEntityPacket { +} diff --git a/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundSyncBlockEntityPacket.java b/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundSyncBlockEntityPacket.java new file mode 100644 index 00000000..cc8629b8 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundSyncBlockEntityPacket.java @@ -0,0 +1,4 @@ +package com.plusls.MasaGadget.impl.network.packet; + +public class ServerboundSyncBlockEntityPacket { +} diff --git a/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundSyncEntityPacket.java b/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundSyncEntityPacket.java new file mode 100644 index 00000000..2a6fa010 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundSyncEntityPacket.java @@ -0,0 +1,4 @@ +package com.plusls.MasaGadget.impl.network.packet; + +public class ServerboundSyncEntityPacket { +} diff --git a/src/main/java/com/plusls/MasaGadget/malilib/fastSwitchMasaConfigGui/MasaGuiUtil.java b/src/main/java/com/plusls/MasaGadget/malilib/fastSwitchMasaConfigGui/MasaGuiUtil.java deleted file mode 100644 index df7be838..00000000 --- a/src/main/java/com/plusls/MasaGadget/malilib/fastSwitchMasaConfigGui/MasaGuiUtil.java +++ /dev/null @@ -1,149 +0,0 @@ -package com.plusls.MasaGadget.malilib.fastSwitchMasaConfigGui; - -import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.util.MiscUtil; -import fi.dy.masa.malilib.gui.GuiConfigsBase; -import net.fabricmc.loader.api.FabricLoader; -import net.fabricmc.loader.api.metadata.ModMetadata; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screens.Screen; -import org.jetbrains.annotations.Nullable; -import top.hendrixshen.magiclib.compat.modmenu.ModMenuCompatApi; -import top.hendrixshen.magiclib.util.FabricUtil; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.function.Function; - -public class MasaGuiUtil { - public final static Map, String> masaGuiData = new HashMap<>(); - public final static ArrayList> masaGuiConfigScreenFactorys = new ArrayList<>(); - public final static Map, ModMenuCompatApi.ConfigScreenFactoryCompat> masaGuiClassData = new HashMap<>(); - - @Nullable - private static final Class modMenuApiClass; - private static final Method getModConfigScreenFactoryMethod; - private static final Method createMethod; - @Nullable - private static final Class legacyModMenuApiClass; - private static final Method legacyGetModConfigScreenFactoryMethod; - private static final Method legacyCreateMethod; - private static final Method legacyGetConfigScreenFactory; - private static boolean initialized = false; - - static { - Class tmpModMenuApiClass; - Method tmpGetModConfigScreenFactoryMethod; - Method tmpGetConfigScreenFactory; - - Method tmpCreateMethod; - - try { - tmpModMenuApiClass = Class.forName("com.terraformersmc.modmenu.api.ModMenuApi"); - tmpGetModConfigScreenFactoryMethod = tmpModMenuApiClass.getMethod("getModConfigScreenFactory"); - Class configScreenFactoryClass = Class.forName("com.terraformersmc.modmenu.api.ConfigScreenFactory"); - tmpCreateMethod = configScreenFactoryClass.getMethod("create", Screen.class); - } catch (ClassNotFoundException | NoSuchMethodException e) { - tmpModMenuApiClass = null; - tmpGetModConfigScreenFactoryMethod = null; - tmpCreateMethod = null; - } - modMenuApiClass = tmpModMenuApiClass; - getModConfigScreenFactoryMethod = tmpGetModConfigScreenFactoryMethod; - createMethod = tmpCreateMethod; - - try { - tmpModMenuApiClass = Class.forName("io.github.prospector.modmenu.api.ModMenuApi"); - try { - tmpGetModConfigScreenFactoryMethod = tmpModMenuApiClass.getMethod("getModConfigScreenFactory"); - Class legacyConfigScreenFactoryClass = Class.forName("io.github.prospector.modmenu.api.ConfigScreenFactory"); - tmpCreateMethod = legacyConfigScreenFactoryClass.getMethod("create", Screen.class); - tmpGetConfigScreenFactory = null; - } catch (NoSuchMethodException e) { - tmpGetConfigScreenFactory = tmpModMenuApiClass.getMethod("getConfigScreenFactory"); - tmpGetModConfigScreenFactoryMethod = null; - tmpCreateMethod = null; - } - } catch (ClassNotFoundException | NoSuchMethodException e) { - tmpModMenuApiClass = null; - tmpGetModConfigScreenFactoryMethod = null; - tmpCreateMethod = null; - tmpGetConfigScreenFactory = null; - } - legacyModMenuApiClass = tmpModMenuApiClass; - legacyGetModConfigScreenFactoryMethod = tmpGetModConfigScreenFactoryMethod; - legacyCreateMethod = tmpCreateMethod; - legacyGetConfigScreenFactory = tmpGetConfigScreenFactory; - } - - public static void initMasaModScreenList() { - if (initialized) { - return; - } - initialized = true; - Minecraft client = Minecraft.getInstance(); - if (!FabricUtil.isModLoaded(ModInfo.MODMENU_MOD_ID)) { - return; - } - FabricLoader.getInstance().getEntrypointContainers("modmenu", Object.class).forEach(entrypoint -> { - ModMetadata metadata = entrypoint.getProvider().getMetadata(); - try { - Object api = entrypoint.getEntrypoint(); - ModMenuCompatApi.ConfigScreenFactoryCompat configScreenFactoryCompat; - if (modMenuApiClass != null && modMenuApiClass.isAssignableFrom(api.getClass())) { - // >= 1.16 - Object modConfigScreenFactory = getModConfigScreenFactoryMethod.invoke(api); - configScreenFactoryCompat = screen -> { - try { - return (Screen) createMethod.invoke(modConfigScreenFactory, screen); - } catch (IllegalAccessException | InvocationTargetException e) { - throw new RuntimeException(e); - } - }; - - } else if (legacyModMenuApiClass != null && legacyModMenuApiClass.isAssignableFrom(api.getClass())) { - if (legacyGetModConfigScreenFactoryMethod != null) { - // 1.15 and 1.16 legacy - Object legacyModConfigScreenFactory = legacyGetModConfigScreenFactoryMethod.invoke(api); - configScreenFactoryCompat = screen -> { - try { - return (Screen) legacyCreateMethod.invoke(legacyModConfigScreenFactory, screen); - } catch (IllegalAccessException | InvocationTargetException e) { - throw new RuntimeException(e); - } - }; - } else { - // 1.14 - Function f = MiscUtil.cast(legacyGetConfigScreenFactory.invoke(api)); - configScreenFactoryCompat = f::apply; - } - - } else { - ModInfo.LOGGER.error("Mod {} provides a unknow type {} of ModMenuApi", metadata.getId(), api.getClass()); - return; - } - Screen screen = configScreenFactoryCompat.create(client.screen); - if (screen instanceof GuiConfigsBase) { - String modName = metadata.getName(); - if (!masaGuiClassData.containsKey(screen.getClass())) { - masaGuiData.put(configScreenFactoryCompat, modName); - masaGuiConfigScreenFactorys.add(configScreenFactoryCompat); - masaGuiClassData.put(screen.getClass(), configScreenFactoryCompat); - } else { - ModMenuCompatApi.ConfigScreenFactoryCompat savedConfigScreenFactoryCompat = masaGuiClassData.get(screen.getClass()); - String savedName = masaGuiData.get(savedConfigScreenFactoryCompat); - if (savedName.length() > modName.length()) { - masaGuiData.put(savedConfigScreenFactoryCompat, modName); - } - } - - } - } catch (Throwable e) { - ModInfo.LOGGER.error("Mod {} provides a broken implementation of ModMenuApi", metadata.getId(), e); - } - }); - } -} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/MixinConnection.java b/src/main/java/com/plusls/MasaGadget/mixin/MixinConnection.java index 22b08a86..1ca047e3 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/MixinConnection.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/MixinConnection.java @@ -12,20 +12,24 @@ @Mixin(Connection.class) public abstract class MixinConnection { @Shadow - private static void genericsFtw(Packet packet, PacketListener packetListener) { - } - + private native static void genericsFtw(Packet packet, PacketListener packetListener); - @Redirect(method = "channelRead0*", at = @At(value = "INVOKE", - target = "Lnet/minecraft/network/Connection;genericsFtw(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketListener;)V" - , ordinal = 0)) + @Redirect( + method = "channelRead0*", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/network/Connection;genericsFtw(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketListener;)V", + ordinal = 0 + ) + ) private void redirectGenericsFtw(Packet packet, PacketListener packetListener) { try { - genericsFtw(packet, packetListener); + MixinConnection.genericsFtw(packet, packetListener); } catch (Throwable e) { if (!(e instanceof RunningOnDifferentThreadException)) { e.printStackTrace(); } + throw e; } } diff --git a/src/main/java/com/plusls/MasaGadget/mixin/accessor/AccessorGuiComponent.java b/src/main/java/com/plusls/MasaGadget/mixin/accessor/AccessorGuiComponent.java new file mode 100644 index 00000000..e993ac2b --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/mixin/accessor/AccessorGuiComponent.java @@ -0,0 +1,8 @@ +package com.plusls.MasaGadget.mixin.accessor; + +import org.spongepowered.asm.mixin.Mixin; +import top.hendrixshen.magiclib.api.preprocess.DummyClass; + +@Mixin(DummyClass.class) +public interface AccessorGuiComponent { +} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/event/disconnect/MixinMinecraftClient.java b/src/main/java/com/plusls/MasaGadget/mixin/event/disconnect/MixinMinecraftClient.java index 069d963b..39d467ca 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/event/disconnect/MixinMinecraftClient.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/event/disconnect/MixinMinecraftClient.java @@ -1,19 +1,24 @@ package com.plusls.MasaGadget.mixin.event.disconnect; -import com.plusls.MasaGadget.event.DisconnectEvent; +import com.plusls.MasaGadget.impl.event.DisconnectEvent; import net.minecraft.client.Minecraft; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import top.hendrixshen.magiclib.impl.event.EventManager; @Mixin(Minecraft.class) public abstract class MixinMinecraftClient { - // TODO 去掉该部分 - @Inject(method = "disconnect(Lnet/minecraft/client/gui/screens/Screen;)V", at = @At(value = "HEAD")) + @Inject( + method = "disconnect(Lnet/minecraft/client/gui/screens/Screen;)V", + at = @At( + value = "HEAD" + ) + ) private void onDisconnect(CallbackInfo ci) { if (!Minecraft.getInstance().hasSingleplayerServer()) { - DisconnectEvent.onDisconnect(); + EventManager.dispatch(new DisconnectEvent()); } } } diff --git a/src/main/java/com/plusls/MasaGadget/mixin/generic/autoSyncEntityData/MixinClientPlayNetworkHandler.java b/src/main/java/com/plusls/MasaGadget/mixin/feature/autoSyncEntityData/MixinClientPlayNetworkHandler.java similarity index 94% rename from src/main/java/com/plusls/MasaGadget/mixin/generic/autoSyncEntityData/MixinClientPlayNetworkHandler.java rename to src/main/java/com/plusls/MasaGadget/mixin/feature/autoSyncEntityData/MixinClientPlayNetworkHandler.java index cfd9c983..0e276d6a 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/generic/autoSyncEntityData/MixinClientPlayNetworkHandler.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/feature/autoSyncEntityData/MixinClientPlayNetworkHandler.java @@ -1,7 +1,7 @@ -package com.plusls.MasaGadget.mixin.generic.autoSyncEntityData; +package com.plusls.MasaGadget.mixin.feature.autoSyncEntityData; import com.google.common.collect.ImmutableList; -import com.plusls.MasaGadget.config.Configs; +import com.plusls.MasaGadget.game.Configs; import com.plusls.MasaGadget.mixin.accessor.AccessorVillager; import com.plusls.MasaGadget.util.PcaSyncProtocol; import net.minecraft.client.Minecraft; @@ -40,7 +40,7 @@ public class MixinClientPlayNetworkHandler { @Inject(method = "handleSoundEvent", at = @At(value = "RETURN")) private void syncVillagerData(ClientboundSoundPacket packet, CallbackInfo ci) { - if (!Configs.autoSyncEntityData || + if (!Configs.autoSyncEntityData.getBooleanValue() || Minecraft.getInstance().hasSingleplayerServer() || !PcaSyncProtocol.enable) { return; diff --git a/src/main/java/com/plusls/MasaGadget/mixin/generic/autoSyncEntityData/MixinVillagerEntity.java b/src/main/java/com/plusls/MasaGadget/mixin/feature/autoSyncEntityData/MixinVillagerEntity.java similarity index 88% rename from src/main/java/com/plusls/MasaGadget/mixin/generic/autoSyncEntityData/MixinVillagerEntity.java rename to src/main/java/com/plusls/MasaGadget/mixin/feature/autoSyncEntityData/MixinVillagerEntity.java index 7bf32483..05a5590f 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/generic/autoSyncEntityData/MixinVillagerEntity.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/feature/autoSyncEntityData/MixinVillagerEntity.java @@ -1,6 +1,6 @@ -package com.plusls.MasaGadget.mixin.generic.autoSyncEntityData; +package com.plusls.MasaGadget.mixin.feature.autoSyncEntityData; -import com.plusls.MasaGadget.config.Configs; +import com.plusls.MasaGadget.game.Configs; import com.plusls.MasaGadget.util.PcaSyncProtocol; import net.minecraft.client.Minecraft; import net.minecraft.world.entity.npc.Villager; @@ -18,7 +18,7 @@ public abstract class MixinVillagerEntity { @SuppressWarnings("ConstantConditions") @Inject(method = "tick", at = @At(value = "RETURN")) private void syncVillagerData(CallbackInfo ci) { - if (!Configs.autoSyncEntityData || + if (!Configs.autoSyncEntityData.getBooleanValue() || Minecraft.getInstance().hasSingleplayerServer() || !PcaSyncProtocol.enable) { return; @@ -34,7 +34,7 @@ private void syncVillagerData(CallbackInfo ci) { @SuppressWarnings("ConstantConditions") @Inject(method = "handleEntityEvent", at = @At(value = "RETURN")) private void syncVillagerData(byte status, CallbackInfo ci) { - if (!Configs.autoSyncEntityData || + if (!Configs.autoSyncEntityData.getBooleanValue() || Minecraft.getInstance().hasSingleplayerServer() || !PcaSyncProtocol.enable) { return; diff --git a/src/main/java/com/plusls/MasaGadget/mixin/generic/autoSyncEntityData/MixinZombieVillagerEntity.java b/src/main/java/com/plusls/MasaGadget/mixin/feature/autoSyncEntityData/MixinZombieVillagerEntity.java similarity index 90% rename from src/main/java/com/plusls/MasaGadget/mixin/generic/autoSyncEntityData/MixinZombieVillagerEntity.java rename to src/main/java/com/plusls/MasaGadget/mixin/feature/autoSyncEntityData/MixinZombieVillagerEntity.java index f1a7ac51..e6e84c29 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/generic/autoSyncEntityData/MixinZombieVillagerEntity.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/feature/autoSyncEntityData/MixinZombieVillagerEntity.java @@ -1,6 +1,6 @@ -package com.plusls.MasaGadget.mixin.generic.autoSyncEntityData; +package com.plusls.MasaGadget.mixin.feature.autoSyncEntityData; -import com.plusls.MasaGadget.config.Configs; +import com.plusls.MasaGadget.game.Configs; import com.plusls.MasaGadget.util.PcaSyncProtocol; import net.minecraft.client.Minecraft; import net.minecraft.world.entity.EntityType; @@ -31,7 +31,7 @@ public MixinZombieVillagerEntity(EntityType entityType, Level @Inject(method = "handleEntityEvent", at = @At(value = "RETURN")) private void syncVillagerData(byte status, CallbackInfo ci) { - if (!Configs.autoSyncEntityData || + if (!Configs.autoSyncEntityData.getBooleanValue() || Minecraft.getInstance().hasSingleplayerServer() || !PcaSyncProtocol.enable) { return; @@ -55,7 +55,7 @@ private void syncConvertingData(CallbackInfo ci) { this.villagerConversionTime -= i; if (this.villagerConversionTime <= 0) { // 如果这里为负,应该是没有同步数据 - if (!Configs.autoSyncEntityData || + if (!Configs.autoSyncEntityData.getBooleanValue() || Minecraft.getInstance().hasSingleplayerServer() || !PcaSyncProtocol.enable) { return; diff --git a/src/main/java/com/plusls/MasaGadget/mixin/generic/cacheContainerMenu/MixinClientPacketListener.java b/src/main/java/com/plusls/MasaGadget/mixin/feature/cacheContainerMenu/MixinClientPacketListener.java similarity index 70% rename from src/main/java/com/plusls/MasaGadget/mixin/generic/cacheContainerMenu/MixinClientPacketListener.java rename to src/main/java/com/plusls/MasaGadget/mixin/feature/cacheContainerMenu/MixinClientPacketListener.java index 3a6ba847..2a7ef849 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/generic/cacheContainerMenu/MixinClientPacketListener.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/feature/cacheContainerMenu/MixinClientPacketListener.java @@ -1,7 +1,7 @@ -package com.plusls.MasaGadget.mixin.generic.cacheContainerMenu; +package com.plusls.MasaGadget.mixin.feature.cacheContainerMenu; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.generic.cacheContainerMenu.cacheContainerMenu.CacheContainerMenuHandler; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.impl.feature.cacheContainerMenu.CacheContainerMenuHandler; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen; import net.minecraft.client.multiplayer.ClientPacketListener; @@ -21,64 +21,85 @@ @Mixin(ClientPacketListener.class) public class MixinClientPacketListener { - - @Inject(method = "handleOpenScreen", at = @At(value = "RETURN")) + @Inject( + method = "handleOpenScreen", + at = @At( + value = "RETURN" + ) + ) private void postHandleOpenScreen(ClientboundOpenScreenPacket clientboundOpenScreenPacket, CallbackInfo ci) { Minecraft minecraft = Minecraft.getInstance(); - if (!Configs.cacheContainerMenu || minecraft.hasSingleplayerServer()) { + + if (!Configs.cacheContainerMenu.getBooleanValue() || minecraft.hasSingleplayerServer()) { return; } + LocalPlayer localPlayer = Objects.requireNonNull(minecraft.player); + if (localPlayer.containerMenu != localPlayer.inventoryMenu) { - CacheContainerMenuHandler.updateLastClickBlockPos(); + CacheContainerMenuHandler.getInstance().checkLastClickBlockPos(); } } - @Inject(method = "handleContainerSetSlot", at = @At(value = "RETURN")) - private void postHandleContainerSetSlot(ClientboundContainerSetSlotPacket clientboundContainerSetSlotPacket, CallbackInfo ci) { + @Inject( + method = "handleContainerSetSlot", + at = @At( + value = "RETURN" + ) + ) + private void postHandleContainerSetSlot(ClientboundContainerSetSlotPacket clientboundContainerSetSlotPacket, + CallbackInfo ci) { Minecraft minecraft = Minecraft.getInstance(); - if (!Configs.cacheContainerMenu || minecraft.hasSingleplayerServer()) { + + if (!Configs.cacheContainerMenu.getBooleanValue() || minecraft.hasSingleplayerServer()) { return; } + LocalPlayer localPlayer = Objects.requireNonNull(minecraft.player); int containerId = clientboundContainerSetSlotPacket.getContainerId(); + if (containerId != 0 && containerId != -1 && containerId != -2 && (clientboundContainerSetSlotPacket.getContainerId() == localPlayer.containerMenu.containerId || !(minecraft.screen instanceof CreativeModeInventoryScreen))) { - if (CacheContainerMenuHandler.checkContainerMenu()) { - Container container = CacheContainerMenuHandler.getLastClickContainer(); + if (CacheContainerMenuHandler.getInstance().isAvailableMenu()) { + Container container = CacheContainerMenuHandler.getInstance().getLastClickContainer(); + if (container != null) { int slotId = clientboundContainerSetSlotPacket.getSlot(); + if (slotId < container.getContainerSize()) { container.setItem(slotId, clientboundContainerSetSlotPacket.getItem()); } } } else { - CacheContainerMenuHandler.clearLastClickData(); + CacheContainerMenuHandler.getInstance().clearLastClickData(); } } } - @Inject(method = "handleContainerContent", at = @At(value = "RETURN")) private void postHandleContainerContent(ClientboundContainerSetContentPacket clientboundContainerSetContentPacket, CallbackInfo ci) { Minecraft minecraft = Minecraft.getInstance(); - if (!Configs.cacheContainerMenu || minecraft.hasSingleplayerServer()) { + + if (!Configs.cacheContainerMenu.getBooleanValue() || minecraft.hasSingleplayerServer()) { return; } + LocalPlayer localPlayer = Objects.requireNonNull(minecraft.player); int containerId = clientboundContainerSetContentPacket.getContainerId(); + if (containerId != 0 && containerId == localPlayer.containerMenu.containerId) { - if (CacheContainerMenuHandler.checkContainerMenu()) { - Container container = CacheContainerMenuHandler.getLastClickContainer(); + if (CacheContainerMenuHandler.getInstance().isAvailableMenu()) { + Container container = CacheContainerMenuHandler.getInstance().getLastClickContainer(); List items = clientboundContainerSetContentPacket.getItems(); + if (container != null) { for (int i = 0; i < container.getContainerSize() && i < items.size(); ++i) { container.setItem(i, items.get(i)); } } } else { - CacheContainerMenuHandler.clearLastClickData(); + CacheContainerMenuHandler.getInstance().clearLastClickData(); } } } diff --git a/src/main/java/com/plusls/MasaGadget/mixin/generic/cacheContainerMenu/MixinLocalPlayer.java b/src/main/java/com/plusls/MasaGadget/mixin/feature/cacheContainerMenu/MixinLocalPlayer.java similarity index 52% rename from src/main/java/com/plusls/MasaGadget/mixin/generic/cacheContainerMenu/MixinLocalPlayer.java rename to src/main/java/com/plusls/MasaGadget/mixin/feature/cacheContainerMenu/MixinLocalPlayer.java index 751ff80d..2d71f54e 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/generic/cacheContainerMenu/MixinLocalPlayer.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/feature/cacheContainerMenu/MixinLocalPlayer.java @@ -1,6 +1,6 @@ -package com.plusls.MasaGadget.mixin.generic.cacheContainerMenu; +package com.plusls.MasaGadget.mixin.feature.cacheContainerMenu; -import com.plusls.MasaGadget.generic.cacheContainerMenu.cacheContainerMenu.CacheContainerMenuHandler; +import com.plusls.MasaGadget.impl.feature.cacheContainerMenu.CacheContainerMenuHandler; import net.minecraft.client.player.LocalPlayer; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -9,8 +9,13 @@ @Mixin(LocalPlayer.class) public class MixinLocalPlayer { - @Inject(method = "closeContainer", at = @At(value = "RETURN")) + @Inject( + method = "closeContainer", + at = @At( + value = "RETURN" + ) + ) private void postCloseContainer(CallbackInfo ci) { - CacheContainerMenuHandler.clearLastClickData(); + CacheContainerMenuHandler.getInstance().clearLastClickData(); } } diff --git a/src/main/java/com/plusls/MasaGadget/mixin/generic/cacheContainerMenu/MixinMultiPlayerGameMode.java b/src/main/java/com/plusls/MasaGadget/mixin/feature/cacheContainerMenu/MixinMultiPlayerGameMode.java similarity index 52% rename from src/main/java/com/plusls/MasaGadget/mixin/generic/cacheContainerMenu/MixinMultiPlayerGameMode.java rename to src/main/java/com/plusls/MasaGadget/mixin/feature/cacheContainerMenu/MixinMultiPlayerGameMode.java index 831f646f..f5cfcda0 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/generic/cacheContainerMenu/MixinMultiPlayerGameMode.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/feature/cacheContainerMenu/MixinMultiPlayerGameMode.java @@ -1,7 +1,7 @@ -package com.plusls.MasaGadget.mixin.generic.cacheContainerMenu; +package com.plusls.MasaGadget.mixin.feature.cacheContainerMenu; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.generic.cacheContainerMenu.cacheContainerMenu.CacheContainerMenuHandler; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.impl.feature.cacheContainerMenu.CacheContainerMenuHandler; import net.minecraft.client.multiplayer.MultiPlayerGameMode; import net.minecraft.client.player.LocalPlayer; import net.minecraft.world.InteractionHand; @@ -12,21 +12,27 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -//#if MC <= 11802 +//#if MC < 11900 //$$ import net.minecraft.client.multiplayer.ClientLevel; //#endif @Mixin(MultiPlayerGameMode.class) public class MixinMultiPlayerGameMode { - @Inject(method = "useItemOn", at = @At(value = "HEAD")) + @Inject( + method = "useItemOn", + at = @At( + value = "HEAD" + ) + ) private void prevUseItemOn(LocalPlayer localPlayer, - //#if MC <= 11802 + //#if MC < 11900 //$$ ClientLevel clientLevel, //#endif - InteractionHand interactionHand, BlockHitResult blockHitResult, CallbackInfoReturnable cir) { - if (!Configs.cacheContainerMenu) { - return; + InteractionHand interactionHand, + BlockHitResult blockHitResult, + CallbackInfoReturnable cir) { + if (Configs.cacheContainerMenu.getBooleanValue()) { + CacheContainerMenuHandler.getInstance().setLastClickBlockPos(blockHitResult.getBlockPos()); } - CacheContainerMenuHandler.setLastClickBlockPos(blockHitResult.getBlockPos()); } } diff --git a/src/main/java/com/plusls/MasaGadget/mixin/litematica/disableLitematicaEasyPlaceFailTip/MixinWorldUtils.java b/src/main/java/com/plusls/MasaGadget/mixin/litematica/disableLitematicaEasyPlaceFailTip/MixinWorldUtils.java deleted file mode 100644 index d3167d2d..00000000 --- a/src/main/java/com/plusls/MasaGadget/mixin/litematica/disableLitematicaEasyPlaceFailTip/MixinWorldUtils.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.plusls.MasaGadget.mixin.litematica.disableLitematicaEasyPlaceFailTip; - -import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; -import fi.dy.masa.litematica.util.WorldUtils; -import net.minecraft.client.Minecraft; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; - -@Dependencies(and = @Dependency(ModInfo.LITEMATICA_MOD_ID)) -@Mixin(value = WorldUtils.class, priority = 1001, remap = false) -public class MixinWorldUtils { - @Inject(method = "handleEasyPlace", at = @At(value = "INVOKE", target = "Lfi/dy/masa/malilib/util/InfoUtils;showGuiOrInGameMessage(Lfi/dy/masa/malilib/gui/Message$MessageType;Ljava/lang/String;[Ljava/lang/Object;)V", ordinal = 0), cancellable = true) - private static void cancelEasyPlaceFailTip(Minecraft mc, CallbackInfoReturnable cir) { - if (Configs.disableLitematicaEasyPlaceFailTip) { - cir.setReturnValue(true); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/plusls/MasaGadget/mixin/malilib/backportI18nSupport/MixinConfigBase.java b/src/main/java/com/plusls/MasaGadget/mixin/malilib/backportI18nSupport/MixinConfigBase.java deleted file mode 100644 index f59053be..00000000 --- a/src/main/java/com/plusls/MasaGadget/mixin/malilib/backportI18nSupport/MixinConfigBase.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.plusls.MasaGadget.mixin.malilib.backportI18nSupport; - -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.util.MiscUtil; -import fi.dy.masa.malilib.config.IConfigBase; -import fi.dy.masa.malilib.config.options.ConfigBase; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; -import top.hendrixshen.magiclib.language.api.I18n; - -@Dependencies(and = @Dependency(value = "minecraft", versionPredicate = "<=1.17.1")) -@Mixin(value = ConfigBase.class, remap = false) -public abstract class MixinConfigBase implements IConfigBase { - - @Nullable - private static final Class tweakerMoreIConfigBaseClass; - - static { - @Nullable Class tweakerMoreIConfigBaseClass1; - try { - tweakerMoreIConfigBaseClass1 = Class.forName("me.fallenbreath.tweakermore.config.options.TweakerMoreIConfigBase"); - } catch (ClassNotFoundException e) { - tweakerMoreIConfigBaseClass1 = null; - } - tweakerMoreIConfigBaseClass = tweakerMoreIConfigBaseClass1; - } - - @Inject(method = "getComment", at = @At(value = "RETURN"), cancellable = true) - private void useI18nComment(CallbackInfoReturnable cir) { - if (Configs.backportI18nSupport) { - cir.setReturnValue(MiscUtil.getTranslatedOrFallback("config.comment." + this.getName().toLowerCase(), - cir.getReturnValue())); - } - } - - @Override - public String getConfigGuiDisplayName() { - - if (tweakerMoreIConfigBaseClass != null && tweakerMoreIConfigBaseClass.isInstance(this)) { - return I18n.get("tweakermore.config." + this.getName()); - } else if (Configs.backportI18nSupport) { - return MiscUtil.getTranslatedOrFallback("config.name." + this.getName().toLowerCase(), this.getName()); - } else { - return this.getName(); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/plusls/MasaGadget/mixin/malilib/backportI18nSupport/MixinConfigBooleanClient.java b/src/main/java/com/plusls/MasaGadget/mixin/malilib/backportI18nSupport/MixinConfigBooleanClient.java deleted file mode 100644 index 1e971d2f..00000000 --- a/src/main/java/com/plusls/MasaGadget/mixin/malilib/backportI18nSupport/MixinConfigBooleanClient.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.plusls.MasaGadget.mixin.malilib.backportI18nSupport; - - -import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.util.MiscUtil; -import fi.dy.masa.tweakeroo.config.ConfigBooleanClient; -import org.spongepowered.asm.mixin.Dynamic; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; - -@Dependencies(and = {@Dependency(ModInfo.TWEAKEROO_MOD_ID), @Dependency(value = "minecraft", versionPredicate = "<=1.17.1")}) -@Mixin(value = ConfigBooleanClient.class, remap = false) -public abstract class MixinConfigBooleanClient { - - @Dynamic - @Redirect(method = "getConfigGuiDisplayName", at = @At(value = "INVOKE", target = "Lfi/dy/masa/tweakeroo/config/ConfigBooleanClient;getName()Ljava/lang/String;", ordinal = 0)) - private String i18nDisplayName(ConfigBooleanClient instance) { - if (Configs.backportI18nSupport) { - return MiscUtil.getTranslatedOrFallback("config.name." + instance.getName().toLowerCase(), instance.getName()); - } else { - return instance.getName(); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/plusls/MasaGadget/mixin/malilib/backportI18nSupport/MixinFeatureToggle.java b/src/main/java/com/plusls/MasaGadget/mixin/malilib/backportI18nSupport/MixinFeatureToggle.java deleted file mode 100644 index 0d6c3a55..00000000 --- a/src/main/java/com/plusls/MasaGadget/mixin/malilib/backportI18nSupport/MixinFeatureToggle.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.plusls.MasaGadget.mixin.malilib.backportI18nSupport; - -import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.util.MiscUtil; -import fi.dy.masa.malilib.config.IHotkeyTogglable; -import fi.dy.masa.tweakeroo.config.FeatureToggle; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; - -@Dependencies(and = {@Dependency(ModInfo.TWEAKEROO_MOD_ID), @Dependency(value = "minecraft", versionPredicate = "<=1.17.1")}) -@Mixin(value = FeatureToggle.class, remap = false) -public abstract class MixinFeatureToggle implements IHotkeyTogglable { - - @Inject(method = "getComment", at = @At(value = "RETURN"), cancellable = true) - private void useI18nComment(CallbackInfoReturnable cir) { - if (Configs.backportI18nSupport) { - cir.setReturnValue(MiscUtil.getTranslatedOrFallback("config.comment." + this.getName().toLowerCase(), - cir.getReturnValue())); - } - } - - @Override - public String getConfigGuiDisplayName() { - if (Configs.backportI18nSupport) { - return MiscUtil.getTranslatedOrFallback("config.name." + this.getName().toLowerCase(), this.getName()); - } else { - return this.getName(); - } - } -} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/malilib/backportI18nSupport/MixinInfoToggle.java b/src/main/java/com/plusls/MasaGadget/mixin/malilib/backportI18nSupport/MixinInfoToggle.java deleted file mode 100644 index 9ec49ae4..00000000 --- a/src/main/java/com/plusls/MasaGadget/mixin/malilib/backportI18nSupport/MixinInfoToggle.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.plusls.MasaGadget.mixin.malilib.backportI18nSupport; - -import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.util.MiscUtil; -import fi.dy.masa.malilib.config.IHotkeyTogglable; -import fi.dy.masa.minihud.config.InfoToggle; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; - -@Dependencies(and = {@Dependency(ModInfo.MINIHUD_MOD_ID), @Dependency(value = "minecraft", versionPredicate = "<=1.17.1")}) -@Mixin(value = InfoToggle.class, remap = false) -public abstract class MixinInfoToggle implements IHotkeyTogglable { - - @Inject(method = "getComment", at = @At(value = "RETURN"), cancellable = true) - private void useI18nComment(CallbackInfoReturnable cir) { - if (Configs.backportI18nSupport) { - cir.setReturnValue(MiscUtil.getTranslatedOrFallback("config.comment." + this.getName().toLowerCase(), - cir.getReturnValue())); - } - } - - @Override - public String getConfigGuiDisplayName() { - if (Configs.backportI18nSupport) { - return MiscUtil.getTranslatedOrFallback("config.name." + this.getName().toLowerCase(), this.getName()); - } else { - return this.getName(); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/plusls/MasaGadget/mixin/malilib/backportI18nSupport/MixinRendererToggle.java b/src/main/java/com/plusls/MasaGadget/mixin/malilib/backportI18nSupport/MixinRendererToggle.java deleted file mode 100644 index f056bc5d..00000000 --- a/src/main/java/com/plusls/MasaGadget/mixin/malilib/backportI18nSupport/MixinRendererToggle.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.plusls.MasaGadget.mixin.malilib.backportI18nSupport; - -import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.util.MiscUtil; -import fi.dy.masa.malilib.config.IHotkeyTogglable; -import fi.dy.masa.minihud.config.RendererToggle; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; - -@Dependencies(and = {@Dependency(ModInfo.MINIHUD_MOD_ID), @Dependency(value = "minecraft", versionPredicate = "<=1.17.1")}) -@Mixin(value = RendererToggle.class, remap = false) -public abstract class MixinRendererToggle implements IHotkeyTogglable { - - @Inject(method = "getComment", at = @At(value = "RETURN"), cancellable = true) - private void useI18nComment(CallbackInfoReturnable cir) { - if (Configs.backportI18nSupport) { - cir.setReturnValue(MiscUtil.getTranslatedOrFallback("config.comment." + this.getName().toLowerCase(), - cir.getReturnValue())); - } - } - - @Override - public String getConfigGuiDisplayName() { - if (Configs.backportI18nSupport) { - return MiscUtil.getTranslatedOrFallback("config.name." + this.getName().toLowerCase(), this.getName()); - } else { - return this.getName(); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/plusls/MasaGadget/mixin/malilib/fastSwitchMasaConfigGui/MixinGuiConfigBase.java b/src/main/java/com/plusls/MasaGadget/mixin/malilib/fastSwitchMasaConfigGui/MixinGuiConfigBase.java deleted file mode 100644 index 96665885..00000000 --- a/src/main/java/com/plusls/MasaGadget/mixin/malilib/fastSwitchMasaConfigGui/MixinGuiConfigBase.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.plusls.MasaGadget.mixin.malilib.fastSwitchMasaConfigGui; - -import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.gui.IDropdownRenderer; -import com.plusls.MasaGadget.gui.MyWidgetDropDownList; -import com.plusls.MasaGadget.malilib.fastSwitchMasaConfigGui.MasaGuiUtil; -import fi.dy.masa.malilib.gui.GuiBase; -import fi.dy.masa.malilib.gui.GuiConfigsBase; -import fi.dy.masa.malilib.gui.GuiListBase; -import fi.dy.masa.malilib.gui.widgets.WidgetConfigOption; -import fi.dy.masa.malilib.gui.widgets.WidgetDropDownList; -import fi.dy.masa.malilib.gui.widgets.WidgetListConfigOptions; -import fi.dy.masa.malilib.util.GuiUtils; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import top.hendrixshen.magiclib.compat.modmenu.ModMenuCompatApi; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; - -//#if MC > 11904 -import net.minecraft.client.gui.GuiGraphics; -//#elseif MC > 11404 -//$$ import com.mojang.blaze3d.vertex.PoseStack; -//#endif - -@Dependencies(and = @Dependency(ModInfo.MODMENU_MOD_ID)) -@Mixin(value = GuiConfigsBase.class, remap = false, priority = 1100) -public abstract class MixinGuiConfigBase extends GuiListBase implements IDropdownRenderer { - protected MixinGuiConfigBase(int listX, int listY) { - super(listX, listY); - } - - private WidgetDropDownList> masa_gadget$masaModGuiList; - - @SuppressWarnings({"MixinAnnotationTarget" ,"UnresolvedMixinReference"}) - @Inject( - method = "initGui", - at = @At( - value = "RETURN" - ) - ) - public void postInitGui(CallbackInfo ci) { - // 在其他地方初始化会导致其它 mod 爆炸 - MasaGuiUtil.initMasaModScreenList(); - this.masa_gadget$masaModGuiList = new MyWidgetDropDownList<>( - GuiUtils.getScaledWindowWidth() - 155, 13, 130, 18, 200, 10, - MasaGuiUtil.masaGuiConfigScreenFactorys, - MasaGuiUtil.masaGuiData::get, - configScreenFactory -> GuiBase.openGui(configScreenFactory.create(this.getParent())), - configScreenFactory -> Configs.fastSwitchMasaConfigGui); - this.masa_gadget$masaModGuiList.setSelectedEntry(MasaGuiUtil.masaGuiClassData.get(this.getClass())); - - this.addWidget(this.masa_gadget$masaModGuiList); - } - - @Override - //#if MC > 11904 - public void masa_gad_get$renderHovered(GuiGraphics gui, int mouseX, int mouseY) { - //#elseif MC > 11502 - //$$ public void masa_gad_get$renderHovered(PoseStack poseStack, int mouseX, int mouseY) { - //#else - //$$ public void masa_gad_get$renderHovered(int mouseX, int mouseY) { - //#endif - if (this.masa_gadget$masaModGuiList == null) { - return; - } - //#if MC > 11904 - this.masa_gadget$masaModGuiList.render(mouseX, mouseY, false, gui); - //#elseif MC > 11502 - //$$ this.masa_gadget$masaModGuiList.render(mouseX, mouseY, false, poseStack); - //#else - //$$ this.masa_gadget$masaModGuiList.render(mouseX, mouseY, false); - //#endif - if (this.masa_gadget$masaModGuiList.isMouseOver(mouseX, mouseY)) { - this.hoveredWidget = this.masa_gadget$masaModGuiList; - } - //#if MC > 11904 - this.drawHoveredWidget(mouseX, mouseY, gui); - //#elseif MC > 11502 - //$$ this.drawHoveredWidget(mouseX, mouseY, poseStack); - //#else - //$$ this.drawHoveredWidget(mouseX, mouseY); - //#endif - } -} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/malilib/fastSwitchMasaConfigGui/MixinWidgetDropDownList.java b/src/main/java/com/plusls/MasaGadget/mixin/malilib/fastSwitchMasaConfigGui/MixinWidgetDropDownList.java deleted file mode 100644 index b18d3bdb..00000000 --- a/src/main/java/com/plusls/MasaGadget/mixin/malilib/fastSwitchMasaConfigGui/MixinWidgetDropDownList.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.plusls.MasaGadget.mixin.malilib.fastSwitchMasaConfigGui; - -import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.gui.MyWidgetDropDownList; -import fi.dy.masa.malilib.gui.widgets.WidgetDropDownList; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyArgs; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.invoke.arg.Args; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; -import top.hendrixshen.magiclib.util.MiscUtil; - -/* - * Modified from TweakerMore - * https://github.com/Fallen-Breath/tweakermore/blob/stable/src/main/java/me/fallenbreath/tweakermore/mixins/core/gui/WidgetDropDownListMixin.java - */ -@Dependencies(and = @Dependency(ModInfo.MODMENU_MOD_ID)) -@Mixin(value = WidgetDropDownList.class, remap = false) -public class MixinWidgetDropDownList { - @SuppressWarnings({"ConstantConditions", "PointlessBitwiseExpression"}) - @ModifyArgs( - method = "render", - at = @At( - value = "INVOKE", - target = "Lfi/dy/masa/malilib/render/RenderUtils;drawRect(IIIII)V", - remap = false - ), - remap = false - ) - private void selectorDropDownListMakeOpaque(Args args) { - if (MiscUtil.cast(this) instanceof MyWidgetDropDownList) { - // ensure background is opaque - int bgColor = args.get(4); - int a = (bgColor >> 24) & 0xFF; - bgColor = (0xFF << 24) | (a << 16) | (a << 8) | (a << 0); - args.set(4, bgColor); - - // show left box border - args.set(0, (int)args.get(0) + 1); - } - } - - @SuppressWarnings("ConstantConditions") - @Inject( - method = "onMouseScrolledImpl", - at = @At( - value = "INVOKE", - target = "Lfi/dy/masa/malilib/gui/GuiScrollBar;offsetValue(I)V", - shift = At.Shift.AFTER - ), - cancellable = true - ) - private void fixNoReturnValueHandlingForScroll(CallbackInfoReturnable cir) { - if (MiscUtil.cast(this) instanceof MyWidgetDropDownList) { - cir.setReturnValue(true); - } - } -} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/malilib/fastSwitchMasaConfigGui/MixinWidgetListBase.java b/src/main/java/com/plusls/MasaGadget/mixin/malilib/fastSwitchMasaConfigGui/MixinWidgetListBase.java deleted file mode 100644 index b8bf05a3..00000000 --- a/src/main/java/com/plusls/MasaGadget/mixin/malilib/fastSwitchMasaConfigGui/MixinWidgetListBase.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.plusls.MasaGadget.mixin.malilib.fastSwitchMasaConfigGui; - -import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.gui.IDropdownRenderer; -import com.plusls.MasaGadget.mixin.accessor.AccessorWidgetListConfigOptions; -import fi.dy.masa.malilib.gui.GuiConfigsBase; -import fi.dy.masa.malilib.gui.widgets.WidgetListBase; -import fi.dy.masa.malilib.gui.widgets.WidgetListConfigOptions; -import fi.dy.masa.malilib.gui.widgets.WidgetListEntryBase; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; -import top.hendrixshen.magiclib.util.MiscUtil; - -//#if MC > 11904 -import net.minecraft.client.gui.GuiGraphics; -//#elseif MC > 11502 -//$$ import com.mojang.blaze3d.vertex.PoseStack; -//#endif - -/* - * Modified from TweakerMore - * https://github.com/Fallen-Breath/tweakermore/blob/stable/src/main/java/me/fallenbreath/tweakermore/mixins/core/gui/WidgetListBaseMixin.java - */ -@Dependencies(and = @Dependency(ModInfo.MODMENU_MOD_ID)) -@Mixin(value = WidgetListBase.class, priority = 1100) -public abstract class MixinWidgetListBase> { - private boolean masa_gadget$shouldRenderDropdownListAgain = false; - - @Inject(method = "drawContents", at = @At("HEAD"), remap = false) - private void drawTweakerMoreConfigGuiDropDownListSetFlag(CallbackInfo ci) { - this.masa_gadget$shouldRenderDropdownListAgain = true; - } - - //#if MC < 11904 - //$$ @Inject( - //$$ method = "drawContents", - //$$ at = @At( - //$$ value = "INVOKE", - //#if MC > 11904 - //$$ target = "Lfi/dy/masa/malilib/gui/widgets/WidgetBase;postRenderHovered(IIZLnet/minecraft/client/gui/GuiGraphics;)V", - //$$ remap = true - //#elseif MC > 11502 - //$$ target = "Lfi/dy/masa/malilib/gui/widgets/WidgetBase;postRenderHovered(IIZLcom/mojang/blaze3d/vertex/PoseStack;)V", - //$$ remap = true - //#else - //$$ target = "Lfi/dy/masa/malilib/gui/widgets/WidgetBase;postRenderHovered(IIZ)V", - //$$ remap = false - //#endif - //$$ ), - //$$ remap = false - //$$ ) - //#if MC > 11904 - //$$ private void drawDropDownListAgainBeforeHover(GuiGraphics gui, int mouseX, int mouseY, float partialTicks, CallbackInfo ci) { - //$$ this.masa_gadget$renderDropdownListAgain(gui, mouseX, mouseY); - //#elseif MC > 11502 - //$$ private void drawDropDownListAgainBeforeHover(PoseStack poseStack, int mouseX, int mouseY, float partialTicks, CallbackInfo ci) { - //$$ this.masa_gadget$renderDropdownListAgain(poseStack, mouseX, mouseY); - //#else - //$$ private void drawTweakerMoreConfigGuiDropDownListAgainBeforeHover(int mouseX, int mouseY, float partialTicks, CallbackInfo ci) { - //$$ this.masa_gadget$renderDropdownListAgain(mouseX, mouseY); - //#endif - //$$ } - //#endif - - @Inject( - method = "drawContents", - at = @At( - "TAIL" - ), - remap = false - ) - //#if MC > 11904 - private void drawDropDownListAgainAfterHover(GuiGraphics gui, int mouseX, int mouseY, float partialTicks, CallbackInfo ci) { - this.masa_gadget$renderDropdownListAgain(gui, mouseX, mouseY); - //#elseif MC > 11502 - //$$ private void drawDropDownListAgainAfterHover(PoseStack poseStack, int mouseX, int mouseY, float partialTicks, CallbackInfo ci) { - //$$ this.masa_gadget$renderDropdownListAgain(poseStack, mouseX, mouseY); - //#else - //$$ private void drawDropDownListAgainAfterHover(int mouseX, int mouseY, float partialTicks, CallbackInfo ci) { - //$$ this.masa_gadget$renderDropdownListAgain(mouseX, mouseY); - //#endif - } - - @SuppressWarnings("ConstantConditions") - //#if MC > 11904 - private void masa_gadget$renderDropdownListAgain(GuiGraphics gui, int mouseX, int mouseY) { - //#elseif MC > 11502 - //$$ private void masa_gadget$renderDropdownListAgain(PoseStack poseStack, int mouseX, int mouseY) { - //#else - //$$ private void masa_gadget$renderDropdownListAgain(int mouseX, int mouseY) { - //#endif - if (this.masa_gadget$shouldRenderDropdownListAgain) { - if (!(MiscUtil.cast(this) instanceof WidgetListConfigOptions)) { - return; - } - GuiConfigsBase guiConfig = ((AccessorWidgetListConfigOptions) this).getParent(); - - //#if MC > 11904 - ((IDropdownRenderer)guiConfig).masa_gad_get$renderHovered(gui ,mouseX, mouseY); - //#elseif MC > 11502 - //$$ ((IDropdownRenderer)guiConfig).masa_gad_get$renderHovered(poseStack ,mouseX, mouseY); - //#else - //$$ ((IDropdownRenderer)guiConfig).masa_gad_get$renderHovered(mouseX, mouseY); - //#endif - this.masa_gadget$shouldRenderDropdownListAgain = false; - } - } -} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/malilib/favorites/MixinGuiConfigBase.java b/src/main/java/com/plusls/MasaGadget/mixin/malilib/favorites/MixinGuiConfigBase.java deleted file mode 100644 index 25df16e6..00000000 --- a/src/main/java/com/plusls/MasaGadget/mixin/malilib/favorites/MixinGuiConfigBase.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.plusls.MasaGadget.mixin.malilib.favorites; - -import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.gui.MasaGadgetIcons; -import com.plusls.MasaGadget.gui.WidgetIconToggleButton; -import fi.dy.masa.malilib.gui.GuiConfigsBase; -import fi.dy.masa.malilib.gui.GuiListBase; -import fi.dy.masa.malilib.gui.widgets.WidgetConfigOption; -import fi.dy.masa.malilib.gui.widgets.WidgetListConfigOptions; -import fi.dy.masa.malilib.util.GuiUtils; -//#if MC > 11902 -import org.spongepowered.asm.mixin.Intrinsic; -//#endif -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(value = GuiConfigsBase.class, remap = false) -public abstract class MixinGuiConfigBase extends GuiListBase { - private WidgetIconToggleButton favoritesButton; - - protected MixinGuiConfigBase(int listX, int listY) { - super(listX, listY); - } - - //#if MC > 11902 - @Intrinsic - @Override - public void initGui() { - super.initGui(); - } - //#endif - - @SuppressWarnings({"MixinAnnotationTarget" ,"UnresolvedMixinReference"}) - @Inject( - method = "initGui", - at = @At( - value = "RETURN" - ) - ) - public void postInitGui(CallbackInfo ci) { - favoritesButton = new WidgetIconToggleButton(GuiUtils.getScaledWindowWidth() - 175, 13, - MasaGadgetIcons.FAVORITE, Configs.favoritesFilter, - status -> { - Configs.favoritesFilter = status; - WidgetListConfigOptions widgetListConfigOptions = this.getListWidget(); - if (widgetListConfigOptions != null) { - widgetListConfigOptions.getScrollbar().setValue(0); - widgetListConfigOptions.refreshEntries(); - } - ModInfo.configHandler.saveToFile(); - ModInfo.configHandler.loadFromFile(); - }, - status -> status ? ModInfo.translate("message.showAllOptions") : ModInfo.translate("message.showFavorite"), - widgetIconToggleButton -> Configs.favoritesSupport); - this.addWidget(favoritesButton); - } -} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/malilib/fixConfigWidgetWidth/MixinWidgetListConfigOptions.java b/src/main/java/com/plusls/MasaGadget/mixin/malilib/fixConfigWidgetWidth/MixinWidgetListConfigOptions.java deleted file mode 100644 index 6e6f8137..00000000 --- a/src/main/java/com/plusls/MasaGadget/mixin/malilib/fixConfigWidgetWidth/MixinWidgetListConfigOptions.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.plusls.MasaGadget.mixin.malilib.fixConfigWidgetWidth; - -import com.plusls.MasaGadget.config.Configs; -import fi.dy.masa.malilib.config.IConfigBase; -import fi.dy.masa.malilib.gui.widgets.WidgetListConfigOptions; -import org.spongepowered.asm.mixin.Dynamic; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; - -@Dependencies(and = @Dependency(value = "minecraft", versionPredicate = "<=1.17.1")) -@Mixin(value = WidgetListConfigOptions.class, remap = false) -public abstract class MixinWidgetListConfigOptions { - - @Dynamic - @Redirect(method = "getMaxNameLengthWrapped", - at = @At(value = "INVOKE", target = "Lfi/dy/masa/malilib/config/IConfigBase;getName()Ljava/lang/String;", ordinal = 0)) - private String fixWidth(IConfigBase instance) { - if (Configs.fixConfigWidgetWidth) { - return instance.getConfigGuiDisplayName(); - } - return instance.getName(); - } - -} \ No newline at end of file diff --git a/src/main/java/com/plusls/MasaGadget/mixin/litematica/betterEasyPlaceMode/MixinWorldUtils.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/litematica/betterEasyPlaceMode/MixinWorldUtils.java similarity index 64% rename from src/main/java/com/plusls/MasaGadget/mixin/litematica/betterEasyPlaceMode/MixinWorldUtils.java rename to src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/litematica/betterEasyPlaceMode/MixinWorldUtils.java index b767df40..01265906 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/litematica/betterEasyPlaceMode/MixinWorldUtils.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/litematica/betterEasyPlaceMode/MixinWorldUtils.java @@ -1,8 +1,8 @@ -package com.plusls.MasaGadget.mixin.litematica.betterEasyPlaceMode; +package com.plusls.MasaGadget.mixin.mod_tweak.litematica.betterEasyPlaceMode; import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.util.HitResultUtil; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.impl.generic.HitResultHandler; import fi.dy.masa.litematica.util.WorldUtils; import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; @@ -15,32 +15,45 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyVariable; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; +import top.hendrixshen.magiclib.util.collect.ValueContainer; -@Dependencies(and = @Dependency(ModInfo.LITEMATICA_MOD_ID)) +@Dependencies(require = @Dependency(ModInfo.LITEMATICA_MOD_ID)) @Mixin(value = WorldUtils.class, remap = false) public class MixinWorldUtils { - @ModifyVariable(method = "handleEasyPlace", - at = @At(value = "INVOKE_ASSIGN", + @ModifyVariable( + method = "handleEasyPlace", + at = @At( + value = "INVOKE_ASSIGN", target = "Lfi/dy/masa/litematica/util/WorldUtils;doEasyPlaceAction(Lnet/minecraft/client/Minecraft;)Lnet/minecraft/world/InteractionResult;", - ordinal = 0, remap = true), - ordinal = 0) + remap = true + ) + ) private static InteractionResult checkInventory(InteractionResult interactionResult) { Minecraft mc = Minecraft.getInstance(); + if (!Configs.betterEasyPlaceMode || mc.level == null || interactionResult != InteractionResult.FAIL) { return interactionResult; } - HitResult trace = HitResultUtil.getLastHitResult(); - if (trace != null && trace.getType() == HitResult.Type.BLOCK) { - BlockHitResult blockHitResult = (BlockHitResult) trace; + + ValueContainer trace = HitResultHandler.getInstance().getLastHitResult(); + + if (trace.isEmpty()) { + return interactionResult; + } + + if (trace.get().getType() == HitResult.Type.BLOCK) { + BlockHitResult blockHitResult = (BlockHitResult) trace.get(); BlockPos pos = blockHitResult.getBlockPos(); Block block = mc.level.getBlockState(pos).getBlock(); mc.level.getBlockState(pos); + if (block == Blocks.BEACON || mc.level.getBlockEntity(pos) instanceof Container) { interactionResult = InteractionResult.PASS; } } + return interactionResult; } } diff --git a/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/litematica/disableLitematicaEasyPlaceFailTip/MixinWorldUtils.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/litematica/disableLitematicaEasyPlaceFailTip/MixinWorldUtils.java new file mode 100644 index 00000000..1e79dc01 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/litematica/disableLitematicaEasyPlaceFailTip/MixinWorldUtils.java @@ -0,0 +1,30 @@ +package com.plusls.MasaGadget.mixin.mod_tweak.litematica.disableLitematicaEasyPlaceFailTip; + +import com.plusls.MasaGadget.ModInfo; +import com.plusls.MasaGadget.game.Configs; +import fi.dy.masa.litematica.util.WorldUtils; +import net.minecraft.client.Minecraft; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; + +@Dependencies(require = @Dependency(ModInfo.LITEMATICA_MOD_ID)) +@Mixin(value = WorldUtils.class, priority = 1100, remap = false) +public class MixinWorldUtils { + @Inject( + method = "handleEasyPlace", + at = @At( + value = "INVOKE", + target = "Lfi/dy/masa/malilib/util/InfoUtils;showGuiOrInGameMessage(Lfi/dy/masa/malilib/gui/Message$MessageType;Ljava/lang/String;[Ljava/lang/Object;)V" + ), + cancellable = true + ) + private static void cancelEasyPlaceFailTip(Minecraft mc, CallbackInfoReturnable cir) { + if (Configs.disableLitematicaEasyPlaceFailTip.getBooleanValue()) { + cir.setReturnValue(true); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/plusls/MasaGadget/mixin/litematica/fixCarpetAccurateProtocol/MixinBlockItem.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/litematica/fixCarpetAccurateProtocol/MixinBlockItem.java similarity index 78% rename from src/main/java/com/plusls/MasaGadget/mixin/litematica/fixCarpetAccurateProtocol/MixinBlockItem.java rename to src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/litematica/fixCarpetAccurateProtocol/MixinBlockItem.java index 5b09498a..4b5bf5b5 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/litematica/fixCarpetAccurateProtocol/MixinBlockItem.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/litematica/fixCarpetAccurateProtocol/MixinBlockItem.java @@ -1,8 +1,8 @@ -package com.plusls.MasaGadget.mixin.litematica.fixCarpetAccurateProtocol; +package com.plusls.MasaGadget.mixin.mod_tweak.litematica.fixCarpetAccurateProtocol; import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.litematica.fixCarpetAccurateProtocol.BlockPlacer; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.util.BlockPlacer; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.block.Block; @@ -12,8 +12,8 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; // 用魔法打败魔法 // 提升优先级,确保是由 carpet extra 的协议处理的 @@ -21,10 +21,9 @@ // tweakeroo 是 990 // carpet extra 是 1000 // 可以保证第一个执行自己的函数 -@Dependencies(and = @Dependency(ModInfo.LITEMATICA_MOD_ID)) +@Dependencies(require = @Dependency(ModInfo.LITEMATICA_MOD_ID)) @Mixin(value = BlockItem.class, priority = 980) public abstract class MixinBlockItem { - @Shadow public abstract Block getBlock(); @@ -33,18 +32,20 @@ public abstract class MixinBlockItem { @Inject(method = "getPlacementState", at = @At(value = "HEAD"), cancellable = true) private void preGetPlacementState(BlockPlaceContext context, CallbackInfoReturnable cir) { - if (!Configs.fixAccurateProtocol) { + if (!Configs.fixAccurateProtocol.getBooleanValue()) { return; } + BlockState blockState = null; + try { blockState = BlockPlacer.alternativeBlockPlacement(this.getBlock(), context); } catch (Exception e) { e.printStackTrace(); } + if (blockState != null && this.canPlace(context, blockState)) { cir.setReturnValue(blockState); } } - } \ No newline at end of file diff --git a/src/main/java/com/plusls/MasaGadget/mixin/litematica/fixCarpetAccurateProtocol/MixinWorldUtils.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/litematica/fixCarpetAccurateProtocol/MixinWorldUtils.java similarity index 56% rename from src/main/java/com/plusls/MasaGadget/mixin/litematica/fixCarpetAccurateProtocol/MixinWorldUtils.java rename to src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/litematica/fixCarpetAccurateProtocol/MixinWorldUtils.java index a5a95e5f..410da22b 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/litematica/fixCarpetAccurateProtocol/MixinWorldUtils.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/litematica/fixCarpetAccurateProtocol/MixinWorldUtils.java @@ -1,7 +1,7 @@ -package com.plusls.MasaGadget.mixin.litematica.fixCarpetAccurateProtocol; +package com.plusls.MasaGadget.mixin.mod_tweak.litematica.fixCarpetAccurateProtocol; import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; +import com.plusls.MasaGadget.game.Configs; import fi.dy.masa.litematica.materials.MaterialCache; import fi.dy.masa.litematica.util.EntityUtils; import fi.dy.masa.litematica.util.RayTraceUtils; @@ -28,14 +28,16 @@ import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; +import top.hendrixshen.magiclib.api.compat.minecraft.world.entity.player.PlayerCompat; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; import java.util.Objects; @@ -48,20 +50,22 @@ //#endif @SuppressWarnings("DefaultAnnotationParam") -@Dependencies(and = @Dependency(ModInfo.LITEMATICA_MOD_ID)) +@Dependencies(require = @Dependency(ModInfo.LITEMATICA_MOD_ID)) @Mixin(value = WorldUtils.class, priority = 900, remap = false) public class MixinWorldUtils { - - private static final ThreadLocal easyPlaceActionNewSide = ThreadLocal.withInitial(() -> null); - private static final ThreadLocal easyPlaceActionOldYaw = ThreadLocal.withInitial(() -> null); - private static final ThreadLocal interactBlockCount = ThreadLocal.withInitial(() -> null); - + @Unique + private static final ThreadLocal masa_gadget_mod$easyPlaceActionNewSide = ThreadLocal.withInitial(() -> null); + @Unique + private static final ThreadLocal masa_gadget_mod$easyPlaceActionOldYaw = ThreadLocal.withInitial(() -> null); + @Unique + private static final ThreadLocal masa_gadget_mod$interactBlockCount = ThreadLocal.withInitial(() -> null); @Inject(method = "applyCarpetProtocolHitVec", at = @At(value = "HEAD"), cancellable = true) private static void preApplyCarpetProtocolHitVec(BlockPos pos, BlockState state, Vec3 hitVecIn, CallbackInfoReturnable cir) { - if (!Configs.fixAccurateProtocol) { + if (!Configs.fixAccurateProtocol.getBooleanValue()) { return; } + double x = hitVecIn.x; double y = hitVecIn.y; double z = hitVecIn.z; @@ -94,19 +98,28 @@ private static void preApplyCarpetProtocolHitVec(BlockPos pos, BlockState state, y = pos.getY(); } } + ModInfo.LOGGER.debug("applyCarpetProtocolHitVec: {} -> {}", hitVecIn, new Vec3(x, y, z).toString()); cir.setReturnValue(new Vec3(x, y, z)); } // 修复 漏斗,原木放置问题 // 核心思路是修改玩家看的位置以及 side - @Inject(method = "doEasyPlaceAction", at = @At(value = "INVOKE", - target = "Lfi/dy/masa/litematica/util/WorldUtils;cacheEasyPlacePosition(Lnet/minecraft/core/BlockPos;)V", ordinal = 0, remap = true), - locals = LocalCapture.CAPTURE_FAILHARD) - private static void fixDoEasyPlaceAction0(Minecraft mc, CallbackInfoReturnable cir, RayTraceUtils.RayTraceWrapper traceWrapper) { - if (!Configs.fixAccurateProtocol) { + @Inject( + method = "doEasyPlaceAction", + at = @At( + value = "INVOKE", + target = "Lfi/dy/masa/litematica/util/WorldUtils;cacheEasyPlacePosition(Lnet/minecraft/core/BlockPos;)V", + remap = true + ), + locals = LocalCapture.CAPTURE_FAILHARD + ) + private static void fixDoEasyPlaceAction0(Minecraft mc, CallbackInfoReturnable cir, + RayTraceUtils.RayTraceWrapper traceWrapper) { + if (!Configs.fixAccurateProtocol.getBooleanValue()) { return; } + BlockHitResult trace = Objects.requireNonNull(traceWrapper).getBlockHitResult(); BlockPos pos = Objects.requireNonNull(trace).getBlockPos(); Level world = Objects.requireNonNull(SchematicWorldHandler.getSchematicWorld()); @@ -117,21 +130,22 @@ private static void fixDoEasyPlaceAction0(Minecraft mc, CallbackInfoReturnable 11502 BlockPlaceContext itemPlacementContext = new BlockPlaceContext(mc.player, hand, itemStack, new BlockHitResult(hitPos, newSide, pos, false)); @@ -139,81 +153,115 @@ private static void fixDoEasyPlaceAction0(Minecraft mc, CallbackInfoReturnable 11802 - target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;useItemOn(Lnet/minecraft/client/player/LocalPlayer;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/phys/BlockHitResult;)Lnet/minecraft/world/InteractionResult;", - //#else - //$$ target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;useItemOn(Lnet/minecraft/client/player/LocalPlayer;Lnet/minecraft/client/multiplayer/ClientLevel;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/phys/BlockHitResult;)Lnet/minecraft/world/InteractionResult;", + @Redirect( + method = "doEasyPlaceAction", + at = @At( + value = "INVOKE", + //#if MC > 11802 + target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;useItemOn(Lnet/minecraft/client/player/LocalPlayer;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/phys/BlockHitResult;)Lnet/minecraft/world/InteractionResult;", + //#else + //$$ target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;useItemOn(Lnet/minecraft/client/player/LocalPlayer;Lnet/minecraft/client/multiplayer/ClientLevel;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/phys/BlockHitResult;)Lnet/minecraft/world/InteractionResult;", + //#endif + ordinal = 0, + remap = true + ) + ) + private static InteractionResult myInteractBlock( + MultiPlayerGameMode clientPlayerInteractionManager, + LocalPlayer player, + //#if MC < 11900 + //$$ ClientLevel level, //#endif - ordinal = 0, remap = true)) - private static InteractionResult myInteractBlock(MultiPlayerGameMode clientPlayerInteractionManager, LocalPlayer player, - //#if MC <= 11802 - //$$ ClientLevel world, - //#endif - InteractionHand hand, BlockHitResult hitResult) { - InteractionResult ret = clientPlayerInteractionManager.useItemOn(player, - //#if MC <= 11802 - //$$ world, + InteractionHand hand, + BlockHitResult hitResult + ) { + InteractionResult ret = clientPlayerInteractionManager.useItemOn( + player, + //#if MC < 11900 + //$$ level, //#endif - hand, hitResult); - if (!Configs.fixAccurateProtocol || interactBlockCount.get() == null) { + hand, + hitResult + ); + + if (!Configs.fixAccurateProtocol.getBooleanValue() || + MixinWorldUtils.masa_gadget_mod$interactBlockCount.get() == null) { return ret; } - for (int i = 0; i < interactBlockCount.get(); ++i) { - clientPlayerInteractionManager.useItemOn(player, - //#if MC <= 11802 - //$$ world, + + for (int i = 0; i < MixinWorldUtils.masa_gadget_mod$interactBlockCount.get(); i++) { + clientPlayerInteractionManager.useItemOn( + player, + //#if MC < 11900 + //$$ level, //#endif - hand, hitResult); + hand, hitResult + ); } - interactBlockCount.set(null); + + MixinWorldUtils.masa_gadget_mod$interactBlockCount.remove(); return ret; } - @Inject(method = "doEasyPlaceAction", at = @At(value = "INVOKE", - //#if MC > 11802 - target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;useItemOn(Lnet/minecraft/client/player/LocalPlayer;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/phys/BlockHitResult;)Lnet/minecraft/world/InteractionResult;", - //#else - //$$ target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;useItemOn(Lnet/minecraft/client/player/LocalPlayer;Lnet/minecraft/client/multiplayer/ClientLevel;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/phys/BlockHitResult;)Lnet/minecraft/world/InteractionResult;", - //#endif - shift = At.Shift.AFTER, ordinal = 0, remap = true)) + @Inject( + method = "doEasyPlaceAction", + at = @At( + value = "INVOKE", + //#if MC > 11802 + target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;useItemOn(Lnet/minecraft/client/player/LocalPlayer;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/phys/BlockHitResult;)Lnet/minecraft/world/InteractionResult;", + //#else + //$$ target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;useItemOn(Lnet/minecraft/client/player/LocalPlayer;Lnet/minecraft/client/multiplayer/ClientLevel;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/phys/BlockHitResult;)Lnet/minecraft/world/InteractionResult;", + //#endif + shift = At.Shift.AFTER, ordinal = 0, remap = true + ) + ) private static void fixDoEasyPlaceAction1(Minecraft mc, CallbackInfoReturnable cir) { - if (!Configs.fixAccurateProtocol) { + if (!Configs.fixAccurateProtocol.getBooleanValue()) { return; } // 让玩家看回原来的位置 - if (easyPlaceActionOldYaw.get() != null) { - Objects.requireNonNull(mc.player).setYRot(easyPlaceActionOldYaw.get()); - mc.player.connection.send(new ServerboundMovePlayerPacket.Rot(mc.player.getYRot(), mc.player.getXRot(), mc.player.onGround())); + if (MixinWorldUtils.masa_gadget_mod$easyPlaceActionOldYaw.get() != null) { + PlayerCompat playerCompat = PlayerCompat.of(Objects.requireNonNull(mc.player)); + playerCompat.setYRot(masa_gadget_mod$easyPlaceActionOldYaw.get()); + mc.player.connection.send(new ServerboundMovePlayerPacket.Rot(playerCompat.getYRot(), playerCompat.getXRot(), playerCompat.isOnGround())); } } } diff --git a/src/main/java/com/plusls/MasaGadget/mixin/litematica/nudgeSelectionSupportFreeCamera/MixinInputHandler.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/litematica/nudgeSelectionSupportFreeCamera/MixinInputHandler.java similarity index 60% rename from src/main/java/com/plusls/MasaGadget/mixin/litematica/nudgeSelectionSupportFreeCamera/MixinInputHandler.java rename to src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/litematica/nudgeSelectionSupportFreeCamera/MixinInputHandler.java index d3b98add..e4cc4cab 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/litematica/nudgeSelectionSupportFreeCamera/MixinInputHandler.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/litematica/nudgeSelectionSupportFreeCamera/MixinInputHandler.java @@ -1,8 +1,7 @@ -package com.plusls.MasaGadget.mixin.litematica.nudgeSelectionSupportFreeCamera; - +package com.plusls.MasaGadget.mixin.mod_tweak.litematica.nudgeSelectionSupportFreeCamera; import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; +import com.plusls.MasaGadget.game.Configs; import fi.dy.masa.litematica.event.InputHandler; import fi.dy.masa.tweakeroo.config.FeatureToggle; import fi.dy.masa.tweakeroo.util.CameraEntity; @@ -10,19 +9,24 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyVariable; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; -@Dependencies(and = {@Dependency(ModInfo.LITEMATICA_MOD_ID), @Dependency(ModInfo.TWEAKEROO_MOD_ID), @Dependency(value = "minecraft", versionPredicate = "<=1.15.2")}) +@Dependencies(require = { + @Dependency(ModInfo.LITEMATICA_MOD_ID), + @Dependency(ModInfo.TWEAKEROO_MOD_ID), + @Dependency(value = "minecraft", versionPredicates = "<=1.15.2") +}) @Mixin(value = InputHandler.class, remap = false) public class MixinInputHandler { - @SuppressWarnings("InvalidInjectorMethodSignature") @ModifyVariable(method = "nudgeSelection", at = @At(value = "HEAD"), ordinal = 0) static private Player modifyPlayer(Player player) { - if (FeatureToggle.TWEAK_FREE_CAMERA.getBooleanValue() && Configs.nudgeSelectionSupportFreeCamera) { + if (FeatureToggle.TWEAK_FREE_CAMERA.getBooleanValue() && + Configs.nudgeSelectionSupportFreeCamera.getBooleanValue()) { player = CameraEntity.getCamera(); } + return player; } } diff --git a/src/main/java/com/plusls/MasaGadget/mixin/litematica/saveInventoryToSchematicInServer/MixinSchematicUtils.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/litematica/saveInventoryToSchematicInServer/MixinSchematicUtils.java similarity index 73% rename from src/main/java/com/plusls/MasaGadget/mixin/litematica/saveInventoryToSchematicInServer/MixinSchematicUtils.java rename to src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/litematica/saveInventoryToSchematicInServer/MixinSchematicUtils.java index 2c6cec7d..d8e63390 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/litematica/saveInventoryToSchematicInServer/MixinSchematicUtils.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/litematica/saveInventoryToSchematicInServer/MixinSchematicUtils.java @@ -1,8 +1,8 @@ -package com.plusls.MasaGadget.mixin.litematica.saveInventoryToSchematicInServer; +package com.plusls.MasaGadget.mixin.mod_tweak.litematica.saveInventoryToSchematicInServer; import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.litematica.saveInventoryToSchematicInServer.PcaSyncUtil; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.util.PcaSyncUtil; import com.plusls.MasaGadget.util.PcaSyncProtocol; import fi.dy.masa.litematica.data.DataManager; import fi.dy.masa.litematica.selection.AreaSelection; @@ -15,16 +15,16 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; -@Dependencies(and = @Dependency(ModInfo.LITEMATICA_MOD_ID)) +@Dependencies(require = @Dependency(ModInfo.LITEMATICA_MOD_ID)) @Mixin(value = SchematicUtils.class, remap = false) public class MixinSchematicUtils { @Inject(method = "saveSchematic", at = @At(value = "HEAD")) private static void syncInventory(boolean inMemoryOnly, CallbackInfoReturnable cir) { - if (!Configs.saveInventoryToSchematicInServer || + if (!Configs.saveInventoryToSchematicInServer.getBooleanValue() || Minecraft.getInstance().hasSingleplayerServer() || !PcaSyncProtocol.enable) { return; } @@ -38,7 +38,7 @@ private static void syncInventory(boolean inMemoryOnly, CallbackInfoReturnable cir) { - if (Configs.saveInventoryToSchematicInServer && PcaSyncUtil.lastUpdatePos == null) { + if (Configs.saveInventoryToSchematicInServer.getBooleanValue() && PcaSyncUtil.lastUpdatePos == null) { InfoUtils.showGuiOrInGameMessage(Message.MessageType.SUCCESS, ModInfo.MOD_ID + ".message.loadInventoryToLocalSuccess"); } } diff --git a/src/main/java/com/plusls/MasaGadget/mixin/litematica/useRelativePath/MixinSchematicPlacement.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/litematica/useRelativePath/MixinSchematicPlacement.java similarity index 58% rename from src/main/java/com/plusls/MasaGadget/mixin/litematica/useRelativePath/MixinSchematicPlacement.java rename to src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/litematica/useRelativePath/MixinSchematicPlacement.java index a2a0cde7..a1a2fe68 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/litematica/useRelativePath/MixinSchematicPlacement.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/litematica/useRelativePath/MixinSchematicPlacement.java @@ -1,25 +1,33 @@ -package com.plusls.MasaGadget.mixin.litematica.useRelativePath; +package com.plusls.MasaGadget.mixin.mod_tweak.litematica.useRelativePath; import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; +import com.plusls.MasaGadget.game.Configs; import fi.dy.masa.litematica.schematic.placement.SchematicPlacement; import net.fabricmc.loader.api.FabricLoader; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; import java.io.File; -@Dependencies(and = @Dependency(ModInfo.LITEMATICA_MOD_ID)) +@Dependencies(require = @Dependency(ModInfo.LITEMATICA_MOD_ID)) @Mixin(value = SchematicPlacement.class, remap = false) public class MixinSchematicPlacement { - @Redirect(method = "toJson", at = @At(value = "INVOKE", target = "Ljava/io/File;getAbsolutePath()Ljava/lang/String;", ordinal = 0)) + @Redirect( + method = "toJson", + at = @At( + value = "INVOKE", + target = "Ljava/io/File;getAbsolutePath()Ljava/lang/String;", + ordinal = 0 + ) + ) private String toRelativePath(File file) { - if (!Configs.useRelativePath) { + if (!Configs.useRelativePath.getBooleanValue()) { return file.getAbsolutePath(); } + if (file.isAbsolute()) { try { return FabricLoader.getInstance().getGameDir().relativize(file.toPath()).toString(); diff --git a/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/backportI18nSupport/MixinConfigBase.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/backportI18nSupport/MixinConfigBase.java new file mode 100644 index 00000000..75cb5e9e --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/backportI18nSupport/MixinConfigBase.java @@ -0,0 +1,65 @@ +package com.plusls.MasaGadget.mixin.mod_tweak.malilib.backportI18nSupport; + +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.util.MiscUtil; +import fi.dy.masa.malilib.config.IConfigBase; +import fi.dy.masa.malilib.config.options.ConfigBase; +import org.spongepowered.asm.mixin.Intrinsic; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; +import top.hendrixshen.magiclib.api.i18n.I18n; +import top.hendrixshen.magiclib.util.ReflectionUtil; +import top.hendrixshen.magiclib.util.collect.ValueContainer; + +@Dependencies(require = @Dependency(value = "minecraft", versionPredicates = "<=1.17.1")) +@Mixin(value = ConfigBase.class, remap = false) +public abstract class MixinConfigBase implements IConfigBase { + @Unique + private static final ValueContainer> masa_gadget$tweakerMoreIConfigBaseClass = ReflectionUtil + .getClass("me.fallenbreath.tweakermore.config.options.TweakerMoreIConfigBase"); + + @Inject( + method = "getComment", + at = @At( + value = "RETURN" + ), + cancellable = true + ) + private void useI18nComment(CallbackInfoReturnable cir) { + if (Configs.backportI18nSupport.getBooleanValue()) { + cir.setReturnValue(MiscUtil.getTranslatedOrFallback("config.comment." + this.getName().toLowerCase(), + cir.getReturnValue())); + } + } + + @Intrinsic + @Override + public String getConfigGuiDisplayName() { + return IConfigBase.super.getConfigGuiDisplayName(); + } + + @SuppressWarnings({"MixinAnnotationTarget", "UnresolvedMixinReference"}) + @Inject( + method = "getConfigGuiDisplayName", + at = @At( + value = "HEAD" + ), + cancellable = true + ) + private void patchGetConfigGuiDisplayName(CallbackInfoReturnable cir) { + if (MixinConfigBase.masa_gadget$tweakerMoreIConfigBaseClass + .filter(clazz -> clazz.isInstance(this)).isPresent()) { + return; + } + + if (Configs.backportI18nSupport.getBooleanValue()) { + cir.setReturnValue(I18n.translateOrFallback("config.name." + this.getName().toLowerCase(), + this.getName())); + } + } +} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/fastSwitchMasaConfigGui/MixinGuiConfigBase.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/fastSwitchMasaConfigGui/MixinGuiConfigBase.java new file mode 100644 index 00000000..8a7e374f --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/fastSwitchMasaConfigGui/MixinGuiConfigBase.java @@ -0,0 +1,93 @@ +package com.plusls.MasaGadget.mixin.mod_tweak.malilib.fastSwitchMasaConfigGui; + +import com.plusls.MasaGadget.ModInfo; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.api.gui.MasaGadgetDropdownList; +import com.plusls.MasaGadget.impl.mod_tweak.malilib.fastSwitchMasaConfigGui.FastMasaGuiSwitcher; +import fi.dy.masa.malilib.gui.GuiBase; +import fi.dy.masa.malilib.gui.GuiConfigsBase; +import fi.dy.masa.malilib.gui.GuiListBase; +import fi.dy.masa.malilib.gui.widgets.WidgetConfigOption; +import fi.dy.masa.malilib.gui.widgets.WidgetListConfigOptions; +import fi.dy.masa.malilib.interfaces.IStringValue; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; +import top.hendrixshen.magiclib.impl.malilib.config.gui.SelectorDropDownList; + +//#if MC > 11904 +import net.minecraft.client.gui.GuiGraphics; +//#elseif MC > 11404 +//$$ import com.mojang.blaze3d.vertex.PoseStack; +//#endif + +@Dependencies(require = @Dependency(ModInfo.MODMENU_MOD_ID)) +@Mixin(value = GuiConfigsBase.class, remap = false, priority = 1100) +public abstract class MixinGuiConfigBase extends GuiListBase implements MasaGadgetDropdownList { + protected MixinGuiConfigBase(int listX, int listY) { + super(listX, listY); + } + + @Unique + private SelectorDropDownList masa_gadget$masaModGuiList; + + @SuppressWarnings({"MixinAnnotationTarget", "UnresolvedMixinReference"}) + @Inject( + method = "initGui", + at = @At( + value = "RETURN" + ) + ) + public void postInitGui(CallbackInfo ci) { + if (Configs.fastSwitchMasaConfigGui.getBooleanValue()) { + this.masa_gadget$masaModGuiList = new SelectorDropDownList<>( + this.width - 111, 10, 100, 16, 200, 5, + FastMasaGuiSwitcher.getInstance().getModNameList()); + this.masa_gadget$masaModGuiList.setSelectedEntry(FastMasaGuiSwitcher.getInstance().getModName(this.getClass())); + this.masa_gadget$masaModGuiList.setEntryChangeListener(entry -> + GuiBase.openGui(FastMasaGuiSwitcher.getInstance().getConfigScreenFactory(entry) + .create(this.getParent()))); + this.addWidget(this.masa_gadget$masaModGuiList); + } + } + + @Override + public void masa_gad_get$renderHovered( + //#if MC > 11904 + GuiGraphics poseStackOrGuiGraphics, + //#elseif MC > 11502 + //$$ PoseStack poseStackOrGuiGraphics, + //#endif + int mouseX, + int mouseY + ) { + if (this.masa_gadget$masaModGuiList == null) { + return; + } + + this.masa_gadget$masaModGuiList.render( + mouseX, + mouseY, + false + //#if MC > 11502 + , poseStackOrGuiGraphics + //#endif + ); + + if (this.masa_gadget$masaModGuiList.isMouseOver(mouseX, mouseY)) { + this.hoveredWidget = this.masa_gadget$masaModGuiList; + } + + this.drawHoveredWidget( + mouseX, + mouseY + //#if MC > 11502 + , poseStackOrGuiGraphics + //#endif + ); + } +} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/fastSwitchMasaConfigGui/MixinWidgetListBase.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/fastSwitchMasaConfigGui/MixinWidgetListBase.java new file mode 100644 index 00000000..aa99df90 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/fastSwitchMasaConfigGui/MixinWidgetListBase.java @@ -0,0 +1,148 @@ +/* + * This file is part of the TweakerMore project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 Fallen_Breath and contributors + * + * TweakerMore is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * TweakerMore is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with TweakerMore. If not, see . + */ + +package com.plusls.MasaGadget.mixin.mod_tweak.malilib.fastSwitchMasaConfigGui; + +import com.plusls.MasaGadget.api.gui.MasaGadgetDropdownList; +import fi.dy.masa.malilib.gui.GuiConfigsBase; +import fi.dy.masa.malilib.gui.widgets.WidgetListBase; +import fi.dy.masa.malilib.gui.widgets.WidgetListConfigOptions; +import fi.dy.masa.malilib.gui.widgets.WidgetListEntryBase; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import top.hendrixshen.magiclib.mixin.malilib.accessor.WidgetListConfigOptionsAccessor; +import top.hendrixshen.magiclib.util.MiscUtil; + +//#if MC > 11904 +import net.minecraft.client.gui.GuiGraphics; +//#elseif MC > 11502 +//$$ import com.mojang.blaze3d.vertex.PoseStack; +//#endif + +/** + * Reference to TweakerMore + */ +@Mixin(value = WidgetListBase.class, remap = false, priority = 1100) +public abstract class MixinWidgetListBase> { + // To make sure it only once gets rendered + @Unique + private boolean masa_gadget_mod$shouldRenderMagicConfigGuiDropDownList = false; + + @SuppressWarnings("ConstantConditions") + @Unique + private void masa_gadget_mod$drawMagicConfigGuiDropDownListAgain( + //#if MC > 11904 + GuiGraphics poseStackOrGuiGraphics, + //#elseif MC > 11502 + //$$ PoseStack poseStackOrGuiGraphics, + //#endif + int mouseX, + int mouseY + ) { + if (this.masa_gadget_mod$shouldRenderMagicConfigGuiDropDownList) { + if (!(MiscUtil.cast(this) instanceof WidgetListConfigOptions)) { + return; + } + + GuiConfigsBase guiConfig = ((WidgetListConfigOptionsAccessor) this).magiclib$getParent(); + + // Render it again to make sure it's on the top but below hovering widgets. + ((MasaGadgetDropdownList) guiConfig).masa_gad_get$renderHovered( + //#if MC > 11600 + poseStackOrGuiGraphics, + //#endif + mouseX, + mouseY + ); + + this.masa_gadget_mod$shouldRenderMagicConfigGuiDropDownList = false; + } + } + + @Inject( + method = "drawContents", + at = @At( + "HEAD" + ) + ) + private void drawMagicConfigGuiDropDownListSetFlag(CallbackInfo ci) { + this.masa_gadget_mod$shouldRenderMagicConfigGuiDropDownList = true; + } + + //#if MC < 11904 + //$$ @Inject( + //$$ method = "drawContents", + //$$ at = @At( + //$$ value = "INVOKE", + //#if MC > 11502 + //$$ target = "Lfi/dy/masa/malilib/gui/widgets/WidgetBase;postRenderHovered(IIZLcom/mojang/blaze3d/vertex/PoseStack;)V" + //#else + //$$ target = "Lfi/dy/masa/malilib/gui/widgets/WidgetBase;postRenderHovered(IIZ)V" + //#endif + //$$ ) + //$$ ) + //$$ private void drawMagicConfigGuiDropDownListAgainBeforeHover( + //$$ //#if MC > 11502 + //$$ PoseStack poseStack, + //$$ //#endif + //$$ int mouseX, + //$$ int mouseY, + //$$ float partialTicks, + //$$ CallbackInfo ci + //$$ ) { + //$$ this.masa_gadget_mod$drawMagicConfigGuiDropDownListAgain( + //$$ //#if MC > 11502 + //$$ poseStack, + //$$ //#endif + //$$ mouseX, + //$$ mouseY + //$$ ); + //$$ } + //#endif + + @Inject( + method = "drawContents", + at = @At( + value = "TAIL" + ) + ) + private void drawMagicConfigGuiDropDownListAgainAfterHover( + //#if MC > 11904 + GuiGraphics poseStackOrGuiGraphics, + //#elseif MC > 11502 + //$$ PoseStack poseStackOrGuiGraphics, + //#endif + int mouseX, + int mouseY, + float partialTicks, + CallbackInfo ci + ) { + this.masa_gadget_mod$drawMagicConfigGuiDropDownListAgain( + //#if MC > 11502 + poseStackOrGuiGraphics, + //#endif + mouseX, + mouseY + ); + } +} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/favoritesSupport/MixinGuiConfigBase.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/favoritesSupport/MixinGuiConfigBase.java new file mode 100644 index 00000000..4a1061d6 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/favoritesSupport/MixinGuiConfigBase.java @@ -0,0 +1,57 @@ +package com.plusls.MasaGadget.mixin.mod_tweak.malilib.favoritesSupport; + +import com.plusls.MasaGadget.SharedConstants; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.impl.mod_tweak.malilib.favoritesSupport.MalilibFavoritesButton; +import com.plusls.MasaGadget.impl.mod_tweak.malilib.favoritesSupport.MalilibFavoritesData; +import fi.dy.masa.malilib.gui.GuiConfigsBase; +import fi.dy.masa.malilib.gui.GuiListBase; +import fi.dy.masa.malilib.gui.widgets.WidgetConfigOption; +import fi.dy.masa.malilib.gui.widgets.WidgetListConfigOptions; +import org.spongepowered.asm.mixin.Intrinsic; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import top.hendrixshen.magiclib.api.i18n.I18n; +import top.hendrixshen.magiclib.util.collect.ValueContainer; + +@Mixin(value = GuiConfigsBase.class, remap = false) +public abstract class MixinGuiConfigBase extends GuiListBase { + protected MixinGuiConfigBase(int listX, int listY) { + super(listX, listY); + } + + @Intrinsic + @Override + public void initGui() { + super.initGui(); + } + + @SuppressWarnings({"MixinAnnotationTarget" ,"UnresolvedMixinReference"}) + @Inject( + method = "initGui", + at = @At( + value = "RETURN" + ) + ) + public void postInitGui(CallbackInfo ci) { + if (!Configs.favoritesSupport.getBooleanValue()) { + return; + } + + MalilibFavoritesButton favoritesButton = MalilibFavoritesButton.create( + this.width - 132, 10, MalilibFavoritesData.getInstance().isFilterSwitch(), + status -> { + MalilibFavoritesData.getInstance().setFilterSwitch(status); + ValueContainer.ofNullable(this.getListWidget()).ifPresent(w -> { + w.getScrollbar().setValue(0); + w.refreshEntries(); + }); + SharedConstants.getConfigHandler().save(); + }, + status -> status ? I18n.tr("masa_gadget_mod.message.showAllOptions") : + I18n.tr("masa_gadget_mod.message.showFavorite")); + this.addWidget(favoritesButton); + } +} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/malilib/favorites/MixinWidgetConfigOption.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/favoritesSupport/MixinWidgetConfigOption.java similarity index 53% rename from src/main/java/com/plusls/MasaGadget/mixin/malilib/favorites/MixinWidgetConfigOption.java rename to src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/favoritesSupport/MixinWidgetConfigOption.java index 5274074c..2c9aabcb 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/malilib/favorites/MixinWidgetConfigOption.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/favoritesSupport/MixinWidgetConfigOption.java @@ -1,9 +1,10 @@ -package com.plusls.MasaGadget.mixin.malilib.favorites; +package com.plusls.MasaGadget.mixin.mod_tweak.malilib.favoritesSupport; -import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.gui.MasaGadgetIcons; -import com.plusls.MasaGadget.gui.WidgetIconToggleButton; +import com.google.common.collect.Sets; +import com.plusls.MasaGadget.SharedConstants; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.impl.mod_tweak.malilib.favoritesSupport.MalilibFavoritesButton; +import com.plusls.MasaGadget.impl.mod_tweak.malilib.favoritesSupport.MalilibFavoritesData; import fi.dy.masa.malilib.config.IConfigBase; import fi.dy.masa.malilib.gui.GuiConfigsBase; import fi.dy.masa.malilib.gui.widgets.WidgetConfigOption; @@ -15,9 +16,9 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import top.hendrixshen.magiclib.language.api.I18n; +import top.hendrixshen.magiclib.api.i18n.I18n; -import java.util.HashSet; +import java.util.Set; @Mixin(value = WidgetConfigOption.class, remap = false) public abstract class MixinWidgetConfigOption extends WidgetConfigOptionBase { @@ -25,34 +26,42 @@ public MixinWidgetConfigOption(int x, int y, int width, int height, WidgetListCo super(x, y, width, height, parent, entry, listIndex); } - @Inject(method = "addConfigOption", at = @At(value = "HEAD")) + @Inject( + method = "addConfigOption", + at = @At( + value = "HEAD" + ) + ) private void addFavoritesButton(int x, int y, float zLevel, int labelWidth, int configWidth, IConfigBase config, CallbackInfo ci) { - if (!Configs.favoritesSupport) { + if (!Configs.favoritesSupport.getBooleanValue()) { return; } Screen screen = Minecraft.getInstance().screen; + if (!(screen instanceof GuiConfigsBase)) { return; } + String modId = ((GuiConfigsBase) screen).getModId(); - this.addWidget(new WidgetIconToggleButton(x + labelWidth + configWidth + 25 + - this.getStringWidth(I18n.get("malilib.gui.button.reset.caps")), y + 3, - MasaGadgetIcons.FAVORITE, Configs.FAVORITES.computeIfAbsent(modId, k -> new HashSet<>()).contains(config.getName()), + this.addWidget(MalilibFavoritesButton.create(x + labelWidth + configWidth + 25 + + this.getStringWidth(I18n.tr("malilib.gui.button.reset.caps")), y + 3, + MalilibFavoritesData.getInstance().getFavorites() + .computeIfAbsent(modId, k -> Sets.newHashSet()).contains(config.getName()), status -> { - HashSet modFavorites = Configs.FAVORITES.computeIfAbsent(modId, k -> new HashSet<>()); + Set modFavorites = MalilibFavoritesData.getInstance().getFavorites() + .computeIfAbsent(modId, k -> Sets.newHashSet()); + if (status) { modFavorites.add(config.getName()); } else { modFavorites.remove(config.getName()); } - ModInfo.configHandler.saveToFile(); - ModInfo.configHandler.loadFromFile(); - }, - status -> status ? ModInfo.translate("message.cancelFavorite") : ModInfo.translate("message.setFavorite"), - widgetIconToggleButton -> Configs.favoritesSupport)); - + SharedConstants.getConfigHandler().save(); + }, + status -> status ? I18n.tr("masa_gadget_mod.message.cancelFavorite") : + I18n.tr("masa_gadget_mod.message.setFavorite"))); } } diff --git a/src/main/java/com/plusls/MasaGadget/mixin/malilib/favorites/MixinWidgetListConfigOptions.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/favoritesSupport/MixinWidgetListConfigOptions.java similarity index 64% rename from src/main/java/com/plusls/MasaGadget/mixin/malilib/favorites/MixinWidgetListConfigOptions.java rename to src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/favoritesSupport/MixinWidgetListConfigOptions.java index eba85808..56f0e878 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/malilib/favorites/MixinWidgetListConfigOptions.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/favoritesSupport/MixinWidgetListConfigOptions.java @@ -1,7 +1,8 @@ -package com.plusls.MasaGadget.mixin.malilib.favorites; +package com.plusls.MasaGadget.mixin.mod_tweak.malilib.favoritesSupport; -import com.google.common.collect.ImmutableList; -import com.plusls.MasaGadget.config.Configs; +import com.google.common.collect.Sets; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.impl.mod_tweak.malilib.favoritesSupport.MalilibFavoritesData; import fi.dy.masa.malilib.config.IConfigBase; import fi.dy.masa.malilib.gui.GuiConfigsBase; import fi.dy.masa.malilib.gui.widgets.WidgetConfigOption; @@ -15,42 +16,57 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.Collection; -import java.util.HashSet; +import java.util.Collections; import java.util.List; @Mixin(value = WidgetListConfigOptions.class, remap = false) public abstract class MixinWidgetListConfigOptions extends WidgetListConfigOptionsBase { - public MixinWidgetListConfigOptions(int x, int y, int width, int height, int configWidth) { super(x, y, width, height, configWidth); } - @Inject(method = "getEntryStringsForFilter*", at = @At(value = "HEAD"), cancellable = true) + @Inject( + method = "getEntryStringsForFilter*", + at = @At( + value = "HEAD" + ), + cancellable = true + ) private void filterFavorites(GuiConfigsBase.ConfigOptionWrapper entry, CallbackInfoReturnable> cir) { - if (Configs.favoritesSupport && Configs.favoritesFilter) { + if (Configs.favoritesSupport.getBooleanValue() && MalilibFavoritesData.getInstance().isFilterSwitch()) { IConfigBase config = entry.getConfig(); Screen screen = Minecraft.getInstance().screen; + if (!(screen instanceof GuiConfigsBase)) { return; } + String modId = ((GuiConfigsBase) screen).getModId(); - if (config == null || !Configs.FAVORITES.computeIfAbsent(modId, k -> new HashSet<>()).contains(config.getName())) { - cir.setReturnValue(ImmutableList.of("")); + + if (config == null || !MalilibFavoritesData.getInstance().getFavorites() + .computeIfAbsent(modId, k -> Sets.newHashSet()).contains(config.getName())) { + cir.setReturnValue(Collections.emptyList()); } } } + // TODO: Compat @Override protected void addNonFilteredContents(Collection placements) { - if (Configs.favoritesSupport && Configs.favoritesFilter) { + if (Configs.favoritesSupport.getBooleanValue() && MalilibFavoritesData.getInstance().isFilterSwitch()) { Screen screen = Minecraft.getInstance().screen; + if (!(screen instanceof GuiConfigsBase)) { return; } + String modId = ((GuiConfigsBase) screen).getModId(); + for (GuiConfigsBase.ConfigOptionWrapper configWrapper : placements) { IConfigBase config = configWrapper.getConfig(); - if (config != null && Configs.FAVORITES.computeIfAbsent(modId, k -> new HashSet<>()).contains(config.getName())) { + + if (config != null && MalilibFavoritesData.getInstance().getFavorites() + .computeIfAbsent(modId, k -> Sets.newHashSet()).contains(config.getName())) { this.listContents.add(configWrapper); } } diff --git a/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/fixConfigWidgetWidth/MixinWidgetListConfigOptions.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/fixConfigWidgetWidth/MixinWidgetListConfigOptions.java new file mode 100644 index 00000000..0bb3b7b7 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/fixConfigWidgetWidth/MixinWidgetListConfigOptions.java @@ -0,0 +1,74 @@ +package com.plusls.MasaGadget.mixin.mod_tweak.malilib.fixConfigWidgetWidth; + +import com.plusls.MasaGadget.game.Configs; +import fi.dy.masa.malilib.gui.GuiConfigsBase; +import fi.dy.masa.malilib.gui.widgets.WidgetConfigOption; +import fi.dy.masa.malilib.gui.widgets.WidgetListConfigOptions; +import fi.dy.masa.malilib.gui.widgets.WidgetListConfigOptionsBase; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; +import top.hendrixshen.magiclib.impl.malilib.config.gui.MagicConfigGui; +import top.hendrixshen.magiclib.util.ReflectionUtil; +import top.hendrixshen.magiclib.util.collect.ValueContainer; + +import java.util.List; +import java.util.Objects; + +@Dependencies(require = @Dependency(value = "minecraft", versionPredicates = "<=1.17.1")) +@Mixin(value = WidgetListConfigOptions.class, remap = false) +public abstract class MixinWidgetListConfigOptions extends WidgetListConfigOptionsBase { + @Unique + private static final ValueContainer> masa_gadget$tweakerMoreIConfigBaseClass = ReflectionUtil + .getClass("me.fallenbreath.tweakermore.gui.TweakerMoreConfigGui"); + + @Shadow + @Final + protected GuiConfigsBase parent; + + public MixinWidgetListConfigOptions(int x, int y, int width, int height, int configWidth) { + super(x, y, width, height, configWidth); + } + + @Inject( + method = "getMaxNameLengthWrapped", + at = @At( + value = "INVOKE", + target = "Ljava/util/List;iterator()Ljava/util/Iterator;" + ), + cancellable = true + ) + private void fixWidth(List wrappers, CallbackInfoReturnable cir) { + // MagicConfigGui was fixed by magiclib. + if (this.parent instanceof MagicConfigGui) { + return; + } + + // TweakerMore manager it ui by itself. + if (MixinWidgetListConfigOptions.masa_gadget$tweakerMoreIConfigBaseClass + .filter(clazz -> clazz.isInstance(this.parent)).isPresent()) { + return; + } + + if (!Configs.fixConfigWidgetWidth.getBooleanValue()) { + return; + } + + int maxWidth = 0; + + for (GuiConfigsBase.ConfigOptionWrapper wrapper : wrappers) { + if (wrapper.getType() == GuiConfigsBase.ConfigOptionWrapper.Type.CONFIG) { + maxWidth = Math.max(maxWidth, this.getStringWidth( + Objects.requireNonNull(wrapper.getConfig()).getConfigGuiDisplayName())); + } + } + + cir.setReturnValue(maxWidth); + } +} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/malilib/fixGetInventoryType/MixinInventoryOverlay.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/fixGetInventoryType/MixinInventoryOverlay.java similarity index 51% rename from src/main/java/com/plusls/MasaGadget/mixin/malilib/fixGetInventoryType/MixinInventoryOverlay.java rename to src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/fixGetInventoryType/MixinInventoryOverlay.java index c5941d7e..ef33da19 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/malilib/fixGetInventoryType/MixinInventoryOverlay.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/fixGetInventoryType/MixinInventoryOverlay.java @@ -1,6 +1,6 @@ -package com.plusls.MasaGadget.mixin.malilib.fixGetInventoryType; +package com.plusls.MasaGadget.mixin.mod_tweak.malilib.fixGetInventoryType; -import com.plusls.MasaGadget.config.Configs; +import com.plusls.MasaGadget.game.Configs; import fi.dy.masa.malilib.render.InventoryOverlay; import net.minecraft.world.Container; import net.minecraft.world.item.BlockItem; @@ -8,35 +8,48 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.AbstractFurnaceBlock; import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity; +import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; -@Dependencies(and = @Dependency(value = "minecraft", versionPredicate = "<=1.17.1")) +@Dependencies(require = @Dependency(value = "minecraft", versionPredicates = "<=1.17.1")) @Mixin(value = InventoryOverlay.class, remap = false) public class MixinInventoryOverlay { - - @Inject(method = "getInventoryType(Lnet/minecraft/world/Container;)Lfi/dy/masa/malilib/render/InventoryOverlay$InventoryRenderType;", - at = @At(value = "RETURN"), cancellable = true, remap = true) + @Inject( + method = "getInventoryType(Lnet/minecraft/world/Container;)Lfi/dy/masa/malilib/render/InventoryOverlay$InventoryRenderType;", + at = @At( + value = "RETURN" + ), + cancellable = true, + remap = true + ) private static void checkAbstractFurnaceBlockEntity(Container inv, CallbackInfoReturnable cir) { - if (Configs.fixGetInventoryType && - cir.getReturnValue() == InventoryOverlay.InventoryRenderType.GENERIC && inv instanceof AbstractFurnaceBlockEntity) { + if (Configs.fixGetInventoryType.getBooleanValue() && + cir.getReturnValue() == InventoryOverlay.InventoryRenderType.GENERIC && + inv instanceof AbstractFurnaceBlockEntity) { cir.setReturnValue(InventoryOverlay.InventoryRenderType.FURNACE); } } - @Inject(method = "getInventoryType(Lnet/minecraft/world/item/ItemStack;)Lfi/dy/masa/malilib/render/InventoryOverlay$InventoryRenderType;", - at = @At(value = "RETURN"), cancellable = true, remap = true) - private static void checkAbstractFurnaceBlockEntity(ItemStack stack, CallbackInfoReturnable cir) { + @Inject( + method = "getInventoryType(Lnet/minecraft/world/item/ItemStack;)Lfi/dy/masa/malilib/render/InventoryOverlay$InventoryRenderType;", + at = @At( + value = "RETURN" + ), + cancellable = true, + remap = true + ) + private static void checkAbstractFurnaceBlockEntity(@NotNull ItemStack stack, CallbackInfoReturnable cir) { Item item = stack.getItem(); - if (Configs.fixGetInventoryType && + + if (Configs.fixGetInventoryType.getBooleanValue() && cir.getReturnValue() == InventoryOverlay.InventoryRenderType.GENERIC && - item instanceof BlockItem && - ((BlockItem) item).getBlock() instanceof AbstractFurnaceBlock) { + item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof AbstractFurnaceBlock) { cir.setReturnValue(InventoryOverlay.InventoryRenderType.FURNACE); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/malilib/fixSearchbarHotkeyInput/MixinGuiBase.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/fixSearchbarHotkeyInput/MixinGuiBase.java similarity index 56% rename from src/main/java/com/plusls/MasaGadget/mixin/malilib/fixSearchbarHotkeyInput/MixinGuiBase.java rename to src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/fixSearchbarHotkeyInput/MixinGuiBase.java index fc894744..b61904e8 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/malilib/fixSearchbarHotkeyInput/MixinGuiBase.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/fixSearchbarHotkeyInput/MixinGuiBase.java @@ -1,6 +1,6 @@ -package com.plusls.MasaGadget.mixin.malilib.fixSearchbarHotkeyInput; +package com.plusls.MasaGadget.mixin.mod_tweak.malilib.fixSearchbarHotkeyInput; -import com.plusls.MasaGadget.config.Configs; +import com.plusls.MasaGadget.game.Configs; import fi.dy.masa.malilib.gui.GuiBase; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -15,23 +15,38 @@ public class MixinGuiBase { @Shadow private int keyInputCount; @Unique - private long openTime; + private long masa_gadget$openTime; - @Inject(method = "init", at = @At(value = "HEAD"), remap = true) + @Inject( + method = "init", + at = @At( + value = "HEAD" + ), + remap = true + ) private void preInit(CallbackInfo ci) { - if (!Configs.fixSearchbarHotkeyInput) { + if (!Configs.fixSearchbarHotkeyInput.getBooleanValue()) { return; } - this.openTime = System.nanoTime(); + + this.masa_gadget$openTime = System.nanoTime(); this.keyInputCount = 0; } - @Inject(method = "charTyped", at = @At(value = "HEAD"), cancellable = true, remap = true) + @Inject( + method = "charTyped", + at = @At( + value = "HEAD" + ), + cancellable = true, + remap = true + ) private void preCharTyped(char charIn, int modifiers, CallbackInfoReturnable cir) { - if (!Configs.fixSearchbarHotkeyInput) { + if (!Configs.fixSearchbarHotkeyInput.getBooleanValue()) { return; } - if (this.keyInputCount <= 0 && System.nanoTime() - this.openTime <= 100000000) { + + if (this.keyInputCount <= 0 && System.nanoTime() - this.masa_gadget$openTime <= 100000000) { this.keyInputCount++; cir.setReturnValue(true); } diff --git a/src/main/java/com/plusls/MasaGadget/mixin/malilib/optimizeConfigWidgetSearch/MixinWidgetListConfigOptions.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/optimizeConfigWidgetSearch/MixinWidgetListConfigOptions.java similarity index 80% rename from src/main/java/com/plusls/MasaGadget/mixin/malilib/optimizeConfigWidgetSearch/MixinWidgetListConfigOptions.java rename to src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/optimizeConfigWidgetSearch/MixinWidgetListConfigOptions.java index fe25318e..e92eaaab 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/malilib/optimizeConfigWidgetSearch/MixinWidgetListConfigOptions.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/optimizeConfigWidgetSearch/MixinWidgetListConfigOptions.java @@ -1,7 +1,7 @@ -package com.plusls.MasaGadget.mixin.malilib.optimizeConfigWidgetSearch; +package com.plusls.MasaGadget.mixin.mod_tweak.malilib.optimizeConfigWidgetSearch; import com.google.common.collect.ImmutableList; -import com.plusls.MasaGadget.config.Configs; +import com.plusls.MasaGadget.game.Configs; import fi.dy.masa.malilib.config.IConfigBase; import fi.dy.masa.malilib.config.IConfigResettable; import fi.dy.masa.malilib.gui.GuiConfigsBase; @@ -12,12 +12,12 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; import java.util.List; -@Dependencies(and = @Dependency(value = "minecraft", versionPredicate = "<=1.17.1")) +@Dependencies(require = @Dependency(value = "minecraft", versionPredicates = "<=1.17.1")) @Mixin(value = WidgetListConfigOptions.class, remap = false) public abstract class MixinWidgetListConfigOptions extends WidgetListConfigOptionsBase { public MixinWidgetListConfigOptions(int x, int y, int width, int height, int configWidth) { @@ -26,9 +26,10 @@ public MixinWidgetListConfigOptions(int x, int y, int width, int height, int con @Inject(method = "getEntryStringsForFilter*", at = @At(value = "HEAD"), cancellable = true) private void preGetEntryStringsForFilter(GuiConfigsBase.ConfigOptionWrapper entry, CallbackInfoReturnable> cir) { - if (!Configs.optimizeConfigWidgetSearch) { + if (!Configs.optimizeConfigWidgetSearch.getBooleanValue()) { return; } + IConfigBase config = entry.getConfig(); if (config != null) { if (config instanceof IConfigResettable && ((IConfigResettable) config).isModified()) { @@ -39,14 +40,16 @@ private void preGetEntryStringsForFilter(GuiConfigsBase.ConfigOptionWrapper entr } } - - // fix upper case when search Disable Hotkeys + // TODO: Compat + // Fix upper case when search Disable Hotkeys @Override protected boolean matchesFilter(List entryStrings, String filterText) { - if (!Configs.optimizeConfigWidgetSearch) { + if (!Configs.optimizeConfigWidgetSearch.getBooleanValue()) { return super.matchesFilter(entryStrings, filterText); } + filterText = filterText.toLowerCase(); + if (filterText.isEmpty()) { return true; } @@ -56,6 +59,7 @@ protected boolean matchesFilter(List entryStrings, String filterText) { return true; } } + return false; } } \ No newline at end of file diff --git a/src/main/java/com/plusls/MasaGadget/mixin/malilib/showOriginalConfigName/MixinWidgetConfigOption.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/showOriginalConfigName/MixinWidgetConfigOption.java similarity index 63% rename from src/main/java/com/plusls/MasaGadget/mixin/malilib/showOriginalConfigName/MixinWidgetConfigOption.java rename to src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/showOriginalConfigName/MixinWidgetConfigOption.java index 4248c32f..345d3cc4 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/malilib/showOriginalConfigName/MixinWidgetConfigOption.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/showOriginalConfigName/MixinWidgetConfigOption.java @@ -1,7 +1,7 @@ -package com.plusls.MasaGadget.mixin.malilib.showOriginalConfigName; +package com.plusls.MasaGadget.mixin.mod_tweak.malilib.showOriginalConfigName; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.gui.ScalableWidgetLabel; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.impl.gui.ScalableWidgetLabel; import com.plusls.MasaGadget.util.MiscUtil; import fi.dy.masa.malilib.config.IConfigBase; import fi.dy.masa.malilib.gui.GuiConfigsBase; @@ -9,27 +9,38 @@ import fi.dy.masa.malilib.gui.widgets.WidgetConfigOptionBase; import fi.dy.masa.malilib.gui.widgets.WidgetLabel; import fi.dy.masa.malilib.gui.widgets.WidgetListConfigOptionsBase; +import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +// TODO: Rewrite. @Mixin(value = WidgetConfigOption.class, remap = false) public abstract class MixinWidgetConfigOption extends WidgetConfigOptionBase { - public MixinWidgetConfigOption(int x, int y, int width, int height, WidgetListConfigOptionsBase parent, GuiConfigsBase.ConfigOptionWrapper entry, int listIndex) { super(x, y, width, height, parent, entry, listIndex); } - @Inject(method = "addConfigOption", at = @At(value = "INVOKE", target = "Lfi/dy/masa/malilib/gui/widgets/WidgetConfigOption;addLabel(IIIII[Ljava/lang/String;)V", ordinal = 0, shift = At.Shift.AFTER)) - private void myAddLable(int x, int y, float zLevel, int labelWidth, int configWidth, IConfigBase config, CallbackInfo ci) { + @Inject( + method = "addConfigOption", + at = @At( + value = "INVOKE", + target = "Lfi/dy/masa/malilib/gui/widgets/WidgetConfigOption;addLabel(IIIII[Ljava/lang/String;)V", + ordinal = 0, + shift = At.Shift.AFTER + ) + ) + private void myAddLabel(int x, int y, float zLevel, int labelWidth, int configWidth, @NotNull IConfigBase config, CallbackInfo ci) { String displayName = MiscUtil.getStringWithoutFormat(config.getConfigGuiDisplayName()); - if (Configs.showOriginalConfigName && !displayName.equals(config.getName())) { + + if (Configs.showOriginalConfigName.getBooleanValue() && !displayName.equals(config.getName())) { if (this.subWidgets.get(this.subWidgets.size() - 1).getClass() == WidgetLabel.class) { this.subWidgets.remove(this.subWidgets.size() - 1); this.addLabel(x, y, width, height, -1, config.getConfigGuiDisplayName(), ""); ScalableWidgetLabel label = new ScalableWidgetLabel(x, y + 7, width, height, -1, - (float) Configs.showOriginalConfigNameScale, String.format("§7%s§r", config.getName())); + (float) Configs.showOriginalConfigNameScale.getDoubleValue(), + String.format("§7%s§r", config.getName())); this.addWidget(label); } } diff --git a/src/main/java/com/plusls/MasaGadget/mixin/malilib/showOriginalConfigName/MixinWidgetListConfigOptions.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/showOriginalConfigName/MixinWidgetListConfigOptions.java similarity index 54% rename from src/main/java/com/plusls/MasaGadget/mixin/malilib/showOriginalConfigName/MixinWidgetListConfigOptions.java rename to src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/showOriginalConfigName/MixinWidgetListConfigOptions.java index 4906035d..16a15031 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/malilib/showOriginalConfigName/MixinWidgetListConfigOptions.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/showOriginalConfigName/MixinWidgetListConfigOptions.java @@ -1,6 +1,6 @@ -package com.plusls.MasaGadget.mixin.malilib.showOriginalConfigName; +package com.plusls.MasaGadget.mixin.mod_tweak.malilib.showOriginalConfigName; -import com.plusls.MasaGadget.config.Configs; +import com.plusls.MasaGadget.game.Configs; import com.plusls.MasaGadget.util.MiscUtil; import fi.dy.masa.malilib.gui.GuiConfigsBase; import fi.dy.masa.malilib.gui.widgets.WidgetConfigOption; @@ -12,29 +12,45 @@ import java.util.Objects; +// TODO: Rewrite @Mixin(value = WidgetListConfigOptions.class, remap = false) public abstract class MixinWidgetListConfigOptions extends WidgetListConfigOptionsBase { - private GuiConfigsBase.ConfigOptionWrapper mg_getMaxNameLength_wrapped; + private GuiConfigsBase.ConfigOptionWrapper masa_gadget$maxLengthConfig; public MixinWidgetListConfigOptions(int x, int y, int width, int height, int configWidth) { super(x, y, width, height, configWidth); } - @ModifyVariable(method = "getMaxNameLengthWrapped", at = @At(value = "INVOKE", target = "Ljava/lang/Math;max(II)I", ordinal = 0), ordinal = 0) + @ModifyVariable( + method = "getMaxNameLengthWrapped", + at = @At( + value = "INVOKE", + target = "Ljava/lang/Math;max(II)I" + ) + ) private GuiConfigsBase.ConfigOptionWrapper getWrapper(GuiConfigsBase.ConfigOptionWrapper value) { - this.mg_getMaxNameLength_wrapped = value; + this.masa_gadget$maxLengthConfig = value; return value; } - @ModifyVariable(method = "getMaxNameLengthWrapped", at = @At(value = "INVOKE_ASSIGN", target = "Ljava/lang/Math;max(II)I", ordinal = 0), ordinal = 0) + @ModifyVariable( + method = "getMaxNameLengthWrapped", + at = @At( + value = "INVOKE_ASSIGN", + target = "Ljava/lang/Math;max(II)I" + ) + ) private int getWrapper(int width) { - if (Configs.showOriginalConfigName) { - String displayName = MiscUtil.getStringWithoutFormat(Objects.requireNonNull(mg_getMaxNameLength_wrapped.getConfig()).getConfigGuiDisplayName()); - String name = mg_getMaxNameLength_wrapped.getConfig().getName(); + if (Configs.showOriginalConfigName.getBooleanValue()) { + String displayName = MiscUtil.getStringWithoutFormat(Objects.requireNonNull( + this.masa_gadget$maxLengthConfig.getConfig()).getConfigGuiDisplayName()); + String name = this.masa_gadget$maxLengthConfig.getConfig().getName(); + if (!displayName.equals(name)) { - width = Math.max(width, (int) Math.ceil(this.getStringWidth(name) * Configs.showOriginalConfigNameScale)); + width = Math.max(width, (int) Math.ceil(this.getStringWidth(name) * Configs.showOriginalConfigNameScale.getDoubleValue())); } } + return width; } } diff --git a/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/minihud/backportI18nSupport/MixinInfoToggle.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/minihud/backportI18nSupport/MixinInfoToggle.java new file mode 100644 index 00000000..1362758b --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/minihud/backportI18nSupport/MixinInfoToggle.java @@ -0,0 +1,57 @@ +package com.plusls.MasaGadget.mixin.mod_tweak.minihud.backportI18nSupport; + +import com.plusls.MasaGadget.ModInfo; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.util.MiscUtil; +import fi.dy.masa.malilib.config.IHotkeyTogglable; +import fi.dy.masa.minihud.config.InfoToggle; +import org.spongepowered.asm.mixin.Intrinsic; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; +import top.hendrixshen.magiclib.api.i18n.I18n; + +@Dependencies(require = { + @Dependency(ModInfo.MINIHUD_MOD_ID), + @Dependency(value = "minecraft", versionPredicates = "<=1.17.1") +}) +@Mixin(value = InfoToggle.class, remap = false) +public abstract class MixinInfoToggle implements IHotkeyTogglable { + @Inject( + method = "getComment", + at = @At( + value = "RETURN" + ), + cancellable = true + ) + private void useI18nComment(CallbackInfoReturnable cir) { + if (Configs.backportI18nSupport.getBooleanValue()) { + cir.setReturnValue(MiscUtil.getTranslatedOrFallback("config.comment." + this.getName().toLowerCase(), + cir.getReturnValue())); + } + } + + @Intrinsic + @Override + public String getConfigGuiDisplayName() { + return IHotkeyTogglable.super.getConfigGuiDisplayName(); + } + + @SuppressWarnings({"MixinAnnotationTarget", "UnresolvedMixinReference"}) + @Inject( + method = "getConfigGuiDisplayName", + at = @At( + value = "HEAD" + ), + cancellable = true + ) + private void patchGetConfigGuiDisplayName(CallbackInfoReturnable cir) { + if (Configs.backportI18nSupport.getBooleanValue()) { + cir.setReturnValue(I18n.translateOrFallback("config.name." + this.getName().toLowerCase(), + this.getName())); + } + } +} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/minihud/backportI18nSupport/MixinRendererToggle.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/minihud/backportI18nSupport/MixinRendererToggle.java new file mode 100644 index 00000000..eaf3cae1 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/minihud/backportI18nSupport/MixinRendererToggle.java @@ -0,0 +1,55 @@ +package com.plusls.MasaGadget.mixin.mod_tweak.minihud.backportI18nSupport; + +import com.plusls.MasaGadget.ModInfo; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.util.MiscUtil; +import fi.dy.masa.malilib.config.IHotkeyTogglable; +import fi.dy.masa.minihud.config.RendererToggle; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; +import top.hendrixshen.magiclib.api.i18n.I18n; + +@Dependencies(require = { + @Dependency(ModInfo.MINIHUD_MOD_ID), + @Dependency(value = "minecraft", versionPredicates = "<=1.17.1") +}) +@Mixin(value = RendererToggle.class, remap = false) +public abstract class MixinRendererToggle implements IHotkeyTogglable { + @Inject( + method = "getComment", + at = @At( + value = "RETURN" + ), + cancellable = true + ) + private void useI18nComment(CallbackInfoReturnable cir) { + if (Configs.backportI18nSupport.getBooleanValue()) { + cir.setReturnValue(MiscUtil.getTranslatedOrFallback("config.comment." + this.getName().toLowerCase(), + cir.getReturnValue())); + } + } + + @Override + public String getConfigGuiDisplayName() { + return IHotkeyTogglable.super.getConfigGuiDisplayName(); + } + + @SuppressWarnings({"MixinAnnotationTarget", "UnresolvedMixinReference"}) + @Inject( + method = "getConfigGuiDisplayName", + at = @At( + value = "HEAD" + ), + cancellable = true + ) + private void patchGetConfigGuiDisplayName(CallbackInfoReturnable cir) { + if (Configs.backportI18nSupport.getBooleanValue()) { + cir.setReturnValue(I18n.translateOrFallback("config.name." + this.getName().toLowerCase(), + this.getName())); + } + } +} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/minihud/minihudI18n/MixinRenderHandler.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/minihud/minihudI18n/MixinRenderHandler.java similarity index 55% rename from src/main/java/com/plusls/MasaGadget/mixin/minihud/minihudI18n/MixinRenderHandler.java rename to src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/minihud/minihudI18n/MixinRenderHandler.java index 8094c084..1fbd3919 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/minihud/minihudI18n/MixinRenderHandler.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/minihud/minihudI18n/MixinRenderHandler.java @@ -1,25 +1,27 @@ -package com.plusls.MasaGadget.mixin.minihud.minihudI18n; +package com.plusls.MasaGadget.mixin.mod_tweak.minihud.minihudI18n; +import com.google.common.collect.Lists; import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; +import com.plusls.MasaGadget.game.Configs; import fi.dy.masa.minihud.event.RenderHandler; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.Redirect; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; -import top.hendrixshen.magiclib.language.api.I18n; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; +import top.hendrixshen.magiclib.api.i18n.I18n; -import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -@Dependencies(and = @Dependency(ModInfo.MINIHUD_MOD_ID)) +@Dependencies(require = @Dependency(ModInfo.MINIHUD_MOD_ID)) @Mixin(value = RenderHandler.class, remap = false) public class MixinRenderHandler { - private static final Pattern TOKEN_PATTERN = Pattern.compile("[\\w ]+: "); + @Unique + private static final Pattern masa_gadget$textPattern = Pattern.compile("[\\w ]+: "); @Redirect( method = "addLine(Lfi/dy/masa/minihud/config/InfoToggle;)V", @@ -28,12 +30,8 @@ public class MixinRenderHandler { target = "Ljava/lang/String;format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;" ) ) - private String onStringFormat(String format, Object[] args) { - if (Configs.minihudI18n) { - return I18n.get(format, args); - } else { - return String.format(format, args); - } + private String patchFormat(String format, Object[] args) { + return Configs.minihudI18n.getBooleanValue() ? I18n.tr(format, args) : String.format(format, args); } @ModifyVariable( @@ -43,21 +41,24 @@ private String onStringFormat(String format, Object[] args) { ), argsOnly = true ) - private String onAddLine(String string) { - if (!Configs.minihudI18n) { + private String patchLine(String string) { + if (!Configs.minihudI18n.getBooleanValue()) { return string; } - Matcher matcher = TOKEN_PATTERN.matcher(string); + Matcher matcher = masa_gadget$textPattern.matcher(string); int start = 0; - List keys = new ArrayList<>(); + List keys = Lists.newArrayList(); + while (matcher.find(start)) { keys.add(matcher.group()); start = matcher.end(); } + for (String key : keys) { - string = string.replace(key, I18n.get(key)); + string = string.replace(key, I18n.tr(key)); } + return string; } } \ No newline at end of file diff --git a/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/backportI18nSupport/MixinConfigBooleanClient.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/backportI18nSupport/MixinConfigBooleanClient.java new file mode 100644 index 00000000..f638de22 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/backportI18nSupport/MixinConfigBooleanClient.java @@ -0,0 +1,35 @@ +package com.plusls.MasaGadget.mixin.mod_tweak.tweakeroo.backportI18nSupport; + +import com.plusls.MasaGadget.ModInfo; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.util.MiscUtil; +import fi.dy.masa.tweakeroo.config.ConfigBooleanClient; +import org.spongepowered.asm.mixin.Dynamic; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; + +@Dependencies(require = { + @Dependency(ModInfo.TWEAKEROO_MOD_ID), + @Dependency(value = "minecraft", versionPredicates = "<=1.17.1") +}) +@Mixin(value = ConfigBooleanClient.class, remap = false) +public class MixinConfigBooleanClient { + @Dynamic + @Redirect( + method = "getConfigGuiDisplayName", + at = @At( + value = "INVOKE", + target = "Lfi/dy/masa/tweakeroo/config/ConfigBooleanClient;getName()Ljava/lang/String;" + ) + ) + private String i18nDisplayName(ConfigBooleanClient instance) { + if (Configs.backportI18nSupport.getBooleanValue()) { + return MiscUtil.getTranslatedOrFallback("config.name." + instance.getName().toLowerCase(), instance.getName()); + } else { + return instance.getName(); + } + } +} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/backportI18nSupport/MixinFeatureToggle.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/backportI18nSupport/MixinFeatureToggle.java new file mode 100644 index 00000000..82b21496 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/backportI18nSupport/MixinFeatureToggle.java @@ -0,0 +1,56 @@ +package com.plusls.MasaGadget.mixin.mod_tweak.tweakeroo.backportI18nSupport; + +import com.plusls.MasaGadget.ModInfo; +import com.plusls.MasaGadget.game.Configs; +import fi.dy.masa.malilib.config.IHotkeyTogglable; +import fi.dy.masa.tweakeroo.config.FeatureToggle; +import org.spongepowered.asm.mixin.Intrinsic; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; +import top.hendrixshen.magiclib.api.i18n.I18n; + +@Dependencies(require = { + @Dependency(ModInfo.TWEAKEROO_MOD_ID), + @Dependency(value = "minecraft", versionPredicates = "<=1.17.1") +}) +@Mixin(value = FeatureToggle.class, remap = false) +public abstract class MixinFeatureToggle implements IHotkeyTogglable { + @Inject( + method = "getComment", + at = @At( + value = "RETURN" + ), + cancellable = true + ) + private void useI18nComment(CallbackInfoReturnable cir) { + if (Configs.backportI18nSupport.getBooleanValue()) { + cir.setReturnValue(I18n.translateOrFallback("config.comment." + this.getName().toLowerCase(), + cir.getReturnValue())); + } + } + + @Intrinsic + @Override + public String getConfigGuiDisplayName() { + return IHotkeyTogglable.super.getConfigGuiDisplayName(); + } + + @SuppressWarnings({"MixinAnnotationTarget", "UnresolvedMixinReference"}) + @Inject( + method = "getConfigGuiDisplayName", + at = @At( + value = "HEAD" + ), + cancellable = true + ) + private void patchGetConfigGuiDisplayName(CallbackInfoReturnable cir) { + if (Configs.backportI18nSupport.getBooleanValue()) { + cir.setReturnValue(I18n.translateOrFallback("config.name." + this.getName().toLowerCase(), + this.getName())); + } + } +} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/handRestockCrafting/MixinInventoryUtils.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/handRestockCrafting/MixinInventoryUtils.java new file mode 100644 index 00000000..6f3baf1e --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/handRestockCrafting/MixinInventoryUtils.java @@ -0,0 +1,53 @@ +package com.plusls.MasaGadget.mixin.mod_tweak.tweakeroo.handRestockCrafting; + +import com.plusls.MasaGadget.ModInfo; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.util.RestockUtil; +import fi.dy.masa.tweakeroo.util.InventoryUtils; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; + +@Dependencies(require = { + @Dependency(ModInfo.TWEAKEROO_MOD_ID), + @Dependency(ModInfo.ITEMSCROLLER_MOD_ID) +}) +@Mixin(value = InventoryUtils.class, remap = false) +public class MixinInventoryUtils { + @Inject( + method = "restockNewStackToHand", + at = @At( + "RETURN" + ), + locals = LocalCapture.CAPTURE_FAILHARD + ) + private static void restockOnFailed(Player player, InteractionHand hand, ItemStack itemStack, + boolean allowHotbar, CallbackInfo ci, int slotWithItem) { + if (slotWithItem == -1 && Configs.restockWithCrafting.getBooleanValue()) { + RestockUtil.tryCraftingRestocking(player, hand, itemStack); + } + } + + @Inject( + method = "preRestockHand", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/Minecraft;getInstance()Lnet/minecraft/client/Minecraft;", + remap = true + ), + locals = LocalCapture.CAPTURE_FAILHARD + ) + private static void PreRestockOnFailed(Player player, InteractionHand hand, + boolean stackSlot, CallbackInfo ci, ItemStack stackHand) { + if (Configs.restockWithCrafting.getBooleanValue()) { + RestockUtil.tryCraftingRestocking(player, hand, stackHand); + } + } +} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportPlayer/MixinRenderUtils.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/inventoryPreviewSupportPlayer/MixinRenderUtils.java similarity index 54% rename from src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportPlayer/MixinRenderUtils.java rename to src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/inventoryPreviewSupportPlayer/MixinRenderUtils.java index 04031809..bd7fc40b 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportPlayer/MixinRenderUtils.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/inventoryPreviewSupportPlayer/MixinRenderUtils.java @@ -1,8 +1,8 @@ -package com.plusls.MasaGadget.mixin.tweakeroo.inventoryPreviewSupportPlayer; +package com.plusls.MasaGadget.mixin.mod_tweak.tweakeroo.inventoryPreviewSupportPlayer; import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.util.HitResultUtil; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.impl.generic.HitResultHandler; import fi.dy.masa.malilib.render.InventoryOverlay; import fi.dy.masa.malilib.util.GuiUtils; import fi.dy.masa.tweakeroo.renderer.RenderUtils; @@ -12,10 +12,12 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.DyeColor; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyVariable; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; +import top.hendrixshen.magiclib.api.compat.minecraft.world.entity.player.PlayerCompat; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; //#if MC > 11904 import net.minecraft.client.gui.GuiGraphics; @@ -23,30 +25,41 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; //#endif -@Dependencies(and = @Dependency(ModInfo.TWEAKEROO_MOD_ID)) +@Dependencies(require = @Dependency(ModInfo.TWEAKEROO_MOD_ID)) @Mixin(value = RenderUtils.class, remap = false) public abstract class MixinRenderUtils { //#if MC > 11904 + @Unique private static GuiGraphics masa_gadget$gui; - @Inject(method = "renderInventoryOverlay", at = @At("HEAD")) + @Inject( + method = "renderInventoryOverlay", + at = @At( + value = "HEAD" + ) + ) private static void intercept(Minecraft mc, GuiGraphics gui, CallbackInfo ci) { - masa_gadget$gui = gui; + MixinRenderUtils.masa_gadget$gui = gui; } //#endif - @ModifyVariable(method = "renderInventoryOverlay", - at = @At(value = "INVOKE", + @ModifyVariable( + method = "renderInventoryOverlay", + at = @At( + value = "INVOKE", target = "Lfi/dy/masa/malilib/util/GuiUtils;getScaledWindowWidth()I", - ordinal = 0, remap = false), ordinal = 0) + remap = false + ) + ) private static Container modifyInv(Container inv) { Container ret = inv; - Entity traceEntity = HitResultUtil.getHitEntity(); - if (Configs.inventoryPreviewSupportPlayer && ret == null && - traceEntity instanceof Player) { - Player playerEntity = (Player) traceEntity; - ret = playerEntity.getInventory(); + Entity traceEntity = HitResultHandler.getInstance().getHitEntity().orElse(null); + if (Configs.inventoryPreviewSupportPlayer.getBooleanValue() && + ret == null && traceEntity instanceof Player) { + Player player = (Player) traceEntity; + PlayerCompat playerCompat = PlayerCompat.of(player); + ret = playerCompat.getInventory(); int x = GuiUtils.getScaledWindowWidth() / 2 - 88; int y = GuiUtils.getScaledWindowHeight() / 2 + 10; int slotOffsetX = 8; @@ -54,17 +67,24 @@ private static Container modifyInv(Container inv) { InventoryOverlay.InventoryRenderType type = InventoryOverlay.InventoryRenderType.GENERIC; DyeColor dye = DyeColor.GRAY; float[] colors = dye.getTextureDiffuseColors(); - fi.dy.masa.malilib.render.RenderUtils.color(colors[0], colors[1], colors[2], 1.0F); InventoryOverlay.renderInventoryBackground(type, x, y, 9, 27, Minecraft.getInstance()); - InventoryOverlay.renderInventoryStacks(type, playerEntity.getEnderChestInventory(), x + slotOffsetX, + InventoryOverlay.renderInventoryStacks( + type, + player.getEnderChestInventory(), + x + slotOffsetX, + y + slotOffsetY, + 9, + 0, + 27, + Minecraft.getInstance() //#if MC > 11904 - y + slotOffsetY, 9, 0, 27, Minecraft.getInstance(), masa_gadget$gui); - //#else - //$$ y + slotOffsetY, 9, 0, 27, Minecraft.getInstance()); + , masa_gadget$gui //#endif + ); fi.dy.masa.malilib.render.RenderUtils.color(1.0F, 1.0F, 1.0F, 1.0F); } + return ret; } } diff --git a/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/inventoryPreviewSupportSelect/MixinInGameHud.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/inventoryPreviewSupportSelect/MixinInGameHud.java new file mode 100644 index 00000000..f4a1f1fd --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/inventoryPreviewSupportSelect/MixinInGameHud.java @@ -0,0 +1,47 @@ +package com.plusls.MasaGadget.mixin.mod_tweak.tweakeroo.inventoryPreviewSupportSelect; + +import com.plusls.MasaGadget.ModInfo; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.impl.mod_tweak.tweakeroo.inventoryPreviewSupportSelect.InventoryOverlayRenderHandler; +import net.minecraft.client.gui.Gui; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; +import top.hendrixshen.magiclib.api.render.context.RenderContext; + +//#if MC > 11904 +import net.minecraft.client.gui.GuiGraphics; +//#elseif MC > 11502 +//$$ import com.mojang.blaze3d.vertex.PoseStack; +//#endif + +@Dependencies(require = @Dependency(ModInfo.TWEAKEROO_MOD_ID)) +@Mixin(value = Gui.class, priority = 1100) +public abstract class MixinInGameHud { + @Inject( + method = "render", + at = @At( + value = "RETURN" + ) + ) + private void onGameOverlayPost( + //#if MC > 11904 + GuiGraphics poseStackOrGuiGraphics, + //#elseif MC > 11502 + //$$ PoseStack poseStackOrGuiGraphics, + //#endif + float partialTicks, + CallbackInfo ci + ) { + if (Configs.inventoryPreviewSupportSelect.getBooleanValue()) { + InventoryOverlayRenderHandler.getInstance().render(RenderContext.of( + //#if MC > 11502 + poseStackOrGuiGraphics + //#endif + )); + } + } +} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/inventoryPreviewSupportSelect/MixinInventoryOverlay.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/inventoryPreviewSupportSelect/MixinInventoryOverlay.java new file mode 100644 index 00000000..447a1046 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/inventoryPreviewSupportSelect/MixinInventoryOverlay.java @@ -0,0 +1,44 @@ +package com.plusls.MasaGadget.mixin.mod_tweak.tweakeroo.inventoryPreviewSupportSelect; + +import com.plusls.MasaGadget.ModInfo; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.impl.mod_tweak.tweakeroo.inventoryPreviewSupportSelect.InventoryOverlayRenderHandler; +import fi.dy.masa.malilib.render.InventoryOverlay; +import net.minecraft.client.Minecraft; +import net.minecraft.world.item.ItemStack; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; + +//#if MC > 11904 +import net.minecraft.client.gui.GuiGraphics; +//#endif + +@Dependencies(require = @Dependency(ModInfo.TWEAKEROO_MOD_ID)) +@Mixin(value = InventoryOverlay.class, remap = false) +public class MixinInventoryOverlay { + @Inject( + method = "renderStackAt", + at = @At( + value = "RETURN" + ) + ) + private static void addStackToolTip( + ItemStack stack, + float x, + float y, + float scale, + Minecraft mc, + //#if MC > 11904 + GuiGraphics gui, + //#endif + CallbackInfo ci + ) { + if (Configs.inventoryPreviewSupportSelect.getBooleanValue()) { + InventoryOverlayRenderHandler.getInstance().updateState((int) x, (int) y, stack); + } + } +} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/inventoryPreviewSupportShulkerBoxItemEntity/MixinRenderUtils.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/inventoryPreviewSupportShulkerBoxItemEntity/MixinRenderUtils.java new file mode 100644 index 00000000..20e706d6 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/inventoryPreviewSupportShulkerBoxItemEntity/MixinRenderUtils.java @@ -0,0 +1,86 @@ +package com.plusls.MasaGadget.mixin.mod_tweak.tweakeroo.inventoryPreviewSupportShulkerBoxItemEntity; + +import com.plusls.MasaGadget.ModInfo; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.impl.generic.HitResultHandler; +import fi.dy.masa.tweakeroo.renderer.RenderUtils; +import net.minecraft.core.NonNullList; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.Container; +import net.minecraft.world.ContainerHelper; +import net.minecraft.world.SimpleContainer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.ShulkerBoxBlock; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyVariable; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; + +//#if MC > 12004 +//$$ import net.minecraft.client.Minecraft; +//$$ import net.minecraft.core.component.DataComponents; +//$$ import net.minecraft.world.item.component.CustomData; +//#endif + +@Dependencies(require = @Dependency(ModInfo.TWEAKEROO_MOD_ID)) +@Mixin(value = RenderUtils.class, remap = false) +public abstract class MixinRenderUtils { + @ModifyVariable( + method = "renderInventoryOverlay", + at = @At( + value = "INVOKE", + target = "Lfi/dy/masa/malilib/util/GuiUtils;getScaledWindowWidth()I", + remap = false + ), + ordinal = 0 + ) + private static Container modifyInv(Container inv) { + Container ret = inv; + Entity traceEntity = HitResultHandler.getInstance().getHitEntity().orElse(null); + + if (Configs.inventoryPreviewSupportShulkerBoxItemEntity.getBooleanValue() && + ret == null && + traceEntity instanceof ItemEntity) { + ItemStack itemStack = ((ItemEntity) traceEntity).getItem(); + Item item = itemStack.getItem(); + //#if MC > 12004 + //$$ CustomData invData = itemStack.get(DataComponents.BLOCK_ENTITY_DATA); + //$$ + //$$ if (invData == null) { + //$$ return null; + //$$ } + //$$ + //$$ CompoundTag invNbt = invData.copyTag(); + //#else + CompoundTag invNbt = itemStack.getTagElement("BlockEntityTag"); + //#endif + + NonNullList stacks = NonNullList.withSize(27, ItemStack.EMPTY); + + if (item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof ShulkerBoxBlock) { + ret = new SimpleContainer(27); + + if (invNbt != null) { + ContainerHelper.loadAllItems( + invNbt, + stacks + //#if MC > 12004 + //$$ , Minecraft.getInstance().level.registryAccess() + //#endif + ); + } + + for (int i = 0; i < 27; i++) { + ret.setItem(i, stacks.get(i)); + } + } + } + + return ret; + } +} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportTradeOfferList/MixinRenderUtils.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/inventoryPreviewSupportTradeOfferList/MixinRenderUtils.java similarity index 64% rename from src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportTradeOfferList/MixinRenderUtils.java rename to src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/inventoryPreviewSupportTradeOfferList/MixinRenderUtils.java index 9117568d..d3613206 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportTradeOfferList/MixinRenderUtils.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/inventoryPreviewSupportTradeOfferList/MixinRenderUtils.java @@ -1,8 +1,8 @@ -package com.plusls.MasaGadget.mixin.tweakeroo.inventoryPreviewSupportTradeOfferList; +package com.plusls.MasaGadget.mixin.mod_tweak.tweakeroo.inventoryPreviewSupportTradeOfferList; import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.util.HitResultUtil; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.impl.generic.HitResultHandler; import fi.dy.masa.malilib.render.InventoryOverlay; import fi.dy.masa.malilib.util.GuiUtils; import fi.dy.masa.tweakeroo.renderer.RenderUtils; @@ -17,10 +17,11 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.trading.MerchantOffer; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyVariable; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; //#if MC > 11904 import net.minecraft.client.gui.GuiGraphics; @@ -28,48 +29,62 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; //#endif -@Dependencies(and = @Dependency(ModInfo.TWEAKEROO_MOD_ID)) +@Dependencies(require = @Dependency(ModInfo.TWEAKEROO_MOD_ID)) @Mixin(value = RenderUtils.class, remap = false) public class MixinRenderUtils { //#if MC > 11904 + @Unique private static GuiGraphics masa_gadget$gui; @Inject(method = "renderInventoryOverlay", at = @At("HEAD")) private static void intercept(Minecraft mc, GuiGraphics gui, CallbackInfo ci) { - masa_gadget$gui = gui; + MixinRenderUtils.masa_gadget$gui = gui; } //#endif - private static final int MAX_TRADE_OFFER_SIZE = 9; + @Unique + private static final int masa_gadget$maxTradeOfferSize = 9; - // 如果使用 Inject,函数原型里面会有 PoseStack 在低版本会出问题 - @ModifyVariable(method = "renderInventoryOverlay", - at = @At(value = "INVOKE", + @ModifyVariable( + method = "renderInventoryOverlay", + at = @At( + value = "INVOKE", target = "Lfi/dy/masa/malilib/util/GuiUtils;getScaledWindowWidth()I", - ordinal = 0, remap = false), ordinal = 0) + remap = false + ), + ordinal = 0 + ) private static Container renderTradeOfferList(Container inv) { - if (!Configs.inventoryPreviewSupportTradeOfferList) { + if (!Configs.inventoryPreviewSupportTradeOfferList.getBooleanValue()) { return inv; } - Entity entity = HitResultUtil.getHitEntity(); + + Entity entity = HitResultHandler.getInstance().getHitEntity().orElse(null); + if (!(entity instanceof AbstractVillager)) { return inv; } + AbstractVillager abstractVillager = (AbstractVillager) entity; + if (abstractVillager instanceof Villager && ((Villager)abstractVillager).getVillagerData().getProfession() == VillagerProfession.NONE) { return inv; } - SimpleContainer simpleInventory = new SimpleContainer(MAX_TRADE_OFFER_SIZE); + + SimpleContainer simpleInventory = new SimpleContainer(MixinRenderUtils.masa_gadget$maxTradeOfferSize); + for (MerchantOffer tradeOffer : abstractVillager.getOffers()) { for (int i = 0; i < simpleInventory.getContainerSize(); ++i) { ItemStack itemStack = simpleInventory.getItem(i); + if (itemStack.isEmpty()) { simpleInventory.setItem(i, tradeOffer.getResult().copy()); break; } } } + int x = GuiUtils.getScaledWindowWidth() / 2 - 88; int y = GuiUtils.getScaledWindowHeight() / 2 - 5; int slotOffsetX = 8; @@ -79,13 +94,21 @@ private static Container renderTradeOfferList(Container inv) { float[] colors = dye.getTextureDiffuseColors(); fi.dy.masa.malilib.render.RenderUtils.color(colors[0], colors[1], colors[2], 1.0F); - InventoryOverlay.renderInventoryBackground(type, x, y, MAX_TRADE_OFFER_SIZE, MAX_TRADE_OFFER_SIZE, Minecraft.getInstance()); - InventoryOverlay.renderInventoryStacks(type, simpleInventory, x + slotOffsetX, + InventoryOverlay.renderInventoryBackground(type, x, y, MixinRenderUtils.masa_gadget$maxTradeOfferSize, + MixinRenderUtils.masa_gadget$maxTradeOfferSize, Minecraft.getInstance()); + InventoryOverlay.renderInventoryStacks( + type, + simpleInventory, + x + slotOffsetX, + y + slotOffsetY, + MixinRenderUtils.masa_gadget$maxTradeOfferSize, + 0, + MixinRenderUtils.masa_gadget$maxTradeOfferSize, + Minecraft.getInstance() //#if MC > 11904 - y + slotOffsetY, MAX_TRADE_OFFER_SIZE, 0, MAX_TRADE_OFFER_SIZE, Minecraft.getInstance(), masa_gadget$gui); - //#else - //$$ y + slotOffsetY, MAX_TRADE_OFFER_SIZE, 0, MAX_TRADE_OFFER_SIZE, Minecraft.getInstance()); + , masa_gadget$gui //#endif + ); fi.dy.masa.malilib.render.RenderUtils.color(1.0F, 1.0F, 1.0F, 1.0F); return inv; } diff --git a/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSyncDataClientOnly/MixinClientPacketListener.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/inventoryPreviewSyncDataClientOnly/MixinClientPacketListener.java similarity index 63% rename from src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSyncDataClientOnly/MixinClientPacketListener.java rename to src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/inventoryPreviewSyncDataClientOnly/MixinClientPacketListener.java index 5e28e07c..d0d9e8de 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSyncDataClientOnly/MixinClientPacketListener.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/inventoryPreviewSyncDataClientOnly/MixinClientPacketListener.java @@ -1,7 +1,7 @@ -package com.plusls.MasaGadget.mixin.tweakeroo.inventoryPreviewSyncDataClientOnly; +package com.plusls.MasaGadget.mixin.mod_tweak.tweakeroo.inventoryPreviewSyncDataClientOnly; import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; +import com.plusls.MasaGadget.game.Configs; import com.plusls.MasaGadget.util.PcaSyncProtocol; import fi.dy.masa.tweakeroo.config.FeatureToggle; import fi.dy.masa.tweakeroo.config.Hotkeys; @@ -12,24 +12,30 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; -@Dependencies(and = @Dependency(ModInfo.TWEAKEROO_MOD_ID)) +@Dependencies(require = @Dependency(ModInfo.TWEAKEROO_MOD_ID)) @Mixin(ClientPacketListener.class) public class MixinClientPacketListener { - - @Inject(method = "handleOpenScreen", at = @At(value = "RETURN")) + @Inject( + method = "handleOpenScreen", + at = @At( + value = "RETURN" + ) + ) private void postHandleOpenScreen(ClientboundOpenScreenPacket clientboundOpenScreenPacket, CallbackInfo ci) { Minecraft minecraft = Minecraft.getInstance(); - if (!Configs.inventoryPreviewSyncDataClientOnly || - (Configs.inventoryPreviewSyncData && PcaSyncProtocol.enable) || + + if (!Configs.inventoryPreviewSyncDataClientOnly.getBooleanValue() || + (Configs.inventoryPreviewSyncData.getBooleanValue() && PcaSyncProtocol.enable) || minecraft.hasSingleplayerServer() || !FeatureToggle.TWEAK_INVENTORY_PREVIEW.getBooleanValue() || !Hotkeys.INVENTORY_PREVIEW.getKeybind().isKeybindHeld() ) { return; } + minecraft.setScreen(null); } } diff --git a/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewUseCache/MixinMixinRenderUtils.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/inventoryPreviewUseCache/MixinMixinRenderUtils.java similarity index 60% rename from src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewUseCache/MixinMixinRenderUtils.java rename to src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/inventoryPreviewUseCache/MixinMixinRenderUtils.java index 0e8e509e..86f69a8d 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewUseCache/MixinMixinRenderUtils.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/inventoryPreviewUseCache/MixinMixinRenderUtils.java @@ -1,8 +1,8 @@ -package com.plusls.MasaGadget.mixin.tweakeroo.inventoryPreviewUseCache; +package com.plusls.MasaGadget.mixin.mod_tweak.tweakeroo.inventoryPreviewUseCache; import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.util.HitResultUtil; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.impl.generic.HitResultHandler; import fi.dy.masa.malilib.util.InventoryUtils; import fi.dy.masa.tweakeroo.renderer.RenderUtils; import fi.dy.masa.tweakeroo.util.RayTraceUtils; @@ -17,40 +17,48 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; +import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; -@Dependencies(and = @Dependency(ModInfo.TWEAKEROO_MOD_ID)) +@Dependencies(require = @Dependency(ModInfo.TWEAKEROO_MOD_ID)) @Mixin(value = RenderUtils.class, remap = false) public class MixinMixinRenderUtils { - @Redirect(method = "renderInventoryOverlay", - at = @At(value = "INVOKE", + @Redirect( + method = "renderInventoryOverlay", + at = @At( + value = "INVOKE", target = "Lfi/dy/masa/tweakeroo/util/RayTraceUtils;getRayTraceFromEntity(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/Entity;Z)Lnet/minecraft/world/phys/HitResult;", - ordinal = 0, remap = true)) + remap = true + ) + ) private static HitResult getRayTraceFromEntityFromCache(Level worldIn, Entity entityIn, boolean useLiquids) { - - if (!Configs.inventoryPreviewUseCache) { - return RayTraceUtils.getRayTraceFromEntity(worldIn, entityIn, useLiquids); + if (Configs.inventoryPreviewUseCache.getBooleanValue()) { + return HitResultHandler.getInstance().getLastHitResult() + .orElse(BlockHitResult.miss(Vec3.ZERO, Direction.UP, BlockPos.ZERO)); } else { - HitResult ret = HitResultUtil.getLastHitResult(); - return ret == null ? BlockHitResult.miss(Vec3.ZERO, Direction.UP, BlockPos.ZERO) : ret; + return RayTraceUtils.getRayTraceFromEntity(worldIn, entityIn, useLiquids); } } - @Redirect(method = "renderInventoryOverlay", - at = @At(value = "INVOKE", + @Redirect( + method = "renderInventoryOverlay", + at = @At( + value = "INVOKE", target = "Lfi/dy/masa/malilib/util/InventoryUtils;getInventory(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/Container;", - ordinal = 0, remap = true)) + remap = true + ) + ) private static Container getInventoryFromCache(Level world, BlockPos pos) { - if (!Configs.inventoryPreviewUseCache) { - return InventoryUtils.getInventory(world, pos); - } else { - Object blockEntity = HitResultUtil.getLastHitBlockEntity(); + if (Configs.inventoryPreviewUseCache.getBooleanValue()) { + Object blockEntity = HitResultHandler.getInstance().getLastHitBlockEntity().orElse(null); + if (blockEntity instanceof Container) { return (Container) blockEntity; } + return null; + } else { + return InventoryUtils.getInventory(world, pos); } } - } diff --git a/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/handRestockCrafting/MixinInventoryUtils.java b/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/handRestockCrafting/MixinInventoryUtils.java deleted file mode 100644 index a786a76b..00000000 --- a/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/handRestockCrafting/MixinInventoryUtils.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.plusls.MasaGadget.mixin.tweakeroo.handRestockCrafting; - -import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.tweakeroo.handRestockCrafting.RestockUtil; -import fi.dy.masa.tweakeroo.util.InventoryUtils; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; - -@Dependencies(and = {@Dependency(ModInfo.TWEAKEROO_MOD_ID), @Dependency(ModInfo.ITEMSCROLLER_MOD_ID)}) -@Mixin(value = InventoryUtils.class, remap = false) -public class MixinInventoryUtils { - @Inject(method = "restockNewStackToHand", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD) - private static void restockOnFailed(Player player, InteractionHand hand, ItemStack itemStack, boolean allowHotbar, CallbackInfo ci, int slotWithItem) { - if (slotWithItem == -1 && Configs.restockWithCrafting) { - RestockUtil.tryCraftingRestocking(player, hand, itemStack); - } - } - - @Inject(method = "preRestockHand", - at = @At(value = "INVOKE", - target = "Lnet/minecraft/client/Minecraft;getInstance()Lnet/minecraft/client/Minecraft;", - remap = true, ordinal = 0), - locals = LocalCapture.CAPTURE_FAILHARD) - private static void PreRestockOnFailed(Player player, InteractionHand hand, boolean stackSlot, CallbackInfo ci, ItemStack stackHand) { - if (Configs.restockWithCrafting) { - RestockUtil.tryCraftingRestocking(player, hand, stackHand); - } - } -} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportComparator/MixinGameRenderer.java b/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportComparator/MixinGameRenderer.java deleted file mode 100644 index 9f3f3f27..00000000 --- a/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportComparator/MixinGameRenderer.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.plusls.MasaGadget.mixin.tweakeroo.inventoryPreviewSupportComparator; - -import com.plusls.MasaGadget.ModInfo; -import net.minecraft.client.renderer.GameRenderer; -import org.spongepowered.asm.mixin.Mixin; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; - -@Dependencies(and = @Dependency(ModInfo.TWEAKEROO_MOD_ID)) -@Mixin(GameRenderer.class) -public class MixinGameRenderer { - // dummy impl - //see 1.14.4 -} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportComparator/MixinWorldRenderer.java b/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportComparator/MixinWorldRenderer.java deleted file mode 100644 index c785c411..00000000 --- a/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportComparator/MixinWorldRenderer.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.plusls.MasaGadget.mixin.tweakeroo.inventoryPreviewSupportComparator; - -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; -import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.util.HitResultUtil; -import com.plusls.MasaGadget.util.RenderUtil; -import fi.dy.masa.tweakeroo.config.FeatureToggle; -import fi.dy.masa.tweakeroo.config.Hotkeys; -import net.minecraft.ChatFormatting; -import net.minecraft.client.Camera; -import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.client.renderer.LevelRenderer; -import net.minecraft.client.renderer.LightTexture; -import net.minecraft.core.BlockPos; -import net.minecraft.network.chat.Component; -import net.minecraft.world.level.block.entity.ComparatorBlockEntity; -import org.joml.Matrix4f; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import top.hendrixshen.magiclib.compat.minecraft.api.network.chat.ComponentCompatApi; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; - -@Dependencies(and = @Dependency(ModInfo.TWEAKEROO_MOD_ID)) -@Mixin(LevelRenderer.class) -public class MixinWorldRenderer { - - //#if MC > 11404 - @Inject(method = "renderLevel", at = @At(value = "RETURN")) - private void postRender(PoseStack matrices, float tickDelta, long limitTime, - boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, - LightTexture lightmapTextureManager, Matrix4f matrix4f, CallbackInfo ci) { - - if (!FeatureToggle.TWEAK_INVENTORY_PREVIEW.getBooleanValue() || !Hotkeys.INVENTORY_PREVIEW.getKeybind().isKeybindHeld() || - !Configs.inventoryPreviewSupportComparator) { - return; - } - - - // 开始渲染 - BlockPos pos = HitResultUtil.getHitBlockPos(); - Object blockEntity = HitResultUtil.getLastHitBlockEntity(); - - if (pos != null && blockEntity instanceof ComparatorBlockEntity) { - Component literalText = ComponentCompatApi.literal(((ComparatorBlockEntity) blockEntity).getOutputSignal() + "") - .withStyle(ChatFormatting.GREEN); - // 不加 1.17 渲染会有问题 - RenderSystem.disableDepthTest(); - RenderUtil.renderTextOnWorld(matrices, camera, pos, literalText, true); - RenderSystem.enableDepthTest(); - } - } - //#endif -} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportSelect/MixinInGameHud.java b/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportSelect/MixinInGameHud.java deleted file mode 100644 index 356ff03e..00000000 --- a/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportSelect/MixinInGameHud.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.plusls.MasaGadget.mixin.tweakeroo.inventoryPreviewSupportSelect; - -import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.tweakeroo.inventoryPreviewSupportSelect.InventoryOverlayRenderHandler; -import net.minecraft.client.gui.Gui; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; - -//#if MC > 11904 -import net.minecraft.client.gui.GuiGraphics; -//#else -//$$ import com.mojang.blaze3d.vertex.PoseStack; -//#endif - -// 自己实现是为了调低优先级保证最后执行保证渲染在最上层 -@Dependencies(and = @Dependency(ModInfo.TWEAKEROO_MOD_ID)) -@Mixin(value = Gui.class, priority = 1001) -public abstract class MixinInGameHud { - @Inject(method = "render", at = @At("RETURN")) - //#if MC > 11904 - private void onGameOverlayPost(GuiGraphics gui, float f, CallbackInfo ci) { - //#elseif MC > 11502 - //$$ private void onGameOverlayPost(PoseStack poseStack, float partialTicks, CallbackInfo ci) { - //#else - //$$ private void onGameOverlayPost(float partialTicks, CallbackInfo ci) { - //#endif - if (Configs.inventoryPreviewSupportSelect) { - //#if MC > 11904 - InventoryOverlayRenderHandler.instance.render(gui); - //#elseif MC > 11502 - //$$ InventoryOverlayRenderHandler.instance.render(poseStack); - //#else - //$$ InventoryOverlayRenderHandler.instance.render(new PoseStack()); - //#endif - } - } -} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportSelect/MixinInventoryOverlay.java b/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportSelect/MixinInventoryOverlay.java deleted file mode 100644 index f2c9f91c..00000000 --- a/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportSelect/MixinInventoryOverlay.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.plusls.MasaGadget.mixin.tweakeroo.inventoryPreviewSupportSelect; - -import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.tweakeroo.inventoryPreviewSupportSelect.InventoryOverlayRenderHandler; -import fi.dy.masa.malilib.render.InventoryOverlay; -import net.minecraft.client.Minecraft; -import net.minecraft.world.item.ItemStack; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; - -//#if MC > 11904 -import net.minecraft.client.gui.GuiGraphics; -//#endif - -@Dependencies(and = @Dependency(ModInfo.TWEAKEROO_MOD_ID)) -@Mixin(value = InventoryOverlay.class, remap = false) -public class MixinInventoryOverlay { - @Inject(method = "renderStackAt", at = @At(value = "RETURN")) - //#if MC > 11904 - private static void addStackToolTip(ItemStack stack, float x, float y, float scale, Minecraft mc, GuiGraphics gui, CallbackInfo ci) { - //#else - //$$ private static void addStackToolTip(ItemStack stack, float x, float y, float scale, Minecraft mc, CallbackInfo ci) { - //#endif - if (Configs.inventoryPreviewSupportSelect) { - InventoryOverlayRenderHandler.instance.updateState((int) x, (int) y, stack); - } - } -} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportShulkerBoxItemEntity/MixinRenderUtils.java b/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportShulkerBoxItemEntity/MixinRenderUtils.java deleted file mode 100644 index 0eaffcb0..00000000 --- a/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportShulkerBoxItemEntity/MixinRenderUtils.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.plusls.MasaGadget.mixin.tweakeroo.inventoryPreviewSupportShulkerBoxItemEntity; - -import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.util.HitResultUtil; -import fi.dy.masa.tweakeroo.renderer.RenderUtils; -import net.minecraft.core.NonNullList; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.world.Container; -import net.minecraft.world.ContainerHelper; -import net.minecraft.world.SimpleContainer; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.item.ItemEntity; -import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.ShulkerBoxBlock; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyVariable; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; - -@Dependencies(and = @Dependency(ModInfo.TWEAKEROO_MOD_ID)) -@Mixin(value = RenderUtils.class, remap = false) -public abstract class MixinRenderUtils { - - @ModifyVariable(method = "renderInventoryOverlay", - at = @At(value = "INVOKE", - target = "Lfi/dy/masa/malilib/util/GuiUtils;getScaledWindowWidth()I", - ordinal = 0, remap = false), ordinal = 0) - private static Container modifyInv(Container inv) { - Container ret = inv; - Entity traceEntity = HitResultUtil.getHitEntity(); - - if (Configs.inventoryPreviewSupportShulkerBoxItemEntity && ret == null && - traceEntity instanceof ItemEntity) { - ItemStack itemStack = ((ItemEntity) traceEntity).getItem(); - Item item = itemStack.getItem(); - CompoundTag invNbt = itemStack.getTagElement("BlockEntityTag"); - NonNullList stacks = NonNullList.withSize(27, ItemStack.EMPTY); - if (item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof ShulkerBoxBlock) { - ret = new SimpleContainer(27); - if (invNbt != null) { - ContainerHelper.loadAllItems(invNbt, stacks); - } - for (int i = 0; i < 27; ++i) { - ret.setItem(i, stacks.get(i)); - } - - } - } - return ret; - } -} diff --git a/src/main/java/com/plusls/MasaGadget/tweakeroo/inventoryPreviewSupportSelect/InventoryOverlayRenderHandler.java b/src/main/java/com/plusls/MasaGadget/tweakeroo/inventoryPreviewSupportSelect/InventoryOverlayRenderHandler.java deleted file mode 100644 index b06e763b..00000000 --- a/src/main/java/com/plusls/MasaGadget/tweakeroo/inventoryPreviewSupportSelect/InventoryOverlayRenderHandler.java +++ /dev/null @@ -1,378 +0,0 @@ -package com.plusls.MasaGadget.tweakeroo.inventoryPreviewSupportSelect; - -import com.google.common.collect.ImmutableList; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.BufferBuilder; -import com.mojang.blaze3d.vertex.DefaultVertexFormat; -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.blaze3d.vertex.Tesselator; -import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; -import fi.dy.masa.malilib.render.RenderUtils; -import fi.dy.masa.malilib.util.Color4f; -import fi.dy.masa.malilib.util.GuiUtils; -import fi.dy.masa.tweakeroo.config.FeatureToggle; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.network.chat.Component; -import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.TooltipFlag; -import net.minecraft.world.level.block.ShulkerBoxBlock; -import net.minecraft.world.phys.HitResult; -import org.jetbrains.annotations.Nullable; -import org.joml.Matrix4f; -import top.hendrixshen.magiclib.compat.minecraft.api.blaze3d.vertex.VertexFormatCompatApi; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -//#if MC > 11904 -import net.minecraft.client.gui.GuiGraphics; -//#endif - -//#if MC <= 11605 -//$$ import org.lwjgl.opengl.GL11; -//#endif - -public class InventoryOverlayRenderHandler { - final public static InventoryOverlayRenderHandler instance = new InventoryOverlayRenderHandler(); - final private static int UN_SELECTED = 114514; - private int selectedIdx = UN_SELECTED; - private int currentIdx = -1; - private int renderX = -1; - private int renderY = -1; - private ItemStack itemStack = null; - // 支持显示盒子在箱子里 - private boolean selectInventory = false; - private boolean renderingSubInventory = false; - private int subSelectedIdx = UN_SELECTED; - private int subCurrentIdx = -1; - private int subRenderX = -1; - private int subRenderY = -1; - private ItemStack subItemStack = null; - - public static void onHitCallback(@Nullable HitResult hitResult, boolean oldStatus, boolean stateChanged) { - if (!FeatureToggle.TWEAK_INVENTORY_PREVIEW.getBooleanValue() || !Configs.inventoryPreviewSupportSelect) { - return; - } - if (!oldStatus) { - // 重置预览选择槽 - InventoryOverlayRenderHandler.instance.resetSelectedIdx(); - } - } - - - private static void fillGradient(PoseStack matrices, Collection gradientDataCollection) { - //#if MC < 11904 - //$$ RenderSystem.disableTexture(); - //#endif - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - //#if MC > 11605 - RenderSystem.setShader(GameRenderer::getPositionColorShader); - //#else - //$$ RenderSystem.disableAlphaTest(); - //$$ RenderSystem.shadeModel(GL11.GL_SMOOTH); - //#endif - Tesselator tesselator = Tesselator.getInstance(); - BufferBuilder bufferBuilder = tesselator.getBuilder(); - bufferBuilder.begin(VertexFormatCompatApi.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); - for (GradientData gradientData : gradientDataCollection) { - fillGradient(matrices.last().pose(), bufferBuilder, gradientData); - } - tesselator.end(); - - //#if MC <= 11605 - //$$ RenderSystem.shadeModel(GL11.GL_FLAT); - //#endif - - RenderSystem.disableBlend(); - //#if MC < 11904 - //$$ RenderSystem.enableTexture(); - //#endif - } - - private static void fillGradient(Matrix4f matrix, BufferBuilder bufferBuilder, GradientData gradientData) { - bufferBuilder.vertex(matrix, gradientData.endX, gradientData.startY, gradientData.z) - .color(gradientData.colorStart.r, gradientData.colorStart.g, gradientData.colorStart.b, gradientData.colorStart.a).endVertex(); - bufferBuilder.vertex(matrix, gradientData.startX, gradientData.startY, gradientData.z) - .color(gradientData.colorStart.r, gradientData.colorStart.g, gradientData.colorStart.b, gradientData.colorStart.a).endVertex(); - bufferBuilder.vertex(matrix, gradientData.startX, gradientData.endY, gradientData.z) - .color(gradientData.colorEnd.r, gradientData.colorEnd.g, gradientData.colorEnd.b, gradientData.colorEnd.a).endVertex(); - bufferBuilder.vertex(matrix, gradientData.endX, gradientData.endY, gradientData.z) - .color(gradientData.colorEnd.r, gradientData.colorEnd.g, gradientData.colorEnd.b, gradientData.colorEnd.a).endVertex(); - } - - public void render(T obj) { - //#if MC > 11904 - GuiGraphics gui = (GuiGraphics) obj; - PoseStack poseStack = gui.pose(); - //#else - //$$ PoseStack poseStack = (PoseStack) obj; - //#endif - // fuck mojang - // for 1.18 - // 不添加会渲染错误,不知道麻将哪里 pop 了没有 apply - //#if MC > 11605 && MC < 12000 - //$$ RenderSystem.applyModelViewMatrix(); - //#endif - - if (currentIdx == 0) { - return; - } - if (selectedIdx != UN_SELECTED) { - if (selectedIdx >= currentIdx) { - selectedIdx %= currentIdx; - } else if (selectedIdx < 0) { - while (selectedIdx < 0) { - selectedIdx += currentIdx; - } - } else { - if (itemStack != null) { - if (selectInventory) { - if (itemStack.getItem() instanceof BlockItem && - ((BlockItem) itemStack.getItem()).getBlock() instanceof ShulkerBoxBlock) { - //#if MC > 11904 - gui.fill(renderX, renderY, renderX + 16, renderY + 16, 0x80ffffff, 0x80ffffff); - //#else - //$$ renderSelectedRect(poseStack, renderX, renderY); - //#endif - // 盒子预览 - renderingSubInventory = true; - RenderUtils.renderShulkerBoxPreview(itemStack, - GuiUtils.getScaledWindowWidth() / 2 - 96, - //#if MC > 11904 - GuiUtils.getScaledWindowHeight() / 2 + 30, true, gui); - //#else - //$$ GuiUtils.getScaledWindowHeight() / 2 + 30, true); - //#endif - renderingSubInventory = false; - if (subSelectedIdx != UN_SELECTED) { - if (subCurrentIdx != 0) { - if (subSelectedIdx >= subCurrentIdx) { - subSelectedIdx %= subCurrentIdx; - } else if (subSelectedIdx < 0) { - while (subSelectedIdx < 0) { - subSelectedIdx += subCurrentIdx; - } - } else { - if (subItemStack != null) { - poseStack.pushPose(); - poseStack.translate(0, 0, 400); - ModInfo.LOGGER.debug("subRenderX: {} subRenderY: {}", subRenderX, subRenderY); - //#if MC > 11904 - gui.fill(subRenderX, subRenderY, subRenderX + 16, subRenderY + 16, 0x80ffffff, 0x80ffffff); - gui.renderTooltip(Minecraft.getInstance().font, subItemStack, subRenderX, subRenderY + 8); - //#else - //$$ renderSelectedRect(poseStack, subRenderX, subRenderY); - //$$ renderOrderedTooltip(poseStack, subItemStack, subRenderX, subRenderY + 8); - //#endif - poseStack.popPose(); - - } else { - ModInfo.LOGGER.debug("InventoryOverlayRenderHandler sub wtf???"); - } - } - - } - - } - } else { - // 激活预览但是被预览的物品不是盒子 - switchSelectInventory(); - } - } - if (!selectInventory) { - ModInfo.LOGGER.debug("renderX: {} renderY: {}", renderX, renderY); - //#if MC > 11904 - gui.fill(renderX, renderY, renderX + 16, renderY + 16, 0x80ffffff, 0x80ffffff); - gui.renderTooltip(Minecraft.getInstance().font, itemStack, renderX, renderY + 8); - //#else - //$$ renderSelectedRect(poseStack, renderX, renderY); - //$$ renderOrderedTooltip(poseStack, itemStack, renderX, renderY + 8); - //#endif - } - - } else { - ModInfo.LOGGER.debug("InventoryOverlayRenderHandler wtf???"); - } - } - } - currentIdx = 0; - itemStack = null; - renderX = -1; - renderY = -1; - - subCurrentIdx = 0; - subItemStack = null; - subRenderX = -1; - subRenderY = -1; - } - - // for 1.14 - - public void updateState(int x, int y, ItemStack stack) { - if (renderingSubInventory) { - if (subCurrentIdx++ == subSelectedIdx) { - subRenderX = x; - subRenderY = y; - subItemStack = stack; - } - } else { - if (currentIdx++ == selectedIdx) { - renderX = x; - renderY = y; - itemStack = stack; - } - } - } - - public void switchSelectInventory() { - selectInventory = !selectInventory; - subSelectedIdx = UN_SELECTED; - } - - public void resetSelectedIdx() { - selectedIdx = UN_SELECTED; - if (selectInventory) { - switchSelectInventory(); - } - } - - public void addSelectedIdx(int n) { - if (selectInventory) { - if (subSelectedIdx == UN_SELECTED) { - subSelectedIdx = 0; - } else { - subSelectedIdx += n; - } - } else { - if (selectedIdx == UN_SELECTED) { - selectedIdx = 0; - } else { - selectedIdx += n; - } - } - } - - public void renderSelectedRect(PoseStack matrices, int x, int y) { - // 选中框 - RenderSystem.disableDepthTest(); - RenderSystem.colorMask(true, true, true, false); - fillGradient(matrices, ImmutableList.of(new GradientData( - Color4f.fromColor(0x80ffffff), Color4f.fromColor(0x80ffffff), - x, y, x + 16, y + 16, 0))); - RenderSystem.colorMask(true, true, true, true); - RenderSystem.enableDepthTest(); - } - - public void renderOrderedTooltip(PoseStack matrices, ItemStack stack, int x, int y) { - y = y + 8; - RenderSystem.disableDepthTest(); - Minecraft mc = Minecraft.getInstance(); - List components = stack.getTooltipLines(mc.player, mc.options.advancedItemTooltips ? - TooltipFlag.Default.ADVANCED : TooltipFlag.Default.NORMAL); - if (components.isEmpty()) - return; - int xOffset = 0; - int yOffset = (components.size() == 1) ? -2 : 0; - - for (Component component : components) { - int m = mc.font.width(component); - if (m > xOffset) - xOffset = m; - yOffset += 10; - } - - int renderX = x + 12; - int renderY = y - 12; - - if (renderX + xOffset > GuiUtils.getScaledWindowWidth()) { - renderX -= 28 + xOffset; - } - - if (renderY + yOffset + 6 > GuiUtils.getScaledWindowHeight()) { - renderY = GuiUtils.getScaledWindowHeight() - yOffset - 6; - } - matrices.pushPose(); - - - //#if MC < 11904 - //$$ float oldBlitOffset = mc.getItemRenderer().blitOffset; - //$$ mc.getItemRenderer().blitOffset = 400.0F; - //#endif - - Color4f colorA = Color4f.fromColor(0xf0100010); - - ArrayList gradientDataArrayList = new ArrayList<>(); - gradientDataArrayList.add(new GradientData(colorA, colorA, renderX - 3, renderY - 4, - renderX + xOffset + 3, renderY - 3, 400)); - gradientDataArrayList.add(new GradientData(colorA, colorA, renderX - 3, renderY + yOffset + 3, - renderX + xOffset + 3, renderY + yOffset + 4, 400)); - gradientDataArrayList.add(new GradientData(colorA, colorA, renderX - 3, renderY - 3, - renderX + xOffset + 3, renderY + yOffset + 3, 400)); - gradientDataArrayList.add(new GradientData(colorA, colorA, renderX - 4, renderY - 3, - renderX - 3, renderY + yOffset + 3, 400)); - gradientDataArrayList.add(new GradientData(colorA, colorA, renderX + xOffset + 3, renderY - 3, - renderX + xOffset + 4, renderY + yOffset + 3, 400)); - - Color4f colorB = Color4f.fromColor(0x505000ff); - Color4f colorC = Color4f.fromColor(0x5028007f); - - gradientDataArrayList.add(new GradientData(colorB, colorC, renderX - 3, renderY - 3 + 1, - renderX - 3 + 1, renderY + yOffset + 3 - 1, 400)); - gradientDataArrayList.add(new GradientData(colorB, colorC, renderX + xOffset + 2, renderY - 3 + 1, - renderX + xOffset + 3, renderY + yOffset + 3 - 1, 400)); - gradientDataArrayList.add(new GradientData(colorB, colorB, renderX - 3, renderY - 3, - renderX + xOffset + 3, renderY - 3 + 1, 400)); - gradientDataArrayList.add(new GradientData(colorC, colorC, renderX - 3, renderY + yOffset + 2, - renderX + xOffset + 3, renderY + yOffset + 3, 400)); - - //#if MC < 11904 - //$$ RenderSystem.disableTexture(); - //#endif - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - fillGradient(matrices, gradientDataArrayList); - RenderSystem.disableBlend(); - //#if MC < 11904 - //$$ RenderSystem.enableTexture(); - //#endif - matrices.translate(0.0D, 0.0D, 400.0D); - - for (int i = 0; i < components.size(); i++) { - mc.font.drawInBatch(components.get(i), renderX, renderY, 0xffffffff, true, - matrices.last().pose(), false, 0, 0xf000f0); - renderY += 10 + ((i == 0) ? 2 : 0); - } - matrices.popPose(); - //#if MC < 11904 - //$$ mc.getItemRenderer().blitOffset = oldBlitOffset; - //#endif - RenderSystem.enableDepthTest(); - } - - public static class GradientData { - public int startX; - public int startY; - public int endX; - public int endY; - - public int z; - - public Color4f colorStart; - public Color4f colorEnd; - - public GradientData(Color4f colorStart, Color4f colorEnd, int startX, int startY, int endX, int endY, int z) { - this.endY = endY; - this.colorStart = colorStart; - this.colorEnd = colorEnd; - this.startX = startX; - this.startY = startY; - this.endX = endX; - this.z = z; - } - } -} diff --git a/src/main/java/com/plusls/MasaGadget/tweakeroo/inventoryPreviewSupportSelect/MouseScrollInputHandler.java b/src/main/java/com/plusls/MasaGadget/tweakeroo/inventoryPreviewSupportSelect/MouseScrollInputHandler.java deleted file mode 100644 index 811ee0c2..00000000 --- a/src/main/java/com/plusls/MasaGadget/tweakeroo/inventoryPreviewSupportSelect/MouseScrollInputHandler.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.plusls.MasaGadget.tweakeroo.inventoryPreviewSupportSelect; - -import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.util.HitResultUtil; -import fi.dy.masa.malilib.event.InputEventHandler; -import fi.dy.masa.malilib.hotkeys.IMouseInputHandler; -import fi.dy.masa.tweakeroo.config.FeatureToggle; -import fi.dy.masa.tweakeroo.config.Hotkeys; -import net.minecraft.client.Minecraft; -//#if MC >= 11903 -import net.minecraft.core.registries.BuiltInRegistries; -//#else -//$$ import net.minecraft.core.Registry; -//#endif -import net.minecraft.world.entity.player.Player; -import top.hendrixshen.magiclib.util.FabricUtil; - -public class MouseScrollInputHandler implements IMouseInputHandler { - public static void register() { - MouseScrollInputHandler handler = new MouseScrollInputHandler(); - InputEventHandler.getInputManager().registerMouseInputHandler(handler); - } - - @Override - public boolean onMouseScroll(int mouseX, int mouseY, double amount) { - Player player = Minecraft.getInstance().player; - if (FabricUtil.isModLoaded(ModInfo.TWEAKEROO_MOD_ID) && - Configs.inventoryPreviewSupportSelect && - FeatureToggle.TWEAK_INVENTORY_PREVIEW.getBooleanValue() && - HitResultUtil.getLastInventoryPreviewStatus()) { - if (amount < 0) { - InventoryOverlayRenderHandler.instance.addSelectedIdx(1); - } else if (amount > 0) { - InventoryOverlayRenderHandler.instance.addSelectedIdx(-1); - } - if (FabricUtil.isModLoaded(ModInfo.LITEMATICA_MOD_ID) && - fi.dy.masa.litematica.config.Configs.Generic.TOOL_ITEM_ENABLED.getBooleanValue() && - //#if MC >= 11903 - player != null && BuiltInRegistries.ITEM.getKey(player.getMainHandItem().getItem()).toString().contains(fi.dy.masa.litematica.config.Configs.Generic.TOOL_ITEM.getStringValue())) { - //#else - //$$ player != null && Registry.ITEM.getKey(player.getMainHandItem().getItem()).toString().contains(fi.dy.masa.litematica.config.Configs.Generic.TOOL_ITEM.getStringValue())) { - //#endif - return false; - } - return true; - } - return false; - } - - @Override - public boolean onMouseClick(int mouseX, int mouseY, int eventButton, boolean eventButtonState) { - // 左右中 -> 0 1 2 以此类推 - if (FabricUtil.isModLoaded(ModInfo.TWEAKEROO_MOD_ID) && - Configs.inventoryPreviewSupportSelect && - FeatureToggle.TWEAK_INVENTORY_PREVIEW.getBooleanValue() && - Hotkeys.INVENTORY_PREVIEW.getKeybind().isKeybindHeld() - && eventButton == 2 && eventButtonState) { - // 按下中键决定显示容器详细信息,再按一次取消 - InventoryOverlayRenderHandler.instance.switchSelectInventory(); - } - return false; - } -} diff --git a/src/main/java/com/plusls/MasaGadget/litematica/fixCarpetAccurateProtocol/BlockPlacer.java b/src/main/java/com/plusls/MasaGadget/util/BlockPlacer.java similarity index 98% rename from src/main/java/com/plusls/MasaGadget/litematica/fixCarpetAccurateProtocol/BlockPlacer.java rename to src/main/java/com/plusls/MasaGadget/util/BlockPlacer.java index 49696708..2f21d9a5 100644 --- a/src/main/java/com/plusls/MasaGadget/litematica/fixCarpetAccurateProtocol/BlockPlacer.java +++ b/src/main/java/com/plusls/MasaGadget/util/BlockPlacer.java @@ -1,4 +1,4 @@ -package com.plusls.MasaGadget.litematica.fixCarpetAccurateProtocol; +package com.plusls.MasaGadget.util; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; diff --git a/src/main/java/com/plusls/MasaGadget/tweakeroo/inventoryPreviewSyncDataClientOnly/InventoryPreviewSyncDataClientOnlyUtil.java b/src/main/java/com/plusls/MasaGadget/util/InventoryPreviewSyncDataClientOnlyUtil.java similarity index 78% rename from src/main/java/com/plusls/MasaGadget/tweakeroo/inventoryPreviewSyncDataClientOnly/InventoryPreviewSyncDataClientOnlyUtil.java rename to src/main/java/com/plusls/MasaGadget/util/InventoryPreviewSyncDataClientOnlyUtil.java index d23e110a..10657842 100644 --- a/src/main/java/com/plusls/MasaGadget/tweakeroo/inventoryPreviewSyncDataClientOnly/InventoryPreviewSyncDataClientOnlyUtil.java +++ b/src/main/java/com/plusls/MasaGadget/util/InventoryPreviewSyncDataClientOnlyUtil.java @@ -1,9 +1,8 @@ -package com.plusls.MasaGadget.tweakeroo.inventoryPreviewSyncDataClientOnly; +package com.plusls.MasaGadget.util; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.generic.cacheContainerMenu.cacheContainerMenu.CacheContainerMenuHandler; -import com.plusls.MasaGadget.util.HitResultUtil; -import com.plusls.MasaGadget.util.PcaSyncProtocol; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.impl.feature.cacheContainerMenu.CacheContainerMenuHandler; +import com.plusls.MasaGadget.impl.generic.HitResultHandler; import fi.dy.masa.tweakeroo.config.FeatureToggle; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; @@ -26,9 +25,10 @@ public class InventoryPreviewSyncDataClientOnlyUtil { public static void onHitCallback(@Nullable HitResult hitResult, boolean oldStatus, boolean stateChanged) { Minecraft mc = Minecraft.getInstance(); - if (!Configs.inventoryPreviewSyncDataClientOnly || + + if (!Configs.inventoryPreviewSyncDataClientOnly.getBooleanValue() || mc.player == null || mc.player.isShiftKeyDown() || - (Configs.inventoryPreviewSyncData && PcaSyncProtocol.enable) || + (Configs.inventoryPreviewSyncData.getBooleanValue() && PcaSyncProtocol.enable) || mc.hasSingleplayerServer() || !FeatureToggle.TWEAK_INVENTORY_PREVIEW.getBooleanValue() ) { @@ -43,16 +43,21 @@ public static void onHitCallback(@Nullable HitResult hitResult, boolean oldStatu } else { return; } + if (hitResult == null) { Objects.requireNonNull(Minecraft.getInstance().player).closeContainer(); return; } + LocalPlayer player = Objects.requireNonNull(mc.player); + if (hitResult.getType() == HitResult.Type.BLOCK) { BlockHitResult blockHitResult = (BlockHitResult) hitResult; BlockPos pos = blockHitResult.getBlockPos(); - Object blockEntity = HitResultUtil.getLastHitBlockEntity(); - if (blockEntity instanceof Container && !pos.equals(CacheContainerMenuHandler.lastClickBlockPos)) { + Object blockEntity = HitResultHandler.getInstance().getLastHitBlockEntity().orElse(null); + + if (blockEntity instanceof Container && + !pos.equals(CacheContainerMenuHandler.getInstance().getLastClickBlockPos())) { player.closeContainer(); Objects.requireNonNull(mc.gameMode).useItemOn(player, //#if MC <= 11802 @@ -62,6 +67,7 @@ public static void onHitCallback(@Nullable HitResult hitResult, boolean oldStatu } } else if (hitResult.getType() == HitResult.Type.ENTITY) { Entity entity = ((EntityHitResult) hitResult).getEntity(); + if (entity instanceof Container || entity instanceof AbstractHorse) { // TODO diff --git a/src/main/java/com/plusls/MasaGadget/tweakeroo/inventoryPreviewSyncData/InventoryPreviewSyncDataUtil.java b/src/main/java/com/plusls/MasaGadget/util/InventoryPreviewSyncDataUtil.java similarity index 72% rename from src/main/java/com/plusls/MasaGadget/tweakeroo/inventoryPreviewSyncData/InventoryPreviewSyncDataUtil.java rename to src/main/java/com/plusls/MasaGadget/util/InventoryPreviewSyncDataUtil.java index a3030af0..0cd4c266 100644 --- a/src/main/java/com/plusls/MasaGadget/tweakeroo/inventoryPreviewSyncData/InventoryPreviewSyncDataUtil.java +++ b/src/main/java/com/plusls/MasaGadget/util/InventoryPreviewSyncDataUtil.java @@ -1,8 +1,7 @@ -package com.plusls.MasaGadget.tweakeroo.inventoryPreviewSyncData; +package com.plusls.MasaGadget.util; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.util.HitResultUtil; -import com.plusls.MasaGadget.util.PcaSyncProtocol; +import com.plusls.MasaGadget.game.Configs; +import com.plusls.MasaGadget.impl.generic.HitResultHandler; import fi.dy.masa.tweakeroo.config.FeatureToggle; import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; @@ -18,25 +17,24 @@ import net.minecraft.world.phys.HitResult; import org.jetbrains.annotations.Nullable; - public class InventoryPreviewSyncDataUtil { - public static void onHitCallback(@Nullable HitResult hitResult, boolean oldStatus, boolean stateChanged) { Minecraft mc = Minecraft.getInstance(); - if (!Configs.inventoryPreviewSyncData || + + if (!Configs.inventoryPreviewSyncData.getBooleanValue() || !PcaSyncProtocol.enable || mc.hasSingleplayerServer() || !FeatureToggle.TWEAK_INVENTORY_PREVIEW.getBooleanValue()) { return; } - if (oldStatus) { - if (stateChanged) { - PcaSyncProtocol.cancelSyncBlockEntity(); - PcaSyncProtocol.cancelSyncEntity(); - return; - } - } else { + if (!oldStatus) { + return; + } + + if (stateChanged) { + PcaSyncProtocol.cancelSyncBlockEntity(); + PcaSyncProtocol.cancelSyncEntity(); return; } @@ -48,8 +46,10 @@ public static void onHitCallback(@Nullable HitResult hitResult, boolean oldStatu if (hitResult.getType() == HitResult.Type.BLOCK) { BlockPos pos = ((BlockHitResult) hitResult).getBlockPos(); - Object blockEntity = HitResultUtil.getLastHitBlockEntity(); - if (blockEntity instanceof AbstractFurnaceBlockEntity || + Object blockEntity = HitResultHandler.getInstance().getLastHitBlockEntity().orElse(null); + + if ( + blockEntity instanceof AbstractFurnaceBlockEntity || blockEntity instanceof DispenserBlockEntity || blockEntity instanceof HopperBlockEntity || blockEntity instanceof ShulkerBoxBlockEntity || @@ -57,21 +57,24 @@ public static void onHitCallback(@Nullable HitResult hitResult, boolean oldStatu blockEntity instanceof BrewingStandBlockEntity || blockEntity instanceof ChestBlockEntity || blockEntity instanceof CompoundContainer || - (blockEntity instanceof ComparatorBlockEntity && Configs.inventoryPreviewSupportComparator) || + (blockEntity instanceof ComparatorBlockEntity && Configs.inventoryPreviewSupportComparator.getBooleanValue()) || //#if MC > 11404 - (blockEntity instanceof BeehiveBlockEntity && Configs.pcaSyncProtocolSyncBeehive) - //#else - //$$ true - //#endif + (blockEntity instanceof BeehiveBlockEntity && Configs.pcaSyncProtocolSyncBeehive.getBooleanValue()) + //#else + //$$ true + //#endif ) { PcaSyncProtocol.syncBlockEntity(pos); } } else if (hitResult.getType() == HitResult.Type.ENTITY) { Entity entity = ((EntityHitResult) hitResult).getEntity(); - if (entity instanceof Container || + + if ( + entity instanceof Container || entity instanceof AbstractVillager || entity instanceof AbstractHorse || - entity instanceof Player) { + entity instanceof Player + ) { PcaSyncProtocol.syncEntity(entity.getId()); } } diff --git a/src/main/java/com/plusls/MasaGadget/util/MiscUtil.java b/src/main/java/com/plusls/MasaGadget/util/MiscUtil.java index 386d8018..56eee015 100644 --- a/src/main/java/com/plusls/MasaGadget/util/MiscUtil.java +++ b/src/main/java/com/plusls/MasaGadget/util/MiscUtil.java @@ -15,7 +15,7 @@ import net.minecraft.world.level.chunk.LevelChunk; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import top.hendrixshen.magiclib.language.api.I18n; +import top.hendrixshen.magiclib.api.i18n.I18n; public class MiscUtil extends top.hendrixshen.magiclib.util.MiscUtil { public static T getBestEntity(T entity) { @@ -53,7 +53,7 @@ public static String getStringWithoutFormat(String text) { @Nullable public static String getTranslatedOrFallback(String key, @Nullable String fallback, Object... objects) { - String translated = I18n.get(key, objects); + String translated = I18n.tr(key, objects); return !key.equals(translated) ? translated : fallback; } diff --git a/src/main/java/com/plusls/MasaGadget/util/PcaSyncProtocol.java b/src/main/java/com/plusls/MasaGadget/util/PcaSyncProtocol.java index c0264a2e..47acb0ba 100644 --- a/src/main/java/com/plusls/MasaGadget/util/PcaSyncProtocol.java +++ b/src/main/java/com/plusls/MasaGadget/util/PcaSyncProtocol.java @@ -2,9 +2,8 @@ import com.mojang.serialization.Dynamic; import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.event.DisconnectEvent; -import com.plusls.MasaGadget.litematica.saveInventoryToSchematicInServer.PcaSyncUtil; +import com.plusls.MasaGadget.api.event.DisconnectListener; +import com.plusls.MasaGadget.game.Configs; import com.plusls.MasaGadget.mixin.accessor.*; import fi.dy.masa.malilib.gui.Message; import fi.dy.masa.malilib.util.InfoUtils; @@ -33,22 +32,34 @@ import net.minecraft.world.item.trading.MerchantOffers; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; -import top.hendrixshen.magiclib.compat.minecraft.api.nbt.TagCompatApi; +import top.hendrixshen.magiclib.MagicLib; +import top.hendrixshen.magiclib.api.compat.minecraft.nbt.TagCompat; +import top.hendrixshen.magiclib.api.compat.minecraft.world.SimpleContainerCompat; +import top.hendrixshen.magiclib.api.compat.minecraft.world.entity.player.PlayerCompat; +import top.hendrixshen.magiclib.api.compat.minecraft.world.level.LevelCompat; +import top.hendrixshen.magiclib.api.compat.minecraft.world.level.block.BlockEntityCompat; +import top.hendrixshen.magiclib.util.minecraft.NetworkUtil; import java.util.Objects; +//#if MC > 12004 +//$$ import com.plusls.MasaGadget.impl.network.packet.*; +//$$ import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; +//$$ import net.minecraft.Util; +//#endif + public class PcaSyncProtocol { private static final String NAMESPACE = "pca"; // send - private static final ResourceLocation SYNC_BLOCK_ENTITY = id("sync_block_entity"); - private static final ResourceLocation SYNC_ENTITY = id("sync_entity"); - private static final ResourceLocation CANCEL_SYNC_REQUEST_BLOCK_ENTITY = id("cancel_sync_block_entity"); - private static final ResourceLocation CANCEL_SYNC_ENTITY = id("cancel_sync_entity"); + public static final ResourceLocation SYNC_BLOCK_ENTITY = id("sync_block_entity"); + public static final ResourceLocation SYNC_ENTITY = id("sync_entity"); + public static final ResourceLocation CANCEL_SYNC_REQUEST_BLOCK_ENTITY = id("cancel_sync_block_entity"); + public static final ResourceLocation CANCEL_SYNC_ENTITY = id("cancel_sync_entity"); // recv - private static final ResourceLocation ENABLE_PCA_SYNC_PROTOCOL = id("enable_pca_sync_protocol"); - private static final ResourceLocation DISABLE_PCA_SYNC_PROTOCOL = id("disable_pca_sync_protocol"); - private static final ResourceLocation UPDATE_ENTITY = id("update_entity"); - private static final ResourceLocation UPDATE_BLOCK_ENTITY = id("update_block_entity"); + public static final ResourceLocation ENABLE_PCA_SYNC_PROTOCOL = id("enable_pca_sync_protocol"); + public static final ResourceLocation DISABLE_PCA_SYNC_PROTOCOL = id("disable_pca_sync_protocol"); + public static final ResourceLocation UPDATE_ENTITY = id("update_entity"); + public static final ResourceLocation UPDATE_BLOCK_ENTITY = id("update_block_entity"); public static boolean enable = false; private static BlockPos lastBlockPos = null; private static int lastEntityId = -1; @@ -58,13 +69,22 @@ private static ResourceLocation id(String path) { } public static void init() { - ClientPlayNetworking.registerGlobalReceiver(ENABLE_PCA_SYNC_PROTOCOL, PcaSyncProtocol::enablePcaSyncProtocolHandle); - ClientPlayNetworking.registerGlobalReceiver(DISABLE_PCA_SYNC_PROTOCOL, PcaSyncProtocol::disablePcaSyncProtocolHandle); + //#if MC > 12004 + //$$ PayloadTypeRegistry.playS2C().register(ClientboundDisablePcaSyncProtocolPacket.TYPE, ClientboundDisablePcaSyncProtocolPacket.CODEC); + //$$ PayloadTypeRegistry.playS2C().register(ClientboundEnablePcaSyncProtocolPacket.TYPE, ClientboundEnablePcaSyncProtocolPacket.CODEC); + //$$ PayloadTypeRegistry.playS2C().register(ClientboundUpdateBlockEntityPacket.TYPE, ClientboundUpdateBlockEntityPacket.CODEC); + //$$ PayloadTypeRegistry.playS2C().register(ClientboundUpdateEntityPacket.TYPE, ClientboundUpdateEntityPacket.CODEC); + //$$ ClientPlayNetworking.registerGlobalReceiver(ClientboundDisablePcaSyncProtocolPacket.TYPE, ClientboundDisablePcaSyncProtocolPacket::handle); + //$$ ClientPlayNetworking.registerGlobalReceiver(ClientboundEnablePcaSyncProtocolPacket.TYPE, ClientboundEnablePcaSyncProtocolPacket::handle); + //$$ ClientPlayNetworking.registerGlobalReceiver(ClientboundUpdateBlockEntityPacket.TYPE, ClientboundUpdateBlockEntityPacket::handle); + //$$ ClientPlayNetworking.registerGlobalReceiver(ClientboundUpdateEntityPacket.TYPE, ClientboundUpdateEntityPacket::handle); + //#else + ClientPlayNetworking.registerGlobalReceiver(ENABLE_PCA_SYNC_PROTOCOL, PcaSyncProtocol::enablePcaSyncProtocolHandler); + ClientPlayNetworking.registerGlobalReceiver(DISABLE_PCA_SYNC_PROTOCOL, PcaSyncProtocol::disablePcaSyncProtocolHandler); ClientPlayNetworking.registerGlobalReceiver(UPDATE_ENTITY, PcaSyncProtocol::updateEntityHandler); ClientPlayNetworking.registerGlobalReceiver(UPDATE_BLOCK_ENTITY, PcaSyncProtocol::updateBlockEntityHandler); - // 该事件仅在服务器主动断开客户端发生 - // ClientPlayConnectionEvents.DISCONNECT.register(PcaSyncProtocol::onDisconnect); - DisconnectEvent.register(PcaSyncProtocol::onDisconnect); + //#endif + MagicLib.getInstance().getEventManager().register(DisconnectListener.class, PcaSyncProtocol::onDisconnect); } private static void onDisconnect() { @@ -72,14 +92,16 @@ private static void onDisconnect() { enable = false; } - private static void enablePcaSyncProtocolHandle(Minecraft client, ClientPacketListener handler, FriendlyByteBuf buf, PacketSender responseSender) { + public static void enablePcaSyncProtocolHandler(Minecraft client, ClientPacketListener handler, + FriendlyByteBuf buf, PacketSender responseSender) { if (!client.hasSingleplayerServer()) { ModInfo.LOGGER.info("pcaSyncProtocol enable."); enable = true; } } - private static void disablePcaSyncProtocolHandle(Minecraft client, ClientPacketListener handler, FriendlyByteBuf buf, PacketSender responseSender) { + public static void disablePcaSyncProtocolHandler(Minecraft client, ClientPacketListener handler, + FriendlyByteBuf buf, PacketSender responseSender) { if (!client.hasSingleplayerServer()) { ModInfo.LOGGER.info("pcaSyncProtocol disable."); enable = false; @@ -87,50 +109,96 @@ private static void disablePcaSyncProtocolHandle(Minecraft client, ClientPacketL } // 反序列化实体数据 - private static void updateEntityHandler(Minecraft client, ClientPacketListener handler, FriendlyByteBuf buf, PacketSender responseSender) { + public static void updateEntityHandler(Minecraft client, ClientPacketListener handler, + FriendlyByteBuf buf, PacketSender responseSender) { LocalPlayer player = client.player; + if (player == null) { return; } - Level world = player.getLevelCompat(); - if (!world.getDimensionLocation().equals(buf.readResourceLocation())) { + + PlayerCompat playerCompat = PlayerCompat.of(player); + LevelCompat levelCompat = playerCompat.getLevel(); + Level level = levelCompat.get(); + + if (!levelCompat.getDimensionLocation().equals(buf.readResourceLocation())) { return; } + int entityId = buf.readInt(); - CompoundTag tag = buf.readNbt(); - Entity entity = world.getEntity(entityId); + CompoundTag tag = NetworkUtil.readNbt(buf); + Entity entity = level.getEntity(entityId); if (entity != null) { ModInfo.LOGGER.debug("update entity!"); assert tag != null; + if (entity instanceof Mob) { if (tag.getBoolean("PersistenceRequired")) { ((Mob) entity).setPersistenceRequired(); } } + if (entity instanceof AbstractMinecartContainer) { NonNullList itemStacks = ((AccessorAbstractMinecartContainer) entity).getItemStacks(); itemStacks.clear(); - ContainerHelper.loadAllItems(tag, itemStacks); - } else if (entity instanceof AbstractVillager) { + ContainerHelper.loadAllItems( + tag, + itemStacks + //#if MC > 12004 + //$$ , client.level.registryAccess() + //#endif + ); + } + + if (entity instanceof AbstractVillager) { ((AbstractVillager) entity).getInventory().clearContent(); - ((AbstractVillager) entity).getInventory().fromTagCompat(tag.getList("Inventory", TagCompatApi.TAG_COMPOUND)); + SimpleContainerCompat.of(((AbstractVillager) entity).getInventory()).fromTag( + tag.getList("Inventory", TagCompat.TAG_COMPOUND) + //#if MC > 12004 + //$$ , client.level.registryAccess() + //#endif + ); + + //#if MC > 12004 + //$$ if (tag.contains("Offers")) { + //$$ MerchantOffers.CODEC + //$$ .parse(client.level.registryAccess().createSerializationContext(NbtOps.INSTANCE), + //$$ tag.getCompound("Offers").get("Offers")) + //$$ .resultOrPartial(Util.prefix("Failed to load offers: ", MagicLib.getLogger()::warn)) + //$$ .ifPresent(merchantOffers -> ((AccessorAbstractVillager) entity).setOffers(merchantOffers)); + //$$ } + //#else ((AccessorAbstractVillager) entity).setOffers(new MerchantOffers(tag.getCompound("Offers"))); + //#endif + if (entity instanceof Villager) { ((AccessorVillager) entity).setNumberOfRestocksToday(tag.getInt("RestocksToday")); ((AccessorVillager) entity).setLastRestockGameTime(tag.getLong("LastRestock")); ((AccessorLivingEntity) entity).setBrain(((AccessorLivingEntity) entity).invokeMakeBrain(new Dynamic<>(NbtOps.INSTANCE, tag.get("Brain")))); } - } else if (entity instanceof AbstractHorse) { + } + + if (entity instanceof AbstractHorse) { // TODO 写的更优雅一些 entity.load(tag); - } else if (entity instanceof Player) { + } + + if (entity instanceof Player) { Player playerEntity = (Player) entity; - playerEntity.getInventory().load(tag.getList("Inventory", TagCompatApi.TAG_COMPOUND)); - if (tag.contains("EnderItems", TagCompatApi.TAG_LIST)) { - playerEntity.getEnderChestInventory().fromTag(tag.getList("EnderItems", TagCompatApi.TAG_COMPOUND)); + PlayerCompat.of(playerEntity).getInventory().load(tag.getList("Inventory", TagCompat.TAG_COMPOUND)); + + if (tag.contains("EnderItems", TagCompat.TAG_LIST)) { + playerEntity.getEnderChestInventory().fromTag( + tag.getList("EnderItems", TagCompat.TAG_COMPOUND) + //#if MC > 12004 + //$$ , client.level.registryAccess() + //#endif + ); } - } else if (entity instanceof ZombieVillager) { + } + + if (entity instanceof ZombieVillager) { if (tag.contains("ConversionTime", 99) && tag.getInt("ConversionTime") > -1) { ((AccessorZombieVillager) entity).invokeStartConverting(tag.hasUUID("ConversionPlayer") ? tag.getUUID("ConversionPlayer") : null, tag.getInt("ConversionTime")); } @@ -139,70 +207,114 @@ private static void updateEntityHandler(Minecraft client, ClientPacketListener h } // 反序列化 blockEntity 数据 - private static void updateBlockEntityHandler(Minecraft client, ClientPacketListener handler, FriendlyByteBuf buf, PacketSender responseSender) { + public static void updateBlockEntityHandler(Minecraft client, ClientPacketListener handler, + FriendlyByteBuf buf, PacketSender responseSender) { LocalPlayer player = client.player; + if (player == null) { return; } - Level world = player.getLevelCompat(); - if (!world.getDimensionLocation().equals(buf.readResourceLocation())) { + + LevelCompat levelCompat = PlayerCompat.of(player).getLevel(); + Level level = levelCompat.get(); + + if (!levelCompat.getDimensionLocation().equals(buf.readResourceLocation())) { return; } + BlockPos pos = buf.readBlockPos(); CompoundTag tag = buf.readNbt(); - BlockEntity blockEntity = world.getBlockEntity(pos); - if (Configs.saveInventoryToSchematicInServer && pos.equals(PcaSyncUtil.lastUpdatePos)) { + BlockEntity blockEntity = level.getBlockEntity(pos); + + if (Configs.saveInventoryToSchematicInServer.getBooleanValue() && pos.equals(PcaSyncUtil.lastUpdatePos)) { InfoUtils.showGuiOrInGameMessage(Message.MessageType.SUCCESS, ModInfo.MOD_ID + ".message.loadInventoryToLocalSuccess"); PcaSyncUtil.lastUpdatePos = null; } + if (blockEntity != null) { ModInfo.LOGGER.debug("update blockEntity!"); - blockEntity.load(Objects.requireNonNull(tag)); + BlockEntityCompat.of(blockEntity).load( + Objects.requireNonNull(tag) + //#if MC > 12004 + //$$ , client.level.registryAccess() + //#endif + ); } } - static public void syncBlockEntity(BlockPos pos) { + public static void syncBlockEntity(BlockPos pos) { if (lastBlockPos != null && lastBlockPos.equals(pos)) { return; } + ModInfo.LOGGER.debug("syncBlockEntity: {}", pos); lastBlockPos = pos; lastEntityId = -1; FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); buf.writeBlockPos(pos); - ClientPlayNetworking.send(SYNC_BLOCK_ENTITY, buf); + ClientPlayNetworking.send( + //#if MC > 12004 + //$$ new ServerboundSyncBlockEntityPacket(buf) + //#else + SYNC_BLOCK_ENTITY, + buf + //#endif + ); } - static public void syncEntity(int entityId) { + public static void syncEntity(int entityId) { if (lastEntityId != -1 && lastEntityId == entityId) { return; } + ModInfo.LOGGER.debug("syncEntity: {}", entityId); lastEntityId = entityId; lastBlockPos = null; FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); buf.writeInt(entityId); - ClientPlayNetworking.send(SYNC_ENTITY, buf); + ClientPlayNetworking.send( + //#if MC > 12004 + //$$ new ServerboundSyncEntityPacket(buf) + //#else + SYNC_ENTITY, + buf + //#endif + ); } - static public void cancelSyncBlockEntity() { + public static void cancelSyncBlockEntity() { if (lastBlockPos == null) { return; } + lastBlockPos = null; ModInfo.LOGGER.debug("cancelSyncBlockEntity."); FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); - ClientPlayNetworking.send(CANCEL_SYNC_REQUEST_BLOCK_ENTITY, buf); + ClientPlayNetworking.send( + //#if MC > 12004 + //$$ new ServerboundCancelSyncBlockEntityPacket(buf) + //#else + CANCEL_SYNC_REQUEST_BLOCK_ENTITY, + buf + //#endif + ); } - static public void cancelSyncEntity() { + public static void cancelSyncEntity() { if (lastEntityId == -1) { return; } + lastEntityId = -1; ModInfo.LOGGER.debug("cancelSyncEntity."); FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); - ClientPlayNetworking.send(CANCEL_SYNC_ENTITY, buf); + ClientPlayNetworking.send( + //#if MC > 12004 + //$$ new ServerboundCancelSyncEntityPacket(buf) + //#else + CANCEL_SYNC_ENTITY, + buf + //#endif + ); } - } diff --git a/src/main/java/com/plusls/MasaGadget/litematica/saveInventoryToSchematicInServer/PcaSyncUtil.java b/src/main/java/com/plusls/MasaGadget/util/PcaSyncUtil.java similarity index 95% rename from src/main/java/com/plusls/MasaGadget/litematica/saveInventoryToSchematicInServer/PcaSyncUtil.java rename to src/main/java/com/plusls/MasaGadget/util/PcaSyncUtil.java index f7d0d4b2..85fe639d 100644 --- a/src/main/java/com/plusls/MasaGadget/litematica/saveInventoryToSchematicInServer/PcaSyncUtil.java +++ b/src/main/java/com/plusls/MasaGadget/util/PcaSyncUtil.java @@ -1,6 +1,5 @@ -package com.plusls.MasaGadget.litematica.saveInventoryToSchematicInServer; +package com.plusls.MasaGadget.util; -import com.plusls.MasaGadget.util.PcaSyncProtocol; import fi.dy.masa.litematica.selection.Box; import fi.dy.masa.litematica.util.EntityUtils; import fi.dy.masa.litematica.util.PositionUtils; diff --git a/src/main/java/com/plusls/MasaGadget/util/RenderUtil.java b/src/main/java/com/plusls/MasaGadget/util/RenderUtil.java index 5d6b9d9a..a9417738 100644 --- a/src/main/java/com/plusls/MasaGadget/util/RenderUtil.java +++ b/src/main/java/com/plusls/MasaGadget/util/RenderUtil.java @@ -1,95 +1,23 @@ package com.plusls.MasaGadget.util; -import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.*; import fi.dy.masa.malilib.render.RenderUtils; import fi.dy.masa.malilib.util.Color4f; -import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.client.renderer.entity.EntityRenderDispatcher; -import net.minecraft.core.BlockPos; -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.phys.Vec3; -import org.joml.Matrix4f; +import org.jetbrains.annotations.NotNull; //#if MC < 11700 //$$ import org.lwjgl.opengl.GL11; //#endif -//#if MC <= 11502 -//$$ import com.mojang.blaze3d.systems.RenderSystem; +//#if MC > 11404 +import com.mojang.blaze3d.systems.RenderSystem; //#endif public class RenderUtil { - - // 只能在 EntityRenderer.render 中调用 - public static void renderTextOnEntity(PoseStack matrixStack, Entity entity, - EntityRenderDispatcher entityRenderDispatcher, - Component text, float height, boolean seeThrough) { - if (entityRenderDispatcher.distanceToSqr(entity) <= 4096.0D) { - Position camPos = Minecraft.getInstance().gameRenderer.getMainCamera().getPosition(); - Position eysPos = entity.getEyePosition(0); - float xAngle = (float) Mth.atan2(camPos.z() - eysPos.z(), camPos.x() - eysPos.x()); - float YAngle = (float) Mth.atan2(camPos.x() - eysPos.x(), camPos.z() - eysPos.z()); - matrixStack.pushPose(); - matrixStack.translate(0.6 * Mth.cos(xAngle), height, 0.6 * Mth.cos(YAngle)); - matrixStack.mulPose(entityRenderDispatcher.cameraOrientation()); - matrixStack.scale(-0.018F, -0.018F, -0.018F); - renderText(matrixStack, text, seeThrough); - matrixStack.popPose(); - } - } - - - // 在 LevelRenderer.renderLevel 中调用 - public static void renderTextOnWorld(PoseStack matrixStack, Camera camera, BlockPos pos, - Component text, boolean seeThrough) { - matrixStack.pushPose(); - matrixStack.translate(pos.getX() + 0.5 - camera.getPosition().x(), pos.getY() + 0.6 - camera.getPosition().y(), pos.getZ() + 0.5 - camera.getPosition().z()); - // 保证文字面向玩家 - matrixStack.mulPose(camera.rotation()); - matrixStack.scale(-0.04F, -0.04F, -0.04F); - renderText(matrixStack, text, seeThrough); - matrixStack.popPose(); - } - - public static void renderText(PoseStack matrixStack, Component text, boolean seeThrough) { - - //#if MC <= 11502 - //$$ // 不加的话 minihud 渲染球体时会导致 bug - //$$ RenderSystem.disableLighting(); - //#endif - matrixStack.pushPose(); - Minecraft client = Minecraft.getInstance(); - Matrix4f matrix4f = matrixStack.last().pose(); - float backgroundOpacity = Minecraft.getInstance().options.getBackgroundOpacity(0.25F); - int backgroundColor = (int) (backgroundOpacity * 255.0F) << 24; - float xOffset = (float) (-client.font.width(text) / 2); - // ARG 1 text - // ARG 2 x - // ARG 3 y - // ARG 4 color - // COMMENT the text color in the 0xAARRGGBB format - // ARG 5 shadow - // ARG 6 matrix - // ARG 7 vertexConsumers - // ARG 8 seeThrough - // ARG 9 backgroundColor - // ARG 10 light - client.font.drawInBatch(text, xOffset, 0, 0x20ffffff, false, matrix4f, seeThrough, backgroundColor, 0xF000F0); - matrixStack.translate(0, 0, 2); - client.font.drawInBatch(text, xOffset, 0, 0xffffffff, false, matrix4f, seeThrough, 0, 0xF000F0); - matrixStack.popPose(); - //#if MC <= 11502 - //$$ RenderSystem.enableLighting(); - //#endif - } - - public static void drawConnectLine(Vec3 pos1, Vec3 pos2, double boxLength, Color4f pos1Color, Color4f pos2Color, Color4f lineColor) { + public static void drawConnectLine(Vec3 pos1, Vec3 pos2, double boxLength, Color4f pos1Color, Color4f pos2Color, @NotNull Color4f lineColor) { Vec3 camPos = Minecraft.getInstance().gameRenderer.getMainCamera().getPosition(); pos1 = pos1.subtract(camPos); pos2 = pos2.subtract(camPos); diff --git a/src/main/java/com/plusls/MasaGadget/tweakeroo/handRestockCrafting/RestockUtil.java b/src/main/java/com/plusls/MasaGadget/util/RestockUtil.java similarity index 73% rename from src/main/java/com/plusls/MasaGadget/tweakeroo/handRestockCrafting/RestockUtil.java rename to src/main/java/com/plusls/MasaGadget/util/RestockUtil.java index 8f8d39f6..0e8ee146 100644 --- a/src/main/java/com/plusls/MasaGadget/tweakeroo/handRestockCrafting/RestockUtil.java +++ b/src/main/java/com/plusls/MasaGadget/util/RestockUtil.java @@ -1,8 +1,8 @@ -package com.plusls.MasaGadget.tweakeroo.handRestockCrafting; +package com.plusls.MasaGadget.util; import com.google.common.collect.Lists; import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; +import com.plusls.MasaGadget.game.Configs; import fi.dy.masa.itemscroller.recipes.CraftingHandler; import fi.dy.masa.itemscroller.recipes.RecipePattern; import fi.dy.masa.itemscroller.recipes.RecipeStorage; @@ -16,7 +16,8 @@ import net.minecraft.world.inventory.ClickType; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; -import top.hendrixshen.magiclib.compat.minecraft.api.world.item.ItemStackCompatApi; +import top.hendrixshen.magiclib.api.compat.minecraft.world.entity.player.PlayerCompat; +import top.hendrixshen.magiclib.api.compat.minecraft.world.item.ItemStackCompat; import java.util.List; import java.util.stream.Collectors; @@ -29,7 +30,7 @@ public static void updateRecipes() { try { RestockUtil.recipes.clear(); - RestockUtil.recipes.addAll(Configs.restockWithCraftingRecipes.stream() + RestockUtil.recipes.addAll(Configs.restockWithCraftingRecipes.getStrings().stream() .mapToInt(Integer::valueOf) .mapToObj(storage::getRecipe) .filter(recipe -> recipe.getRecipeLength() == 4) @@ -43,31 +44,37 @@ public static void tryCraftingRestocking(Player player, InteractionHand hand, It if (player.isCreative()) { return; } - updateRecipes(); + + RestockUtil.updateRecipes(); // TODO: Lazy update (on itemscoller's RecipeStorage updated or config changed) Minecraft mc = Minecraft.getInstance(); AbstractContainerScreen gui = new InventoryScreen(player); gui.init(Minecraft.getInstance(), 0, 0); + for (RecipePattern recipe : RestockUtil.recipes) { - if (ItemStackCompatApi.isSameItemSameTags(recipe.getResult(), itemStack)) { + if (ItemStackCompat.isSameItemSameTags(recipe.getResult(), itemStack)) { InventoryUtils.tryMoveItemsToFirstCraftingGrid(recipe, gui, false); mc.gameMode.handleInventoryMouseClick(player.inventoryMenu.containerId, 0, 0, ClickType.PICKUP, player); - //#if MC > 11904 - if (ItemStack.isSameItem(player.inventoryMenu.getCarried(), itemStack)) { - //#elseif MC > 11902 - //$$ if (player.inventoryMenu.getCarried().sameItem(itemStack)) { - //#elseif MC > 11605 - //$$ if (player.inventoryMenu.getCarried().sameItemStackIgnoreDurability(itemStack)) { - //#else - //$$ if (player.getInventory().getCarried().sameItemStackIgnoreDurability(itemStack)) { - //#endif + + if ( + //#if MC > 11904 + ItemStack.isSameItem(player.inventoryMenu.getCarried(), itemStack) + //#elseif MC > 11902 + //$$ player.inventoryMenu.getCarried().sameItem(itemStack) + //#elseif MC > 11605 + //$$ player.inventoryMenu.getCarried().sameItemStackIgnoreDurability(itemStack) + //#else + //$$ PlayerCompat.of(player).getInventory().getCarried().sameItemStackIgnoreDurability(itemStack) + //#endif + ) { mc.gameMode.handleInventoryMouseClick(player.inventoryMenu.containerId, - hand == InteractionHand.MAIN_HAND ? player.getInventory().selected + 36 : 45, + hand == InteractionHand.MAIN_HAND ? PlayerCompat.of(player).getInventory().selected + 36 : 45, 0, ClickType.PICKUP, player); return; } else { Slot slot = CraftingHandler.getFirstCraftingOutputSlotForGui(gui); CraftingHandler.SlotRange range = CraftingHandler.getCraftingGridSlots(gui, slot); + for (int s = range.getFirst(); s <= range.getLast(); s++) { mc.gameMode.handleInventoryMouseClick(gui.getMenu().containerId, s, 0, ClickType.QUICK_MOVE, mc.player); } diff --git a/src/main/java/com/plusls/MasaGadget/util/SearchMobSpawnPointUtil.java b/src/main/java/com/plusls/MasaGadget/util/SearchMobSpawnPointUtil.java index e3027bf6..beb6445a 100644 --- a/src/main/java/com/plusls/MasaGadget/util/SearchMobSpawnPointUtil.java +++ b/src/main/java/com/plusls/MasaGadget/util/SearchMobSpawnPointUtil.java @@ -1,7 +1,7 @@ package com.plusls.MasaGadget.util; import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; +import com.plusls.MasaGadget.game.Configs; import fi.dy.masa.minihud.renderer.shapes.ShapeBase; import fi.dy.masa.minihud.renderer.shapes.ShapeDespawnSphere; import fi.dy.masa.minihud.renderer.shapes.ShapeManager; @@ -10,70 +10,72 @@ import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.player.LocalPlayer; import net.minecraft.core.BlockPos; -//#if MC >= 11903 -import net.minecraft.core.registries.BuiltInRegistries; -//#else -//$$ import net.minecraft.core.Registry; -//#endif -import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.SpawnPlacements; import net.minecraft.world.level.LightLayer; -import net.minecraft.world.level.NaturalSpawner; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.levelgen.Heightmap; import net.minecraft.world.level.lighting.LevelLightEngine; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.Nullable; -import top.hendrixshen.magiclib.compat.minecraft.api.network.chat.StyleCompatApi; -import top.hendrixshen.magiclib.util.FabricUtil; -import top.hendrixshen.magiclib.util.InfoUtil; +import top.hendrixshen.magiclib.MagicLib; +import top.hendrixshen.magiclib.api.compat.minecraft.network.chat.ComponentCompat; +import top.hendrixshen.magiclib.api.compat.minecraft.world.level.LevelCompat; +import top.hendrixshen.magiclib.util.minecraft.ComponentUtil; +import top.hendrixshen.magiclib.util.minecraft.InfoUtil; -import java.util.Objects; +//#if MC < 12005 +import net.minecraft.world.level.NaturalSpawner; +//#endif -//#if MC >= 11902 && MC < 11903 -//$$ import net.minecraft.Util; -//$$ import net.minecraft.client.gui.chat.ClientChatPreview; -//$$ import net.minecraft.network.chat.Component; +//#if MC > 11902 +import net.minecraft.core.registries.BuiltInRegistries; +//#else +//$$ import net.minecraft.core.Registry; //#endif public class SearchMobSpawnPointUtil { @Nullable private static ShapeDespawnSphere getShapeDespawnSphere() { ShapeDespawnSphere ret = null; + for (ShapeBase shapeBase : ShapeManager.INSTANCE.getAllShapes()) { if (shapeBase.isEnabled() && shapeBase instanceof ShapeDespawnSphere) { if (ret == null) { ret = (ShapeDespawnSphere) shapeBase; } else { - Objects.requireNonNull(Minecraft.getInstance().player).displayClientMessage( - ModInfo.translatable("message.onlySupportOneDespawnShape") - .withStyle(ChatFormatting.RED), false); + InfoUtil.displayChatMessage(ComponentUtil.tr("masa_gadget_mod.message.onlySupportOneDespawnShape") + .withStyle(ChatFormatting.RED).get()); return null; } } } + if (ret == null) { - Objects.requireNonNull(Minecraft.getInstance().player).displayClientMessage( - ModInfo.translatable("message.canNotFindDespawnShape") - .withStyle(ChatFormatting.RED), false); + InfoUtil.displayChatMessage(ComponentUtil.tr("masa_gadget_mod.message.canNotFindDespawnShape") + .withStyle(ChatFormatting.RED).get()); } + return ret; } public static void search() { - ClientLevel world = Minecraft.getInstance().level; + ClientLevel level = Minecraft.getInstance().level; LocalPlayer player = Minecraft.getInstance().player; - if (world == null || player == null) { + if (level == null || player == null) { return; } - ShapeDespawnSphere shapeDespawnSphere = getShapeDespawnSphere(); + + LevelCompat levelCompat = LevelCompat.of(level); + ShapeDespawnSphere shapeDespawnSphere = SearchMobSpawnPointUtil.getShapeDespawnSphere(); + if (shapeDespawnSphere == null) { return; } + Vec3 centerPos = shapeDespawnSphere.getCenter(); BlockPos pos = new BlockPos((int) centerPos.x, (int) centerPos.y, (int) centerPos.z); ModInfo.LOGGER.warn("shape: {}", shapeDespawnSphere.getCenter()); @@ -86,18 +88,21 @@ public static void search() { //#else //$$ int maxSpawnLightLevel = fi.dy.masa.minihud.config.Configs.Generic.LIGHT_LEVEL_THRESHOLD.getIntegerValue(); //#endif - LevelLightEngine lightingProvider = world.getChunkSource().getLightEngine(); - EntityType entityType = world.getDimensionLocation().equals(new ResourceLocation("the_nether")) ? EntityType.ZOMBIFIED_PIGLIN : EntityType.CREEPER; - EntityType entityType2 = world.getDimensionLocation().equals(new ResourceLocation("the_nether")) ? null : EntityType.SPIDER; + LevelLightEngine lightingProvider = level.getChunkSource().getLightEngine(); + EntityType entityType = levelCompat.getDimensionLocation().equals(new ResourceLocation("the_nether")) ? EntityType.ZOMBIFIED_PIGLIN : EntityType.CREEPER; + EntityType entityType2 = levelCompat.getDimensionLocation().equals(new ResourceLocation("the_nether")) ? null : EntityType.SPIDER; for (int x = pos.getX() - 129; x <= maxX; ++x) { for (int z = pos.getZ() - 129; z <= maxZ; ++z) { - LevelChunk chunk = world.getChunk(x >> 4, z >> 4); + LevelChunk chunk = level.getChunk(x >> 4, z >> 4); + if (chunk == null) { continue; } + int maxY = Math.min(pos.getY() + 129, chunk.getHeight(Heightmap.Types.WORLD_SURFACE, x, z) + 1); - for (int y = Math.max(pos.getY() - 129, world.getMinBuildHeight() + 1); y <= maxY; ++y) { + + for (int y = Math.max(pos.getY() - 129, levelCompat.getMinBuildHeight() + 1); y <= maxY; ++y) { if (squaredDistanceTo(x, y, z, centerPos) > 16384) { if (y > centerPos.y) { break; @@ -108,20 +113,40 @@ public static void search() { player.distanceToSqr(spawnPos.getX(), spawnPos.getY(), spawnPos.getZ())) { continue; } + currentPos.set(x, y, z); - if (NaturalSpawner.isSpawnPositionOk(SpawnPlacements.getPlacementType(entityType), world, currentPos, entityType) && - lightingProvider.getLayerListener(LightLayer.BLOCK).getLightValue(currentPos) < maxSpawnLightLevel) { - Block block = world.getBlockState(currentPos.below()).getBlock(); - //#if MC >= 11903 - String blockId = BuiltInRegistries.BLOCK.getKey(world.getBlockState(currentPos.below()).getBlock()).toString(); + + if ( + //#if MC > 12004 + //$$ SpawnPlacements.isSpawnPositionOk(entityType, level, currentPos) && //#else - //$$ String blockId = Registry.BLOCK.getKey(world.getBlockState(currentPos.below()).getBlock()).toString(); + NaturalSpawner.isSpawnPositionOk(SpawnPlacements.getPlacementType(entityType), level, currentPos, entityType) && + //#endif + lightingProvider.getLayerListener(LightLayer.BLOCK).getLightValue(currentPos) < maxSpawnLightLevel) { + Block block = level.getBlockState(currentPos.below()).getBlock(); + //#if MC > 11902 + String blockId = BuiltInRegistries.BLOCK.getKey(level.getBlockState(currentPos.below()).getBlock()).toString(); + //#else + //$$ String blockId = Registry.BLOCK.getKey(level.getBlockState(currentPos.below()).getBlock()).toString(); //#endif String blockName = block.getName().getString(); - if (Configs.searchMobSpawnPointBlackList.stream().noneMatch(s -> blockId.contains(s) || blockName.contains(s))) { - if (world.noCollision(entityType.getAABB(currentPos.getX() + 0.5D, currentPos.getY(), currentPos.getZ() + 0.5D))) { + + if (Configs.searchMobSpawnPointBlackList.getStrings().stream().noneMatch(s -> blockId.contains(s) || blockName.contains(s))) { + if (level.noCollision( + //#if MC > 12004 + //$$ entityType.getSpawnAABB(currentPos.getX() + 0.5D, currentPos.getY(), currentPos.getZ() + 0.5D) + //#else + entityType.getAABB(currentPos.getX() + 0.5D, currentPos.getY(), currentPos.getZ() + 0.5D) + //#endif + )) { spawnPos = currentPos.immutable(); - } else if (entityType2 != null && world.noCollision(entityType2.getAABB(currentPos.getX() + 0.5D, currentPos.getY(), currentPos.getZ() + 0.5D))) { + } else if (entityType2 != null && level.noCollision( + //#if MC > 12004 + //$$ entityType.getSpawnAABB(currentPos.getX() + 0.5D, currentPos.getY(), currentPos.getZ() + 0.5D) + //#else + entityType2.getAABB(currentPos.getX() + 0.5D, currentPos.getY(), currentPos.getZ() + 0.5D) + //#endif + )) { spawnPos = currentPos.immutable(); } } @@ -129,18 +154,22 @@ public static void search() { } } } - Component text; + + ComponentCompat text; + if (spawnPos == null) { - text = ModInfo.translatable("message.noBlockCanSpawn") - .withStyle(StyleCompatApi.empty().withColor(ChatFormatting.GREEN)); + text = ComponentUtil.tr("masa_gadget_mod.message.noBlockCanSpawn") + .withStyle(ChatFormatting.GREEN); } else { // for ommc parser - text = ModInfo.translatable("message.spawnPos", spawnPos.getX(), spawnPos.getY(), spawnPos.getZ()); - if (FabricUtil.isModLoaded(ModInfo.OMMC_MOD_ID)) { + text = ComponentUtil.tr("masa_gadget_mod.message.spawnPos", spawnPos.getX(), spawnPos.getY(), spawnPos.getZ()); + + if (MagicLib.getInstance().getCurrentPlatform().isModLoaded(ModInfo.OMMC_MOD_ID)) { InfoUtil.sendCommand(String.format("highlightWaypoint %d %d %d", spawnPos.getX(), spawnPos.getY(), spawnPos.getZ())); } } - InfoUtil.displayChatMessage(text); + + InfoUtil.displayChatMessage(text.get()); } 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 e4a78ddb..5d7a721d 100644 --- a/src/main/java/com/plusls/MasaGadget/util/SyncUtil.java +++ b/src/main/java/com/plusls/MasaGadget/util/SyncUtil.java @@ -4,6 +4,7 @@ import net.minecraft.client.server.IntegratedServer; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; +import top.hendrixshen.magiclib.api.compat.minecraft.world.entity.EntityCompat; public class SyncUtil { /** @@ -18,11 +19,15 @@ public static Entity syncEntityDataFromIntegratedServer(Entity entity) { return entity; } - //#if MC > 11502 - ServerLevel level = server.getLevel(entity.getLevelCompat().dimension()); - //#else - //$$ ServerLevel level = server.getLevel(entity.dimension); - //#endif + EntityCompat entityCompat = EntityCompat.of(entity); + + ServerLevel level = server.getLevel( + //#if MC > 11502 + entityCompat.getLevel().get().dimension() + //#else + //$$ entity.dimension + //#endif + ); if (level == null) { return entity; diff --git a/src/main/resources/assets/masa_gadget_mod/lang/en_us.json b/src/main/resources/assets/masa_gadget_mod/lang/en_us.json index ff04f211..af010644 100644 --- a/src/main/resources/assets/masa_gadget_mod/lang/en_us.json +++ b/src/main/resources/assets/masa_gadget_mod/lang/en_us.json @@ -1,97 +1,98 @@ { - "masa_gadget_mod.gui.button.tab.generic": "Generic", - "masa_gadget_mod.gui.button.tab.litematica": "Litematica", - "masa_gadget_mod.gui.button.tab.malilib": "Malilib", - "masa_gadget_mod.gui.button.tab.minihud": "Minihud", - "masa_gadget_mod.gui.button.tab.tweakeroo": "Tweakeroo", + "masa_gadget_mod.config.category.generic.name": "Generic", + "masa_gadget_mod.config.category.all.name": "All", + "masa_gadget_mod.config.category.litematica.name": "Litematica", + "masa_gadget_mod.config.category.malilib.name": "Malilib", + "masa_gadget_mod.config.category.minihud.name": "MiniHud", + "masa_gadget_mod.config.category.tweakeroo.name": "Tweakeroo", "masa_gadget_mod.gui.title.configs": "MasaGadget - Config - Version: %s", - "masa_gadget_mod.config.generic.autoSyncEntityData.name": "autoSyncEntityData", - "masa_gadget_mod.config.generic.autoSyncEntityData.comment": "Auto use pcaSyncProtocol to sync entity data", - "masa_gadget_mod.config.generic.cacheContainerMenu.name": "cacheContainerMenu", - "masa_gadget_mod.config.generic.cacheContainerMenu.comment": "Cache container menu, minecraft will cache inventory data from server when open inventory", - "masa_gadget_mod.config.generic.debug.name": "debug", - "masa_gadget_mod.config.generic.debug.comment": "Display debug message", - "masa_gadget_mod.config.generic.openConfigGui.name": "openConfigGui", - "masa_gadget_mod.config.generic.openConfigGui.comment": "A hotkey to open the in-game Config GUI", - "masa_gadget_mod.config.generic.renderNextRestockTime.name": "renderNextRestockTime", - "masa_gadget_mod.config.generic.renderNextRestockTime.comment": "Render next restock time on villager.", - "masa_gadget_mod.config.generic.renderTradeEnchantedBook.name": "renderTradeEnchantedBook", - "masa_gadget_mod.config.generic.renderTradeEnchantedBook.comment": "Render trade enchanted book text on villager.", - "masa_gadget_mod.config.generic.renderVillageHomeTracer.name": "renderVillageHomeTracer", - "masa_gadget_mod.config.generic.renderVillageHomeTracer.comment": "Render the tracking line of the villager to the home.", - "masa_gadget_mod.config.generic.renderVillageHomeTracerColor.name": "renderVillageHomeTracerColor", - "masa_gadget_mod.config.generic.renderVillageHomeTracerColor.comment": "renderVillageHomeTracer track line color.", - "masa_gadget_mod.config.generic.renderVillageJobSiteTracer.name": "renderVillageJobSiteTracer", - "masa_gadget_mod.config.generic.renderVillageJobSiteTracer.comment": "Render tracking line of villager to the job site.", - "masa_gadget_mod.config.generic.renderVillageJobSiteTracerColor.name": "renderVillageJobSiteTracerColor", - "masa_gadget_mod.config.generic.renderVillageJobSiteTracerColor.comment": "renderVillageJobSiteTracer track line color.", - "masa_gadget_mod.config.generic.renderZombieVillagerConvertTime.name": "renderZombieVillagerConvertTime", - "masa_gadget_mod.config.generic.renderZombieVillagerConvertTime.comment": "Render zombie villager convert time on zombie villager.", - "masa_gadget_mod.config.generic.searchMobSpawnPoint.name": "searchMobSpawnPoint", - "masa_gadget_mod.config.generic.searchMobSpawnPoint.comment": "Search mob spawn point. Need set §6Despawn Sphere§r in minihud, \nand light check depends on §6lightLevelThresholdSafe§r in minihud", - "masa_gadget_mod.config.generic.searchMobSpawnPointBlackList.name": "searchMobSpawnPointBlackList", - "masa_gadget_mod.config.generic.searchMobSpawnPointBlackList.comment": "Don't search blocks in this list.", - "masa_gadget_mod.config.generic.syncAllEntityData.name": "syncAllEntityData", - "masa_gadget_mod.config.generic.syncAllEntityData.comment": "Use pcaSyncProtocol to sync all entity data.", + "masa_gadget_mod.config.option.autoSyncEntityData.name": "autoSyncEntityData", + "masa_gadget_mod.config.option.autoSyncEntityData.comment": "Auto use pcaSyncProtocol to sync entity data", + "masa_gadget_mod.config.option.cacheContainerMenu.name": "cacheContainerMenu", + "masa_gadget_mod.config.option.cacheContainerMenu.comment": "Cache container menu, minecraft will cache inventory data from server when open inventory", + "masa_gadget_mod.config.option.debug.name": "debug", + "masa_gadget_mod.config.option.debug.comment": "Display debug message", + "masa_gadget_mod.config.option.openConfigGui.name": "openConfigGui", + "masa_gadget_mod.config.option.openConfigGui.comment": "A hotkey to open the in-game Config GUI", + "masa_gadget_mod.config.option.renderNextRestockTime.name": "renderNextRestockTime", + "masa_gadget_mod.config.option.renderNextRestockTime.comment": "Render next restock time on villager.", + "masa_gadget_mod.config.option.renderTradeEnchantedBook.name": "renderTradeEnchantedBook", + "masa_gadget_mod.config.option.renderTradeEnchantedBook.comment": "Render trade enchanted book text on villager.", + "masa_gadget_mod.config.option.renderVillageHomeTracer.name": "renderVillageHomeTracer", + "masa_gadget_mod.config.option.renderVillageHomeTracer.comment": "Render the tracking line of the villager to the home.", + "masa_gadget_mod.config.option.renderVillageHomeTracerColor.name": "renderVillageHomeTracerColor", + "masa_gadget_mod.config.option.renderVillageHomeTracerColor.comment": "renderVillageHomeTracer track line color.", + "masa_gadget_mod.config.option.renderVillageJobSiteTracer.name": "renderVillageJobSiteTracer", + "masa_gadget_mod.config.option.renderVillageJobSiteTracer.comment": "Render tracking line of villager to the job site.", + "masa_gadget_mod.config.option.renderVillageJobSiteTracerColor.name": "renderVillageJobSiteTracerColor", + "masa_gadget_mod.config.option.renderVillageJobSiteTracerColor.comment": "renderVillageJobSiteTracer track line color.", + "masa_gadget_mod.config.option.renderZombieVillagerConvertTime.name": "renderZombieVillagerConvertTime", + "masa_gadget_mod.config.option.renderZombieVillagerConvertTime.comment": "Render zombie villager convert time on zombie villager.", + "masa_gadget_mod.config.option.searchMobSpawnPoint.name": "searchMobSpawnPoint", + "masa_gadget_mod.config.option.searchMobSpawnPoint.comment": "Search mob spawn point. Need set §6Despawn Sphere§r in minihud, \nand light check depends on §6lightLevelThresholdSafe§r in minihud", + "masa_gadget_mod.config.option.searchMobSpawnPointBlackList.name": "searchMobSpawnPointBlackList", + "masa_gadget_mod.config.option.searchMobSpawnPointBlackList.comment": "Don't search blocks in this list.", + "masa_gadget_mod.config.option.syncAllEntityData.name": "syncAllEntityData", + "masa_gadget_mod.config.option.syncAllEntityData.comment": "Use pcaSyncProtocol to sync all entity data.", - "masa_gadget_mod.config.litematica.betterEasyPlaceMode.name": "betterEasyPlaceMode", - "masa_gadget_mod.config.litematica.betterEasyPlaceMode.comment": "Easy place mode can open inventory (such as chest, hopper, etc.), \nand can use beacon.", - "masa_gadget_mod.config.litematica.disableLitematicaEasyPlaceFailTip.name": "disableLitematicaEasyPlaceFailTip", - "masa_gadget_mod.config.litematica.disableLitematicaEasyPlaceFailTip.comment": "Disable easyPlace failure that annoying prompt window.", - "masa_gadget_mod.config.litematica.fixAccurateProtocol.name": "fixAccurateProtocol", - "masa_gadget_mod.config.litematica.fixAccurateProtocol.comment": "Fix accurate protocol support", - "masa_gadget_mod.config.litematica.nudgeSelectionSupportFreeCamera.name": "nudgeSelectionSupportFreeCamera", - "masa_gadget_mod.config.litematica.nudgeSelectionSupportFreeCamera.comment": "Nudge Selection Support Free Camera", - "masa_gadget_mod.config.litematica.saveInventoryToSchematicInServer.name": "saveInventoryToSchematicInServer", - "masa_gadget_mod.config.litematica.saveInventoryToSchematicInServer.comment": "Use pcaSyncProtocol to sync inventory data to local and save to schematic", - "masa_gadget_mod.config.litematica.useRelativePath.name": "useRelativePath", - "masa_gadget_mod.config.litematica.useRelativePath.comment": "Save and load schematic use relative path", + "masa_gadget_mod.config.option.betterEasyPlaceMode.name": "betterEasyPlaceMode", + "masa_gadget_mod.config.option.betterEasyPlaceMode.comment": "Easy place mode can open inventory (such as chest, hopper, etc.), \nand can use beacon.", + "masa_gadget_mod.config.option.disableLitematicaEasyPlaceFailTip.name": "disableLitematicaEasyPlaceFailTip", + "masa_gadget_mod.config.option.disableLitematicaEasyPlaceFailTip.comment": "Disable easyPlace failure that annoying prompt window.", + "masa_gadget_mod.config.option.fixAccurateProtocol.name": "fixAccurateProtocol", + "masa_gadget_mod.config.option.fixAccurateProtocol.comment": "Fix accurate protocol support", + "masa_gadget_mod.config.option.nudgeSelectionSupportFreeCamera.name": "nudgeSelectionSupportFreeCamera", + "masa_gadget_mod.config.option.nudgeSelectionSupportFreeCamera.comment": "Nudge Selection Support Free Camera", + "masa_gadget_mod.config.option.saveInventoryToSchematicInServer.name": "saveInventoryToSchematicInServer", + "masa_gadget_mod.config.option.saveInventoryToSchematicInServer.comment": "Use pcaSyncProtocol to sync inventory data to local and save to schematic", + "masa_gadget_mod.config.option.useRelativePath.name": "useRelativePath", + "masa_gadget_mod.config.option.useRelativePath.comment": "Save and load schematic use relative path", - "masa_gadget_mod.config.malilib.backportI18nSupport.name": "backportI18nSupport", - "masa_gadget_mod.config.malilib.backportI18nSupport.comment": "Backport masa mod i18n support from 1.18.x", - "masa_gadget_mod.config.malilib.fastSwitchMasaConfigGui.name": "fastSwitchMasaConfigGui", - "masa_gadget_mod.config.malilib.fastSwitchMasaConfigGui.comment": "Render drop down list widget, player can switch other masa's mod config gui quickly.", - "masa_gadget_mod.config.malilib.favoritesSupport.name": "favoritesSupport", - "masa_gadget_mod.config.malilib.favoritesSupport.comment": "Users can favorite and filter their frequently used options.", - "masa_gadget_mod.config.malilib.fixConfigWidgetWidth.name": "fixConfigWidgetWidth", - "masa_gadget_mod.config.malilib.fixConfigWidgetWidth.comment": "Use the length of getTranslatedGuiDisplayName as widget width", - "masa_gadget_mod.config.malilib.fixGetInventoryType.name": "fixGetInventoryType", - "masa_gadget_mod.config.malilib.fixGetInventoryType.comment": "Fix AbstractFurnaceBlock inventory type", - "masa_gadget_mod.config.malilib.fixSearchbarHotkeyInput.name": "fixSearchbarHotkeyInput", - "masa_gadget_mod.config.malilib.fixSearchbarHotkeyInput.comment": "Fix searchbar input when press hotkey to open config gui.", - "masa_gadget_mod.config.malilib.optimizeConfigWidgetSearch.name": "optimizeConfigWidgetSearch", - "masa_gadget_mod.config.malilib.optimizeConfigWidgetSearch.comment": "Make search support uppercase, translate text, and can use §6modified§r to search modified config", - "masa_gadget_mod.config.malilib.showOriginalConfigName.name": "showOriginalConfigName", - "masa_gadget_mod.config.malilib.showOriginalConfigName.comment": "Show original config name when config gui display name no the same as original config name.", - "masa_gadget_mod.config.malilib.showOriginalConfigNameScale.name": "showOriginalConfigNameScale", - "masa_gadget_mod.config.malilib.showOriginalConfigNameScale.comment": "Original config name font scale.", + "masa_gadget_mod.config.option.backportI18nSupport.name": "backportI18nSupport", + "masa_gadget_mod.config.option.backportI18nSupport.comment": "Backport masa mod i18n support from 1.18.x", + "masa_gadget_mod.config.option.fastSwitchMasaConfigGui.name": "fastSwitchMasaConfigGui", + "masa_gadget_mod.config.option.fastSwitchMasaConfigGui.comment": "Render drop down list widget, player can switch other masa's mod config gui quickly.", + "masa_gadget_mod.config.option.favoritesSupport.name": "favoritesSupport", + "masa_gadget_mod.config.option.favoritesSupport.comment": "Users can favorite and filter their frequently used options.", + "masa_gadget_mod.config.option.fixConfigWidgetWidth.name": "fixConfigWidgetWidth", + "masa_gadget_mod.config.option.fixConfigWidgetWidth.comment": "Use the length of getTranslatedGuiDisplayName as widget width", + "masa_gadget_mod.config.option.fixGetInventoryType.name": "fixGetInventoryType", + "masa_gadget_mod.config.option.fixGetInventoryType.comment": "Fix AbstractFurnaceBlock inventory type", + "masa_gadget_mod.config.option.fixSearchbarHotkeyInput.name": "fixSearchbarHotkeyInput", + "masa_gadget_mod.config.option.fixSearchbarHotkeyInput.comment": "Fix searchbar input when press hotkey to open config gui.", + "masa_gadget_mod.config.option.optimizeConfigWidgetSearch.name": "optimizeConfigWidgetSearch", + "masa_gadget_mod.config.option.optimizeConfigWidgetSearch.comment": "Make search support uppercase, translate text, and can use §6modified§r to search modified config", + "masa_gadget_mod.config.option.showOriginalConfigName.name": "showOriginalConfigName", + "masa_gadget_mod.config.option.showOriginalConfigName.comment": "Show original config name when config gui display name no the same as original config name.", + "masa_gadget_mod.config.option.showOriginalConfigNameScale.name": "showOriginalConfigNameScale", + "masa_gadget_mod.config.option.showOriginalConfigNameScale.comment": "Original config name font scale.", - "masa_gadget_mod.config.minihud.minihudI18n.name": "minihudI18n", - "masa_gadget_mod.config.minihud.minihudI18n.comment": "Minihud display text support i18n translate.", - "masa_gadget_mod.config.minihud.pcaSyncProtocolSyncBeehive.name": "pcaSyncProtocolSyncBeehive", - "masa_gadget_mod.config.minihud.pcaSyncProtocolSyncBeehive.comment": "Press §6inventoryPreview§r hotkey to use PCA sync protocol to sync Beehive", + "masa_gadget_mod.config.option.minihudI18n.name": "minihudI18n", + "masa_gadget_mod.config.option.minihudI18n.comment": "Minihud display text support i18n translate.", + "masa_gadget_mod.config.option.pcaSyncProtocolSyncBeehive.name": "pcaSyncProtocolSyncBeehive", + "masa_gadget_mod.config.option.pcaSyncProtocolSyncBeehive.comment": "Press §6inventoryPreview§r hotkey to use PCA sync protocol to sync Beehive", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSupportComparator.name": "inventoryPreviewSupportComparator", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSupportComparator.comment": "Inventory preview will render the output of comparator.", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSupportPlayer.name": "inventoryPreviewSupportPlayer", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSupportPlayer.comment": "Player can use inventory preview to show the inventory of player and ender chest inventory", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSupportSelect.name": "inventoryPreviewSupportSelect", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSupportSelect.comment": "When player press the inventory preview hotkey, \nplayer can use the mouse wheel to select items (player can view the enchantment information), and when player select the shulker box in the chest, player can press the mouse scroll to preview the items in the box", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSupportShulkerBoxItemEntity.name": "inventoryPreviewSupportShulkerBoxItemEntity", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSupportShulkerBoxItemEntity.comment": "Inventory preview support shulker box item entity.", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSupportTradeOfferList.name": "inventoryPreviewSupportTradeOfferList", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSupportTradeOfferList.comment": "Inventory preview will preview the trade offer list of merchant", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSyncData.name": "inventoryPreviewSyncData", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSyncData.comment": "When toggle inventory preview, use pcaSyncProtocol to sync block entity data and entity data from server, such as chest, villager", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSyncDataClientOnly.name": "inventoryPreviewSyncDataClientOnly", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSyncDataClientOnly.comment": "Open inventory to sync inventory data when use inventory preview", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewUseCache.name": "inventoryPreviewUseCache", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewUseCache.comment": "Inventory preview get the hit result from cache, to reduce lag when render", - "masa_gadget_mod.config.tweakeroo.restockWithCrafting.name": "restockWithCrafting", - "masa_gadget_mod.config.tweakeroo.restockWithCrafting.comment": "Automatically craft required items in the 2x2 crafting grid \nwhen Tweakeroo can't find the item. This feature requires ItemScroller。", - "masa_gadget_mod.config.tweakeroo.restockWithCraftingRecipes.name": "restockWithCraftingRecipes", - "masa_gadget_mod.config.tweakeroo.restockWithCraftingRecipes.comment": "Recipe indexes in ItemScroller recipe storage. Note: only 2x2 recipes are supported.", + "masa_gadget_mod.config.option.inventoryPreviewSupportComparator.name": "inventoryPreviewSupportComparator", + "masa_gadget_mod.config.option.inventoryPreviewSupportComparator.comment": "Inventory preview will render the output of comparator.", + "masa_gadget_mod.config.option.inventoryPreviewSupportPlayer.name": "inventoryPreviewSupportPlayer", + "masa_gadget_mod.config.option.inventoryPreviewSupportPlayer.comment": "Player can use inventory preview to show the inventory of player and ender chest inventory", + "masa_gadget_mod.config.option.inventoryPreviewSupportSelect.name": "inventoryPreviewSupportSelect", + "masa_gadget_mod.config.option.inventoryPreviewSupportSelect.comment": "When player press the inventory preview hotkey, \nplayer can use the mouse wheel to select items (player can view the enchantment information), and when player select the shulker box in the chest, player can press the mouse scroll to preview the items in the box", + "masa_gadget_mod.config.option.inventoryPreviewSupportShulkerBoxItemEntity.name": "inventoryPreviewSupportShulkerBoxItemEntity", + "masa_gadget_mod.config.option.inventoryPreviewSupportShulkerBoxItemEntity.comment": "Inventory preview support shulker box item entity.", + "masa_gadget_mod.config.option.inventoryPreviewSupportTradeOfferList.name": "inventoryPreviewSupportTradeOfferList", + "masa_gadget_mod.config.option.inventoryPreviewSupportTradeOfferList.comment": "Inventory preview will preview the trade offer list of merchant", + "masa_gadget_mod.config.option.inventoryPreviewSyncData.name": "inventoryPreviewSyncData", + "masa_gadget_mod.config.option.inventoryPreviewSyncData.comment": "When toggle inventory preview, use pcaSyncProtocol to sync block entity data and entity data from server, such as chest, villager", + "masa_gadget_mod.config.option.inventoryPreviewSyncDataClientOnly.name": "inventoryPreviewSyncDataClientOnly", + "masa_gadget_mod.config.option.inventoryPreviewSyncDataClientOnly.comment": "Open inventory to sync inventory data when use inventory preview", + "masa_gadget_mod.config.option.inventoryPreviewUseCache.name": "inventoryPreviewUseCache", + "masa_gadget_mod.config.option.inventoryPreviewUseCache.comment": "Inventory preview get the hit result from cache, to reduce lag when render", + "masa_gadget_mod.config.option.restockWithCrafting.name": "restockWithCrafting", + "masa_gadget_mod.config.option.restockWithCrafting.comment": "Automatically craft required items in the 2x2 crafting grid \nwhen Tweakeroo can't find the item. This feature requires ItemScroller。", + "masa_gadget_mod.config.option.restockWithCraftingRecipes.name": "restockWithCraftingRecipes", + "masa_gadget_mod.config.option.restockWithCraftingRecipes.comment": "Recipe indexes in ItemScroller recipe storage. Note: only 2x2 recipes are supported.", "masa_gadget_mod.message.canNotFindDespawnShape": "Can't find despawn shape.", "masa_gadget_mod.message.cancelFavorite": "Cancel favorite.", diff --git a/src/main/resources/assets/masa_gadget_mod/lang/zh_cn.json b/src/main/resources/assets/masa_gadget_mod/lang/zh_cn.json index d83d909f..735de3e6 100644 --- a/src/main/resources/assets/masa_gadget_mod/lang/zh_cn.json +++ b/src/main/resources/assets/masa_gadget_mod/lang/zh_cn.json @@ -1,97 +1,98 @@ { - "masa_gadget_mod.gui.button.tab.generic": "通用", - "masa_gadget_mod.gui.button.tab.litematica": "Litematica", - "masa_gadget_mod.gui.button.tab.malilib": "Malilib", - "masa_gadget_mod.gui.button.tab.minihud": "Minihud", - "masa_gadget_mod.gui.button.tab.tweakeroo": "Tweakeroo", + "masa_gadget_mod.config.category.generic.name": "Generic", + "masa_gadget_mod.config.category.all.name": "All", + "masa_gadget_mod.config.category.litematica.name": "Litematica", + "masa_gadget_mod.config.category.malilib.name": "Malilib", + "masa_gadget_mod.config.category.minihud.name": "MiniHud", + "masa_gadget_mod.config.category.tweakeroo.name": "Tweakeroo", "masa_gadget_mod.gui.title.configs": "MasaGadget 设置 - 版本: %s", - "masa_gadget_mod.config.generic.autoSyncEntityData.name": "自动同步实体数据", - "masa_gadget_mod.config.generic.autoSyncEntityData.comment": "自动使用 PCA 同步协议来同步实体数据(如村民补货时间,僵尸村民转换时间,怪物是否消失)", - "masa_gadget_mod.config.generic.cacheContainerMenu.name": "缓存容器数据", - "masa_gadget_mod.config.generic.cacheContainerMenu.comment": "在打开容器的时候会自动缓存容器数据到本地", - "masa_gadget_mod.config.generic.debug.name": "调试模式", - "masa_gadget_mod.config.generic.debug.comment": "开启后将会打印调试日志", - "masa_gadget_mod.config.generic.openConfigGui.name": "打开设置界面", - "masa_gadget_mod.config.generic.openConfigGui.comment": "打开设置界面的快捷键", - "masa_gadget_mod.config.generic.renderNextRestockTime.name": "渲染村民交易补货冷却", - "masa_gadget_mod.config.generic.renderNextRestockTime.comment": "渲染距离村民下一次补货还需要多长时间", - "masa_gadget_mod.config.generic.renderTradeEnchantedBook.name": "渲染村民交易的第一本附魔书", - "masa_gadget_mod.config.generic.renderTradeEnchantedBook.comment": "渲染村民交易的第一本附魔书,如果是满级附魔则会显示金色文本,同时还会显示出价格,\n绿色表示良商,白色表示中商,红色表示奸商", - "masa_gadget_mod.config.generic.renderVillageHomeTracer.name": "渲染村民绑定床", - "masa_gadget_mod.config.generic.renderVillageHomeTracer.comment": "渲染村民到床的追踪线.", - "masa_gadget_mod.config.generic.renderVillageHomeTracerColor.name": "渲染村民绑定床颜色", - "masa_gadget_mod.config.generic.renderVillageHomeTracerColor.comment": "渲染村民绑定床追踪线颜色.", - "masa_gadget_mod.config.generic.renderVillageJobSiteTracer.name": "渲染村民绑定工作方块", - "masa_gadget_mod.config.generic.renderVillageJobSiteTracer.comment": "渲染村民到工作方块的追踪线", - "masa_gadget_mod.config.generic.renderVillageJobSiteTracerColor.name": "渲染村民绑定工作方块颜色", - "masa_gadget_mod.config.generic.renderVillageJobSiteTracerColor.comment": "渲染村民绑定工作方块追踪线颜色.", - "masa_gadget_mod.config.generic.renderZombieVillagerConvertTime.name": "渲染僵尸村民转换时间", - "masa_gadget_mod.config.generic.renderZombieVillagerConvertTime.comment": "渲染距离僵尸村民转换完成还需要多长时间", - "masa_gadget_mod.config.generic.searchMobSpawnPoint.name": "搜寻可刷怪的地方", - "masa_gadget_mod.config.generic.searchMobSpawnPoint.comment": "搜寻可刷怪的地方。需要在 minihud 中设置 §6怪物立刻消失范围球体§r,\n亮度检查取决于 minihud 中的 §6lightLevelThresholdSafe§r 设置", - "masa_gadget_mod.config.generic.searchMobSpawnPointBlackList.name": "搜寻刷怪点黑名单", - "masa_gadget_mod.config.generic.searchMobSpawnPointBlackList.comment": "在黑名单中的方块会跳过搜索", - "masa_gadget_mod.config.generic.syncAllEntityData.name": "同步所有实体数据", - "masa_gadget_mod.config.generic.syncAllEntityData.comment": "使用 pca 同步协议同步所有实体数据", + "masa_gadget_mod.config.option.autoSyncEntityData.name": "自动同步实体数据", + "masa_gadget_mod.config.option.autoSyncEntityData.comment": "自动使用 PCA 同步协议来同步实体数据(如村民补货时间,僵尸村民转换时间,怪物是否消失)", + "masa_gadget_mod.config.option.cacheContainerMenu.name": "缓存容器数据", + "masa_gadget_mod.config.option.cacheContainerMenu.comment": "在打开容器的时候会自动缓存容器数据到本地", + "masa_gadget_mod.config.option.debug.name": "调试模式", + "masa_gadget_mod.config.option.debug.comment": "开启后将会打印调试日志", + "masa_gadget_mod.config.option.openConfigGui.name": "打开设置界面", + "masa_gadget_mod.config.option.openConfigGui.comment": "打开设置界面的快捷键", + "masa_gadget_mod.config.option.renderNextRestockTime.name": "渲染村民交易补货冷却", + "masa_gadget_mod.config.option.renderNextRestockTime.comment": "渲染距离村民下一次补货还需要多长时间", + "masa_gadget_mod.config.option.renderTradeEnchantedBook.name": "渲染村民交易的第一本附魔书", + "masa_gadget_mod.config.option.renderTradeEnchantedBook.comment": "渲染村民交易的第一本附魔书,如果是满级附魔则会显示金色文本,同时还会显示出价格,\n绿色表示良商,白色表示中商,红色表示奸商", + "masa_gadget_mod.config.option.renderVillageHomeTracer.name": "渲染村民绑定床", + "masa_gadget_mod.config.option.renderVillageHomeTracer.comment": "渲染村民到床的追踪线.", + "masa_gadget_mod.config.option.renderVillageHomeTracerColor.name": "渲染村民绑定床颜色", + "masa_gadget_mod.config.option.renderVillageHomeTracerColor.comment": "渲染村民绑定床追踪线颜色.", + "masa_gadget_mod.config.option.renderVillageJobSiteTracer.name": "渲染村民绑定工作方块", + "masa_gadget_mod.config.option.renderVillageJobSiteTracer.comment": "渲染村民到工作方块的追踪线", + "masa_gadget_mod.config.option.renderVillageJobSiteTracerColor.name": "渲染村民绑定工作方块颜色", + "masa_gadget_mod.config.option.renderVillageJobSiteTracerColor.comment": "渲染村民绑定工作方块追踪线颜色.", + "masa_gadget_mod.config.option.renderZombieVillagerConvertTime.name": "渲染僵尸村民转换时间", + "masa_gadget_mod.config.option.renderZombieVillagerConvertTime.comment": "渲染距离僵尸村民转换完成还需要多长时间", + "masa_gadget_mod.config.option.searchMobSpawnPoint.name": "搜寻可刷怪的地方", + "masa_gadget_mod.config.option.searchMobSpawnPoint.comment": "搜寻可刷怪的地方。需要在 minihud 中设置 §6怪物立刻消失范围球体§r,\n亮度检查取决于 minihud 中的 §6lightLevelThresholdSafe§r 设置", + "masa_gadget_mod.config.option.searchMobSpawnPointBlackList.name": "搜寻刷怪点黑名单", + "masa_gadget_mod.config.option.searchMobSpawnPointBlackList.comment": "在黑名单中的方块会跳过搜索", + "masa_gadget_mod.config.option.syncAllEntityData.name": "同步所有实体数据", + "masa_gadget_mod.config.option.syncAllEntityData.comment": "使用 pca 同步协议同步所有实体数据", - "masa_gadget_mod.config.litematica.betterEasyPlaceMode.name": "更好的轻松放置模式", - "masa_gadget_mod.config.litematica.betterEasyPlaceMode.comment": "轻松放置时可以打开容器(比如箱子,漏斗等等),以及可以使用信标", - "masa_gadget_mod.config.litematica.disableLitematicaEasyPlaceFailTip.name": "禁用投影轻松放置失败提示", - "masa_gadget_mod.config.litematica.disableLitematicaEasyPlaceFailTip.comment": "禁用轻松放置失败时那烦人的提示窗", - "masa_gadget_mod.config.litematica.fixAccurateProtocol.name": "修复精准放置协议", - "masa_gadget_mod.config.litematica.fixAccurateProtocol.comment": "Litematica 本身的精准放置协议实现的有问题,修复后可以在服务器中使用轻松放置来摆放中继器,\n活塞,侦测器,楼梯等方块", - "masa_gadget_mod.config.litematica.nudgeSelectionSupportFreeCamera.name": "移动投影时支持 Free Camera", - "masa_gadget_mod.config.litematica.nudgeSelectionSupportFreeCamera.comment": "在开启 Free Camera 时,移动投影的方向会取决于 Camera 的方向", - "masa_gadget_mod.config.litematica.saveInventoryToSchematicInServer.name": "服务器中保存投影保留容器数据", - "masa_gadget_mod.config.litematica.saveInventoryToSchematicInServer.comment": "保存投影时会使用 PCA 同步协议来同步容器中的数据到本地", - "masa_gadget_mod.config.litematica.useRelativePath.name": "使用相对路径", - "masa_gadget_mod.config.litematica.useRelativePath.comment": "加载和保存投影时使用相对路径", + "masa_gadget_mod.config.option.betterEasyPlaceMode.name": "更好的轻松放置模式", + "masa_gadget_mod.config.option.betterEasyPlaceMode.comment": "轻松放置时可以打开容器(比如箱子,漏斗等等),以及可以使用信标", + "masa_gadget_mod.config.option.disableLitematicaEasyPlaceFailTip.name": "禁用投影轻松放置失败提示", + "masa_gadget_mod.config.option.disableLitematicaEasyPlaceFailTip.comment": "禁用轻松放置失败时那烦人的提示窗", + "masa_gadget_mod.config.option.fixAccurateProtocol.name": "修复精准放置协议", + "masa_gadget_mod.config.option.fixAccurateProtocol.comment": "Litematica 本身的精准放置协议实现的有问题,修复后可以在服务器中使用轻松放置来摆放中继器,\n活塞,侦测器,楼梯等方块", + "masa_gadget_mod.config.option.nudgeSelectionSupportFreeCamera.name": "移动投影时支持 Free Camera", + "masa_gadget_mod.config.option.nudgeSelectionSupportFreeCamera.comment": "在开启 Free Camera 时,移动投影的方向会取决于 Camera 的方向", + "masa_gadget_mod.config.option.saveInventoryToSchematicInServer.name": "服务器中保存投影保留容器数据", + "masa_gadget_mod.config.option.saveInventoryToSchematicInServer.comment": "保存投影时会使用 PCA 同步协议来同步容器中的数据到本地", + "masa_gadget_mod.config.option.useRelativePath.name": "使用相对路径", + "masa_gadget_mod.config.option.useRelativePath.comment": "加载和保存投影时使用相对路径", - "masa_gadget_mod.config.malilib.backportI18nSupport.name": "移植 i18n 支持", - "masa_gadget_mod.config.malilib.backportI18nSupport.comment": "让 masa 系 mod 支持 malilib 的 1.18.x 的 i18n 移植", - "masa_gadget_mod.config.malilib.fastSwitchMasaConfigGui.name": "快速切换 Masa mod 配置界面", - "masa_gadget_mod.config.malilib.fastSwitchMasaConfigGui.comment": "可以通过右上角的下拉菜单快速切换到别的 masa mod 的设置界面", - "masa_gadget_mod.config.malilib.favoritesSupport.name": "收藏夹支持", - "masa_gadget_mod.config.malilib.favoritesSupport.comment": "可以收藏并过滤出自己喜欢的选项", - "masa_gadget_mod.config.malilib.fixConfigWidgetWidth.name": "修复 Masa 配置文本的宽度", - "masa_gadget_mod.config.malilib.fixConfigWidgetWidth.comment": "在使用汉化包后现在的界面会根据汉化后的文本长度自动调节", - "masa_gadget_mod.config.malilib.fixGetInventoryType.name": "修复容器类型", - "masa_gadget_mod.config.malilib.fixGetInventoryType.comment": "修复对烟熏炉之类的熔炉变种的容器类型的判断", - "masa_gadget_mod.config.malilib.fixSearchbarHotkeyInput.name": "修复搜索框按键输入", - "masa_gadget_mod.config.malilib.fixSearchbarHotkeyInput.comment": "修复用热键打开配置界面时会在搜索框产生错误输入的 bug", - "masa_gadget_mod.config.malilib.optimizeConfigWidgetSearch.name": "Masa 搜索优化", - "masa_gadget_mod.config.malilib.optimizeConfigWidgetSearch.comment": "在 Masa 家的搜索栏中可以使用中文搜索,还能使用 §6modified§r 来搜索修改过的配置项", - "masa_gadget_mod.config.malilib.showOriginalConfigName.name": "显示原始的配置选项名", - "masa_gadget_mod.config.malilib.showOriginalConfigName.comment": "如果当前显示的配置选项名和原始名字不一致时,在下方显示原始的配置名(英文)", - "masa_gadget_mod.config.malilib.showOriginalConfigNameScale.name": "显示原始的配置选项名字体大小", - "masa_gadget_mod.config.malilib.showOriginalConfigNameScale.comment": "原始的配置选项名字体大小", + "masa_gadget_mod.config.option.backportI18nSupport.name": "移植 i18n 支持", + "masa_gadget_mod.config.option.backportI18nSupport.comment": "让 masa 系 mod 支持 malilib 的 1.18.x 的 i18n 移植", + "masa_gadget_mod.config.option.fastSwitchMasaConfigGui.name": "快速切换 Masa mod 配置界面", + "masa_gadget_mod.config.option.fastSwitchMasaConfigGui.comment": "可以通过右上角的下拉菜单快速切换到别的 masa mod 的设置界面", + "masa_gadget_mod.config.option.favoritesSupport.name": "收藏夹支持", + "masa_gadget_mod.config.option.favoritesSupport.comment": "可以收藏并过滤出自己喜欢的选项", + "masa_gadget_mod.config.option.fixConfigWidgetWidth.name": "修复 Masa 配置文本的宽度", + "masa_gadget_mod.config.option.fixConfigWidgetWidth.comment": "在使用汉化包后现在的界面会根据汉化后的文本长度自动调节", + "masa_gadget_mod.config.option.fixGetInventoryType.name": "修复容器类型", + "masa_gadget_mod.config.option.fixGetInventoryType.comment": "修复对烟熏炉之类的熔炉变种的容器类型的判断", + "masa_gadget_mod.config.option.fixSearchbarHotkeyInput.name": "修复搜索框按键输入", + "masa_gadget_mod.config.option.fixSearchbarHotkeyInput.comment": "修复用热键打开配置界面时会在搜索框产生错误输入的 bug", + "masa_gadget_mod.config.option.optimizeConfigWidgetSearch.name": "Masa 搜索优化", + "masa_gadget_mod.config.option.optimizeConfigWidgetSearch.comment": "在 Masa 家的搜索栏中可以使用中文搜索,还能使用 §6modified§r 来搜索修改过的配置项", + "masa_gadget_mod.config.option.showOriginalConfigName.name": "显示原始的配置选项名", + "masa_gadget_mod.config.option.showOriginalConfigName.comment": "如果当前显示的配置选项名和原始名字不一致时,在下方显示原始的配置名(英文)", + "masa_gadget_mod.config.option.showOriginalConfigNameScale.name": "显示原始的配置选项名字体大小", + "masa_gadget_mod.config.option.showOriginalConfigNameScale.comment": "原始的配置选项名字体大小", - "masa_gadget_mod.config.minihud.minihudI18n.name": "Minihud 支持翻译", - "masa_gadget_mod.config.minihud.minihudI18n.comment": "Minihud 显示的文本可以被翻译", - "masa_gadget_mod.config.minihud.pcaSyncProtocolSyncBeehive.name": "PCA同步协议同步蜂巢数据", - "masa_gadget_mod.config.minihud.pcaSyncProtocolSyncBeehive.comment": "按下 §6容器预览§r 的快捷键将会使用 PCA 同步协议来 同步蜂巢,蜂箱数据", + "masa_gadget_mod.config.option.minihudI18n.name": "Minihud 支持翻译", + "masa_gadget_mod.config.option.minihudI18n.comment": "Minihud 显示的文本可以被翻译", + "masa_gadget_mod.config.option.pcaSyncProtocolSyncBeehive.name": "PCA同步协议同步蜂巢数据", + "masa_gadget_mod.config.option.pcaSyncProtocolSyncBeehive.comment": "按下 §6容器预览§r 的快捷键将会使用 PCA 同步协议来 同步蜂巢,蜂箱数据", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSupportComparator.name": "容器预览支持比较器", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSupportComparator.comment": "对比较器使用容器预览时将会显示比较器应该输出的信号", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSupportPlayer.name": "容器预览支持预览玩家", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSupportPlayer.comment": "对着玩家使用容器预览时,会显示出玩家背包和末影箱的内容", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSupportSelect.name": "容器预览支持选中格子", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSupportSelect.comment": "按下容器预览快捷键时可以使用鼠标滚轮来选中物品(可以查看附魔信息),\n在选中箱子中的潜影盒时可以按下鼠标中键来预览盒子内的物品", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSupportShulkerBoxItemEntity.name": "容器预览支持潜影盒实体", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSupportShulkerBoxItemEntity.comment": "容器预览支持潜影盒实体", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSupportTradeOfferList.name": "容器预览显示交易列表", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSupportTradeOfferList.comment": "容器预览村民时会显示出当前的交易列表", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSyncData.name": "容器预览时同步数据", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSyncData.comment": "容器预览时使用 PCA 同步协议来从服务器同步方块实体信息和实体信息,比如箱子内的物品,村民背包", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSyncDataClientOnly.name": "容器预览时同步数据(仅客户端)", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewSyncDataClientOnly.comment": "容器预览时模拟开启容器来同步容器的信息", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewUseCache.name": "容器预览时使用缓存", - "masa_gadget_mod.config.tweakeroo.inventoryPreviewUseCache.comment": "容器预览时从缓存中获取指向的方块和实体数据,从而减少渲染时的卡顿", - "masa_gadget_mod.config.tweakeroo.restockWithCrafting.name": "自动补货允许 2x2 合成", - "masa_gadget_mod.config.tweakeroo.restockWithCrafting.comment": "当背包内没有自动物品而 Tweakeroo 需要自动补货时,\n通过预先定义的合成表自动合成相应物品。此功能需要 ItemScroller。", - "masa_gadget_mod.config.tweakeroo.restockWithCraftingRecipes.name": "自动补货合成配方", - "masa_gadget_mod.config.tweakeroo.restockWithCraftingRecipes.comment": "ItemScroller 存储的配方编号,只支持 2x2 配方", + "masa_gadget_mod.config.option.inventoryPreviewSupportComparator.name": "容器预览支持比较器", + "masa_gadget_mod.config.option.inventoryPreviewSupportComparator.comment": "对比较器使用容器预览时将会显示比较器应该输出的信号", + "masa_gadget_mod.config.option.inventoryPreviewSupportPlayer.name": "容器预览支持预览玩家", + "masa_gadget_mod.config.option.inventoryPreviewSupportPlayer.comment": "对着玩家使用容器预览时,会显示出玩家背包和末影箱的内容", + "masa_gadget_mod.config.option.inventoryPreviewSupportSelect.name": "容器预览支持选中格子", + "masa_gadget_mod.config.option.inventoryPreviewSupportSelect.comment": "按下容器预览快捷键时可以使用鼠标滚轮来选中物品(可以查看附魔信息),\n在选中箱子中的潜影盒时可以按下鼠标中键来预览盒子内的物品", + "masa_gadget_mod.config.option.inventoryPreviewSupportShulkerBoxItemEntity.name": "容器预览支持潜影盒实体", + "masa_gadget_mod.config.option.inventoryPreviewSupportShulkerBoxItemEntity.comment": "容器预览支持潜影盒实体", + "masa_gadget_mod.config.option.inventoryPreviewSupportTradeOfferList.name": "容器预览显示交易列表", + "masa_gadget_mod.config.option.inventoryPreviewSupportTradeOfferList.comment": "容器预览村民时会显示出当前的交易列表", + "masa_gadget_mod.config.option.inventoryPreviewSyncData.name": "容器预览时同步数据", + "masa_gadget_mod.config.option.inventoryPreviewSyncData.comment": "容器预览时使用 PCA 同步协议来从服务器同步方块实体信息和实体信息,比如箱子内的物品,村民背包", + "masa_gadget_mod.config.option.inventoryPreviewSyncDataClientOnly.name": "容器预览时同步数据(仅客户端)", + "masa_gadget_mod.config.option.inventoryPreviewSyncDataClientOnly.comment": "容器预览时模拟开启容器来同步容器的信息", + "masa_gadget_mod.config.option.inventoryPreviewUseCache.name": "容器预览时使用缓存", + "masa_gadget_mod.config.option.inventoryPreviewUseCache.comment": "容器预览时从缓存中获取指向的方块和实体数据,从而减少渲染时的卡顿", + "masa_gadget_mod.config.option.restockWithCrafting.name": "自动补货允许 2x2 合成", + "masa_gadget_mod.config.option.restockWithCrafting.comment": "当背包内没有自动物品而 Tweakeroo 需要自动补货时,\n通过预先定义的合成表自动合成相应物品。此功能需要 ItemScroller。", + "masa_gadget_mod.config.option.restockWithCraftingRecipes.name": "自动补货合成配方", + "masa_gadget_mod.config.option.restockWithCraftingRecipes.comment": "ItemScroller 存储的配方编号,只支持 2x2 配方", "masa_gadget_mod.message.canNotFindDespawnShape": "找不到怪物消失图形", "masa_gadget_mod.message.cancelFavorite": "取消收藏", diff --git a/src/main/resources/assets/masa_gadget_mod/lang/zh_tw.json b/src/main/resources/assets/masa_gadget_mod/lang/zh_tw.json index 186d5314..01f3cc11 100644 --- a/src/main/resources/assets/masa_gadget_mod/lang/zh_tw.json +++ b/src/main/resources/assets/masa_gadget_mod/lang/zh_tw.json @@ -1,10 +1,12 @@ { + "masa_gadget_mod.config.category.generic.name": "Generic", + "masa_gadget_mod.config.category.all.name": "All", + "masa_gadget_mod.config.category.litematica.name": "Litematica", + "masa_gadget_mod.config.category.malilib.name": "Malilib", + "masa_gadget_mod.config.category.minihud.name": "MiniHud", + "masa_gadget_mod.config.category.tweakeroo.name": "Tweakeroo", "masa_gadget_mod.gui.title.configs": "Masa Gadget 設定介面", - "masa_gadget_mod.gui.button.tab.generic": "通用", - "masa_gadget_mod.gui.button.tab.litematica": "Litematica", - "masa_gadget_mod.gui.button.tab.malilib": "Malilib", - "masa_gadget_mod.gui.button.tab.minihud": "Minihud", - "masa_gadget_mod.gui.button.tab.tweakeroo": "Tweakeroo", + "masa_gadget_mod.message.setFavorite": "收藏", "masa_gadget_mod.message.cancelFavorite": "取消收藏", "masa_gadget_mod.message.showAllOptions": "顯示所有設定項", diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index a322aec8..fd794d8e 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -31,14 +31,14 @@ "com.plusls.MasaGadget.MasaGadgetMod" ], "modmenu": [ - "com.plusls.MasaGadget.compat.modmenu.ModMenuApiImpl" + "com.plusls.MasaGadget.impl.compat.modmenu.ModMenuApiImpl" ] }, "mixins": [ "${mod_id}.mixins.json" ], "depends": { - "magiclib-${minecraft_version_id}": ">=${magiclib_dependency}", + "magiclib": ">=${magiclib_dependency}", "malilib": "*", "minecraft": "${minecraft_dependency}" }, diff --git a/src/main/resources/masa_gadget_mod.mixins.json b/src/main/resources/masa_gadget_mod.mixins.json index d0b63f1d..1203be18 100644 --- a/src/main/resources/masa_gadget_mod.mixins.json +++ b/src/main/resources/masa_gadget_mod.mixins.json @@ -3,60 +3,60 @@ "minVersion": "0.8", "package": "com.plusls.MasaGadget.mixin", "compatibilityLevel": "JAVA_8", - "plugin": "top.hendrixshen.magiclib.dependency.impl.MagicMixinPlugin", + "plugin": "top.hendrixshen.magiclib.impl.mixin.MagicMixinPlugin", "client": [ "MixinConnection", "accessor.AccessorAbstractMinecartContainer", "accessor.AccessorAbstractVillager", + "accessor.AccessorGuiComponent", "accessor.AccessorGuiListBase", "accessor.AccessorLivingEntity", "accessor.AccessorVillager", "accessor.AccessorWidgetListConfigOptions", "accessor.AccessorZombieVillager", "event.disconnect.MixinMinecraftClient", - "generic.autoSyncEntityData.MixinClientPlayNetworkHandler", - "generic.autoSyncEntityData.MixinVillagerEntity", - "generic.autoSyncEntityData.MixinZombieVillagerEntity", - "generic.cacheContainerMenu.MixinClientPacketListener", - "generic.cacheContainerMenu.MixinLocalPlayer", - "generic.cacheContainerMenu.MixinMultiPlayerGameMode", - "litematica.betterEasyPlaceMode.MixinWorldUtils", - "litematica.disableLitematicaEasyPlaceFailTip.MixinWorldUtils", - "litematica.fixCarpetAccurateProtocol.MixinBlockItem", - "litematica.fixCarpetAccurateProtocol.MixinWorldUtils", - "litematica.nudgeSelectionSupportFreeCamera.MixinInputHandler", - "litematica.saveInventoryToSchematicInServer.MixinSchematicUtils", - "litematica.useRelativePath.MixinSchematicPlacement", - "malilib.backportI18nSupport.MixinConfigBase", - "malilib.backportI18nSupport.MixinConfigBooleanClient", - "malilib.backportI18nSupport.MixinFeatureToggle", - "malilib.backportI18nSupport.MixinInfoToggle", - "malilib.backportI18nSupport.MixinRendererToggle", - "malilib.fastSwitchMasaConfigGui.MixinGuiConfigBase", - "malilib.fastSwitchMasaConfigGui.MixinWidgetDropDownList", - "malilib.fastSwitchMasaConfigGui.MixinWidgetListBase", - "malilib.favorites.MixinGuiConfigBase", - "malilib.favorites.MixinWidgetConfigOption", - "malilib.favorites.MixinWidgetListConfigOptions", - "malilib.fixConfigWidgetWidth.MixinWidgetListConfigOptions", - "malilib.fixGetInventoryType.MixinInventoryOverlay", - "malilib.fixSearchbarHotkeyInput.MixinGuiBase", - "malilib.optimizeConfigWidgetSearch.MixinWidgetListConfigOptions", - "malilib.showOriginalConfigName.MixinWidgetConfigOption", - "malilib.showOriginalConfigName.MixinWidgetListConfigOptions", - "minihud.minihudI18n.MixinRenderHandler", - "tweakeroo.handRestockCrafting.MixinInventoryUtils", - "tweakeroo.inventoryPreviewSupportComparator.MixinGameRenderer", - "tweakeroo.inventoryPreviewSupportComparator.MixinWorldRenderer", - "tweakeroo.inventoryPreviewSupportPlayer.MixinRenderUtils", - "tweakeroo.inventoryPreviewSupportSelect.MixinInGameHud", - "tweakeroo.inventoryPreviewSupportSelect.MixinInventoryOverlay", - "tweakeroo.inventoryPreviewSupportShulkerBoxItemEntity.MixinRenderUtils", - "tweakeroo.inventoryPreviewSupportTradeOfferList.MixinRenderUtils", - "tweakeroo.inventoryPreviewSyncDataClientOnly.MixinClientPacketListener", - "tweakeroo.inventoryPreviewUseCache.MixinMixinRenderUtils" + "feature.autoSyncEntityData.MixinClientPlayNetworkHandler", + "feature.autoSyncEntityData.MixinVillagerEntity", + "feature.autoSyncEntityData.MixinZombieVillagerEntity", + "feature.cacheContainerMenu.MixinClientPacketListener", + "feature.cacheContainerMenu.MixinLocalPlayer", + "feature.cacheContainerMenu.MixinMultiPlayerGameMode", + "mod_tweak.litematica.betterEasyPlaceMode.MixinWorldUtils", + "mod_tweak.litematica.disableLitematicaEasyPlaceFailTip.MixinWorldUtils", + "mod_tweak.litematica.fixCarpetAccurateProtocol.MixinBlockItem", + "mod_tweak.litematica.fixCarpetAccurateProtocol.MixinWorldUtils", + "mod_tweak.litematica.nudgeSelectionSupportFreeCamera.MixinInputHandler", + "mod_tweak.litematica.saveInventoryToSchematicInServer.MixinSchematicUtils", + "mod_tweak.litematica.useRelativePath.MixinSchematicPlacement", + "mod_tweak.malilib.backportI18nSupport.MixinConfigBase", + "mod_tweak.malilib.fastSwitchMasaConfigGui.MixinGuiConfigBase", + "mod_tweak.malilib.fastSwitchMasaConfigGui.MixinWidgetListBase", + "mod_tweak.malilib.favoritesSupport.MixinGuiConfigBase", + "mod_tweak.malilib.favoritesSupport.MixinWidgetConfigOption", + "mod_tweak.malilib.favoritesSupport.MixinWidgetListConfigOptions", + "mod_tweak.malilib.fixConfigWidgetWidth.MixinWidgetListConfigOptions", + "mod_tweak.malilib.fixGetInventoryType.MixinInventoryOverlay", + "mod_tweak.malilib.fixSearchbarHotkeyInput.MixinGuiBase", + "mod_tweak.malilib.optimizeConfigWidgetSearch.MixinWidgetListConfigOptions", + "mod_tweak.malilib.showOriginalConfigName.MixinWidgetConfigOption", + "mod_tweak.malilib.showOriginalConfigName.MixinWidgetListConfigOptions", + "mod_tweak.minihud.backportI18nSupport.MixinInfoToggle", + "mod_tweak.minihud.backportI18nSupport.MixinRendererToggle", + "mod_tweak.minihud.minihudI18n.MixinRenderHandler", + "mod_tweak.tweakeroo.backportI18nSupport.MixinConfigBooleanClient", + "mod_tweak.tweakeroo.backportI18nSupport.MixinFeatureToggle", + "mod_tweak.tweakeroo.handRestockCrafting.MixinInventoryUtils", + "mod_tweak.tweakeroo.inventoryPreviewSupportPlayer.MixinRenderUtils", + "mod_tweak.tweakeroo.inventoryPreviewSupportSelect.MixinInGameHud", + "mod_tweak.tweakeroo.inventoryPreviewSupportSelect.MixinInventoryOverlay", + "mod_tweak.tweakeroo.inventoryPreviewSupportShulkerBoxItemEntity.MixinRenderUtils", + "mod_tweak.tweakeroo.inventoryPreviewSupportTradeOfferList.MixinRenderUtils", + "mod_tweak.tweakeroo.inventoryPreviewSyncDataClientOnly.MixinClientPacketListener", + "mod_tweak.tweakeroo.inventoryPreviewUseCache.MixinMixinRenderUtils" ], "injectors": { "defaultRequire": 1 - } + }, + "mixins": [ + ] } diff --git a/common.gradle b/versions/1.14.4/build.gradle similarity index 70% rename from common.gradle rename to versions/1.14.4/build.gradle index 27c5e553..2c311a49 100644 --- a/common.gradle +++ b/versions/1.14.4/build.gradle @@ -1,9 +1,6 @@ -import com.google.common.collect.ImmutableList -import com.google.common.collect.ImmutableMap -import org.objectweb.asm.ClassReader -import org.objectweb.asm.ClassWriter -import org.objectweb.asm.tree.ClassNode -import org.objectweb.asm.tree.LdcInsnNode +plugins { + id("top.hendrixshen.replace-token").version("${replace_token_version}") +} apply(plugin: "fabric-loom") apply(plugin: "maven-publish") @@ -72,12 +69,10 @@ dependencies { annotationProcessor("org.projectlombok:lombok:${project.lombok_version}") // Dependency - modImplementation("top.hendrixshen.magiclib:magiclib-${project.minecraft_version.replace(".", "_")}:${project.magiclib_version}") { - exclude(group: "carpet", module: "fabric-carpet") - } + modImplementation("top.hendrixshen.magiclib:magiclib-all-${project.minecraft_version}-fabric:${project.magiclib_version}") // API - apiDependencies.forEach {item -> + apiDependencies.forEach { item -> String dependencyNotation = item[0] String propertyPrefix = item[1] boolean shouldResolve = item[2] @@ -91,7 +86,7 @@ dependencies { } // Compile only library. - compileOnlyDependencies.forEach {item -> + compileOnlyDependencies.forEach { item -> String dependencyNotation = item[0] String propertyPrefix = item[1] boolean shouldResolve = item[2] @@ -206,6 +201,14 @@ remapJar { remapperIsolation.set(false) } +replaceToken { + targetSourceSets.set([sourceSets.main]) + replace("@MOD_IDENTIFIER@", project.parent.property("mod_id")) + replace("@MOD_NAME@" , project.parent.property("mod_name")) + replace("@MOD_VERSION@" , project.version) + replaceIn("com/plusls/MasaGadget/SharedConstants") +} + processResources { outputs.upToDateWhen { false } @@ -235,8 +238,20 @@ processResources { } java { - sourceCompatibility(JavaVersion.VERSION_1_8) - targetCompatibility(JavaVersion.VERSION_1_8) + if (mcVersion > 12004) { + sourceCompatibility(JavaVersion.VERSION_21) + targetCompatibility(JavaVersion.VERSION_21) + } else if (mcVersion > 11701) { + sourceCompatibility(JavaVersion.VERSION_17) + targetCompatibility(JavaVersion.VERSION_17) + } else if (mcVersion > 11605) { + sourceCompatibility(JavaVersion.VERSION_16) + targetCompatibility(JavaVersion.VERSION_16) + } else { + sourceCompatibility(JavaVersion.VERSION_1_8) + targetCompatibility(JavaVersion.VERSION_1_8) + } + withSourcesJar() } @@ -261,64 +276,3 @@ publishing { } } } - -ImmutableMap replaceTokenMap = ImmutableMap.builder() - .put("@MOD_IDENTIFIER@" , project.mod_id) - .put("@MOD_NAME@" , project.mod_name) - .put("@MINECRAFT_VERSION_IDENTIFY@", project.minecraft_version.replace(".", "_")) - .build() -ImmutableList replaceTokenFile = ImmutableList.builder() - .add("ModInfo") - .build() - -tasks.classes { - doLast { - File dir = file("build/classes/java") - - dir.eachFileRecurse { - String path = it.path.replace(dir.path, "") - - if (path.endsWith(".class") && replaceTokenFile.stream().anyMatch { path.contains(it as String) }) { - ClassReader cr = new ClassReader(it.newInputStream().bytes) - ClassNode cn = new ClassNode() - cr.accept(cn, ClassReader.SKIP_FRAMES | ClassReader.SKIP_DEBUG) - - // ReplaceToken in fields - cn.fields.each { - if (it.desc == "Ljava/lang/String;" && it.value instanceof String) { - String value = it.value as String - - replaceTokenMap.each { - value = value.replace(it.key as String, it.value as String) - } - - it.value = value - } - } - - // ReplaceToken in methods - cn.methods.each { - it.instructions.each { - if (it instanceof LdcInsnNode) { - LdcInsnNode ldc = it as LdcInsnNode - - if (ldc.cst instanceof String) { - String value = ldc.cst as String - - replaceTokenMap.each { - value = value.replace(it.key as String, it.value as String) - } - - ldc.cst = value - } - } - } - } - - ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES) - cn.accept(cw) - new FileOutputStream(it).write(cw.toByteArray()) - } - } - } -} diff --git a/versions/1.14.4/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportComparator/MixinGameRenderer.java b/versions/1.14.4/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportComparator/MixinGameRenderer.java deleted file mode 100644 index 3a321c22..00000000 --- a/versions/1.14.4/src/main/java/com/plusls/MasaGadget/mixin/tweakeroo/inventoryPreviewSupportComparator/MixinGameRenderer.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.plusls.MasaGadget.mixin.tweakeroo.inventoryPreviewSupportComparator; - -import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.vertex.PoseStack; -import com.plusls.MasaGadget.ModInfo; -import com.plusls.MasaGadget.config.Configs; -import com.plusls.MasaGadget.util.HitResultUtil; -import com.plusls.MasaGadget.util.RenderUtil; -import fi.dy.masa.malilib.util.WorldUtils; -import fi.dy.masa.tweakeroo.config.FeatureToggle; -import fi.dy.masa.tweakeroo.config.Hotkeys; -import net.minecraft.ChatFormatting; -import net.minecraft.client.Camera; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.core.BlockPos; -import net.minecraft.network.chat.TextComponent; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.ComparatorBlockEntity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; -import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; - -@Dependencies(and = @Dependency(ModInfo.TWEAKEROO_MOD_ID)) -@Mixin(GameRenderer.class) -public class MixinGameRenderer { - @Inject(method = "render(FJ)V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/GameRenderer;renderHand:Z")) - private void postRender(float partialTicks, long finishTimeNano, CallbackInfo ci) { - Minecraft mc = Minecraft.getInstance(); - Level world = WorldUtils.getBestWorld(mc); - Camera camera = Minecraft.getInstance().gameRenderer.getMainCamera(); - if (world == null) { - return; - } - - if (!FeatureToggle.TWEAK_INVENTORY_PREVIEW.getBooleanValue() || !Hotkeys.INVENTORY_PREVIEW.getKeybind().isKeybindHeld() || - !Configs.inventoryPreviewSupportComparator) { - return; - } - - // 开始渲染 - BlockPos pos = HitResultUtil.getHitBlockPos(); - Object blockEntity = HitResultUtil.getLastHitBlockEntity(); - - if (pos != null && blockEntity instanceof ComparatorBlockEntity) { - TextComponent literalText = new TextComponent(((ComparatorBlockEntity) blockEntity).getOutputSignal() + ""); - literalText.withStyle(ChatFormatting.GREEN); - GlStateManager.disableDepthTest(); - PoseStack poseStackCompat = new PoseStack(); - RenderUtil.renderTextOnWorld(poseStackCompat, camera, pos, literalText, true); - GlStateManager.enableDepthTest(); - } - } -} diff --git a/versions/1.19.4/src/main/java/com/plusls/MasaGadget/mixin/accessor/AccessorGuiComponent.java b/versions/1.19.4/src/main/java/com/plusls/MasaGadget/mixin/accessor/AccessorGuiComponent.java new file mode 100644 index 00000000..31516fd0 --- /dev/null +++ b/versions/1.19.4/src/main/java/com/plusls/MasaGadget/mixin/accessor/AccessorGuiComponent.java @@ -0,0 +1,25 @@ +package com.plusls.MasaGadget.mixin.accessor; + +import net.minecraft.client.gui.GuiComponent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +//#if MC > 11502 +import com.mojang.blaze3d.vertex.PoseStack; +//#endif + +@Mixin(GuiComponent.class) +public interface AccessorGuiComponent { + @Invoker("fillGradient") + void masa_gadget_mod$fillGradient( + //#if MC > 11502 + PoseStack poseStack, + //#endif + int startX, + int startY, + int endX, + int endY, + int colorStart, + int colorEnd + ); +} diff --git a/versions/1.20.6/gradle.properties b/versions/1.20.6/gradle.properties new file mode 100644 index 00000000..8ec0f268 --- /dev/null +++ b/versions/1.20.6/gradle.properties @@ -0,0 +1,9 @@ +# Development Environment +minecraft_version=1.20.6 +minecraft_dependency=1.20.6 + +# Compatible Libraries +itemscroller_version=5450180 +litematica_version=5450189 +minihud_version=5450183 +tweakeroo_version=5450185 diff --git a/versions/1.20.6/src/main/java/com/plusls/MasaGadget/api/network/packet/PCAPacket.java b/versions/1.20.6/src/main/java/com/plusls/MasaGadget/api/network/packet/PCAPacket.java new file mode 100644 index 00000000..8a82dbf1 --- /dev/null +++ b/versions/1.20.6/src/main/java/com/plusls/MasaGadget/api/network/packet/PCAPacket.java @@ -0,0 +1,12 @@ +package com.plusls.MasaGadget.api.network.packet; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; + +@Getter +@AllArgsConstructor +public abstract class PCAPacket implements CustomPacketPayload { + private final FriendlyByteBuf byteBuf; +} diff --git a/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/NoopCodec.java b/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/NoopCodec.java new file mode 100644 index 00000000..0f2a0d70 --- /dev/null +++ b/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/NoopCodec.java @@ -0,0 +1,24 @@ +package com.plusls.MasaGadget.impl.network; + +import com.plusls.MasaGadget.api.network.packet.PCAPacket; +import lombok.AllArgsConstructor; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Function; + +@AllArgsConstructor(staticName = "create") +public class NoopCodec implements StreamCodec { + private final Function transformer; + + @Override + public @NotNull P decode(B byteBuf) { + return this.transformer.apply(byteBuf); + } + + @Override + public void encode(B byteBuf, P packet) { + byteBuf.writeBytes(packet.getByteBuf().readByteArray()); + } +} diff --git a/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundDisablePcaSyncProtocolPacket.java b/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundDisablePcaSyncProtocolPacket.java new file mode 100644 index 00000000..ae958fdf --- /dev/null +++ b/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundDisablePcaSyncProtocolPacket.java @@ -0,0 +1,34 @@ +package com.plusls.MasaGadget.impl.network.packet; + +import com.plusls.MasaGadget.api.network.packet.PCAPacket; +import com.plusls.MasaGadget.impl.network.NoopCodec; +import com.plusls.MasaGadget.util.PcaSyncProtocol; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Function; + +public class ClientboundDisablePcaSyncProtocolPacket extends PCAPacket { + public static final Type TYPE = new Type<>(PcaSyncProtocol.DISABLE_PCA_SYNC_PROTOCOL); + public static final StreamCodec CODEC = NoopCodec.create(ClientboundDisablePcaSyncProtocolPacket.transform()); + + public ClientboundDisablePcaSyncProtocolPacket(FriendlyByteBuf byteBuf) { + super(byteBuf); + } + + public static void handle(PCAPacket packet, ClientPlayNetworking.Context context) { + PcaSyncProtocol.disablePcaSyncProtocolHandler(context.client(), context.client().getConnection(), packet.getByteBuf(), context.responseSender()); + } + + private static Function transform() { + return ClientboundDisablePcaSyncProtocolPacket::new; + } + + @Override + public @NotNull Type type() { + return ClientboundDisablePcaSyncProtocolPacket.TYPE; + } +} diff --git a/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundEnablePcaSyncProtocolPacket.java b/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundEnablePcaSyncProtocolPacket.java new file mode 100644 index 00000000..5281b54d --- /dev/null +++ b/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundEnablePcaSyncProtocolPacket.java @@ -0,0 +1,34 @@ +package com.plusls.MasaGadget.impl.network.packet; + +import com.plusls.MasaGadget.api.network.packet.PCAPacket; +import com.plusls.MasaGadget.impl.network.NoopCodec; +import com.plusls.MasaGadget.util.PcaSyncProtocol; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Function; + +public class ClientboundEnablePcaSyncProtocolPacket extends PCAPacket { + public static final Type TYPE = new Type<>(PcaSyncProtocol.ENABLE_PCA_SYNC_PROTOCOL); + public static final StreamCodec CODEC = NoopCodec.create(ClientboundEnablePcaSyncProtocolPacket.transform()); + + public ClientboundEnablePcaSyncProtocolPacket(FriendlyByteBuf byteBuf) { + super(byteBuf); + } + + public static void handle(PCAPacket packet, ClientPlayNetworking.Context context) { + PcaSyncProtocol.enablePcaSyncProtocolHandler(context.client(), context.client().getConnection(), packet.getByteBuf(), context.responseSender()); + } + + private static Function transform() { + return ClientboundEnablePcaSyncProtocolPacket::new; + } + + @Override + public @NotNull Type type() { + return ClientboundEnablePcaSyncProtocolPacket.TYPE; + } +} diff --git a/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundUpdateBlockEntityPacket.java b/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundUpdateBlockEntityPacket.java new file mode 100644 index 00000000..9a08ea4e --- /dev/null +++ b/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundUpdateBlockEntityPacket.java @@ -0,0 +1,34 @@ +package com.plusls.MasaGadget.impl.network.packet; + +import com.plusls.MasaGadget.api.network.packet.PCAPacket; +import com.plusls.MasaGadget.impl.network.NoopCodec; +import com.plusls.MasaGadget.util.PcaSyncProtocol; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Function; + +public class ClientboundUpdateBlockEntityPacket extends PCAPacket { + public static final Type TYPE = new Type<>(PcaSyncProtocol.UPDATE_BLOCK_ENTITY); + public static final StreamCodec CODEC = NoopCodec.create(ClientboundUpdateBlockEntityPacket.transform()); + + public ClientboundUpdateBlockEntityPacket(FriendlyByteBuf byteBuf) { + super(byteBuf); + } + + public static void handle(PCAPacket packet, ClientPlayNetworking.Context context) { + PcaSyncProtocol.updateBlockEntityHandler(context.client(), context.client().getConnection(), packet.getByteBuf(), context.responseSender()); + } + + private static Function transform() { + return ClientboundUpdateBlockEntityPacket::new; + } + + @Override + public @NotNull Type type() { + return ClientboundUpdateBlockEntityPacket.TYPE; + } +} diff --git a/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundUpdateEntityPacket.java b/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundUpdateEntityPacket.java new file mode 100644 index 00000000..b6a2e8de --- /dev/null +++ b/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ClientboundUpdateEntityPacket.java @@ -0,0 +1,34 @@ +package com.plusls.MasaGadget.impl.network.packet; + +import com.plusls.MasaGadget.api.network.packet.PCAPacket; +import com.plusls.MasaGadget.impl.network.NoopCodec; +import com.plusls.MasaGadget.util.PcaSyncProtocol; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Function; + +public class ClientboundUpdateEntityPacket extends PCAPacket { + public static final Type TYPE = new Type<>(PcaSyncProtocol.UPDATE_ENTITY); + public static final StreamCodec CODEC = NoopCodec.create(ClientboundUpdateEntityPacket.transform()); + + public ClientboundUpdateEntityPacket(FriendlyByteBuf byteBuf) { + super(byteBuf); + } + + public static void handle(PCAPacket packet, ClientPlayNetworking.Context context) { + PcaSyncProtocol.updateEntityHandler(context.client(), context.client().getConnection(), packet.getByteBuf(), context.responseSender()); + } + + private static Function transform() { + return ClientboundUpdateEntityPacket::new; + } + + @Override + public @NotNull Type type() { + return ClientboundUpdateEntityPacket.TYPE; + } +} diff --git a/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundCancelSyncBlockEntityPacket.java b/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundCancelSyncBlockEntityPacket.java new file mode 100644 index 00000000..fa0e8586 --- /dev/null +++ b/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundCancelSyncBlockEntityPacket.java @@ -0,0 +1,15 @@ +package com.plusls.MasaGadget.impl.network.packet; + +import com.plusls.MasaGadget.util.PcaSyncProtocol; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import org.jetbrains.annotations.NotNull; + +public record ServerboundCancelSyncBlockEntityPacket(FriendlyByteBuf buf) implements CustomPacketPayload { + public static final Type TYPE = new Type<>(PcaSyncProtocol.CANCEL_SYNC_REQUEST_BLOCK_ENTITY); + + @Override + public @NotNull Type type() { + return ServerboundCancelSyncBlockEntityPacket.TYPE; + } +} diff --git a/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundCancelSyncEntityPacket.java b/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundCancelSyncEntityPacket.java new file mode 100644 index 00000000..2c9097c8 --- /dev/null +++ b/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundCancelSyncEntityPacket.java @@ -0,0 +1,15 @@ +package com.plusls.MasaGadget.impl.network.packet; + +import com.plusls.MasaGadget.util.PcaSyncProtocol; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import org.jetbrains.annotations.NotNull; + +public record ServerboundCancelSyncEntityPacket(FriendlyByteBuf buf) implements CustomPacketPayload { + public static final Type TYPE = new Type<>(PcaSyncProtocol.CANCEL_SYNC_ENTITY); + + @Override + public @NotNull Type type() { + return ServerboundCancelSyncEntityPacket.TYPE; + } +} diff --git a/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundSyncBlockEntityPacket.java b/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundSyncBlockEntityPacket.java new file mode 100644 index 00000000..264c7582 --- /dev/null +++ b/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundSyncBlockEntityPacket.java @@ -0,0 +1,15 @@ +package com.plusls.MasaGadget.impl.network.packet; + +import com.plusls.MasaGadget.util.PcaSyncProtocol; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import org.jetbrains.annotations.NotNull; + +public record ServerboundSyncBlockEntityPacket(FriendlyByteBuf buf) implements CustomPacketPayload { + public static final Type TYPE = new Type<>(PcaSyncProtocol.SYNC_ENTITY); + + @Override + public @NotNull Type type() { + return ServerboundSyncBlockEntityPacket.TYPE; + } +} diff --git a/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundSyncEntityPacket.java b/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundSyncEntityPacket.java new file mode 100644 index 00000000..17d1e636 --- /dev/null +++ b/versions/1.20.6/src/main/java/com/plusls/MasaGadget/impl/network/packet/ServerboundSyncEntityPacket.java @@ -0,0 +1,15 @@ +package com.plusls.MasaGadget.impl.network.packet; + +import com.plusls.MasaGadget.util.PcaSyncProtocol; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import org.jetbrains.annotations.NotNull; + +public record ServerboundSyncEntityPacket(FriendlyByteBuf buf) implements CustomPacketPayload { + public static final Type TYPE = new Type<>(PcaSyncProtocol.SYNC_BLOCK_ENTITY); + + @Override + public @NotNull Type type() { + return ServerboundSyncEntityPacket.TYPE; + } +}