Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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?

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.

  • Author

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. 

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

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.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.