Search in sources :

Example 1 with BlockHutTownHall

use of com.minecolonies.coremod.blocks.BlockHutTownHall 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 2 with BlockHutTownHall

use of com.minecolonies.coremod.blocks.BlockHutTownHall 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 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 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 && !ColonyManager.isTooCloseToColony(world, buildPos)))) {
        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)

Aggregations

AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)2 BlockHutTownHall (com.minecolonies.coremod.blocks.BlockHutTownHall)2 Colony (com.minecolonies.coremod.colony.Colony)2 Block (net.minecraft.block.Block)2 ItemStack (net.minecraft.item.ItemStack)2 TextComponentString (net.minecraft.util.text.TextComponentString)2