Search in sources :

Example 6 with IBlueprintDataProvider

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

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 7 with IBlueprintDataProvider

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

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 8 with IBlueprintDataProvider

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

the class WindowScan method onOpened.

@Override
public void onOpened() {
    super.onOpened();
    if (!Minecraft.getInstance().player.isCreative()) {
        pos1x.disable();
        pos1y.disable();
        pos1z.disable();
        pos2x.disable();
        pos2y.disable();
        pos2z.disable();
    }
    pos1x.setText(String.valueOf(pos1.getX()));
    pos1y.setText(String.valueOf(pos1.getY()));
    pos1z.setText(String.valueOf(pos1.getZ()));
    pos2x.setText(String.valueOf(pos2.getX()));
    pos2y.setText(String.valueOf(pos2.getY()));
    pos2z.setText(String.valueOf(pos2.getZ()));
    Settings.instance.setAnchorPos(this.anchorPos);
    Settings.instance.setBox(new Tuple<>(pos1, pos2));
    if (anchorPos.isPresent()) {
        final TileEntity tile = Minecraft.getInstance().player.level.getBlockEntity(anchorPos.get());
        if (tile instanceof IBlueprintDataProvider && !((IBlueprintDataProvider) tile).getSchematicName().isEmpty()) {
            findPaneOfTypeByID(NAME_LABEL, TextField.class).setText(((IBlueprintDataProvider) tile).getSchematicName());
        }
    }
    findPaneOfTypeByID(FILTER_NAME, TextField.class).setHandler(input -> {
        final String name = findPaneOfTypeByID(FILTER_NAME, TextField.class).getText();
        if (!name.isEmpty()) {
            filter = name;
        }
        updateResources();
    });
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlueprintDataProvider(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider) TextField(com.ldtteam.blockout.controls.TextField)

Example 9 with IBlueprintDataProvider

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

the class WindowTagTool method updateResourceList.

/**
 * Updates the current tag list
 */
public void updateResourceList() {
    tagList.enable();
    tagList.show();
    TileEntity te = world.getBlockEntity(anchorPos);
    if (te instanceof IBlueprintDataProvider) {
        IBlueprintDataProvider dataTE = (IBlueprintDataProvider) te;
        positionsList = new ArrayList<>(dataTE.getPositionedTags().keySet());
    } else {
        close();
    }
    // Creates a dataProvider for the unemployed resourceList.
    tagList.setDataProvider(new ScrollingList.DataProvider() {

        /**
         * The number of rows of the list.
         * @return the number.
         */
        @Override
        public int getElementCount() {
            return positionsList.size();
        }

        /**
         * Inserts the elements into each row.
         * @param index the index of the row/list element.
         * @param rowPane the parent Pane for the row, containing the elements to update.
         */
        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            TileEntity te = world.getBlockEntity(anchorPos);
            if (te instanceof IBlueprintDataProvider) {
                IBlueprintDataProvider dataTE = (IBlueprintDataProvider) te;
                positionsList = new ArrayList<>(dataTE.getPositionedTags().keySet());
                positionsList = new ArrayList<>(dataTE.getPositionedTags().keySet());
                final BlockPos pos = positionsList.get(index);
                final List<String> tags = dataTE.getPositionedTags().get(pos);
                final ItemStack displayStack = BlockUtils.getItemStackFromBlockState(world.getBlockState(dataTE.getRealWorldPos(pos)));
                rowPane.findPaneOfTypeByID(LIST_BLOCK, ItemIcon.class).setItem(displayStack);
                final Text tagsText = rowPane.findPaneOfTypeByID(TAG_TEXT, Text.class);
                tagsText.setText(tags.toString());
            } else {
                close();
            }
        }
    });
}
Also used : IBlueprintDataProvider(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider) ArrayList(java.util.ArrayList) Pane(com.ldtteam.blockout.Pane) TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) ScrollingList(com.ldtteam.blockout.views.ScrollingList) ArrayList(java.util.ArrayList) List(java.util.List) ItemStack(net.minecraft.item.ItemStack) ScrollingList(com.ldtteam.blockout.views.ScrollingList)

Example 10 with IBlueprintDataProvider

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

the class BlueprintUtil method createBlueprint.

/**
 * Generates a Blueprint objects from the world
 *
 * @param world The World that is used for the Blueprint
 * @param pos   The Position of the Blueprint
 * @param sizeX The Size on the X-Axis
 * @param sizeY The Size on the Y-Axis
 * @param sizeZ The Size on the Z-Axis
 * @param name  a Name for the Structure
 * @return the generated Blueprint
 */
