Search in sources :

Example 1 with InvalidInputDataException

use of buildcraft.api.core.InvalidInputDataException in project BuildCraft by BuildCraft.

the class TilePipeHolder method readFromNBT.

@Override
public void readFromNBT(NBTTagCompound nbt) {
    super.readFromNBT(nbt);
    if (nbt.hasKey("pipe")) {
        try {
            pipe = new Pipe(this, nbt.getCompoundTag("pipe"));
            eventBus.registerHandler(pipe.behaviour);
            eventBus.registerHandler(pipe.flow);
            if (pipe.flow instanceof IFlowItems) {
                eventBus.registerHandler(FilterEventHandler.class);
            }
        } catch (InvalidInputDataException e) {
            // Unfortunately we can't throw an exception because then this tile won't persist :/
            e.printStackTrace();
            unknownData = nbt.copy();
        }
    }
    NBTTagCompound plugs = nbt.getCompoundTag("plugs");
    for (EnumFacing face : EnumFacing.VALUES) {
        pluggables.get(face).readFromNbt(plugs.getCompoundTag(face.getName()));
    }
    wireManager.readFromNbt(nbt.getCompoundTag("wireManager"));
    if (nbt.hasKey("redstone")) {
        int[] temp = nbt.getIntArray("redstone");
        if (temp.length == 6) {
            redstoneValues = temp;
        }
    }
}
Also used : InvalidInputDataException(buildcraft.api.core.InvalidInputDataException) EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IItemPipe(buildcraft.api.transport.pipe.IItemPipe) IPipe(buildcraft.api.transport.pipe.IPipe) Pipe(buildcraft.transport.pipe.Pipe) IFlowItems(buildcraft.api.transport.pipe.IFlowItems)

Example 2 with InvalidInputDataException

use of buildcraft.api.core.InvalidInputDataException in project BuildCraft by BuildCraft.

the class ActionType method readFromBuffer.

@Override
public ActionWrapper readFromBuffer(PacketBufferBC buffer) throws IOException {
    if (buffer.readBoolean()) {
        String name = buffer.readString();
        EnumPipePart part = buffer.readEnumValue(EnumPipePart.class);
        IStatement statement = StatementManager.statements.get(name);
        if (statement instanceof IAction) {
            return ActionWrapper.wrap(statement, part.face);
        } else {
            throw new InvalidInputDataException("Unknown action '" + name + "'");
        }
    } else {
        return null;
    }
}
Also used : InvalidInputDataException(buildcraft.api.core.InvalidInputDataException) IAction(buildcraft.api.statements.IAction) EnumPipePart(buildcraft.api.core.EnumPipePart) IStatement(buildcraft.api.statements.IStatement)

Example 3 with InvalidInputDataException

use of buildcraft.api.core.InvalidInputDataException in project BuildCraft by BuildCraft.

the class TriggerType method readFromBuffer.

@Override
public TriggerWrapper readFromBuffer(PacketBufferBC buffer) throws IOException {
    if (buffer.readBoolean()) {
        String name = buffer.readString();
        EnumPipePart part = buffer.readEnumValue(EnumPipePart.class);
        IStatement statement = StatementManager.statements.get(name);
        if (statement instanceof ITrigger) {
            return TriggerWrapper.wrap(statement, part.face);
        } else {
            throw new InvalidInputDataException("Unknown trigger '" + name + "'");
        }
    } else {
        return null;
    }
}
Also used : InvalidInputDataException(buildcraft.api.core.InvalidInputDataException) EnumPipePart(buildcraft.api.core.EnumPipePart) IStatement(buildcraft.api.statements.IStatement) ITrigger(buildcraft.api.statements.ITrigger)

Example 4 with InvalidInputDataException

use of buildcraft.api.core.InvalidInputDataException in project BuildCraft by BuildCraft.

the class TileReplacer method update.

