Posted May 28, 20223 yr I have this idea where you can add emblems to your chestplate to distinguish yourself. What I am wondering is whether or not I need to register every variant. It can get quite overwhelming to need to register 4 chestplates for every symbol, and they wouldn’t be treated as the vanilla chestplate. Would I be able to avoid this through tags or some other way?
May 29, 20223 yr 11 hours ago, MWR said: It can get quite overwhelming to need to register 4 chestplates for every symbol, and they wouldn’t be treated as the vanilla chestplate. Would I be able to avoid this through tags or some other way? it depends on in which way you want to modify the Chestplate, in which way do you want to modify the Chestplate? Note: if you want a different Item for each modification, you need to register all the Items
May 29, 20223 yr yes, you can use tags (nbt tags within the item, not the new "item tags"). you need a custom recipe that takes a chestplate and some items and returns a chestplate with some data in nbt tags. and you need to render your stuff when you render your armor item. if you are going to use the crafting table (you don't have to, it can be your own block), in assemble method of the recipe call startingChestPlate.copy() to get the itemstack to return. then, result.getOrCreateTag() returns the root tag. it's best to make a CompoundTag for your mod, fill it using putString calls and then append your compound tag under the root using the put method.
May 30, 20223 yr Author 13 hours ago, MFMods said: yes, you can use tags (nbt tags within the item, not the new "item tags"). you need a custom recipe that takes a chestplate and some items and returns a chestplate with some data in nbt tags. and you need to render your stuff when you render your armor item. Ok, so I came up with this: { "type": "minecraft:crafting_shapeless", "ingredients": [ { "item": "minecraft:diamond_chestplate" }, { "item": "minecraft:gunpowder" } ], "result": { "item": "minecraft:diamond_chestplate", "nbt": "{Emblem:Creeper}" } } 13 hours ago, MFMods said: if you are going to use the crafting table (you don't have to, it can be your own block), in assemble method of the recipe call startingChestPlate.copy() to get the itemstack to return. then, result.getOrCreateTag() returns the root tag. it's best to make a CompoundTag for your mod, fill it using putString calls and then append your compound tag under the root using the put method. Where would this assemble method go? Would I need to make an ArmorItem class of some sort? The custom recipe added this tag without needing code, so do I just need to figure out how to render it based on this NBT tag? Would I need to override the vanilla ArmorItem, or make a new one? If possible, I don't want to change vanilla chestplates, in case it somehow breaks functionality with other mods. Edited May 30, 20223 yr by MWR I realized that I need more than JSONs if I need to remove a tag.
May 30, 20223 yr make a class EmblemRecipe that extends SpecialRecipe. in method "matches" confirm that the player provided a chestplate (maybe you'll allow adding things in steps?) and things you accept. in "assemble" method you make a recipe result - vanilla chestplate with nbt or your own item with nbt, that's up to you. use SimpleRecipeSerializer as a recipe serializer. register it in RegistryEvent.Register<IRecipeSerializer<?>> event. make a json file like this: { "type": "your_mod_id:recipe_name" } where recipe_name is name you give to the serializer. basically this is the recipe class: public class YourRecipe extends SpecialRecipe { public static IRecipeSerializer<YourRecipe> StupidSerializer = (IRecipeSerializer<YourRecipe>) (new SimpleRecipeSerializer<YourRecipe>(YourRecipe::new).setRegistryName(YourMod.MODID, "recipe_name")); public YourRecipe(ResourceLocation resourceLocation) { super(resourceLocation); } @Override public boolean matches(CraftingInventory inventory, World world) { return true if items are acceptable; } @Override public ItemStack assemble(CraftingInventory inventory) { return nice new itemstack with nbt; } @Override public IRecipeSerializer<?> getSerializer() { return StupidSerializer; } }
June 1, 20223 yr Author On 5/30/2022 at 8:25 AM, MFMods said: make a class EmblemRecipe that extends SpecialRecipe. in method "matches" confirm that the player provided a chestplate (maybe you'll allow adding things in steps?) and things you accept. in "assemble" method you make a recipe result - vanilla chestplate with nbt or your own item with nbt, that's up to you. use SimpleRecipeSerializer as a recipe serializer. register it in RegistryEvent.Register<IRecipeSerializer<?>> event. make a json file like this: { "type": "your_mod_id:recipe_name" } where recipe_name is name you give to the serializer. basically this is the recipe class: public class YourRecipe extends SpecialRecipe { public static IRecipeSerializer<YourRecipe> StupidSerializer = (IRecipeSerializer<YourRecipe>) (new SimpleRecipeSerializer<YourRecipe>(YourRecipe::new).setRegistryName(YourMod.MODID, "recipe_name")); public YourRecipe(ResourceLocation resourceLocation) { super(resourceLocation); } @Override public boolean matches(CraftingInventory inventory, World world) { return true if items are acceptable; } @Override public ItemStack assemble(CraftingInventory inventory) { return nice new itemstack with nbt; } @Override public IRecipeSerializer<?> getSerializer() { return StupidSerializer; } } Would I have to make a JSON for every combination, or is there a way to have generic ingredients and results?
June 3, 20223 yr Author I'm not sure if there is a more elegant way to hold a list of potential ingredients, but this works: public class EmblemRecipe extends CustomRecipe { ArrayList<Item> ingredients = new ArrayList<>(Arrays.asList(Items.GUNPOWDER, Items.BONE, Items.REDSTONE)); String[] emblems = {"Creeper", "Skeleton", "Redstone"}; public EmblemRecipe(ResourceLocation id) { super(id); } @Override public boolean matches(CraftingContainer inv, Level level) { ItemStack chestplate = ItemStack.EMPTY; ItemStack ingredient = ItemStack.EMPTY; for(int i = 0; i < inv.getContainerSize(); ++i) { ItemStack itemstack = inv.getItem(i); if (chestplate.isEmpty() && itemstack.getItem() instanceof ArmorItem && ((ArmorItem)itemstack.getItem()).getSlot() == EquipmentSlot.CHEST) { chestplate = itemstack; } if (ingredient.isEmpty() && ingredients.contains(itemstack.getItem())) { ingredient = itemstack; } } return !chestplate.isEmpty() && !ingredient.isEmpty(); } @Override public ItemStack assemble(CraftingContainer inv) { ItemStack chestplate = null; CompoundTag compoundtag = null; String emblem = null; for(int i = 0; i < inv.getContainerSize(); ++i ) { ItemStack itemstack = inv.getItem(i); if (itemstack.getItem() instanceof ArmorItem) { chestplate = itemstack.copy(); compoundtag = chestplate.getOrCreateTagElement("emblem"); } if (ingredients.contains(itemstack.getItem())) { emblem = emblems[ingredients.indexOf(itemstack.getItem())]; } } compoundtag.putString("Emblem", emblem); chestplate.setTag(compoundtag); return chestplate; } @Override public boolean canCraftInDimensions(int width, int height) { return width * height >= 2; } @Override public ItemStack getResultItem() { return ItemStack.EMPTY; } @Override public RecipeSerializer<?> getSerializer() { return ModRecipeSerializer.EMBLEM_RECIPE.get(); } @Override public RecipeType<?> getType() { return RecipeType.CRAFTING; } } Now my struggle is rendering the armor. I can't find where vanilla armor is rendered, and when I do, would I need to extend that class and make my own renderer for armor?
June 6, 20223 yr Author On 6/3/2022 at 3:40 AM, diesieben07 said: HumanoidArmorLayer. You can provide your own model and rendering via getArmorModel. Do I need to make my own model if I just want change the texture?
June 6, 20223 yr Author 9 hours ago, diesieben07 said: No. Ok so I just need to figure how to change textures based on NBT data.
June 16, 20223 yr Author On 6/3/2022 at 3:40 AM, diesieben07 said: HumanoidArmorLayer. You can provide your own model and rendering via getArmorModel. So far, I've overridden getArmorResource: public class ModHumanoidArmorLayer<T extends LivingEntity, M extends HumanoidModel<T>, A extends HumanoidModel<T>> extends HumanoidArmorLayer<T, M, A> { ... @Override public ResourceLocation getArmorResource(net.minecraft.world.entity.Entity entity, ItemStack stack, EquipmentSlot slot, @Nullable String type) { ArmorItem item = (ArmorItem)stack.getItem(); String texture = item.getMaterial().getName(); String domain = "minecraft"; int idx = texture.indexOf(':'); if (idx != -1) { domain = texture.substring(0, idx); texture = texture.substring(idx + 1); } String emblem = stack.getTagElement("emblem").getString("emblem"); String s1 = String.format(java.util.Locale.ROOT, "%s:textures/models/armor/%s_layer_%d%s_%s.png", domain, texture, (usesInnerModel(slot) ? 2 : 1), type == null ? "" : String.format(java.util.Locale.ROOT, "_%s", type), emblem); s1 = net.minecraftforge.client.ForgeHooksClient.getArmorTexture(entity, stack, s1, slot, type); ResourceLocation resourcelocation = ARMOR_LOCATION_CACHE.get(s1); if (resourcelocation == null) { resourcelocation = new ResourceLocation(s1); ARMOR_LOCATION_CACHE.put(s1, resourcelocation); } return resourcelocation; } } But how could I override the vanilla HumanoidArmorLayer? I made my own custom model for getArmorModel (which is copy/pasted from vanilla), but I am not sure how to control its textures without HumanoidArmorLayer.
June 16, 20223 yr Author 17 hours ago, diesieben07 said: getArmorTexture will be used as the texture. Don't make your own layer. Here is my code for ModArmorItem: public class ModArmorItem extends ArmorItem { public ModArmorItem(ArmorMaterial material, EquipmentSlot slot, Properties properties) { super(material, slot, properties); } @Override public String getArmorTexture(ItemStack stack, Entity entity, EquipmentSlot slot, String type) { ArmorItem item = (ArmorItem)stack.getItem(); String texture = item.getMaterial().getName(); String domain = "minecraft"; String emblem = ""; if (stack.getTagElement("Emblem") != null) { emblem = stack.getTagElement("Emblem").getString("Emblem"); domain = "emblematic"; } texture = texture.substring(texture.indexOf(':') + 1); return String.format(java.util.Locale.ROOT, "%s:textures/models/armor/%s_layer_1%s.png", domain, texture, emblem == "" ? "" : String.format(java.util.Locale.ROOT, "_%s", emblem)); //TODO: change when including leather because of overlays } } I'm not sure what I did wrong. The texture does not change, but I can verify that the modified chestplate code is being used. Edited June 17, 20223 yr by MWR Fixed an error in code, but it is still not working.
June 17, 20223 yr Author 11 hours ago, diesieben07 said: What do you mean by this? One time I crashed because of a bug in my code. I was just saying that because of that, I know it’s my code being used for the chestplate and not vanilla code. Also, I learned the reason why it’s not working is because of the Emblem tag. stack.getTagElement(“Emblem”) returns null even if it has that tag. I’m not sure what is the correct way to get the Emblem tag. Edited June 17, 20223 yr by MWR Realized why it’s not working.
June 17, 20223 yr Author 2 hours ago, Luis_ST said: you never add the Tag to the ItemStack Where am I supposed to add it? I handled adding the tag in the custom recipe, and it adds the proper NBT data to the chestplate.
June 18, 20223 yr Author I got it working! I was using getTagElement incorrectly, I'm not sure what the correct way is to use getTagElement, but it doesn't matter. @Override public String getArmorTexture(ItemStack stack, Entity entity, EquipmentSlot slot, String type) { ArmorItem item = (ArmorItem)stack.getItem(); String texture = item.getMaterial().getName(); String domain = "minecraft"; String emblem = ""; if (stack.getTag().contains("Emblem")) { emblem = stack.getTag().getString("Emblem"); domain = "emblematic"; } texture = texture.substring(texture.indexOf(':') + 1); return String.format(java.util.Locale.ROOT, "%s:textures/models/armor/%s_layer_1%s.png", domain, texture, emblem == "" ? "" : String.format(java.util.Locale.ROOT, "_%s", emblem)); //TODO: change when including leather because of overlays } Thank you to all who helped!
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.