当前位置: 首页>>代码示例>>Java>>正文


Java World.isBlockModifiable方法代码示例

本文整理汇总了Java中net.minecraft.world.World.isBlockModifiable方法的典型用法代码示例。如果您正苦于以下问题:Java World.isBlockModifiable方法的具体用法?Java World.isBlockModifiable怎么用?Java World.isBlockModifiable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.minecraft.world.World的用法示例。


在下文中一共展示了World.isBlockModifiable方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onItemRightClick

import net.minecraft.world.World; //导入方法依赖的package包/类
@Override
@SuppressWarnings("ConstantConditions")
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
	final RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, false);
	ItemStack stack = playerIn.getHeldItem(hand);
	if (raytraceresult == null) {
		return ActionResult.newResult(EnumActionResult.PASS, stack);
	} else {
		if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK) {
			final BlockPos blockpos = raytraceresult.getBlockPos();

			if (!worldIn.isBlockModifiable(playerIn, blockpos) || !playerIn.canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, stack)) {
				return ActionResult.newResult(EnumActionResult.FAIL, stack);
			}

			final BlockPos up = blockpos.up();
			final IBlockState iblockstate = worldIn.getBlockState(blockpos);

			if (iblockstate.getMaterial().isSolid()) {
				// special case for handling block placement with water lilies
				BlockPos I = up.add(-1, 0, -1);
				BlockPos F = up.add(1, 1, 1);
				for (BlockPos blockPos : BlockPos.getAllInBox(I, F)) {
					Block block = worldIn.getBlockState(blockPos).getBlock();
					if (block != ModBlocks.crop_kelp && block != Blocks.WATER) {
						return ActionResult.newResult(EnumActionResult.FAIL, stack);
					}
				}
				final net.minecraftforge.common.util.BlockSnapshot blocksnapshot = net.minecraftforge.common.util.BlockSnapshot.getBlockSnapshot(worldIn, up);
				if (net.minecraftforge.event.ForgeEventFactory.onPlayerBlockPlace(playerIn, blocksnapshot, net.minecraft.util.EnumFacing.UP, hand).isCanceled()) {
					blocksnapshot.restore(true, false);
					return ActionResult.newResult(EnumActionResult.FAIL, stack);
				}

				worldIn.setBlockState(up, this.crop.getDefaultState(), 11);

				if (!playerIn.capabilities.isCreativeMode) {
					stack.shrink(1);
				}

				worldIn.playSound(playerIn, blockpos, SoundEvents.BLOCK_WATERLILY_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
				return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
			}
		}

		return ActionResult.newResult(EnumActionResult.FAIL, stack);
	}
}
 
开发者ID:Um-Mitternacht,项目名称:Bewitchment,代码行数:49,代码来源:ItemKelpSeed.java

示例2: onItemRightClick

import net.minecraft.world.World; //导入方法依赖的package包/类
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
    MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, true);

    if (movingobjectposition == null)
    {
        return itemStackIn;
    }
    else
    {
        if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
        {
            BlockPos blockpos = movingobjectposition.getBlockPos();

            if (!worldIn.isBlockModifiable(playerIn, blockpos))
            {
                return itemStackIn;
            }

            if (!playerIn.canPlayerEdit(blockpos.offset(movingobjectposition.sideHit), movingobjectposition.sideHit, itemStackIn))
            {
                return itemStackIn;
            }

            if (worldIn.getBlockState(blockpos).getBlock().getMaterial() == Material.water)
            {
                --itemStackIn.stackSize;
                playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);

                if (itemStackIn.stackSize <= 0)
                {
                    return new ItemStack(Items.potionitem);
                }

                if (!playerIn.inventory.addItemStackToInventory(new ItemStack(Items.potionitem)))
                {
                    playerIn.dropPlayerItemWithRandomChoice(new ItemStack(Items.potionitem, 1, 0), false);
                }
            }
        }

        return itemStackIn;
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:48,代码来源:ItemGlassBottle.java

示例3: onItemRightClick

