Skip to content

Commit

Permalink
Merge branch 'release/1.0.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
NatoBoram committed Jun 14, 2022
2 parents a21e836 + 6e5e13c commit e215246
Show file tree
Hide file tree
Showing 16 changed files with 246 additions and 15 deletions.
6 changes: 0 additions & 6 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ release:
description: "$CI_COMMIT_MESSAGE"
assets:
links:
- name: "switcheroo-$CI_COMMIT_TAG+$MINECRAFT-dev.jar"
url: "https://gitlab.com/NatoBoram/fabric-switcheroo/-/jobs/artifacts/$CI_COMMIT_TAG/raw/build/libs/switcheroo-$VERSION+$MINECRAFT-dev.jar?job=build"
link_type: "package"
- name: "switcheroo-$CI_COMMIT_TAG+$MINECRAFT-sources-dev.jar"
url: "https://gitlab.com/NatoBoram/fabric-switcheroo/-/jobs/artifacts/$CI_COMMIT_TAG/raw/build/libs/switcheroo-$VERSION+$MINECRAFT-sources-dev.jar?job=build"
link_type: "other"
- name: "switcheroo-$CI_COMMIT_TAG+$MINECRAFT-sources.jar"
url: "https://gitlab.com/NatoBoram/fabric-switcheroo/-/jobs/artifacts/$CI_COMMIT_TAG/raw/build/libs/switcheroo-$VERSION+$MINECRAFT-sources.jar?job=build"
link_type: "other"
Expand Down
32 changes: 32 additions & 0 deletions .minepkg-lock.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,35 @@ lockfileVersion = 1
minecraft = "1.19"
fabricLoader = "0.14.7"
mapping = "1.19+build.1"

[dependencies]

[dependencies.cloth-config]
name = "cloth-config"
version = "7.0.69+mpkg.1"
type = "mod"
ipfsHash = "QmUN6Uno6umgW8KmVZyYowhFkkAb1uwggvv3jpoZEJvEwe"
Sha256 = "35fe7b75fa1541832a97e3b1a62850756965bd669ec4c06aaacd6372fa5644ae"
url = "https://api.preview.minepkg.io/v1/releases/fabric/cloth-config@7.0.69+mpkg.1/download"
provider = "minepkg"
dependend = ""

[dependencies.fabric]
name = "fabric"
version = "0.55.3+1.19.mpkg.1"
type = "mod"
ipfsHash = "QmQ9UmDMgnQLa8zUmXdH8N4pfGb9HPeNRw1JmFF9k5PbwF"
Sha256 = "25f101fd22fba2e9078e43ea0ddc3e45017d9db0aa58f857b871b973631c0a85"
url = "https://api.preview.minepkg.io/v1/releases/fabric/fabric@0.55.3+1.19.mpkg.1/download"
provider = "minepkg"
dependend = ""

[dependencies.minepkg-companion]
name = "minepkg-companion"
version = "0.5.1"
type = "mod"
ipfsHash = "QmTEXDsrpysTEUJQRzBqMn5pZZ8Jwt8kmgrmvv4yRXmq7x"
Sha256 = "1184592fc170f13cce5e3b3bcae87282ed1a743b22b4e70e8f0d6beb082032db"
url = "https://api.preview.minepkg.io/v1/releases/fabric/minepkg-companion@0.5.1/download"
provider = "minepkg"
dependend = ""
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/) and this

### Security

## [1.0.9] - 2022-06-13

### Added

