Jump to content

Recommended Posts

Posted

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?

Posted
  On 5/28/2022 at 10:25 PM, 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?

Expand  

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

Posted

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.

Posted (edited)
  On 5/29/2022 at 2:58 PM, 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.

Expand  

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}"
  }
}
  On 5/29/2022 at 2:58 PM, 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.

Expand  

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 by MWR
I realized that I need more than JSONs if I need to remove a tag.
Posted

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;
	}
}

 

Posted
  On 5/30/2022 at 12:25 PM, 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;
	}
}

 

Expand  

Would I have to make a JSON for every combination, or is there a way to have generic ingredients and results?

Posted

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?

  • 2 weeks later...
Posted
  On 6/3/2022 at 7:40 AM, diesieben07 said:

HumanoidArmorLayer. You can provide your own model and rendering via getArmorModel.

Expand  

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.

Posted (edited)
  On 6/16/2022 at 7:13 AM, diesieben07 said:

getArmorTexture will be used as the texture. Don't make your own layer.

Expand  

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 by MWR
Fixed an error in code, but it is still not working.
Posted (edited)
  On 6/17/2022 at 7:19 AM, diesieben07 said:

What do you mean by this?

Expand  

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 by MWR
Realized why it’s not working.
Posted
  On 6/17/2022 at 7:01 PM, Luis_ST said:

you never add the Tag to the ItemStack

Expand  

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.

