Skip to content

Commit

Permalink
tags
Browse files Browse the repository at this point in the history
  • Loading branch information
PinkGoosik committed Jul 16, 2024
1 parent 2c2997d commit 9b6f6d9
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 17 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/visuality/config/VisualityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ public class VisualityConfig {
"minecraft:diamond_leggings", "minecraft:diamond_boots"));

public static final ArrayList<String> 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);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/visuality/mixin/BlockMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
33 changes: 28 additions & 5 deletions src/main/java/visuality/registry/ShinyArmorRegistry.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,44 @@
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;

import java.util.ArrayList;
import java.util.Optional;

public class ShinyArmorRegistry {
public static final ArrayList<Item> ENTRIES = new ArrayList<>();
private static final ArrayList<Item> ITEMS = new ArrayList<>();
private static final ArrayList<TagKey<Item>> TAGS = new ArrayList<>();

public static void reload() {
ENTRIES.clear();
ArrayList<Item> entries = new ArrayList<>();
VisualityMod.config.shinyArmorEntries.forEach(entry -> getItemFromString(entry).ifPresent(entries::add));
ENTRIES.addAll(entries);
ITEMS.clear();
TAGS.clear();
ArrayList<Item> items = new ArrayList<>();
ArrayList<TagKey<Item>> 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<Item> getItemFromString(String id) {
Expand Down
33 changes: 28 additions & 5 deletions src/main/java/visuality/registry/ShinyBlockRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,44 @@

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;

import java.util.ArrayList;
import java.util.Optional;

public class ShinyBlockRegistry {
public static final ArrayList<AbstractBlock> ENTRIES = new ArrayList<>();
private static final ArrayList<AbstractBlock> BLOCKS = new ArrayList<>();
private static final ArrayList<TagKey<Block>> TAGS = new ArrayList<>();

public static void reload() {
ENTRIES.clear();
ArrayList<Block> entries = new ArrayList<>();
VisualityMod.config.shinyBlockEntries.forEach(entry -> getBlockFromString(entry).ifPresent(entries::add));
ENTRIES.addAll(entries);
BLOCKS.clear();
TAGS.clear();
ArrayList<Block> blocks = new ArrayList<>();
ArrayList<TagKey<Block>> 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<Block> getBlockFromString(String id) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/visuality/util/ShinyArmorUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
}
Expand Down

0 comments on commit 9b6f6d9

Please sign in to comment.