import net.minecraft.world.World; //导入方法依赖的package包/类
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
    if (worldIn.isRemote)
    {
        return itemStackIn;
    }
    else
    {
        MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, true);

        if (movingobjectposition == null)
        {
            return itemStackIn;
        }
        else
        {
            if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
            {
                BlockPos blockpos = movingobjectposition.getBlockPos();

                if (!worldIn.isBlockModifiable(playerIn, blockpos))
                {
                    return itemStackIn;
                }

                if (!playerIn.canPlayerEdit(blockpos, movingobjectposition.sideHit, itemStackIn))
                {
                    return itemStackIn;
                }

                if (worldIn.getBlockState(blockpos).getBlock() instanceof BlockLiquid)
                {
                    Entity entity = spawnCreature(worldIn, itemStackIn.getMetadata(), (double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 0.5D, (double)blockpos.getZ() + 0.5D);

                    if (entity != null)
                    {
                        if (entity instanceof EntityLivingBase && itemStackIn.hasDisplayName())
                        {
                            ((EntityLiving)entity).setCustomNameTag(itemStackIn.getDisplayName());
                        }

                        if (!playerIn.capabilities.isCreativeMode)
                        {
                            --itemStackIn.stackSize;
                        }

                        playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
                    }
                }
            }

            return itemStackIn;
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:59,代码来源:ItemMonsterPlacer.java

示例4: onItemRightClick

import net.minecraft.world.World; //导入方法依赖的package包/类
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
    boolean flag = this.isFull == Blocks.air;
    MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, flag);

    if (movingobjectposition == null)
    {
        return itemStackIn;
    }
    else
    {
        if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
        {
            BlockPos blockpos = movingobjectposition.getBlockPos();

            if (!worldIn.isBlockModifiable(playerIn, blockpos))
            {
                return itemStackIn;
            }

            if (flag)
            {
                if (!playerIn.canPlayerEdit(blockpos.offset(movingobjectposition.sideHit), movingobjectposition.sideHit, itemStackIn))
                {
                    return itemStackIn;
                }

                IBlockState iblockstate = worldIn.getBlockState(blockpos);
                Material material = iblockstate.getBlock().getMaterial();

                if (material == Material.water && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
                {
                    worldIn.setBlockToAir(blockpos);
                    playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
                    return this.fillBucket(itemStackIn, playerIn, Items.water_bucket);
                }

                if (material == Material.lava && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
                {
                    worldIn.setBlockToAir(blockpos);
                    playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
                    return this.fillBucket(itemStackIn, playerIn, Items.lava_bucket);
                }
            }
            else
            {
                if (this.isFull == Blocks.air)
                {
                    return new ItemStack(Items.bucket);
                }

                BlockPos blockpos1 = blockpos.offset(movingobjectposition.sideHit);

                if (!playerIn.canPlayerEdit(blockpos1, movingobjectposition.sideHit, itemStackIn))
                {
                    return itemStackIn;
                }

                if (this.tryPlaceContainedLiquid(worldIn, blockpos1) && !playerIn.capabilities.isCreativeMode)
                {
                    playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
                    return new ItemStack(Items.bucket);
                }
            }
        }

        return itemStackIn;
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:73,代码来源:ItemBucket.java

示例5: onItemRightClick

import net.minecraft.world.World; //导入方法依赖的package包/类
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand)
{
    boolean flag = this.containedBlock == Blocks.AIR;
    RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, flag);
    ActionResult<ItemStack> ret = net.minecraftforge.event.ForgeEventFactory.onBucketUse(playerIn, worldIn, itemStackIn, raytraceresult);
    if (ret != null) return ret;

    if (raytraceresult == null)
    {
        return new ActionResult(EnumActionResult.PASS, itemStackIn);
    }
    else if (raytraceresult.typeOfHit != RayTraceResult.Type.BLOCK)
    {
        return new ActionResult(EnumActionResult.PASS, itemStackIn);
    }
    else
    {
        BlockPos blockpos = raytraceresult.getBlockPos();

        if (!worldIn.isBlockModifiable(playerIn, blockpos))
        {
            return new ActionResult(EnumActionResult.FAIL, itemStackIn);
        }
        else if (flag)
        {
            if (!playerIn.canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, itemStackIn))
            {
                return new ActionResult(EnumActionResult.FAIL, itemStackIn);
            }
            else
            {
                IBlockState iblockstate = worldIn.getBlockState(blockpos);
                Material material = iblockstate.getMaterial();

                if (material == Material.WATER && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
                {
                    worldIn.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 11);
                    playerIn.addStat(StatList.getObjectUseStats(this));
                    playerIn.playSound(SoundEvents.ITEM_BUCKET_FILL, 1.0F, 1.0F);
                    return new ActionResult(EnumActionResult.SUCCESS, this.fillBucket(itemStackIn, playerIn, Items.WATER_BUCKET));
                }
                else if (material == Material.LAVA && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
                {
                    playerIn.playSound(SoundEvents.ITEM_BUCKET_FILL_LAVA, 1.0F, 1.0F);
                    worldIn.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 11);
                    playerIn.addStat(StatList.getObjectUseStats(this));
                    return new ActionResult(EnumActionResult.SUCCESS, this.fillBucket(itemStackIn, playerIn, Items.LAVA_BUCKET));
                }
                else
                {
                    return new ActionResult(EnumActionResult.FAIL, itemStackIn);
                }
            }
        }
        else
        {
            boolean flag1 = worldIn.getBlockState(blockpos).getBlock().isReplaceable(worldIn, blockpos);
            BlockPos blockpos1 = flag1 && raytraceresult.sideHit == EnumFacing.UP ? blockpos : blockpos.offset(raytraceresult.sideHit);

            if (!playerIn.canPlayerEdit(blockpos1, raytraceresult.sideHit, itemStackIn))
            {
                return new ActionResult(EnumActionResult.FAIL, itemStackIn);
            }
            else if (this.tryPlaceContainedLiquid(playerIn, worldIn, blockpos1))
            {
                playerIn.addStat(StatList.getObjectUseStats(this));
                return !playerIn.capabilities.isCreativeMode ? new ActionResult(EnumActionResult.SUCCESS, new ItemStack(Items.BUCKET)) : new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
            }
            else
            {
                return new ActionResult(EnumActionResult.FAIL, itemStackIn);
            }
        }
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:76,代码来源:ItemBucket.java

示例6: onItemRightClick

import net.minecraft.world.World; //导入方法依赖的package包/类
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand)
{
    RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, true);

    if (raytraceresult == null)
    {
        return new ActionResult(EnumActionResult.PASS, itemStackIn);
    }
    else
    {
        if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK)
        {
            BlockPos blockpos = raytraceresult.getBlockPos();

            if (!worldIn.isBlockModifiable(playerIn, blockpos) || !playerIn.canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, itemStackIn))
            {
                return new ActionResult(EnumActionResult.FAIL, itemStackIn);
            }

            BlockPos blockpos1 = blockpos.up();
            IBlockState iblockstate = worldIn.getBlockState(blockpos);

            if (iblockstate.getMaterial() == Material.WATER && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0 && worldIn.isAirBlock(blockpos1))
            {
                // special case for handling block placement with water lilies
                net.minecraftforge.common.util.BlockSnapshot blocksnapshot = net.minecraftforge.common.util.BlockSnapshot.getBlockSnapshot(worldIn, blockpos1);
                worldIn.setBlockState(blockpos1, Blocks.WATERLILY.getDefaultState());
                if (net.minecraftforge.event.ForgeEventFactory.onPlayerBlockPlace(playerIn, blocksnapshot, net.minecraft.util.EnumFacing.UP, hand).isCanceled())
                {
                    blocksnapshot.restore(true, false);
                    return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemStackIn);
                }

                worldIn.setBlockState(blockpos1, Blocks.WATERLILY.getDefaultState(), 11);

                if (!playerIn.capabilities.isCreativeMode)
                {
                    --itemStackIn.stackSize;
                }

                playerIn.addStat(StatList.getObjectUseStats(this));
                worldIn.playSound(playerIn, blockpos, SoundEvents.BLOCK_WATERLILY_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
                return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
            }
        }

        return new ActionResult(EnumActionResult.FAIL, itemStackIn);
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:50,代码来源:ItemLilyPad.java

示例7: onItemRightClick

import net.minecraft.world.World; //导入方法依赖的package包/类
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
    MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, true);

    if (movingobjectposition == null)
    {
        return itemStackIn;
    }
    else
    {
        if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
        {
            BlockPos blockpos = movingobjectposition.getBlockPos();

            if (!worldIn.isBlockModifiable(playerIn, blockpos))
            {
                return itemStackIn;
            }

            if (!playerIn.canPlayerEdit(blockpos.offset(movingobjectposition.sideHit), movingobjectposition.sideHit, itemStackIn))
            {
                return itemStackIn;
            }

            BlockPos blockpos1 = blockpos.up();
            IBlockState iblockstate = worldIn.getBlockState(blockpos);

            if (iblockstate.getBlock().getMaterial() == Material.water && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0 && worldIn.isAirBlock(blockpos1))
            {
                worldIn.setBlockState(blockpos1, Blocks.waterlily.getDefaultState());

                if (!playerIn.capabilities.isCreativeMode)
                {
                    --itemStackIn.stackSize;
                }

                playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
            }
        }

        return itemStackIn;
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:47,代码来源:ItemLilyPad.java

示例8: onItemRightClick

import net.minecraft.world.World; //导入方法依赖的package包/类
public ActionResult<ItemStack> onItemRightClick(World itemStackIn, EntityPlayer worldIn, EnumHand playerIn)
{
    boolean flag = this.containedBlock == Blocks.AIR;
    ItemStack itemstack = worldIn.getHeldItem(playerIn);
    RayTraceResult raytraceresult = this.rayTrace(itemStackIn, worldIn, flag);

    if (raytraceresult == null)
    {
        return new ActionResult(EnumActionResult.PASS, itemstack);
    }
    else if (raytraceresult.typeOfHit != RayTraceResult.Type.BLOCK)
    {
        return new ActionResult(EnumActionResult.PASS, itemstack);
    }
    else
    {
        BlockPos blockpos = raytraceresult.getBlockPos();

        if (!itemStackIn.isBlockModifiable(worldIn, blockpos))
        {
            return new ActionResult(EnumActionResult.FAIL, itemstack);
        }
        else if (flag)
        {
            if (!worldIn.canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, itemstack))
            {
                return new ActionResult(EnumActionResult.FAIL, itemstack);
            }
            else
            {
                IBlockState iblockstate = itemStackIn.getBlockState(blockpos);
                Material material = iblockstate.getMaterial();

                if (material == Material.WATER && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
                {
                    itemStackIn.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 11);
                    worldIn.addStat(StatList.getObjectUseStats(this));
                    worldIn.playSound(SoundEvents.ITEM_BUCKET_FILL, 1.0F, 1.0F);
                    return new ActionResult(EnumActionResult.SUCCESS, this.fillBucket(itemstack, worldIn, Items.WATER_BUCKET));
                }
                else if (material == Material.LAVA && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
                {
                    worldIn.playSound(SoundEvents.ITEM_BUCKET_FILL_LAVA, 1.0F, 1.0F);
                    itemStackIn.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 11);
                    worldIn.addStat(StatList.getObjectUseStats(this));
                    return new ActionResult(EnumActionResult.SUCCESS, this.fillBucket(itemstack, worldIn, Items.LAVA_BUCKET));
                }
                else
                {
                    return new ActionResult(EnumActionResult.FAIL, itemstack);
                }
            }
        }
        else
        {
            boolean flag1 = itemStackIn.getBlockState(blockpos).getBlock().isReplaceable(itemStackIn, blockpos);
            BlockPos blockpos1 = flag1 && raytraceresult.sideHit == EnumFacing.UP ? blockpos : blockpos.offset(raytraceresult.sideHit);

            if (!worldIn.canPlayerEdit(blockpos1, raytraceresult.sideHit, itemstack))
            {
                return new ActionResult(EnumActionResult.FAIL, itemstack);
            }
            else if (this.tryPlaceContainedLiquid(worldIn, itemStackIn, blockpos1))
            {
                worldIn.addStat(StatList.getObjectUseStats(this));
                return !worldIn.capabilities.isCreativeMode ? new ActionResult(EnumActionResult.SUCCESS, new ItemStack(Items.BUCKET)) : new ActionResult(EnumActionResult.SUCCESS, itemstack);
            }
            else
            {
                return new ActionResult(EnumActionResult.FAIL, itemstack);
            }
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:75,代码来源:ItemBucket.java

示例9: onItemRightClick

import net.minecraft.world.World; //导入方法依赖的package包/类
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack itemstack, World world, EntityPlayer player, EnumHand hand)
{
    FluidStack fluidStack = getFluid(itemstack);
    // empty bucket shouldn't exist, do nothing since it should be handled by the bucket event
    if (fluidStack == null)
    {
        return ActionResult.newResult(EnumActionResult.PASS, itemstack);
    }

    // clicked on a block?
    RayTraceResult mop = this.rayTrace(world, player, false);

    if(mop == null || mop.typeOfHit != RayTraceResult.Type.BLOCK)
    {
        return ActionResult.newResult(EnumActionResult.PASS, itemstack);
    }

    BlockPos clickPos = mop.getBlockPos();
    // can we place liquid there?
    if (world.isBlockModifiable(player, clickPos))
    {
        // the block adjacent to the side we clicked on
        BlockPos targetPos = clickPos.offset(mop.sideHit);

        // can the player place there?
        if (player.canPlayerEdit(targetPos, mop.sideHit, itemstack))
        {
            // try placing liquid
            if (FluidUtil.tryPlaceFluid(player, player.getEntityWorld(), fluidStack, targetPos)
                    && !player.capabilities.isCreativeMode)
            {
                // success!
                player.addStat(StatList.getObjectUseStats(this));

                itemstack.stackSize--;
                ItemStack emptyStack = getEmpty() != null ? getEmpty().copy() : new ItemStack(this);

                // check whether we replace the item or add the empty one to the inventory
                if (itemstack.stackSize <= 0)
                {
                    return ActionResult.newResult(EnumActionResult.SUCCESS, emptyStack);
                }
                else
                {
                    // add empty bucket to player inventory
                    ItemHandlerHelper.giveItemToPlayer(player, emptyStack);
                    return ActionResult.newResult(EnumActionResult.SUCCESS, itemstack);
                }
            }
        }
    }

    // couldn't place liquid there2
    return ActionResult.newResult(EnumActionResult.FAIL, itemstack);
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:57,代码来源:UniversalBucket.java

示例10: onItemRightClick

import net.minecraft.world.World; //导入方法依赖的package包/类
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand)
{
    List<EntityAreaEffectCloud> list = worldIn.<EntityAreaEffectCloud>getEntitiesWithinAABB(EntityAreaEffectCloud.class, playerIn.getEntityBoundingBox().expandXyz(2.0D), new Predicate<EntityAreaEffectCloud>()
    {
        public boolean apply(@Nullable EntityAreaEffectCloud p_apply_1_)
        {
            return p_apply_1_ != null && p_apply_1_.isEntityAlive() && p_apply_1_.getOwner() instanceof EntityDragon;
        }
    });

    if (!list.isEmpty())
    {
        EntityAreaEffectCloud entityareaeffectcloud = (EntityAreaEffectCloud)list.get(0);
        entityareaeffectcloud.setRadius(entityareaeffectcloud.getRadius() - 0.5F);
        worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ITEM_BOTTLE_FILL_DRAGONBREATH, SoundCategory.NEUTRAL, 1.0F, 1.0F);
        return new ActionResult(EnumActionResult.SUCCESS, this.turnBottleIntoItem(itemStackIn, playerIn, new ItemStack(Items.DRAGON_BREATH)));
    }
    else
    {
        RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, true);

        if (raytraceresult == null)
        {
            return new ActionResult(EnumActionResult.PASS, itemStackIn);
        }
        else
        {
            if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK)
            {
                BlockPos blockpos = raytraceresult.getBlockPos();

                if (!worldIn.isBlockModifiable(playerIn, blockpos) || !playerIn.canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, itemStackIn))
                {
                    return new ActionResult(EnumActionResult.PASS, itemStackIn);
                }

                if (worldIn.getBlockState(blockpos).getMaterial() == Material.WATER)
                {
                    worldIn.playSound(playerIn, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ITEM_BOTTLE_FILL, SoundCategory.NEUTRAL, 1.0F, 1.0F);
                    return new ActionResult(EnumActionResult.SUCCESS, this.turnBottleIntoItem(itemStackIn, playerIn, new ItemStack(Items.POTIONITEM)));
                }
            }

            return new ActionResult(EnumActionResult.PASS, itemStackIn);
        }
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:48,代码来源:ItemGlassBottle.java

