Checking for log variations - metadata in 1.7.10

Started by zergmazter on Tue, 08/07/2018 - 03:44

Topic category: General discussion

Last seen on 23:29, 7. Oct 2018
Joined Nov 2014
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
Checking for log variations - metadata in 1.7.10
Tue, 08/07/2018 - 16:22 (edited)

I've googled it, searched the forums here, searched the minecraft forums, and anything I could imagine but there seems to be no info on how to select Birch, Acacia, Dark Oak, etc woods for code.

For example if (event.world.getBlock(X, Y, Z) == Blocks.log), Blocks.log will always assume it's Oak, and there is no way of choosing any of the other ones, that I know of. I spent 8 months trying to make an event handler and I finally did it. This however is beyond me. Without any documentation Im solely dependent on finding random code by chance that actually does what I'm trying to do. Please help me.

Edited by zergmazter on Tue, 08/07/2018 - 16:22
Last seen on 23:58, 10. Nov 2018
Joined Aug 2013
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
  • wiki contributor
  • moderator
The fact that you are using…
Tue, 08/07/2018 - 08:19

The fact that you are using a version before introducing blockstate system makes it kinda messy, but what you want to do is ,after the check for the block itself, checking for a metadata value of the block, that you can get using World#getBlockMetadata() The method takes as arguments the coordinates of the block and returns a value of type int. All you have to do is then to do a check for whatever metadata you need.

Last seen on 23:29, 7. Oct 2018
Joined Nov 2014
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
Omg Thank you Nuparu00!!!! I…
Tue, 08/07/2018 - 22:12

Omg Thank you Nuparu00!!!! I had spent 30 hours trying to find the answer and you just gave me the key. It's all working woohoo! Thanks!!!

Last seen on 23:29, 7. Oct 2018
Joined Nov 2014
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
Ok so everything worked so…
Wed, 08/08/2018 - 03:19

Ok so everything worked so far, but my code is having a bug when I try to place metadata on the

event.world.setBlock(X, Y, Z, Blocks.planks); //Currently Blocks.stone as a place holder//. If I do

event.world.setBlock(X, Y, Z, Blocks.planks,1,0); I get a block update error in the minecraft environment test. I can hear the block being placed but there is no visual update, therefore it still looks like the log:1 block. After doing a quick block update by breaking the neighboring block, then finally planks:1 becomes visible. The code:

		@SubscribeEvent
		public void onBlockRightClicked(PlayerInteractEvent event) {
			if (event.action != PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK)
				return;

			ItemStack heldItem = event.entityPlayer.getHeldItem();
			Block block = event.world.getBlock(event.x, event.y, event.z);

			if (block == Blocks.log && heldItem != null && heldItem.getItem() == Items.wooden_axe) {
				int X = event.x, Y = event.y, Z = event.z;

				if (event.world.getBlockMetadata(X, Y, Z) == 1) {
					event.world.setBlock(X, Y, Z, Blocks.stone);

					if (event.world.getBlock(X, Y, Z) == Blocks.stone) {
						event.world.playSoundEffect((double) X + 0.5D, (double) Y + 0.5D, (double) Z + 0.5D, "dig.wood", 1.0F, 1.0F);

					}
				}
			}

 

Last seen on 23:29, 7. Oct 2018
Joined Nov 2014
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
The bugged code: event…
Wed, 08/08/2018 - 03:21

The bugged code:

event.world.setBlock(X, Y, Z, Blocks.planks,1,0);

 

Last seen on 23:58, 10. Nov 2018
Joined Aug 2013
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
  • wiki contributor
  • moderator
The flag argument in World…
Wed, 08/08/2018 - 07:53

The flag argument in World#setBlock() has to be 3, if you want it to be updated OR you can use the World#setBlock() method, that does not take the flag argument + World#setBlockMetadataWithNotify(), which takes 3 arguments of type int for coordinates, one int for metadata and one int for the flag (again with value 3)

Last seen on 23:29, 7. Oct 2018
Joined Nov 2014
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
Thank you so much Nuparu00 I…
Wed, 08/08/2018 - 16:08

Thank you so much Nuparu00

I'm getting the hang of this. It's all working now. I finally have an idea what those Int are for.