From 9582eabc549e01478efeca3a03020cce3cd6a671 Mon Sep 17 00:00:00 2001 From: Sakura Ryoko Date: Wed, 8 Jan 2025 23:20:15 -0500 Subject: [PATCH] Port to SNAP --- build.gradle | 32 ++--- gradle.properties | 14 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../dy/masa/tweakeroo/data/DataManager.java | 2 +- .../masa/tweakeroo/data/ServerDataSyncer.java | 2 +- .../dy/masa/tweakeroo/event/InputHandler.java | 19 +-- .../masa/tweakeroo/event/RenderHandler.java | 2 +- .../mixin/MixinClientCommandSource.java | 5 +- .../MixinClientCommonNetworkHandler.java | 2 +- .../mixin/MixinClientPlayNetworkHandler.java | 2 +- .../mixin/MixinClientPlayerEntity.java | 3 +- .../renderer/InventoryOverlayHandler.java | 2 +- .../tweakeroo/tweaks/PlacementTweaks.java | 47 +++---- .../masa/tweakeroo/util/InventoryUtils.java | 130 ++++++++++++------ .../fi/dy/masa/tweakeroo/util/MiscUtils.java | 25 +++- src/main/resources/fabric.mod.json | 4 +- 16 files changed, 172 insertions(+), 121 deletions(-) diff --git a/build.gradle b/build.gradle index 31b9b16ba..3bbb44893 100644 --- a/build.gradle +++ b/build.gradle @@ -1,25 +1,11 @@ -import org.gradle.api.tasks.bundling.AbstractArchiveTask - plugins { id 'fabric-loom' version '1.9-SNAPSHOT' } -//sourceCompatibility = JavaVersion.VERSION_21 -//targetCompatibility = JavaVersion.VERSION_21 - repositories { - //maven { url 'https://masa.dy.fi/maven' } - maven { - url 'https://masa.dy.fi/maven' - mavenLocal() - } - //maven { url 'https://maven.terraformersmc.com/releases/' } - maven { - url 'https://maven.terraformersmc.com/releases/' - mavenLocal() - } - maven { url 'https://jitpack.io' } - flatDir { dirs 'libs' } + maven { url = 'https://masa.dy.fi/maven' } + maven { url = 'https://maven.terraformersmc.com/releases/' } + maven { url = 'https://jitpack.io' } } dependencies { @@ -37,12 +23,14 @@ dependencies { modCompileOnly "com.terraformersmc:modmenu:${project.mod_menu_version}" } -group = project.group + "." + project.mod_id -base.archivesName = project.mod_file_name + '-' + project.minecraft_version_out -version = project.mod_version +base { + group = project.group + "." + project.mod_id + archivesName = project.mod_file_name + '-' + project.minecraft_version_out + version = project.mod_version -if (version.endsWith('-dev')) { - version += "." + new Date().format('yyyyMMdd.HHmmss') + if (version.endsWith('-dev')) { + version += "." + new Date().format('yyyyMMdd.HHmmss') + } } processResources { diff --git a/gradle.properties b/gradle.properties index a7d9a4b5a..7af9b109f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,16 +9,16 @@ author = masa mod_file_name = tweakeroo-fabric # Current mod version -mod_version = 0.23.1 +mod_version = SNAP # Required malilib version -malilib_version = 1.21.4-0.23.1 +malilib_version = e6e1b721d6 # Minecraft, Fabric Loader and API and mappings versions -minecraft_version_out = 1.21.4 -minecraft_version = 1.21.4 -mappings_version = 1.21.4+build.1 +minecraft_version_out = 25w02a +minecraft_version = 25w02a +mappings_version = 25w02a+build.5 -fabric_loader_version = 0.16.9 +fabric_loader_version = 0.16.10 mod_menu_version = 13.0.0-beta.1 -# fabric_api_version = 0.110.5+1.21.4 +# fabric_api_version = 0.114.1+1.21.4 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e2847c820..cea7a793a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/src/main/java/fi/dy/masa/tweakeroo/data/DataManager.java b/src/main/java/fi/dy/masa/tweakeroo/data/DataManager.java index 78dcf92d9..02c5aee96 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/data/DataManager.java +++ b/src/main/java/fi/dy/masa/tweakeroo/data/DataManager.java @@ -16,7 +16,7 @@ public class DataManager implements IServerListener private boolean hasCarpetServer; private boolean hasServuxServer; public static final Identifier CARPET_HELLO = Identifier.of("carpet", "hello"); - public static final Identifier SERVUX_ENTITY_DATA = Identifier.of("servux", "entity_data"); + public static final Identifier SERVUX_LITEMATIC_DATA = Identifier.of("servux", "litematics"); //private IntegratedServer integratedServer; //private DynamicRegistryManager.Immutable registryManager = DynamicRegistryManager.EMPTY; private boolean hasIntegratedServer; diff --git a/src/main/java/fi/dy/masa/tweakeroo/data/ServerDataSyncer.java b/src/main/java/fi/dy/masa/tweakeroo/data/ServerDataSyncer.java index 6cfc94b45..4209e0785 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/data/ServerDataSyncer.java +++ b/src/main/java/fi/dy/masa/tweakeroo/data/ServerDataSyncer.java @@ -38,9 +38,9 @@ import fi.dy.masa.malilib.interfaces.IDataSyncer; import fi.dy.masa.malilib.network.ClientPlayHandler; import fi.dy.masa.malilib.network.IPluginClientPlayHandler; -import fi.dy.masa.malilib.util.Constants; import fi.dy.masa.malilib.util.InventoryUtils; import fi.dy.masa.malilib.util.WorldUtils; +import fi.dy.masa.malilib.util.data.Constants; import fi.dy.masa.malilib.util.nbt.NbtKeys; import fi.dy.masa.tweakeroo.Reference; import fi.dy.masa.tweakeroo.Tweakeroo; 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 a9b629304..0b71c7926 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/event/InputHandler.java +++ b/src/main/java/fi/dy/masa/tweakeroo/event/InputHandler.java @@ -334,21 +334,22 @@ else if (mc.options.rightKey.matchesKey(eventKey, scanCode)) } } - public void handleMovementKeys(Input m) + public void handleMovementKeys(Input input) { GameOptions settings = MinecraftClient.getInstance().options; + PlayerInput m = input.playerInput; if (settings.leftKey.isPressed() && settings.rightKey.isPressed()) { if (this.lastSidewaysInput == LeftRight.LEFT) { - m.movementSideways = 1; - m.playerInput = new PlayerInput(m.playerInput.forward(), m.playerInput.backward(), true, false, m.playerInput.jump(), m.playerInput.sneak(), m.playerInput.sprint()); + //m.movementSideways = 1; + input.playerInput = new PlayerInput(m.forward(), m.backward(), true, false, m.jump(), m.sneak(), m.sprint()); } else if (this.lastSidewaysInput == LeftRight.RIGHT) { - m.movementSideways = -1; - m.playerInput = new PlayerInput(m.playerInput.forward(), m.playerInput.backward(), false, true, m.playerInput.jump(), m.playerInput.sneak(), m.playerInput.sprint()); + //m.movementSideways = -1; + input.playerInput = new PlayerInput(m.forward(), m.backward(), false, true, m.jump(), m.sneak(), m.sprint()); } } @@ -356,13 +357,13 @@ else if (this.lastSidewaysInput == LeftRight.RIGHT) { if (this.lastForwardInput == ForwardBack.FORWARD) { - m.movementForward = 1; - m.playerInput = new PlayerInput(true, false, m.playerInput.left(), m.playerInput.right(), m.playerInput.jump(), m.playerInput.sneak(), m.playerInput.sprint()); + //m.movementForward = 1; + input.playerInput = new PlayerInput(true, false, m.left(), m.right(), m.jump(), m.sneak(), m.sprint()); } else if (this.lastForwardInput == ForwardBack.BACK) { - m.movementForward = -1; - m.playerInput = new PlayerInput(false, true, m.playerInput.left(), m.playerInput.right(), m.playerInput.jump(), m.playerInput.sneak(), m.playerInput.sprint()); + //m.movementForward = -1; + input.playerInput = new PlayerInput(false, true, m.left(), m.right(), m.jump(), m.sneak(), m.sprint()); } } } 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 c8fc48ef4..a1c859406 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/event/RenderHandler.java +++ b/src/main/java/fi/dy/masa/tweakeroo/event/RenderHandler.java @@ -26,9 +26,9 @@ import fi.dy.masa.malilib.gui.GuiBase; 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.malilib.util.WorldUtils; +import fi.dy.masa.malilib.util.data.Color4f; import fi.dy.masa.malilib.util.nbt.NbtKeys; import fi.dy.masa.tweakeroo.config.Configs; import fi.dy.masa.tweakeroo.config.FeatureToggle; diff --git a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinClientCommandSource.java b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinClientCommandSource.java index bdff5c479..290649331 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinClientCommandSource.java +++ b/src/main/java/fi/dy/masa/tweakeroo/mixin/MixinClientCommandSource.java @@ -13,6 +13,8 @@ import net.minecraft.command.CommandSource; import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.BlockPos; + +import fi.dy.masa.malilib.util.position.PositionUtils; import fi.dy.masa.tweakeroo.config.FeatureToggle; @Mixin(ClientCommandSource.class) @@ -26,7 +28,8 @@ private void onGetBlockPositionSuggestions(CallbackInfoReturnable= 0.8F && + //! this.isSprinting() && ! this.isUsingItem() && this.input.movementForward >= 0.8F && + ! this.isSprinting() && ! this.isUsingItem() && this.input.hasForwardMovement() && (this.getHungerManager().getFoodLevel() > 6.0F || this.getAbilities().allowFlying) && ! this.hasStatusEffect(StatusEffects.BLINDNESS) && ! this.isTouchingWater()) { diff --git a/src/main/java/fi/dy/masa/tweakeroo/renderer/InventoryOverlayHandler.java b/src/main/java/fi/dy/masa/tweakeroo/renderer/InventoryOverlayHandler.java index 20b299137..bf5eda15c 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/renderer/InventoryOverlayHandler.java +++ b/src/main/java/fi/dy/masa/tweakeroo/renderer/InventoryOverlayHandler.java @@ -34,10 +34,10 @@ import fi.dy.masa.malilib.interfaces.IDataSyncer; import fi.dy.masa.malilib.interfaces.IInventoryOverlayHandler; import fi.dy.masa.malilib.render.InventoryOverlay; -import fi.dy.masa.malilib.util.Constants; import fi.dy.masa.malilib.util.EntityUtils; import fi.dy.masa.malilib.util.InventoryUtils; import fi.dy.masa.malilib.util.WorldUtils; +import fi.dy.masa.malilib.util.data.Constants; import fi.dy.masa.malilib.util.nbt.NbtBlockUtils; import fi.dy.masa.malilib.util.nbt.NbtKeys; import fi.dy.masa.tweakeroo.Reference; 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 34dcee8c1..456189825 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/tweaks/PlacementTweaks.java +++ b/src/main/java/fi/dy/masa/tweakeroo/tweaks/PlacementTweaks.java @@ -1,18 +1,7 @@ package fi.dy.masa.tweakeroo.tweaks; import java.util.Optional; - -import fi.dy.masa.malilib.gui.Message; -import fi.dy.masa.malilib.util.*; -import fi.dy.masa.malilib.util.PositionUtils.HitPart; -import fi.dy.masa.malilib.util.restrictions.BlockRestriction; -import fi.dy.masa.malilib.util.restrictions.ItemRestriction; -import fi.dy.masa.tweakeroo.config.Configs; -import fi.dy.masa.tweakeroo.config.FeatureToggle; -import fi.dy.masa.tweakeroo.config.Hotkeys; -import fi.dy.masa.tweakeroo.mixin.IMixinAbstractBlock; -import fi.dy.masa.tweakeroo.util.*; -import fi.dy.masa.tweakeroo.util.InventoryUtils; +import javax.annotation.Nullable; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -36,14 +25,26 @@ import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; -import javax.annotation.Nullable; +import fi.dy.masa.malilib.gui.Message; +import fi.dy.masa.malilib.util.EquipmentUtils; +import fi.dy.masa.malilib.util.GuiUtils; +import fi.dy.masa.malilib.util.InfoUtils; +import fi.dy.masa.malilib.util.MessageOutputType; +import fi.dy.masa.malilib.util.position.PositionUtils; +import fi.dy.masa.malilib.util.restrictions.BlockRestriction; +import fi.dy.masa.malilib.util.restrictions.ItemRestriction; +import fi.dy.masa.tweakeroo.config.Configs; +import fi.dy.masa.tweakeroo.config.FeatureToggle; +import fi.dy.masa.tweakeroo.config.Hotkeys; +import fi.dy.masa.tweakeroo.mixin.IMixinAbstractBlock; +import fi.dy.masa.tweakeroo.util.*; public class PlacementTweaks { private static BlockPos posFirst = null; private static BlockPos posFirstBreaking = null; private static BlockPos posLast = null; - private static HitPart hitPartFirst = null; + private static PositionUtils.HitPart hitPartFirst = null; private static Hand handFirst = Hand.MAIN_HAND; private static Vec3d hitVecFirst = null; private static Direction sideFirst = null; @@ -178,7 +179,7 @@ private static void onAttackTick(MinecraftClient mc) if (FeatureToggle.TWEAK_FAST_LEFT_CLICK.getBooleanValue()) { if (mc.player.getAbilities().creativeMode || - (Configs.Generic.FAST_LEFT_CLICK_ALLOW_TOOLS.getBooleanValue() || (mc.player.getMainHandStack().getItem() instanceof MiningToolItem) == false)) + (Configs.Generic.FAST_LEFT_CLICK_ALLOW_TOOLS.getBooleanValue() || (EquipmentUtils.isAnyTool(mc.player.getMainHandStack())) == false)) { final int count = Configs.Generic.FAST_LEFT_CLICK_COUNT.getIntegerValue(); @@ -330,7 +331,7 @@ public static ActionResult onProcessRightClickBlock( Direction sideIn = hitResult.getSide(); Vec3d hitVec = hitResult.getPos(); Direction playerFacingH = player.getHorizontalFacing(); - HitPart hitPart = PositionUtils.getHitPart(sideIn, playerFacingH, posIn, hitVec); + PositionUtils.HitPart hitPart = PositionUtils.getHitPart(sideIn, playerFacingH, posIn, hitVec); Direction sideRotated = getRotatedFacing(sideIn, playerFacingH, hitPart); float yaw = player.getYaw(); @@ -390,7 +391,7 @@ private static ActionResult tryPlaceBlock( float playerYaw, Vec3d hitVec, Hand hand, - HitPart hitPart, + PositionUtils.HitPart hitPart, boolean isFirstClick) { Direction side = sideIn; @@ -412,7 +413,7 @@ private static ActionResult tryPlaceBlock( posNew = isFirstClick && (rotation || offset || adjacent) ? getPlacementPositionForTargetedPosition(world, posIn, sideIn, ctx) : posIn; // Place the block into the adjacent position - if (adjacent && hitPart != null && hitPart != HitPart.CENTER) + if (adjacent && hitPart != null && hitPart != PositionUtils.HitPart.CENTER) { posNew = posNew.offset(sideRotatedIn.getOpposite()).offset(sideIn.getOpposite()); hitVec = hitVec.add(Vec3d.of(sideRotatedIn.getOpposite().getVector().add(sideIn.getOpposite().getVector()))); @@ -897,21 +898,21 @@ private static ActionResult handleFlexibleBlockPlacement( float playerYaw, Vec3d hitVec, Hand hand, - @Nullable HitPart hitPart) + @Nullable PositionUtils.HitPart hitPart) { Direction facing = Direction.fromHorizontalQuarterTurns(MathHelper.floor((playerYaw * 4.0F / 360.0F) + 0.5D) & 3); Direction facingOrig = facing; float yawOrig = player.getYaw(); - if (hitPart == HitPart.CENTER) + if (hitPart == PositionUtils.HitPart.CENTER) { facing = facing.getOpposite(); } - else if (hitPart == HitPart.LEFT) + else if (hitPart == PositionUtils.HitPart.LEFT) { facing = facing.rotateYCounterclockwise(); } - else if (hitPart == HitPart.RIGHT) + else if (hitPart == PositionUtils.HitPart.RIGHT) { facing = facing.rotateYClockwise(); } @@ -951,7 +952,7 @@ private static void clearClickedBlockInfoAttack() sideFirstBreaking = null; } - private static Direction getRotatedFacing(Direction originalSide, Direction playerFacingH, HitPart hitPart) + private static Direction getRotatedFacing(Direction originalSide, Direction playerFacingH, PositionUtils.HitPart hitPart) { if (originalSide.getAxis().isVertical()) { 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 c1cec9d9c..a7dbd7172 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/util/InventoryUtils.java +++ b/src/main/java/fi/dy/masa/tweakeroo/util/InventoryUtils.java @@ -7,6 +7,8 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.apache.commons.lang3.tuple.Pair; + import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.client.MinecraftClient; @@ -41,6 +43,7 @@ import net.minecraft.world.World; import fi.dy.masa.malilib.gui.Message; +import fi.dy.masa.malilib.util.EquipmentUtils; import fi.dy.masa.malilib.util.GuiUtils; import fi.dy.masa.malilib.util.InfoUtils; import fi.dy.masa.tweakeroo.Tweakeroo; @@ -474,8 +477,9 @@ private static boolean isBetterWeaponAndHasDurability(ItemStack testedStack, Ite return hasEnoughDurability(testedStack) && isBetterWeapon(testedStack, previousTool, entity); } - private static float getBaseAttackDamage(ItemStack stack) + private static double getBaseAttackDamage(ItemStack stack) { + /* Item item = stack.getItem(); if ((item instanceof SwordItem) == false && (item instanceof MiningToolItem) == false) return 0F; @@ -496,6 +500,18 @@ private static float getBaseAttackDamage(ItemStack stack) } return 0F; + */ + + Pair pair = EquipmentUtils.getDamageAndSpeedAttributes(stack); + + if (pair.getLeft() > 0) + { + return pair.getLeft(); + } + else + { + return 0; + } } protected static boolean matchesWeaponMapping(ItemStack stack, Entity entity) @@ -535,6 +551,7 @@ public static void trySwitchToEffectiveTool(BlockPos pos) } } + /* public static int getEnchantmentLevel(ItemStack stack, @Nonnull RegistryKey enchantment) { ItemEnchantmentsComponent enchants = stack.getEnchantments(); @@ -554,6 +571,7 @@ public static int getEnchantmentLevel(ItemStack stack, @Nonnull RegistryKey 0 && - getEnchantmentLevel(previousTool, Enchantments.SILK_TOUCH) == -1 && + if (EquipmentUtils.getEnchantmentLevel(testedStack, Enchantments.SILK_TOUCH) > 0 && + EquipmentUtils.getEnchantmentLevel(previousTool, Enchantments.SILK_TOUCH) == -1 && testedStack.isSuitableFor(state)) { return true; @@ -625,10 +656,10 @@ private static boolean hasSameOrBetterToolEnchantments(ItemStack testedStack, It int count = 0; // Core Tool Enchants - count += hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.MENDING); - count += hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.UNBREAKING); - count += hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.EFFICIENCY); - count += hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.FORTUNE); + count += EquipmentUtils.hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.MENDING); + count += EquipmentUtils.hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.UNBREAKING); + count += EquipmentUtils.hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.EFFICIENCY); + count += EquipmentUtils.hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.FORTUNE); return count >= 0; } @@ -638,47 +669,50 @@ private static boolean hasSameOrBetterWeaponEnchantments(ItemStack testedStack, int count = 0; // Core Weapon Enchantments - count += hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.MENDING); - count += hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.UNBREAKING); - count += hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.LOOTING); + count += EquipmentUtils.hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.MENDING); + count += EquipmentUtils.hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.UNBREAKING); + count += EquipmentUtils.hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.LOOTING); // Damage Dealing - count += hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.SHARPNESS); - count += hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.SMITE); - count += hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.BANE_OF_ARTHROPODS); - count += hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.POWER); - count += hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.IMPALING); - count += hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.DENSITY); + count += EquipmentUtils.hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.SHARPNESS); + count += EquipmentUtils.hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.SMITE); + count += EquipmentUtils.hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.BANE_OF_ARTHROPODS); + count += EquipmentUtils.hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.POWER); + count += EquipmentUtils.hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.IMPALING); + count += EquipmentUtils.hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.DENSITY); // Support - count += hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.SWEEPING_EDGE); - count += hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.FIRE_ASPECT); - count += hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.PUNCH); - count += hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.INFINITY); - count += hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.FLAME); - count += hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.MULTISHOT); - count += hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.QUICK_CHARGE); - count += hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.PIERCING); - count += hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.RIPTIDE); - count += hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.LOYALTY); - count += hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.CHANNELING); - count += hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.BREACH); + count += EquipmentUtils.hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.SWEEPING_EDGE); + count += EquipmentUtils.hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.FIRE_ASPECT); + count += EquipmentUtils.hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.PUNCH); + count += EquipmentUtils.hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.INFINITY); + count += EquipmentUtils.hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.FLAME); + count += EquipmentUtils.hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.MULTISHOT); + count += EquipmentUtils.hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.QUICK_CHARGE); + count += EquipmentUtils.hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.PIERCING); + count += EquipmentUtils.hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.RIPTIDE); + count += EquipmentUtils.hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.LOYALTY); + count += EquipmentUtils.hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.CHANNELING); + count += EquipmentUtils.hasSameOrBetterEnchantment(testedStack, previousTool, Enchantments.BREACH); return count >= 0; } + /* private static int hasSameOrBetterEnchantment(ItemStack testedStack, ItemStack previous, RegistryKey enchantment) { - return getEnchantmentLevel(testedStack, enchantment) - getEnchantmentLevel(previous, enchantment); + return EquipmentUtils.getEnchantmentLevel(testedStack, enchantment) - EquipmentUtils.getEnchantmentLevel(previous, enchantment); } + */ protected static float getBaseBlockBreakingSpeed(ItemStack stack, BlockState state) { - float speed = stack.getMiningSpeedMultiplier(state); + //float speed = stack.getMiningSpeedMultiplier(state); + float speed = EquipmentUtils.getMiningSpeed(stack, state); if (speed > 1.0f) { - int effLevel = getEnchantmentLevel(stack, Enchantments.EFFICIENCY); + int effLevel = EquipmentUtils.getEnchantmentLevel(stack, Enchantments.EFFICIENCY); if (effLevel > 0) { @@ -850,7 +884,7 @@ private static void repairModeHandleSlot(PlayerEntity player, EquipmentSlot type if (stack.isEmpty() == false && (stack.isDamageable() == false || stack.isDamaged() == false || - getEnchantmentLevel(stack, Enchantments.MENDING) <= 0)) + EquipmentUtils.getEnchantmentLevel(stack, Enchantments.MENDING) <= 0)) { Slot slot = player.currentScreenHandler.getSlot(slotNum); int slotRepairableItem = findRepairableItemNotInRepairableSlot(slot, player); @@ -879,7 +913,7 @@ private static int findRepairableItemNotInRepairableSlot(Slot targetSlot, Player // Don't take items from the current hotbar slot if ((slot.id - 36) != player.getInventory().selectedSlot && stack.isDamageable() && stack.isDamaged() && targetSlot.canInsert(stack) && - getEnchantmentLevel(stack, Enchantments.MENDING) > 0) + EquipmentUtils.getEnchantmentLevel(stack, Enchantments.MENDING) > 0) { return slot.id; } @@ -905,11 +939,11 @@ public static void equipBestElytra(PlayerEntity player) int targetSlot = findSlotWithBestItemMatch(container, (testedStack, previousBestMatch) -> { if (!filter.test(testedStack)) return false; if (!filter.test(previousBestMatch)) return true; - if (getEnchantmentLevel(testedStack, Enchantments.UNBREAKING) > getEnchantmentLevel(previousBestMatch, Enchantments.UNBREAKING)) + if (EquipmentUtils.getEnchantmentLevel(testedStack, Enchantments.UNBREAKING) > EquipmentUtils.getEnchantmentLevel(previousBestMatch, Enchantments.UNBREAKING)) { return true; } - if (getEnchantmentLevel(testedStack, Enchantments.UNBREAKING) < getEnchantmentLevel(previousBestMatch, Enchantments.UNBREAKING)) + if (EquipmentUtils.getEnchantmentLevel(testedStack, Enchantments.UNBREAKING) < EquipmentUtils.getEnchantmentLevel(previousBestMatch, Enchantments.UNBREAKING)) { return false; } @@ -932,9 +966,10 @@ public static void swapElytraAndChestPlate(@Nullable PlayerEntity player) ScreenHandler container = player.currentScreenHandler; ItemStack currentStack = player.getEquippedStack(EquipmentSlot.CHEST); - Predicate stackFilterChestPlate = (s) -> s.getItem() instanceof ArmorItem && + Predicate stackFilterChestPlate = (s) -> EquipmentUtils.matchArmorSlot(s, EquipmentSlot.CHEST); + //s.getItem() instanceof ArmorItem && //((ArmorItem) s.getItem()).getSlotType() == EquipmentSlot.CHEST; - s.get(DataComponentTypes.EQUIPPABLE).slot() == EquipmentSlot.CHEST; + //s.get(DataComponentTypes.EQUIPPABLE).slot() == EquipmentSlot.CHEST; if (currentStack.isEmpty() || stackFilterChestPlate.test(currentStack)) { @@ -955,7 +990,7 @@ public static void swapElytraAndChestPlate(@Nullable PlayerEntity player) { return false; } - return getEnchantmentLevel(previousBestMatch, Enchantments.PROTECTION) <= getEnchantmentLevel(testedStack, Enchantments.PROTECTION); + return EquipmentUtils.getEnchantmentLevel(previousBestMatch, Enchantments.PROTECTION) <= EquipmentUtils.getEnchantmentLevel(testedStack, Enchantments.PROTECTION); }, UniformIntProvider.create(9, container.slots.size() - 1)); if (targetSlot >= 0) @@ -1132,10 +1167,16 @@ private static int getUsableHotbarSlotForTool(int currentHotbarSlot, Collection< return currentHotbarSlot; } + /* if ((stack.getItem() instanceof MiningToolItem) == false) { nonTool = currentHotbarSlot; } + */ + if (EquipmentUtils.isRegularTool(stack) == false) + { + nonTool = currentHotbarSlot; + } } for (int hotbarSlot : validSlots) @@ -1147,7 +1188,8 @@ private static int getUsableHotbarSlotForTool(int currentHotbarSlot, Collection< return hotbarSlot; } - if (nonTool == -1 && (stack.getItem() instanceof MiningToolItem) == false) + //if (nonTool == -1 && (stack.getItem() instanceof MiningToolItem) == false) + if (nonTool == -1 && EquipmentUtils.isRegularTool(stack) == false) { nonTool = hotbarSlot; } @@ -1183,18 +1225,18 @@ private static int findSlotWithSuitableReplacementToolWithDurabilityLeft(ScreenH private static boolean hasSameIshEnchantments(ItemStack stackReference, ItemStack stack) { - int level = getEnchantmentLevel(stackReference, Enchantments.SILK_TOUCH); + int level = EquipmentUtils.getEnchantmentLevel(stackReference, Enchantments.SILK_TOUCH); if (level > 0) { - return getEnchantmentLevel(stack, Enchantments.SILK_TOUCH) >= level; + return EquipmentUtils.getEnchantmentLevel(stack, Enchantments.SILK_TOUCH) >= level; } - level = getEnchantmentLevel(stackReference, Enchantments.FORTUNE); + level = EquipmentUtils.getEnchantmentLevel(stackReference, Enchantments.FORTUNE); if (level > 0) { - return getEnchantmentLevel(stack, Enchantments.FORTUNE) >= level; + return EquipmentUtils.getEnchantmentLevel(stack, Enchantments.FORTUNE) >= level; } return true; @@ -1221,7 +1263,7 @@ private static int findSlotWithEffectiveItemWithDurabilityLeft(ScreenHandler con if (speed > 1.0f) { - int effLevel = getEnchantmentLevel(stack, Enchantments.EFFICIENCY); + int effLevel = EquipmentUtils.getEnchantmentLevel(stack, Enchantments.EFFICIENCY); if (effLevel > 0) { diff --git a/src/main/java/fi/dy/masa/tweakeroo/util/MiscUtils.java b/src/main/java/fi/dy/masa/tweakeroo/util/MiscUtils.java index 393b84257..f6987661b 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/util/MiscUtils.java +++ b/src/main/java/fi/dy/masa/tweakeroo/util/MiscUtils.java @@ -1,7 +1,5 @@ package fi.dy.masa.tweakeroo.util; -import javax.annotation.Nullable; -import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.File; import java.text.SimpleDateFormat; @@ -9,6 +7,8 @@ import java.util.function.Predicate; import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.annotation.Nullable; +import javax.imageio.ImageIO; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -17,6 +17,7 @@ import net.minecraft.block.entity.CommandBlockBlockEntity; import net.minecraft.block.entity.SignBlockEntity; import net.minecraft.block.entity.SignText; +import net.minecraft.class_10583; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.ingame.AbstractSignEditScreen; import net.minecraft.client.gui.screen.world.CustomizeFlatLevelScreen; @@ -59,8 +60,8 @@ import fi.dy.masa.malilib.gui.Message; import fi.dy.masa.malilib.util.FileUtils; import fi.dy.masa.malilib.util.InfoUtils; -import fi.dy.masa.malilib.util.PositionUtils; import fi.dy.masa.malilib.util.StringUtils; +import fi.dy.masa.malilib.util.position.PositionUtils; import fi.dy.masa.tweakeroo.Reference; import fi.dy.masa.tweakeroo.Tweakeroo; import fi.dy.masa.tweakeroo.config.Configs; @@ -389,8 +390,10 @@ public static void printDeathCoordinates(MinecraftClient mc) MutableText message = Text.literal(str); Style style = message.getStyle(); String coords = pos.getX() + " " + pos.getY() + " " + pos.getZ(); - style = style.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, coords)); - style = style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.literal(coords))); + //style = style.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, coords)); + //style = style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.literal(coords))); + style = style.withClickEvent(new ClickEvent.SuggestCommand(coords)); + style = style.withHoverEvent(new HoverEvent.ShowText(Text.literal(coords))); message.setStyle(style); mc.inGameHud.getChatHud().addMessage(message); Tweakeroo.logger.info(str); @@ -467,9 +470,21 @@ public static boolean commandNearbyPets(boolean sitDown) public static boolean isTameableOwnedBy(Entity entity, UUID ownerUuid) { + /* return ((entity instanceof TameableEntity) && ownerUuid.equals(((TameableEntity) entity).getOwnerUuid())) && ((TameableEntity) entity).isTamed(); + */ + + // todo new 'TamableEntityHolder<>` Generic type class is used here. + if (entity instanceof TameableEntity te) + { + LivingEntity owner = te.getOwner(); + + return owner != null && owner.getUuid().equals(ownerUuid); + } + + return false; } public static void rightClickEntity(Entity entity, MinecraftClient mc, PlayerEntity player) diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index cb749c39d..0b2e226bd 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -33,7 +33,7 @@ ], "depends": { - "minecraft": "1.21.4", - "malilib": ">=0.23.1" + "minecraft": ">1.21.4 <1.21.6", + "malilib": "SNAP" } }