Jump to content

Recommended Posts

Posted

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?

 

Posted

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?

Posted

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);

Posted

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.

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

    • I have used mixins once before, and it was with @At RETURN, so it worked fine. Now im trying to use it as INVOKE, and the compilation is successful, but the client crashes almost on startup (just a couple seconds after running runClient)   Im trying to inject the method finishConversion inside the ZombieVillager class. This is my Mixin class important stuff:   import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.monster.ZombieVillager; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ZombieVillager.class) public class ZombieVillagerCures { @Inject(method = "finishConversion", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/entity/LivingEntity;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;)Z")) private void addZombieVillagerCuredAmmount(ServerLevel level, CallbackInfo info) { System.out.println("The Mixin Worked!!! " + level); } // Lnet/minecraft/world/entity/LivingEntity;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;)Z } I'm sure the issue lies in the @At cuz other @At values work fine. Its probably the fully qualified name thing. idk how to get it in VS code
    • I'm wayy less skilled than you i bet, but maybe u could try to just convert one into the other?
    • wildbackport is not working
    • Through Betafort Recovery, Bitcoin scam victims can retrieve their money. I recommend Betafort Recovery to anyone who has fallen victim to a scam and has been looking for methods and techniques to recover their lost cryptocurrency or wallets. Betafort Recovery is a reliable cryptocurrency recovery firm that assists victims in recovering their stolen cryptocurrency and offers secure solutions to protect your wallets from online scammers. I must admit that I was deeply melancholy and had given up on life until these experts could restore my $23,400 to my wallet. If you've lost your cryptocurrency and you are helpless about it, contact Betafort Recovery to get your money back. One key aspect that makes Betafort Recovery stand out is its focus on providing secure solutions to protect wallets from online scammers. It's not just about recovering lost funds; it's also about preventing future incidents and ensuring that clients' digital assets are safeguarded against potential threats. This proactive approach demonstrates their commitment to the long-term financial security of their clients. Furthermore, for individuals who have lost their cryptocurrency and are feeling helpless, reaching out to Betafort Recovery could be a turning point in their situation. The reassurance that they are legitimate for seeking help and recovering lost funds can provide much-needed relief and a sense of empowerment. Betafort Recovery as a reliable cryptocurrency recovery firm is certainly well-founded. Their ability to assist scam victims in recovering stolen cryptocurrency, their focus on providing secure solutions, and their commitment to supporting clients through challenging situations make them a valuable resource for individuals navigating the complex world of digital currencies. If you or someone you know has fallen victim to a cryptocurrency scam, contacting Betafort Recovery could be the first step towards reclaiming lost funds and regaining peace of mind.  
    • Idk how i didn't notice that, but I deleted it and fixed some other issues and now I get this https://mclo.gs/YsWacqq
  • Topics

×
×
  • Create New...

Important Information

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