Search in sources :

Example 16 with IBlueprintDataProvider

use of com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider in project minecolonies by ldtteam.

the class BuildingCook method initTagPositions.

/**
 * Reads the tag positions
 */
public void initTagPositions() {
    if (initTags) {
        return;
    }
    final IBlueprintDataProvider te = getTileEntity();
    if (te != null) {
        initTags = true;
        sitPositions = new ArrayList<>();
        for (final Map.Entry<BlockPos, List<String>> entry : te.getWorldTagPosMap().entrySet()) {
            if (entry.getValue().contains(TAG_SITTING)) {
                sitPositions.add(entry.getKey());
            }
        }
    }
}
Also used : IBlueprintDataProvider(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider) BlockPos(net.minecraft.util.math.BlockPos)

Example 17 with IBlueprintDataProvider

use of com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider in project minecolonies by ldtteam.

the class AbstractEntityAIStructureWithWorkOrder method executeSpecificCompleteActions.

@Override
public void executeSpecificCompleteActions() {
    if (job.getBlueprint() == null && job.hasWorkOrder()) {
        // fix for bad structures
        job.complete();
    }
    if (job.getBlueprint() == null) {
        return;
    }
    final String structureName = job.getBlueprint().getName();
    final WorkOrderBuildDecoration wo = job.getWorkOrder();
    if (wo instanceof WorkOrderBuildBuilding) {
        sendCompletionMessage(wo);
        WorkOrderBuild wob = (WorkOrderBuild) wo;
        String buildingName = wo.getStructureName();
        buildingName = buildingName.substring(buildingName.indexOf('/') + 1, buildingName.lastIndexOf('/')) + " " + buildingName.substring(buildingName.lastIndexOf('/') + 1, buildingName.lastIndexOf(String.valueOf(wob.getUpgradeLevel())));
        job.getColony().getEventDescriptionManager().addEventDescription(wob.getUpgradeLevel() > 1 ? new BuildingUpgradedEvent(wo.getSchematicLocation(), buildingName, wob.getUpgradeLevel()) : new BuildingBuiltEvent(wo.getSchematicLocation(), buildingName, wob.getUpgradeLevel()));
    } else if (wo instanceof WorkOrderBuildRemoval) {
        worker.getCitizenChatHandler().sendLocalizedChat(COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_DECONSTRUCTION_COMPLETE, structureName);
        WorkOrderBuild wob = (WorkOrderBuild) wo;
        String buildingName = wo.getStructureName();
        buildingName = buildingName.substring(buildingName.indexOf('/') + 1, buildingName.lastIndexOf('/')) + " " + buildingName.substring(buildingName.lastIndexOf('/') + 1, buildingName.indexOf(String.valueOf(wob.getUpgradeLevel())));
        job.getColony().getEventDescriptionManager().addEventDescription(new BuildingDeconstructedEvent(wo.getSchematicLocation(), buildingName, wob.getUpgradeLevel()));
    } else {
        sendCompletionMessage(wo);
    }
    if (wo == null) {
        Log.getLogger().error(String.format("Worker (%d:%d) ERROR - Finished, but missing work order(%d)", worker.getCitizenColonyHandler().getColony().getID(), worker.getCitizenData().getId(), job.getWorkOrderId()));
    } else {
        job.complete();
        if (wo instanceof WorkOrderBuildBuilding) {
            final IBuilding building = job.getColony().getBuildingManager().getBuilding(wo.getSchematicLocation());
            if (building == null) {
                Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Finished, but missing building(%s)", worker.getCitizenColonyHandler().getColony().getID(), worker.getCitizenData().getId(), wo.getSchematicLocation()));
            } else {
                // Normally levels are done through the schematic data, but incase it is missing we do it manually here.
                final TileEntity te = worker.level.getBlockEntity(building.getID());
                if (te instanceof AbstractTileEntityColonyBuilding && ((IBlueprintDataProvider) te).getSchematicName().isEmpty()) {
                    building.onUpgradeComplete(((WorkOrderBuildBuilding) wo).getUpgradeLevel());
                    building.setBuildingLevel(((WorkOrderBuildBuilding) wo).getUpgradeLevel());
                }
            }
        } else if (wo instanceof WorkOrderBuildRemoval) {
            final IBuilding building = job.getColony().getBuildingManager().getBuilding(wo.getSchematicLocation());
            if (building == null) {
                Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Finished, but missing building(%s)", worker.getCitizenColonyHandler().getColony().getID(), worker.getCitizenData().getId(), wo.getSchematicLocation()));
            } else {
                building.setDeconstructed();
            }
        }
    }
    getOwnBuilding().resetNeededResources();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BuildingDeconstructedEvent(com.minecolonies.coremod.colony.colonyEvents.buildingEvents.BuildingDeconstructedEvent) BuildingBuiltEvent(com.minecolonies.coremod.colony.colonyEvents.buildingEvents.BuildingBuiltEvent) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) IBlueprintDataProvider(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider) BuildingUpgradedEvent(com.minecolonies.coremod.colony.colonyEvents.buildingEvents.BuildingUpgradedEvent)

