Jump to content

Recommended Posts

Posted (edited)

I feel really bad that I can't figure this out. I've tried for days now and I'm sure there's a really simple solution. What I want is this: When EntityPlayer moves on ground, specifically the block, grass, I want the grass to change to a different block. This change has to be constant as they travel around the world. Any help is greatly appreciated!

Edited by LittleOne
Posted

what version of minecraft? Because 1.13 Broke a lot of mechanics for items, blocks and entities.

I have not had a lot of time to have a look myself to check whats changed. So if its 1.13 then your going to need to ask a person 

then me sorry I've only just go back to coding mods 2 days ago the last version i coded was 1.8 sorry. :(

Posted

You should usually post what you've tried so we can tell what kind of help you need.

 

Basically, you can use a player tick event handler and check if the player is on the ground (there is a public field called onGround) and if that is true, then just check the block in the position under the player position to confirm it is grass or whatever and then set that block to stone or whatever.

  • Thanks 1

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted (edited)
public void onLivingUpdateEvent(LivingUpdateEvent event) {
		event.getEntity();
		if(event.getEntity() instanceof EntityPlayer) {
			EntityPlayer player = (EntityPlayer) event.getEntity();
			BlockPos playerUPos = player.getPosition().down();
			IBlockState playerUState = (IBlockState)playerUPos;
			Block playerUBlock = (Block)playerUState;
			IBlockState grassState = Blocks.GRASS.getDefaultState();
			if(player.onGround && playerUBlock == Blocks.GRASS) {
				
			}
		}
	}
}

Something like this? Or am I missing something? If I need more java experience before doing this, I will accept that. Thank you in advance. How to set blockstate next?

Edited by LittleOne
Posted

Yes, that is the general idea. There is actually a PlayerTickEvent which is a bit more specific, which I prefer because it is a bit wasteful to call your method for every living entity, but since you test immediately for player it probably isn't a bit deal.

 

I don't think your methods for checking the block and setting the block are quite right. It looks like you're trying to directly cast the position into the block state. Instead you should use the player world (player.world) and use the getBlockState() method.

 

Also generally shouldn't compare to the default state. It would work for grass because I think it doesn't have any properties, but I'd probably do it like this:
 

if (player.onGround && player.world.getBlockState(playerUPos).getBlock() == Blocks.GRASS))

 

and to set the block something like:

player.world.setBlockState(Blocks.STONE.getDefaultState())

 

  • Thanks 1

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted
2 hours ago, LittleOne said:

IBlockState playerUState = (IBlockState)playerUPos;

Block playerUBlock = (Block)playerUState;

You really should look at the IBlockState interface. IBlockStates are not Blocks. They are a wrapper around Block+Metadata.

  • Thanks 1

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

Solved! Thanks for your clarification and help. I will also look at the IBlockState Interface. Also, it's working!

@SubscribeEvent
	public void onPlayerTickEvent(PlayerTickEvent event) {
		if(event.player instanceof EntityPlayer) {
			EntityPlayer player = (EntityPlayer) event.player;
			BlockPos playerUPos = player.getPosition().down();
			IBlockState playerUState = player.world.getBlockState(playerUPos);
			if (player.onGround && player.world.getBlockState(playerUPos).getBlock() == Blocks.GRASS) {
				player.world.setBlockState(playerUPos, Blocks.STONE.getDefaultState());
			}
		}
	}

 

  • Like 1

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.