Search in sources :

Example 6 with IOwnable

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

the class BlockMine method activateMine.

public void activateMine(World world, int par2, int par3, int par4) {
    if (!world.isRemote) {
        Owner owner = ((IOwnable) world.getTileEntity(par2, par3, par4)).getOwner();
        world.setBlock(par2, par3, par4, mod_SecurityCraft.mine);
        ((IOwnable) world.getTileEntity(par2, par3, par4)).setOwner(owner.getUUID(), owner.getName());
    }
}
Also used : Owner(net.geforcemods.securitycraft.api.Owner) IOwnable(net.geforcemods.securitycraft.api.IOwnable)

Example 7 with IOwnable

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

the class ItemUniversalOwnerChanger method onItemUse.

@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
    TileEntity te = world.getTileEntity(pos);
    String newOwner = stack.getDisplayName();
    if (!world.isRemote) {
        if (!stack.hasDisplayName()) {
            PlayerUtils.sendMessageToPlayer(player, StatCollector.translateToLocal("item.universalOwnerChanger.name"), StatCollector.translateToLocal("messages.universalOwnerChanger.noName"), EnumChatFormatting.RED);
            return false;
        }
        if (!(te instanceof IOwnable)) {
            PlayerUtils.sendMessageToPlayer(player, StatCollector.translateToLocal("item.universalOwnerChanger.name"), StatCollector.translateToLocal("messages.universalOwnerChanger.cantChange"), EnumChatFormatting.RED);
            return false;
        }
        if (!((IOwnable) te).getOwner().isOwner(player)) {
            PlayerUtils.sendMessageToPlayer(player, StatCollector.translateToLocal("item.universalOwnerChanger.name"), StatCollector.translateToLocal("messages.universalOwnerChanger.notOwned"), EnumChatFormatting.RED);
            return false;
        }
        if (BlockUtils.getBlock(world, pos) instanceof BlockReinforcedDoor) {
            if (BlockUtils.getBlock(world, pos.up()) instanceof BlockReinforcedDoor)
                ((IOwnable) world.getTileEntity(pos.up())).getOwner().set(PlayerUtils.isPlayerOnline(newOwner) ? PlayerUtils.getPlayerFromName(newOwner).getUniqueID().toString() : "ownerUUID", newOwner);
            else
                ((IOwnable) world.getTileEntity(pos.up())).getOwner().set(PlayerUtils.isPlayerOnline(newOwner) ? PlayerUtils.getPlayerFromName(newOwner).getUniqueID().toString() : "ownerUUID", newOwner);
        }
        if (te instanceof IOwnable)
            ((IOwnable) te).getOwner().set(PlayerUtils.isPlayerOnline(newOwner) ? PlayerUtils.getPlayerFromName(newOwner).getUniqueID().toString() : "ownerUUID", newOwner);
        MinecraftServer.getServer().getConfigurationManager().sendPacketToAllPlayers(te.getDescriptionPacket());
        PlayerUtils.sendMessageToPlayer(player, StatCollector.translateToLocal("item.universalOwnerChanger.name"), StatCollector.translateToLocal("messages.universalOwnerChanger.changed").replace("#", newOwner), EnumChatFormatting.GREEN);
        return true;
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IOwnable(net.geforcemods.securitycraft.api.IOwnable) BlockReinforcedDoor(net.geforcemods.securitycraft.blocks.BlockReinforcedDoor)

Example 8 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, 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 9 with IOwnable

use of net.geforcemods.securitycraft.api.IOwnable 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 10 with IOwnable

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

the class GuiSCManual method updateRecipeAndIcons.

private void updateRecipeAndIcons() {
    if (this.currentPage < 0) {
        recipe = null;
        this.hoverCheckers.clear();
        return;
    }
    this.hoverCheckers.clear();
    if (mod_SecurityCraft.instance.manualPages.get(currentPage).hasCustomRecipe()) {
        this.recipe = mod_SecurityCraft.instance.manualPages.get(currentPage).getRecipe();
    } else {
        for (Object object : CraftingManager.getInstance().getRecipeList()) {
            if (object instanceof ShapedRecipes) {
                ShapedRecipes recipe = (ShapedRecipes) object;
                if (recipe.getRecipeOutput() != null && recipe.getRecipeOutput().getItem() == mod_SecurityCraft.instance.manualPages.get(currentPage).getItem()) {
                    this.recipe = recipe.recipeItems;
                    break;
                }
            } else if (object instanceof ShapelessRecipes) {
                ShapelessRecipes recipe = (ShapelessRecipes) object;
                if (recipe.getRecipeOutput() != null && recipe.getRecipeOutput().getItem() == mod_SecurityCraft.instance.manualPages.get(currentPage).getItem()) {
                    this.recipe = this.toItemStackArray(recipe.recipeItems);
                    break;
                }
            }
            this.recipe = null;
        }
    }
    if (recipe != null) {
        outer: for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if ((i * 3) + j == recipe.length)
                    break outer;
                if (recipe[(i * 3) + j] != null)
                    hoverCheckers.add(new CustomHoverChecker(144 + (i * 20), 144 + (i * 20) + 16, (k + 100) + (j * 20), (k + 100) + (j * 20) + 16, 20, recipe[(i * 3) + j].getDisplayName()));
            }
        }
    } else {
        String name = mod_SecurityCraft.instance.manualPages.get(currentPage).getItemName();
        //make first character lower case and remove spaces
        name = name.substring(0, 1).toLowerCase() + name.substring(1, name.length()).replace(" ", "");
        hoverCheckers.add(new CustomHoverChecker(144, 144 + (2 * 20) + 16, k + 100, (k + 100) + (2 * 20) + 16, 20, I18n.translateToLocal("gui.scManual.recipe." + name)));
    }
    Item item = mod_SecurityCraft.instance.manualPages.get(currentPage).getItem();
    TileEntity te = ((item instanceof ItemBlock && ((ItemBlock) item).getBlock() instanceof ITileEntityProvider) ? ((ITileEntityProvider) ((ItemBlock) item).getBlock()).createNewTileEntity(Minecraft.getMinecraft().theWorld, 0) : null);
    Block itemBlock = ((item instanceof ItemBlock) ? ((ItemBlock) item).getBlock() : null);
    if (te != null) {
        if (te instanceof IOwnable) {
            this.hoverCheckers.add(new CustomHoverChecker(118, 118 + 16, k + 29, (k + 29) + 16, 20, I18n.translateToLocal("gui.scManual.ownableBlock")));
        }
        if (te instanceof IPasswordProtected) {
            this.hoverCheckers.add(new CustomHoverChecker(118, 118 + 16, k + 55, (k + 55) + 16, 20, I18n.translateToLocal("gui.scManual.passwordProtectedBlock")));
        }
        if (te instanceof TileEntitySCTE && ((TileEntitySCTE) te).isActivatedByView()) {
            this.hoverCheckers.add(new CustomHoverChecker(118, 118 + 16, k + 81, (k + 81) + 16, 20, I18n.translateToLocal("gui.scManual.viewActivatedBlock")));
        }
        if (itemBlock instanceof IExplosive) {
            this.hoverCheckers.add(new CustomHoverChecker(118, 118 + 16, k + 107, (k + 107) + 16, 20, I18n.translateToLocal("gui.scManual.explosiveBlock")));
        }
        if (te instanceof CustomizableSCTE) {
            this.hoverCheckers.add(new CustomHoverChecker(118, 118 + 16, k + 213, (k + 213) + 16, 20, I18n.translateToLocal("gui.scManual.customizableBlock")));
        }
    }
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IPasswordProtected(net.geforcemods.securitycraft.api.IPasswordProtected) CustomHoverChecker(net.geforcemods.securitycraft.gui.components.CustomHoverChecker) TileEntitySCTE(net.geforcemods.securitycraft.api.TileEntitySCTE) ItemBlock(net.minecraft.item.ItemBlock) TileEntity(net.minecraft.tileentity.TileEntity) Item(net.minecraft.item.Item) ITileEntityProvider(net.minecraft.block.ITileEntityProvider) CustomizableSCTE(net.geforcemods.securitycraft.api.CustomizableSCTE) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) IOwnable(net.geforcemods.securitycraft.api.IOwnable) IExplosive(net.geforcemods.securitycraft.api.IExplosive) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes)

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