Search in sources :

Example 21 with IOwnable

use of net.geforcemods.securitycraft.api.IOwnable in project SecurityCraft by Geforce132.

the class ItemMineRemoteAccessTool method onItemUse.

public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) {
    if (!par3World.isRemote) {
        if (par3World.getBlock(par4, par5, par6) instanceof IExplosive) {
            if (!isMineAdded(par1ItemStack, par3World, par4, par5, par6)) {
                int availSlot = this.getNextAvaliableSlot(par1ItemStack);
                if (availSlot == 0) {
                    PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.remoteAccessMine.name"), StatCollector.translateToLocal("messages.mrat.noSlots"), EnumChatFormatting.RED);
                    return false;
                }
                if (par3World.getTileEntity(par4, par5, par6) instanceof IOwnable && !((IOwnable) par3World.getTileEntity(par4, par5, par6)).getOwner().isOwner(par2EntityPlayer)) {
                    PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.remoteAccessMine.name"), StatCollector.translateToLocal("messages.mrat.cantBind"), EnumChatFormatting.RED);
                    return false;
                }
                if (par1ItemStack.stackTagCompound == null) {
                    par1ItemStack.stackTagCompound = new NBTTagCompound();
                }
                par1ItemStack.stackTagCompound.setIntArray(("mine" + availSlot), new int[] { par4, par5, par6 });
                mod_SecurityCraft.network.sendTo(new PacketCUpdateNBTTag(par1ItemStack), (EntityPlayerMP) par2EntityPlayer);
                PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.remoteAccessMine.name"), StatCollector.translateToLocal("messages.mrat.bound").replace("#", Utils.getFormattedCoordinates(par4, par5, par6)), EnumChatFormatting.GREEN);
            } else {
                this.removeTagFromItemAndUpdate(par1ItemStack, par4, par5, par6, par2EntityPlayer);
                PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.remoteAccessMine.name"), StatCollector.translateToLocal("messages.mrat.unbound").replace("#", Utils.getFormattedCoordinates(par4, par5, par6)), EnumChatFormatting.RED);
            }
        } else {
            par2EntityPlayer.openGui(mod_SecurityCraft.instance, GuiHandler.MRAT_MENU_ID, par3World, (int) par2EntityPlayer.posX, (int) par2EntityPlayer.posY, (int) par2EntityPlayer.posZ);
        }
    }
    return true;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOwnable(net.geforcemods.securitycraft.api.IOwnable) IExplosive(net.geforcemods.securitycraft.api.IExplosive) PacketCUpdateNBTTag(net.geforcemods.securitycraft.network.packets.PacketCUpdateNBTTag)

Example 22 with IOwnable

use of net.geforcemods.securitycraft.api.IOwnable in project SecurityCraft by Geforce132.

the class ItemAdminTool method onItemUse.

public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, BlockPos pos, EnumFacing par5EnumFacing, float hitX, float hitY, float hitZ) {
    if (!par3World.isRemote) {
        if (par3World.getTileEntity(pos) != null) {
            TileEntity te = par3World.getTileEntity(pos);
            boolean hasInfo = false;
            if (te instanceof IOwnable) {
                PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.adminTool.name"), StatCollector.translateToLocal("messages.adminTool.owner.name").replace("#", (((IOwnable) te).getOwner().getName() == null ? "????" : ((IOwnable) te).getOwner().getName())), EnumChatFormatting.DARK_PURPLE);
                PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.adminTool.name"), StatCollector.translateToLocal("messages.adminTool.owner.uuid").replace("#", (((IOwnable) te).getOwner().getUUID() == null ? "????" : ((IOwnable) te).getOwner().getUUID())), EnumChatFormatting.DARK_PURPLE);
                hasInfo = true;
            }
            if (te instanceof IPasswordProtected) {
                PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.adminTool.name"), StatCollector.translateToLocal("messages.adminTool.password").replace("#", (((IPasswordProtected) te).getPassword() == null ? "????" : ((IPasswordProtected) te).getPassword())), EnumChatFormatting.DARK_PURPLE);
                hasInfo = true;
            }
            if (te instanceof CustomizableSCTE) {
                List<EnumCustomModules> modules = ((CustomizableSCTE) te).getModules();
                if (!modules.isEmpty()) {
                    PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.adminTool.name"), StatCollector.translateToLocal("messages.adminTool.equippedModules"), EnumChatFormatting.DARK_PURPLE);
                    for (EnumCustomModules module : modules) {
                        PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.adminTool.name"), "-" + module.getName(), EnumChatFormatting.DARK_PURPLE);
                    }
                    hasInfo = true;
                }
            }
            if (!hasInfo) {
                PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.adminTool.name"), StatCollector.translateToLocal("messages.adminTool.noInfo"), EnumChatFormatting.DARK_PURPLE);
            }
            return false;
        }
        PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.adminTool.name"), StatCollector.translateToLocal("messages.adminTool.noInfo"), EnumChatFormatting.DARK_PURPLE);
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPasswordProtected(net.geforcemods.securitycraft.api.IPasswordProtected) CustomizableSCTE(net.geforcemods.securitycraft.api.CustomizableSCTE) IOwnable(net.geforcemods.securitycraft.api.IOwnable) EnumCustomModules(net.geforcemods.securitycraft.misc.EnumCustomModules)

Example 23 with IOwnable

use of net.geforcemods.securitycraft.api.IOwnable in project SecurityCraft by Geforce132.

the class ItemBlockReinforcedSlabs method tryPlace.

private boolean tryPlace(ItemStack stack, World worldIn, BlockPos pos, Object variantInStack) {
    IBlockState iblockstate = worldIn.getBlockState(pos);
    Owner owner = null;
    if (worldIn.getTileEntity(pos) instanceof IOwnable) {
        owner = ((IOwnable) worldIn.getTileEntity(pos)).getOwner();
    }
    if (iblockstate.getBlock() == this.singleSlab) {
        Comparable<?> comparable = iblockstate.getValue(this.singleSlab.getVariantProperty());
        if (comparable == variantInStack) {
            IBlockState iblockstate1 = this.doubleSlab.getDefaultState().withProperty(this.singleSlab.getVariantProperty(), comparable);
            if (worldIn.checkNoEntityCollision(this.doubleSlab.getCollisionBoundingBox(worldIn, pos, iblockstate1)) && worldIn.setBlockState(pos, iblockstate1, 3)) {
                worldIn.playSoundEffect(pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, this.doubleSlab.stepSound.getPlaceSound(), (this.doubleSlab.stepSound.getVolume() + 1.0F) / 2.0F, this.doubleSlab.stepSound.getFrequency() * 0.8F);
                --stack.stackSize;
                if (owner != null) {
                    ((IOwnable) worldIn.getTileEntity(pos)).getOwner().set(owner.getUUID(), owner.getName());
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Owner(net.geforcemods.securitycraft.api.Owner) IBlockState(net.minecraft.block.state.IBlockState) IOwnable(net.geforcemods.securitycraft.api.IOwnable)

Example 24 with IOwnable

use of net.geforcemods.securitycraft.api.IOwnable in project SecurityCraft by Geforce132.

the class ItemBlockReinforcedWoodSlabs method tryPlace.

private boolean tryPlace(ItemStack stack, World worldIn, BlockPos pos, Object variantInStack) {
    IBlockState iblockstate = worldIn.getBlockState(pos);
    Owner owner = null;
    if (worldIn.getTileEntity(pos) instanceof IOwnable) {
        owner = ((IOwnable) worldIn.getTileEntity(pos)).getOwner();
    }
    if (iblockstate.getBlock() == this.singleSlab) {
        Comparable<?> comparable = iblockstate.getValue(this.singleSlab.getVariantProperty());
        if (comparable == variantInStack) {
            IBlockState iblockstate1 = this.doubleSlab.getDefaultState().withProperty(this.singleSlab.getVariantProperty(), comparable);
            if (worldIn.checkNoEntityCollision(this.doubleSlab.getCollisionBoundingBox(worldIn, pos, iblockstate1)) && worldIn.setBlockState(pos, iblockstate1, 3)) {
                worldIn.playSoundEffect(pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, this.doubleSlab.stepSound.getPlaceSound(), (this.doubleSlab.stepSound.getVolume() + 1.0F) / 2.0F, this.doubleSlab.stepSound.getFrequency() * 0.8F);
                --stack.stackSize;
                if (owner != null) {
                    ((IOwnable) worldIn.getTileEntity(pos)).getOwner().set(owner.getUUID(), owner.getName());
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Owner(net.geforcemods.securitycraft.api.Owner) IBlockState(net.minecraft.block.state.IBlockState) IOwnable(net.geforcemods.securitycraft.api.IOwnable)

Example 25 with IOwnable

use of net.geforcemods.securitycraft.api.IOwnable in project SecurityCraft by Geforce132.

the class ForgeEventHandler method onPlayerInteracted.

@SubscribeEvent
public void onPlayerInteracted(PlayerInteractEvent event) {
    if (!event.entityPlayer.worldObj.isRemote) {
        World world = event.entityPlayer.worldObj;
        TileEntity tileEntity = event.entityPlayer.worldObj.getTileEntity(event.pos);
        Block block = event.entityPlayer.worldObj.getBlockState(event.pos).getBlock();
        if (event.action != Action.RIGHT_CLICK_BLOCK)
            return;
        if (event.action == Action.RIGHT_CLICK_BLOCK && PlayerUtils.isHoldingItem(event.entityPlayer, mod_SecurityCraft.codebreaker) && handleCodebreaking(event)) {
            event.setCanceled(true);
            return;
        }
        if (event.action == Action.RIGHT_CLICK_BLOCK && tileEntity != null && tileEntity instanceof CustomizableSCTE && PlayerUtils.isHoldingItem(event.entityPlayer, mod_SecurityCraft.universalBlockModifier)) {
            event.setCanceled(true);
            if (!((IOwnable) tileEntity).getOwner().isOwner(event.entityPlayer)) {
                PlayerUtils.sendMessageToPlayer(event.entityPlayer, StatCollector.translateToLocal("item.universalBlockModifier.name"), StatCollector.translateToLocal("messages.notOwned").replace("#", ((TileEntityOwnable) tileEntity).getOwner().getName()), EnumChatFormatting.RED);
                return;
            }
            event.entityPlayer.openGui(mod_SecurityCraft.instance, GuiHandler.CUSTOMIZE_BLOCK, world, event.pos.getX(), event.pos.getY(), event.pos.getZ());
            return;
        }
        if (event.action == Action.RIGHT_CLICK_BLOCK && tileEntity instanceof INameable && ((INameable) tileEntity).canBeNamed() && PlayerUtils.isHoldingItem(event.entityPlayer, Items.name_tag) && event.entityPlayer.getCurrentEquippedItem().hasDisplayName()) {
            event.setCanceled(true);
            for (String character : new String[] { "(", ")" }) {
                if (event.entityPlayer.getCurrentEquippedItem().getDisplayName().contains(character)) {
                    PlayerUtils.sendMessageToPlayer(event.entityPlayer, "Naming", StatCollector.translateToLocal("messages.naming.error").replace("#n", event.entityPlayer.getCurrentEquippedItem().getDisplayName()).replace("#c", character), EnumChatFormatting.RED);
                    return;
                }
            }
            if (((INameable) tileEntity).getCustomName().matches(event.entityPlayer.getCurrentEquippedItem().getDisplayName())) {
                PlayerUtils.sendMessageToPlayer(event.entityPlayer, "Naming", StatCollector.translateToLocal("messages.naming.alreadyMatches").replace("#n", ((INameable) tileEntity).getCustomName()), EnumChatFormatting.RED);
                return;
            }
            event.entityPlayer.getCurrentEquippedItem().stackSize--;
            ((INameable) tileEntity).setCustomName(event.entityPlayer.getCurrentEquippedItem().getDisplayName());
            return;
        }
        if (event.action == Action.RIGHT_CLICK_BLOCK && tileEntity != null && isOwnableBlock(block, tileEntity) && PlayerUtils.isHoldingItem(event.entityPlayer, mod_SecurityCraft.universalBlockRemover)) {
            event.setCanceled(true);
            if (!((IOwnable) tileEntity).getOwner().isOwner(event.entityPlayer)) {
                PlayerUtils.sendMessageToPlayer(event.entityPlayer, StatCollector.translateToLocal("item.universalBlockRemover.name"), StatCollector.translateToLocal("messages.notOwned").replace("#", ((TileEntityOwnable) tileEntity).getOwner().getName()), EnumChatFormatting.RED);
                return;
            }
            if (block == mod_SecurityCraft.laserBlock) {
                world.destroyBlock(event.pos, true);
                BlockLaserBlock.destroyAdjecentLasers(event.world, event.pos.getX(), event.pos.getY(), event.pos.getZ());
                event.entityPlayer.getCurrentEquippedItem().damageItem(1, event.entityPlayer);
            } else {
                world.destroyBlock(event.pos, true);
                world.removeTileEntity(event.pos);
                event.entityPlayer.getCurrentEquippedItem().damageItem(1, event.entityPlayer);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) CustomizableSCTE(net.geforcemods.securitycraft.api.CustomizableSCTE) INameable(net.geforcemods.securitycraft.api.INameable) Block(net.minecraft.block.Block) BlockLaserBlock(net.geforcemods.securitycraft.blocks.BlockLaserBlock) IOwnable(net.geforcemods.securitycraft.api.IOwnable) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

IOwnable (net.geforcemods.securitycraft.api.IOwnable)32 Owner (net.geforcemods.securitycraft.api.Owner)13 TileEntity (net.minecraft.tileentity.TileEntity)10 CustomizableSCTE (net.geforcemods.securitycraft.api.CustomizableSCTE)8 IPasswordProtected (net.geforcemods.securitycraft.api.IPasswordProtected)6 PacketCUpdateNBTTag (net.geforcemods.securitycraft.network.packets.PacketCUpdateNBTTag)6 Block (net.minecraft.block.Block)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 IExplosive (net.geforcemods.securitycraft.api.IExplosive)5 EnumCustomModules (net.geforcemods.securitycraft.misc.EnumCustomModules)4 IBlockState (net.minecraft.block.state.IBlockState)4 ItemBlock (net.minecraft.item.ItemBlock)4 INameable (net.geforcemods.securitycraft.api.INameable)3 BlockReinforcedDoor (net.geforcemods.securitycraft.blocks.BlockReinforcedDoor)3 CameraView (net.geforcemods.securitycraft.misc.CameraView)3 TileEntitySCTE (net.geforcemods.securitycraft.api.TileEntitySCTE)2 BlockLaserBlock (net.geforcemods.securitycraft.blocks.BlockLaserBlock)2 EntitySecurityCamera (net.geforcemods.securitycraft.entity.EntitySecurityCamera)2 CustomHoverChecker (net.geforcemods.securitycraft.gui.components.CustomHoverChecker)2 ITileEntityProvider (net.minecraft.block.ITileEntityProvider)2