Posted October 23, 20186 yr Hello, so I'm trying to make a new material with tools that get random bonus attributes when crafted. I'm starting with the sword, which can get a bonus 1-3 damage when crafted. My problem is that, whenever I craft them, the damage of all the previous swords changes too. This is my code: public class ToolSword extends ItemSword implements IHasModel{ private Random rand; private int bonusDamage; public ToolSword(String name, ToolMaterial material){ super(material); setUnlocalizedName(name); setRegistryName(name); setCreativeTab(CreativeTabs.COMBAT); rand = new Random(); bonusDamage = 0; ModItems.ITEMS.add(this); } @Override public void registerModels() { Main.proxy.registerItemRenderer(this, 0, "inventory"); } @Override public void onCreated(ItemStack stack, World worldIn, EntityPlayer playerIn){ bonusDamage = rand.nextInt(3) + 1; } @Override public Multimap<String, AttributeModifier> getAttributeModifiers(EntityEquipmentSlot slot, ItemStack stack) { final Multimap<String, AttributeModifier> modifiers = super.getAttributeModifiers(slot, stack); if (slot == EntityEquipmentSlot.MAINHAND) { replaceModifier(modifiers, SharedMonsterAttributes.ATTACK_DAMAGE, ATTACK_DAMAGE_MODIFIER, bonusDamage); } return modifiers; } private void replaceModifier(Multimap<String, AttributeModifier> modifierMultimap, IAttribute attribute, UUID id, double amount) { // Get the modifiers for the specified attribute final Collection<AttributeModifier> modifiers = modifierMultimap.get(attribute.getName()); // Find the modifier with the specified ID, if any final Optional<AttributeModifier> modifierOptional = modifiers.stream().filter(attributeModifier -> attributeModifier.getID().equals(id)).findFirst(); if (modifierOptional.isPresent()) { // If it exists, final AttributeModifier modifier = modifierOptional.get(); modifiers.remove(modifier); // Remove it modifiers.add(new AttributeModifier(modifier.getID(), modifier.getName(), modifier.getAmount() + amount, modifier.getOperation())); // Add the new modifier } } } I did try using stack.addAttributeModifier which kept each item with its unique value. However, it completely replaces the old damage and attack speed values and the Sharpness enchantment no longer has effect on it, so I don't like using this command because I still want Sharpness to increase its damage even more. Any help?
October 23, 20186 yr Items are singletons (there is only 1 of the ever) if you want damage etc. you have to apply that stuff to the ItemStacks About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
October 23, 20186 yr Author 6 minutes ago, Cadiboo said: Items are singletons (there is only 1 of the ever) if you want damage etc. you have to apply that stuff to the ItemStacks I also tried that, but the original attributes all get removed, but I just want to add additional damage, while keeping the original one and the original attack speed. This is what I tried: @Override public void onCreated(ItemStack stack, World worldIn, EntityPlayer playerIn){ bonusDamage = rand.nextInt(3) + 9; stack.addAttributeModifier(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier("Weapon modifier", bonusDamage, 0), EntityEquipmentSlot.MAINHAND); } It says "add" but it doesn't really add, it replaces the old ones, which I don't want.
October 23, 20186 yr there is a ItemStack sensitive variant of addAttributeModifier. not sure if this fixes that but at least it's what I used for something similar My Projects: Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming) Important: As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts
October 23, 20186 yr You should probably be using a capability on the ItemStack and subscribe to an attack entity event, and add extra damage based on that capability About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
October 23, 20186 yr You need to store the additional value to your ItemStack's NBT data or a capability, then override Item#getAttributeModifiers and make the damage attribute add the itemDamage + yourDamage as the modifier. See how ItemSword does that. Edit: Thanks for @Animefan8888 for correcting my mistake, whoops, had ItemStack written as the base class instead of Item. Edited October 23, 20186 yr by V0idWa1k3r
October 23, 20186 yr 1 hour ago, V0idWa1k3r said: Edit: Thanks for @Animefan8888 for correcting my mistake, whoops No problem.? Edited October 23, 20186 yr by Animefan8888 VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
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.