示例11: onItemRightClick

import net.minecraft.world.World; //导入方法依赖的package包/类
/**
 * Applies the data in the EntityTag tag of the given ItemStack to the given
 * Entity.
 */

@Override
public ActionResult<ItemStack> onItemRightClick( World worldIn, EntityPlayer playerIn,
		EnumHand hand) {
	ItemStack itemStackIn=playerIn.getHeldItem(hand);
	if (worldIn.isRemote)
		return new ActionResult<ItemStack>(EnumActionResult.PASS, itemStackIn);
	else {
		RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, true);

		if (raytraceresult != null && raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK) {
			BlockPos blockpos = raytraceresult.getBlockPos();

			if (!(worldIn.getBlockState(blockpos).getBlock() instanceof BlockLiquid))
				return new ActionResult<ItemStack>(EnumActionResult.PASS, itemStackIn);
			else if (worldIn.isBlockModifiable(playerIn, blockpos)
					&& playerIn.canPlayerEdit(blockpos, raytraceresult.sideHit, itemStackIn)) {
				
				boolean hastag = itemStackIn.getTagCompound() != null && itemStackIn.getTagCompound().hasKey("SavedEntity");
				
				EntityLivingBase entity = spawnCreature(worldIn, itemStackIn.getItemDamage(),
						blockpos.getX() + 0.5D, blockpos.getY() + 0.5D, blockpos.getZ() + 0.5D,
						hastag
								? itemStackIn.getTagCompound().getCompoundTag("SavedEntity") : null);

				if (entity == null)
					return new ActionResult(EnumActionResult.PASS, itemStackIn);
				else {
					if (entity instanceof EntityLivingBase && itemStackIn.hasDisplayName())
						entity.setCustomNameTag(itemStackIn.getDisplayName());

					if (!playerIn.capabilities.isCreativeMode)
						itemStackIn.shrink(1);
					if (entity instanceof EntityBuilding) {
						((EntityBuilding) entity).setOwner(playerIn);
						if(hastag) {
							((EntityBuilding) entity).setConstructing(true);
							((EntityBuilding) entity).redeploy = true;
						}
						entity.rotationYaw = playerIn.rotationYawHead;
						entity.renderYawOffset = playerIn.rotationYawHead;
						entity.rotationYawHead = playerIn.rotationYawHead;
						
						/*
						 * if(entity instanceof EntityTeleporter){
						 * ((EntityTeleporter)
						 * entity).setExit(itemStackIn.getItemDamage()>23);
						 * }
						 */
					}
					playerIn.addStat(StatList.getObjectUseStats(this));
					return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
				}
			} else
				return new ActionResult(EnumActionResult.FAIL, itemStackIn);
		} else
			return new ActionResult(EnumActionResult.PASS, itemStackIn);
	}
}
 
