Search in sources :

Example 6 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, 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 7 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, BlockPos pos, EntityPlayer par5EntityPlayer) {
    if (par1ItemStack.getTagCompound() == null) {
        return;
    }
    for (int i = 1; i <= 6; i++) {
        if (par1ItemStack.getTagCompound().getIntArray("mine" + i).length > 0) {
            int[] coords = par1ItemStack.getTagCompound().getIntArray("mine" + i);
            if (coords[0] == pos.getX() && coords[1] == pos.getY() && coords[2] == pos.getZ()) {
                par1ItemStack.getTagCompound().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 8 with PacketCUpdateNBTTag

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

the class ItemMineRemoteAccessTool 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) instanceof IExplosive) {
            if (!isMineAdded(stack, worldIn, pos)) {
                int availSlot = this.getNextAvaliableSlot(stack);
                if (availSlot == 0) {
                    PlayerUtils.sendMessageToPlayer(playerIn, I18n.translateToLocal("item.remoteAccessMine.name"), I18n.translateToLocal("messages.mrat.noSlots"), TextFormatting.RED);
                    return EnumActionResult.FAIL;
                }
                if (worldIn.getTileEntity(pos) instanceof IOwnable && !((IOwnable) worldIn.getTileEntity(pos)).getOwner().isOwner(playerIn)) {
                    PlayerUtils.sendMessageToPlayer(playerIn, I18n.translateToLocal("item.remoteAccessMine.name"), I18n.translateToLocal("messages.mrat.cantBind"), TextFormatting.RED);
                    return EnumActionResult.FAIL;
                }
                if (stack.getTagCompound() == null) {
                    stack.setTagCompound(new NBTTagCompound());
                }
                stack.getTagCompound().setIntArray(("mine" + availSlot), new int[] { BlockUtils.fromPos(pos)[0], BlockUtils.fromPos(pos)[1], BlockUtils.fromPos(pos)[2] });
                mod_SecurityCraft.network.sendTo(new PacketCUpdateNBTTag(stack), (EntityPlayerMP) playerIn);
                PlayerUtils.sendMessageToPlayer(playerIn, I18n.translateToLocal("item.remoteAccessMine.name"), I18n.translateToLocal("messages.mrat.bound").replace("#", Utils.getFormattedCoordinates(pos)), TextFormatting.GREEN);
            } else {
                this.removeTagFromItemAndUpdate(stack, pos, playerIn);
                PlayerUtils.sendMessageToPlayer(playerIn, I18n.translateToLocal("item.remoteAccessMine.name"), I18n.translateToLocal("messages.mrat.unbound").replace("#", Utils.getFormattedCoordinates(pos)), TextFormatting.RED);
            }
        } else {
            playerIn.openGui(mod_SecurityCraft.instance, GuiHandler.MRAT_MENU_ID, worldIn, (int) playerIn.posX, (int) playerIn.posY, (int) playerIn.posZ);
        }
    }
    return EnumActionResult.SUCCESS;
}
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)

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