Jump to content

Recommended Posts

Posted (edited)

Okay, so I'm trying to figure out what event, or how to even do something that will allow an enchantment I've thought of; Stepping. It would allow the player (when their boots are enchanted with this) to step up blocks at level 1 and 2, and walk on water and lava at level 2.

 

Would this be done with an event, or...? I've got the code all ready to go, I just don't know where to put it.

 

EDIT: I'm not even sure the title of this thread is appropriate for what I'm trying to do...

Edited by blahblahbal
Posted

I actually already have the stepping/water walking code. I'm just trying to figure out how to actually run it while the player has boots that are enchanted with this enchantment equipped. I tried onLivingUpdate, but that broke the whole thing.

Posted
@SubscribeEvent
	public void onLivingUpdate(LivingEvent event)
	{
		if (event.entityLiving instanceof EntityPlayer)
		{
			EntityPlayer player = (EntityPlayer)event.entityLiving;
			if (EnchantmentHelper.getEnchantments(player.getCurrentArmor(3)).containsValue(86))
			{
				if (EnchantmentHelper.getEnchantmentLevel(86, new ItemStack(player.getCurrentArmor(3).getItem())) == 2)
				{
					if (player.worldObj.isRemote)
					{
						int x = (int) Math.floor(player.posX);
						int y = (int) (player.posY - player.getYOffset());
						int z = (int) Math.floor(player.posZ);
						BlockPos pos = new BlockPos(x, y, z);

						Block b = player.worldObj.getBlockState(pos.down()).getBlock();

						if ((b == Blocks.lava || b == Blocks.flowing_lava || b == Blocks.water || b == Blocks.flowing_water) && player.worldObj.isAirBlock(pos))
						{
							if (!player.isSneaking())
							{
								player.motionY = 0.0d;
								player.fallDistance = 0.0f;
								player.onGround = true;
							}
						}
					}
		        }
				if ((!player.capabilities.isFlying) && (player.moveForward > 0.0F))
			    {
					if ((player.worldObj.isRemote) && (!player.isSneaking()))
			    	{
						if (!PlayerEvents.INSTANCE.prevStep.containsKey(Integer.valueOf(player.getEntityId())))
						{
							PlayerEvents.INSTANCE.prevStep.put(Integer.valueOf(player.getEntityId()), Float.valueOf(player.stepHeight));
						}
						player.stepHeight = 1.0F;
			    	}
			    }
			}
		}
	}

Here it is. I have it in my ModEventHandler class.

Posted
1 hour ago, blahblahbal said:

if (EnchantmentHelper.getEnchantments(player.getCurrentArmor(3)).containsValue(86))

Ew. Absolutely ew.

Contains value 86? Really? You couldn't use an actual enchantment instance?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)
1 hour ago, blahblahbal said:

I could have, yes, but why do that when it's longer and less direct? Plus, I looked at the vanilla code for the getEnchantments method and it simply saves the id and level.

Because you are not the same person when you get back to the code some time later and you'll wonder what was it. Readability is that important.

Also the id is subjected to change on

is important.

Also the id is subjected to change on MC version update, so using the instance is better as at least it will give you some errors if the reference got changed. Chances are instance based code will work on the ID change.

EDIT: Was it your own enchantment? If it's the case, you just can't use the if, it is highly subjected to change.

Edited by Abastro
See EDIT

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

Not to mention if someone else registers an enchantment before you do.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Alright, I see your point. Regardless, this isn't the reason why the code isn't working. I don't know why we're discussing something that has nothing to do with why the code isn't working.

Posted

I've changed the Event to a TickEvent, but it still doesn't seem to work. I'm still using the hardcoded value of 86, but will change it when I get it working. I did notice that the ID is stored as the Key, not the Value, so I changed containsValue to containsKey.

	@SubscribeEvent
	public void playerTick(TickEvent.PlayerTickEvent event)
	{
		if (event.phase == TickEvent.Phase.END) // && event.side == Side.SERVER)
		{
			EntityPlayer player = (EntityPlayer)event.player;
			if (player.inventory.armorInventory[3] != null)
			{
				if (EnchantmentHelper.getEnchantments(player.getCurrentArmor(3)).containsKey(86))
				{
					if (EnchantmentHelper.getEnchantmentLevel(86, new ItemStack(player.getCurrentArmor(3).getItem())) == 2)
					{
						if (player.worldObj.isRemote)
						{
							int x = (int) Math.floor(player.posX);
							int y = (int) (player.posY - player.getYOffset());
							int z = (int) Math.floor(player.posZ);
							BlockPos pos = new BlockPos(x, y, z);

							Block b = player.worldObj.getBlockState(pos.down()).getBlock();

							if ((b == Blocks.lava || b == Blocks.flowing_lava || b == Blocks.water || b == Blocks.flowing_water) && player.worldObj.isAirBlock(pos))
							{
								if (!player.isSneaking())
								{
									player.motionY = 0.0d;
									player.fallDistance = 0.0f;
									player.onGround = true;
								}
							}
						}
			        }
					if ((!player.capabilities.isFlying) && (player.moveForward > 0.0F))
				    {
						if ((player.worldObj.isRemote) && (!player.isSneaking()))
				    	{
							if (!PlayerEvents.INSTANCE.prevStep.containsKey(Integer.valueOf(player.getEntityId())))
							{
								PlayerEvents.INSTANCE.prevStep.put(Integer.valueOf(player.getEntityId()), Float.valueOf(player.stepHeight));
							}
							player.stepHeight = 1.0F;
				    	}
				    }
				}
			}
		}
	}

I know it's getting to at least the containsKey call because I had forgotten the null check and it errored.

Posted
1 hour ago, blahblahbal said:

if (EnchantmentHelper.getEnchantmentLevel(86, new ItemStack(player.getCurrentArmor(3).getItem())) == 2)

You're making a NEW itemstack, with the item from the itemstack you've already gained...

Of course it is not gonna have an enchantment on it, unless you actually add one manually to that new itemstack

Just use the itemstack you get from getCurrentArmor instead of making a new one

  • Like 1

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Posted (edited)

...Derp. That's fixed. But something else must be wrong, because it still doesn't work.


EDIT: Nevermind, I had the wrong index on the getCurrentArmor call. And all the other things where the index is needed.

Edited by blahblahbal

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



×
×
  • Create New...

Important Information

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