开发者ID:rafradek,项目名称:Mods,代码行数:64,代码来源:ItemMonsterPlacerPlus.java

示例12: onItemRightClick

import net.minecraft.world.World; //导入方法依赖的package包/类
public ActionResult<ItemStack> onItemRightClick(World itemStackIn, EntityPlayer worldIn, EnumHand playerIn)
{
    List<EntityAreaEffectCloud> list = itemStackIn.<EntityAreaEffectCloud>getEntitiesWithinAABB(EntityAreaEffectCloud.class, worldIn.getEntityBoundingBox().expandXyz(2.0D), new Predicate<EntityAreaEffectCloud>()
    {
        public boolean apply(@Nullable EntityAreaEffectCloud p_apply_1_)
        {
            return p_apply_1_ != null && p_apply_1_.isEntityAlive() && p_apply_1_.getOwner() instanceof EntityDragon;
        }
    });
    ItemStack itemstack = worldIn.getHeldItem(playerIn);

    if (!list.isEmpty())
    {
        EntityAreaEffectCloud entityareaeffectcloud = (EntityAreaEffectCloud)list.get(0);
        entityareaeffectcloud.setRadius(entityareaeffectcloud.getRadius() - 0.5F);
        itemStackIn.playSound((EntityPlayer)null, worldIn.posX, worldIn.posY, worldIn.posZ, SoundEvents.ITEM_BOTTLE_FILL_DRAGONBREATH, SoundCategory.NEUTRAL, 1.0F, 1.0F);
        return new ActionResult(EnumActionResult.SUCCESS, this.turnBottleIntoItem(itemstack, worldIn, new ItemStack(Items.DRAGON_BREATH)));
    }
    else
    {
        RayTraceResult raytraceresult = this.rayTrace(itemStackIn, worldIn, true);

        if (raytraceresult == null)
        {
            return new ActionResult(EnumActionResult.PASS, itemstack);
        }
        else
        {
            if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK)
            {
                BlockPos blockpos = raytraceresult.getBlockPos();

                if (!itemStackIn.isBlockModifiable(worldIn, blockpos) || !worldIn.canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, itemstack))
                {
                    return new ActionResult(EnumActionResult.PASS, itemstack);
                }

                if (itemStackIn.getBlockState(blockpos).getMaterial() == Material.WATER)
                {
                    itemStackIn.playSound(worldIn, worldIn.posX, worldIn.posY, worldIn.posZ, SoundEvents.ITEM_BOTTLE_FILL, SoundCategory.NEUTRAL, 1.0F, 1.0F);
                    return new ActionResult(EnumActionResult.SUCCESS, this.turnBottleIntoItem(itemstack, worldIn, PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM), PotionTypes.WATER)));
                }
            }

            return new ActionResult(EnumActionResult.PASS, itemstack);
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:49,代码来源:ItemGlassBottle.java

