Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Changing Swing Speed
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 1
GravityWolf

Changing Swing Speed

By GravityWolf, September 13, 2013 in Modder Support

  • Start new topic

Recommended Posts

GravityWolf    1

GravityWolf

GravityWolf    1

  • Stone Miner
  • GravityWolf
  • Members
  • 1
  • 98 posts
Posted September 13, 2013

This is my third time doing this, and I hope I get a response this time xD

 

So, basically, I want it so I could change the swing speed, like if you were using a Haste potion effect. (I don't want to do that though, it doesn't give me enough speed options that way) I tried looking in the Potions class, and I found

 

    public static final Potion digSpeed = (new Potion(3, false, 14270531)).setPotionName("potion.digSpeed").setIconIndex(2, 0).setEffectiveness(1.5D);

 

There was nothing else in the code about it, so I took it that 142703531 had something to do with it. If you know anything about it, or have any ideas on it, it would be great if you could let me know! Thanks!

 

~GravityWolf

Share this post


Link to post
Share on other sites

GravityWolf    1

GravityWolf

GravityWolf    1

  • Stone Miner
  • GravityWolf
  • Members
  • 1
  • 98 posts
Posted September 13, 2013

Hope this doesn't count as spam, but I think I made some progress:

 

I found this:

 

if (this.isPotionActive(Potion.digSpeed))
        {
            f *= 1.0F + (float)(this.getActivePotionEffect(Potion.digSpeed).getAmplifier() + 1) * 0.2F;
        }

 

and this:

 

private int getArmSwingAnimationEnd()
    {
        return this.isPotionActive(Potion.digSpeed) ? 6 - (1 + this.getActivePotionEffect(Potion.digSpeed).getAmplifier()) * 1 : (this.isPotionActive(Potion.digSlowdown) ? 6 + (1 + this.getActivePotionEffect(Potion.digSlowdown).getAmplifier()) * 2 : 6);
    }

 

I think these are important, the second one probably more so. They seem to require potion effects, and like I said in the OP, I don't really want to use potion effects. If you have any ideas, let me know! Thanks!

 

~GravityWolf

Share this post


Link to post
Share on other sites

TLHPoE    39

TLHPoE

TLHPoE    39

  • Dragon Slayer
  • TLHPoE
  • Members
  • 39
  • 638 posts
Posted September 13, 2013

Why not look into the Haste effect?

 

 

I think you'd be better off making a pseudo potion item instead of using the vanilla potion class.


Kain

Share this post


Link to post
Share on other sites

lithial13    1

lithial13

lithial13    1

  • Tree Puncher
  • lithial13
  • Members
  • 1
  • 3 posts
Posted September 13, 2013

Are you trying to increase speed for swinging a sword or breaking a block?

if its a block you wanna do this

 

 

	@ForgeSubscribe
// haste
public void onUpdate(PlayerEvent.BreakSpeed event) {
	EntityPlayer e = null;

	if (event.entityLiving instanceof EntityPlayer) {
		e = (EntityPlayer) event.entityLiving;
		if (e == null)
			return;

		final int vigor = EnchantmentHelper.getEnchantmentLevel(effectId, e.getHeldItem());

		if (vigor > 0) {
			event.newSpeed += (2.0F * vigor);

		}
	}
}
}

 

Share this post


Link to post
Share on other sites

GravityWolf    1

GravityWolf

GravityWolf    1

  • Stone Miner
  • GravityWolf
  • Members
  • 1
  • 98 posts
Posted September 13, 2013

Why not look into the Haste effect?

 

 

I think you'd be better off making a pseudo potion item instead of using the vanilla potion class.

 

I would do that, but it swings too fast too quickly. What I mean is Haste 1 gives you increased swing speed, but Haste 2 gives you almost double speed of Haste 1.

 

Are you trying to increase speed for swinging a sword or breaking a block?

if its a block you wanna do this

 

 

	@ForgeSubscribe
// haste
public void onUpdate(PlayerEvent.BreakSpeed event) {
	EntityPlayer e = null;

	if (event.entityLiving instanceof EntityPlayer) {
		e = (EntityPlayer) event.entityLiving;
		if (e == null)
			return;

		final int vigor = EnchantmentHelper.getEnchantmentLevel(effectId, e.getHeldItem());

		if (vigor > 0) {
			event.newSpeed += (2.0F * vigor);

		}
	}
}
}

 

 

I'm looking for sword swing speed.

Share this post


Link to post
Share on other sites

gristly    2

gristly

gristly    2

  • Tree Puncher
  • gristly
  • Members
  • 2
  • 16 posts
Posted September 13, 2013

I'm not sure how to add this, however Dinnerbone has stated that the attribute system will encompass swing speed (as well as bow draw time), so if I were you I might just flesh out the other areas of my mod and hope that the attributes for that come in 1.7 :D

Share this post


Link to post
Share on other sites

GravityWolf    1

GravityWolf

GravityWolf    1

  • Stone Miner
  • GravityWolf
  • Members
  • 1
  • 98 posts
Posted September 14, 2013

I'm not sure how to add this, however Dinnerbone has stated that the attribute system will encompass swing speed (as well as bow draw time), so if I were you I might just flesh out the other areas of my mod and hope that the attributes for that come in 1.7 :D

 

I will use that when that comes out, but for now I think I can utilize the haste effect code.

Share this post


Link to post
Share on other sites

chimera27    5

