Search in sources :

Example 1 with PacketCSetCameraLocation

use of net.geforcemods.securitycraft.network.packets.PacketCSetCameraLocation in project SecurityCraft by Geforce132.

the class ItemCameraMonitor 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) {
        //When the mod is using the LookingGlass system.
        if (mod_SecurityCraft.instance.useLookingGlass()) {
            if (par3World.getBlock(par4, par5, par6) instanceof BlockSecurityCamera) {
                if (!((TileEntitySecurityCamera) par3World.getTileEntity(par4, par5, par6)).getOwner().isOwner(par2EntityPlayer)) {
                    PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.cameraMonitor.name"), StatCollector.translateToLocal("messages.cameraMonitor.cannotView"), EnumChatFormatting.RED);
                    return false;
                }
                if (par1ItemStack.getTagCompound() == null) {
                    par1ItemStack.setTagCompound(new NBTTagCompound());
                }
                CameraView view = new CameraView(par4, par5, par6, par2EntityPlayer.dimension);
                if (isCameraAdded(par1ItemStack.getTagCompound(), view)) {
                    par1ItemStack.getTagCompound().removeTag(getTagNameFromPosition(par1ItemStack.getTagCompound(), view));
                    PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.cameraMonitor.name"), StatCollector.translateToLocal("messages.cameraMonitor.unbound").replace("#", Utils.getFormattedCoordinates(view.x, view.y, view.z)), EnumChatFormatting.RED);
                    return true;
                }
                par1ItemStack.getTagCompound().setString("Camera1", view.toNBTString());
                mod_SecurityCraft.network.sendTo(new PacketCCreateLGView(view.x, view.y, view.z, view.dimension), (EntityPlayerMP) par2EntityPlayer);
                PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.cameraMonitor.name"), StatCollector.translateToLocal("messages.cameraMonitor.bound").replace("#", Utils.getFormattedCoordinates(view.x, view.y, view.z)), EnumChatFormatting.GREEN);
                return true;
            } else if (par3World.getBlock(par4, par5, par6) == mod_SecurityCraft.frame) {
                if (!par1ItemStack.hasTagCompound() || !hasCameraAdded(par1ItemStack.getTagCompound()))
                    return false;
                CameraView view = getCameraView(par1ItemStack.getTagCompound());
                if (view == null)
                    return true;
                ((TileEntityFrame) par3World.getTileEntity(par4, par5, par6)).setCameraLocation(view.x, view.y, view.z, view.dimension);
                mod_SecurityCraft.network.sendToAll(new PacketCSetCameraLocation(par4, par5, par6, view.x, view.y, view.z, view.dimension));
                par1ItemStack.stackSize--;
                return true;
            } else {
                if (!par1ItemStack.hasTagCompound() || !hasCameraAdded(par1ItemStack.getTagCompound()))
                    return false;
                CameraView view = getCameraView(par1ItemStack.getTagCompound());
                if (view == null)
                    return true;
                if (!(par3World.getBlock(view.x, view.y, view.z) instanceof BlockSecurityCamera)) {
                    PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.cameraMonitor.name"), StatCollector.translateToLocal("messages.cameraMonitor.noCamera").replace("#", Utils.getFormattedCoordinates(view.x, view.y, view.z)), EnumChatFormatting.RED);
                    return false;
                }
                if (mod_SecurityCraft.instance.useLookingGlass()) {
                    mod_SecurityCraft.network.sendTo(new PacketCCreateLGView(view.x, view.y, view.z, view.dimension), (EntityPlayerMP) par2EntityPlayer);
                } else {
                    par2EntityPlayer.openGui(mod_SecurityCraft.instance, GuiHandler.CAMERA_MONITOR_GUI_ID, par3World, par4, par5, par6);
                }
                return false;
            }
        } else {
            //When the mod is using the built-in mounting system.
            if (par3World.getBlock(par4, par5, par6) == mod_SecurityCraft.securityCamera) {
                if (!((IOwnable) par3World.getTileEntity(par4, par5, par6)).getOwner().isOwner(par2EntityPlayer)) {
                    PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.cameraMonitor.name"), StatCollector.translateToLocal("messages.cameraMonitor.cannotView"), EnumChatFormatting.RED);
                    return true;
                }
                if (par2EntityPlayer.getCurrentEquippedItem().getTagCompound() == null) {
                    par2EntityPlayer.getCurrentEquippedItem().setTagCompound(new NBTTagCompound());
                }
                CameraView view = new CameraView(par4, par5, par6, par2EntityPlayer.dimension);
                if (isCameraAdded(par2EntityPlayer.getCurrentEquippedItem().getTagCompound(), view)) {
                    par2EntityPlayer.getCurrentEquippedItem().getTagCompound().removeTag(getTagNameFromPosition(par2EntityPlayer.getCurrentEquippedItem().getTagCompound(), view));
                    PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.cameraMonitor.name"), StatCollector.translateToLocal("messages.cameraMonitor.unbound").replace("#", Utils.getFormattedCoordinates(par4, par5, par6)), EnumChatFormatting.RED);
                    return true;
                }
                for (int i = 1; i <= 30; i++) {
                    if (!par2EntityPlayer.getCurrentEquippedItem().getTagCompound().hasKey("Camera" + i)) {
                        par2EntityPlayer.getCurrentEquippedItem().getTagCompound().setString("Camera" + i, view.toNBTString());
                        PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.cameraMonitor.name"), StatCollector.translateToLocal("messages.cameraMonitor.bound").replace("#", Utils.getFormattedCoordinates(par4, par5, par6)), EnumChatFormatting.GREEN);
                        break;
                    }
                }
                mod_SecurityCraft.network.sendTo(new PacketCUpdateNBTTag(par1ItemStack), (EntityPlayerMP) par2EntityPlayer);
                return true;
            }
        }
    }
    return true;
}
Also used : PacketCSetCameraLocation(net.geforcemods.securitycraft.network.packets.PacketCSetCameraLocation) PacketCCreateLGView(net.geforcemods.securitycraft.network.packets.PacketCCreateLGView) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOwnable(net.geforcemods.securitycraft.api.IOwnable) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PacketCUpdateNBTTag(net.geforcemods.securitycraft.network.packets.PacketCUpdateNBTTag) BlockSecurityCamera(net.geforcemods.securitycraft.blocks.BlockSecurityCamera) TileEntitySecurityCamera(net.geforcemods.securitycraft.tileentity.TileEntitySecurityCamera) CameraView(net.geforcemods.securitycraft.misc.CameraView)

Aggregations

IOwnable (net.geforcemods.securitycraft.api.IOwnable)1 BlockSecurityCamera (net.geforcemods.securitycraft.blocks.BlockSecurityCamera)1 CameraView (net.geforcemods.securitycraft.misc.CameraView)1 PacketCCreateLGView (net.geforcemods.securitycraft.network.packets.PacketCCreateLGView)1 PacketCSetCameraLocation (net.geforcemods.securitycraft.network.packets.PacketCSetCameraLocation)1 PacketCUpdateNBTTag (net.geforcemods.securitycraft.network.packets.PacketCUpdateNBTTag)1 TileEntitySecurityCamera (net.geforcemods.securitycraft.tileentity.TileEntitySecurityCamera)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1