Клик по воде

Версия Minecraft
1.12
5,018
47
783
Как то раз возникла такая проблема, я и не смог ее никак решить. Что только не писал - ничего не работало.
Как вы знаете,есть такой эвент  RightClickBlock. Он есть как в райткликблоке, так и в PlayerInteractEvent. 
Так вот, что бы я не ставил в этом эвенте,
так
Код:
event.getWorld().getBlockState(event.getPos()) == Blocks.WATER.getDefaultState()

или так
Код:
event.getWorld().getBlockState(event.getPos()).getBlock() == Blocks.WATER
или даже так
Код:
event.getWorld().getBlockState(event.getPos()).getBlock().getMaterial(Blocks.WATER.getDefaultState()) == Material.WATER
...
Ничего не работало. Райтклик по воде не происходил.(происходил райтклик по блоку под водой, я проверял...) Что не так?
 
Решение
Короче решил проблему. Вот кому надо код.
Код:
public class EventHandThirstUpdate {

	@SubscribeEvent
	public void placeble(PlayerInteractEvent.RightClickEmpty event){
		final Minecraft mc = Minecraft.getMinecraft();
		final World world = (World)Minecraft.getMinecraft().world;
		final EntityPlayer player = (EntityPlayer)Minecraft.getMinecraft().player;
		ItemStack is = event.getEntityPlayer().getHeldItem(EnumHand.MAIN_HAND);
		RayTraceResult raytraceresult = this.rayTrace(world, player, true);
		if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK)
		{
			BlockPos blockpos = raytraceresult.getBlockPos();


			if (world.getBlockState(blockpos).getMaterial() == Material.WATER)
			{...
5,018
47
783
Ну так вот смотрю.Там получается материал
Код:
 Material material = iblockstate.getMaterial();

                    if (material == Material.WATER && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
                    {
я аналогично делал же..(ну тоесть материал получал)


ну вот что то налепил... Помогите отдебажить) не работает все ровно
Код:
	@SubscribeEvent
	public void placeble(RightClickBlock.RightClickBlock event){
		System.out.println("Event Work");
		ItemStack is = event.getEntityPlayer().getHeldItem(EnumHand.MAIN_HAND);
		 boolean flag = this.containedBlock == Blocks.AIR;
		final Minecraft mc = Minecraft.getMinecraft();
        final World world = (World)Minecraft.getMinecraft().world;
        final EntityPlayer player = (EntityPlayer)Minecraft.getMinecraft().player;
        RayTraceResult raytraceresult = this.rayTrace(world, player, flag);
        BlockPos blockpos = raytraceresult.getBlockPos();
        if (Minecraft.getMinecraft().objectMouseOver != null && Minecraft.getMinecraft().objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK) {
          //  final int blockX = Minecraft.getMinecraft().objectMouseOver.getBlockPos().getX();
        //    final int blockY = Minecraft.getMinecraft().objectMouseOver.getBlockPos().getY();
        //    final int blockZ = Minecraft.getMinecraft().objectMouseOver.getBlockPos().getZ();
            final IBlockState iblockstate = world.getBlockState(blockpos);
            Material material = iblockstate.getMaterial();
            if (material == Material.WATER)
            {
            	 world.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 11);
            }
		}
	}
    protected RayTraceResult rayTrace(World worldIn, EntityPlayer playerIn, boolean useLiquids)
    {
        float f = playerIn.rotationPitch;
        float f1 = playerIn.rotationYaw;
        double d0 = playerIn.posX;
        double d1 = playerIn.posY + (double)playerIn.getEyeHeight();
        double d2 = playerIn.posZ;
        Vec3d vec3d = new Vec3d(d0, d1, d2);
        float f2 = MathHelper.cos(-f1 * 0.017453292F - (float)Math.PI);
        float f3 = MathHelper.sin(-f1 * 0.017453292F - (float)Math.PI);
        float f4 = -MathHelper.cos(-f * 0.017453292F);
        float f5 = MathHelper.sin(-f * 0.017453292F);
        float f6 = f3 * f4;
        float f7 = f2 * f4;
        double d3 = 5.0D;
        if (playerIn instanceof net.minecraft.entity.player.EntityPlayerMP)
        {
            d3 = ((net.minecraft.entity.player.EntityPlayerMP)playerIn).interactionManager.getBlockReachDistance();
        }
        Vec3d vec3d1 = vec3d.addVector((double)f6 * d3, (double)f5 * d3, (double)f7 * d3);
        return worldIn.rayTraceBlocks(vec3d, vec3d1, useLiquids, !useLiquids, false);
    }
}
 
5,018
47
783
Короче решил проблему. Вот кому надо код.
Код:
public class EventHandThirstUpdate {

	@SubscribeEvent
	public void placeble(PlayerInteractEvent.RightClickEmpty event){
		final Minecraft mc = Minecraft.getMinecraft();
		final World world = (World)Minecraft.getMinecraft().world;
		final EntityPlayer player = (EntityPlayer)Minecraft.getMinecraft().player;
		ItemStack is = event.getEntityPlayer().getHeldItem(EnumHand.MAIN_HAND);
		RayTraceResult raytraceresult = this.rayTrace(world, player, true);
		if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK)
		{
			BlockPos blockpos = raytraceresult.getBlockPos();


			if (world.getBlockState(blockpos).getMaterial() == Material.WATER)
			{
				world.setBlockState(blockpos.up(), Blocks.BEDROCK.getDefaultState());
				 world.playSound(player, player.posX, player.posY, player.posZ, SoundEvents.ITEM_BOTTLE_FILL, SoundCategory.NEUTRAL, 1.0F, 1.0F);
			}
		}
	}
	protected RayTraceResult rayTrace(World worldIn, EntityPlayer playerIn, boolean useLiquids)
	{
		float f = playerIn.rotationPitch;
		float f1 = playerIn.rotationYaw;
		double d0 = playerIn.posX;
		double d1 = playerIn.posY + (double)playerIn.getEyeHeight();
		double d2 = playerIn.posZ;
		Vec3d vec3d = new Vec3d(d0, d1, d2);
		float f2 = MathHelper.cos(-f1 * 0.017453292F - (float)Math.PI);
		float f3 = MathHelper.sin(-f1 * 0.017453292F - (float)Math.PI);
		float f4 = -MathHelper.cos(-f * 0.017453292F);
		float f5 = MathHelper.sin(-f * 0.017453292F);
		float f6 = f3 * f4;
		float f7 = f2 * f4;
		double d3 = 5.0D;
		if (playerIn instanceof net.minecraft.entity.player.EntityPlayerMP)
		{
			d3 = ((net.minecraft.entity.player.EntityPlayerMP)playerIn).interactionManager.getBlockReachDistance();
		}
		Vec3d vec3d1 = vec3d.addVector((double)f6 * d3, (double)f5 * d3, (double)f7 * d3);
		return worldIn.rayTraceBlocks(vec3d, vec3d1, useLiquids, !useLiquids, false);
	}
}
 
5,018
47
783
Ахтунг, небольшой хотфикс. Обнаружилось, что ломается все остальное с этим эвентом. Райтклик в пустоту или по энтити вызывает краш.Поэтому лучше использовать этот эвент
Код:
public void placeble(PlayerInteractEvent.RightClickBlock event){
Ну и да, по лаве аналогично
 
Сверху