Skip to content

Commit

Permalink
Replace references to "MobSource" with constant
Browse files Browse the repository at this point in the history
Replaces uses of MobSource in BoneItem and BoneColorProvider with BONE_NBT_ID in AbstractBone
  • Loading branch information
JuliaLange committed Mar 3, 2024
1 parent d32343e commit c5eaa76
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/client/java/me/woach/bone/util/BoneColorProvider.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.woach.bone.util;

import me.woach.bone.bonedata.AbstractBone;
import me.woach.bone.items.ItemsRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
import net.minecraft.item.Item;
Expand All @@ -14,8 +15,8 @@ public static void registerBoneColorProvider() {
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> {
if (!stack.isEmpty() && stack.hasNbt()) {
NbtCompound nbt = stack.getNbt();
if (nbt != null && nbt.contains("MobSource", NbtElement.STRING_TYPE)) {
String mobSource = nbt.getString("MobSource");
if (nbt != null && nbt.contains(AbstractBone.BONE_NBT_ID, NbtElement.STRING_TYPE)) {
String mobSource = nbt.getString(AbstractBone.BONE_NBT_ID);
return getMobColor(mobSource);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/woach/bone/bonedata/AbstractBone.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class AbstractBone {
private final Identifier dropEntity;
private final Random rng = Random.create();

private static final String BONE_NBT_ID = "MobSource";
public static final String BONE_NBT_ID = "MobSource";

public AbstractBone(boolean enabled, int chance, Map<EnchantmentTarget, Enchantment> itemToEffect,
Identifier dropEntity) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/me/woach/bone/items/BoneItem.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.woach.bone.items;

import me.woach.bone.bonedata.AbstractBone;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
Expand All @@ -14,8 +15,8 @@ public BoneItem() {
public Text getName(ItemStack stack) {
if (stack.hasNbt()) {
assert stack.getNbt() != null;
if (stack.getNbt().contains("MobSource")) {
String mobKey = "entity." + stack.getNbt().getString("MobSource").toLowerCase().replace(":", ".");
if (stack.getNbt().contains(AbstractBone.BONE_NBT_ID)) {
String mobKey = "entity." + stack.getNbt().getString(AbstractBone.BONE_NBT_ID).toLowerCase().replace(":", ".");
String boneKey = "item.minecraft.bone";
return Text.translatable(mobKey).append(" ").append(Text.translatable(boneKey));
}
Expand Down

0 comments on commit c5eaa76

Please sign in to comment.