Skip to content

Commit

Permalink
⬆️ Minecraft 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
NatoBoram committed Jun 29, 2024
1 parent 4950371 commit 35e54bb
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 95 deletions.
6 changes: 3 additions & 3 deletions .minepkg-lock.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
gradle 8.7
java openjdk-17
java openjdk-21
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ Switcheroo will use the least effective tool that's still effective to break blo

## Installation

[![cloth-config2](https://img.shields.io/badge/Cloth%20Config%20API-11.1.118-9cff55)](https://github.com/shedaniel/cloth-config)
[![fabric](https://img.shields.io/badge/Fabric%20API-0.92.0-dbd0b4)](https://github.com/FabricMC/fabric)
[![modmenu](https://img.shields.io/badge/Mod%20Menu-7.2.2-134bff)](https://github.com/TerraformersMC/ModMenu)
[![cloth-config2](https://img.shields.io/badge/Cloth%20Config%20API-15.0.127-9cff55)](https://github.com/shedaniel/cloth-config)
[![fabric](https://img.shields.io/badge/Fabric%20API-0.100.1-dbd0b4)](https://github.com/FabricMC/fabric)
[![modmenu](https://img.shields.io/badge/Mod%20Menu-11.0.0--rc.4-134bff)](https://github.com/TerraformersMC/ModMenu)

Downloads are available in [Releases](https://github.com/NatoBoram/switcheroo/releases). You can also test development builds by downloading them form the [Actions](https://github.com/NatoBoram/switcheroo/actions/workflows/gradle.yaml?query=branch%3Amain).

Expand All @@ -52,7 +52,7 @@ Downloads are available in [Releases](https://github.com/NatoBoram/switcheroo/re

## Contributing

Requires Java 17.
Requires Java 21.

### Developing

Expand Down
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.10
loader_version=0.15.9
minecraft_version=1.21
yarn_mappings=1.21+build.2
loader_version=0.15.11

#Fabric api
fabric_version=0.92.0+1.20.1
# Fabric API
fabric_version=0.100.1+1.21

# Mod Properties
mod_version=1.0.13
maven_group=com.natoboram
archives_base_name=switcheroo

# Dependencies
clothconfig_version=11.1.118
modmenu_version=7.2.2
clothconfig_version=15.0.127
modmenu_version=11.0.0-rc.4
10 changes: 5 additions & 5 deletions minepkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ author = "Nato Boram"

# These are global requirements
[requirements]
minecraft = ">=1.20.1"
fabricLoader = ">=0.15.9"
minecraft = ">=1.21"
fabricLoader = ">=0.15.11"

[dependencies]
cloth-config = ">=11.1.118+mpkg.1"
fabric = ">=0.92.0+1.20.1"
modmenu = ">=7.2.2+mpkg.1"
cloth-config = ">=15.0.127+mpkg.1"
fabric = ">=0.92.0+1.21"
modmenu = ">=11.0.0-rc.4+mpkg.1"

[dev]
buildCommand = "./gradlew build"
29 changes: 20 additions & 9 deletions src/main/java/com/natoboram/switcheroo/BlockSwitch.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.minecraft.block.SugarCaneBlock;
import net.minecraft.block.VineBlock;
import net.minecraft.client.MinecraftClient;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -33,7 +34,11 @@
import net.minecraft.item.ItemStack;
import net.minecraft.item.ShearsItem;
import net.minecraft.item.SwordItem;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -72,6 +77,11 @@ public ActionResult interact(final PlayerEntity player, final World world, final
return ActionResult.PASS;
}

// Cache enchantments
final DynamicRegistryManager manager = world.getRegistryManager();
final Registry<Enchantment> enchantments = manager.get(RegistryKeys.ENCHANTMENT);
final RegistryEntry<Enchantment> silkTouchEntry = enchantments.getEntry(Enchantments.SILK_TOUCH).get();

// Use CROP_SWITCH to handle crops
if (world.getBlockState(pos).getBlock() instanceof CropBlock && config.enableCrop)
return CROP_SWITCH.interact(player, world, hand, pos, direction);
Expand Down Expand Up @@ -116,21 +126,21 @@ && axeFilter(block, stack.getItem()))
// If there's no effective tools, check for the mining speed
if (tools.isEmpty())
for (final ItemStack stack : inventory.main)
if (ItemStackUtil.getMiningSpeedMultiplier(stack, blockState) > 1.0F
if (ItemStackUtil.getMiningSpeedMultiplier(stack, blockState, world) > 1.0F
&& !(stack.getItem() instanceof SwordItem) && axeFilter(block, stack.getItem()))
tools.add(stack);

// Add Silk Touch
if (tools.isEmpty() && preferSilkTouch(block, config))
for (final ItemStack stack : inventory.main)
if (EnchantmentHelper.getLevel(Enchantments.SILK_TOUCH, stack) > 0)
if (EnchantmentHelper.getLevel(silkTouchEntry, stack) > 0)
tools.add(stack);
}

// Keep Silk Touch
if (preferSilkTouch(block, config)
&& tools.stream().anyMatch(tool -> EnchantmentHelper.getLevel(Enchantments.SILK_TOUCH, tool) > 0))
tools.removeIf(tool -> EnchantmentHelper.getLevel(Enchantments.SILK_TOUCH, tool) <= 0);
&& tools.stream().anyMatch(tool -> EnchantmentHelper.getLevel(silkTouchEntry, tool) > 0))
tools.removeIf(tool -> EnchantmentHelper.getLevel(silkTouchEntry, tool) <= 0);

// Filters enchanted items with low durability
ItemStackUtil.removeDamagedEnchantedItems(tools, config);
Expand All @@ -141,16 +151,17 @@ && axeFilter(block, stack.getItem()))

// Get best or worst tool
if (CLIENT.options.sprintKey.isPressed() || config.alwaysFastest)
ItemStackUtil.keepFastestTools(tools, blockState);
ItemStackUtil.keepFastestTools(tools, blockState, world);
else
ItemStackUtil.keepSlowestTools(tools, blockState);
ItemStackUtil.keepSlowestTools(tools, blockState, world);

final ItemStack mainHand = player.getMainHandStack();
final double mainHandSpeed = ItemStackUtil.getMiningSpeedMultiplier(mainHand, blockState);
final double mainHandSpeed = ItemStackUtil.getMiningSpeedMultiplier(mainHand, blockState, world);

// Stop if there's already a valid item in hand
if (tools.stream().anyMatch(stack -> mainHandSpeed == ItemStackUtil.getMiningSpeedMultiplier(stack, blockState)
&& ItemStack.areItemsEqual(stack, mainHand))) {
if (tools.stream()
.anyMatch(stack -> mainHandSpeed == ItemStackUtil.getMiningSpeedMultiplier(stack, blockState, world)
&& ItemStack.areItemsEqual(stack, mainHand))) {
if (config.debug)
LOGGER.info("There's already a " + mainHand.getItem() + " in hand.");
return ActionResult.PASS;
Expand Down
42 changes: 24 additions & 18 deletions src/main/java/com/natoboram/switcheroo/EntitySwitch.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package com.natoboram.switcheroo;

import static com.natoboram.switcheroo.ItemStackUtil.getAttackDamage;
import static com.natoboram.switcheroo.ItemStackUtil.getDps;
import static com.natoboram.switcheroo.ItemStackUtil.getMaxAttackDamage;
import static com.natoboram.switcheroo.ItemStackUtil.getMaxDps;
import static com.natoboram.switcheroo.ItemStackUtil.keepMostAttackDamage;
import static com.natoboram.switcheroo.ItemStackUtil.keepMostDamagedItems;
import static com.natoboram.switcheroo.ItemStackUtil.keepMostDps;
import static com.natoboram.switcheroo.ItemStackUtil.removeDamagedEnchantedItems;

import java.util.ArrayList;

import org.apache.logging.log4j.LogManager;
Expand All @@ -12,7 +21,6 @@
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityGroup;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
Expand Down Expand Up @@ -68,36 +76,34 @@ public ActionResult interact(final PlayerEntity player, final World world, final
}

// Filters enchanted items with low durability
ItemStackUtil.removeDamagedEnchantedItems(weapons, config);
removeDamagedEnchantedItems(weapons, config);

// Safety before launching streams
if (weapons.isEmpty())
return ActionResult.PASS;

final EntityGroup entityGroup = livingEntity.getGroup();

// Use max AD on players and max DPS on mobs
if (entity instanceof PlayerEntity) {

// Stop if there's already a max ad weapon in hand
final double maxAd = ItemStackUtil.getMaxAttackDamage(weapons, entityGroup);
final double currentAd = ItemStackUtil.getAttackDamage(CLIENT.player.getMainHandStack(), entityGroup);
final double maxAd = getMaxAttackDamage(weapons, entity, world);
final double currentAd = getAttackDamage(CLIENT.player.getMainHandStack(), entity, world);
if (currentAd >= maxAd || weapons.isEmpty())
return ActionResult.PASS;

ItemStackUtil.keepMostAttackDamage(weapons, entityGroup, maxAd);
keepMostAttackDamage(weapons, entity, maxAd, world);
} else {

// Stop if there's already a max dps weapon in hand
final double maxDps = ItemStackUtil.getMaxDps(weapons, entityGroup);
final double currentDps = ItemStackUtil.getDps(CLIENT.player.getMainHandStack(), entityGroup);
final double maxDps = getMaxDps(weapons, entity, world);
final double currentDps = getDps(CLIENT.player.getMainHandStack(), entity, world);
if (currentDps >= maxDps || weapons.isEmpty())
return ActionResult.PASS;

ItemStackUtil.keepMostDps(weapons, entityGroup, maxDps);
keepMostDps(weapons, entity, maxDps, world);
}

ItemStackUtil.keepMostDamagedItems(weapons);
keepMostDamagedItems(weapons);

if (!weapons.isEmpty())
Switch.switcheroo(player, weapons.get(0), config);
Expand All @@ -110,13 +116,13 @@ private boolean isBlacklisted(final LivingEntity livingEntity, final SwitcherooC

for (final String blacklisted : blacklist) {
switch (blacklisted.split(":").length) {
case 1:
if (id.toString().equals("minecraft:" + blacklisted))
return true;
default:
case 2:
if (id.toString().equals(blacklisted))
return true;
case 1:
if (id.toString().equals("minecraft:" + blacklisted))
return true;
default:
case 2:
if (id.toString().equals(blacklisted))
return true;
}
}
return false;
Expand Down
Loading

0 comments on commit 35e54bb

Please sign in to comment.