Jump to content

[1.7.10] PlaceEvent doesn't actually take metadata into account


Recommended Posts

Posted

I have some code that turns metal blocks into fluids in a custom dimension, and while testing it against some blocks that are only metal via metadata, it only spawned the fluid which was for the metadata of 0. After debugging a little, I found that the metadata of the block placed is always zero, regardless of the block.

 

I was wondering how to fix this.

 

Code:

if(OreDictionary.doesOreNameExist("blockTin")) {
			for(ItemStack ore : OreDictionary.getOres("blockTin")) {
				if(ore != null) {
					if(event.block == Block.getBlockFromItem(ore.getItem()) && event.blockMetadata == ore.getItemDamage()) {
						System.out.println("block=" + Block.getBlockFromItem(ore.getItem()) + ", meta=" + ore.getItemDamage());
						System.out.println("event.block=" + event.block + ", event.meta=" + event.blockMetadata);
						if(FluidRegistry.getFluid("tin.molten") != null) {
							event.world.setBlock(event.x, event.y, event.z, FluidRegistry.getFluid("tin.molten").getBlock());
						} else {
							event.world.setBlock(event.x, event.y, event.z, Blocks.lava);
						}
					}
				}
			}
		}

Check out WIP mod Project Aurora (https://github.com/SimplyTheOther/ProjectAurora)

Posted

The issue here, as far I can see, is purely logical. The code is placing what you tell it.

Every fluid, has a source-block. This is what is being placed when you do not specify the meta in your world#setBlock method.

 

You use the method setBlock(x, y, z, block),when you should be using the other method setBlock(x, y, z, block, meta, flag).

Your meta-damage seems to be the ore#getItemDamage(), so use that for the meta tag.

The flag variable, in it's simplest description, is a notification. If the flag has a value of "1", it marks the block for update. If it is "2", it sends the update to the client (almost always wanted). "3" does both flag 1+2. "4" is special, in that it prevents the block from being re-rendered.

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

Something something something update to the new BlockState methods so this won't happen again.

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

The issue here, as far I can see, is purely logical. The code is placing what you tell it.

Every fluid, has a source-block. This is what is being placed when you do not specify the meta in your world#setBlock method.

 

You use the method setBlock(x, y, z, block),when you should be using the other method setBlock(x, y, z, block, meta, flag).

Your meta-damage seems to be the ore#getItemDamage(), so use that for the meta tag.

The flag variable, in it's simplest description, is a notification. If the flag has a value of "1", it marks the block for update. If it is "2", it sends the update to the client (almost always wanted). "3" does both flag 1+2. "4" is special, in that it prevents the block from being re-rendered.

 

You're kind of right. My console messages print whenever any block is placed, not just tin, and they always print a metadata of 0. But thanks for the heads up, I'll change my code.

Check out WIP mod Project Aurora (https://github.com/SimplyTheOther/ProjectAurora)

  • 1 month later...
Posted

Okay, so it appears that event.blockMetadata always is 0, so I found a better way, event.world.getBlockMetadata(event.x, event.y, event.z) . However, in the console, the event fires twice for each block, initially getting the metadata correct, but then firing the event with a metadata of 0 as well, which makes a different liquid. How would I get around this?

Check out WIP mod Project Aurora (https://github.com/SimplyTheOther/ProjectAurora)

Posted

1.7.10 is no longer supported. Update.

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.

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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