Skip to content

Commit

Permalink
Improve config handling, default prefix and tag parsing
Browse files Browse the repository at this point in the history
- ignore leading/trailing whitespace
- with no prefix in front of the item id, "minecraft:" will be used
- allow ability to use tags, e.g. #minecraft:planks
  • Loading branch information
MightyKnight committed Jun 7, 2021
1 parent 504501e commit 842a1a8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/main/java/net/heyzeer0/sd/configs/GeneralConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,14 @@ public class GeneralConfig implements ConfigData {
Registry.ITEM.getId(Items.SHIELD).toString(),
Registry.ITEM.getId(Items.TOTEM_OF_UNDYING).toString());

// Ignore case and leading/trailing whitespaces when checking if entry is in config
public boolean contains(String s) {
for(String item : hiddenItems) {
if(s.equalsIgnoreCase(item.trim())) {
return true;
}
}
return false;
}

}
19 changes: 17 additions & 2 deletions src/main/java/net/heyzeer0/sd/mixins/MixinHeldItemRenderer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.heyzeer0.sd.mixins;

import net.heyzeer0.sd.ModCore;
import net.heyzeer0.sd.configs.GeneralConfig;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.render.VertexConsumerProvider;
Expand All @@ -9,6 +10,7 @@
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -29,9 +31,22 @@ private void hideShield(LivingEntity entity, ItemStack stack, ModelTransformatio

ClientPlayerEntity player = MinecraftClient.getInstance().player;
if (player != null && player.getOffHandStack() != stack) return;
if (!ModCore.getMain().getGeneralConfig().hiddenItems.contains(Registry.ITEM.getId(stack.getItem()).toString())) return;

callback.cancel();
GeneralConfig config = ModCore.getMain().getGeneralConfig();
String id = Registry.ITEM.getId(stack.getItem()).toString();

// Check if the item is specified in config
if(config.contains(id) || (id.startsWith("minecraft:") && config.contains(id.substring(10)))) {
callback.cancel();
}

// Check if the item has a tag that was specified in config
for(Identifier i : MinecraftClient.getInstance().getNetworkHandler().getTagManager().getItems().getTagsFor(stack.getItem())) {
if (ModCore.getMain().getGeneralConfig().hiddenItems.contains('#' + i.toString())) {
callback.cancel();
}
}

}

}

0 comments on commit 842a1a8

Please sign in to comment.