Jump to content

[1.6.2] Problem with capabilities.setPlayerWalkSpeed


dncwalk99

Recommended Posts

I keep getting a NoSuchMethod crash when I equip a piece of armor that is meant to adjust the players walk speed.  I'm setting the speed in my event handler class.  Is this the correct place to do it? Is there another way?

 

	@ForgeSubscribe
public void onLivingUpdateEvent(LivingUpdateEvent event)
{
	if (event.entity instanceof EntityPlayer)
	{
		EntityPlayer player = (EntityPlayer) event.entity;

		ItemStack helm = player.getCurrentItemOrArmor(4);
		ItemStack chest = player.getCurrentItemOrArmor(3);
		ItemStack legs = player.getCurrentItemOrArmor(2);
		ItemStack boots = player.getCurrentItemOrArmor(1);

		if (helm != null && helm.itemID == GaiaMod.GaiaHelm.itemID)
		{
			player.setAir(300);
			player.getFoodStats().addStats(20,5.0F);
		}
		else if (helm != null && helm.itemID == GaiaMod.OmegaHelm.itemID)
		{
			player.setAir(300);
			player.getFoodStats().addStats(20,5.0F);
		}
		else
		{

		}

		if (chest != null && chest.itemID == GaiaMod.GaiaChest.itemID)
		{
			player.capabilities.allowFlying = true;
		}
		else if (chest != null && chest.itemID == GaiaMod.OmegaChest.itemID)
		{
			player.capabilities.allowFlying = true;
		}
		else
		{
			player.capabilities.allowFlying = false;
			player.capabilities.isFlying = false;
			player.sendPlayerAbilities();
		}

		if (legs != null && legs.itemID == GaiaMod.GaiaLeggings.itemID)
		{

			player.capabilities.setPlayerWalkSpeed(0.2F);
			player.jumpMovementFactor = .05F;
		}
		else if (legs != null && legs.itemID == GaiaMod.OmegaLeggings.itemID)
		{
			player.capabilities.setPlayerWalkSpeed(0.2F);
			player.jumpMovementFactor = .05F;
		}
		else
		{
			player.capabilities.setPlayerWalkSpeed(.1F);
			player.sendPlayerAbilities();
		}



		if (boots != null && boots.itemID == GaiaMod.GaiaBoots.itemID)
		{
			player.fallDistance = 0.0F;
			player.stepHeight = 1.0F;

		}
		else if (boots != null && boots.itemID == GaiaMod.OmegaBoots.itemID)
		{
			player.fallDistance = 0.0F;
			player.stepHeight = 1.0F;

		}
		else
		{

		}
	}
}

 

 

And yes.. OP armor is OP.  Not the final product.. just using extreme numbers to quickly verify if things work.

 

Any ideas?

 

Link to comment
Share on other sites

GotoLink, you're right again.  But from the forum posts about changing attributes I've managed to confuse myself.  It's not imperative that I have this in my mod, but I'll keep trying to figure it out.  If you feel like giving up a small example with a breakdown.. I and I'm sure others would appreciate it. 

 

Here's what I've done:

 

AttributeInstance attributeinstance = player.getEntityAttribute(SharedMonsterAttributes.movementSpeed);
			attributeinstance.setAttribute(attributeinstance.getBaseValue()*3.5D);

 

It kind of works.  I get the speed, but the screen keeps jerking as though I keep sprinting off and on. 

 

Any thoughts?

Link to comment
Share on other sites

By using setAttribute, and getBaseValue() you are overwriting any modifiers already existing, potion effects for the most part.

 

Here is how i do it in the LevelUp! mod update:

