Skip to content

Commit

Permalink
Initial toggle state is on instead of off
Browse files Browse the repository at this point in the history
  • Loading branch information
MelanX committed Dec 23, 2024
1 parent 4ea1f3c commit 8eb0115
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 58 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ group=de.melanx
base_version=6.0

## Upload Properties
upload_versions=1.21, 1.21.1
upload_release=beta
upload_versions=1.21, 1.21.1, 1.21.2, 1.21.3, 1.21.4
upload_release=release
modrinth_project=L9JLNLqk
curse_project=361977

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/de/melanx/toolswap/handler/ToggleState.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public static ToggleState initialize() {

private void load() {
try {
if (Files.notExists(SWAP_STATE_FILE)) {
Files.writeString(SWAP_STATE_FILE, "true");
this.shouldSwapTools = true;
return;
}

String s = Files.readString(SWAP_STATE_FILE);
this.shouldSwapTools = Boolean.parseBoolean(s);
} catch (IOException e) {
Expand Down
56 changes: 0 additions & 56 deletions src/main/java/de/melanx/toolswap/helper/ToolEntry.java
Original file line number Diff line number Diff line change
@@ -1,46 +1,14 @@
package de.melanx.toolswap.helper;

import de.melanx.toolswap.ToolSwap;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.TieredItem;
import net.minecraft.world.item.component.Tool;
import net.minecraft.world.level.block.Block;

import javax.annotation.Nullable;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public record ToolEntry(Tool tool, ItemStack stack) {

private static final Set<TieredItem> LOGGED_ITEMS = new HashSet<>();
private static final Set<TagKey<Block>> LOGGED_TAGS = new HashSet<>();

private static final Map<TagKey<Block>, Integer> HARVEST_LEVELS = Map.of(
BlockTags.INCORRECT_FOR_WOODEN_TOOL, 0,
BlockTags.INCORRECT_FOR_STONE_TOOL, 1,
BlockTags.INCORRECT_FOR_IRON_TOOL, 2,
BlockTags.INCORRECT_FOR_DIAMOND_TOOL, 3,
BlockTags.INCORRECT_FOR_GOLD_TOOL, 0,
BlockTags.INCORRECT_FOR_NETHERITE_TOOL, 4
);

public Tool getTool() {
return this.tool;
}

public ItemStack getStack() {
return this.stack;
}

@Nullable
public TieredItem tieredItem() {
return this.stack.getItem() instanceof TieredItem tieredItem ? tieredItem : null;
}

public boolean isEnchanted() {
return this.stack.isEnchanted();
}
Expand All @@ -49,30 +17,6 @@ public int damagePerBlock() {
return this.tool.damagePerBlock();
}

public int getHarvestLevel() {
TieredItem item = this.tieredItem();
if (item == null) {
return 0;
}
Tier tier = item.getTier();
TagKey<Block> incorrectBlocksForDrops = tier.getIncorrectBlocksForDrops();
Integer harvestLevel = HARVEST_LEVELS.get(incorrectBlocksForDrops);
if (harvestLevel == null) {
if (LOGGED_ITEMS.add(item) || LOGGED_TAGS.add(incorrectBlocksForDrops)) {
ToolSwap.LOGGER.info("Please notify the author of this. Missing tag compat of item {}: {}", item, incorrectBlocksForDrops);
}

return 0;
}

return harvestLevel;
}

public float getEfficiency() {
TieredItem item = this.tieredItem();
return item != null ? item.getTier().getSpeed() : 0.0F;
}

@Override
public String toString() {
return this.stack.toString();
Expand Down

0 comments on commit 8eb0115

Please sign in to comment.