Search in sources :

Example 1 with MappingNotFoundException

use of buildcraft.api.blueprints.MappingNotFoundException 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 2 with MappingNotFoundException

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

the class Sequence method readFromNBT.

public void readFromNBT(NBTTagCompound nbt) {
    initialDate = nbt.getLong("initialDate");
    MappingRegistry registry = new MappingRegistry();
    registry.read(nbt.getCompoundTag("registry"));
    NBTTagList list = nbt.getTagList("actions", Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < list.tagCount(); ++i) {
        NBTTagCompound cpt = list.getCompoundTagAt(i);
        try {
            registry.scanAndTranslateStacksToWorld(cpt);
            SequenceAction action = (SequenceAction) strToClass.get(cpt.getString("class")).newInstance();
            action.world = world;
            action.readFromNBT(cpt);
            action.date = (action.date - initialDate) + world.getTotalWorldTime();
            actions.add(action);
        } catch (MappingNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) MappingNotFoundException(buildcraft.api.blueprints.MappingNotFoundException) MappingRegistry(buildcraft.api.blueprints.MappingRegistry) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 3 with MappingNotFoundException

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

the class SchematicPipe method idsToWorld.

@Override
public void idsToWorld(MappingRegistry registry) {
    super.idsToWorld(registry);
    if (tileNBT.hasKey("pipeId")) {
        try {
            Item item = registry.getItemForId(tileNBT.getInteger("pipeId"));
            tileNBT.setString("pipeId", Item.itemRegistry.getNameForObject(item).toString());
        } catch (MappingNotFoundException e) {
            tileNBT.removeTag("pipeId");
        }
    }
}
Also used : MappingNotFoundException(buildcraft.api.blueprints.MappingNotFoundException) Item(net.minecraft.item.Item)

Example 4 with MappingNotFoundException

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

the class Blueprint method loadSingleSchematicFromNBT.

private void loadSingleSchematicFromNBT(BlockPos pos, NBTTagCompound cpt) {
    if (cpt.hasKey("blockId")) {
        Block block;
        try {
            block = mapping.getBlockForId(cpt.getInteger("blockId"));
        } catch (MappingNotFoundException e) {
            block = null;
            isComplete = false;
        }
        if (block != null) {
            int meta = cpt.getInteger("blockMeta");
            SchematicBlockBase schematic = SchematicRegistry.INSTANCE.createSchematicBlock(block.getStateFromMeta(meta));
            if (schematic != null) {
                schematic.readSchematicFromNBT(cpt, mapping);
                if (!schematic.doNotUse()) {
                    schematic.idsToWorld(mapping);
                    switch(schematic.getBuildingPermission()) {
                        case ALL:
                            break;
                        case CREATIVE_ONLY:
                            if (buildingPermission == BuildingPermission.ALL) {
                                buildingPermission = BuildingPermission.CREATIVE_ONLY;
                            }
                            break;
                        case NONE:
                            buildingPermission = BuildingPermission.NONE;
                            break;
                    }
                } else {
                    schematic = null;
                    isComplete = false;
                }
            }
            set(pos, schematic);
        } else {
            set(pos, null);
            isComplete = false;
        }
    } else {
        set(pos, null);
    }
}
Also used : MappingNotFoundException(buildcraft.api.blueprints.MappingNotFoundException) SchematicBlockBase(buildcraft.api.blueprints.SchematicBlockBase) SchematicBlock(buildcraft.api.blueprints.SchematicBlock) Block(net.minecraft.block.Block)

Aggregations

MappingNotFoundException (buildcraft.api.blueprints.MappingNotFoundException)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 MappingRegistry (buildcraft.api.blueprints.MappingRegistry)1 SchematicBlock (buildcraft.api.blueprints.SchematicBlock)1 SchematicBlockBase (buildcraft.api.blueprints.SchematicBlockBase)1 SchematicEntity (buildcraft.api.blueprints.SchematicEntity)1 Block (net.minecraft.block.Block)1 Item (net.minecraft.item.Item)1 NBTBase (net.minecraft.nbt.NBTBase)1 BlockPos (net.minecraft.util.math.BlockPos)1