Checking for log variations - metadata in 1.7.10

Started by Zergmazter on

Topic category: General discussion

Active 5 years ago
Joined Nov 2014
Points:
752

User statistics:

  • Modifications: 0
  • Forum topics: 5
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 21
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
Active 1 year ago
Joined Aug 2013
Points:
1162

User statistics:

  • Modifications: 4
  • Forum topics: 6
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 737
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.

Active 5 years ago
Joined Nov 2014
Points:
752

User statistics:

  • Modifications: 0
  • Forum topics: 5
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 21
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!!!

Active 5 years ago
Joined Nov 2014
Points:
752

User statistics:

  • Modifications: 0
  • Forum topics: 5
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 21
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);

					}
				}
			}

 

Active 5 years ago
Joined Nov 2014
Points:
752

User statistics:

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

The bugged code:

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

 

Active 1 year ago
Joined Aug 2013
Points:
1162

User statistics:

  • Modifications: 4
  • Forum topics: 6
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 737
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)

Active 5 years ago
Joined Nov 2014
Points:
752

User statistics:

  • Modifications: 0
  • Forum topics: 5
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 21
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.