示例13: onItemRightClick

import net.minecraft.world.World; //导入方法依赖的package包/类
public ActionResult<ItemStack> onItemRightClick(World itemStackIn, EntityPlayer worldIn, EnumHand playerIn)
{
    ItemStack itemstack = worldIn.getHeldItem(playerIn);

    if (itemStackIn.isRemote)
    {
        return new ActionResult(EnumActionResult.PASS, itemstack);
    }
    else
    {
        RayTraceResult raytraceresult = this.rayTrace(itemStackIn, worldIn, true);

        if (raytraceresult != null && raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK)
        {
            BlockPos blockpos = raytraceresult.getBlockPos();

            if (!(itemStackIn.getBlockState(blockpos).getBlock() instanceof BlockLiquid))
            {
                return new ActionResult(EnumActionResult.PASS, itemstack);
            }
            else if (itemStackIn.isBlockModifiable(worldIn, blockpos) && worldIn.canPlayerEdit(blockpos, raytraceresult.sideHit, itemstack))
            {
                Entity entity = spawnCreature(itemStackIn, func_190908_h(itemstack), (double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 0.5D, (double)blockpos.getZ() + 0.5D);

                if (entity == null)
                {
                    return new ActionResult(EnumActionResult.PASS, itemstack);
                }
                else
                {
                    if (entity instanceof EntityLivingBase && itemstack.hasDisplayName())
                    {
                        entity.setCustomNameTag(itemstack.getDisplayName());
                    }

                    applyItemEntityDataToEntity(itemStackIn, worldIn, itemstack, entity);

                    if (!worldIn.capabilities.isCreativeMode)
                    {
                        itemstack.func_190918_g(1);
                    }

                    worldIn.addStat(StatList.getObjectUseStats(this));
                    return new ActionResult(EnumActionResult.SUCCESS, itemstack);
                }
            }
            else
            {
                return new ActionResult(EnumActionResult.FAIL, itemstack);
            }
        }
        else
        {
            return new ActionResult(EnumActionResult.PASS, itemstack);
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:58,代码来源:ItemMonsterPlacer.java


注:本文中的net.minecraft.world.World.isBlockModifiable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。