Search in sources :

Example 36 with Colony

use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.

the class BlockHutField method onBlockPlacedBy.

@Override
public void onBlockPlacedBy(@NotNull final World worldIn, @NotNull final BlockPos pos, final IBlockState state, final EntityLivingBase placer, final ItemStack stack) {
    //Only work on server side.
    if (worldIn.isRemote) {
        return;
    }
    if (placer instanceof EntityPlayer) {
        @Nullable final Colony colony = ColonyManager.getColony(worldIn, pos);
        if (colony != null) {
            @NotNull final InventoryField inventoryField = new InventoryField();
            final ScarecrowTileEntity scareCrow = (ScarecrowTileEntity) worldIn.getTileEntity(pos);
            final EntityPlayer player = (EntityPlayer) placer;
            if (scareCrow != null) {
                scareCrow.setInventoryField(inventoryField);
                colony.addNewField(scareCrow, player.inventory, pos, worldIn);
            }
        }
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) Colony(com.minecolonies.coremod.colony.Colony) InventoryField(com.minecolonies.coremod.inventory.InventoryField) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable)

Example 37 with Colony

use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.

the class ListColoniesCommand method execute.

@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
    int page = getIthArgument(args, 0, 1);
    final int abandonedSince = getIthArgument(args, 1, 0);
    final List<Colony> colonies;
    if (abandonedSince > 0) {
        colonies = ColonyManager.getColoniesAbandonedSince(abandonedSince);
    } else {
        colonies = ColonyManager.getColonies();
    }
    final int colonyCount = colonies.size();
    // check to see if we have to add one page to show the half page
    final int halfPage = (colonyCount % COLONIES_ON_PAGE == 0) ? 0 : 1;
    final int pageCount = ((colonyCount) / COLONIES_ON_PAGE) + halfPage;
    if (page < 1 || page > pageCount) {
        page = 1;
    }
    final int pageStartIndex = COLONIES_ON_PAGE * (page - 1);
    final int pageStopIndex = Math.min(COLONIES_ON_PAGE * page, colonyCount);
    final int prevPage = Math.max(0, page - 1);
    final int nextPage = Math.min(page + 1, (colonyCount / COLONIES_ON_PAGE) + halfPage);
    final List<Colony> coloniesPage;
    if (pageStartIndex < 0 || pageStartIndex >= colonyCount) {
        coloniesPage = new ArrayList<>();
    } else {
        coloniesPage = colonies.subList(pageStartIndex, pageStopIndex);
    }
    final ITextComponent headerLine = new TextComponentString(PAGE_TOP_LEFT + page + PAGE_TOP_MIDDLE + pageCount + PAGE_TOP_RIGHT);
    sender.sendMessage(headerLine);
    for (final Colony colony : coloniesPage) {
        sender.sendMessage(new TextComponentString(String.format(ID_AND_NAME_TEXT, colony.getID(), colony.getName())).setStyle(new Style().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format(COMMAND_COLONY_INFO, colony.getID())))));
        final BlockPos center = colony.getCenter();
        final ITextComponent teleport = new TextComponentString(COORDINATES_TEXT + String.format(COORDINATES_XYZ, center.getX(), center.getY(), center.getZ())).setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, TELEPORT_COMMAND + colony.getID())));
        sender.sendMessage(teleport);
    }
    final ITextComponent prevButton = new TextComponentString(PREV_PAGE).setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, LIST_COMMAND_SUGGESTED + prevPage)));
    final ITextComponent nextButton = new TextComponentString(NEXT_PAGE).setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, LIST_COMMAND_SUGGESTED + nextPage)));
    final ITextComponent beginLine = new TextComponentString(PAGE_LINE);
    final ITextComponent endLine = new TextComponentString(PAGE_LINE);
    sender.sendMessage(beginLine.appendSibling(prevButton).appendSibling(new TextComponentString(PAGE_LINE_DIVIDER)).appendSibling(nextButton).appendSibling(endLine));
}
Also used : ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) Colony(com.minecolonies.coremod.colony.Colony) Style(net.minecraft.util.text.Style) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 38 with Colony

use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.

the class ColonyPackageManager method sendPermissionsPackets.

@Override
public void sendPermissionsPackets(@NotNull final Set<EntityPlayerMP> oldSubscribers, final boolean hasNewSubscribers) {
    final Permissions permissions = colony.getPermissions();
    if (permissions.isDirty() || hasNewSubscribers || colony.getWorld().rand.nextInt(CHANCE_TO_UPDATE) <= 1) {
        subscribers.stream().filter(player -> permissions.isDirty() || !oldSubscribers.contains(player)).forEach(player -> {
            final Rank rank = permissions.getRank(player);
            MineColonies.getNetwork().sendTo(new PermissionsMessage.View(colony, rank), player);
        });
    }
}
Also used : Permissions(com.minecolonies.coremod.colony.permissions.Permissions) MAX_SQ_DIST_OLD_SUBSCRIBER_UPDATE(com.minecolonies.api.util.constant.ColonyConstants.MAX_SQ_DIST_OLD_SUBSCRIBER_UPDATE) ColonyUtils(com.minecolonies.coremod.util.ColonyUtils) Colony(com.minecolonies.coremod.colony.Colony) World(net.minecraft.world.World) TICKS_HOUR(com.minecolonies.api.util.constant.Constants.TICKS_HOUR) ColonyViewMessage(com.minecolonies.coremod.network.messages.ColonyViewMessage) Set(java.util.Set) MAX_SQ_DIST_SUBSCRIBER_UPDATE(com.minecolonies.api.util.constant.ColonyConstants.MAX_SQ_DIST_SUBSCRIBER_UPDATE) ColonyStylesMessage(com.minecolonies.coremod.network.messages.ColonyStylesMessage) Structures(com.minecolonies.coremod.colony.Structures) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) HashSet(java.util.HashSet) Rank(com.minecolonies.api.colony.permissions.Rank) List(java.util.List) MineColonies(com.minecolonies.coremod.MineColonies) WorkManager(com.minecolonies.coremod.colony.WorkManager) EntityPlayer(net.minecraft.entity.player.EntityPlayer) AbstractWorkOrder(com.minecolonies.coremod.colony.workorders.AbstractWorkOrder) NotNull(org.jetbrains.annotations.NotNull) ColonyViewWorkOrderMessage(com.minecolonies.coremod.network.messages.ColonyViewWorkOrderMessage) PermissionsMessage(com.minecolonies.coremod.network.messages.PermissionsMessage) PermissionsMessage(com.minecolonies.coremod.network.messages.PermissionsMessage) Permissions(com.minecolonies.coremod.colony.permissions.Permissions) Rank(com.minecolonies.api.colony.permissions.Rank)

