Search in sources :

Example 6 with PlacementError

use of com.ldtteam.structurize.placement.handlers.placement.PlacementError in project minecolonies by Minecolonies.

the class ItemSupplyChestDeployer method checkFluidAndNotInColony.

/**
 * Check if the there is water at one of three positions.
 *
 * @param world              the world.
 * @param pos                the first position.
 * @param placementErrorList a list of placement errors.
 * @param placer             the player placing the supply camp.
 */
private static void checkFluidAndNotInColony(final World world, final BlockPos pos, @NotNull final List<PlacementError> placementErrorList, final PlayerEntity placer) {
    final boolean isOverworld = WorldUtil.isOverworldType(world);
    final boolean isWater = BlockUtils.isWater(world.getBlockState(pos));
    final boolean notInAnyColony = hasPlacePermission(world, pos, placer);
    if (!isWater && isOverworld) {
        final PlacementError placementError = new PlacementError(PlacementError.PlacementErrorType.NOT_WATER, pos);
        placementErrorList.add(placementError);
    } else if (!world.getBlockState(pos).getFluidState().getType().isSame(Fluids.LAVA) && !isOverworld) {
        final PlacementError placementError = new PlacementError(PlacementError.PlacementErrorType.NOT_WATER, pos);
        placementErrorList.add(placementError);
    }
    if (!notInAnyColony) {
        final PlacementError placementError = new PlacementError(PlacementError.PlacementErrorType.INSIDE_COLONY, pos);
        placementErrorList.add(placementError);
    }
}
Also used : PlacementError(com.ldtteam.structurize.placement.handlers.placement.PlacementError)

Example 7 with PlacementError

use of com.ldtteam.structurize.placement.handlers.placement.PlacementError in project minecolonies by Minecolonies.

the class ItemSupplyChestDeployer method canShipBePlaced.

/**
 * Checks if the ship can be placed.
 *
 * @param world              the world.
 * @param pos                the pos.
 * @param ship               the blueprint.
 * @param placementErrorList the list of placement errors.
 * @param placer             the placer.
 * @return true if so.
 */
public static boolean canShipBePlaced(@NotNull final World world, @NotNull final BlockPos pos, final Blueprint ship, @NotNull final List<PlacementError> placementErrorList, final PlayerEntity placer) {
    if (MineColonies.getConfig().getServer().noSupplyPlacementRestrictions.get()) {
        return true;
    }
    final int sizeX = ship.getSizeX();
    final int sizeZ = ship.getSizeZ();
    final int waterLevel = BlueprintTagUtils.getNumberOfGroundLevels(ship, DEFAULT_WATER_LEVELS);
    final BlockPos zeroPos = pos.subtract(ship.getPrimaryBlockOffset());
    for (int z = zeroPos.getZ(); z < zeroPos.getZ() + sizeZ; z++) {
        for (int x = zeroPos.getX(); x < zeroPos.getX() + sizeX; x++) {
            for (int y = zeroPos.getY(); y <= zeroPos.getY() + waterLevel + SCAN_HEIGHT; y++) {
                if (y < zeroPos.getY() + waterLevel) {
                    checkFluidAndNotInColony(world, new BlockPos(x, y, z), placementErrorList, placer);
                } else if (world.getBlockState(new BlockPos(x, y, z)).getMaterial().isSolid()) {
                    final PlacementError placementError = new PlacementError(PlacementError.PlacementErrorType.NEEDS_AIR_ABOVE, new BlockPos(x, y, z));
                    placementErrorList.add(placementError);
                }
            }
        }
    }
    return placementErrorList.isEmpty();
}
Also used : PlacementError(com.ldtteam.structurize.placement.handlers.placement.PlacementError) BlockPos(net.minecraft.util.math.BlockPos) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint)

Example 8 with PlacementError

use of com.ldtteam.structurize.placement.handlers.placement.PlacementError in project minecolonies by ldtteam.

the class WindowMinecoloniesBuildTool method checkAndPlace.