Posted

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Looks like an issue with biomeswevegone
    • In the server.properties, set max-tick-time to -1   if there are further issues, make a test without distanthorizons
    • Verified user can get a $300 off TℰℳU Coupon code using the code ((“{{ '[''com31844'']}}”)). This TℰℳU $100Off code is specifically for new and existing customers both and can be redeemed to receive a $100discount on your purchase. Our exclusive TℰℳU Coupon code offers a flat $100off your purchase, plus an additional 100% discount on top of that. You can slash prices by up to $100as a new TℰℳU customer using code ((“{{ '[''com31844'']}}”)). Existing users can enjoy $100off their next haul with this code. But that’s not all! With our TℰℳU Coupon codes for 2025, you can get up to 90% discount on select items and clearance sales. Whether you’re a new customer or an existing shopper, our TℰℳU codes provide extra discounts tailored just for you. Save up to 100% with these current TℰℳU Coupons ["^"{{ '[''com31844'']}} "^"] for April 2025. The latest TℰℳU coupon codes at here. New users at TℰℳU receive a $100discount on orders over $100Use the code ((“{{ '[''com31844'']}}”)) during checkout to get TℰℳU Coupon $100Off For New Users. You can save $100Off your first order with the coupon code available for a limited time only. TℰℳU 90% Off promo code ((“{{ '[''com31844'']}}”)) will save you $100on your order. To get a discount, click on the item to purchase and enter the coe. Yes, offers $100Off coupon code “{{ '[''com31844'']}}” for first time users. You can get a $100bonus plus $100Off any purchase at TℰℳU with the $100Coupon Bundle at TℰℳU if you sign up with the referral code ((“{{ '[''com31844'']}}”)) and make a first purchase of $100or more. Free TℰℳU codes $100off — ((“{{ '[''com31844'']}}”)) Get a $100discount on your TℰℳU order with the promo code "{{ '[''com31844'']}}". You can get a discount by clicking on the item to purchase and entering this TℰℳU Coupon code $100off ((“{{ '[''com31844'']}}”)). ŢℰNew User Coupon ((“{{ '[''com31844'']}})): Up To $100OFF For First-Time Users Our TℰℳU first-time user coupon codes are designed just for new customers, offering the biggest discounts and the best deals currently available on TℰℳU To maximize your savings, download the TℰℳU app and apply our TℰℳU new user coupon during checkout. TℰℳU Coupon Codes For Existing Users ((“{{ '[''com31844'']}}”)): $100Price Slash Have you been shopping on TℰℳU or a while? Our TℰℳU Coupon for existing customers is here to reward you for your continued support, offering incredible discounts on your favorite products. TℰℳU Coupon For $100Off ((“{{ '[''com31844'']}}”)): Get A Flat $100Discount On Order Value Get ready to save big with our incredible TℰℳU Coupon for $100off! Our amazing ŢℰM$100off coupon code will give you a flat $100discount on your order value, making your shopping experience even more rewarding. TℰℳU Coupon Code For $100Off ((“{{ '[''com31844'']}}”)): For Both New And Existing Customers Our incredible TℰℳU Coupon code for $100off is here to help you save big on your purchases. Whether you’re a new user or an existing customer, our $100off code for TℰℳU will give you an additional discount! TℰℳU Coupon Bundle ((“{{ '[''com31844'']}}”)): Flat $100Off + Up To $100Discount Get ready for an unbelievable deal with our TℰℳU Coupon bundle for 2025! Our TℰℳU Coupon bundles will give you a flat $100discount and an additional $100off on top of it. Free TℰℳU Coupons ((“{{ '[''com31844'']}}”)): Unlock Unlimited Savings! Get ready to unlock a world of savings with our free TℰℳU Coupons! We’ve got you covered with a wide range of TℰℳU Coupon code options that will help you maximize your shopping experience. 100% Off TℰℳU Coupons, Promo Codes + 25% Cash Back ((“{{ '[''com31844'']}}”)) Redeem TℰℳU Coupon Code ((“{{ '[''com31844'']}}”)) TℰℳU Coupon $100OFF ((“{{ '[''com31844'']}}”)) TℰℳU Coupon $100OFF FOR EXISTING CUSTOMERS ((“{{ '[''com31844'']}}”)) TℰℳU Coupon $100OFF FIRST ORDER ((“{{ '[''com31844'']}}”)) TℰℳU Coupon $100OFF REDDIT ((“{{ '[''com31844'']}}”)) TℰℳU Coupon $100OFF FOR EXISTING CUSTOMERS REDDIT ((“{{ '[''com31844'']}}”)) TℰℳU $100OFF CODE ((“{{ '[''com31844'']}}”)) TℰℳU 70 OFF COUPON 2025 ((“{{ '[''com31844'']}}”)) DOMINOS 70 RS OFF COUPON CODE ((“{{ '[''com31844'']}}”)) WHAT IS A COUPON RATE ((“{{ '[''com31844'']}}”)) TℰℳU $100OFF FOR EXISTING CUSTOMERS ((“{{ '[''com31844'']}}”)) TℰℳU $100OFF FIRST ORDER ((“{{ '[''com31844'']}}”)) TℰℳU $100OFF FREE SHIPPING ((“{{ '[''com31844'']}}”)) You can get an exclusive $100off discount on your TℰℳU purchase with the code [{{ '[''com31844'']}}] Or [{{ '[''com31844'']}}].This code is specially designed for new customers and offers a significant price cut on your shopping. Make your first purchase on TℰℳU more rewarding by using this code to get $100off instantly.   TℰℳU Coupon Code For $100Off [{{ '[''com31844'']}}] Or [{{ '[''com31844'']}}]: Get A Flat $100Discount On Order Value Get ready to save big with our incredible TℰℳU coupon for $100off! Our coupon code will give you a flat $100discount on your order value, making your shopping experience even more rewarding.   Exclusive TℰℳU Discount Code [{{ '[''com31844'']}}] Or [{{ '[''com31844'']}}]: Flat $300 OFF for New and Existing Customers Using our TℰℳU promo code you can get A$ 200 off your order and 100% off using our TℰℳU promo code [{{ '[''com31844'']}}] Or [{{ '[''com31844'']}}]. As a new TℰℳU customer, you can save up to $100using this promo code. For returning users, our TℰℳU promo code offers a $100price slash on your next shopping spree. This is our way of saying thank you for shopping with us! Get ready to save big with our incredible TℰℳU Coupon code for $300 off! Our amazing TℰℳU $300 off coupon code will give you a flat $300 discount on your order value, making your shopping experience even more rewarding.   TℰℳU Coupon Code For 40% Off ["{com31844}"] For Both New And Existing Customers   Our incredible TℰℳU Coupon code for 40% off is here to help you save big on your purchases. Whether you’re a new user or an existing customer, our 40% off code for TℰℳU will give you an additional discount!   TℰℳU Coupon Bundle ["{com31844}"]: Flat $300 Off + Up To 90% Discount   Get ready for an unbelievable deal with our TℰℳU Coupon bundle for 2025! Our TℰℳU Coupon bundles will give you a flat $300 discount and an additional 40% off on top of it.   Free TℰℳU Coupons ["{com31844}"]: Unlock Unlimited Savings!   Get ready to unlock a world of savings with our free TℰℳU Coupons! We’ve got you covered with a wide range of TℰℳU Coupon code options that will help you maximize your shopping experience.   50% Off TℰℳU Coupons, Promo Codes + 25% Cash Back ["{com31844}"]   Redeem TℰℳU Coupon Code ["{com31844}"]   TℰℳU Coupon $300 OFF ["{com31844}"]   TℰℳU Coupon $300 OFF ["{com31844}"]   TℰℳU Coupon $300 OFF FOR EXISTING CUSTOMERS ["{com31844}"]   TℰℳU Coupon $300 OFF FIRST ORDER ["{com31844}"]   TℰℳU Coupon $300 OFF FIRST ORDER ["{com31844}"]   TℰℳU Coupon $300 OFF FOR EXISTING CUSTOMERS FREE SHIPPING USA ["{com31844}"]   TℰℳU Coupon $300 OFF HOW DOES IT WORK ["{com31844}"]   TℰℳU Coupon $300 OFF FOR EXISTING CUSTOMERS CANADA ["{com31844}"]   TℰℳU Coupon $300 OFF 2025 ["{com31844}"]   TℰℳU Coupon $300 OFF FOR NEW CUSTOMERS ["{com31844}"]   TℰℳU Coupon $300 OFF CANADA ["{com31844}"]   TℰℳU Coupon $300 OFF FOR EXISTING CUSTOMERS FIRST ORDER ["{com31844}"]   TℰℳU 300 OFF COUPON BUNDLE ["{com31844}"]   This TℰℳU coupon $300 off is designed to provide substantial savings on your purchases, making shopping for your favorite items easier than ever. With our $300 off TℰℳU coupon, you'll be amazed at how much you can save on your next order. Here are the key benefits you can expect when using our coupon code {com31844} "OR" {com31844}: {com31844} "OR" {com31844}: Flat $300 off on your purchase {com31844} "OR" {com31844}: $300 coupon pack for multiple uses {com31844} "OR" {com31844}: $300 flat discount for new customers {com31844} "OR" {com31844}: Extra $300 promo code for existing customers {com31844} "OR" {com31844}: $300 coupon exclusively for USA/Canada users H2: TℰℳU Coupon Code $300 Off For New Users In 2024 New users can reap the highest benefits by using our coupon code on the TℰℳU app. This TℰℳU coupon $300 off is specifically designed to welcome new customers with incredible savings  
    • Now the serve runs for a bit, then crashes after 20 minutes of running, what's the issue here? apologies if I need to start a new post and didn't https://pastebin.com/uBpp5bCz  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.