Posted October 4, 201311 yr 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?
October 4, 201311 yr Author 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?
October 5, 201311 yr 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);
October 5, 201311 yr Author 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.
October 5, 201311 yr Author Fixed. Problem solved. Good call. Don't know how I missed it.. i have to get more sleep.
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.