Search in sources :

Example 1 with CameraView

use of net.geforcemods.securitycraft.misc.CameraView in project SecurityCraft by Geforce132.

the class ItemCameraMonitor method onItemUse.

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (!worldIn.isRemote) {
        if (BlockUtils.getBlock(worldIn, pos) == SCContent.securityCamera) {
            if (!((IOwnable) worldIn.getTileEntity(pos)).getOwner().isOwner(playerIn)) {
                PlayerUtils.sendMessageToPlayer(playerIn, ClientUtils.localize("item.cameraMonitor.name"), ClientUtils.localize("messages.cameraMonitor.cannotView"), TextFormatting.RED);
                return EnumActionResult.SUCCESS;
            }
            if (playerIn.inventory.getCurrentItem().getTagCompound() == null)
                playerIn.inventory.getCurrentItem().setTagCompound(new NBTTagCompound());
            CameraView view = new CameraView(pos, playerIn.dimension);
            if (isCameraAdded(playerIn.inventory.getCurrentItem().getTagCompound(), view)) {
                playerIn.inventory.getCurrentItem().getTagCompound().removeTag(getTagNameFromPosition(playerIn.inventory.getCurrentItem().getTagCompound(), view));
                PlayerUtils.sendMessageToPlayer(playerIn, ClientUtils.localize("item.cameraMonitor.name"), ClientUtils.localize("messages.cameraMonitor.unbound").replace("#", Utils.getFormattedCoordinates(pos)), TextFormatting.RED);
                return EnumActionResult.SUCCESS;
            }
            for (int i = 1; i <= 30; i++) if (!playerIn.inventory.getCurrentItem().getTagCompound().hasKey("Camera" + i)) {
                playerIn.inventory.getCurrentItem().getTagCompound().setString("Camera" + i, view.toNBTString());
                PlayerUtils.sendMessageToPlayer(playerIn, ClientUtils.localize("item.cameraMonitor.name"), ClientUtils.localize("messages.cameraMonitor.bound").replace("#", Utils.getFormattedCoordinates(pos)), TextFormatting.GREEN);
                break;
            }
            SecurityCraft.network.sendTo(new PacketCUpdateNBTTag(stack), (EntityPlayerMP) playerIn);
            return EnumActionResult.SUCCESS;
        }
    } else if (worldIn.isRemote && BlockUtils.getBlock(worldIn, pos) != SCContent.securityCamera) {
        if (playerIn.getRidingEntity() != null && playerIn.getRidingEntity() instanceof EntitySecurityCamera)
            return EnumActionResult.SUCCESS;
        if (stack.getTagCompound() == null || stack.getTagCompound().hasNoTags()) {
            PlayerUtils.sendMessageToPlayer(playerIn, ClientUtils.localize("item.cameraMonitor.name"), ClientUtils.localize("messages.cameraMonitor.rightclickToView"), TextFormatting.RED);
            return EnumActionResult.SUCCESS;
        }
        playerIn.openGui(SecurityCraft.instance, GuiHandler.CAMERA_MONITOR_GUI_ID, worldIn, pos.getX(), pos.getY(), pos.getZ());
        return EnumActionResult.SUCCESS;
    }
    return EnumActionResult.SUCCESS;
}
Also used : EntitySecurityCamera(net.geforcemods.securitycraft.entity.EntitySecurityCamera) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOwnable(net.geforcemods.securitycraft.api.IOwnable) PacketCUpdateNBTTag(net.geforcemods.securitycraft.network.packets.PacketCUpdateNBTTag) CameraView(net.geforcemods.securitycraft.misc.CameraView)

Example 2 with CameraView

use of net.geforcemods.securitycraft.misc.CameraView in project SecurityCraft by Geforce132.

the class ItemCameraMonitorRenderer method renderItem.