* Prefer Silk Touch on certain blocks
* `/switcheroo prefer silk_touch`
* `/switcheroo prefer silk_touch add dirt_path`
* `/switcheroo prefer silk_touch remove dirt_path`
* By default, prefers Silk Touch on `bee_nest`, `beehive`, `black_stained_glass`, `black_stained_glass_pane`, `blue_ice`,
`blue_stained_glass`, `blue_stained_glass_pane`, `bookshelf`, `brain_coral`, `brain_coral_block`, `brown_mushroom_block`,
`brown_stained_glass`, `brown_stained_glass_pane`, `bubble_coral`, `bubble_coral_block`, `campfire`, `crimson_nylium`,
`cyan_stained_glass`, `cyan_stained_glass_pane`, `dirt_path`, `ender_chest`, `fire_coral`, `fire_coral_block`, `glass`,
`glass_pane`, `gray_stained_glass`, `gray_stained_glass_pane`, `green_stained_glass`, `green_stained_glass_pane`, `horn_coral`,
`horn_coral_block`, `ice`, `infested_chiseled_stone_bricks`, `infested_cobblestone`, `infested_cracked_stone_bricks`,
`infested_deepslate`, `infested_mossy_stone_bricks`, `infested_stone`, `infested_stone_bricks`, `large_amethyst_bud`,
`light_blue_stained_glass`, `light_blue_stained_glass_pane`, `light_gray_stained_glass`, `light_gray_stained_glass_pane`,
`lime_stained_glass`, `lime_stained_glass_pane`, `magenta_stained_glass`, `magenta_stained_glass_pane`, `medium_amethyst_bud`,
`mushroom_stem`, `mycelium`, `orange_stained_glass`, `orange_stained_glass_pane`, `packed_ice`, `pink_stained_glass`,
`pink_stained_glass_pane`, `purple_stained_glass`, `purple_stained_glass_pane`, `red_mushroom_block`, `red_stained_glass`,
`red_stained_glass_pane`, `sculk`, `sculk_catalyst`, `sculk_sensor`, `sculk_shrieker`, `sculk_vein`, `sea_lantern`, `small_amethyst_bud`,
`snow`, `snow_block`, `soul_campfire`, `tube_coral`, `tube_coral_block`, `turtle_egg`, `twisting_vines`, `twisting_vines_plant`,
`warped_nylium`, `weeping_vines`, `weeping_vines_plant`, `white_stained_glass`, `white_stained_glass_pane`, `yellow_stained_glass`
and `yellow_stained_glass_pane`.

## [1.0.8] - 2022-06-8

* Updated to Minecraft 1.19
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# [Switcheroo](https://gitlab.com/NatoBoram/fabric-switcheroo)

