bugfix on external ids

This commit is contained in:
Jörg Henke 2020-08-16 16:40:37 +02:00
parent a7352e84a2
commit 988a867099
6 changed files with 110 additions and 17 deletions

View File

@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.8.8+build.202 loader_version=0.8.8+build.202
# Mod Properties # Mod Properties
mod_version = 1.16.1.6 mod_version = 1.16.1.7
maven_group = de.jottyfan.minecraft maven_group = de.jottyfan.minecraft
archives_base_name = quickiefabric archives_base_name = quickiefabric

View File

@ -1,15 +1,19 @@
package de.jottyfan.minecraft.quickiefabric.tools; package de.jottyfan.minecraft.quickiefabric.tools;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import de.jottyfan.minecraft.quickiefabric.tools.externalmods.Byg;
import de.jottyfan.minecraft.quickiefabric.tools.externalmods.Terrestria;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.util.Identifier;
/** /**
* *
@ -21,8 +25,9 @@ public interface ToolRangeable {
.newHashSet(new Block[] { Blocks.GRAVEL, Blocks.SAND, Blocks.GRASS_BLOCK, Blocks.DIRT, Blocks.CLAY, .newHashSet(new Block[] { Blocks.GRAVEL, Blocks.SAND, Blocks.GRASS_BLOCK, Blocks.DIRT, Blocks.CLAY,
Blocks.FARMLAND, Blocks.GRASS_PATH, Blocks.RED_SAND, Blocks.SOUL_SAND }); Blocks.FARMLAND, Blocks.GRASS_PATH, Blocks.RED_SAND, Blocks.SOUL_SAND });
public static final Set<String> SHOVEL_EXTERNAL_EFFECTIVE_ON = Sets.newHashSet("byg:black_sand", "byg:white_sand", public static final Set<Identifier> SHOVEL_EXTERNAL_EFFECTIVE_ON = mergeSets(
"byg:peat", "byg:meadow_dirt", "byg:mud_block", "byg:blue_sand", "byg:purple_sand", "terrestria:basalt_sand"); Byg.createFromStrings("black_sand", "white_sand", "peat", "meadow_dirt", "mud_block", "blue_sand", "purple_sand"),
Terrestria.createFromStrings("basalt_sand"));
public static final List<List<Block>> AXE_EFFECTIVE_ON = Lists.newArrayList( public static final List<List<Block>> AXE_EFFECTIVE_ON = Lists.newArrayList(
Arrays.asList(Blocks.ACACIA_LOG, Blocks.STRIPPED_ACACIA_LOG, Blocks.ACACIA_WOOD, Blocks.STRIPPED_ACACIA_WOOD), Arrays.asList(Blocks.ACACIA_LOG, Blocks.STRIPPED_ACACIA_LOG, Blocks.ACACIA_WOOD, Blocks.STRIPPED_ACACIA_WOOD),
@ -42,16 +47,31 @@ public interface ToolRangeable {
Blocks.MUSHROOM_STEM), Blocks.MUSHROOM_STEM),
Arrays.asList(Blocks.POTTED_RED_MUSHROOM, Blocks.RED_MUSHROOM_BLOCK, Blocks.RED_MUSHROOM, Blocks.MUSHROOM_STEM)); Arrays.asList(Blocks.POTTED_RED_MUSHROOM, Blocks.RED_MUSHROOM_BLOCK, Blocks.RED_MUSHROOM, Blocks.MUSHROOM_STEM));
public static final List<String> AXE_EFFECTIVE_ON_EXTERNAL = Lists.newArrayList("terrestia:redwood_log", public static final Set<Identifier> AXE_EFFECTIVE_ON_EXTERNAL = mergeSets(
"terrestia:hemlock_log", "terrestia:rubber_log", "terrestia:cypress_log", "terrestia:willow_log", "terrestia:japanese_maple_log", Terrestria.createFromStrings("redwood_log", "hemlock_log", "rubber_log", "cypress_log", "willow_log",
"terrestia:rainbow_eucalyptus_log", "terrestia:sakura_log", "terrestia:yucca_palm:_log", "byg:aspen_log", "byg:baobab_log", "japanese_maple_log", "rainbow_eucalyptus_log", "sakura_log", "yucca_palm_log"),
"byg:blue_enchanted_log", "byg:cherry_log", "byg:cika_log", "byg:cypress_log", "byg:ebony_log", "byg:fir_log", Byg.createFromStrings("aspen_log", "baobab_log", "blue_enchanted_log", "cherry_log", "cika_log", "cypress_log",
"byg:green_enchanted_log", "byg:holly_log", "byg:jacaranda_log", "byg:mahogany_log", "byg:mangrove_log", "ebony_log", "fir_log", "green_enchanted_log", "holly_log", "jacaranda_log", "mahogany_log", "mangrove_log",
"byg:maple_log", "byg:palo_verde_log", "byg:pine_log", "byg:rainbow_eucalyptus_log", "byg:redwood_log", "maple_log", "palo_verde_log", "pine_log", "rainbow_eucalyptus_log", "redwood_log", "skyris_log",
"byg:skyris_log", "byg:willow_log", "byg:witch_hazel_log", "byg:zelkova_log"); "willow_log", "witch_hazel_log", "zelkova_log"));
public static final Set<Block> PICKAXE_EFFECTIVE_ON = Sets.newHashSet(new Block[] { Blocks.GLOWSTONE }); public static final Set<Block> PICKAXE_EFFECTIVE_ON = Sets.newHashSet(new Block[] { Blocks.GLOWSTONE });
/**
* merge all sets
*
* @param sets the sets
* @return one merged set
*/
@SafeVarargs
public static Set<Identifier> mergeSets(Set<Identifier>... sets) {
Set<Identifier> result = new HashSet<>();
for (Set<Identifier> set : sets) {
result.addAll(set);
}
return result;
}
/** /**
* @return range of blocks to be harvested * @return range of blocks to be harvested
*/ */