public static Blueprint createBlueprint(World world, BlockPos pos, final boolean saveEntities, short sizeX, short sizeY, short sizeZ, String name, Optional<BlockPos> anchorPos) {
    final List<BlockState> pallete = new ArrayList<>();
    // Allways add AIR to Pallete
    pallete.add(Blocks.AIR.defaultBlockState());
    final short[][][] structure = new short[sizeY][sizeZ][sizeX];
    final List<CompoundNBT> tileEntities = new ArrayList<>();
    final List<String> requiredMods = new ArrayList<>();
    for (final BlockPos mutablePos : BlockPos.betweenClosed(pos, pos.offset(sizeX - 1, sizeY - 1, sizeZ - 1))) {
        BlockState state = world.getBlockState(mutablePos);
        String modName = state.getBlock().getRegistryName().getNamespace();
        short x = (short) (mutablePos.getX() - pos.getX()), y = (short) (mutablePos.getY() - pos.getY()), z = (short) (mutablePos.getZ() - pos.getZ());
        if (!modName.equals("minecraft") && !modName.equals(MOD_ID)) {
            if (!ModList.get().getModContainerById(modName).isPresent()) {
                structure[y][z][x] = (short) pallete.indexOf(Blocks.AIR.defaultBlockState());
                continue;
            }
            if (!requiredMods.contains(modName)) {
                requiredMods.add(modName);
            }
        }
        final TileEntity te = world.getBlockEntity(mutablePos);
        if (te != null) {
            CompoundNBT teTag = te.serializeNBT();
            teTag.putShort("x", x);
            teTag.putShort("y", y);
            teTag.putShort("z", z);
            tileEntities.add(teTag);
        }
        if (!pallete.contains(state)) {
            pallete.add(state);
        }
        structure[y][z][x] = (short) pallete.indexOf(state);
    }
    final CompoundNBT[] tes = tileEntities.toArray(new CompoundNBT[0]);
    final List<CompoundNBT> entitiesTag = new ArrayList<>();
    List<Entity> entities = new ArrayList<>();
    if (saveEntities) {
        entities = world.getEntities(null, new AxisAlignedBB(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + sizeX, pos.getY() + sizeY, pos.getZ() + sizeZ));
    }
    for (final Entity entity : entities) {
        final Vector3d oldPos = entity.position();
        final CompoundNBT entityTag = entity.serializeNBT();
        if (!entityTag.contains("id"))
            continue;
        final ListNBT posList = new ListNBT();
        posList.add(DoubleNBT.valueOf(oldPos.x - pos.getX()));
        posList.add(DoubleNBT.valueOf(oldPos.y - pos.getY()));
        posList.add(DoubleNBT.valueOf(oldPos.z - pos.getZ()));
        BlockPos entityPos = entity.blockPosition();
        if (entity instanceof HangingEntity) {
            entityPos = ((HangingEntity) entity).getPos();
        }
        entityTag.put("Pos", posList);
        entityTag.put("TileX", IntNBT.valueOf(entityPos.getX() - pos.getX()));
        entityTag.put("TileY", IntNBT.valueOf(entityPos.getY() - pos.getY()));
        entityTag.put("TileZ", IntNBT.valueOf(entityPos.getZ() - pos.getZ()));
        entitiesTag.add(entityTag);
    }
    final Blueprint schem = new Blueprint(sizeX, sizeY, sizeZ, (short) pallete.size(), pallete, structure, tes, requiredMods);
    schem.setEntities(entitiesTag.toArray(new CompoundNBT[0]));
    if (anchorPos.isPresent()) {
        BlockPos relativeAnchorPos = new BlockPos(anchorPos.get().subtract(pos));
        schem.setCachePrimaryOffset(relativeAnchorPos);
    }
    // Blueprints do auto-calc anchors when missing, so if it uses a blueprint provider as anchor we fill in the schematic data afterwards to both TE and blueprint
    final TileEntity tile = world.getBlockEntity(pos.offset(schem.getPrimaryBlockOffset()));
    if (tile instanceof IBlueprintDataProvider) {
        final CompoundNBT blueprintData = (CompoundNBT) schem.getBlockInfoAsMap().get(schem.getPrimaryBlockOffset()).getTileEntityData().get(TAG_BLUEPRINTDATA);
        if (name != null) {
            final String fileName = new File(name).getName();
            blueprintData.putString(TAG_SCHEMATIC_NAME, fileName);
            ((IBlueprintDataProvider) tile).setSchematicName(fileName);
        }
        final BlockPos corner1 = BlockPos.ZERO.subtract(schem.getPrimaryBlockOffset());
        final BlockPos corner2 = new BlockPos(sizeX - 1, sizeY - 1, sizeZ - 1).subtract(schem.getPrimaryBlockOffset());
        ((IBlueprintDataProvider) tile).setSchematicCorners(corner1, corner2);
        BlockPosUtil.writeToNBT(blueprintData, TAG_CORNER_ONE, corner1);
        BlockPosUtil.writeToNBT(blueprintData, TAG_CORNER_TWO, corner2);
        if (!world.isClientSide) {
            ((ServerWorld) world).getChunkSource().blockChanged(pos);
        }
    }
    if (name != null) {
        schem.setName(name);
    }
    return schem;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) HangingEntity(net.minecraft.entity.item.HangingEntity) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) HangingEntity(net.minecraft.entity.item.HangingEntity) IBlueprintDataProvider(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider) TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState) Vector3d(net.minecraft.util.math.vector.Vector3d) BlockPos(net.minecraft.util.math.BlockPos) File(java.io.File)

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