Posted September 6, 20232 yr 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 September 6, 20232 yr by notAstral
September 6, 20232 yr 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); } } } }
September 7, 20232 yr 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.