Example 18 with IBlueprintDataProvider

use of com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider in project minecolonies by ldtteam.

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)

Example 19 with IBlueprintDataProvider

use of com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider in project minecolonies by ldtteam.

the class AbstractJobStructure method complete.

/**
 * Do final completion when the Job's current work is complete.
 */
public void complete() {
    getWorkOrder().onCompleted(getCitizen().getColony(), this.getCitizen());
    if (blueprint != null) {
        final CompoundNBT[][][] tileEntityData = blueprint.getTileEntities();
        for (short x = 0; x < blueprint.getSizeX(); x++) {
            for (short y = 0; y < blueprint.getSizeY(); y++) {
                for (short z = 0; z < blueprint.getSizeZ(); z++) {
                    final CompoundNBT compoundNBT = tileEntityData[y][z][x];
                    if (compoundNBT != null && compoundNBT.contains(TAG_BLUEPRINTDATA)) {
                        final BlockPos tePos = getWorkOrder().getSchematicLocation().subtract(blueprint.getPrimaryBlockOffset()).offset(x, y, z);
                        final TileEntity te = getColony().getWorld().getBlockEntity(tePos);
                        if (te instanceof IBlueprintDataProvider) {
                            ((IBlueprintDataProvider) te).readSchematicDataFromNBT(compoundNBT);
                            ((ServerWorld) getColony().getWorld()).getChunkSource().blockChanged(tePos);
                            te.setChanged();
                        }
                    }
                }
            }
        }
    }
    getCitizen().getColony().getWorkManager().removeWorkOrder(workOrderId);
    setWorkOrder(null);
    setBlueprint(null);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) CompoundNBT(net.minecraft.nbt.CompoundNBT) IBlueprintDataProvider(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider) BlockPos(net.minecraft.util.math.BlockPos)

Example 20 with IBlueprintDataProvider

use of com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider in project Structurize by ldtteam.

the class WindowTagTool method removeTag.

/**
 * Removes a block pos
 *
 * @param button
 */
private void removeTag(final Button button) {
    int row = tagList.getListElementIndexByPane(button);
    BlockPos toRemove = positionsList.get(row);
    TileEntity te = world.getBlockEntity(anchorPos);
    if (te instanceof IBlueprintDataProvider) {
        IBlueprintDataProvider dataTE = (IBlueprintDataProvider) te;
        Map<BlockPos, List<String>> map = dataTE.getPositionedTags();
        if (map.containsKey(toRemove) && !map.get(toRemove).isEmpty()) {
            String tag = map.get(toRemove).get(map.get(toRemove).size() - 1);
            dataTE.removeTag(toRemove, tag);
            Network.getNetwork().sendToServer(new AddRemoveTagMessage(false, tag, toRemove, anchorPos));
        }
        updateResourceList();
    } else {
        close();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AddRemoveTagMessage(com.ldtteam.structurize.network.messages.AddRemoveTagMessage) IBlueprintDataProvider(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider) BlockPos(net.minecraft.util.math.BlockPos) ScrollingList(com.ldtteam.blockout.views.ScrollingList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

IBlueprintDataProvider (com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider)21 TileEntity (net.minecraft.tileentity.TileEntity)19 BlockPos (net.minecraft.util.math.BlockPos)16 Blueprint (com.ldtteam.structures.blueprints.v1.Blueprint)5 ItemStack (net.minecraft.item.ItemStack)5 ScrollingList (com.ldtteam.blockout.views.ScrollingList)4 StructureName (com.ldtteam.structurize.management.StructureName)4 SchematicRequestMessage (com.ldtteam.structurize.network.messages.SchematicRequestMessage)4 IStructureHandler (com.ldtteam.structurize.placement.structure.IStructureHandler)4 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)4 IColonyView (com.minecolonies.api.colony.IColonyView)4 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)4 LoadOnlyStructureHandler (com.minecolonies.api.util.LoadOnlyStructureHandler)4 List (java.util.List)4 CompoundNBT (net.minecraft.nbt.CompoundNBT)4 Mirror (net.minecraft.util.Mirror)4 Pane (com.ldtteam.blockout.Pane)3 BlockState (net.minecraft.block.BlockState)3 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)3 Color (com.ldtteam.blockout.Color)2