Posted June 12, 20187 yr 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, 20187 yr by LittleOne
June 12, 20187 yr 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.
June 13, 20187 yr 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.
June 13, 20187 yr Author 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.
June 13, 20187 yr If you know to basis for how farmland changes to dirt by jumping on it that might help sorry i can help you anymore
June 13, 20187 yr 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. Check out my tutorials here: http://jabelarminecraft.blogspot.com/
June 14, 20187 yr Author 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, 20187 yr by LittleOne
June 14, 20187 yr 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()) Check out my tutorials here: http://jabelarminecraft.blogspot.com/
June 14, 20187 yr On 6/14/2018 at 1:11 AM, 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. 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.
June 14, 20187 yr Author 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()); } } }
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.