@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
    if (type == ItemRenderType.FIRST_PERSON_MAP) {
        // Draw the base monitor texture.
        ((TextureManager) data[1]).bindTexture(new ResourceLocation("securitycraft:textures/gui/camera/cameraBackground.png"));
        Tessellator tessellator = Tessellator.instance;
        tessellator.startDrawingQuads();
        tessellator.addVertexWithUV(0 - 7, 128 + 7, 0.0D, 0.0D, 1.0D);
        tessellator.addVertexWithUV(128 + 7, 128 + 7, 0.0D, 1.0D, 1.0D);
        tessellator.addVertexWithUV(128 + 7, 0 - 7, 0.0D, 1.0D, 0.0D);
        tessellator.addVertexWithUV(0 - 7, 0 - 7, 0.0D, 0.0D, 0.0D);
        tessellator.draw();
        if (item != null && item.getItem() instanceof ItemCameraMonitor && ((ItemCameraMonitor) item.getItem()).hasCameraAdded(item.getTagCompound())) {
            CameraView view = ((ItemCameraMonitor) item.getItem()).getCameraView(item.getTagCompound());
            if (SecurityCraft.instance.hasViewForCoords(view.toNBTString())) {
                IWorldView worldView = SecurityCraft.instance.getViewFromCoords(view.toNBTString()).getView();
                if (worldView.isReady() && worldView.getTexture() != 0) {
                    // Bind the IWorldView texture then draw it.
                    GL11.glDisable(3008);
                    GL11.glDisable(2896);
                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, worldView.getTexture());
                    tessellator.startDrawingQuads();
                    tessellator.addVertexWithUV(128 + 7, 0 - 7, 0.0D, 0.0D, 1.0D);
                    tessellator.addVertexWithUV(0 - 7, 0 - 7, 0.0D, -1.0D, 1.0D);
                    tessellator.addVertexWithUV(0 - 7, 128 + 7, 0.0D, -1.0D, 0.0D);
                    tessellator.addVertexWithUV(128 + 7, 128 + 7, 0.0D, 0.0D, 0.0D);
                    tessellator.draw();
                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
                    GL11.glEnable(3008);
                    GL11.glEnable(2896);
                // 
                }
                // Update the camera.
                worldView.markDirty();
            }
        }
    }
}
Also used : TextureManager(net.minecraft.client.renderer.texture.TextureManager) Tessellator(net.minecraft.client.renderer.Tessellator) ItemCameraMonitor(net.geforcemods.securitycraft.items.ItemCameraMonitor) ResourceLocation(net.minecraft.util.ResourceLocation) CameraView(net.geforcemods.securitycraft.misc.CameraView) IWorldView(com.xcompwiz.lookingglass.api.view.IWorldView)

Example 3 with CameraView

use of net.geforcemods.securitycraft.misc.CameraView in project SecurityCraft by Geforce132.

