Search in sources :

Example 1 with StructureWrapper

use of com.minecolonies.coremod.util.StructureWrapper in project minecolonies by Minecolonies.

the class WindowBuildBuilding method updateResources.

/**
 * Clears and resets/updates all resources.
 */
private void updateResources() {
    final World world = Minecraft.getMinecraft().world;
    resources.clear();
    final int nextLevel = building.getBuildingLevel() == building.getBuildingMaxLevel() ? building.getBuildingMaxLevel() : (building.getBuildingLevel() + 1);
    final StructureName sn = new StructureName(Structures.SCHEMATICS_PREFIX, styles.get(stylesDropDownList.getSelectedIndex()), building.getSchematicName() + nextLevel);
    final StructureWrapper wrapper = new StructureWrapper(world, sn.toString());
    wrapper.setPosition(building.getLocation());
    wrapper.rotate(building.getRotation(), world, building.getLocation(), building.isMirrored() ? Mirror.FRONT_BACK : Mirror.NONE);
    while (wrapper.findNextBlock()) {
        @Nullable final Template.BlockInfo blockInfo = wrapper.getBlockInfo();
        @Nullable final Template.EntityInfo entityInfo = wrapper.getEntityinfo();
        if (entityInfo != null) {
            for (final ItemStack stack : ItemStackUtils.getListOfStackForEntity(entityInfo, world, Minecraft.getMinecraft().player)) {
                if (!ItemStackUtils.isEmpty(stack)) {
                    addNeededResource(stack, 1);
                }
            }
        }
        if (blockInfo == null) {
            continue;
        }
        @Nullable final IBlockState blockState = blockInfo.blockState;
        @Nullable final Block block = blockState.getBlock();
        if (wrapper.isStructureBlockEqualWorldBlock() || (blockState.getBlock() instanceof BlockBed && blockState.getValue(BlockBed.PART).equals(BlockBed.EnumPartType.FOOT)) || (blockState.getBlock() instanceof BlockDoor && blockState.getValue(BlockDoor.HALF).equals(BlockDoor.EnumDoorHalf.UPPER))) {
            continue;
        }
        if (block != null && block != Blocks.AIR && !AbstractEntityAIStructure.isBlockFree(block, 0) && block != ModBlocks.blockSolidSubstitution && block != ModBlocks.blockSubstitution) {
            if (wrapper.getBlockInfo().tileentityData != null) {
                final List<ItemStack> itemList = new ArrayList<>();
                if (wrapper.getBlockInfo() != null && wrapper.getBlockInfo().tileentityData != null) {
                    itemList.addAll(ItemStackUtils.getItemStacksOfTileEntity(wrapper.getBlockInfo().tileentityData, world));
                }
                for (final ItemStack stack : itemList) {
                    addNeededResource(stack, 1);
                }
            }
            addNeededResource(BlockUtils.getItemStackFromBlockState(blockState), 1);
        }
    }
    window.findPaneOfTypeByID(LIST_RESOURCES, ScrollingList.class).refreshElementPanes();
    updateResourceList();
}
Also used : StructureWrapper(com.minecolonies.coremod.util.StructureWrapper) IBlockState(net.minecraft.block.state.IBlockState) ArrayList(java.util.ArrayList) StructureName(com.minecolonies.coremod.colony.StructureName) BlockBed(net.minecraft.block.BlockBed) World(net.minecraft.world.World) Template(net.minecraft.world.gen.structure.template.Template) BlockDoor(net.minecraft.block.BlockDoor) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) ScrollingList(com.minecolonies.blockout.views.ScrollingList) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with StructureWrapper

use of com.minecolonies.coremod.util.StructureWrapper in project minecolonies by Minecolonies.

the class ConstructionTapeHelper method placeConstructionTape.

/**
 * Calculates the borders for the workOrderBuildDecoration and sends it to the placement.
 *
 * @param workOrder the workOrder.
 * @param world     the world.
 */
public static void placeConstructionTape(@NotNull final WorkOrderBuildDecoration workOrder, @NotNull final World world) {
    final Tuple<Tuple<Integer, Integer>, Tuple<Integer, Integer>> corners = ColonyUtils.calculateCorners(workOrder.getBuildingLocation(), world, new StructureWrapper(world, workOrder.getStructureName()), workOrder.getRotation(world), workOrder.isMirrored());
    placeConstructionTape(workOrder.getBuildingLocation(), corners, world);
}
Also used : StructureWrapper(com.minecolonies.coremod.util.StructureWrapper) Tuple(net.minecraft.util.Tuple)

Example 3 with StructureWrapper

use of com.minecolonies.coremod.util.StructureWrapper in project minecolonies by Minecolonies.

the class EntityAIStructureBuilder method getWorkingPosition.

/**
 * Calculates the working position.
 * <p>
 * Takes a min distance from width and length.
 * <p>
 * Then finds the floor level at that distance and then check if it does contain two air levels.
 *
 * @param targetPosition the position to work at.
 * @return BlockPos position to work from.
 */
