Search in sources :

Example 1 with UsableMetaItem

use of omtteam.openmodularturrets.items.UsableMetaItem in project OpenModularTurrets by OpenModularTurretsTeam.

the class BlockTurretBase method clOnBlockActivated.

@Override
protected boolean clOnBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (!world.isRemote && hand == EnumHand.MAIN_HAND) {
        ItemStack heldItem = player.getHeldItemMainhand();
        TurretBase base = (TurretBase) world.getTileEntity(pos);
        if (player.isSneaking() && ConfigHandler.isAllowBaseCamo() && heldItem == ItemStackTools.getEmptyStack()) {
            if (base != null) {
                if (player.getUniqueID().toString().equals(base.getOwner())) {
                    base.setCamoState(state);
                    world.notifyBlockUpdate(pos, state, state, 3);
                } else {
                    addChatMessage(player, new TextComponentString(safeLocalize("status.ownership")));
                }
            }
        }
        Block heldItemBlock = null;
        if (heldItem != ItemStackTools.getEmptyStack()) {
            heldItemBlock = Block.getBlockFromItem(heldItem.getItem());
        }
        if (!player.isSneaking() && ConfigHandler.isAllowBaseCamo() && heldItem != ItemStackTools.getEmptyStack() && heldItem.getItem() instanceof ItemBlock && heldItemBlock.isNormalCube(heldItemBlock.getStateFromMeta(heldItem.getMetadata())) && Block.getBlockFromItem(heldItem.getItem()).isOpaqueCube(heldItemBlock.getStateFromMeta(heldItem.getMetadata())) && !(Block.getBlockFromItem(heldItem.getItem()) instanceof BlockTurretBase)) {
            if (base != null) {
                if (player.getUniqueID().toString().equals(base.getOwner())) {
                    base.setCamoState(heldItemBlock.getStateFromMeta(heldItem.getItemDamage()));
                    world.notifyBlockUpdate(pos, state, state, 3);
                } else {
                    addChatMessage(player, new TextComponentString(safeLocalize("status.ownership")));
                }
            }
        } else if (player.isSneaking() && base != null && player.getHeldItemMainhand() != ItemStackTools.getEmptyStack() && player.getHeldItemMainhand().getItem() instanceof UsableMetaItem && player.getHeldItemMainhand().getItemDamage() == 2) {
            ((UsableMetaItem) player.getHeldItemMainhand().getItem()).setDataStored(player.getHeldItemMainhand(), base.writeMemoryCardNBT());
        } else if (!player.isSneaking() && base != null && player.getHeldItemMainhand() != ItemStackTools.getEmptyStack() && player.getHeldItemMainhand().getItem() instanceof UsableMetaItem && player.getHeldItemMainhand().getItemDamage() == 2 && ((UsableMetaItem) player.getHeldItemMainhand().getItem()).hasDataStored(player.getHeldItemMainhand())) {
            base.readMemoryCardNBT(((UsableMetaItem) player.getHeldItemMainhand().getItem()).getDataStored(player.getHeldItemMainhand()));
        } else if (!player.isSneaking() && base != null) {
            TrustedPlayer trustedPlayer = PlayerUtil.getTrustedPlayer(player, base);
            if (trustedPlayer != null && trustedPlayer.canOpenGUI) {
                world.notifyBlockUpdate(pos, state, state, 6);
                player.openGui(OpenModularTurrets.instance, base.getTier(), world, pos.getX(), pos.getY(), pos.getZ());
                return true;
            } else if (PlayerUtil.isPlayerOwner(player, base)) {
                world.notifyBlockUpdate(pos, state, state, 6);
                player.openGui(OpenModularTurrets.instance, base.getTier(), world, pos.getX(), pos.getY(), pos.getZ());
            } else {
                addChatMessage(player, new TextComponentString(safeLocalize("status.ownership")));
            }
        }
    }
    return true;
}
Also used : TrustedPlayer(omtteam.omlib.util.TrustedPlayer) UsableMetaItem(omtteam.openmodularturrets.items.UsableMetaItem) TurretBase(omtteam.openmodularturrets.tileentity.TurretBase) ItemBlockTurretBase(omtteam.openmodularturrets.items.blocks.ItemBlockTurretBase) Block(net.minecraft.block.Block) IHasItemBlock(omtteam.omlib.api.IHasItemBlock) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack) IHasItemBlock(omtteam.omlib.api.IHasItemBlock) ItemBlock(net.minecraft.item.ItemBlock) ItemBlockTurretBase(omtteam.openmodularturrets.items.blocks.ItemBlockTurretBase) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

Block (net.minecraft.block.Block)1 ItemBlock (net.minecraft.item.ItemBlock)1 ItemStack (net.minecraft.item.ItemStack)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 IHasItemBlock (omtteam.omlib.api.IHasItemBlock)1 TrustedPlayer (omtteam.omlib.util.TrustedPlayer)1 UsableMetaItem (omtteam.openmodularturrets.items.UsableMetaItem)1 ItemBlockTurretBase (omtteam.openmodularturrets.items.blocks.ItemBlockTurretBase)1 TurretBase (omtteam.openmodularturrets.tileentity.TurretBase)1