Search in sources :

Example 1 with PlacementSettings

use of com.ldtteam.structurize.util.PlacementSettings in project minecolonies by Minecolonies.

the class AbstractBuilding method calculateCorners.

@Override
public void calculateCorners() {
    final AbstractTileEntityColonyBuilding te = getTileEntity();
    if (te != null && !te.getSchematicName().isEmpty()) {
        setCorners(te.getInWorldCorners().getA(), te.getInWorldCorners().getB());
        return;
    }
    final WorkOrderBuildBuilding workOrder = new WorkOrderBuildBuilding(this, Math.max(1, getBuildingLevel()));
    final LoadOnlyStructureHandler wrapper = new LoadOnlyStructureHandler(colony.getWorld(), getPosition(), workOrder.getStructureName(), new PlacementSettings(), true);
    if (!wrapper.hasBluePrint()) {
        setCorners(getPosition(), getPosition());
        return;
    }
    final Tuple<BlockPos, BlockPos> corners = ColonyUtils.calculateCorners(this.getPosition(), colony.getWorld(), wrapper.getBluePrint(), workOrder.getRotation(colony.getWorld()), workOrder.isMirrored());
    this.setCorners(corners.getA(), corners.getB());
}
Also used : WorkOrderBuildBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuildBuilding) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings)

Example 2 with PlacementSettings

use of com.ldtteam.structurize.util.PlacementSettings in project minecolonies by Minecolonies.

the class CreativeRaiderStructureHandler method loadAndPlaceStructureWithRotation.

/**
 * Load a structure into this world and place it in the right position and rotation.
 *
 * @param worldObj       the world to load it in
 * @param name           the structures name
 * @param pos            coordinates
 * @param rotation       the rotation.
 * @param mirror         the mirror used.
 * @param fancyPlacement if fancy or complete.
 * @param colonyId       the colony id.
 * @param event          the raid event.
 * @param player         the placing player.
 * @return the placed blueprint.
 */
public static Blueprint loadAndPlaceStructureWithRotation(final World worldObj, @NotNull final String name, @NotNull final BlockPos pos, final Rotation rotation, @NotNull final Mirror mirror, final boolean fancyPlacement, final int colonyId, final IColonyRaidEvent event, @Nullable final ServerPlayerEntity player) {
    try {
        @NotNull final IStructureHandler structure = new CreativeRaiderStructureHandler(worldObj, pos, name, new PlacementSettings(mirror, rotation), fancyPlacement, event, colonyId);
        if (structure.hasBluePrint()) {
            @NotNull final StructurePlacer instantPlacer = new StructurePlacer(structure);
            Manager.addToQueue(new TickedWorldOperation(instantPlacer, player));
        }
        return structure.getBluePrint();
    } catch (final IllegalStateException e) {
        Log.getLogger().warn("Could not load structure!", e);
    }
    return null;
}
Also used : IStructureHandler(com.ldtteam.structurize.placement.structure.IStructureHandler) StructurePlacer(com.ldtteam.structurize.placement.StructurePlacer) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) NotNull(org.jetbrains.annotations.NotNull) TickedWorldOperation(com.ldtteam.structurize.util.TickedWorldOperation)

Example 3 with PlacementSettings

use of com.ldtteam.structurize.util.PlacementSettings in project minecolonies by Minecolonies.

the class AbstractSchematicProvider method getRotation.

