ItemSeeds.java 文件源码

java
阅读 23 收藏 0 点赞 0 评论 0

项目:ExPetrum 作者:
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    if (worldIn.isRemote)
    {
        return EnumActionResult.FAIL;
    }

    TileEntity tile = worldIn.getTileEntity(pos);
    if (tile != null && tile.hasCapability(ExPFarmlandCapability.farmlandCap, EnumFacing.UP))
    {
        if (worldIn.isAirBlock(pos.up()))
        {
            // FIXME fix packet pipeline render issues!
            try
            {
                ItemStack held = player.getHeldItem(hand);
                CapabilityExPSeeds seedsCap = (CapabilityExPSeeds) held.getCapability(ExPSeedsCapability.seedsCap, null);
                CropStats stats = new CropStats(seedsCap.getOrCreateStats());
                worldIn.setBlockState(pos.up(), ExPBlocks.crop.getDefaultState());
                TileCrop cropTile = (TileCrop) worldIn.getTileEntity(pos.up());
                ExPCrop cropCap = (ExPCrop) IExPCrop.of(cropTile);
                cropCap.stats = stats;
                cropCap.timeKeeper = new Calendar(IExPWorld.of(worldIn).today().getTime());
                NBTTagCompound sent = new NBTTagCompound();
                sent.setTag("tileData", cropTile.serializeNBT());
                sent.setTag("blockPosData", new DimBlockPos(pos.up(), worldIn.provider.getDimension()).serializeNBT());
                VoidNetwork.sendDataToAllAround(PacketType.TileData, sent, new TargetPoint(worldIn.provider.getDimension(), pos.getX(), pos.up().getY(), pos.getZ(), 96));
                held.shrink(1);
                return EnumActionResult.SUCCESS;
            }
            catch (Exception ex)
            {
                ExPMisc.modLogger.log(LogLevel.Error, "Unable to place seeds at %s!", ex, pos.toString());
            }
        }
    }

    return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号