Search in sources :

Example 1 with PacketCUpdateNBTTag

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

the class ItemMineRemoteAccessTool method removeTagFromItemAndUpdate.

private void removeTagFromItemAndUpdate(ItemStack par1ItemStack, int par2, int par3, int par4, EntityPlayer par5EntityPlayer) {
    if (par1ItemStack.stackTagCompound == null) {
        return;
    }
    for (int i = 1; i <= 6; i++) {
        if (par1ItemStack.stackTagCompound.getIntArray("mine" + i).length > 0) {
            int[] coords = par1ItemStack.stackTagCompound.getIntArray("mine" + i);
            if (coords[0] == par2 && coords[1] == par3 && coords[2] == par4) {
                par1ItemStack.stackTagCompound.setIntArray("mine" + i, new int[] { 0, 0, 0 });
                mod_SecurityCraft.network.sendTo(new PacketCUpdateNBTTag(par1ItemStack), (EntityPlayerMP) par5EntityPlayer);
                return;
            }
        } else {
            continue;
        }
    }
    return;
}
Also used : PacketCUpdateNBTTag(net.geforcemods.securitycraft.network.packets.PacketCUpdateNBTTag)

Example 2 with PacketCUpdateNBTTag

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

the class ItemMineRemoteAccessTool 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 (BlockUtils.getBlock(par3World, pos) instanceof IExplosive) {
            if (!isMineAdded(par1ItemStack, par3World, pos)) {
                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(pos) instanceof IOwnable && !((IOwnable) par3World.getTileEntity(pos)).getOwner().isOwner(par2EntityPlayer)) {
                    PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.remoteAccessMine.name"), StatCollector.translateToLocal("messages.mrat.cantBind"), EnumChatFormatting.RED);
                    return false;
                }
                if (par1ItemStack.getTagCompound() == null) {
                    par1ItemStack.setTagCompound(new NBTTagCompound());
                }
                par1ItemStack.getTagCompound().setIntArray(("mine" + availSlot), new int[] { BlockUtils.fromPos(pos)[0], BlockUtils.fromPos(pos)[1], BlockUtils.fromPos(pos)[2] });
                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(pos)), EnumChatFormatting.GREEN);
            } else {
                this.removeTagFromItemAndUpdate(par1ItemStack, pos, par2EntityPlayer);
                PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.remoteAccessMine.name"), StatCollector.translateToLocal("messages.mrat.unbound").replace("#", Utils.getFormattedCoordinates(pos)), 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 3 with PacketCUpdateNBTTag

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

the class ItemCameraMonitor method onItemUse.

public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, BlockPos pos, EnumFacing side, float par8, float par9, float par10) {
    if (!par3World.isRemote) {
        if (BlockUtils.getBlock(par3World, pos) == mod_SecurityCraft.securityCamera) {
            if (!((IOwnable) par3World.getTileEntity(pos)).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(pos, 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(pos)), 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(pos)), EnumChatFormatting.GREEN);
                    break;
                }
            }
            mod_SecurityCraft.network.sendTo(new PacketCUpdateNBTTag(par1ItemStack), (EntityPlayerMP) par2EntityPlayer);
            return true;
        }
    } else if (par3World.isRemote && BlockUtils.getBlock(par3World, pos) != mod_SecurityCraft.securityCamera) {
        if (par2EntityPlayer.ridingEntity != null && par2EntityPlayer.ridingEntity instanceof EntitySecurityCamera)
            return true;
        if (par1ItemStack.getTagCompound() == null || par1ItemStack.getTagCompound().hasNoTags()) {
            PlayerUtils.sendMessageToPlayer(par2EntityPlayer, StatCollector.translateToLocal("item.cameraMonitor.name"), StatCollector.translateToLocal("messages.cameraMonitor.rightclickToView"), EnumChatFormatting.RED);
            return true;
        }
        par2EntityPlayer.openGui(mod_SecurityCraft.instance, GuiHandler.CAMERA_MONITOR_GUI_ID, par3World, pos.getX(), pos.getY(), pos.getZ());
        return true;
    }
    return true;
}
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 4 with PacketCUpdateNBTTag

use of net.geforcemods.securitycraft.network.packets.PacketCUpdateNBTTag 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) == mod_SecurityCraft.securityCamera) {
            if (!((IOwnable) worldIn.getTileEntity(pos)).getOwner().isOwner(playerIn)) {
                PlayerUtils.sendMessageToPlayer(playerIn, I18n.translateToLocal("item.cameraMonitor.name"), I18n.translateToLocal("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, I18n.translateToLocal("item.cameraMonitor.name"), I18n.translateToLocal("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, I18n.translateToLocal("item.cameraMonitor.name"), I18n.translateToLocal("messages.cameraMonitor.bound").replace("#", Utils.getFormattedCoordinates(pos)), TextFormatting.GREEN);
                    break;
                }
            }
            mod_SecurityCraft.network.sendTo(new PacketCUpdateNBTTag(stack), (EntityPlayerMP) playerIn);
            return EnumActionResult.SUCCESS;
        }
    } else if (worldIn.isRemote && BlockUtils.getBlock(worldIn, pos) != mod_SecurityCraft.securityCamera) {
        if (playerIn.getRidingEntity() != null && playerIn.getRidingEntity() instanceof EntitySecurityCamera)
            return EnumActionResult.SUCCESS;
        if (stack.getTagCompound() == null || stack.getTagCompound().hasNoTags()) {
            PlayerUtils.sendMessageToPlayer(playerIn, I18n.translateToLocal("item.cameraMonitor.name"), I18n.translateToLocal("messages.cameraMonitor.rightclickToView"), TextFormatting.RED);
            return EnumActionResult.SUCCESS;
        }
        playerIn.openGui(mod_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 5 with PacketCUpdateNBTTag

use of net.geforcemods.securitycraft.network.packets.PacketCUpdateNBTTag 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

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