@Override
public int getRotation() {
    if (cachedRotation != -1) {
        return cachedRotation;
    }
    final StructureName structureName = new StructureName(Structures.SCHEMATICS_PREFIX, style, this.getSchematicName() + Math.max(1, buildingLevel));
    try {
        final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(colony.getWorld(), getPosition(), structureName.toString(), new PlacementSettings(), true);
        final Blueprint blueprint = structure.getBluePrint();
        if (blueprint != null) {
            final BlockState structureState = structure.getBluePrint().getBlockInfoAsMap().get(structure.getBluePrint().getPrimaryBlockOffset()).getState();
            if (structureState != null) {
                if (!(structureState.getBlock() instanceof AbstractBlockHut) || !(colony.getWorld().getBlockState(this.location).getBlock() instanceof AbstractBlockHut)) {
                    Log.getLogger().error(String.format("Schematic %s doesn't have a correct Primary Offset", structureName.toString()));
                    return 0;
                }
                final int structureRotation = structureState.getValue(AbstractBlockHut.FACING).get2DDataValue();
                final int worldRotation = colony.getWorld().getBlockState(this.location).getValue(AbstractBlockHut.FACING).get2DDataValue();
                if (structureRotation <= worldRotation) {
                    cachedRotation = worldRotation - structureRotation;
                } else {
                    cachedRotation = 4 + worldRotation - structureRotation;
                }
                return cachedRotation;
            }
        }
    } catch (Exception e) {
        Log.getLogger().error(String.format("Failed to get rotation for %s: ", structureName.toString()), e);
        return 0;
    }
    return 0;
}
Also used : BlockState(net.minecraft.block.BlockState) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) StructureName(com.ldtteam.structurize.management.StructureName) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) AbstractBlockHut(com.minecolonies.api.blocks.AbstractBlockHut) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint)

Example 4 with PlacementSettings

use of com.ldtteam.structurize.util.PlacementSettings in project minecolonies by Minecolonies.

the class AbstractSchematicProvider method unsafeUpdateTEDataFromSchematic.

/**
 * Load the schematic data from the TE schematic name, if it's a reattempt, calculate the name from the building (backup).
 * Might throw exceptions if data is invalid.
 */
private void unsafeUpdateTEDataFromSchematic(final TileEntityColonyBuilding te) {
    final String structureName;
    if (te.getSchematicName().isEmpty()) {
        structureName = new StructureName(Structures.SCHEMATICS_PREFIX, style, this.getSchematicName() + Math.max(1, buildingLevel)).toString();
    } else {
        structureName = new StructureName(Structures.SCHEMATICS_PREFIX, style, te.getSchematicName()).toString();
    }
    final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(colony.getWorld(), getPosition(), structureName, new PlacementSettings(), true);
    final Blueprint blueprint = structure.getBluePrint();
    blueprint.rotateWithMirror(BlockPosUtil.getRotationFromRotations(getRotation()), isMirrored() ? Mirror.FRONT_BACK : Mirror.NONE, colony.getWorld());
    final BlockInfo info = blueprint.getBlockInfoAsMap().getOrDefault(blueprint.getPrimaryBlockOffset(), null);
    if (info.getTileEntityData() != null) {
        te.readSchematicDataFromNBT(info.getTileEntityData());
    }
}
Also used : Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) BlockInfo(com.ldtteam.structurize.util.BlockInfo) StructureName(com.ldtteam.structurize.management.StructureName) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings)

Example 5 with PlacementSettings

use of com.ldtteam.structurize.util.PlacementSettings in project minecolonies by Minecolonies.

the class WindowBuildBuilding method updateResources.

/**
 * Clears and resets/updates all resources.
 */