Example 39 with Colony

use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.

the class BuildingWareHouse method getTileEntity.

/**
 * Returns the tile entity that belongs to the colony building.
 *
 * @return {@link TileEntityColonyBuilding} object of the building.
 */
@Override
public TileEntityWareHouse getTileEntity() {
    final Colony colony = getColony();
    if ((tileEntity == null || tileEntity.isInvalid()) && colony != null && colony.getWorld() != null && getLocation() != null && colony.getWorld().getBlockState(getLocation()) != null && colony.getWorld().getBlockState(this.getLocation()).getBlock() instanceof BlockHutWareHouse) {
        final TileEntity te = getColony().getWorld().getTileEntity(this.getLocation());
        if (te instanceof TileEntityWareHouse) {
            tileEntity = (TileEntityWareHouse) te;
            if (tileEntity.getBuilding() == null) {
                tileEntity.setColony(colony);
                tileEntity.setBuilding(this);
            }
        }
    }
    return tileEntity;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityWareHouse(com.minecolonies.coremod.tileentities.TileEntityWareHouse) Colony(com.minecolonies.coremod.colony.Colony) BlockHutWareHouse(com.minecolonies.coremod.blocks.BlockHutWareHouse)

Example 40 with Colony

use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.

the class ItemScepterGuard method handleItemUsage.

/**
 * Handles the usage of the item.
 *
 * @param worldIn  the world it is used in.
 * @param pos      the position.
 * @param compound the compound.
 * @param playerIn the player using it.
 * @return if it has been successful.
 */
@NotNull
private static EnumActionResult handleItemUsage(final World worldIn, final BlockPos pos, final NBTTagCompound compound, final EntityPlayer playerIn) {
    final Colony colony = ColonyManager.getClosestColony(worldIn, pos);
    if (colony == null) {
        return EnumActionResult.FAIL;
    }
    final BlockPos guardTower = BlockPosUtil.readFromNBT(compound, "pos");
    final AbstractBuilding hut = colony.getBuildingManager().getBuilding(guardTower);
    if (!(hut instanceof AbstractBuildingGuards)) {
        return EnumActionResult.FAIL;
    }
    final AbstractBuildingGuards tower = (AbstractBuildingGuards) hut;
    if (BlockPosUtil.getDistance2D(pos, guardTower) > tower.getPatrolDistance()) {
        LanguageHandler.sendPlayerMessage(playerIn, "com.minecolonies.coremod.job.guard.toolClickGuardTooFar");
        return EnumActionResult.FAIL;
    }
    final Task task = Task.values()[compound.getInteger("task")];
    final CitizenData citizen = tower.getMainWorker();
    String name = "";
    if (citizen != null) {
        name = " " + citizen.getName();
    }
    if (task.equals(Task.GUARD)) {
        LanguageHandler.sendPlayerMessage(playerIn, "com.minecolonies.coremod.job.guard.toolClickGuard", pos, name);
        tower.setGuardTarget(pos);
        playerIn.inventory.removeStackFromSlot(playerIn.inventory.currentItem);
    } else {
        if (!compound.hasKey(TAG_LAST_POS)) {
            tower.resetPatrolTargets();
        }
        tower.addPatrolTargets(pos);
        LanguageHandler.sendPlayerMessage(playerIn, "com.minecolonies.coremod.job.guard.toolClickPatrol", pos, name);
    }
    BlockPosUtil.writeToNBT(compound, TAG_LAST_POS, pos);
    return EnumActionResult.SUCCESS;
}
Also used : AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) Task(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards.Task) Colony(com.minecolonies.coremod.colony.Colony) BlockPos(net.minecraft.util.math.BlockPos) CitizenData(com.minecolonies.coremod.colony.CitizenData) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Colony (com.minecolonies.coremod.colony.Colony)81 TextComponentString (net.minecraft.util.text.TextComponentString)29 IColony (com.minecolonies.api.colony.IColony)21 EntityPlayer (net.minecraft.entity.player.EntityPlayer)20 BlockPos (net.minecraft.util.math.BlockPos)19 Nullable (org.jetbrains.annotations.Nullable)16 CitizenData (com.minecolonies.coremod.colony.CitizenData)13 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)13 NotNull (org.jetbrains.annotations.NotNull)11 ItemStack (net.minecraft.item.ItemStack)9 Entity (net.minecraft.entity.Entity)8 TileEntity (net.minecraft.tileentity.TileEntity)8 World (net.minecraft.world.World)6 List (java.util.List)5 UUID (java.util.UUID)5 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)4 Delivery (com.minecolonies.api.colony.requestsystem.requestable.Delivery)4 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)4 AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)4