Search in sources :

Example 1 with SchematicEntity

use of buildcraft.api.blueprints.SchematicEntity in project BuildCraft by BuildCraft.

the class Blueprint method saveContents.

@Override
public void saveContents(NBTTagCompound nbt) {
    NBTTagCompound nbtContents = new NBTTagCompound();
    for (BlockPos pos : BlockPos.getAllInBox(BlockPos.ORIGIN, size.subtract(Utils.POS_ONE))) {
        SchematicBlockBase schematic = null;
        NBTTagCompound cpt = new NBTTagCompound();
        try {
            schematic = get(pos);
            if (schematic != null) {
                schematic.idsToBlueprint(mapping);
                schematic.writeSchematicToNBT(cpt, mapping);
                /* We don't use the index of the current for loop because we shouldn't rely on the behaviour of
                     * BlockPos.getAllInBox */
                nbtContents.setTag(StringUtilBC.blockPosToShortString(pos), cpt);
            }
        } catch (Throwable t) {
            CrashReport crash;
            if (t instanceof ReportedException) {
                crash = ((ReportedException) t).getCrashReport();
            } else {
                crash = new CrashReport("Failed to save the contents of a blueprint!", t);
            }
            CrashReportCategory cat = crash.makeCategory("Block Being Saved");
            cat.addCrashSection("Block Position (In schematic)", pos);
            cat.addCrashSection("Schematic type", schematic == null ? "~~NULL~~" : schematic.getClass());
            mapping.addToCrashReport(crash.makeCategory("Mapping Registry"));
            throw new ReportedException(crash);
        }
    }
    nbt.setTag("contents", nbtContents);
    NBTTagList entitiesNBT = new NBTTagList();
    for (SchematicEntity s : entities) {
        NBTTagCompound subNBT = new NBTTagCompound();
        s.idsToBlueprint(mapping);
        s.writeSchematicToNBT(subNBT, mapping);
        entitiesNBT.appendTag(subNBT);
    }
    nbt.setTag("entities", entitiesNBT);
    NBTTagCompound contextNBT = new NBTTagCompound();
    mapping.write(contextNBT);
    nbt.setTag("idMapping", contextNBT);
}
Also used : SchematicBlockBase(buildcraft.api.blueprints.SchematicBlockBase) NBTTagList(net.minecraft.nbt.NBTTagList) CrashReport(net.minecraft.crash.CrashReport) SchematicEntity(buildcraft.api.blueprints.SchematicEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockPos(net.minecraft.util.math.BlockPos) CrashReportCategory(net.minecraft.crash.CrashReportCategory) ReportedException(net.minecraft.util.ReportedException)

Example 2 with SchematicEntity

use of buildcraft.api.blueprints.SchematicEntity in project BuildCraft by BuildCraft.

the class Blueprint method readEntitiesFromWorld.

@Override
public void readEntitiesFromWorld(IBuilderContext context, TileEntity anchorTile) {
    BptContext bptContext = (BptContext) context;
    // Should this be used somewhere?
    Vec3d transform = new Vec3d(0, 0, 0).subtract(Utils.convert(context.surroundingBox().min()));
    for (Object o : context.world().loadedEntityList) {
        Entity e = (Entity) o;
        if (context.surroundingBox().contains(new Vec3d(e.posX, e.posY, e.posZ))) {
            SchematicEntity s = SchematicRegistry.INSTANCE.createSchematicEntity(e.getClass());
            if (s != null) {
                s.readFromWorld(context, e);
                switch(s.getBuildingPermission()) {
                    case ALL:
                        entities.add(s);
                        break;
                    case CREATIVE_ONLY:
                        if (bptContext.readConfiguration.allowCreative) {
                            if (buildingPermission == BuildingPermission.ALL) {
                                buildingPermission = BuildingPermission.CREATIVE_ONLY;
                            }
                            entities.add(s);
                        }
                        break;
                    case NONE:
                        buildingPermission = BuildingPermission.NONE;
                        break;
                }
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) SchematicEntity(buildcraft.api.blueprints.SchematicEntity) SchematicEntity(buildcraft.api.blueprints.SchematicEntity) Vec3d(net.minecraft.util.math.Vec3d)

Example 3 with SchematicEntity

use of buildcraft.api.blueprints.SchematicEntity in project BuildCraft by BuildCraft.

the class Blueprint method loadContents.

@Override
public void loadContents(NBTTagCompound nbt) throws BptError {
    mapping.read(nbt.getCompoundTag("idMapping"));
    NBTBase base = nbt.getTag("contents");
    if (base instanceof NBTTagCompound) {
        NBTTagCompound contents = (NBTTagCompound) base;
        for (BlockPos pos : BlockPos.getAllInBox(BlockPos.ORIGIN, size.subtract(Utils.POS_ONE))) {
            NBTTagCompound single = contents.getCompoundTag(StringUtilBC.blockPosToShortString(pos));
            loadSingleSchematicFromNBT(pos, single);
        }
    } else {
        // 1.7.10 back-compat
        NBTTagList nbtContents = nbt.getTagList("contents", Constants.NBT.TAG_COMPOUND);
        int index = 0;
        for (int x = 0; x < size.getX(); ++x) {
            for (int y = 0; y < size.getY(); ++y) {
                for (int z = 0; z < size.getZ(); ++z) {
                    NBTTagCompound cpt = nbtContents.getCompoundTagAt(index);
                    loadSingleSchematicFromNBT(new BlockPos(x, y, z), cpt);
                    index++;
                }
            }
        }
    }
    NBTTagList entitiesNBT = nbt.getTagList("entities", Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < entitiesNBT.tagCount(); ++i) {
        NBTTagCompound cpt = entitiesNBT.getCompoundTagAt(i);
        if (cpt.hasKey("entityId")) {
            Class<? extends Entity> entity;
            try {
                entity = mapping.getEntityForId(cpt.getInteger("entityId"));
            } catch (MappingNotFoundException e) {
                entity = null;
                isComplete = false;
            }
            if (entity != null) {
                SchematicEntity s = SchematicRegistry.INSTANCE.createSchematicEntity(entity);
                s.readSchematicFromNBT(cpt, mapping);
                s.idsToWorld(mapping);
                entities.add(s);
            } else {
                isComplete = false;
            }
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) MappingNotFoundException(buildcraft.api.blueprints.MappingNotFoundException) NBTBase(net.minecraft.nbt.NBTBase) SchematicEntity(buildcraft.api.blueprints.SchematicEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with SchematicEntity

use of buildcraft.api.blueprints.SchematicEntity in project BuildCraft by BuildCraft.

the class SchematicFactoryEntity method loadSchematicFromWorldNBT.

@Override
protected SchematicEntity loadSchematicFromWorldNBT(NBTTagCompound nbt, MappingRegistry registry) throws MappingNotFoundException {
    int entityId = nbt.getInteger("entityId");
    SchematicEntity s = SchematicRegistry.INSTANCE.createSchematicEntity(registry.getEntityForId(entityId));
    if (s != null) {
        s.readSchematicFromNBT(nbt, registry);
    } else {
        return null;
    }
    return s;
}
Also used : SchematicEntity(buildcraft.api.blueprints.SchematicEntity)

Example 5 with SchematicEntity

use of buildcraft.api.blueprints.SchematicEntity in project BuildCraft by BuildCraft.

the class BptBuilderBlueprint method internalInit.

@Override
protected void internalInit() {
    BlockPos worldOffset = pos.subtract(blueprint.anchor);
    BlockPos bptMin = BlockPos.ORIGIN;
    if (worldOffset.getY() < 0)
        bptMin = VecUtil.replaceValue(bptMin, Axis.Y, -worldOffset.getY());
    BlockPos bptMax = blueprint.size.subtract(Utils.POS_ONE);
    if (worldOffset.add(bptMax).getY() > context.world().getHeight()) {
        bptMax = VecUtil.replaceValue(bptMax, Axis.Y, context.world().getHeight() - worldOffset.getY());
    }
    /* Check to make sure the max is bigger than the min- if its not it means that the size was 0 for one of the
         * axis */
    if (Utils.min(bptMin, bptMax).equals(bptMin) && Utils.max(bptMin, bptMax).equals(bptMax)) {
        try {
            for (BlockPos bptOffset : Utils.getAllInBox(bptMin, bptMax, getOrder())) {
                BlockPos pointWorldOffset = worldOffset.add(bptOffset);
                if (!isLocationUsed(pointWorldOffset)) {
                    SchematicBlock slot = (SchematicBlock) blueprint.get(bptOffset);
                    if (slot == null && !blueprint.excavate) {
                        continue;
                    }
                    if (slot == null) {
                        slot = new SchematicBlock();
                        slot.state = Blocks.AIR.getDefaultState();
                    }
                    if (!SchematicRegistry.INSTANCE.isAllowedForBuilding(slot.state)) {
                        continue;
                    }
                    BuildingSlotBlock b = new BuildingSlotBlock();
                    b.schematic = slot;
                    b.pos = pointWorldOffset;
                    b.mode = Mode.ClearIfInvalid;
                    b.buildStage = 0;
                    addToBuildList(b);
                }
            }
        } catch (ArrayIndexOutOfBoundsException aioobe) {
            BCLog.logger.warn("Attempted to use the positions " + bptMin + ", " + bptMax + " to access a blueprint with a size of " + blueprint.size);
            throw BCLog.logger.throwing(aioobe);
        }
        LinkedList<BuildingSlotBlock> tmpStandalone = new LinkedList<>();
        LinkedList<BuildingSlotBlock> tmpExpanding = new LinkedList<>();
        for (BlockPos bptOffset : Utils.getAllInBox(bptMin, bptMax, getOrder())) {
            BlockPos pointWorldOffset = worldOffset.add(bptOffset);
            SchematicBlock slot = (SchematicBlock) blueprint.get(bptOffset);
            if (slot == null) {
                continue;
            }
            if (!SchematicRegistry.INSTANCE.isAllowedForBuilding(slot.state)) {
                continue;
            }
            BuildingSlotBlock b = new BuildingSlotBlock();
            b.schematic = slot;
            b.pos = pointWorldOffset;
            b.mode = Mode.Build;
            if (!isLocationUsed(pointWorldOffset)) {
                switch(slot.getBuildStage()) {
                    case STANDALONE:
                        tmpStandalone.add(b);
                        b.buildStage = 1;
                        break;
                    case EXPANDING:
                        tmpExpanding.add(b);
                        b.buildStage = 2;
                        break;
                }
            } else {
                postProcessing.add(b);
            }
        }
        for (BuildingSlotBlock b : tmpStandalone) {
            addToBuildList(b);
        }
        for (BuildingSlotBlock b : tmpExpanding) {
            addToBuildList(b);
        }
    }
    int seqId = 0;
    for (SchematicEntity e : ((Blueprint) blueprint).entities) {
        BuildingSlotEntity b = new BuildingSlotEntity();
        b.schematic = e;
        b.sequenceNumber = seqId;
        if (!builtEntities.contains(seqId)) {
            entityList.add(b);
        } else {
            postProcessing.add(b);
        }
        seqId++;
    }
    recomputeNeededItems();
}
Also used : BuildingSlotBlock(buildcraft.core.builders.BuildingSlotBlock) SchematicEntity(buildcraft.api.blueprints.SchematicEntity) BuildingSlotEntity(buildcraft.core.builders.BuildingSlotEntity) SchematicBlock(buildcraft.api.blueprints.SchematicBlock) BlockPos(net.minecraft.util.math.BlockPos) LinkedList(java.util.LinkedList)

Aggregations

SchematicEntity (buildcraft.api.blueprints.SchematicEntity)6 BlockPos (net.minecraft.util.math.BlockPos)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 MappingNotFoundException (buildcraft.api.blueprints.MappingNotFoundException)1 SchematicBlock (buildcraft.api.blueprints.SchematicBlock)1 SchematicBlockBase (buildcraft.api.blueprints.SchematicBlockBase)1 BuildingSlotBlock (buildcraft.core.builders.BuildingSlotBlock)1 BuildingSlotEntity (buildcraft.core.builders.BuildingSlotEntity)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 LinkedList (java.util.LinkedList)1 CrashReport (net.minecraft.crash.CrashReport)1 CrashReportCategory (net.minecraft.crash.CrashReportCategory)1 Entity (net.minecraft.entity.Entity)1 NBTBase (net.minecraft.nbt.NBTBase)1 TileEntity (net.minecraft.tileentity.TileEntity)1 ReportedException (net.minecraft.util.ReportedException)1 Vec3d (net.minecraft.util.math.Vec3d)1