diff --git a/gradle.properties b/gradle.properties index 95e27c2..858ba27 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs = -Xmx2G org.gradle.parallel = true # Mod Properties -mod_version = 0.7.6+1.21 +mod_version = 0.7.7+1.21 maven_group = ru.pinkgoosik archives_base_name = visuality minecraft_version_range = >=1.21 <1.22 diff --git a/src/main/java/visuality/config/VisualityConfig.java b/src/main/java/visuality/config/VisualityConfig.java index 757874c..b75aff5 100644 --- a/src/main/java/visuality/config/VisualityConfig.java +++ b/src/main/java/visuality/config/VisualityConfig.java @@ -18,10 +18,7 @@ public class VisualityConfig { "minecraft:diamond_leggings", "minecraft:diamond_boots")); public static final ArrayList DEFAULT_SHINY_BLOCKS = new ArrayList<>(List.of( - "minecraft:gold_ore", "minecraft:deepslate_gold_ore", - "minecraft:nether_gold_ore", "minecraft:diamond_ore", - "minecraft:deepslate_diamond_ore", "minecraft:emerald_ore", - "minecraft:deepslate_emerald_ore")); + "#minecraft:gold_ores", "#minecraft:diamond_ores", "#minecraft:emerald_ores")); public boolean slimeEnabled = true; public TextColor slimeColor = TextColor.fromRgb(8978297); diff --git a/src/main/java/visuality/mixin/BlockMixin.java b/src/main/java/visuality/mixin/BlockMixin.java index 33f564a..18319e7 100644 --- a/src/main/java/visuality/mixin/BlockMixin.java +++ b/src/main/java/visuality/mixin/BlockMixin.java @@ -52,7 +52,7 @@ void randomDisplayTick(BlockState state, World world, BlockPos pos, Random rando } } } - if(VisualityMod.config.shinyBlocksEnabled && ShinyBlockRegistry.ENTRIES.contains(this)) { + if(VisualityMod.config.shinyBlocksEnabled && ShinyBlockRegistry.isShiny(state)) { for(Direction direction : Direction.values()) { BlockPos offset = pos.offset(direction); if(!world.getBlockState(offset).isOpaqueFullCube(world, offset)) { diff --git a/src/main/java/visuality/registry/ShinyArmorRegistry.java b/src/main/java/visuality/registry/ShinyArmorRegistry.java index 0c7053f..29ef166 100644 --- a/src/main/java/visuality/registry/ShinyArmorRegistry.java +++ b/src/main/java/visuality/registry/ShinyArmorRegistry.java @@ -1,7 +1,10 @@ package visuality.registry; import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraft.registry.Registries; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.tag.TagKey; import net.minecraft.util.Identifier; import visuality.VisualityMod; @@ -9,13 +12,33 @@ import java.util.Optional; public class ShinyArmorRegistry { - public static final ArrayList ENTRIES = new ArrayList<>(); + private static final ArrayList ITEMS = new ArrayList<>(); + private static final ArrayList> TAGS = new ArrayList<>(); public static void reload() { - ENTRIES.clear(); - ArrayList entries = new ArrayList<>(); - VisualityMod.config.shinyArmorEntries.forEach(entry -> getItemFromString(entry).ifPresent(entries::add)); - ENTRIES.addAll(entries); + ITEMS.clear(); + TAGS.clear(); + ArrayList items = new ArrayList<>(); + ArrayList> tags = new ArrayList<>(); + + VisualityMod.config.shinyArmorEntries.forEach(entry -> { + if(entry.startsWith("#")) { + tags.add(TagKey.of(RegistryKeys.ITEM, Identifier.of(entry.replace("#", "")))); + return; + } + getItemFromString(entry).ifPresent(items::add); + }); + + ITEMS.addAll(items); + TAGS.addAll(tags); + } + + public static boolean isShiny(ItemStack item) { + if(ITEMS.contains(item.getItem())) return true; + for(var tag : TAGS) { + if(item.isIn(tag)) return true; + } + return false; } private static Optional getItemFromString(String id) { diff --git a/src/main/java/visuality/registry/ShinyBlockRegistry.java b/src/main/java/visuality/registry/ShinyBlockRegistry.java index 33c7b45..9d7fbc4 100644 --- a/src/main/java/visuality/registry/ShinyBlockRegistry.java +++ b/src/main/java/visuality/registry/ShinyBlockRegistry.java @@ -2,7 +2,10 @@ import net.minecraft.block.AbstractBlock; import net.minecraft.block.Block; +import net.minecraft.block.BlockState; import net.minecraft.registry.Registries; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.tag.TagKey; import net.minecraft.util.Identifier; import visuality.VisualityMod; @@ -10,13 +13,33 @@ import java.util.Optional; public class ShinyBlockRegistry { - public static final ArrayList ENTRIES = new ArrayList<>(); + private static final ArrayList BLOCKS = new ArrayList<>(); + private static final ArrayList> TAGS = new ArrayList<>(); public static void reload() { - ENTRIES.clear(); - ArrayList entries = new ArrayList<>(); - VisualityMod.config.shinyBlockEntries.forEach(entry -> getBlockFromString(entry).ifPresent(entries::add)); - ENTRIES.addAll(entries); + BLOCKS.clear(); + TAGS.clear(); + ArrayList blocks = new ArrayList<>(); + ArrayList> tags = new ArrayList<>(); + + VisualityMod.config.shinyBlockEntries.forEach(entry -> { + if(entry.startsWith("#")) { + tags.add(TagKey.of(RegistryKeys.BLOCK, Identifier.of(entry.replace("#", "")))); + return; + } + getBlockFromString(entry).ifPresent(blocks::add); + }); + + BLOCKS.addAll(blocks); + TAGS.addAll(tags); + } + + public static boolean isShiny(BlockState block) { + if(BLOCKS.contains(block.getBlock())) return true; + for(var tag : TAGS) { + if(block.isIn(tag)) return true; + } + return false; } private static Optional getBlockFromString(String id) { diff --git a/src/main/java/visuality/util/ShinyArmorUtils.java b/src/main/java/visuality/util/ShinyArmorUtils.java index 8ca3622..91026a5 100644 --- a/src/main/java/visuality/util/ShinyArmorUtils.java +++ b/src/main/java/visuality/util/ShinyArmorUtils.java @@ -9,7 +9,7 @@ public class ShinyArmorUtils { public static int getShinyLevel(LivingEntity entity) { int shinyArmor = 0; for(ItemStack stack : entity.getArmorItems()) { - if(ShinyArmorRegistry.ENTRIES.contains(stack.getItem())) { + if(ShinyArmorRegistry.isShiny(stack)) { shinyArmor++; } }