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


Java EntityArmorStand.writeToNBTOptional方法代码示例

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


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

示例1: onItemUse

import net.minecraft.entity.item.EntityArmorStand; //导入方法依赖的package包/类
/**
 * Called when a Block is right-clicked with this Item
 */
public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
{
    if (side == EnumFacing.DOWN)
    {
        return false;
    }
    else
    {
        boolean flag = worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos);
        BlockPos blockpos = flag ? pos : pos.offset(side);

        if (!playerIn.canPlayerEdit(blockpos, side, stack))
        {
            return false;
        }
        else
        {
            BlockPos blockpos1 = blockpos.up();
            boolean flag1 = !worldIn.isAirBlock(blockpos) && !worldIn.getBlockState(blockpos).getBlock().isReplaceable(worldIn, blockpos);
            flag1 = flag1 | (!worldIn.isAirBlock(blockpos1) && !worldIn.getBlockState(blockpos1).getBlock().isReplaceable(worldIn, blockpos1));

            if (flag1)
            {
                return false;
            }
            else
            {
                double d0 = (double)blockpos.getX();
                double d1 = (double)blockpos.getY();
                double d2 = (double)blockpos.getZ();
                List<Entity> list = worldIn.getEntitiesWithinAABBExcludingEntity((Entity)null, AxisAlignedBB.fromBounds(d0, d1, d2, d0 + 1.0D, d1 + 2.0D, d2 + 1.0D));

                if (list.size() > 0)
                {
                    return false;
                }
                else
                {
                    if (!worldIn.isRemote)
                    {
                        worldIn.setBlockToAir(blockpos);
                        worldIn.setBlockToAir(blockpos1);
                        EntityArmorStand entityarmorstand = new EntityArmorStand(worldIn, d0 + 0.5D, d1, d2 + 0.5D);
                        float f = (float)MathHelper.floor_float((MathHelper.wrapAngleTo180_float(playerIn.rotationYaw - 180.0F) + 22.5F) / 45.0F) * 45.0F;
                        entityarmorstand.setLocationAndAngles(d0 + 0.5D, d1, d2 + 0.5D, f, 0.0F);
                        this.applyRandomRotations(entityarmorstand, worldIn.rand);
                        NBTTagCompound nbttagcompound = stack.getTagCompound();

                        if (nbttagcompound != null && nbttagcompound.hasKey("EntityTag", 10))
                        {
                            NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                            entityarmorstand.writeToNBTOptional(nbttagcompound1);
                            nbttagcompound1.merge(nbttagcompound.getCompoundTag("EntityTag"));
                            entityarmorstand.readFromNBT(nbttagcompound1);
                        }

                        worldIn.spawnEntityInWorld(entityarmorstand);
                    }

                    --stack.stackSize;
                    return true;
                }
            }
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:70,代码来源:ItemArmorStand.java


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