@Override
public void update() {
    if (world.isRemote) {
        return;
    }
    if (!invSnapshot.getStackInSlot(0).isEmpty() && !invSchematicFrom.getStackInSlot(0).isEmpty() && !invSchematicTo.getStackInSlot(0).isEmpty()) {
        Header header = BCBuildersItems.snapshot.getHeader(invSnapshot.getStackInSlot(0));
        if (header != null) {
            Snapshot snapshot = GlobalSavedDataSnapshots.get(world).getSnapshot(header.key);
            if (snapshot instanceof Blueprint) {
                Blueprint blueprint = (Blueprint) snapshot;
                try {
                    ISchematicBlock from = SchematicBlockManager.readFromNBT(NBTUtilBC.getItemData(invSchematicFrom.getStackInSlot(0)).getCompoundTag(ItemSchematicSingle.NBT_KEY));
                    ISchematicBlock to = SchematicBlockManager.readFromNBT(NBTUtilBC.getItemData(invSchematicTo.getStackInSlot(0)).getCompoundTag(ItemSchematicSingle.NBT_KEY));
                    Blueprint newBlueprint = blueprint.copy();
                    newBlueprint.replace(from, to);
                    newBlueprint.computeKey();
                    GlobalSavedDataSnapshots.get(world).addSnapshot(newBlueprint);
                    invSnapshot.setStackInSlot(0, BCBuildersItems.snapshot.getUsed(EnumSnapshotType.BLUEPRINT, new Header(blueprint.key, getOwner().getId(), new Date(), header.name)));
                    invSchematicFrom.setStackInSlot(0, ItemStack.EMPTY);
                    invSchematicTo.setStackInSlot(0, ItemStack.EMPTY);
                } catch (InvalidInputDataException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
Also used : ISchematicBlock(buildcraft.api.schematics.ISchematicBlock) ItemSnapshot(buildcraft.builders.item.ItemSnapshot) Snapshot(buildcraft.builders.snapshot.Snapshot) InvalidInputDataException(buildcraft.api.core.InvalidInputDataException) Header(buildcraft.builders.snapshot.Snapshot.Header) Blueprint(buildcraft.builders.snapshot.Blueprint) Date(java.util.Date)

Example 5 with InvalidInputDataException

use of buildcraft.api.core.InvalidInputDataException in project BuildCraft by BuildCraft.

the class SchematicBlockManager method readFromNBT.

@Nonnull
public static ISchematicBlock readFromNBT(NBTTagCompound schematicBlockTag) throws InvalidInputDataException {
    ResourceLocation name = new ResourceLocation(schematicBlockTag.getString("name"));
    SchematicBlockFactory<?> factory = SchematicBlockFactoryRegistry.getFactoryByName(name);
    if (factory == null) {
        throw new InvalidInputDataException("Unknown schematic type " + name);
    }
    ISchematicBlock schematicBlock = factory.supplier.get();
    NBTTagCompound data = schematicBlockTag.getCompoundTag("data");
    try {
        schematicBlock.deserializeNBT(data);
        return schematicBlock;
    } catch (InvalidInputDataException e) {
        throw new InvalidInputDataException("Failed to load the schematic from " + data, e);
    }
}
Also used : ISchematicBlock(buildcraft.api.schematics.ISchematicBlock) InvalidInputDataException(buildcraft.api.core.InvalidInputDataException) ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Nonnull(javax.annotation.Nonnull)

Aggregations

InvalidInputDataException (buildcraft.api.core.InvalidInputDataException)12 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 Nonnull (javax.annotation.Nonnull)4 ISchematicBlock (buildcraft.api.schematics.ISchematicBlock)3 EnumPipePart (buildcraft.api.core.EnumPipePart)2 IStatement (buildcraft.api.statements.IStatement)2 ItemStack (net.minecraft.item.ItemStack)2 EnumFacing (net.minecraft.util.EnumFacing)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 BCLog (buildcraft.api.core.BCLog)1 EnumSnapshotType (buildcraft.api.enums.EnumSnapshotType)1 ISchematicEntity (buildcraft.api.schematics.ISchematicEntity)1 SchematicBlockContext (buildcraft.api.schematics.SchematicBlockContext)1 IAction (buildcraft.api.statements.IAction)1 ITrigger (buildcraft.api.statements.ITrigger)1 IParamReaderBuf (buildcraft.api.statements.StatementManager.IParamReaderBuf)1 IFlowItems (buildcraft.api.transport.pipe.IFlowItems)1 IItemPipe (buildcraft.api.transport.pipe.IItemPipe)1 IPipe (buildcraft.api.transport.pipe.IPipe)1 PipeDefinition (buildcraft.api.transport.pipe.PipeDefinition)1