View File

@ -45,9 +45,8 @@ public class ToolRangeableAxe extends AxeItem implements ToolRangeable {
return blockList; return blockList;
} }
} }
for (String externalBlockName : AXE_EFFECTIVE_ON_EXTERNAL) { for (Identifier externalID : AXE_EFFECTIVE_ON_EXTERNAL) {
Identifier id = new Identifier(externalBlockName); Block registeredBlock = Registry.BLOCK.get(externalID); // may be null if mods are not available
Block registeredBlock = Registry.BLOCK.get(id); // may be null if mods are not available
if (registeredBlock != null && registeredBlock.equals(block)) { if (registeredBlock != null && registeredBlock.equals(block)) {
return Lists.newArrayList(block); return Lists.newArrayList(block);
} }

View File

@ -39,16 +39,17 @@ public class ToolSpeedpowderShovel extends ShovelItem implements ToolRangeable {
public boolean canBreakNeigbbors(BlockState blockState) { public boolean canBreakNeigbbors(BlockState blockState) {
boolean result = SHOVEL_EFFECTIVE_ON.contains(blockState.getBlock()) || checkExternalBlock(blockState.getBlock()); boolean result = SHOVEL_EFFECTIVE_ON.contains(blockState.getBlock()) || checkExternalBlock(blockState.getBlock());
if (!result) { if (!result) {
LOGGER.info("cannot break block {} with that speedpoweder shovel", Registry.BLOCK.getId(blockState.getBlock())); if (!blockState.isAir()) {
LOGGER.debug("cannot break block {} with that speedpowder shovel", Registry.BLOCK.getId(blockState.getBlock()));
}
} }
return result; return result;
} }
private boolean checkExternalBlock(Block block) { private boolean checkExternalBlock(Block block) {
boolean result = false; boolean result = false;
for (String externalBlockName : SHOVEL_EXTERNAL_EFFECTIVE_ON) { for (Identifier externalID : SHOVEL_EXTERNAL_EFFECTIVE_ON) {
Identifier id = new Identifier(externalBlockName); Block registeredBlock = Registry.BLOCK.get(externalID); // may be null if mods are not available
Block registeredBlock = Registry.BLOCK.get(id); // may be null if mods are not available
result = result || (registeredBlock != null && registeredBlock.equals(block)); result = result || (registeredBlock != null && registeredBlock.equals(block));
} }
return result; return result;

View File

@ -0,0 +1,37 @@
package de.jottyfan.minecraft.quickiefabric.tools.externalmods;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.util.Identifier;
/**
*
* @author jotty
*
*/
public class Byg extends Identifier {
/**
* create identifier preluded by byg (for biomes you'll go)
*
* @param id the id within byg
*/
public Byg(String id) {
super("byg", id);
}
/**
* create a new set of Byg Identifiers
*
* @param names the names
* @return a set of identifiers
*/
public static final Set<Identifier> createFromStrings(String... names) {
Set<Identifier> set = new HashSet<>();
for (String name : names) {
set.add(new Byg(name));
}
return set;
}
}

View File

@ -0,0 +1,36 @@
package de.jottyfan.minecraft.quickiefabric.tools.externalmods;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.util.Identifier;
/**
*
* @author jotty
*
*/
public class Terrestria extends Identifier {
/**
* create identifier preluded by terrestria
* @param id the id within terrestria
*/
public Terrestria(String id) {
super("terrestria", id);
}
/**
* create a new set of Terrestria Identifiers
*
* @param names the names
* @return a set of identifiers
*/
public static final Set<Identifier> createFromStrings(String... names) {
Set<Identifier> set = new HashSet<>();
for (String name : names) {
set.add(new Terrestria(name));
}
return set;
}
}