Search in sources :

Example 6 with IColony

use of com.minecolonies.api.colony.IColony in project minecolonies by Minecolonies.

the class WindowTownHall method updateAllies.

/**
 * Clears and resets all allies.
 */
private void updateAllies() {
    allies.clear();
    final ColonyView colony = building.getColony();
    for (final Player player : colony.getPermissions().getPlayersByRank(Rank.OFFICER)) {
        final IColony col = ColonyManager.getIColonyByOwner(Minecraft.getMinecraft().world, player.getID());
        if (col instanceof ColonyView) {
            for (final Player owner : colony.getPermissions().getPlayersByRank(Rank.OWNER)) {
                if (col.getPermissions().getRank(owner.getID()) == Rank.OFFICER) {
                    allies.add((ColonyView) col);
                }
            }
        }
    }
}
Also used : ColonyView(com.minecolonies.coremod.colony.ColonyView) Player(com.minecolonies.api.colony.permissions.Player) IColony(com.minecolonies.api.colony.IColony)

Example 7 with IColony

use of com.minecolonies.api.colony.IColony in project minecolonies by Minecolonies.

the class EventHandler method onDebugOverlay.

/**
 * Event when the debug screen is opened. Event gets called by displayed
 * text on the screen, we only need it when f3 is clicked.
 *
 * @param event {@link net.minecraftforge.client.event.RenderGameOverlayEvent.Text}
 */
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onDebugOverlay(final RenderGameOverlayEvent.Text event) {
    if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
        final Minecraft mc = Minecraft.getMinecraft();
        if (mc.gameSettings.showDebugInfo) {
            final WorldClient world = mc.world;
            final EntityPlayerSP player = mc.player;
            IColony colony = ColonyManager.getIColony(world, player.getPosition());
            if (colony == null) {
                if (!ColonyManager.isTooCloseToColony(world, player.getPosition())) {
                    event.getLeft().add(LanguageHandler.format("com.minecolonies.coremod.gui.debugScreen.noCloseColony"));
                    return;
                }
                colony = ColonyManager.getClosestIColony(world, player.getPosition());
                if (colony == null) {
                    return;
                }
                event.getLeft().add(LanguageHandler.format("com.minecolonies.coremod.gui.debugScreen.nextColony", (int) Math.sqrt(colony.getDistanceSquared(player.getPosition())), ColonyManager.getMinimumDistanceBetweenTownHalls()));
                return;
            }
            event.getLeft().add(colony.getName() + " : " + LanguageHandler.format("com.minecolonies.coremod.gui.debugScreen.blocksFromCenter", (int) Math.sqrt(colony.getDistanceSquared(player.getPosition()))));
        }
    }
}
Also used : IColony(com.minecolonies.api.colony.IColony) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) Minecraft(net.minecraft.client.Minecraft) WorldClient(net.minecraft.client.multiplayer.WorldClient) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 8 with IColony

use of com.minecolonies.api.colony.IColony 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 ("pmardle".equalsIgnoreCase(event.getEntityPlayer().getName()) && 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.api.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 9 with IColony

use of com.minecolonies.api.colony.IColony in project minecolonies by Minecolonies.

the class WindowTownHall method updateFeuds.

/**
 * Clears and resets all feuds.
 */
private void updateFeuds() {
    feuds.clear();
    final ColonyView colony = building.getColony();
    for (final Player player : colony.getPermissions().getPlayersByRank(Rank.HOSTILE)) {
        final IColony col = ColonyManager.getIColonyByOwner(Minecraft.getMinecraft().world, player.getID());
        if (col instanceof ColonyView) {
            for (final Player owner : colony.getPermissions().getPlayersByRank(Rank.OWNER)) {
                if (col.getPermissions().getRank(owner.getID()) == Rank.HOSTILE) {
                    feuds.add((ColonyView) col);
                }
            }
        }
    }
}
Also used : ColonyView(com.minecolonies.coremod.colony.ColonyView) Player(com.minecolonies.api.colony.permissions.Player) IColony(com.minecolonies.api.colony.IColony)

Example 10 with IColony

use of com.minecolonies.api.colony.IColony in project minecolonies by Minecolonies.

the class EventHandler method onTownHallPlaced.

protected static boolean onTownHallPlaced(@NotNull final World world, @NotNull final EntityPlayer player, final BlockPos pos) {
    IColony colony = ColonyManager.getIColonyByOwner(world, player);
    if (colony != null) {
        return canOwnerPlaceTownHallHere(world, player, colony, pos);
    }
    colony = ColonyManager.getClosestIColony(world, pos);
    if (colony == null) {
        return true;
    }
    // Town Halls must be far enough apart
    return canPlayerPlaceTownHallHere(world, player, pos, colony);
}
Also used : IColony(com.minecolonies.api.colony.IColony)

Aggregations

IColony (com.minecolonies.api.colony.IColony)22 EntityPlayer (net.minecraft.entity.player.EntityPlayer)16 TextComponentString (net.minecraft.util.text.TextComponentString)14 Colony (com.minecolonies.coremod.colony.Colony)12 Entity (net.minecraft.entity.Entity)7 UUID (java.util.UUID)5 Player (com.minecolonies.api.colony.permissions.Player)2 ColonyView (com.minecolonies.coremod.colony.ColonyView)2 BlockPos (net.minecraft.util.math.BlockPos)2 World (net.minecraft.world.World)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 NotNull (org.jetbrains.annotations.NotNull)2 IDeliverable (com.minecolonies.api.colony.requestsystem.requestable.IDeliverable)1 AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)1 CitizenData (com.minecolonies.coremod.colony.CitizenData)1 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)1 BuildingBasedRequester (com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester)1 TeleportToColony (com.minecolonies.coremod.util.TeleportToColony)1 GameProfile (com.mojang.authlib.GameProfile)1 BlockSilverfish (net.minecraft.block.BlockSilverfish)1