Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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

  • Author

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.