the class ItemCameraMonitor method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stack = playerIn.getHeldItem(hand);
    if (!worldIn.isRemote) {
        if (BlockUtils.getBlock(worldIn, pos) == SCContent.securityCamera) {
            if (!((IOwnable) worldIn.getTileEntity(pos)).getOwner().isOwner(playerIn)) {
                PlayerUtils.sendMessageToPlayer(playerIn, ClientUtils.localize("item.cameraMonitor.name"), ClientUtils.localize("messages.cameraMonitor.cannotView"), TextFormatting.RED);
                return EnumActionResult.SUCCESS;
            }
            if (playerIn.inventory.getCurrentItem().getTagCompound() == null)
                playerIn.inventory.getCurrentItem().setTagCompound(new NBTTagCompound());
            CameraView view = new CameraView(pos, playerIn.dimension);
            if (isCameraAdded(playerIn.inventory.getCurrentItem().getTagCompound(), view)) {
                playerIn.inventory.getCurrentItem().getTagCompound().removeTag(getTagNameFromPosition(playerIn.inventory.getCurrentItem().getTagCompound(), view));
                PlayerUtils.sendMessageToPlayer(playerIn, ClientUtils.localize("item.cameraMonitor.name"), ClientUtils.localize("messages.cameraMonitor.unbound").replace("#", Utils.getFormattedCoordinates(pos)), TextFormatting.RED);
                return EnumActionResult.SUCCESS;
            }
            for (int i = 1; i <= 30; i++) if (!playerIn.inventory.getCurrentItem().getTagCompound().hasKey("Camera" + i)) {
                playerIn.inventory.getCurrentItem().getTagCompound().setString("Camera" + i, view.toNBTString());
                PlayerUtils.sendMessageToPlayer(playerIn, ClientUtils.localize("item.cameraMonitor.name"), ClientUtils.localize("messages.cameraMonitor.bound").replace("#", Utils.getFormattedCoordinates(pos)), TextFormatting.GREEN);
                break;
            }
            SecurityCraft.network.sendTo(new PacketCUpdateNBTTag(stack), (EntityPlayerMP) playerIn);
            return EnumActionResult.SUCCESS;
        }
    } else if (worldIn.isRemote && BlockUtils.getBlock(worldIn, pos) != SCContent.securityCamera) {
        if (playerIn.getRidingEntity() != null && playerIn.getRidingEntity() instanceof EntitySecurityCamera)
            return EnumActionResult.SUCCESS;
        if (stack.getTagCompound() == null || stack.getTagCompound().hasNoTags()) {
            PlayerUtils.sendMessageToPlayer(playerIn, ClientUtils.localize("item.cameraMonitor.name"), ClientUtils.localize("messages.cameraMonitor.rightclickToView"), TextFormatting.RED);
            return EnumActionResult.SUCCESS;
        }
        playerIn.openGui(SecurityCraft.instance, GuiHandler.CAMERA_MONITOR_GUI_ID, worldIn, pos.getX(), pos.getY(), pos.getZ());
        return EnumActionResult.SUCCESS;
    }
    return EnumActionResult.SUCCESS;
}
Also used : EntitySecurityCamera(net.geforcemods.securitycraft.entity.EntitySecurityCamera) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOwnable(net.geforcemods.securitycraft.api.IOwnable) ItemStack(net.minecraft.item.ItemStack) PacketCUpdateNBTTag(net.geforcemods.securitycraft.network.packets.PacketCUpdateNBTTag) CameraView(net.geforcemods.securitycraft.misc.CameraView)

Example 4 with CameraView

use of net.geforcemods.securitycraft.misc.CameraView in project SecurityCraft by Geforce132.

the class ItemCameraMonitor method onItemRightClick.

@Override
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
    if (!par2World.isRemote) {
        if (!par1ItemStack.hasTagCompound() || !hasCameraAdded(par1ItemStack.getTagCompound())) {
            PlayerUtils.sendMessageToPlayer(par3EntityPlayer, StatCollector.translateToLocal("item.cameraMonitor.name"), StatCollector.translateToLocal("messages.cameraMonitor.rightclickToView"), EnumChatFormatting.RED);
            return par1ItemStack;
        }
        if (SecurityCraft.instance.useLookingGlass()) {
            CameraView view = getCameraView(par1ItemStack.getTagCompound());
            if (!(par2World.getBlock(view.x, view.y, view.z) instanceof BlockSecurityCamera)) {
                PlayerUtils.sendMessageToPlayer(par3EntityPlayer, StatCollector.translateToLocal("item.cameraMonitor.name"), StatCollector.translateToLocal("messages.cameraMonitor.noCamera").replace("#", Utils.getFormattedCoordinates(view.x, view.y, view.z)), EnumChatFormatting.RED);
                return par1ItemStack;
            }
            SecurityCraft.network.sendTo(new PacketCCreateLGView(view.x, view.y, view.z, view.dimension), (EntityPlayerMP) par3EntityPlayer);
        } else
            par3EntityPlayer.openGui(SecurityCraft.instance, GuiHandler.CAMERA_MONITOR_GUI_ID, par2World, (int) par3EntityPlayer.posX, (int) par3EntityPlayer.posY, (int) par3EntityPlayer.posZ);
    }
    return par1ItemStack;
}
Also used : PacketCCreateLGView(net.geforcemods.securitycraft.network.packets.PacketCCreateLGView) BlockSecurityCamera(net.geforcemods.securitycraft.blocks.BlockSecurityCamera) CameraView(net.geforcemods.securitycraft.misc.CameraView)

