LittleOne Posted June 12, 2018 Posted June 12, 2018 (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 June 14, 2018 by LittleOne Quote
Wynterking Posted June 12, 2018 Posted June 12, 2018 The question is do you want it to change from grass to dirt then coarse dirt after a certain amount of time or just dirt. Quote
LittleOne Posted June 12, 2018 Author Posted June 12, 2018 To Stone. Apologies, I should have mentioned that. Is this possible? Quote
Wynterking Posted June 12, 2018 Posted June 12, 2018 do you want the block to change while sprinting or walking? Quote
LittleOne Posted June 12, 2018 Author Posted June 12, 2018 Whenever the entity is on ground. Both, I suppose. Quote
Wynterking Posted June 13, 2018 Posted June 13, 2018 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. Quote
LittleOne Posted June 13, 2018 Author Posted June 13, 2018 1.12.2, By the way, thank you for responding quickly. I'm looking for a hint or two in the right direction, even if it is outdated. Quote
Wynterking Posted June 13, 2018 Posted June 13, 2018 If you know to basis for how farmland changes to dirt by jumping on it that might help sorry i can help you anymore 1 Quote
jabelar Posted June 13, 2018 Posted June 13, 2018 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. 1 Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
LittleOne Posted June 14, 2018 Author Posted June 14, 2018 (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 June 14, 2018 by LittleOne Quote
jabelar Posted June 14, 2018 Posted June 14, 2018 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()) 1 Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
Draco18s Posted June 14, 2018 Posted June 14, 2018 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. 1 Quote 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.
LittleOne Posted June 14, 2018 Author Posted June 14, 2018 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()); } } } 1 Quote
Recommended Posts
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.