private void updateResources() {
    if (stylesDropDownList.getSelectedIndex() == -1) {
        return;
    }
    final World world = Minecraft.getInstance().level;
    resources.clear();
    final IBuildingView parentBuilding = building.getColony().getBuilding(building.getParent());
    int nextLevel = building.getBuildingLevel();
    if (building.getBuildingLevel() < building.getBuildingMaxLevel() && (parentBuilding == null || building.getBuildingLevel() < parentBuilding.getBuildingLevel())) {
        nextLevel = building.getBuildingLevel() + 1;
    }
    final TileEntity tile = world.getBlockEntity(building.getID());
    String schematicName = building.getSchematicName();
    if (tile instanceof IBlueprintDataProvider) {
        if (!((IBlueprintDataProvider) tile).getSchematicName().isEmpty()) {
            schematicName = ((IBlueprintDataProvider) tile).getSchematicName().replaceAll("\\d$", "");
        }
    }
    final StructureName sn = new StructureName(Structures.SCHEMATICS_PREFIX, styles.get(stylesDropDownList.getSelectedIndex()), schematicName + nextLevel);
    final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(world, building.getPosition(), sn.toString(), new PlacementSettings(), true);
    final String md5 = Structures.getMD5(sn.toString());
    if (!structure.hasBluePrint() || !structure.isCorrectMD5(md5)) {
        if (!structure.hasBluePrint()) {
            Log.getLogger().info("Template structure " + sn + " missing");
        } else {
            Log.getLogger().info("structure " + sn + " md5 error");
        }
        Log.getLogger().info("Request To Server for structure " + sn);
        if (ServerLifecycleHooks.getCurrentServer() == null) {
            com.ldtteam.structurize.Network.getNetwork().sendToServer(new SchematicRequestMessage(sn.toString()));
            return;
        } else {
            Log.getLogger().error("WindowMinecoloniesBuildTool: Need to download schematic on a standalone client/server. This should never happen", new Exception());
        }
    }
    if (!structure.hasBluePrint()) {
        findPaneOfTypeByID(BUTTON_BUILD, Button.class).hide();
        findPaneOfTypeByID(BUTTON_REPAIR, Button.class).hide();
        findPaneOfTypeByID(BUTTON_PICKUP_BUILDING, Button.class).show();
        return;
    }
    structure.getBluePrint().rotateWithMirror(BlockPosUtil.getRotationFromRotations(building.getRotation()), building.isMirrored() ? Mirror.FRONT_BACK : Mirror.NONE, world);
    StructurePlacer placer = new StructurePlacer(structure);
    StructurePhasePlacementResult result;
    BlockPos progressPos = NULL_POS;
    do {
        result = placer.executeStructureStep(world, null, progressPos, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.and((info, pos, handler) -> false)), true);
        progressPos = result.getIteratorPos();
        for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
            addNeededResource(stack, stack.getCount());
        }
    } while (result != null && result.getBlockResult().getResult() != BlockPlacementResult.Result.FINISHED);
    window.findPaneOfTypeByID(LIST_RESOURCES, ScrollingList.class).refreshElementPanes();
    updateResourceList();
}
Also used : LanguageHandler(com.ldtteam.structurize.util.LanguageHandler) DropDownList(com.ldtteam.blockout.views.DropDownList) Structures(com.ldtteam.structurize.management.Structures) IBuilderUndestroyable(com.minecolonies.api.entity.ai.citizen.builder.IBuilderUndestroyable) ScrollingList(com.ldtteam.blockout.views.ScrollingList) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) TriPredicate(net.minecraftforge.common.util.TriPredicate) ServerLifecycleHooks(net.minecraftforge.fml.server.ServerLifecycleHooks) Settings(com.ldtteam.structures.helpers.Settings) Network(com.minecolonies.coremod.Network) Log(com.minecolonies.api.util.Log) BlockState(net.minecraft.block.BlockState) Constants(com.minecolonies.api.util.constant.Constants) Color(com.ldtteam.blockout.Color) BuildPickUpMessage(com.minecolonies.coremod.network.messages.server.colony.building.BuildPickUpMessage) StructureName(com.ldtteam.structurize.management.StructureName) BuildingSetStyleMessage(com.minecolonies.coremod.network.messages.server.colony.building.BuildingSetStyleMessage) BlueprintPositionInfo(com.ldtteam.structurize.util.BlueprintPositionInfo) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Collectors(java.util.stream.Collectors) Text(com.ldtteam.blockout.controls.Text) Nullable(org.jetbrains.annotations.Nullable) IStructureHandler(com.ldtteam.structurize.placement.structure.IStructureHandler) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) StructurePlacer(com.ldtteam.structurize.placement.StructurePlacer) java.util(java.util) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) Mirror(net.minecraft.util.Mirror) ItemIcon(com.ldtteam.blockout.controls.ItemIcon) ItemStack(net.minecraft.item.ItemStack) Minecraft(net.minecraft.client.Minecraft) BuildRequestMessage(com.minecolonies.coremod.network.messages.server.colony.building.BuildRequestMessage) ModJobs(com.minecolonies.api.colony.jobs.ModJobs) SchematicRequestMessage(com.ldtteam.structurize.network.messages.SchematicRequestMessage) StructurePhasePlacementResult(com.ldtteam.structurize.placement.StructurePhasePlacementResult) IBlueprintDataProvider(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider) IColonyView(com.minecolonies.api.colony.IColonyView) AbstractBuildingBuilderView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingBuilderView) World(net.minecraft.world.World) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) Tuple(net.minecraft.util.Tuple) BlockPos(net.minecraft.util.math.BlockPos) NULL_POS(com.ldtteam.structurize.placement.AbstractBlueprintIterator.NULL_POS) Pane(com.ldtteam.blockout.Pane) BlockPosUtil(com.minecolonies.api.util.BlockPosUtil) AbstractBlockHut(com.minecolonies.api.blocks.AbstractBlockHut) Blocks(net.minecraft.block.Blocks) ModBuildings(com.minecolonies.api.colony.buildings.ModBuildings) Button(com.ldtteam.blockout.controls.Button) WindowConstants(com.minecolonies.api.util.constant.WindowConstants) BlockPlacementResult(com.ldtteam.structurize.placement.BlockPlacementResult) TileEntity(net.minecraft.tileentity.TileEntity) IBlueprintDataProvider(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider) StructureName(com.ldtteam.structurize.management.StructureName) World(net.minecraft.world.World) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) TileEntity(net.minecraft.tileentity.TileEntity) SchematicRequestMessage(com.ldtteam.structurize.network.messages.SchematicRequestMessage) Button(com.ldtteam.blockout.controls.Button) StructurePhasePlacementResult(com.ldtteam.structurize.placement.StructurePhasePlacementResult) StructurePlacer(com.ldtteam.structurize.placement.StructurePlacer) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) BlockPos(net.minecraft.util.math.BlockPos) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) ItemStack(net.minecraft.item.ItemStack) ScrollingList(com.ldtteam.blockout.views.ScrollingList)