[![Latest Release](https://gitlab.com/NatoBoram/switcheroo/-/badges/release.svg)](https://gitlab.com/NatoBoram/switcheroo/-/releases)
[![Modrinth Downloads](https://img.shields.io/badge/dynamic/json?color=5da426&label=Modrinth&query=downloads&suffix=%20downloads&url=https%3A%2F%2Fapi.modrinth.com%2Fapi%2Fv1%2Fmod%2Fwq6HaMZG)](https://modrinth.com/mod/switcheroo)
[![minepkg](https://img.shields.io/badge/dynamic/json?color=ff9800&label=minepkg&query=stats.totalDownloads&suffix=%20downloads&url=https%3A%2F%2Fapi.preview.minepkg.io%2Fv1%2Fprojects%2Fswitcheroo)](https://preview.minepkg.io/projects/switcheroo)
[![CurseForge Downloads](https://img.shields.io/badge/dynamic/json?color=f16436&label=CurseForge&query=downloads.total&suffix=%20downloads&url=https%3A%2F%2Fapi.cfwidget.com%2F441128)](https://www.curseforge.com/minecraft/mc-mods/switcheroo)
Expand Down Expand Up @@ -30,6 +31,11 @@ to attack entities.
* Accessible via `/switcheroo blacklist blocks` and `/switcheroo blacklist mobs`
* Compatible with [ModMenu](https://github.com/TerraformersMC/ModMenu)
* Doesn't consider items when they have 5 durability or less
* Prefer Silk Touch on certain blocks
* `/switcheroo prefer silk_touch`
* `/switcheroo prefer silk_touch add dirt_path`
* `/switcheroo prefer silk_touch remove dirt_path`
* The Silk Touch selection is really shaky, though. Use at your own risk.

## Installation

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ loader_version=0.14.7
fabric_version=0.55.3+1.19

# Mod Properties
mod_version=1.0.8
mod_version=1.0.9
maven_group=com.natoboram
archives_base_name=switcheroo

Expand Down
2 changes: 1 addition & 1 deletion minepkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ manifestVersion = 0
type = "mod"
name = "switcheroo"
description = "Switch your currently held item for an effective item when clicking on a block."
version = "1.0.8"
version = "1.0.9"
platform = "fabric"
license = "GPL-3.0-or-later"
source = "https://gitlab.com/NatoBoram/fabric-switcheroo"
Expand Down
36 changes: 34 additions & 2 deletions src/main/java/com/natoboram/switcheroo/BlockSwitch.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import net.minecraft.block.PlantBlock;
import net.minecraft.block.SugarCaneBlock;
import net.minecraft.client.MinecraftClient;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.AxeItem;
Expand Down Expand Up @@ -66,9 +68,8 @@ public ActionResult interact(final PlayerEntity player, final World world, final
}

// Use CROP_SWITCH to handle crops
if (world.getBlockState(pos).getBlock() instanceof CropBlock && config.enableCrop) {
if (world.getBlockState(pos).getBlock() instanceof CropBlock && config.enableCrop)
return CROP_SWITCH.interact(player, world, hand, pos, direction);
}

final ArrayList<ItemStack> tools = new ArrayList<ItemStack>();
final PlayerInventory inventory = player.getInventory();
Expand Down Expand Up @@ -106,8 +107,18 @@ && axeFilter(block, stack.getItem()))
&& !(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)
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);

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

Expand Down Expand Up @@ -165,4 +176,25 @@ private boolean isBlacklisted(final Block block, final SwitcherooConfig config)

return false;
}

private boolean preferSilkTouch(final Block block, final SwitcherooConfig config) {
final Identifier id = Registry.BLOCK.getId(block);
final String[] blocks = config.prefer.silk_touch.split(" ");

for (final String blockId : blocks) {
switch (blockId.split(":").length) {
case 1:
if (id.toString().equals("minecraft:" + blockId))
return true;
break;
case 2:
default:
if (id.toString().equals(blockId))
return true;
break;
}
}

return false;
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/natoboram/switcheroo/BlockUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.natoboram.switcheroo;

import net.minecraft.block.Block;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

public class BlockUtil {
public static boolean isInList(final Block block, final String[] blocks) {
final Identifier id = Registry.BLOCK.getId(block);

for (final String blockId : blocks) {
switch (blockId.split(":").length) {
case 1:
if (id.toString().equals("minecraft:" + blockId))
return true;
break;
case 2:
default:
if (id.toString().equals(blockId))
return true;
break;
}
}

return false;
}
}
87 changes: 87 additions & 0 deletions src/main/java/com/natoboram/switcheroo/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ final public class Commands {
.getConfigHolder(SwitcherooConfig.class);

/**
* Shows the list of blacklisted blocks.
*
* <pre>
* /switcheroo blacklist blocks
* </pre>
Expand All @@ -33,6 +35,8 @@ static public int blacklistBlocks(final CommandContext<FabricClientCommandSource
}

/**
* Add a block to the blacklist.
*
* <pre>
* /switcheroo blacklist blocks add minecraft:grass_block
* </pre>
Expand All @@ -46,6 +50,8 @@ static public int blacklistBlocksAdd(final CommandContext<FabricClientCommandSou
};

/**
* Remove a block from the blacklist.
*
* <pre>
* /switcheroo blacklist blocks remove minecraft:grass_block
* </pre>
Expand Down Expand Up @@ -78,6 +84,8 @@ static public int blacklistBlocksRemove(final CommandContext<FabricClientCommand
};

/**
* Shows the list of blacklisted mobs.
*
* <pre>
* /switcheroo blacklist mobs
* </pre>
Expand All @@ -89,6 +97,8 @@ static public int blacklistMobs(final CommandContext<FabricClientCommandSource>
}

/**
* Add a mob to the blacklist.
*
* <pre>
* /switcheroo blacklist mobs add minecraft:cow
* </pre>
Expand All @@ -105,6 +115,8 @@ static public int blacklistMobsAdd(final CommandContext<FabricClientCommandSourc
};

/**
* Remove a mob from the blacklist.
*
* <pre>
* /switcheroo blacklist mobs remove minecraft:cow
* </pre>
Expand Down Expand Up @@ -140,6 +152,8 @@ static public int blacklistMobsRemove(final CommandContext<FabricClientCommandSo
};

/**
* Shows the configuration for <code>alwaysFastest</code>.
*
* <pre>
* /switcheroo alwaysFastest
* </pre>
Expand All @@ -150,6 +164,8 @@ static public int alwaysFastest(final CommandContext<FabricClientCommandSource>
}

/**
* Sets the configuration for <code>alwaysFastest</code>.
*
* <pre>
* /switcheroo alwaysFastest true
* </pre>
Expand All @@ -163,6 +179,8 @@ static public int alwaysFastestToggle(final CommandContext<FabricClientCommandSo
}

/**
* Shows the configuration for <code>minDurability</code>.
*
* <pre>
* /switcheroo minDurability
* </pre>
Expand All @@ -173,6 +191,8 @@ static public int minDurability(final CommandContext<FabricClientCommandSource>
}

/**
* Sets the configuration for <code>minDurability</code>.
*
* <pre>
* /switcheroo minDurability 5
* </pre>
Expand All @@ -184,4 +204,71 @@ static public int minDurabilitySet(final CommandContext<FabricClientCommandSourc
CONFIG_HOLDER.save();
return minDurability(command);
}

/**
* Shows the list of blocks to prefer Silk Touch on.
*
* <pre>
* /switcheroo prefer silk_touch
* </pre>
*/
static public int preferSilkTouch(final CommandContext<FabricClientCommandSource> command) {
final String silkTouch = CONFIG_HOLDER.getConfig().prefer.silk_touch;
command.getSource().sendFeedback(Text.of("Silk Touch: §e" + (silkTouch.isEmpty() ? "[]" : silkTouch)));
return Command.SINGLE_SUCCESS;
}

/**
* Add a block to prefer Silk Touch on.
*
* <pre>
* /switcheroo prefer silk_touch add minecraft:grass_block
* </pre>
*/
static public int preferSilkTouchAdd(final CommandContext<FabricClientCommandSource> command)
throws CommandSyntaxException {
final Identifier id = command.getArgument("block", Identifier.class);
CONFIG_HOLDER.getConfig().prefer.silk_touch += " " + id;
CONFIG_HOLDER.save();
command.getSource()
.sendFeedback(Text.of("§fAdded §e" + id + "§f to the list of blocks to prefer Silk Touch on."));
return preferSilkTouch(command);
}

/**
* Remove a block to prefer Silk Touch on.
*
* <pre>
* /switcheroo prefer silk_touch remove minecraft:grass_block
* </pre>
*/
static public int preferSilkTouchRemove(final CommandContext<FabricClientCommandSource> command)
throws CommandSyntaxException {
final Identifier id = command.getArgument("block", Identifier.class);

final ArrayList<String> prefer = new ArrayList<String>(
Arrays.asList(CONFIG_HOLDER.getConfig().prefer.silk_touch.split(" ")));

prefer.removeIf(preferred -> {
switch (preferred.split(":").length) {
case 1:
if (id.toString().equals("minecraft:" + preferred))
return true;
break;
case 2:
default:
if (id.toString().equals(preferred))
return true;
break;
}
return false;
});

CONFIG_HOLDER.getConfig().prefer.silk_touch = String.join(" ", prefer);
CONFIG_HOLDER.save();
command.getSource()
.sendFeedback(Text.of("§fRemoved §e" + id + "§f from the list of blocks to prefer Silk Touch on."));

return preferSilkTouch(command);
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/natoboram/switcheroo/ItemStackUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ public static double getMiningSpeedMultiplier(final ItemStack tool, final BlockS

/** Removes enchanted items that have only 5 durability left. */
public static boolean removeDamagedEnchantedItems(final ArrayList<ItemStack> items, final SwitcherooConfig config) {
return items.removeIf(item -> !item.getEnchantments().isEmpty()
&& item.getMaxDamage() - item.getDamage() <= config.minDurability);
return items.removeIf(
item -> item.hasEnchantments() && item.getMaxDamage() - item.getDamage() <= config.minDurability);
}

public static boolean keepMostDamagedItems(final ArrayList<ItemStack> items) {
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/natoboram/switcheroo/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ public void onInitializeClient() {
.executes(Commands::alwaysFastestToggle)))
.then(literal("minDurability").executes(Commands::minDurability)
.then(argument("integer", IntegerArgumentType.integer())
.executes(Commands::minDurabilitySet))));
.executes(Commands::minDurabilitySet)))
.then(literal("prefer").then(literal("silk_touch")
.executes(Commands::preferSilkTouch)
.then(literal("add").then(
argument("block", BlockIdentifierArgumentType.blockIdentifier())
.executes(Commands::preferSilkTouchAdd)))
.then(literal("remove").then(
argument("block", BlockIdentifierArgumentType.blockIdentifier())
.executes(Commands::preferSilkTouchRemove))))));
});

LOGGER.info("Loaded Switcheroo!");
Expand Down
Loading

0 comments on commit e215246

Please sign in to comment.