Jump to content

Recommended Posts

Posted (edited)

How do I go about making a procedure where if the block is dirt or grass and check if the player is sneaking then if you right-click the block it spawns an item on top of it (yes I am referring to a pebble mod)

Edited by notAstral
  • notAstral changed the title to Making a procedure 1.19.2
Posted

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber
public class TestProcedure {
	@SubscribeEvent
	public static void onRightClickBlock(PlayerInteractEvent.RightClickBlock event) {
		if(event.getLevel().getBlockState(event.getPos()).getBlock() == Blocks.GRASS){
			if(!event.getLevel().isClientSide()){
				event.getLevel().setBlock(new BlockPos(event.getPos().getX(), event.getPos().getY() +1, event.getPos().getZ()), Blocks.MOSS_CARPET.defaultBlockState(), 3);
			}
		}
	}

}

 

Posted

what he said.

...except instead of state.getBlock() == Blocks.grass you should say state.is(BlockTags.DIRT)     . tags are not a new thing and people need to use them.

also, instead of that BlockPos constructor use above() call in BlockPos.

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.