Aggregations

PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)42 BlockPos (net.minecraft.util.math.BlockPos)26 LoadOnlyStructureHandler (com.minecolonies.api.util.LoadOnlyStructureHandler)20 NotNull (org.jetbrains.annotations.NotNull)15 StructurePlacer (com.ldtteam.structurize.placement.StructurePlacer)12 IStructureHandler (com.ldtteam.structurize.placement.structure.IStructureHandler)12 TileEntity (net.minecraft.tileentity.TileEntity)12 World (net.minecraft.world.World)11 ItemStack (net.minecraft.item.ItemStack)10 Blueprint (com.ldtteam.structures.blueprints.v1.Blueprint)9 StructureName (com.ldtteam.structurize.management.StructureName)9 StructurePhasePlacementResult (com.ldtteam.structurize.placement.StructurePhasePlacementResult)8 SchematicRequestMessage (com.ldtteam.structurize.network.messages.SchematicRequestMessage)7 TickedWorldOperation (com.ldtteam.structurize.util.TickedWorldOperation)7 Mirror (net.minecraft.util.Mirror)7 IBlueprintDataProvider (com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider)6 NULL_POS (com.ldtteam.structurize.placement.AbstractBlueprintIterator.NULL_POS)6 BlockPlacementResult (com.ldtteam.structurize.placement.BlockPlacementResult)6 IColonyView (com.minecolonies.api.colony.IColonyView)6 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)6