chimera27

chimera27    5

  • Creeper Killer
  • chimera27
  • Members
  • 5
  • 158 posts
Posted September 14, 2013

Yeah potion effects still seem to be obfuscated (the critical functions for many are things like 'func_902349' and such)

I'd just use a vanilla one with whatever power level you need for now, no real reason why not... also, maybe you could try to find a way to make the sword buff you with like 10 ticks of haste whenever you click with it, that way when they stop clicking the effect would just go away before they could see it


Creator of Metroid Cubed! Power Suits, Beams, Hypermode and more!

width=174 height=100http://i.imgur.com/ghgWmA3.jpg[/img]

Share this post


Link to post
Share on other sites

GravityWolf    1

GravityWolf

GravityWolf    1

  • Stone Miner
  • GravityWolf
  • Members
  • 1
  • 98 posts
Posted September 15, 2013

Got it to work using this:

 

public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5) {

	if(entity instanceof EntityPlayer) {

		EntityPlayer player = (EntityPlayer) entity;
            ItemStack equipped = player.getCurrentEquippedItem();
            
            if(equipped == stack) {
            	
            	if(player.isSwingInProgress) {
            	
            	if(swingSpeed == 0) {
            		
            	} else if (swingSpeed == 1) {
            		
                	player.addPotionEffect(new PotionEffect(Potion.digSpeed.id, 1, 0));
            		
            	} else if (swingSpeed == 2) {
            		
                	player.addPotionEffect(new PotionEffect(Potion.digSpeed.id, 1, 1));
            		
            	} else if (swingSpeed == 3) {
            		
            		player.addPotionEffect(new PotionEffect(Potion.digSpeed.id, 1, 2));
            		
            	} else if (swingSpeed == -1) {
            		
                	player.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, 1, 0));
            		
            	} else if (swingSpeed == -2) {
            		
                	player.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, 1, 1));
            		
            	} else if (swingSpeed == -3) {
            		
                	player.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, 1, 2));
                	
            	} else if (swingSpeed == -4) {
            		
            		player.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, 1, 3));
            		
            	}
            	
            	}
            }

	}

}

 

SwingSpeed is my own custom variable, just btw

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • diesieben07
      [1.16] Large collision box is not working correctly

      By diesieben07 · Posted 1 minute ago

      Correct, blocks cannot go beyond 1x1x1. If you want to make something bigger, you need to have multiple blocks.
    • diesieben07
      The item given to the player disappears

      By diesieben07 · Posted 2 minutes ago

      No, you always need context information. Otherwise how would you know which player it is.
    • diesieben07
      [1.16.4] Creating Sub items through NBT from config

      By diesieben07 · Posted 4 minutes ago

      No. This is intentional, as registration should not depend on configs.
    • BeardlessBrady
      [1.16.4] Creating Sub items through NBT from config

      By BeardlessBrady · Posted 12 minutes ago

      Hello, I am trying to create sub items through NBT by pulling information from the config file. My issue is that it seems like the items are being registered before the config is processed, is there a way to make the config get processed first?   My Code for reference: https://github.com/Beardlessbrady/Currency-Mod/tree/master-1.16/src/main
    • Aviator737
      [1.16] Large collision box is not working correctly

      By Aviator737 · Posted 14 minutes ago

      I made test 3x3 collision. For convenience, I have marked with colors the areas of the cube (see screenshots). Bounding box shows up correctly but collision works strange. I can't fly horizontally through yellow blocks but I can fall through them. Сorner blocks (red) don't work at all. And I can't fall or walk into blue area.  Forge 1.16.5 -  35.1.37 public class TestTileEntityBlock extends TileEntityBlock<TestTileEntity> { private static final VoxelShape SHAPE = makeCuboidShape(-16, -16, -16, 32, 32, 32); public TestTileEntityBlock(Properties properties) { super(properties); } @Override public TileEntity createTileEntity(BlockState state, IBlockReader world) { return new TestTileEntity(); } @SuppressWarnings("deprecation") @Override public VoxelShape getCollisionShape(final BlockState state, final IBlockReader world, final BlockPos pos, final ISelectionContext context) { return SHAPE; } @SuppressWarnings("deprecation") @Override public VoxelShape getShape(final BlockState state, final IBlockReader world, final BlockPos pos, final ISelectionContext context) { return SHAPE; } }
  • Topics

    • Aviator737
      1
      [1.16] Large collision box is not working correctly

      By Aviator737
      Started 14 minutes ago

    • Hubmac
      3
      The item given to the player disappears

      By Hubmac
      Started 1 hour ago

    • BeardlessBrady
      1
      [1.16.4] Creating Sub items through NBT from config

      By BeardlessBrady
      Started 12 minutes ago

    • Seika85
      0
      [1.16.5-forge-36.0.43] Error: "Failed to synchronize registry data, closing connection"

      By Seika85
      Started 15 minutes ago

    • Deadlocked47
      0
      Can't get into forge discord

      By Deadlocked47
      Started 24 minutes ago

  • Who's Online (See full list)

    • diesieben07
    • JackRaidenPH
    • Seika85
    • loordgek
    • BeardlessBrady
    • Coloringgamer
    • Maliksandgreen11
    • Aviator737
    • Hubmac
    • PumpkiinMochaa
    • Zeronota
    • Talp1
    • FREyebeans2506
    • lupicus
    • Deadlocked47
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Changing Swing Speed
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community