Example 5 with CameraView

use of net.geforcemods.securitycraft.misc.CameraView in project SecurityCraft by Geforce132.

the class GuiCameraMonitor method actionPerformed.

@Override
protected void actionPerformed(GuiButton guibutton) {
    if (guibutton.id == -1)
        mc.displayGuiScreen(new GuiCameraMonitor(playerInventory, cameraMonitor, nbtTag, page - 1));
    else if (guibutton.id == 0)
        mc.displayGuiScreen(new GuiCameraMonitor(playerInventory, cameraMonitor, nbtTag, page + 1));
    else if (guibutton.id < 11) {
        int camID = guibutton.id + ((page - 1) * 10);
        CameraView view = (cameraMonitor.getCameraPositions(nbtTag).get(camID - 1));
        if (BlockUtils.getBlock(Minecraft.getMinecraft().theWorld, view.getLocation()) == SCContent.securityCamera) {
            ((BlockSecurityCamera) BlockUtils.getBlock(Minecraft.getMinecraft().theWorld, view.getLocation())).mountCamera(Minecraft.getMinecraft().theWorld, view.x, view.y, view.z, camID, Minecraft.getMinecraft().thePlayer);
            SecurityCraft.network.sendToServer(new PacketSMountCamera(view.x, view.y, view.z, camID));
            Minecraft.getMinecraft().thePlayer.closeScreen();
        } else
            guibutton.enabled = false;
    } else {
        int camID = (guibutton.id - 10) + ((page - 1) * 10);
        SecurityCraft.network.sendToServer(new PacketSRemoveCameraTag(playerInventory.getCurrentItem(), camID));
        nbtTag.removeTag(ItemCameraMonitor.getTagNameFromPosition(nbtTag, cameraMonitor.getCameraPositions(nbtTag).get(camID - 1)));
        guibutton.enabled = false;
        cameraButtons[(camID - 1) % 10].enabled = false;
    }
}
Also used : PacketSMountCamera(net.geforcemods.securitycraft.network.packets.PacketSMountCamera) PacketSRemoveCameraTag(net.geforcemods.securitycraft.network.packets.PacketSRemoveCameraTag) BlockSecurityCamera(net.geforcemods.securitycraft.blocks.BlockSecurityCamera) CameraView(net.geforcemods.securitycraft.misc.CameraView)

Aggregations

CameraView (net.geforcemods.securitycraft.misc.CameraView)10 IOwnable (net.geforcemods.securitycraft.api.IOwnable)4 PacketCUpdateNBTTag (net.geforcemods.securitycraft.network.packets.PacketCUpdateNBTTag)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 BlockSecurityCamera (net.geforcemods.securitycraft.blocks.BlockSecurityCamera)3 EntitySecurityCamera (net.geforcemods.securitycraft.entity.EntitySecurityCamera)3 ItemCameraMonitor (net.geforcemods.securitycraft.items.ItemCameraMonitor)2 PacketCCreateLGView (net.geforcemods.securitycraft.network.packets.PacketCCreateLGView)2 IWorldView (com.xcompwiz.lookingglass.api.view.IWorldView)1 ArrayList (java.util.ArrayList)1 PacketCSetCameraLocation (net.geforcemods.securitycraft.network.packets.PacketCSetCameraLocation)1 PacketGivePotionEffect (net.geforcemods.securitycraft.network.packets.PacketGivePotionEffect)1 PacketSMountCamera (net.geforcemods.securitycraft.network.packets.PacketSMountCamera)1 PacketSRemoveCameraTag (net.geforcemods.securitycraft.network.packets.PacketSRemoveCameraTag)1 TileEntityFrame (net.geforcemods.securitycraft.tileentity.TileEntityFrame)1 GuiButton (net.minecraft.client.gui.GuiButton)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 TextureManager (net.minecraft.client.renderer.texture.TextureManager)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1