Search in sources :

Example 26 with Colony

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

the class ItemAncientTome method onUpdate.

@Override
public void onUpdate(final ItemStack stack, final World worldIn, final Entity entityIn, final int itemSlot, final boolean isSelected) {
    super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected);
    final Colony colony = ColonyManager.getClosestColony(worldIn, entityIn.getPosition());
    raidWillHappen = colony != null && colony.hasWillRaidTonight();
}
Also used : Colony(com.minecolonies.coremod.colony.Colony)

Example 27 with Colony

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

the class BuildRequestMessage method messageOnServerThread.

@Override
public void messageOnServerThread(final BuildRequestMessage message, final EntityPlayerMP player) {
    final Colony colony = ColonyManager.getColony(message.colonyId);
    if (colony == null) {
        return;
    }
    final AbstractBuilding building = colony.getBuildingManager().getBuilding(message.buildingId);
    if (building == null) {
        return;
    }
    // Verify player has permission to change this huts settings
    if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
        return;
    }
    if (building.hasWorkOrder()) {
        building.removeWorkOrder();
    } else {
        switch(message.mode) {
            case BUILD:
                building.requestUpgrade(player);
                break;
            case REPAIR:
                building.requestRepair();
                break;
            default:
                break;
        }
    }
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 28 with Colony

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

the class BuildToolPasteMessage method setupBuilding.

/**
 * setup the building once it has been placed.
 *
 * @param world         World the hut is being placed into.
 * @param player        Who placed the hut.
 * @param sn            The name of the structure.
 * @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 setupBuilding(@NotNull final World world, @NotNull final EntityPlayer player, final StructureName sn, final int rotation, @NotNull final BlockPos buildPos, final boolean mirror) {
    @Nullable final AbstractBuilding building = ColonyManager.getBuilding(world, buildPos);
    if (building == null) {
        Log.getLogger().error("BuildTool: building is null!");
    } else {
        if (building.getTileEntity() != null) {
            final Colony colony = ColonyManager.getColony(world, buildPos);
            if (colony == null) {
                Log.getLogger().info("No colony for " + player.getName());
            } else {
                building.getTileEntity().setColony(colony);
            }
        }
        String name = sn.toString();
        name = name.substring(name.length() - 1);
        try {
            final int level = Integer.parseInt(name);
            building.setBuildingLevel(level);
        } catch (final NumberFormatException e) {
            Log.getLogger().warn("Couldn't parse the level.", e);
        }
        building.setStyle(sn.getStyle());
        building.setRotation(rotation);
        if (mirror) {
            building.invertMirror();
        }
    }
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) TextComponentString(net.minecraft.util.text.TextComponentString) Nullable(org.jetbrains.annotations.Nullable) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 29 with Colony

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

the class BuildToolPasteMessage 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 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 StructureName sn, final int rotation, @NotNull final BlockPos buildPos, final boolean mirror) {
    final Colony tempColony = ColonyManager.getClosestColony(world, buildPos);
    if (tempColony != null && !tempColony.getPermissions().hasPermission(player, Action.MANAGE_HUTS) && !ColonyManager.isTooCloseToColony(world, buildPos)) {
        return;
    }
    final String hut = sn.getSection();
    final Block block = Block.getBlockFromName(Constants.MOD_ID + ":blockHut" + hut);
    if (block != null && 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());
        setupBuilding(world, player, sn, rotation, buildPos, mirror);
    }
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) Block(net.minecraft.block.Block) TextComponentString(net.minecraft.util.text.TextComponentString) AbstractBlockHut(com.minecolonies.coremod.blocks.AbstractBlockHut)

Example 30 with Colony

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

the class BuildToolPlaceMessage method setupBuilding.

/**
 * setup the building once it has been placed.
 *
 * @param world         World the hut is being placed into.
 * @param player        Who placed the hut.
 * @param sn            The name of the structure.
 * @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 setupBuilding(@NotNull final World world, @NotNull final EntityPlayer player, final StructureName sn, final int rotation, @NotNull final BlockPos buildPos, final boolean mirror) {
    @Nullable final AbstractBuilding building = ColonyManager.getBuilding(world, buildPos);
    if (building == null) {
        Log.getLogger().error("BuildTool: building is null!");
    } else {
        if (building.getTileEntity() != null) {
            final Colony colony = ColonyManager.getColony(world, buildPos);
            if (colony == null) {
                Log.getLogger().info("No colony for " + player.getName());
            } else {
                building.getTileEntity().setColony(colony);
            }
        }
        building.setStyle(sn.getStyle());
        building.setRotation(rotation);
        if (mirror) {
            building.invertMirror();
        }
    }
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) Nullable(org.jetbrains.annotations.Nullable) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

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