How can I change my weapons's attack speed ?

Started by JojoMichelDu59 on

Topic category: Advanced modding

Joined Mar 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How can I change my weapons's attack speed ?

Hello, I'm wantng to create a dagger, wich can attack very quickly but has low damage per attack. Where is the code line for changing this please ?

Note : I'm using MCreator 1.8.1

I think that the method you…
Mon, 02/25/2019 - 15:36

I think that the method you are looking for is:

public int getMaxItemUseDuration(ItemStack stack){
        return 0;
}

And update your MCreator to 1.8.2, we don't support 1.8.1 anymore.

Joined Mar 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I just updated to 1.8.2. But…
Mon, 02/25/2019 - 17:47

I just updated to 1.8.2. But where do I need to put this line ? And what do I need to change in this line to get a custom attack speed ?

Joined Mar 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You did not answered my…
Mon, 02/25/2019 - 18:23

You did not answered my questions. Plus, I tryed to experiment with that, but it didn't do anything.

You most likely did not…
Mon, 02/25/2019 - 19:17

You most likely did not place it in the right place. You need to place it inside this part:

block=(Item)(new ItemToolCustom(){

other code

....

    public int getMaxItemUseDuration(ItemStack stack){
            return 0;
    }

}

 

Joined Mar 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I still don't understand…
Mon, 02/25/2019 - 20:11

I still don't understand where do you want me to put it in.

Just tell me under what line I need to put it :

package mod.mcreator;

import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.common.util.EnumHelper;

import net.minecraft.item.ItemSword;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.Minecraft;

import java.util.Set;
import java.util.HashMap;

public class mcreator_dagger extends extra_vanilla.ModElement {

	public static Item block;
	static {
		Item.ToolMaterial enumt = EnumHelper.addToolMaterial("DAGGER", 1, 600, 4, 4, 2);
		block = (Item) (new ItemSword(enumt) {
			public Set<String> getToolClasses(ItemStack stack) {
				HashMap<String, Integer> ret = new HashMap<String, Integer>();
				ret.put("sword", 1);
				return ret.keySet();
			}
		}).setUnlocalizedName("dagger");
		block.setRegistryName("dagger");
		block.setCreativeTab(mcreator_extraVanilla.tab);
		ForgeRegistries.ITEMS.register(block);
	}
	
	@Override
	public void load(FMLInitializationEvent event) {
		if (event.getSide() == Side.CLIENT) {
			Minecraft.getMinecraft().getRenderItem().getItemModelMesher()
					.register(block, 0, new ModelResourceLocation("extra_vanilla:dagger", "inventory"));
		}
	}
}

 

OK, you actually need…
Mon, 02/25/2019 - 20:35

OK, you actually need different method, new example. Change:

block = (Item) (new ItemSword(enumt) {
			public Set<String> getToolClasses(ItemStack stack) {
				HashMap<String, Integer> ret = new HashMap<String, Integer>();
				ret.put("sword", 1);
				return ret.keySet();
			}
		}).setUnlocalizedName("dagger");

to

block = (Item) (new ItemSword(enumt) {
			public Set<String> getToolClasses(ItemStack stack) {
				HashMap<String, Integer> ret = new HashMap<String, Integer>();
				ret.put("sword", 1);
				return ret.keySet();
			}

@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, 2);
		replaceModifier(modifiers, SharedMonsterAttributes.ATTACK_SPEED, ATTACK_SPEED_MODIFIER, 1.5);
	}
	return modifiers;
}

private void replaceModifier(Multimap<String, AttributeModifier> modifierMultimap, IAttribute attribute, UUID id, double multiplier) {
	final Collection<AttributeModifier> modifiers = modifierMultimap.get(attribute.getAttributeUnlocalizedName());
	final Optional<AttributeModifier> modifierOptional = modifiers.stream().filter(attributeModifier -> attributeModifier.getID().equals(id)).findFirst();
	if (modifierOptional.isPresent()) {
		final AttributeModifier modifier = modifierOptional.get();
		modifiers.remove(modifier);
		modifiers.add(new AttributeModifier(modifier.getID(), modifier.getName(), modifier.getAmount() * multiplier, modifier.getOperation()));
	}
}

		}).setUnlocalizedName("dagger");

These two lines change the modifier:

replaceModifier(modifiers, SharedMonsterAttributes.ATTACK_DAMAGE, ATTACK_DAMAGE_MODIFIER, 2);
replaceModifier(modifiers, SharedMonsterAttributes.ATTACK_SPEED, ATTACK_SPEED_MODIFIER, 1.5);

Keep in mind that you need proper imports too (use the Reformat code button in code editor to do this).

If you can't understand where to put this code, I suggest you to learn some code first as custom coding can result in build errors if done wrong.

Joined Mar 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I give up. There should be…
Tue, 02/26/2019 - 11:58

I give up. There should be an attack speed option when creating a tool with MCreator.

Joined Dec 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I mean you did but it doesn…
Wed, 11/18/2020 - 14:24

I mean you did but it doesn’t work ngl