Jump to content

Recommended Posts

Posted

Im trying to use setBlockAndUpdate with my inputs of BlockEvent.EntityPlaceEvent, want to make spawning mobs with structures, like Iron golem. 

After im checking if its pumpkin and if under it Diamond Block, im using setBlockAndUpdate. It replace Block to air and return it to previous blockState. How i can fix it?

Posted

Show your code.

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

I cant copy it right now but its look like that:

@SubscribedEvent

public static void onBlockPlaced(BlockEvent.EntityPlaceEvent event) {

    ExampleMod.LOGGER.info("block placed") 

    if (event.getPlacedBlock().getBlockState() == Block.CARWED_PUMPKIN.getdefaultBlockState()) {

        ExampleMod.LOGGER.info("block is pumpkin") 

        if(Minecraft.getInstance().player.level.getBlockState(New BlockPos(event.getPos().getX(),event.getPos().getY()-1,event.getPos().getZ())) == Blocks.DIAMOND_BLOCK.getdefaultBlockState()){

            Level level = Minecraft.getInstance().player.level;

            level.setBlockAndUpdate(event.getPos(),Blocks.AIR.getdefaultBlockState());

            ExampleMod.LOGGER.info("block on Diamond Block");

        }

    } 

its works fine but Block dont want to be placed, it turn in air for milisecond and turn to pumpkin back. 

Posted (edited)
5 minutes ago, lGuestll666l said:

if(Minecraft.getInstance()

You can't do this. You want the blockstate of a block in the world, use the world given to you in the event. You want the player? Use the player given to you in the event.

 

This code will crash dedicated servers.

Quote

its works fine but Block dont want to be placed, it turn in air for milisecond and turn to pumpkin back. 

Yeah, because the server says "the fuck you doing client, that position is a pumpkin."

Edited by Draco18s
  • Like 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.

  • Guest locked this topic
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.