@Override
public void checkAndPlace() {
    final List<PlacementError> placementErrorList = new ArrayList<>();
    final String schemName = Settings.instance.getStaticSchematicName();
    if (schemName.contains("supplyship") || schemName.contains("nethership")) {
        if (ItemSupplyChestDeployer.canShipBePlaced(Minecraft.getInstance().level, Settings.instance.getPosition(), Settings.instance.getActiveStructure(), placementErrorList, Minecraft.getInstance().player)) {
            super.pasteNice();
        } else {
            LanguageHandler.sendPlayerMessage(Minecraft.getInstance().player, "item.supplyChestDeployer.invalid");
        }
    } else if (schemName.contains("supplycamp")) {
        if (ItemSupplyCampDeployer.canCampBePlaced(Minecraft.getInstance().level, Settings.instance.getPosition(), placementErrorList, Minecraft.getInstance().player)) {
            super.pasteNice();
        }
    }
    HighlightManager.clearCategory(RENDER_BOX_CATEGORY);
    if (!placementErrorList.isEmpty()) {
        LanguageHandler.sendPlayerMessage(Minecraft.getInstance().player, "item.supply.badblocks");
        for (final PlacementError error : placementErrorList) {
            HighlightManager.addRenderBox(RENDER_BOX_CATEGORY, new HighlightManager.TimedBoxRenderData().setPos(error.getPos()).setRemovalTimePoint(Minecraft.getInstance().level.getGameTime() + 120 * 20 * 60).addText(LanguageHandler.translateKey("item.supply.error." + error.getType().toString().toLowerCase())).setColor(0xFF0000));
        }
    }
    if (!Screen.hasShiftDown()) {
        super.cancelClicked();
    }
}
Also used : HighlightManager(com.minecolonies.coremod.event.HighlightManager) PlacementError(com.ldtteam.structurize.placement.handlers.placement.PlacementError) ArrayList(java.util.ArrayList)

Example 9 with PlacementError

use of com.ldtteam.structurize.placement.handlers.placement.PlacementError in project minecolonies by ldtteam.

the class ItemSupplyCampDeployer method canCampBePlaced.

/**
 * Checks if the camp can be placed.
 *
 * @param world              the world.
 * @param pos                the position.
 * @param placementErrorList the list of placement errors.
 * @param placer             the placer.
 * @return true if so.
 */
public static boolean canCampBePlaced(@NotNull final World world, @NotNull final BlockPos pos, @NotNull final List<PlacementError> placementErrorList, final PlayerEntity placer) {
    if (MineColonies.getConfig().getServer().noSupplyPlacementRestrictions.get()) {
        return true;
    }
    final BlockPos zeroPos = pos.subtract(Settings.instance.getActiveStructure().getPrimaryBlockOffset());
    final int sizeX = Settings.instance.getActiveStructure().getSizeX();
    final int sizeZ = Settings.instance.getActiveStructure().getSizeZ();
    final int groundLevel = zeroPos.getY() + BlueprintTagUtils.getNumberOfGroundLevels(Settings.instance.getActiveStructure(), 1) - 1;
    for (int z = zeroPos.getZ(); z < zeroPos.getZ() + sizeZ; z++) {
        for (int x = zeroPos.getX(); x < zeroPos.getX() + sizeX; x++) {
            checkIfSolidAndNotInColony(world, new BlockPos(x, groundLevel, z), placementErrorList, placer);
            if (world.getBlockState(new BlockPos(x, groundLevel + 1, z)).getMaterial().isSolid()) {
                final PlacementError placementError = new PlacementError(PlacementError.PlacementErrorType.NEEDS_AIR_ABOVE, new BlockPos(x, pos.getY(), z));
                placementErrorList.add(placementError);
            }
        }
    }
    return placementErrorList.isEmpty();
}
Also used : PlacementError(com.ldtteam.structurize.placement.handlers.placement.PlacementError) BlockPos(net.minecraft.util.math.BlockPos)

Example 10 with PlacementError

use of com.ldtteam.structurize.placement.handlers.placement.PlacementError in project minecolonies by ldtteam.

the class ItemSupplyCampDeployer method checkIfSolidAndNotInColony.

/**
 * Check if the there is a solid block at a position and it's not in a colony.
 *
 * @param world              the world.
 * @param pos                the position.
 * @param placementErrorList a list of placement errors.
 * @param placer             the player placing the supply camp.
 */
private static void checkIfSolidAndNotInColony(final World world, final BlockPos pos, @NotNull final List<PlacementError> placementErrorList, final PlayerEntity placer) {
    final boolean isSolid = world.getBlockState(pos).getMaterial().isSolid();
    final boolean notInAnyColony = hasPlacePermission(world, pos, placer);
    if (!isSolid) {
        final PlacementError placementError = new PlacementError(PlacementError.PlacementErrorType.NOT_SOLID, pos);
        placementErrorList.add(placementError);
    }
    if (!notInAnyColony) {
        final PlacementError placementError = new PlacementError(PlacementError.PlacementErrorType.INSIDE_COLONY, pos);
        placementErrorList.add(placementError);
    }
}
Also used : PlacementError(com.ldtteam.structurize.placement.handlers.placement.PlacementError)

Aggregations

PlacementError (com.ldtteam.structurize.placement.handlers.placement.PlacementError)10 BlockPos (net.minecraft.util.math.BlockPos)4 Blueprint (com.ldtteam.structures.blueprints.v1.Blueprint)2 HighlightManager (com.minecolonies.coremod.event.HighlightManager)2 ArrayList (java.util.ArrayList)2 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)1