Search in sources :

Example 1 with AbstractBlockHut

use of com.minecolonies.coremod.blocks.AbstractBlockHut in project minecolonies by Minecolonies.

the class ColonyManager method deleteColony.

/**
     * Delete a colony and kill all citizens/purge all buildings.
     *
     * @param id the colonies id.
     */
public static void deleteColony(final int id) {
    try {
        final Colony colony = getColony(id);
        Log.getLogger().info("Deleting colony " + id);
        colonies.remove(id);
        coloniesByWorld.get(colony.getDimension()).remove(colony);
        final Set<World> colonyWorlds = new HashSet<>();
        Log.getLogger().info("Removing citizens for " + id);
        for (final CitizenData citizenData : new ArrayList<>(colony.getCitizens().values())) {
            Log.getLogger().info("Kill Citizen " + citizenData.getName());
            final EntityCitizen entityCitizen = citizenData.getCitizenEntity();
            if (entityCitizen != null) {
                final World world = entityCitizen.getEntityWorld();
                citizenData.getCitizenEntity().onDeath(CONSOLE_DAMAGE_SOURCE);
                colonyWorlds.add(world);
            }
        }
        Log.getLogger().info("Removing buildings for " + id);
        for (final AbstractBuilding building : new ArrayList<>(colony.getBuildings().values())) {
            final BlockPos location = building.getLocation();
            Log.getLogger().info("Delete Building at " + location);
            building.destroy();
            for (final World world : colonyWorlds) {
                if (world.getBlockState(location).getBlock() instanceof AbstractBlockHut) {
                    Log.getLogger().info("Found Block, deleting " + world.getBlockState(location).getBlock());
                    world.setBlockToAir(location);
                }
            }
        }
        Log.getLogger().info("Done with " + id);
    } catch (final RuntimeException e) {
        Log.getLogger().warn("Deleting Colony " + id + " errored:", e);
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) AbstractBlockHut(com.minecolonies.coremod.blocks.AbstractBlockHut) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 2 with AbstractBlockHut

use of com.minecolonies.coremod.blocks.AbstractBlockHut in project minecolonies by Minecolonies.

the class EventHandler method onPlayerInteract.

/**
     * Event when a player right clicks a block, or right clicks with an item.
     * Event gets cancelled when player has no permission. Event gets cancelled
     * when the player has no permission to place a hut, and tried it.
     *
     * @param event {@link PlayerInteractEvent.RightClickBlock}
     */
@SubscribeEvent
public void onPlayerInteract(@NotNull final PlayerInteractEvent.RightClickBlock event) {
    final EntityPlayer player = event.getEntityPlayer();
    final World world = event.getWorld();
    //Only execute for the main hand our colony events.
    if (event.getHand() == EnumHand.MAIN_HAND && !(event.getWorld().isRemote)) {
        // and uses that return value, but I didn't want to call it twice
        if (playerRightClickInteract(player, world, event.getPos()) && world.getBlockState(event.getPos()).getBlock() instanceof AbstractBlockHut) {
            final IColony colony = ColonyManager.getIColony(world, event.getPos());
            if (colony != null && !colony.getPermissions().hasPermission(player, Action.ACCESS_HUTS)) {
                event.setCanceled(true);
            }
            return;
        } else if (event.getEntityPlayer() != null && "pmardle".equalsIgnoreCase(event.getEntityPlayer().getName()) && event.getItemStack() != null && Block.getBlockFromItem(event.getItemStack().getItem()) instanceof BlockSilverfish) {
            LanguageHandler.sendPlayerMessage(event.getEntityPlayer(), "Stop that you twat!!!");
            event.setCanceled(true);
        }
        if (player.getHeldItemMainhand() == null || player.getHeldItemMainhand().getItem() == null) {
            return;
        }
        handleEventCancellation(event, player);
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) IColony(com.minecolonies.coremod.colony.IColony) BlockSilverfish(net.minecraft.block.BlockSilverfish) World(net.minecraft.world.World) AbstractBlockHut(com.minecolonies.coremod.blocks.AbstractBlockHut) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with AbstractBlockHut

use of com.minecolonies.coremod.blocks.AbstractBlockHut in project minecolonies by Minecolonies.

the class ColonyPermissionEventHandler method on.

/**
     * PlayerInteractEvent handler.
     * <p>
     * Check, if a player right clicked a block.
     * Deny if:
     * - If the block is in colony
     * - block is AbstractBlockHut
     * - player has not permission
     *
     * @param event PlayerInteractEvent
     */
@SubscribeEvent
public void on(final PlayerInteractEvent event) {
    if (colony.isCoordInColony(event.getWorld(), event.getPos()) && !(event instanceof PlayerInteractEvent.EntityInteract || event instanceof PlayerInteractEvent.EntityInteractSpecific)) {
        final Block block = event.getWorld().getBlockState(event.getPos()).getBlock();
        // Huts
        if (block instanceof AbstractBlockHut && !colony.getPermissions().hasPermission(event.getEntityPlayer(), Action.ACCESS_HUTS)) {
            cancelEvent(event, event.getEntityPlayer());
        }
        final Permissions perms = colony.getPermissions();
        if (isFreeToInteractWith(event.getWorld().getBlockState(event.getPos()).getBlock(), event.getPos()) && perms.hasPermission(event.getEntityPlayer(), Action.ACCESS_FREE_BLOCKS)) {
            return;
        }
        if (Configurations.enableColonyProtection) {
            if (!perms.hasPermission(event.getEntityPlayer(), Action.RIGHTCLICK_BLOCK) && event.getWorld().getBlockState(event.getPos()).getBlock() != null) {
                cancelEvent(event, event.getEntityPlayer());
            }
            if (event.getWorld().getBlockState(event.getPos()).getBlock() instanceof BlockContainer && !perms.hasPermission(event.getEntityPlayer(), Action.OPEN_CONTAINER)) {
                cancelEvent(event, event.getEntityPlayer());
            }
            if (event.getWorld().getTileEntity(event.getPos()) != null && !perms.hasPermission(event.getEntityPlayer(), Action.RIGHTCLICK_ENTITY)) {
                cancelEvent(event, event.getEntityPlayer());
            }
            if (event.getItemStack() != null && event.getItemStack().getItem() instanceof ItemPotion && !perms.hasPermission(event.getEntityPlayer(), Action.THROW_POTION)) {
                cancelEvent(event, event.getEntityPlayer());
            }
            if (event.getItemStack() != null && event.getItemStack().getItem() instanceof ItemScanTool && !perms.hasPermission(event.getEntityPlayer(), Action.USE_SCAN_TOOL)) {
                cancelEvent(event, event.getEntityPlayer());
            }
        }
    }
}
Also used : ItemPotion(net.minecraft.item.ItemPotion) ItemScanTool(com.minecolonies.coremod.items.ItemScanTool) BlockContainer(net.minecraft.block.BlockContainer) Permissions(com.minecolonies.coremod.colony.permissions.Permissions) Block(net.minecraft.block.Block) AbstractBlockHut(com.minecolonies.coremod.blocks.AbstractBlockHut) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with AbstractBlockHut

use of com.minecolonies.coremod.blocks.AbstractBlockHut in project minecolonies by Minecolonies.

the class BuildToolPlaceMessage method handleHut.

/**
     * Handles the placement of huts.
     *
     * @param world         World the hut is being placed into.
     * @param player        Who placed the hut.
     * @param sn            The name of the structure.
     * @param workOrderName The name of the work order.
     * @param rotation      The number of times the structure should be rotated.
     * @param buildPos      The location the hut is being placed.
     * @param mirror        Whether or not the strcture is mirrored.
     */
private static void handleHut(@NotNull final World world, @NotNull final EntityPlayer player, final Structures.StructureName sn, final int rotation, @NotNull final BlockPos buildPos, final boolean mirror) {
    final String hut = sn.getSection();
    final Block block = Block.getBlockFromName(Constants.MOD_ID + ":blockHut" + hut);
    final Colony tempColony = ColonyManager.getClosestColony(world, buildPos);
    if (tempColony != null && (!tempColony.getPermissions().hasPermission(player, Action.MANAGE_HUTS) && !(block instanceof BlockHutTownHall && BlockPosUtil.getDistance2D(tempColony.getCenter(), buildPos) >= Configurations.workingRangeTownHall * 2 + Configurations.townHallPadding))) {
        return;
    }
    if (block != null && player.inventory.hasItemStack(new ItemStack(block))) {
        if (EventHandler.onBlockHutPlaced(world, player, block, buildPos)) {
            world.destroyBlock(buildPos, true);
            world.setBlockState(buildPos, block.getDefaultState().withRotation(BlockUtils.getRotation(rotation)));
            ((AbstractBlockHut) block).onBlockPlacedByBuildTool(world, buildPos, world.getBlockState(buildPos), player, null, mirror, sn.getStyle());
            player.inventory.clearMatchingItems(Item.getItemFromBlock(block), -1, 1, null);
            setupBuilding(world, player, sn, rotation, buildPos, mirror);
        }
    } else {
        LanguageHandler.sendPlayerMessage(player, BuildToolPlaceMessage.NO_HUT_IN_INVENTORY);
    }
}
Also used : Block(net.minecraft.block.Block) Colony(com.minecolonies.coremod.colony.Colony) TextComponentString(net.minecraft.util.text.TextComponentString) BlockHutTownHall(com.minecolonies.coremod.blocks.BlockHutTownHall) ItemStack(net.minecraft.item.ItemStack) AbstractBlockHut(com.minecolonies.coremod.blocks.AbstractBlockHut)

Example 5 with AbstractBlockHut

use of com.minecolonies.coremod.blocks.AbstractBlockHut in project minecolonies by Minecolonies.

the class EntityAIStructureBuilder method requestMaterials.

/**
     * Iterates through all the required resources and stores them in the building.
     * Suppressing Sonar Rule Squid:S135
     * The rule thinks we should have less continue and breaks.
     * But in this case the rule does not apply because code would become unreadable and uneffective without.
     */
@SuppressWarnings(LOOPS_SHOULD_NOT_CONTAIN_MORE_THAN_A_SINGLE_BREAK_OR_CONTINUE_STATEMENT)
private void requestMaterials() {
    if (job.getWorkOrder().isRequested()) {
        return;
    }
    final AbstractBuildingWorker buildingWorker = getOwnBuilding();
    if (buildingWorker instanceof BuildingBuilder) {
        ((BuildingBuilder) buildingWorker).resetNeededResources();
    }
    while (job.getStructure().findNextBlock()) {
        @Nullable final Template.BlockInfo blockInfo = job.getStructure().getBlockInfo();
        @Nullable final Template.EntityInfo entityInfo = job.getStructure().getEntityinfo();
        if (entityInfo != null) {
            requestEntityToBuildingIfRequired(entityInfo);
        }
        if (blockInfo == null) {
            continue;
        }
        @Nullable IBlockState blockState = blockInfo.blockState;
        @Nullable Block block = blockState.getBlock();
        if (job.getStructure().isStructureBlockEqualWorldBlock() || (blockState.getBlock() instanceof BlockBed && blockState.getValue(BlockBed.PART).equals(BlockBed.EnumPartType.FOOT)) || (blockState.getBlock() instanceof BlockDoor && blockState.getValue(BlockDoor.HALF).equals(BlockDoor.EnumDoorHalf.UPPER))) {
            continue;
        }
        if (block instanceof BlockSolidSubstitution) {
            blockState = getSolidSubstitution(job.getStructure().getBlockPosition());
            block = blockState.getBlock();
        }
        final Block worldBlock = BlockPosUtil.getBlock(world, job.getStructure().getBlockPosition());
        if (block != null && block != Blocks.AIR && worldBlock != Blocks.BEDROCK && !(worldBlock instanceof AbstractBlockHut) && !isBlockFree(block, 0)) {
            requestBlockToBuildingIfRequired((BuildingBuilder) getOwnBuilding(), blockState);
        }
    }
    job.getWorkOrder().setRequested(true);
}
Also used : BlockDoor(net.minecraft.block.BlockDoor) AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) IBlockState(net.minecraft.block.state.IBlockState) BlockSolidSubstitution(com.minecolonies.coremod.blocks.BlockSolidSubstitution) BuildingBuilder(com.minecolonies.coremod.colony.buildings.BuildingBuilder) Block(net.minecraft.block.Block) BlockBed(net.minecraft.block.BlockBed) Nullable(org.jetbrains.annotations.Nullable) AbstractBlockHut(com.minecolonies.coremod.blocks.AbstractBlockHut) Template(net.minecraft.world.gen.structure.template.Template)

Aggregations

AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)7 Block (net.minecraft.block.Block)3 World (net.minecraft.world.World)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)2 BlockPos (net.minecraft.util.math.BlockPos)2 Template (net.minecraft.world.gen.structure.template.Template)2 Nullable (org.jetbrains.annotations.Nullable)2 BlockHutTownHall (com.minecolonies.coremod.blocks.BlockHutTownHall)1 BlockSolidSubstitution (com.minecolonies.coremod.blocks.BlockSolidSubstitution)1 Colony (com.minecolonies.coremod.colony.Colony)1 IColony (com.minecolonies.coremod.colony.IColony)1 AbstractBuildingWorker (com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker)1 BuildingBuilder (com.minecolonies.coremod.colony.buildings.BuildingBuilder)1 Permissions (com.minecolonies.coremod.colony.permissions.Permissions)1 EntityCitizen (com.minecolonies.coremod.entity.EntityCitizen)1 ItemScanTool (com.minecolonies.coremod.items.ItemScanTool)1 BlockBed (net.minecraft.block.BlockBed)1 BlockContainer (net.minecraft.block.BlockContainer)1 BlockDoor (net.minecraft.block.BlockDoor)1