ItemMaterial.java 文件源码

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

项目:LightningCraft 作者:
/** Right-click the item on a block */
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos,
        EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    switch(stack.getItemDamage()) {

    // Cell Upgrade usage
    case Material.UPGRADE:
        // upgrade an upgradable tile entity
        TileEntity tile = world.getTileEntity(pos);
        if(LCConfig.upgradeEnabled && tile != null && tile.hasCapability(LCCapabilities.LIGHTNING_UPGRADABLE, null) && 
                !tile.getCapability(LCCapabilities.LIGHTNING_UPGRADABLE, null).isUpgraded()) {
            EnumActionResult r = tile.getCapability(LCCapabilities.LIGHTNING_UPGRADABLE, null)
                    .onLightningUpgrade(stack, player, world, pos, hand, facing, hitX, hitY, hitZ);
            if(r == EnumActionResult.SUCCESS && !world.isRemote) {
                --stack.stackSize; // transfer the upgrade to the tile entity on success
                tile.markDirty();

                player.addStat(LCAchievements.upgradeMachine, 1); // give out the achievement

                // send a message to nearby clients to update the upgraded status
                LCNetwork.net.sendToAllAround(new MessageLightningUpgrade(pos), 
                        new TargetPoint(world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 1024));
            }
            return r;
        } else {
            return EnumActionResult.FAIL;
        }

    // Underworld Charge usage
    case Material.UNDER_CHARGE:

        if(!world.isRemote) {
            if(PortalUnderworld.ignitePortal(world, pos.up())) {
                if(player.capabilities.isCreativeMode == false) stack.stackSize--;
                Effect.lightning(world, pos.getX(), pos.getY() + 1, pos.getZ());
                if(stack.stackSize <= 0) stack = null;
            }
        }
        return EnumActionResult.SUCCESS;

    // Default usage
    default:
        return super.onItemUse(stack, player, world, pos, hand, facing, hitX, hitY, hitZ);
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号