@Override
public BlockPos getWorkingPosition(final BlockPos targetPosition) {
    final StructureWrapper wrapper = job.getStructure();
    final int x1 = wrapper.getPosition().getX() - wrapper.getOffset().getX() - STAND_OFFSET;
    final int z1 = wrapper.getPosition().getZ() - wrapper.getOffset().getZ() - STAND_OFFSET;
    final int x3 = wrapper.getPosition().getX() + (wrapper.getWidth() - wrapper.getOffset().getX()) + STAND_OFFSET;
    final int z3 = wrapper.getPosition().getZ() + (wrapper.getLength() - wrapper.getOffset().getZ() + STAND_OFFSET);
    final BlockPos[] edges = new BlockPos[] { new BlockPos(x1, BASE_Y_HEIGHT, z1), new BlockPos(x3, 70, z1), new BlockPos(x1, BASE_Y_HEIGHT, z3), new BlockPos(x3, BASE_Y_HEIGHT, z3) };
    for (final BlockPos pos : edges) {
        final BlockPos basePos = world.getTopSolidOrLiquidBlock(pos);
        if (EntityUtils.checkForFreeSpace(world, basePos.down()) && world.getBlockState(basePos).getBlock() != Blocks.SAPLING && world.getBlockState(basePos.down()).getMaterial().isSolid()) {
            return basePos;
        }
    }
    return targetPosition;
}
Also used : StructureWrapper(com.minecolonies.coremod.util.StructureWrapper) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with StructureWrapper

use of com.minecolonies.coremod.util.StructureWrapper in project minecolonies by Minecolonies.

the class AbstractBuilding method create.

/**
 * Create a Building given it's TileEntity.
 *
 * @param colony The owning colony.
 * @param parent The Tile Entity the building belongs to.
 * @return {@link AbstractBuilding} instance, without NBTTags applied.
 */
@Nullable
public static AbstractBuilding create(final Colony colony, @NotNull final TileEntityColonyBuilding parent) {
    @Nullable AbstractBuilding building = null;
    final Class<?> oclass;
    try {
        oclass = blockClassToBuildingClassMap.get(parent.getBlockType().getClass());
        if (oclass == null) {
            Log.getLogger().error(String.format("TileEntity %s does not have an associated Building.", parent.getClass().getName()));
            return null;
        }
        final BlockPos loc = parent.getPosition();
        final Constructor<?> constructor = oclass.getDeclaredConstructor(Colony.class, BlockPos.class);
        building = (AbstractBuilding) constructor.newInstance(colony, loc);
    } catch (@NotNull NoSuchMethodException | InstantiationException | InvocationTargetException | IllegalAccessException exception) {
        Log.getLogger().error(String.format("Unknown Building type '%s' or missing constructor of proper format.", parent.getClass().getName()), exception);
    }
    if (building != null && parent.getWorld() != null) {
        final WorkOrderBuild workOrder = new WorkOrderBuild(building, 1);
        final StructureWrapper wrapper = new StructureWrapper(parent.getWorld(), workOrder.getStructureName());
        final Tuple<Tuple<Integer, Integer>, Tuple<Integer, Integer>> corners = ColonyUtils.calculateCorners(building.getLocation(), parent.getWorld(), wrapper, workOrder.getRotation(parent.getWorld()), workOrder.isMirrored());
        building.setCorners(corners.getFirst().getFirst(), corners.getFirst().getSecond(), corners.getSecond().getFirst(), corners.getSecond().getSecond());
        building.setHeight(wrapper.getHeight());
        ConstructionTapeHelper.placeConstructionTape(building.getLocation(), corners, parent.getWorld());
    }
    return building;
}
Also used : WorkOrderBuild(com.minecolonies.coremod.colony.workorders.WorkOrderBuild) StructureWrapper(com.minecolonies.coremod.util.StructureWrapper) InvocationTargetException(java.lang.reflect.InvocationTargetException) BlockPos(net.minecraft.util.math.BlockPos) Nullable(org.jetbrains.annotations.Nullable) Tuple(net.minecraft.util.Tuple) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with StructureWrapper

use of com.minecolonies.coremod.util.StructureWrapper in project minecolonies by Minecolonies.

the class AbstractBuilding method onUpgradeComplete.

/**
 * Called upon completion of an upgrade process.
 * We suppress this warning since this parameter will be used in child classes which override this method.
 *
 * @param newLevel The new level.
 */
@SuppressWarnings("squid:S1172")
public void onUpgradeComplete(final int newLevel) {
    final WorkOrderBuild workOrder = new WorkOrderBuild(this, newLevel);
    final StructureWrapper wrapper = new StructureWrapper(colony.getWorld(), workOrder.getStructureName());
    final Tuple<Tuple<Integer, Integer>, Tuple<Integer, Integer>> corners = ColonyUtils.calculateCorners(this.getLocation(), colony.getWorld(), wrapper, workOrder.getRotation(colony.getWorld()), workOrder.isMirrored());
    this.height = wrapper.getHeight();
    this.setCorners(corners.getFirst().getFirst(), corners.getFirst().getSecond(), corners.getSecond().getFirst(), corners.getSecond().getSecond());
}
Also used : WorkOrderBuild(com.minecolonies.coremod.colony.workorders.WorkOrderBuild) StructureWrapper(com.minecolonies.coremod.util.StructureWrapper) Tuple(net.minecraft.util.Tuple)

Aggregations

StructureWrapper (com.minecolonies.coremod.util.StructureWrapper)8 Tuple (net.minecraft.util.Tuple)4 Nullable (org.jetbrains.annotations.Nullable)3 WorkOrderBuild (com.minecolonies.coremod.colony.workorders.WorkOrderBuild)2 BlockPos (net.minecraft.util.math.BlockPos)2 ScrollingList (com.minecolonies.blockout.views.ScrollingList)1 StructureName (com.minecolonies.coremod.colony.StructureName)1 AbstractJobStructure (com.minecolonies.coremod.colony.jobs.AbstractJobStructure)1 Structure (com.minecolonies.coremod.entity.ai.util.Structure)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 Block (net.minecraft.block.Block)1 BlockBed (net.minecraft.block.BlockBed)1 BlockDoor (net.minecraft.block.BlockDoor)1 IBlockState (net.minecraft.block.state.IBlockState)1 ItemStack (net.minecraft.item.ItemStack)1 World (net.minecraft.world.World)1 Template (net.minecraft.world.gen.structure.template.Template)1