alex210982 Posted January 12, 2016 Posted January 12, 2016 Hi, I'm wondering if someone can help me. I would like to create a recipe that will allow players to create indestructible items. The same way this command works "/give @a minecraft:diamond_sword 1 0 {Unbreakable:1}" In this command it sets the tag "Unbreakable" to 1. I believe that there must be a way to do this from within the code. This is what i have tried so far. [embed=425,349] ItemStack unbreakableSword = new ItemStack(Items.diamond_sword, 1); setUnbreakable(unbreakableSword); System.out.println("done"); GameRegistry.addRecipe(unbreakableSword, "ABA", "ACA", "ADA", 'A', Blocks.diamond_block, 'B', Items.magma_cream, 'C', Items.ender_eye, 'D', Items.diamond_sword); private static void setUnbreakable(ItemStack unbreakableItem) { NBTTagCompound tag1 = new NBTTagCompound(); tag1.setInteger("Unbreakable", 1); unbreakableItem.setTagCompound(tag1); }[/embed] Thank you In advance. Quote
deerangle Posted January 12, 2016 Posted January 12, 2016 I did this before... just overwrite the items code, where is looses durability, to loose 0 durability: package com.yourmod.main; import net.minecraft.block.Block; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; import net.minecraft.world.World; public class ItemNoDamage extends ItemSword{ public ItemNoDamage(ToolMaterial mat) { super(mat); } @Override public boolean hitEntity(ItemStack item, EntityLivingBase entity, EntityLivingBase player) { item.damageItem(0, player); return true; } @Override public boolean onBlockDestroyed(ItemStack item, World world, Block block, int x, int y, int z, EntityLivingBase player) { if ((double)block.getBlockHardness(world, x, y, z) != 0.0D) { item.damageItem(0, player); } return true; } } Quote
alex210982 Posted January 12, 2016 Author Posted January 12, 2016 Ah thank you. I was hoping to avoid overriding existing class items but if that is the only way ill do that. Thank you again. Quote
jeffryfisher Posted January 12, 2016 Posted January 12, 2016 I suspect that the addRecipe method scrubs away NBT tags, leaving only item and its "damage" (metadata). You might be able to inject your NBT tag from a crafting event. While you're at it, you could define an achievement and award it in the same event handler. Search for tutorials on crafting achievements (there are several). Quote The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.
alex210982 Posted March 7, 2016 Author Posted March 7, 2016 Hi, Overriding the basic item worked beautifully with one problem. I had hoped that it would continue to use the texture already set for that item. However it does not. The current texture is the basic pink and black square. Is there any way that i can get it to use the basic texture? I have tried the .setTextureName method inside the constructor (of the indestructible item) but it says that the method does not exist. Thank you in advance. Quote
Cerandior Posted March 7, 2016 Posted March 7, 2016 Setting the texture for your item would be different depending on the forge version you are using. 1.8 uses json files to set up rendering for items/blocks On 1.7 you can directly set the item texture from the item's class. It's been a while since i last used 1.7 to do anything, i forgot the method's name. It should be something along the lines of " item.setTexture " Quote
alex210982 Posted March 7, 2016 Author Posted March 7, 2016 It is forge 1.8. setTexture does not exist. I saw the json files and thought that might be it. How would i set them to use textures of another item? Quote
Cerandior Posted March 7, 2016 Posted March 7, 2016 It is forge 1.8. setTexture does not exist. I saw the json files and thought that might be it. How would i set them to use textures of another item? Yes there is no such method for items or blocks in 1.8 Follow this guide by bedrockminer: http://bedrockminer.jimdo.com/modding-tutorials/basic-modding-1-8/first-item/ That's how you set up textures for an item. Don't follow that guide for blocks however, as blocks have a different way of rendering. Here is the guide for blocks: http://bedrockminer.jimdo.com/modding-tutorials/basic-modding-1-8/first-block/ Quote
alex210982 Posted March 7, 2016 Author Posted March 7, 2016 Thanks Cerandior I have already looked at those tutorials. They allow you to use custom textures for your items and you put them into your mod folders as required. The problem with this is that if i were to load a texture pack that has not replaced that specific texture then it will not change. Specifically i have Indestructible items (as the post above helped with) but i want to reference the destructible item when looking for its textures. For example, i want my indestructible sword to use the same texture as a diamond sword no matter what texture pack you use. So somewhere it tells the system to look in assets.mymod.textures.items for the png with my items name (swordIndestructible) i want to tell it instead to look for a texture with the name "diamond_sword". I can't seem to find that code to override or change it? Quote
Choonster Posted March 7, 2016 Posted March 7, 2016 Use ModelLoader.setCustomModelResourceLocation / ModelLoader.setCustomMeshDefinition in preInit to set the model used by an Item . This can either be an existing model like minecraft:diamond_sword or your own model that uses the same textures as the existing one ( minecraft:items/diamond_sword ). Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
alex210982 Posted March 8, 2016 Author Posted March 8, 2016 Thank you again, I have tried every combination of: ModelLoader.setCustomModelResourceLocation(Main.unbreakableSword, 0, new ModelResourceLocation ("minecraft:items/diamond_sword", "inventory")); That I can think off and it is still not loading the model for the item. When i try to include: ModelLoader.setCustomMeshDefinition(Main.unbreakableSword, new ItemMeshDefinition() { @Override public ModelResourceLocation getModelLocation(ItemStack stack) { // TODO Auto-generated method stub return null; } }); I have tried to get the model from Items.diamond_Sword but have been unsuccessful in getting the model to be used? If you could give an example of the correct format for these methods I would very much appreciate it. Thanks Quote
Choonster Posted March 8, 2016 Posted March 8, 2016 In the first code block, you're using the wrong location for the model. ModelBakery.registerItemVariants , ModelLoader.setCustomModelResourceLocation and ModelLoader.setCustomMeshDefinition / ItemMeshDefinition all expect the ModelResourceLocation 's domain and path to be in the format modid:modelName , which either maps to the assets/<modid>/models/item/<modelName>.json item model or the model specified in the assets/<modid>/blockstates/<modelName>.json blockstates file (this is added by Forge and only used when the item model isn't found). In this case, use minecraft:diamond_sword (i.e. the assets/minecraft/models/item/diamond_sword.json model) instead of minecraft:items/diamond_sword (this is the texture path used in the minecraft:diamond_sword model, not a model path). If you use ItemMeshDefinition , you must actually return the appropriate ModelResourceLocation from the getModelLocation method rather than returning null . I use vanilla models for several of my mod's items here. There are several chained overloads of registerItemModel , but they all boil down to calling ModelBakery.registerItemVariants with the specified ModelResourceLocation and calling ModelLoader.setCustomMeshDefinition with an ItemMeshDefinition that returns a single constant ModelResourceLocation . Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
Recommended Posts
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.