Search in sources :

Example 11 with CustomizableSCTE

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

the class BlockUtils method setBlockProperty.

public static void setBlockProperty(World par1World, BlockPos pos, PropertyBool property, boolean value, boolean retainOldTileEntity) {
    if (retainOldTileEntity) {
        ItemStack[] modules = null;
        ItemStack[] inventory = null;
        int[] times = new int[4];
        String password = "";
        Owner owner = null;
        int cooldown = -1;
        if (par1World.getTileEntity(pos) instanceof CustomizableSCTE)
            modules = ((CustomizableSCTE) par1World.getTileEntity(pos)).itemStacks;
        if (par1World.getTileEntity(pos) instanceof TileEntityKeypadFurnace) {
            inventory = ((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).furnaceItemStacks;
            times[0] = ((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).furnaceBurnTime;
            times[1] = ((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).currentItemBurnTime;
            times[2] = ((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).cookTime;
            times[3] = ((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).totalCookTime;
        }
        if (par1World.getTileEntity(pos) instanceof TileEntityOwnable && ((TileEntityOwnable) par1World.getTileEntity(pos)).getOwner() != null)
            owner = ((TileEntityOwnable) par1World.getTileEntity(pos)).getOwner();
        if (par1World.getTileEntity(pos) instanceof TileEntityKeypad && ((TileEntityKeypad) par1World.getTileEntity(pos)).getPassword() != null)
            password = ((TileEntityKeypad) par1World.getTileEntity(pos)).getPassword();
        if (par1World.getTileEntity(pos) instanceof TileEntityKeypadFurnace && ((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).getPassword() != null)
            password = ((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).getPassword();
        if (par1World.getTileEntity(pos) instanceof TileEntityKeypadChest && ((TileEntityKeypadChest) par1World.getTileEntity(pos)).getPassword() != null)
            password = ((TileEntityKeypadChest) par1World.getTileEntity(pos)).getPassword();
        if (par1World.getTileEntity(pos) instanceof TileEntityPortableRadar && ((TileEntityPortableRadar) par1World.getTileEntity(pos)).getAttackCooldown() != 0)
            cooldown = ((TileEntityPortableRadar) par1World.getTileEntity(pos)).getAttackCooldown();
        TileEntity tileEntity = par1World.getTileEntity(pos);
        par1World.setBlockState(pos, par1World.getBlockState(pos).withProperty(property, value));
        par1World.setTileEntity(pos, tileEntity);
        if (modules != null)
            ((CustomizableSCTE) par1World.getTileEntity(pos)).itemStacks = modules;
        if (inventory != null && par1World.getTileEntity(pos) instanceof TileEntityKeypadFurnace) {
            ((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).furnaceItemStacks = inventory;
            ((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).furnaceBurnTime = times[0];
            ((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).currentItemBurnTime = times[1];
            ((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).cookTime = times[2];
            ((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).totalCookTime = times[3];
        }
        if (owner != null)
            ((TileEntityOwnable) par1World.getTileEntity(pos)).getOwner().set(owner);
        if (!password.isEmpty() && par1World.getTileEntity(pos) instanceof TileEntityKeypad)
            ((TileEntityKeypad) par1World.getTileEntity(pos)).setPassword(password);
        if (!password.isEmpty() && par1World.getTileEntity(pos) instanceof TileEntityKeypadFurnace)
            ((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).setPassword(password);
        if (!password.isEmpty() && par1World.getTileEntity(pos) instanceof TileEntityKeypadChest)
            ((TileEntityKeypadChest) par1World.getTileEntity(pos)).setPassword(password);
        if (cooldown != -1 && par1World.getTileEntity(pos) instanceof TileEntityPortableRadar)
            ((TileEntityPortableRadar) par1World.getTileEntity(pos)).setAttackCooldown(cooldown);
    } else
        par1World.setBlockState(pos, par1World.getBlockState(pos).withProperty(property, value));
}
Also used : Owner(net.geforcemods.securitycraft.api.Owner) TileEntityKeypadFurnace(net.geforcemods.securitycraft.tileentity.TileEntityKeypadFurnace) TileEntity(net.minecraft.tileentity.TileEntity) CustomizableSCTE(net.geforcemods.securitycraft.api.CustomizableSCTE) TileEntityKeypadChest(net.geforcemods.securitycraft.tileentity.TileEntityKeypadChest) TileEntityPortableRadar(net.geforcemods.securitycraft.tileentity.TileEntityPortableRadar) ItemStack(net.minecraft.item.ItemStack) TileEntityOwnable(net.geforcemods.securitycraft.tileentity.TileEntityOwnable) TileEntityKeypad(net.geforcemods.securitycraft.tileentity.TileEntityKeypad)

Example 12 with CustomizableSCTE

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

the class ModuleUtils method getPlayersFromModule.

public static List<String> getPlayersFromModule(World par1World, BlockPos pos, EnumCustomModules module) {
    List<String> list = new ArrayList<String>();
    CustomizableSCTE te = (CustomizableSCTE) par1World.getTileEntity(pos);
    if (te.hasModule(module)) {
        ItemStack item = te.getModule(module);
        for (int i = 1; i <= 10; i++) if (item.getTagCompound() != null && item.getTagCompound().getString("Player" + i) != null && !item.getTagCompound().getString("Player" + i).isEmpty())
            list.add(item.getTagCompound().getString("Player" + i).toLowerCase());
    }
    return list;
}
Also used : CustomizableSCTE(net.geforcemods.securitycraft.api.CustomizableSCTE) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 13 with CustomizableSCTE

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

the class SCEventHandler method onBlockBroken.

@SubscribeEvent
public void onBlockBroken(BreakEvent event) {
    if (!event.world.isRemote)
        if (event.world.getTileEntity(event.pos) != null && event.world.getTileEntity(event.pos) instanceof CustomizableSCTE) {
            CustomizableSCTE te = (CustomizableSCTE) event.world.getTileEntity(event.pos);
            for (int i = 0; i < te.getNumberOfCustomizableOptions(); i++) if (te.itemStacks[i] != null) {
                ItemStack stack = te.itemStacks[i];
                EntityItem item = new EntityItem(event.world, event.pos.getX(), event.pos.getY(), event.pos.getZ(), stack);
                event.world.spawnEntityInWorld(item);
                te.onModuleRemoved(stack, ((ItemModule) stack.getItem()).getModule());
                te.createLinkedBlockAction(EnumLinkedAction.MODULE_REMOVED, new Object[] { stack, ((ItemModule) stack.getItem()).getModule() }, te);
                if (te instanceof TileEntitySecurityCamera)
                    te.getWorld().notifyNeighborsOfStateChange(te.getPos().offset((EnumFacing) te.getWorld().getBlockState(te.getPos()).getValue(BlockSecurityCamera.FACING), -1), te.getWorld().getBlockState(te.getPos()).getBlock());
            }
        }
}
Also used : CustomizableSCTE(net.geforcemods.securitycraft.api.CustomizableSCTE) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) TileEntitySecurityCamera(net.geforcemods.securitycraft.tileentity.TileEntitySecurityCamera) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 14 with CustomizableSCTE

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

the class SCEventHandler method onPlayerInteracted.

@SubscribeEvent
public void onPlayerInteracted(PlayerInteractEvent event) {
    if (!event.entityPlayer.worldObj.isRemote) {
        World world = event.entityPlayer.worldObj;
        TileEntity tileEntity = event.entityPlayer.worldObj.getTileEntity(event.pos);
        Block block = event.entityPlayer.worldObj.getBlockState(event.pos).getBlock();
        if (event.action != Action.RIGHT_CLICK_BLOCK)
            return;
        if (event.action == Action.RIGHT_CLICK_BLOCK && PlayerUtils.isHoldingItem(event.entityPlayer, SCContent.codebreaker) && handleCodebreaking(event)) {
            event.setCanceled(true);
            return;
        }
        if (event.action == Action.RIGHT_CLICK_BLOCK && tileEntity != null && tileEntity instanceof CustomizableSCTE && PlayerUtils.isHoldingItem(event.entityPlayer, SCContent.universalBlockModifier)) {
            event.setCanceled(true);
            if (!((IOwnable) tileEntity).getOwner().isOwner(event.entityPlayer)) {
                PlayerUtils.sendMessageToPlayer(event.entityPlayer, StatCollector.translateToLocal("item.universalBlockModifier.name"), StatCollector.translateToLocal("messages.notOwned").replace("#", ((TileEntityOwnable) tileEntity).getOwner().getName()), EnumChatFormatting.RED);
                return;
            }
            event.entityPlayer.openGui(SecurityCraft.instance, GuiHandler.CUSTOMIZE_BLOCK, world, event.pos.getX(), event.pos.getY(), event.pos.getZ());
            return;
        }
        if (event.action == Action.RIGHT_CLICK_BLOCK && tileEntity instanceof INameable && ((INameable) tileEntity).canBeNamed() && PlayerUtils.isHoldingItem(event.entityPlayer, Items.name_tag) && event.entityPlayer.getCurrentEquippedItem().hasDisplayName()) {
            event.setCanceled(true);
            for (String character : new String[] { "(", ")" }) if (event.entityPlayer.getCurrentEquippedItem().getDisplayName().contains(character)) {
                PlayerUtils.sendMessageToPlayer(event.entityPlayer, "Naming", StatCollector.translateToLocal("messages.naming.error").replace("#n", event.entityPlayer.getCurrentEquippedItem().getDisplayName()).replace("#c", character), EnumChatFormatting.RED);
                return;
            }
            if (((INameable) tileEntity).getCustomName().matches(event.entityPlayer.getCurrentEquippedItem().getDisplayName())) {
                PlayerUtils.sendMessageToPlayer(event.entityPlayer, "Naming", StatCollector.translateToLocal("messages.naming.alreadyMatches").replace("#n", ((INameable) tileEntity).getCustomName()), EnumChatFormatting.RED);
                return;
            }
            event.entityPlayer.getCurrentEquippedItem().stackSize--;
            ((INameable) tileEntity).setCustomName(event.entityPlayer.getCurrentEquippedItem().getDisplayName());
            return;
        }
        if (event.action == Action.RIGHT_CLICK_BLOCK && tileEntity != null && isOwnableBlock(block, tileEntity) && PlayerUtils.isHoldingItem(event.entityPlayer, SCContent.universalBlockRemover)) {
            event.setCanceled(true);
            if (!((IOwnable) tileEntity).getOwner().isOwner(event.entityPlayer)) {
                PlayerUtils.sendMessageToPlayer(event.entityPlayer, StatCollector.translateToLocal("item.universalBlockRemover.name"), StatCollector.translateToLocal("messages.notOwned").replace("#", ((TileEntityOwnable) tileEntity).getOwner().getName()), EnumChatFormatting.RED);
                return;
            }
            if (block == SCContent.laserBlock) {
                world.destroyBlock(event.pos, true);
                BlockLaserBlock.destroyAdjacentLasers(event.world, event.pos.getX(), event.pos.getY(), event.pos.getZ());
                event.entityPlayer.getCurrentEquippedItem().damageItem(1, event.entityPlayer);
            } else {
                world.destroyBlock(event.pos, true);
                world.removeTileEntity(event.pos);
                event.entityPlayer.getCurrentEquippedItem().damageItem(1, event.entityPlayer);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) CustomizableSCTE(net.geforcemods.securitycraft.api.CustomizableSCTE) INameable(net.geforcemods.securitycraft.api.INameable) Block(net.minecraft.block.Block) BlockLaserBlock(net.geforcemods.securitycraft.blocks.BlockLaserBlock) IOwnable(net.geforcemods.securitycraft.api.IOwnable) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 15 with CustomizableSCTE

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

the class ForgeEventHandler method onPlayerInteracted.

@SubscribeEvent
public void onPlayerInteracted(PlayerInteractEvent event) {
    if (!event.entityPlayer.worldObj.isRemote) {
        World world = event.entityPlayer.worldObj;
        TileEntity tileEntity = event.entityPlayer.worldObj.getTileEntity(event.pos);
        Block block = event.entityPlayer.worldObj.getBlockState(event.pos).getBlock();
        if (event.action != Action.RIGHT_CLICK_BLOCK)
            return;
        if (event.action == Action.RIGHT_CLICK_BLOCK && PlayerUtils.isHoldingItem(event.entityPlayer, mod_SecurityCraft.codebreaker) && handleCodebreaking(event)) {
            event.setCanceled(true);
            return;
        }
        if (event.action == Action.RIGHT_CLICK_BLOCK && tileEntity != null && tileEntity instanceof CustomizableSCTE && PlayerUtils.isHoldingItem(event.entityPlayer, mod_SecurityCraft.universalBlockModifier)) {
            event.setCanceled(true);
            if (!((IOwnable) tileEntity).getOwner().isOwner(event.entityPlayer)) {
                PlayerUtils.sendMessageToPlayer(event.entityPlayer, StatCollector.translateToLocal("item.universalBlockModifier.name"), StatCollector.translateToLocal("messages.notOwned").replace("#", ((TileEntityOwnable) tileEntity).getOwner().getName()), EnumChatFormatting.RED);
                return;
            }
            event.entityPlayer.openGui(mod_SecurityCraft.instance, GuiHandler.CUSTOMIZE_BLOCK, world, event.pos.getX(), event.pos.getY(), event.pos.getZ());
            return;
        }
        if (event.action == Action.RIGHT_CLICK_BLOCK && tileEntity instanceof INameable && ((INameable) tileEntity).canBeNamed() && PlayerUtils.isHoldingItem(event.entityPlayer, Items.name_tag) && event.entityPlayer.getCurrentEquippedItem().hasDisplayName()) {
            event.setCanceled(true);
            for (String character : new String[] { "(", ")" }) {
                if (event.entityPlayer.getCurrentEquippedItem().getDisplayName().contains(character)) {
                    PlayerUtils.sendMessageToPlayer(event.entityPlayer, "Naming", StatCollector.translateToLocal("messages.naming.error").replace("#n", event.entityPlayer.getCurrentEquippedItem().getDisplayName()).replace("#c", character), EnumChatFormatting.RED);
                    return;
                }
            }
            if (((INameable) tileEntity).getCustomName().matches(event.entityPlayer.getCurrentEquippedItem().getDisplayName())) {
                PlayerUtils.sendMessageToPlayer(event.entityPlayer, "Naming", StatCollector.translateToLocal("messages.naming.alreadyMatches").replace("#n", ((INameable) tileEntity).getCustomName()), EnumChatFormatting.RED);
                return;
            }
            event.entityPlayer.getCurrentEquippedItem().stackSize--;
            ((INameable) tileEntity).setCustomName(event.entityPlayer.getCurrentEquippedItem().getDisplayName());
            return;
        }
        if (event.action == Action.RIGHT_CLICK_BLOCK && tileEntity != null && isOwnableBlock(block, tileEntity) && PlayerUtils.isHoldingItem(event.entityPlayer, mod_SecurityCraft.universalBlockRemover)) {
            event.setCanceled(true);
            if (!((IOwnable) tileEntity).getOwner().isOwner(event.entityPlayer)) {
                PlayerUtils.sendMessageToPlayer(event.entityPlayer, StatCollector.translateToLocal("item.universalBlockRemover.name"), StatCollector.translateToLocal("messages.notOwned").replace("#", ((TileEntityOwnable) tileEntity).getOwner().getName()), EnumChatFormatting.RED);
                return;
            }
            if (block == mod_SecurityCraft.laserBlock) {
                world.destroyBlock(event.pos, true);
                BlockLaserBlock.destroyAdjecentLasers(event.world, event.pos.getX(), event.pos.getY(), event.pos.getZ());
                event.entityPlayer.getCurrentEquippedItem().damageItem(1, event.entityPlayer);
            } else {
                world.destroyBlock(event.pos, true);
                world.removeTileEntity(event.pos);
                event.entityPlayer.getCurrentEquippedItem().damageItem(1, event.entityPlayer);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) CustomizableSCTE(net.geforcemods.securitycraft.api.CustomizableSCTE) INameable(net.geforcemods.securitycraft.api.INameable) Block(net.minecraft.block.Block) BlockLaserBlock(net.geforcemods.securitycraft.blocks.BlockLaserBlock) IOwnable(net.geforcemods.securitycraft.api.IOwnable) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

CustomizableSCTE (net.geforcemods.securitycraft.api.CustomizableSCTE)24 TileEntity (net.minecraft.tileentity.TileEntity)12 IOwnable (net.geforcemods.securitycraft.api.IOwnable)10 Block (net.minecraft.block.Block)10 ItemStack (net.minecraft.item.ItemStack)9 IPasswordProtected (net.geforcemods.securitycraft.api.IPasswordProtected)7 INameable (net.geforcemods.securitycraft.api.INameable)6 EnumCustomModules (net.geforcemods.securitycraft.misc.EnumCustomModules)5 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)5 BlockLaserBlock (net.geforcemods.securitycraft.blocks.BlockLaserBlock)3 TileEntityPortableRadar (net.geforcemods.securitycraft.tileentity.TileEntityPortableRadar)3 World (net.minecraft.world.World)3 ArrayList (java.util.ArrayList)2 IExplosive (net.geforcemods.securitycraft.api.IExplosive)2 TileEntitySCTE (net.geforcemods.securitycraft.api.TileEntitySCTE)2 CustomHoverChecker (net.geforcemods.securitycraft.gui.components.CustomHoverChecker)2 ItemModule (net.geforcemods.securitycraft.items.ItemModule)2 TileEntityKeypad (net.geforcemods.securitycraft.tileentity.TileEntityKeypad)2 ITileEntityProvider (net.minecraft.block.ITileEntityProvider)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2