diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1b3de16..100cdb3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,11 +8,11 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v4 with: - distribution: 'adopt' - java-version: 17 + distribution: 'zulu' + java-version: 21 - name: Cache uses: actions/cache@v4 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 052b424..d722ee9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,11 +15,11 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up JDK 20 + - name: Set up JDK 21 uses: actions/setup-java@v4 with: - distribution: 'adopt' - java-version: 20 + distribution: 'zulu' + java-version: 21 - name: Cache uses: actions/cache@v4 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index ba0c57e..44117fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,2 @@ ## Change -- update NeoForge & MaFgLib version \ No newline at end of file +- port to 1.20.6 \ No newline at end of file diff --git a/build.gradle b/build.gradle index 6015665..23921dc 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id "dev.architectury.loom" version "1.5-SNAPSHOT" + id "dev.architectury.loom" version "1.6-SNAPSHOT" id "maven-publish" id "com.hypherionmc.modutils.modpublisher" version "2.+" } @@ -16,11 +16,13 @@ repositories { dependencies { minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" + mappings loom.layered { + mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" + mappings "dev.architectury:yarn-mappings-patch-${loom.platform.get().id()}:${project.yarn_patch}" + } neoForge "net.neoforged:neoforge:${project.neoforge_version}" modImplementation "maven.modrinth:mafglib:${project.malilib_version}" - modLocalRuntime("com.github.ThinkingStudios:ForgedNetworkingAPI:0.1.0-mc1.20.4") implementation "com.google.code.findbugs:jsr305:3.0.2" } @@ -28,19 +30,19 @@ dependencies { processResources { inputs.property "version", project.version - filesMatching("META-INF/mods.toml") { + filesMatching("META-INF/neoforge.mods.toml") { expand "version": project.version } } tasks.withType(JavaCompile) { options.encoding = "UTF-8" - options.release = 17 + options.release = 21 } java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 withSourcesJar() } @@ -85,11 +87,11 @@ publisher { setCurseID("${project.curseforge_id}") setModrinthID("${project.modrinth_id}") - setVersionType("release") + setVersionType("alpha") setChangelog(file("CHANGELOG.md").getText("UTF-8")) setVersion("${project.version}") setDisplayName("${project.version}") - setGameVersions("1.20.3", "1.20.4") + setGameVersions("1.20.5", "1.20.6") setLoaders("neoforge") setCurseEnvironment("client") setArtifact(remapJar) diff --git a/gradle.properties b/gradle.properties index 17048bc..785f6f8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,9 +4,10 @@ org.gradle.jvmargs=-Xmx1G loom.platform=neoforge # Base properties - minecraft_version=1.20.4 - neoforge_version=20.4.235 - yarn_mappings=1.20.4+build.3 + minecraft_version=1.20.6 + neoforge_version=20.6.113-beta + yarn_mappings=1.20.6+build.3 + yarn_patch=1.20.5+build.3 # Mod Properties mod_version=0.1.2 @@ -18,4 +19,4 @@ loom.platform=neoforge curseforge_id=915857 # Dependencies - malilib_version=0.1.7-mc1.20.4 + malilib_version=0.1.8-mc1.20.6 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e411586..48c0a02 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.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/fi/dy/masa/tweakeroo/InitHandler.java b/src/main/java/fi/dy/masa/tweakeroo/InitHandler.java index 4be5348..0d902bf 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/InitHandler.java +++ b/src/main/java/fi/dy/masa/tweakeroo/InitHandler.java @@ -8,6 +8,7 @@ import fi.dy.masa.malilib.event.WorldLoadHandler; import fi.dy.masa.malilib.interfaces.IInitializationHandler; import fi.dy.masa.malilib.interfaces.IRenderer; +import fi.dy.masa.malilib.interfaces.IWorldLoadListener; import fi.dy.masa.tweakeroo.config.Callbacks; import fi.dy.masa.tweakeroo.config.Configs; import fi.dy.masa.tweakeroo.event.ClientTickHandler; @@ -32,7 +33,10 @@ public void registerModHandlers() RenderEventHandler.getInstance().registerWorldLastRenderer(renderer); TickHandler.getInstance().registerClientTickHandler(new ClientTickHandler()); - WorldLoadHandler.getInstance().registerWorldLoadPreHandler(new WorldLoadListener()); + + IWorldLoadListener worldListener = new WorldLoadListener(); + WorldLoadHandler.getInstance().registerWorldLoadPreHandler(worldListener); + WorldLoadHandler.getInstance().registerWorldLoadPostHandler(worldListener); Callbacks.init(MinecraftClient.getInstance()); } diff --git a/src/main/java/fi/dy/masa/tweakeroo/Tweakeroo.java b/src/main/java/fi/dy/masa/tweakeroo/Tweakeroo.java index 8cb3faf..8228e47 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/Tweakeroo.java +++ b/src/main/java/fi/dy/masa/tweakeroo/Tweakeroo.java @@ -2,10 +2,17 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import fi.dy.masa.malilib.event.InitializationHandler; -public class Tweakeroo { +public class Tweakeroo +{ public static final Logger logger = LogManager.getLogger(Reference.MOD_ID); public static int renderCountItems; public static int renderCountXPOrbs; + + public static void onInitialize() + { + InitializationHandler.getInstance().registerInitializationHandler(new InitHandler()); + } } diff --git a/src/main/java/fi/dy/masa/tweakeroo/config/Configs.java b/src/main/java/fi/dy/masa/tweakeroo/config/Configs.java index 3db9874..afeed36 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/config/Configs.java +++ b/src/main/java/fi/dy/masa/tweakeroo/config/Configs.java @@ -38,7 +38,7 @@ public static class Generic { public static final ConfigInteger AFTER_CLICKER_CLICK_COUNT = new ConfigInteger ("afterClickerClickCount", 1, 1, 32, "The number of right clicks to do per placed block when\ntweakAfterClicker is enabled"); public static final ConfigDouble ANGEL_BLOCK_PLACEMENT_DISTANCE = new ConfigDouble ("angelBlockPlacementDistance", 3, 1, 5, "The distance from the player blocks can be placed in\nthe air when tweakAngelBlock is enabled.\n5 is the maximum the server allows."); - public static final ConfigDouble BLOCK_REACH_DISTANCE = new ConfigDouble ("blockReachDistance", 4.5, 0, 8, "The block reach distance to use if the\noverride tweak is enabled.\nThe maximum the server allows is 8 for placing, 6 for breaking."); + public static final ConfigDouble BLOCK_REACH_DISTANCE = new ConfigDouble ("blockReachDistance", 4.5, 1, 64, "The block reach distance to use if the override tweak is enabled.\nThe maximum the game allows is 64.\n§6Do not attempt to use this at a value beyond\n[0.5 - 1.0] higher than the Game Rules defined on a server."); public static final ConfigOptionList BLOCK_TYPE_BREAK_RESTRICTION_WARN = new ConfigOptionList ("blockTypeBreakRestrictionWarn", MessageOutputType.MESSAGE, "Selects which type of warning message to show (if any)\nwhen the Block Type Break Restriction feature prevents breaking a block"); public static final ConfigInteger BREAKING_GRID_SIZE = new ConfigInteger ("breakingGridSize", 3, 1, 1000, "The grid interval size for the grid breaking mode.\nTo quickly adjust the value, scroll while\nholding down the tweak toggle keybind."); public static final ConfigOptionList BREAKING_RESTRICTION_MODE = new ConfigOptionList ("breakingRestrictionMode", PlacementRestrictionMode.LINE, "The Breaking Restriction mode to use (hotkey-selectable)"); @@ -47,7 +47,9 @@ public static class Generic public static final ConfigBoolean CARPET_ACCURATE_PLACEMENT_PROTOCOL = new ConfigBoolean ("carpetAccuratePlacementProtocol", true, "If enabled, then the Flexible Block Placement and the\nAccurate Block Placement use the protocol implemented in Carpet mod.\n§6Note: This is required for any block rotations to work, other than\n§6blocks that only care about the block side you click on (Hoppers, Logs etc.)"); public static final ConfigBoolean CLIENT_PLACEMENT_ROTATION = new ConfigBoolean ("clientPlacementRotation", true, "Enable single player and client side placement rotations,\nsuch as Accurate Placement working in single player without Carpet mod"); public static final ConfigInteger CUSTOM_INVENTORY_GUI_SCALE = new ConfigInteger ("customInventoryGuiScale", 2, 1, 10, "The GUI scale value to use for inventory screens, if\n§etweakCustomInventoryScreenScale§r is enabled."); + //public static final ConfigBoolean DEBUG_LOGGING = new ConfigBoolean ("debugLogging", false, "Enables some debug log messages in the game console,\nfor debugging certain issues or crashes."); public static final ConfigOptionList ELYTRA_CAMERA_INDICATOR = new ConfigOptionList ("elytraCameraIndicator", ActiveMode.WITH_KEY, "Whether or not to render the real pitch angle\nindicator when the elytra camera mode is active"); + public static final ConfigDouble ENTITY_REACH_DISTANCE = new ConfigDouble ("entityReachDistance", 3.0, 1, 64, "The entity reach distance to use if the override tweak is enabled.\nThe maximum the game allows is 64.\n§6Do not attempt to use this at a value beyond\n[0.5 - 1.0] higher than the Game Rules defined on a server."); public static final ConfigOptionList ENTITY_TYPE_ATTACK_RESTRICTION_WARN = new ConfigOptionList ("entityTypeAttackRestrictionWarn", MessageOutputType.MESSAGE, "Selects which type of warning message to show (if any)\nwhen the Entity Type Attack Restriction feature prevents attacking an entity"); public static final ConfigInteger FAST_BLOCK_PLACEMENT_COUNT = new ConfigInteger ("fastBlockPlacementCount", 2, 1, 16, "The maximum number of blocks to place per game tick\nwith the Fast Block Placement tweak"); public static final ConfigBoolean FAST_LEFT_CLICK_ALLOW_TOOLS = new ConfigBoolean ("fastLeftClickAllowTools", false, "Allow the Fast Left Click to work in survival\nalso while holding tool items"); @@ -115,6 +117,7 @@ public static class Generic public static final ImmutableList OPTIONS = ImmutableList.of( CARPET_ACCURATE_PLACEMENT_PROTOCOL, CLIENT_PLACEMENT_ROTATION, + //DEBUG_LOGGING, FAST_LEFT_CLICK_ALLOW_TOOLS, FAST_PLACEMENT_REMEMBER_ALWAYS, FREE_CAMERA_PLAYER_INPUTS, @@ -154,6 +157,7 @@ public static class Generic ANGEL_BLOCK_PLACEMENT_DISTANCE, BREAKING_GRID_SIZE, CUSTOM_INVENTORY_GUI_SCALE, + ENTITY_REACH_DISTANCE, FAST_BLOCK_PLACEMENT_COUNT, FAST_LEFT_CLICK_COUNT, FAST_RIGHT_CLICK_COUNT, @@ -212,7 +216,7 @@ public static class Lists public static final ConfigOptionList BLOCK_TYPE_BREAK_RESTRICTION_LIST_TYPE = new ConfigOptionList("blockTypeBreakRestrictionListType", ListType.BLACKLIST, "The restriction list type for the Block Type Break Restriction tweak"); public static final ConfigStringList BLOCK_TYPE_BREAK_RESTRICTION_BLACKLIST = new ConfigStringList("blockTypeBreakRestrictionBlackList", ImmutableList.of("minecraft:budding_amethyst"), "The blocks that are NOT allowed to be broken while the Block Break Restriction tweak is enabled,\nif the blockBreakRestrictionListType is set to Black List"); public static final ConfigStringList BLOCK_TYPE_BREAK_RESTRICTION_WHITELIST = new ConfigStringList("blockTypeBreakRestrictionWhiteList", ImmutableList.of(), "The only blocks that can be broken while the Block Break Restriction tweak is enabled,\nif the blockBreakRestrictionListType is set to White List"); - public static final ConfigStringList CREATIVE_EXTRA_ITEMS = new ConfigStringList("creativeExtraItems", ImmutableList.of("minecraft:command_block", "minecraft:chain_command_block", "minecraft:repeating_command_block", "minecraft:dragon_egg", "minecraft:structure_void", "minecraft:structure_block", "minecraft:structure_block{BlockEntityTag:{mode:\"SAVE\"}}", "minecraft:structure_block{BlockEntityTag:{mode:\"LOAD\"}}", "minecraft:structure_block{BlockEntityTag:{mode:\"CORNER\"}}"), "Extra items that should be appended to the creative inventory.\nCurrently these will appear in the Transportation category.\nIn the future the group per added item will be customizable."); + //public static final ConfigStringList CREATIVE_EXTRA_ITEMS = new ConfigStringList("creativeExtraItems", ImmutableList.of("minecraft:command_block", "minecraft:chain_command_block", "minecraft:repeating_command_block", "minecraft:dragon_egg", "minecraft:structure_void", "minecraft:structure_block", "minecraft:structure_block{BlockEntityTag:{mode:\"SAVE\"}}", "minecraft:structure_block{BlockEntityTag:{mode:\"LOAD\"}}", "minecraft:structure_block{BlockEntityTag:{mode:\"CORNER\"}}"), "Extra items that should be appended to the creative inventory.\nCurrently these will appear in the Transportation category.\nIn the future the group per added item will be customizable."); public static final ConfigOptionList ENTITY_TYPE_ATTACK_RESTRICTION_LIST_TYPE = new ConfigOptionList("entityTypeAttackRestrictionListType", ListType.BLACKLIST, "The restriction list type for the Entity Type Attack Restriction tweak"); public static final ConfigStringList ENTITY_TYPE_ATTACK_RESTRICTION_BLACKLIST = new ConfigStringList("entityTypeAttackRestrictionBlackList", ImmutableList.of("minecraft:villager"), "The entities that are NOT allowed to be attacked while the Entity Attack Restriction tweak is enabled,\nif the entityAttackRestrictionListType is set to Black List"); public static final ConfigStringList ENTITY_TYPE_ATTACK_RESTRICTION_WHITELIST = new ConfigStringList("entityTypeAttackRestrictionWhiteList", ImmutableList.of(), "The only entities that can be attacked while the Entity Attack Restriction tweak is enabled,\nif the entityAttackRestrictionListType is set to White List"); @@ -240,7 +244,7 @@ public static class Lists BLOCK_TYPE_BREAK_RESTRICTION_LIST_TYPE, BLOCK_TYPE_BREAK_RESTRICTION_BLACKLIST, BLOCK_TYPE_BREAK_RESTRICTION_WHITELIST, - CREATIVE_EXTRA_ITEMS, + //CREATIVE_EXTRA_ITEMS, ENTITY_TYPE_ATTACK_RESTRICTION_LIST_TYPE, ENTITY_TYPE_ATTACK_RESTRICTION_BLACKLIST, ENTITY_TYPE_ATTACK_RESTRICTION_WHITELIST, @@ -276,7 +280,7 @@ public static class Disable public static final ConfigBooleanHotkeyed DISABLE_DOUBLE_TAP_SPRINT = new ConfigBooleanHotkeyed("disableDoubleTapSprint", false, "", "Disables the double-tap-forward-key sprinting"); public static final ConfigBooleanHotkeyed DISABLE_BOSS_BAR = new ConfigBooleanHotkeyed("disableBossBar", false, "", "Disables boss bar rendering"); public static final ConfigBooleanHotkeyed DISABLE_BOSS_FOG = new ConfigBooleanHotkeyed("disableBossFog", false, "", "Removes the fog that boss mobs cause"); - public static final ConfigBooleanHotkeyed DISABLE_CHUNK_RENDERING = new ConfigBooleanHotkeyed("disableChunkRendering", false, "", "Disables chunk (re-)rendering. This will make any block changes non-visible\\nuntil this is disabled again and F3 + A is used to refresh the world rendering.\\nThis might help with low fps in places with lots of block changes in some situations,\\nwhere the block changes are not really relevant at that time."); + public static final ConfigBooleanHotkeyed DISABLE_CHUNK_RENDERING = new ConfigBooleanHotkeyed("disableChunkRendering", false, "", "Disables chunk (re-)rendering. This will make any block changes non-visible\nuntil this is disabled again and F3 + A is used to refresh the world rendering.\nThis might help with low fps in places with lots of block changes in some situations,\nwhere the block changes are not really relevant at that time."); public static final ConfigBooleanHotkeyed DISABLE_CLIENT_ENTITY_UPDATES = new ConfigBooleanHotkeyed("disableClientEntityUpdates", false, "", "Disables ALL except player entity updates on the client.\nThis is mainly meant for situations where you need to be\nable to do stuff to fix excessive entity count related problems"); public static final ConfigBooleanHotkeyed DISABLE_CLIENT_LIGHT_UPDATES = new ConfigBooleanHotkeyed("disableClientLightUpdates", false, "", "Disables all client-side light updates"); public static final ConfigBooleanHotkeyed DISABLE_CONSTANT_CHUNK_SAVING = new ConfigBooleanHotkeyed("disableConstantChunkSaving", false, "", "Disables the game saving up to 20 chunks every tick\nall the time, in addition to the normal auto-save cycle."); @@ -311,7 +315,7 @@ public static class Disable public static final ConfigBooleanHotkeyed DISABLE_TILE_ENTITY_TICKING = new ConfigBooleanClient ("disableTileEntityTicking", false, "", "Prevent all TileEntities from getting ticked"); public static final ConfigBooleanHotkeyed DISABLE_VILLAGER_TRADE_LOCKING = new ConfigBooleanClient ("disableVillagerTradeLocking", false, "", "Prevents villager trades from ever locking, by always incrementing\nthe max uses as well when the recipe uses is incremented"); public static final ConfigBooleanHotkeyed DISABLE_WALL_UNSPRINT = new ConfigBooleanHotkeyed("disableWallUnsprint", false, "", "Touching a wall doesn't drop you out from sprint mode"); - public static final ConfigBooleanHotkeyed DISABLE_WORLD_VIEW_BOB = new ConfigBooleanHotkeyed("disableWorldViewBob", false, "", "Disables the view bob wobble effect of the world, but not the hand"); + public static final ConfigBooleanHotkeyed DISABLE_WORLD_VIEW_BOB = new ConfigBooleanHotkeyed("disableWorldViewBob", false, "", "Disables the view bob wobble effect of the world, but not the hand\nThis setting will fail if you have Iris installed."); public static final ImmutableList OPTIONS = ImmutableList.of( DISABLE_ARMOR_STAND_RENDERING, diff --git a/src/main/java/fi/dy/masa/tweakeroo/config/FeatureToggle.java b/src/main/java/fi/dy/masa/tweakeroo/config/FeatureToggle.java index 6de4ed8..5f22d13 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/config/FeatureToggle.java +++ b/src/main/java/fi/dy/masa/tweakeroo/config/FeatureToggle.java @@ -22,7 +22,7 @@ public enum FeatureToggle implements IHotkeyTogglable, IConfigNotifiable blockReachDistance"), + TWEAK_BLOCK_REACH_OVERRIDE ("tweakBlockReachOverride", false, true, "", "Overrides the block reach distance with\nthe one set in Generic -> blockReachDistance"), TWEAK_BLOCK_TYPE_BREAK_RESTRICTION("tweakBlockTypeBreakRestriction", false, "", "Restricts which blocks you are able to break (manually).\nSee the corresponding 'blockBreakRestriction*' configs in the Lists category."), TWEAK_BREAKING_GRID ("tweakBreakingGrid", false, "", KeybindSettings.INGAME_BOTH, "When enabled, you can only break blocks in\na grid pattern, with a configurable interval.\nTo quickly adjust the interval, scroll while\nholding down the tweak toggle keybind."), TWEAK_BREAKING_RESTRICTION ("tweakBreakingRestriction", false, "", "Enables the Breaking Restriction mode\n (Plane, Layer, Face, Column, Line, Diagonal).\nBasically only allows you to break blocks\nin those patterns, while holding down the attack key."), @@ -37,6 +37,7 @@ public enum FeatureToggle implements IHotkeyTogglable, IConfigNotifiable flyDecelerationRampValue"), TWEAK_CUSTOM_INVENTORY_GUI_SCALE("tweakCustomInventoryScreenScale", false, "", "Allows using a custom GUI scale for any inventory screen.\nSee Generic -> §ecustomInventoryGuiScale§r for the scale value"), TWEAK_ELYTRA_CAMERA ("tweakElytraCamera", false, "", "Allows locking the real player rotations while holding the 'elytraCamera' activation key.\nThe controls will then only affect the separate 'camera rotations' for the rendering/camera.\nMeant for things like looking down/around while elytra flying nice and straight."), + TWEAK_ENTITY_REACH_OVERRIDE ("tweakEntityReachOverride", false, true, "", "Overrides the entity reach distance with\nthe one set in Generic -> entityReachDistance"), TWEAK_ENTITY_TYPE_ATTACK_RESTRICTION("tweakEntityTypeAttackRestriction",false, "", "Restricts which entities you are able to attack (manually).\nSee the corresponding 'entityAttackRestriction*' configs in the Lists category."), TWEAK_SHULKERBOX_STACKING ("tweakEmptyShulkerBoxesStack", false, true, "", "Enables empty Shulker Boxes stacking up to 64.\nNOTE: They will also stack inside inventories!\nOn servers this will cause desyncs/glitches\nunless the server has a mod that does the same.\nIn single player this changes shulker box based system behaviour."), TWEAK_SHULKERBOX_STACK_GROUND ("tweakEmptyShulkerBoxesStackOnGround", false, true, "", "Enables empty Shulker Boxes stacking up to 64\nwhen as items on the ground"), @@ -68,7 +69,7 @@ public enum FeatureToggle implements IHotkeyTogglable, IConfigNotifiable periodicAttackInterval"), TWEAK_PERIODIC_USE ("tweakPeriodicUse", false, "", "Enables periodic uses (right clicks)\nConfigure the interval in Generic -> periodicUseInterval"), TWEAK_PERIODIC_HOLD_ATTACK ("tweakPeriodicHoldAttack", false, "", "Enables periodically holding attack for a configurable amount of time.\nConfigure the interval in Generic -> periodicHoldAttackInterval\nand the duration in periodicHoldAttackDuration\n§6Note: You should not use the normal hold attack\n§6or the periodic attack at the same time"), - TWEAK_PERIODIC_HOLD_USE ("tweakPeriodicHoldUse", false, "", "Enables periodically holding use for a configurable amount of time.\nConfigure the interval in Generic -> periodicHoldUseInterval\nand the duration in periodicHoldUseDuration\\n§6Note: You should not use the normal hold use\n§6or the periodic use at the same time"), + TWEAK_PERIODIC_HOLD_USE ("tweakPeriodicHoldUse", false, "", "Enables periodically holding use for a configurable amount of time.\nConfigure the interval in Generic -> periodicHoldUseInterval\nand the duration in periodicHoldUseDuration\n§6Note: You should not use the normal hold use\n§6or the periodic use at the same time"), TWEAK_PERMANENT_SNEAK ("tweakPermanentSneak", false, "", "If enabled, the player will be sneaking the entire time"), TWEAK_PERMANENT_SPRINT ("tweakPermanentSprint", false, "", "If enabled, the player will be always sprinting when moving forward"), TWEAK_PLACEMENT_GRID ("tweakPlacementGrid", false, "", KeybindSettings.INGAME_BOTH, "When enabled, you can only place blocks in\na grid pattern, with a configurable interval.\nTo quickly adjust the value, scroll while\nholding down the tweak toggle keybind."), diff --git a/src/main/java/fi/dy/masa/tweakeroo/event/InputHandler.java b/src/main/java/fi/dy/masa/tweakeroo/event/InputHandler.java index cfabd9b..8982981 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/event/InputHandler.java +++ b/src/main/java/fi/dy/masa/tweakeroo/event/InputHandler.java @@ -10,14 +10,10 @@ import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.Vec3d; +import net.minecraft.world.RaycastContext; import fi.dy.masa.malilib.config.options.ConfigDouble; import fi.dy.masa.malilib.gui.GuiBase; -import fi.dy.masa.malilib.hotkeys.IHotkey; -import fi.dy.masa.malilib.hotkeys.IKeybindManager; -import fi.dy.masa.malilib.hotkeys.IKeybindProvider; -import fi.dy.masa.malilib.hotkeys.IKeyboardInputHandler; -import fi.dy.masa.malilib.hotkeys.IMouseInputHandler; -import fi.dy.masa.malilib.hotkeys.KeyCallbackAdjustable; +import fi.dy.masa.malilib.hotkeys.*; import fi.dy.masa.malilib.util.GuiUtils; import fi.dy.masa.malilib.util.InfoUtils; import fi.dy.masa.tweakeroo.Reference; @@ -26,7 +22,6 @@ import fi.dy.masa.tweakeroo.config.Hotkeys; import fi.dy.masa.tweakeroo.util.MiscUtils; import fi.dy.masa.tweakeroo.util.SnapAimMode; -import net.minecraft.world.RaycastContext; public class InputHandler implements IKeybindProvider, IKeyboardInputHandler, IMouseInputHandler { @@ -106,7 +101,7 @@ public boolean onMouseClick(int mouseX, int mouseY, int eventButton, boolean eve Vec3d vec3d = eyePos.add(rotVec.multiply(Configs.Generic.ANGEL_BLOCK_PLACEMENT_DISTANCE.getDoubleValue())); BlockHitResult context = mc.world.raycast(new RaycastContext(eyePos, vec3d, RaycastContext.ShapeType.OUTLINE, RaycastContext.FluidHandling.SOURCE_ONLY, mc.player)); - + for (Hand hand : Hand.values()) { ItemStack stack = mc.player.getStackInHand(hand); diff --git a/src/main/java/fi/dy/masa/tweakeroo/event/RenderHandler.java b/src/main/java/fi/dy/masa/tweakeroo/event/RenderHandler.java index c8e6514..2049306 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/event/RenderHandler.java +++ b/src/main/java/fi/dy/masa/tweakeroo/event/RenderHandler.java @@ -5,9 +5,10 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.component.DataComponentTypes; import net.minecraft.entity.Entity; import net.minecraft.item.FilledMapItem; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.HitResult; @@ -16,6 +17,7 @@ import fi.dy.masa.malilib.interfaces.IRenderer; import fi.dy.masa.malilib.util.ActiveMode; import fi.dy.masa.malilib.util.Color4f; +import fi.dy.masa.malilib.util.InventoryUtils; import fi.dy.masa.tweakeroo.config.Configs; import fi.dy.masa.tweakeroo.config.FeatureToggle; import fi.dy.masa.tweakeroo.config.Hotkeys; @@ -71,7 +73,8 @@ else if (FeatureToggle.TWEAK_HOTBAR_SCROLL.getBooleanValue() && @Override public void onRenderTooltipLast(DrawContext drawContext, ItemStack stack, int x, int y) { - if (stack.getItem() instanceof FilledMapItem) + Item item = stack.getItem(); + if (item instanceof FilledMapItem) { if (FeatureToggle.TWEAK_MAP_PREVIEW.getBooleanValue() && (Configs.Generic.MAP_PREVIEW_REQUIRE_SHIFT.getBooleanValue() == false || GuiBase.isShiftDown())) @@ -79,11 +82,10 @@ public void onRenderTooltipLast(DrawContext drawContext, ItemStack stack, int x, fi.dy.masa.malilib.render.RenderUtils.renderMapPreview(stack, x, y, Configs.Generic.MAP_PREVIEW_SIZE.getIntegerValue(), false); } } - else if (FeatureToggle.TWEAK_SHULKERBOX_DISPLAY.getBooleanValue()) + else if (stack.getComponents().contains(DataComponentTypes.CONTAINER) && InventoryUtils.shulkerBoxHasItems(stack)) { - boolean render = Configs.Generic.SHULKER_DISPLAY_REQUIRE_SHIFT.getBooleanValue() == false || GuiBase.isShiftDown(); - - if (render) + if (FeatureToggle.TWEAK_SHULKERBOX_DISPLAY.getBooleanValue() && + (Configs.Generic.SHULKER_DISPLAY_REQUIRE_SHIFT.getBooleanValue() == false || GuiBase.isShiftDown())) { fi.dy.masa.malilib.render.RenderUtils.renderShulkerBoxPreview(stack, x, y, Configs.Generic.SHULKER_DISPLAY_BACKGROUND_COLOR.getBooleanValue(), drawContext); } @@ -91,17 +93,17 @@ else if (FeatureToggle.TWEAK_SHULKERBOX_DISPLAY.getBooleanValue()) } @Override - public void onRenderWorldLast(MatrixStack matrixStack, Matrix4f projMatrix) + public void onRenderWorldLast(Matrix4f matrix4f, Matrix4f projMatrix) { MinecraftClient mc = MinecraftClient.getInstance(); if (mc.player != null) { - this.renderOverlays(matrixStack, mc); + this.renderOverlays(matrix4f, mc); } } - private void renderOverlays(MatrixStack matrixStack, MinecraftClient mc) + private void renderOverlays(Matrix4f matrix4f, MinecraftClient mc) { Entity entity = mc.getCameraEntity(); @@ -128,7 +130,7 @@ private void renderOverlays(MatrixStack matrixStack, MinecraftClient mc) hitResult.getSide(), hitResult.getPos(), color, - matrixStack, + matrix4f, mc); RenderSystem.enableDepthTest(); diff --git a/src/main/java/fi/dy/masa/tweakeroo/event/WorldLoadListener.java b/src/main/java/fi/dy/masa/tweakeroo/event/WorldLoadListener.java index 2a4a0be..e84c24f 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/event/WorldLoadListener.java +++ b/src/main/java/fi/dy/masa/tweakeroo/event/WorldLoadListener.java @@ -14,4 +14,17 @@ public void onWorldLoadPre(@Nullable ClientWorld worldBefore, @Nullable ClientWo // Always disable the Free Camera mode when leaving the world or switching dimensions FeatureToggle.TWEAK_FREE_CAMERA.setBooleanValue(false); } -} + + @Override + public void onWorldLoadPost(@Nullable ClientWorld worldBefore, @Nullable ClientWorld worldAfter, MinecraftClient mc) + { + if (worldBefore == null) + { + if (FeatureToggle.TWEAK_GAMMA_OVERRIDE.getBooleanValue()) + { + FeatureToggle.TWEAK_GAMMA_OVERRIDE.setBooleanValue(false); + FeatureToggle.TWEAK_GAMMA_OVERRIDE.setBooleanValue(true); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinBackgroundRenderer.java b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinBackgroundRenderer.java index 323e2bd..8216ee7 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinBackgroundRenderer.java +++ b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinBackgroundRenderer.java @@ -1,14 +1,9 @@ package fi.dy.masa.tweakeroo.mixin; -import com.mojang.blaze3d.systems.RenderSystem; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Constant; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyConstant; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.Slice; +import org.spongepowered.asm.mixin.injection.*; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.BackgroundRenderer; import net.minecraft.client.render.Camera; @@ -25,7 +20,7 @@ public abstract class MixinBackgroundRenderer @ModifyConstant( method = "applyFog", slice = @Slice( - from = @At(value = "FIELD", target = "Lnet/minecraft/entity/effect/StatusEffects;FIRE_RESISTANCE:Lnet/minecraft/entity/effect/StatusEffect;"), + from = @At(value = "FIELD", target = "Lnet/minecraft/entity/effect/StatusEffects;FIRE_RESISTANCE:Lnet/minecraft/registry/entry/RegistryEntry;"), to = @At(value = "FIELD", target = "Lnet/minecraft/client/render/CameraSubmersionType;POWDER_SNOW:Lnet/minecraft/client/render/CameraSubmersionType;")), constant = @Constant(floatValue = 0.25f), require = 0) @@ -44,9 +39,9 @@ private static float reduceLavaFogStart(float original) @ModifyConstant( method = "applyFog", slice = @Slice( - from = @At(value = "FIELD", target = "Lnet/minecraft/entity/effect/StatusEffects;FIRE_RESISTANCE:Lnet/minecraft/entity/effect/StatusEffect;"), + from = @At(value = "FIELD", target = "Lnet/minecraft/entity/effect/StatusEffects;FIRE_RESISTANCE:Lnet/minecraft/registry/entry/RegistryEntry;"), to = @At(value = "FIELD", target = "Lnet/minecraft/client/render/CameraSubmersionType;POWDER_SNOW:Lnet/minecraft/client/render/CameraSubmersionType;")), - constant = { @Constant(floatValue = 1.0f), @Constant(floatValue = 3.0f)}, + constant = { @Constant(floatValue = 1.0f), @Constant(floatValue = 5.0f)}, require = 0) private static float reduceLavaFogEnd(float original) { @@ -72,10 +67,8 @@ private static float overrideFogStart(float original) { return Math.max(512, MinecraftClient.getInstance().gameRenderer.getViewDistance()) * 1.6f; } - return original; } - @ModifyVariable( method = "applyFog(Lnet/minecraft/client/render/Camera;Lnet/minecraft/client/render/BackgroundRenderer$FogType;FZ)V", slice = @Slice( @@ -87,7 +80,6 @@ private static float overrideFogEnd(float original) { return Math.max(512, MinecraftClient.getInstance().gameRenderer.getViewDistance()) * 2.0f; } - return original; } */ diff --git a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinChatHud.java b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinChatHud.java index f853c97..cfcda3a 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinChatHud.java +++ b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinChatHud.java @@ -18,16 +18,10 @@ @Mixin(value = ChatHud.class, priority = 1100) public abstract class MixinChatHud { - @ModifyVariable(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;ILnet/minecraft/client/gui/hud/MessageIndicator;Z)V", + @ModifyVariable(method = "Lnet/minecraft/client/gui/hud/ChatHud;addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V", at = @At("HEAD"), argsOnly = true) - private Text tweakeroo_addMessageTimestamp(Text componentIn, Text parameterMessage, MessageSignatureData data, int ticks, MessageIndicator indicator, boolean refreshing) + private Text tweakeroo_addMessageTimestamp(Text componentIn, Text parameterMessage, MessageSignatureData data, MessageIndicator indicator) { - // If we're refreshing, we have probably already modified the message, therefore we don't want to do anything. - if (refreshing) - { - return componentIn; - } - if (FeatureToggle.TWEAK_CHAT_TIMESTAMP.getBooleanValue()) { MutableText newComponent = Text.literal(MiscUtils.getChatTimestamp() + " "); diff --git a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinChatScreen.java b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinChatScreen.java index a2f18b5..6fe5754 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinChatScreen.java +++ b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinChatScreen.java @@ -43,7 +43,7 @@ private void restoreText(String defaultText, CallbackInfo ci) @Inject(method = "keyPressed(III)Z", slice = @Slice( - from = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ChatScreen;sendMessage(Ljava/lang/String;Z)Z")), + from = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ChatScreen;sendMessage(Ljava/lang/String;Z)V")), at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;setScreen(Lnet/minecraft/client/gui/screen/Screen;)V", shift = Shift.AFTER)) private void onSendMessage(int keyCode, int scancode, int modifiers, CallbackInfoReturnable cir) { diff --git a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinClientPlayerInteractionManager.java b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinClientPlayerInteractionManager.java index 4b970e2..937f3a4 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinClientPlayerInteractionManager.java +++ b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinClientPlayerInteractionManager.java @@ -21,7 +21,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; -import fi.dy.masa.tweakeroo.config.Configs; import fi.dy.masa.tweakeroo.config.FeatureToggle; import fi.dy.masa.tweakeroo.tweaks.MiscTweaks; import fi.dy.masa.tweakeroo.tweaks.PlacementTweaks; @@ -160,24 +159,6 @@ private void handleBreakingRestriction2(BlockPos pos, Direction side, CallbackIn } } - @Inject(method = "getReachDistance", at = @At("HEAD"), cancellable = true) - private void overrideReachDistance(CallbackInfoReturnable cir) - { - if (FeatureToggle.TWEAK_BLOCK_REACH_OVERRIDE.getBooleanValue()) - { - cir.setReturnValue((float) Configs.Generic.BLOCK_REACH_DISTANCE.getDoubleValue()); - } - } - - @Inject(method = "hasExtendedReach", at = @At("HEAD"), cancellable = true) - private void overrideExtendedReach(CallbackInfoReturnable cir) - { - if (FeatureToggle.TWEAK_BLOCK_REACH_OVERRIDE.getBooleanValue()) - { - cir.setReturnValue(false); - } - } - @Inject(method = "hasLimitedAttackSpeed", at = @At("HEAD"), cancellable = true) private void overrideLimitedAttackSpeed(CallbackInfoReturnable cir) { diff --git a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinExplosion.java b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinExplosion.java index 09549c1..dd59a28 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinExplosion.java +++ b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinExplosion.java @@ -2,9 +2,8 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.Slice; -import net.minecraft.particle.DefaultParticleType; +import org.spongepowered.asm.mixin.injection.ModifyArg; +import net.minecraft.particle.ParticleEffect; import net.minecraft.particle.ParticleTypes; import net.minecraft.world.explosion.Explosion; import fi.dy.masa.tweakeroo.config.FeatureToggle; @@ -12,14 +11,10 @@ @Mixin(Explosion.class) public abstract class MixinExplosion { - @Redirect(method = "affectWorld", - slice = @Slice( - from = @At("HEAD"), - to = @At(value = "FIELD", - target = "Lnet/minecraft/world/explosion/Explosion;affectedBlocks:Lit/unimi/dsi/fastutil/objects/ObjectArrayList;")), - at = @At(value = "FIELD", - target = "Lnet/minecraft/particle/ParticleTypes;EXPLOSION_EMITTER:Lnet/minecraft/particle/DefaultParticleType;")) - private DefaultParticleType redirectSpawnParticles() + @ModifyArg(method = "affectWorld", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/world/World;addParticle(Lnet/minecraft/particle/ParticleEffect;DDDDDD)V")) + private ParticleEffect addParticleModify(ParticleEffect parameters) { if (FeatureToggle.TWEAK_EXPLOSION_REDUCED_PARTICLES.getBooleanValue()) { diff --git a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinGameRenderer.java b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinGameRenderer.java index 43c3f0d..8b5b5d6 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinGameRenderer.java +++ b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinGameRenderer.java @@ -32,8 +32,6 @@ public abstract class MixinGameRenderer { @Shadow @Final MinecraftClient client; - @Shadow protected abstract void bobView(MatrixStack matrices, float tickDelta); - private float realYaw; private float realPitch; @@ -46,16 +44,6 @@ private void onRenderWorld(CallbackInfo ci) } } - @Redirect(method = "renderWorld", require = 0, at = @At(value = "INVOKE", - target = "Lnet/minecraft/client/render/GameRenderer;bobView(Lnet/minecraft/client/util/math/MatrixStack;F)V")) - private void disableWorldViewBob(GameRenderer renderer, MatrixStack matrices, float tickDelta) - { - if (Configs.Disable.DISABLE_WORLD_VIEW_BOB.getBooleanValue() == false) - { - this.bobView(matrices, tickDelta); - } - } - @Inject(method = "getFov", at = @At("HEAD"), cancellable = true) private void applyZoom(Camera camera, float partialTicks, boolean useFOVSetting, CallbackInfoReturnable cir) { @@ -69,7 +57,7 @@ else if (FeatureToggle.TWEAK_FREE_CAMERA.getBooleanValue()) } } - @Redirect(method = "updateTargetedEntity", at = @At(value = "INVOKE", + @Redirect(method = "updateCrosshairTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;getCameraEntity()Lnet/minecraft/entity/Entity;")) private Entity overrideCameraEntityForRayTrace(MinecraftClient mc) { @@ -87,7 +75,7 @@ private Entity overrideCameraEntityForRayTrace(MinecraftClient mc) return mc.getCameraEntity(); } - @ModifyArg(method = "updateTargetedEntity", + @ModifyArg(method = "findCrosshairTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/projectile/ProjectileUtil;raycast(" + "Lnet/minecraft/entity/Entity;" + @@ -114,7 +102,7 @@ private Predicate overrideTargetedEntityCheck(Predicate predicat @Inject(method = "renderWorld", at = @At( value = "INVOKE", shift = Shift.AFTER, - target = "Lnet/minecraft/client/render/GameRenderer;updateTargetedEntity(F)V")) + target = "Lnet/minecraft/client/render/GameRenderer;updateCrosshairTarget(F)V")) private void overrideRenderViewEntityPre(CallbackInfo ci) { if (FeatureToggle.TWEAK_ELYTRA_CAMERA.getBooleanValue() && Hotkeys.ELYTRA_CAMERA.getKeybind().isKeybindHeld()) diff --git a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinGameRenderer_ViewBob.java b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinGameRenderer_ViewBob.java new file mode 100644 index 0000000..fa30642 --- /dev/null +++ b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinGameRenderer_ViewBob.java @@ -0,0 +1,29 @@ +package fi.dy.masa.tweakeroo.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; +import net.minecraft.client.render.GameRenderer; +import net.minecraft.client.util.math.MatrixStack; +import fi.dy.masa.tweakeroo.config.Configs; + +/** + * Separated out for Iris compatibility by adjusting the Mixin Priority + */ +@Mixin(value = GameRenderer.class, priority = 999) +public abstract class MixinGameRenderer_ViewBob +{ + @Shadow + protected abstract void bobView(MatrixStack matrices, float tickDelta); + + @Redirect(method = "renderWorld", require = 0, at = @At(value = "INVOKE", + target = "Lnet/minecraft/client/render/GameRenderer;bobView(Lnet/minecraft/client/util/math/MatrixStack;F)V")) + private void disableWorldViewBob(GameRenderer renderer, MatrixStack matrices, float tickDelta) + { + if (Configs.Disable.DISABLE_WORLD_VIEW_BOB.getBooleanValue() == false) + { + this.bobView(matrices, tickDelta); + } + } +} diff --git a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinInGameHud.java b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinInGameHud.java index d272f3a..d290de5 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinInGameHud.java +++ b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinInGameHud.java @@ -26,7 +26,6 @@ public abstract class MixinInGameHud { @Shadow @Final private PlayerListHud playerListHud; @Shadow @Final private MinecraftClient client; - @Shadow private int scaledWidth; @Inject(method = "getCameraPlayer", at = @At("HEAD"), cancellable = true) private void overridePlayerForRendering(CallbackInfoReturnable cir) @@ -49,7 +48,7 @@ private void overrideCursorRender(CallbackInfo ci) } } - @Inject(method = "render", + @Inject(method = "renderPlayerList", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/PlayerListHud;setVisible(Z)V", ordinal = 1, shift = At.Shift.AFTER)) @@ -61,11 +60,12 @@ private void alwaysRenderPlayerList(DrawContext drawContext, float tickDelta, Ca ScoreboardObjective objective = scoreboard.getObjectiveForSlot(ScoreboardDisplaySlot.LIST); this.playerListHud.setVisible(true); - this.playerListHud.render(drawContext, this.scaledWidth, scoreboard, objective); + this.playerListHud.render(drawContext, drawContext.getScaledWindowWidth(), scoreboard, objective); } } - @Inject(method = "renderScoreboardSidebar", at = @At("HEAD"), cancellable = true) + @Inject(method = "renderScoreboardSidebar(Lnet/minecraft/client/gui/DrawContext;Lnet/minecraft/scoreboard/ScoreboardObjective;)V", + at = @At("HEAD"), cancellable = true) private void disableScoreboardRendering(CallbackInfo ci) { if (Configs.Disable.DISABLE_SCOREBOARD_RENDERING.getBooleanValue()) diff --git a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinItem.java b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinItem.java index 2ab75b7..c405ba3 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinItem.java +++ b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinItem.java @@ -1,5 +1,6 @@ package fi.dy.masa.tweakeroo.mixin; +import net.minecraft.item.Item; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import fi.dy.masa.tweakeroo.util.IItemStackLimit; @@ -7,12 +8,12 @@ @Mixin(net.minecraft.item.Item.class) public abstract class MixinItem implements IItemStackLimit { - @Shadow public int getMaxCount() { return 0; } + @Shadow public abstract Item asItem(); @Override public int getMaxStackSize(net.minecraft.item.ItemStack stack) { - return this.getMaxCount(); + return this.asItem().getMaxCount(); } /* // TODO 1.19.3+ diff --git a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinItemEntity.java b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinItemEntity.java index 32152d5..fab2f59 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinItemEntity.java +++ b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinItemEntity.java @@ -17,7 +17,6 @@ import fi.dy.masa.tweakeroo.config.FeatureToggle; import fi.dy.masa.tweakeroo.util.IEntityItem; -import fi.dy.masa.tweakeroo.util.InventoryUtils; @Mixin(ItemEntity.class) public abstract class MixinItemEntity extends Entity implements IEntityItem @@ -38,21 +37,6 @@ public int getPickupDelay() return this.pickupDelay; } - @Inject(method = "(Lnet/minecraft/world/World;DDDLnet/minecraft/item/ItemStack;)V", at = @At("RETURN")) - private void removeEmptyShulkerBoxTags(World worldIn, double x, double y, double z, ItemStack stack, CallbackInfo ci) - { - if (FeatureToggle.TWEAK_SHULKERBOX_STACK_GROUND.getBooleanValue()) - { - if (stack.getItem() instanceof BlockItem && ((BlockItem) stack.getItem()).getBlock() instanceof ShulkerBoxBlock) - { - if (InventoryUtils.cleanUpShulkerBoxNBT(stack)) - { - ((ItemEntity) (Object) this).setStack(stack); - } - } - } - } - @Inject(method = "canMerge()Z", at = @At("HEAD"), cancellable = true) private void allowStackingEmptyShulkerBoxes(CallbackInfoReturnable cir) { @@ -87,7 +71,7 @@ private void stackEmptyShulkerBoxes(ItemEntity other, CallbackInfo ci) fi.dy.masa.malilib.util.InventoryUtils.shulkerBoxHasItems(stackSelf) == false && // Only stack up to 64, and don't steal from other stacks that are larger stackSelf.getCount() < 64 && stackSelf.getCount() >= stackOther.getCount() && - ItemStack.canCombine(stackSelf, stackOther)) + ItemStack.areItemsAndComponentsEqual(stackSelf, stackOther)) { int amount = Math.min(stackOther.getCount(), 64 - stackSelf.getCount()); diff --git a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinItemStack.java b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinItemStack.java index 3e95230..5c8ef95 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinItemStack.java +++ b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinItemStack.java @@ -5,6 +5,8 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import net.minecraft.component.ComponentMap; +import net.minecraft.component.DataComponentTypes; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import fi.dy.masa.tweakeroo.util.IItemStackLimit; @@ -15,9 +17,11 @@ public abstract class MixinItemStack @Shadow public abstract Item getItem(); - @Inject(method = "getMaxCount", at = @At("HEAD"), cancellable = true) - public void getMaxStackSizeStackSensitive(CallbackInfoReturnable ci) + @Shadow public abstract ComponentMap getComponents(); + + @Inject(method = "getMaxCount", at = @At("RETURN"), cancellable = true) + public void getMaxStackSizeStackSensitive(CallbackInfoReturnable cir) { - ci.setReturnValue(((IItemStackLimit) this.getItem()).getMaxStackSize((ItemStack) (Object) this)); + cir.setReturnValue(Math.max(this.getComponents().getOrDefault(DataComponentTypes.MAX_STACK_SIZE, 1), ((IItemStackLimit) this.getItem()).getMaxStackSize((ItemStack) (Object) this))); } } diff --git a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinPlayerEntity.java b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinPlayerEntity.java index 255261b..41e8b8c 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinPlayerEntity.java +++ b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinPlayerEntity.java @@ -7,12 +7,14 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.world.World; +import fi.dy.masa.tweakeroo.config.Configs; import fi.dy.masa.tweakeroo.config.FeatureToggle; @Mixin(PlayerEntity.class) @@ -45,4 +47,40 @@ private boolean fakeSneaking(PlayerEntity entity) return this.clipAtLedge(); } + + @Inject(method = "getBlockInteractionRange", at = @At("RETURN"), cancellable = true) + private void overrideBlockReachDistance(CallbackInfoReturnable cir) + { + if (FeatureToggle.TWEAK_BLOCK_REACH_OVERRIDE.getBooleanValue()) + { + if (MinecraftClient.getInstance().isIntegratedServerRunning()) + { + cir.setReturnValue(Configs.Generic.BLOCK_REACH_DISTANCE.getDoubleValue()); + } + else + { + // Calculate a "safe" range for servers + double rangeRealMax = cir.getReturnValue() + 1.0; + cir.setReturnValue(Math.min(Configs.Generic.BLOCK_REACH_DISTANCE.getDoubleValue(), rangeRealMax)); + } + } + } + + @Inject(method = "getEntityInteractionRange", at = @At("RETURN"), cancellable = true) + private void overrideEntityReachDistance(CallbackInfoReturnable cir) + { + if (FeatureToggle.TWEAK_ENTITY_REACH_OVERRIDE.getBooleanValue()) + { + if (MinecraftClient.getInstance().isIntegratedServerRunning()) + { + cir.setReturnValue(Configs.Generic.ENTITY_REACH_DISTANCE.getDoubleValue()); + } + else + { + // Calculate a "safe" range for servers + double rangeRealMax = cir.getReturnValue() + 1.0; + cir.setReturnValue(Math.min(Configs.Generic.ENTITY_REACH_DISTANCE.getDoubleValue(), rangeRealMax)); + } + } + } } diff --git a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinShulkerBoxBlock.java b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinShulkerBoxBlock.java index 18ce33b..56d9962 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinShulkerBoxBlock.java +++ b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinShulkerBoxBlock.java @@ -6,10 +6,10 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import net.minecraft.block.ShulkerBoxBlock; -import net.minecraft.client.item.TooltipContext; +import net.minecraft.client.item.TooltipType; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.text.Text; -import net.minecraft.world.BlockView; import fi.dy.masa.tweakeroo.config.Configs; @Mixin(ShulkerBoxBlock.class) @@ -17,9 +17,9 @@ public abstract class MixinShulkerBoxBlock { @Inject(method = "appendTooltip", at = @At("HEAD"), cancellable = true) private void removeVanillaTooltip(ItemStack stack, - BlockView world, + Item.TooltipContext context, List tooltip, - TooltipContext options, + TooltipType options, CallbackInfo ci) { if (Configs.Disable.DISABLE_SHULKER_BOX_TOOLTIP.getBooleanValue()) diff --git a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinSignBlockEntity.java b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinSignBlockEntity.java index 82c7ff6..9b0bee2 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinSignBlockEntity.java +++ b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinSignBlockEntity.java @@ -12,8 +12,10 @@ import net.minecraft.block.entity.SignBlockEntity; import net.minecraft.block.entity.SignText; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.ingame.HangingSignEditScreen; import net.minecraft.client.gui.screen.ingame.SignEditScreen; import net.minecraft.nbt.NbtCompound; +import net.minecraft.registry.RegistryWrapper; import net.minecraft.util.math.BlockPos; import fi.dy.masa.tweakeroo.config.FeatureToggle; @@ -33,16 +35,19 @@ private MixinSignBlockEntity(BlockEntityType blockEntityType, BlockPos blockP } @Inject(method = "readNbt", at = @At("RETURN")) - private void restoreCopiedText(NbtCompound nbt, CallbackInfo ci) + private void restoreCopiedText(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup, CallbackInfo ci) { // Restore the copied/pasted text after the TileEntity sync overrides it with empty lines if (FeatureToggle.TWEAK_SIGN_COPY.getBooleanValue() && this.getWorld() != null && this.getWorld().isClient) { MinecraftClient mc = MinecraftClient.getInstance(); - if ((mc.currentScreen instanceof SignEditScreen) && ((IGuiEditSign) mc.currentScreen).getTile() == (Object) this) + if (mc.currentScreen instanceof SignEditScreen || mc.currentScreen instanceof HangingSignEditScreen) { - MiscUtils.applyPreviousTextToSign((SignBlockEntity) (Object) this, null, ((SignBlockEntity) (Object) this).isPlayerFacingFront(mc.player)); + if (((IGuiEditSign) mc.currentScreen).getTile() == (Object) this) + { + MiscUtils.applyPreviousTextToSign((SignBlockEntity) (Object) this, null, ((SignBlockEntity) (Object) this).isPlayerFacingFront(mc.player)); + } } } } diff --git a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinWorldRenderer.java b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinWorldRenderer.java index 8c96578..5b2954b 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinWorldRenderer.java +++ b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinWorldRenderer.java @@ -49,7 +49,7 @@ private void cancelRainRender(LightmapTextureManager lightmap, float partialTick @Inject(method = "render", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiler/Profiler;swap(Ljava/lang/String;)V", args = "ldc=terrain_setup")) - private void preSetupTerrain(net.minecraft.client.util.math.MatrixStack matrixStack, float partialTicks, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer renderer, LightmapTextureManager lightmap, Matrix4f matrix4f, CallbackInfo ci) + private void preSetupTerrain(float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) { if (FeatureToggle.TWEAK_FREE_CAMERA.getBooleanValue()) { @@ -59,7 +59,7 @@ private void preSetupTerrain(net.minecraft.client.util.math.MatrixStack matrixSt @Inject(method = "render", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiler/Profiler;swap(Ljava/lang/String;)V", args = "ldc=compile_sections")) - private void postSetupTerrain(net.minecraft.client.util.math.MatrixStack matrixStack, float partialTicks, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer renderer, LightmapTextureManager lightmap, Matrix4f matrix4f, CallbackInfo ci) + private void postSetupTerrain(float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) { CameraUtils.setFreeCameraSpectator(false); } @@ -111,6 +111,7 @@ private void rebuildChunksAroundCamera2( int x = MathHelper.floor(camera.getPos().x) >> 4; int z = MathHelper.floor(camera.getPos().z) >> 4; CameraUtils.markChunksForRebuild(x, z, this.lastUpdatePosX, this.lastUpdatePosZ); + // Could send this to ServuX in the future } } } diff --git a/src/main/java/fi/dy/masa/tweakeroo/renderer/RenderUtils.java b/src/main/java/fi/dy/masa/tweakeroo/renderer/RenderUtils.java index 844de5b..e880a00 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/renderer/RenderUtils.java +++ b/src/main/java/fi/dy/masa/tweakeroo/renderer/RenderUtils.java @@ -2,7 +2,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import org.joml.Matrix4f; -import org.joml.Quaternionf; +import org.joml.Matrix4fStack; import net.minecraft.block.Block; import net.minecraft.block.ShulkerBoxBlock; @@ -11,7 +11,6 @@ import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.render.Camera; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.Enchantments; import net.minecraft.entity.Entity; @@ -270,7 +269,7 @@ public static float getLavaFogDistance(Entity entity, float originalFog) { final int resp = EnchantmentHelper.getRespiration(living); final int aqua = EnchantmentHelper.getEquipmentLevel(Enchantments.AQUA_AFFINITY, living); - float fog = originalFog; + float fog = (originalFog > 1.0f) ? 3.3f : 1.3f; if (aqua > 0) { @@ -295,19 +294,21 @@ public static void renderDirectionsCursor(float zLevel, float partialTicks) int width = GuiUtils.getScaledWindowWidth(); int height = GuiUtils.getScaledWindowHeight(); Camera camera = mc.gameRenderer.getCamera(); - MatrixStack matrixStack = RenderSystem.getModelViewStack(); - matrixStack.push(); - matrixStack.translate(width / 2.0, height / 2.0, zLevel); + + Matrix4fStack matrix4fStack = RenderSystem.getModelViewStack(); + matrix4fStack.pushMatrix(); + matrix4fStack.translate((float) (width / 2.0), (float) (height / 2.0), zLevel); float pitch = camera.getPitch(); float yaw = camera.getYaw(); - Quaternionf rot = new Quaternionf().rotationXYZ(-pitch * (float) (Math.PI / 180.0), yaw * (float) (Math.PI / 180.0), 0.0F); - matrixStack.multiply(rot); - //matrixStack.multiply(RotationAxis.NEGATIVE_X.rotationDegrees(camera.getPitch())); - //matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(camera.getYaw())); - matrixStack.scale(-1.0F, -1.0F, -1.0F); + + matrix4fStack.rotateXYZ(-(pitch) * ((float) (Math.PI / 180.0)), yaw * ((float) (Math.PI / 180.0)), 0.0F); + matrix4fStack.rotateX(fi.dy.masa.malilib.render.RenderUtils.matrix4fRotateFix(-pitch)); + matrix4fStack.rotateY(fi.dy.masa.malilib.render.RenderUtils.matrix4fRotateFix(yaw)); + + matrix4fStack.scale(-1.0F, -1.0F, -1.0F); RenderSystem.applyModelViewMatrix(); RenderSystem.renderCrosshair(10); - matrixStack.pop(); + matrix4fStack.popMatrix(); RenderSystem.applyModelViewMatrix(); } diff --git a/src/main/java/fi/dy/masa/tweakeroo/tweaks/MiscTweaks.java b/src/main/java/fi/dy/masa/tweakeroo/tweaks/MiscTweaks.java index f71c109..c8f13a8 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/tweaks/MiscTweaks.java +++ b/src/main/java/fi/dy/masa/tweakeroo/tweaks/MiscTweaks.java @@ -249,10 +249,10 @@ else if (messageOutputType == MessageOutputType.ACTIONBAR) private static boolean potionWarningShouldInclude(StatusEffectInstance effect) { return effect.isAmbient() == false && - (effect.getEffectType().isBeneficial() || + (effect.getEffectType().value().isBeneficial() || Configs.Generic.POTION_WARNING_BENEFICIAL_ONLY.getBooleanValue() == false) && effect.getDuration() <= Configs.Generic.POTION_WARNING_THRESHOLD.getIntegerValue() && - POTION_RESTRICTION.isAllowed(effect.getEffectType()); + POTION_RESTRICTION.isAllowed(effect.getEffectType().value()); } @Nullable diff --git a/src/main/java/fi/dy/masa/tweakeroo/tweaks/PlacementTweaks.java b/src/main/java/fi/dy/masa/tweakeroo/tweaks/PlacementTweaks.java index 0cc87f6..01dbe7c 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/tweaks/PlacementTweaks.java +++ b/src/main/java/fi/dy/masa/tweakeroo/tweaks/PlacementTweaks.java @@ -225,7 +225,7 @@ private static void onUsingTick() { ClientPlayerEntity player = mc.player; World world = player.getEntityWorld(); - final double reach = mc.interactionManager.getReachDistance(); + final double reach = mc.player.getBlockInteractionRange(); final int maxCount = Configs.Generic.FAST_BLOCK_PLACEMENT_COUNT.getIntegerValue(); mc.crosshairTarget = player.raycast(reach, mc.getTickDelta(), false); @@ -893,13 +893,13 @@ else if (hitPart == HitPart.RIGHT) float yaw = facing.asRotation(); float pitch = player.getPitch(); player.setYaw(yaw); - player.networkHandler.sendPacket(new PlayerMoveC2SPacket.LookAndOnGround(yaw, pitch, player.isOnGround())); + player.networkHandler.send(new PlayerMoveC2SPacket.LookAndOnGround(yaw, pitch, player.isOnGround())); //System.out.printf("handleFlexibleBlockPlacement() pos: %s, side: %s, facing orig: %s facing new: %s\n", pos, side, facingOrig, facing); ActionResult result = processRightClickBlockWrapper(controller, player, world, pos, side, hitVec, hand); player.setYaw(yawOrig); - player.networkHandler.sendPacket(new PlayerMoveC2SPacket.LookAndOnGround(yawOrig, pitch, player.isOnGround())); + player.networkHandler.send(new PlayerMoveC2SPacket.LookAndOnGround(yawOrig, pitch, player.isOnGround())); return result; } diff --git a/src/main/java/fi/dy/masa/tweakeroo/util/CreativeExtraItems.java b/src/main/java/fi/dy/masa/tweakeroo/util/CreativeExtraItems.java index bc22fbe..6026f30 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/util/CreativeExtraItems.java +++ b/src/main/java/fi/dy/masa/tweakeroo/util/CreativeExtraItems.java @@ -1,21 +1,15 @@ package fi.dy.masa.tweakeroo.util; +import javax.annotation.Nullable; import java.util.HashMap; import java.util.List; -import javax.annotation.Nullable; import com.google.common.collect.ArrayListMultimap; -import com.mojang.brigadier.StringReader; import net.minecraft.block.InfestedBlock; -import net.minecraft.command.argument.ItemStringReader; -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemGroups; -import net.minecraft.item.ItemStack; -import net.minecraft.registry.Registries; +import net.minecraft.item.*; import net.minecraft.text.TextContent; import net.minecraft.text.TranslatableTextContent; import net.minecraft.util.collection.DefaultedList; +import fi.dy.masa.malilib.util.InventoryUtils; import fi.dy.masa.tweakeroo.Tweakeroo; public class CreativeExtraItems @@ -67,11 +61,11 @@ private static void setCreativeExtraItems(ItemGroup group, List items) for (String str : items) { - ItemStack stack = parseItemFromString(str); + ItemStack stack = InventoryUtils.getItemStackFromString(str); - if (stack.isEmpty() == false) + if (stack != null && stack.isEmpty() == false) { - if (stack.hasNbt()) + if (stack.getComponents().isEmpty() == false) { ADDED_ITEMS.put(group, stack); } @@ -83,28 +77,6 @@ private static void setCreativeExtraItems(ItemGroup group, List items) } } - public static ItemStack parseItemFromString(String str) - { - try - { - ItemStringReader.ItemResult itemResult = ItemStringReader.item(Registries.ITEM.getReadOnlyWrapper(), new StringReader(str)); - Item item = itemResult.item().value(); - - if (item != null) - { - ItemStack stack = new ItemStack(item); - stack.setNbt(itemResult.nbt()); - return stack; - } - } - catch (Exception e) - { - Tweakeroo.logger.warn("Invalid item '{}'", str); - } - - return ItemStack.EMPTY; - } - public static void removeInfestedBlocks(DefaultedList stacks) { stacks.removeIf((stack) -> stack.getItem() instanceof BlockItem && diff --git a/src/main/java/fi/dy/masa/tweakeroo/util/InventoryUtils.java b/src/main/java/fi/dy/masa/tweakeroo/util/InventoryUtils.java index ea5598a..c2668cb 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/util/InventoryUtils.java +++ b/src/main/java/fi/dy/masa/tweakeroo/util/InventoryUtils.java @@ -1,34 +1,25 @@ package fi.dy.masa.tweakeroo.util; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; +import javax.annotation.Nullable; +import java.util.*; import java.util.function.Predicate; import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.annotation.Nullable; import net.minecraft.block.BlockState; import net.minecraft.client.MinecraftClient; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.AttributeModifiersComponent; +import net.minecraft.component.type.ContainerComponent; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.Enchantments; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.EquipmentSlot; +import net.minecraft.entity.attribute.EntityAttributes; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.item.ArmorItem; -import net.minecraft.item.ElytraItem; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.item.MiningToolItem; -import net.minecraft.item.SwordItem; -import net.minecraft.item.ToolItem; -import net.minecraft.nbt.NbtCompound; +import net.minecraft.item.*; import net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket; import net.minecraft.registry.Registries; import net.minecraft.screen.PlayerScreenHandler; @@ -45,7 +36,6 @@ import net.minecraft.world.World; import fi.dy.masa.malilib.gui.Message; -import fi.dy.masa.malilib.util.Constants; import fi.dy.masa.malilib.util.GuiUtils; import fi.dy.masa.malilib.util.InfoUtils; import fi.dy.masa.tweakeroo.Tweakeroo; @@ -316,7 +306,7 @@ public static void restockNewStackToHand(PlayerEntity player, Hand hand, ItemSta { int slotWithItem; - if (stackReference.getItem().isDamageable()) + if (stackReference.isDamageable()) { int minDurability = getMinDurability(stackReference); slotWithItem = findSlotWithSuitableReplacementToolWithDurabilityLeft(player.playerScreenHandler, stackReference, minDurability); @@ -450,14 +440,22 @@ private static boolean makesMoreDamage(ItemStack testedStack, ItemStack previous private static float getBaseAttackDamage(ItemStack stack) { Item item = stack.getItem(); + if ((item instanceof SwordItem) == false && (item instanceof MiningToolItem) == false) + return 0F; - if (item instanceof SwordItem) + AttributeModifiersComponent itemAttribute = stack.getComponents().get(DataComponentTypes.ATTRIBUTE_MODIFIERS); + + if (itemAttribute != null && itemAttribute.equals(AttributeModifiersComponent.DEFAULT) == false) { - return ((SwordItem) item).getAttackDamage(); - } - else if (item instanceof MiningToolItem) - { - return ((MiningToolItem) item).getAttackDamage(); + List modifiers = itemAttribute.modifiers(); + + for (AttributeModifiersComponent.Entry entry : modifiers) + { + if (entry.attribute().equals(EntityAttributes.GENERIC_ATTACK_DAMAGE)) + { + return (float) entry.modifier().value(); + } + } } return 0F; @@ -806,7 +804,7 @@ private static void swapItemToHand(PlayerEntity player, Hand hand, int slotNumbe if (isHotbarSlot(slotNumber)) { inventory.selectedSlot = slotNumber - 36; - mc.getNetworkHandler().sendPacket(new UpdateSelectedSlotC2SPacket(inventory.selectedSlot)); + mc.getNetworkHandler().send(new UpdateSelectedSlotC2SPacket(inventory.selectedSlot)); } else { @@ -820,7 +818,6 @@ else if (hand == Hand.OFF_HAND) } } - private static void swapItemToEquipmentSlot(PlayerEntity player, EquipmentSlot type, int sourceSlotNumber) { if (sourceSlotNumber != -1 && player.currentScreenHandler == player.playerScreenHandler) @@ -851,7 +848,7 @@ private static void swapToolToHand(int slotNumber, MinecraftClient mc) if (isHotbarSlot(slotNumber)) { inventory.selectedSlot = slotNumber - 36; - mc.getNetworkHandler().sendPacket(new UpdateSelectedSlotC2SPacket(inventory.selectedSlot)); + mc.getNetworkHandler().send(new UpdateSelectedSlotC2SPacket(inventory.selectedSlot)); } else { @@ -863,7 +860,7 @@ private static void swapToolToHand(int slotNumber, MinecraftClient mc) if (hotbarSlot != selectedSlot) { inventory.selectedSlot = hotbarSlot; - mc.getNetworkHandler().sendPacket(new UpdateSelectedSlotC2SPacket(inventory.selectedSlot)); + mc.getNetworkHandler().send(new UpdateSelectedSlotC2SPacket(inventory.selectedSlot)); } mc.interactionManager.clickSlot(container.syncId, slotNumber, hotbarSlot, SlotActionType.SWAP, mc.player); @@ -1079,7 +1076,7 @@ public static void switchToPickedBlock() return; } - double reach = mc.interactionManager.getReachDistance(); + double reach = mc.player.getBlockInteractionRange(); boolean isCreative = player.isCreative(); HitResult trace = player.raycast(reach, mc.getTickDelta(), false); @@ -1124,38 +1121,4 @@ public static void switchToPickedBlock() } } } - - public static boolean cleanUpShulkerBoxNBT(ItemStack stack) - { - boolean changed = false; - NbtCompound nbt = stack.getNbt(); - - if (nbt != null) - { - if (nbt.contains("BlockEntityTag", Constants.NBT.TAG_COMPOUND)) - { - NbtCompound tag = nbt.getCompound("BlockEntityTag"); - - if (tag.contains("Items", Constants.NBT.TAG_LIST) && - tag.getList("Items", Constants.NBT.TAG_COMPOUND).size() == 0) - { - tag.remove("Items"); - changed = true; - } - - if (tag.isEmpty()) - { - nbt.remove("BlockEntityTag"); - } - } - - if (nbt.isEmpty()) - { - stack.setNbt(null); - changed = true; - } - } - - return changed; - } } diff --git a/src/main/java/org/thinkingstudio/tweakerge/Tweakerge.java b/src/main/java/org/thinkingstudio/tweakerge/Tweakerge.java index 6313faa..8628faf 100644 --- a/src/main/java/org/thinkingstudio/tweakerge/Tweakerge.java +++ b/src/main/java/org/thinkingstudio/tweakerge/Tweakerge.java @@ -1,19 +1,18 @@ package org.thinkingstudio.tweakerge; -import fi.dy.masa.malilib.event.InitializationHandler; -import fi.dy.masa.tweakeroo.InitHandler; import fi.dy.masa.tweakeroo.Reference; +import fi.dy.masa.tweakeroo.Tweakeroo; import fi.dy.masa.tweakeroo.gui.GuiConfigs; +import net.neoforged.api.distmarker.Dist; import net.neoforged.fml.common.Mod; import net.neoforged.fml.loading.FMLLoader; import org.thinkingstudio.mafglib.util.ForgePlatformUtils; -@Mod(Reference.MOD_ID) +@Mod(value = Reference.MOD_ID, dist = Dist.CLIENT) public class Tweakerge { public Tweakerge() { if (FMLLoader.getDist().isClient()) { - ForgePlatformUtils.getInstance().getClientModIgnoredServerOnly(); - InitializationHandler.getInstance().registerInitializationHandler(new InitHandler()); + Tweakeroo.onInitialize(); ForgePlatformUtils.getInstance().registerModConfigScreen(Reference.MOD_ID, (screen) -> { GuiConfigs gui = new GuiConfigs(); gui.setParent(screen); diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/neoforge.mods.toml similarity index 100% rename from src/main/resources/META-INF/mods.toml rename to src/main/resources/META-INF/neoforge.mods.toml diff --git a/src/main/resources/tweakerge.mixins.json b/src/main/resources/tweakerge.mixins.json index bcb63a6..b6c0d83 100644 --- a/src/main/resources/tweakerge.mixins.json +++ b/src/main/resources/tweakerge.mixins.json @@ -1,82 +1,83 @@ { - "required": true, - "package": "fi.dy.masa.tweakeroo.mixin", - "minVersion": "0.8", - "compatibilityLevel": "JAVA_17", - "client": [ - "IMixinAbstractBlock", - "IMixinAxeItem", - "IMixinChunkLightProvider", - "IMixinClientWorld", - "IMixinCommandBlockExecutor", - "IMixinAbstractHorseEntity", - "IMixinShovelItem", - "IMixinSimpleOption", - "MixinAbstractClientPlayerEntity", - "MixinAbstractInventoryScreen", - "MixinAbstractSignEditScreen", - "MixinBackgroundRenderer", - "MixinBatEntity", - "MixinBeaconBlockEntityRenderer", - "MixinBlockEntityRenderDispatcher", - "MixinBlockItem", - "MixinBossBarHud", - "MixinBuiltChunk", - "MixinChatHud", - "MixinChatScreen", - "MixinChunkBuilder_BuiltChunk", - "MixinClientBossBar", - "MixinClientCommandSource", - "MixinClientPlayerEntity", - "MixinClientPlayerInteractionManager", - "MixinClientPlayNetworkHandler", - "MixinClientWorld", - "MixinClientWorld_Properties", - "MixinCloneCommand", - "MixinCommandBlockScreen", - "MixinCreativeInventoryScreen", - "MixinDimensionEffects_Nether", - "MixinEntity", - "MixinEntityRenderDispatcher", - "MixinExplosion", - "MixinFillCommand", - "MixinGameRenderer", - "MixinHeldItemRenderer", - "MixinInGameHud", - "MixinItem", - "MixinItemEntity", - "MixinItemGroup", - "MixinItemStack", - "MixinKeyboardInput", - "MixinLightingProvider", - "MixinLivingEntity", - "MixinMinecraftClient", - "MixinMobSpawnerBlockEntityRenderer", - "MixinMobSpawnerLogic", - "MixinMouse", - "MixinNetherPortalBlock", - "MixinObserverBlock", - "MixinParticleManager", - "MixinPlayerAbilities", - "MixinPlayerEntity", - "MixinRavagerEntity", - "MixinScaffoldingBlock", - "MixinSculkSensor", - "MixinServerPlayNetworkHandler", - "MixinShulkerBoxBlock", - "MixinSignBlockEntity", - "MixinSlimeBlock", - "MixinStructureBlockBlockEntity", - "MixinTeleportSpectatorMenu", - "MixinThreadedAnvilChunkStorage", - "MixinTradeOffer", - "MixinUpdateStructureBlockC2SPacket", - "MixinWindow", - "MixinWorld", - "MixinWorldRenderer" - ], - "mixinPriority": 990, - "injectors": { - "defaultRequire": 0 + "required": true, + "package": "fi.dy.masa.tweakeroo.mixin", + "minVersion": "0.8", + "compatibilityLevel": "JAVA_17", + "client": [ + "IMixinAbstractBlock", + "IMixinAbstractHorseEntity", + "IMixinAxeItem", + "IMixinChunkLightProvider", + "IMixinClientWorld", + "IMixinCommandBlockExecutor", + "IMixinShovelItem", + "IMixinSimpleOption", + "MixinAbstractClientPlayerEntity", + "MixinAbstractInventoryScreen", + "MixinAbstractSignEditScreen", + "MixinBackgroundRenderer", + "MixinBatEntity", + "MixinBeaconBlockEntityRenderer", + "MixinBlockEntityRenderDispatcher", + "MixinBlockItem", + "MixinBossBarHud", + "MixinBuiltChunk", + "MixinChatHud", + "MixinChatScreen", + "MixinChunkBuilder_BuiltChunk", + "MixinClientBossBar", + "MixinClientCommandSource", + "MixinClientPlayerEntity", + "MixinClientPlayerInteractionManager", + "MixinClientPlayNetworkHandler", + "MixinClientWorld", + "MixinClientWorld_Properties", + "MixinCloneCommand", + "MixinCommandBlockScreen", + "MixinCreativeInventoryScreen", + "MixinDimensionEffects_Nether", + "MixinEntity", + "MixinEntityRenderDispatcher", + "MixinExplosion", + "MixinFillCommand", + "MixinGameRenderer", + "MixinGameRenderer_ViewBob", + "MixinHeldItemRenderer", + "MixinInGameHud", + "MixinItem", + "MixinItemEntity", + "MixinItemGroup", + "MixinItemStack", + "MixinKeyboardInput", + "MixinLightingProvider", + "MixinLivingEntity", + "MixinMinecraftClient", + "MixinMobSpawnerBlockEntityRenderer", + "MixinMobSpawnerLogic", + "MixinMouse", + "MixinNetherPortalBlock", + "MixinObserverBlock", + "MixinParticleManager", + "MixinPlayerAbilities", + "MixinPlayerEntity", + "MixinRavagerEntity", + "MixinScaffoldingBlock", + "MixinSculkSensor", + "MixinServerPlayNetworkHandler", + "MixinShulkerBoxBlock", + "MixinSignBlockEntity", + "MixinSlimeBlock", + "MixinStructureBlockBlockEntity", + "MixinTeleportSpectatorMenu", + "MixinThreadedAnvilChunkStorage", + "MixinTradeOffer", + "MixinUpdateStructureBlockC2SPacket", + "MixinWindow", + "MixinWorld", + "MixinWorldRenderer" + ], + "mixinPriority": 990, + "injectors": { + "defaultRequire": 0 } }