AttributeInstance atinst = player.getEntityAttribute(SharedMonsterAttributes.movementSpeed);//enter the attribute speed without triggering any calculation
		AttributeModifier mod;
		skill = getSkill(player,6);//consider this a whatever value you want
		if(skill!=0)
		{
//Here is the modifier we want to apply, the speedID needs to be unique (!= from any other speed modifier id)
//see func_111129_g() in ModifiableAttributeInstance to understand what the values do
//in this case, the modifier will do speed*=1+skill/100, where "speed" is a intermediate calculated value with previous modifiers
			mod = new AttributeModifier(speedID,"SprintingSkillSpeed",skill/100F,2);
			if(player.isSprinting())//we apply when conditions are met
			{
				if(atinst.getModifier(speedID) == null)//you'll get a crash if you apply twice the same modifier, thus we check with the unique modifier id
				{
					atinst.applyModifier(mod);
				}
			}
			else if(atinst.getModifier(speedID) != null)//we remove when conditions are not met
			{
				atinst.removeModifier(mod);
			}

Here is a suggested modifier for your case:

new AttributeModifier(wtvID,"MySpeedModifier",2.5,2);

Link to comment
Share on other sites

Well.. no more jerking, but I get a crash.  I saw the part about setting the modifier twice, and i dont think im doing that.  Getting nullpointerexception.

 

Error:

 

---- Minecraft Crash Report ----
// Why did you do that?

Time: 10/5/13 1:55 PM
Description: Saving entity NBT

java.lang.NullPointerException
at net.minecraft.entity.SharedMonsterAttributes.func_111262_a(SharedMonsterAttributes.java:72)
at net.minecraft.entity.SharedMonsterAttributes.func_111261_a(SharedMonsterAttributes.java:56)
at net.minecraft.entity.SharedMonsterAttributes.func_111257_a(SharedMonsterAttributes.java:31)
at net.minecraft.entity.EntityLivingBase.writeEntityToNBT(EntityLivingBase.java:516)
at net.minecraft.entity.player.EntityPlayer.writeEntityToNBT(EntityPlayer.java:1004)
at net.minecraft.entity.player.EntityPlayerMP.writeEntityToNBT(EntityPlayerMP.java:213)
at net.minecraft.entity.Entity.writeToNBT(Entity.java:1592)
at net.minecraft.server.integrated.IntegratedPlayerList.writePlayerData(IntegratedPlayerList.java:33)
at net.minecraft.server.management.ServerConfigurationManager.saveAllPlayerData(ServerConfigurationManager.java:886)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:598)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:134)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:487)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)

 

Code:

 

if (legs != null && legs.itemID == GaiaMod.GaiaLeggings.itemID)
		{
			if(atinst.getModifier(wtvID) == null)
			{
				atinst.applyModifier(mod);
				player.jumpMovementFactor = .05F;
			}
		}
		else if (legs != null && legs.itemID == GaiaMod.OmegaLeggings.itemID)
		{
			if(atinst.getModifier(wtvID) == null)
			{
				atinst.applyModifier(mod);
				player.jumpMovementFactor = .05F;
			}
		}
		else 
		{
			if(atinst.getModifier(wtvID) != null)
			{
				atinst.removeModifier(mod);
			}
		}

 

It happens after a minute or so and nothing is really standing out to me as being wrong.

 

Confirmed. Happens when the world saves.

Link to comment
Share on other sites

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

    • Hi I have an issue with a server it solved deleting the ice and fire but my friends and me really want to use it does any of these mods are causing the issue due to incompatibility  Security craft Aquaculture Architectury Artifacts Astikorcarts Baubles BetterCaves yungs BetterStrongholds yungs BetterMineshafts yungs Bountiful Byg  Callablehorses Carry on Chococraft Citadel Clumps Collective Comforts Corailrecycler Craftable horse armor Comes alive Curios forge Decocraft Dungeonsarise  Open blocks elevator Expandability Farlanders Goblin traders Hwyla  Ice and fire Infernal expansion Jei Jump over fences Mantle  Macaws bridges Macaws doors Macaws fences Macaws furniture  Macaws fencesbyg Morpheus Mouse tweaks Mowzies mobs Obfuscate Paraglider Patchouli  Pick up notifier Random village names Spartan shields Small ships Sophisticated backpacks Spartan weaponry Storage drawers straw golem Structure gel Twilight forest  Tinkers construct Two players one horse  Valhesia core  Valhesia structures  Way stones  Vehicle mod  Wall jump Wings Wolves with armor Xptome  Xaeros minimap  Yungsapi  
    • { "type": "magic_overhaul:rune_inscribing", "base": { "item": "//base item" }, "template": { "item": "//template item" }, "output": { "count": 1, "item": "//output item" } } ^ Ok, where is your recipe JSON placed in your file structure? What's it called? And paste the actual JSON you're testing with, because it needs to be valid.
    • I'm trying to run Forge 1.12.2 on Minecraft  so I can use certain mods, but this error popped up. I've seen multiple errors but I just can't figure this one out. Unable to locate the Java runtime. Error details: 0x00000000 - system: The operation completed successfully. Filename on disk:  Path: . Exists: Directory
    • https://mclo.gs/b422RFc
    • Плагин и Приват
  • Topics

×
×
  • Create New...

Important Information

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