Jump to content

Recommended Posts

Posted

Hey guys,

I managed to find the arrows I am looking for. My problem right now is that I am having problems to find the block the arrow is stuck to, from the EntityArrow. I got this right now, but my way of finding the correct BlockPos is.. total bullshit :'D

 

@SubscribeEvent
public void worldTick(WorldTickEvent event)
{
		for (Object obj : event.world.loadedEntityList) {
		if(obj instanceof EntityArrow)
		{

			NBTTagCompound compound = new NBTTagCompound();
			EntityArrow arrow = (EntityArrow) obj;
			arrow.writeToNBT(compound);

			if(compound.getByte("inGround")==(byte)1)
			{
				compound = arrow.getEntityData();
				if(!compound.getBoolean("checked"))
				{
					BlockPos pos = new BlockPos(Math.floor(arrow.posX),Math.floor(arrow.posY),Math.floor(arrow.posZ));
					event.world.setBlockState(pos ,Blocks.iron_ore.getDefaultState());
					compound.setBoolean("checked", true);
					arrow.setDead();
				}
			}
		}
	}
}

Posted

nevermind. just found out what the tiles mean.

For anyone who cares.

The boolean flag is because setDead would make it tick one more time, so i set a checked flagg

 


@SubscribeEvent
public void worldTick(WorldTickEvent event)
{

	for (Object obj : event.world.loadedEntityList) {
		if(obj instanceof EntityArrow)
		{


			EntityArrow arrow = (EntityArrow) obj;
			try {
				Field tileY = EntityArrow.class.getDeclaredField("yTile");
				tileY.setAccessible(true);
				if(tileY.getInt(arrow)==-1) continue;
				NBTTagCompound compound = arrow.getEntityData();
				if(!compound.getBoolean("checked"))
				{
					Field tileX = EntityArrow.class.getDeclaredField("xTile");
					Field tileZ = EntityArrow.class.getDeclaredField("zTile");
					tileX.setAccessible(true);
					tileZ.setAccessible(true);
					System.out.println(tileX.getInt(arrow));
					System.out.println(tileZ.getInt(arrow));
					System.out.println(tileY.getInt(arrow));
					BlockPos pos = new BlockPos(tileX.getInt(arrow), tileY.getInt(arrow), tileZ.getInt(arrow));
					event.world.setBlockState(pos ,Blocks.iron_ore.getDefaultState());
					//compound.setBoolean("checked", true);
					arrow.setDead();

				}
			} catch (Exception e) {

				e.printStackTrace();

			}


		}
	}
}

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.