Pasting Schematics

I am currently trying to paste schematics at a players location. I’ve been having quite the difficulty. This is what I currently have

public void loadSchem(String schemName,Player player){

    ConfigurationNode node = MainClass.getInstance().getNode();

    File inputFile = new File(MainClass.getSchematicsDir(),schemName + ".schematic");
    if(!inputFile.exists()){
        Sponge.getServer().getBroadcastChannel().send(Text.of(TextColors.RED,"SCHEM", schemName , " NOT FOUND!"));
    }else{
        DataContainer schematicData = null;
        try {
            schematicData = DataFormats.NBT.readFrom(new GZIPInputStream(new FileInputStream(inputFile)));
        } catch (Exception e) {
            e.printStackTrace();
            Sponge.getServer().getBroadcastChannel().send(Text.of(TextColors.RED,"ERROR LOADING SCHEM FILE"));


        }

        Schematic schematic = DataTranslators.LEGACY_SCHEMATIC.translate(schematicData);
        schematic.apply(player.getLocation(), BlockChangeFlags.NONE);
    }

}

I end up getting this error in console when im trying to load it [18:52:05 ERROR] [Sponge]: Error occurred while executing command 'bp gen' for s - Pastebin.com Any ideas on what I’m doing wrong?
Thanks :slight_smile:

Whats the style of the schematic file? As in is it from worldedit on bukkit before 1.13? After 1.13? Is it from your own creation?

its a schematic from Forges version of world edit. I’ve tried using both Legacy schematic and just the regular Schematic DataTranslator if thats what you’re implying.
Here is the error when i use

try {
schematicData = DataFormats.NBT.readFrom(new GZIPInputStream(new FileInputStream(inputFile)));
} catch (Exception e) {
e.printStackTrace();
Sponge.getServer().getBroadcastChannel().send(Text.of(TextColors.RED,“ERROR LOADING SCHEM FILE”));
}

Schematic schematic = DataTranslators.SCHEMATIC.translate(schematicData);

over the Legacy data translator

EDIT: and now that I look at it, I am using the sponges FaWe version of world edit to save the schems in a 1.12.2 server which would make sense to use just the Legacy schematic DataTranlsator correct?

Sorry for the second edit within a couple minutes, I just want to try and answer as many questions possible so we can get to the root of the problem as fast as possible, when I save the schem in FaWe, I am not specifying a formart when I do it. Its just using the default saving no with no params. Just /schem save [schemName]

If it also helps to note that the schematic file extension is .schematic.
I have re created the schematic on a 1.12.2 Spigot server and saved the schematic with the appropriate version of world edit to ensure that I am indeed using the LEGACY version of the schematic and im still getting the errors above

All right. So I have done some edits with my code to try and figure out where the error is occurring. It is most defiantly occurring when trying to translate the schematic data. Here is my code

public void loadSchem(String schemName,Player player){

    File inputFile = new File(MainClass.getSchematicsDir(),schemName + ".schematic");
    if(!inputFile.exists()){
        Sponge.getServer().getBroadcastChannel().send(Text.of(TextColors.RED,"SCHEM", schemName , " NOT FOUND!"));
    }else{
        DataContainer schematicData = null;
        try {
            schematicData = DataFormats.NBT.readFrom(new GZIPInputStream(new FileInputStream(inputFile)));
        } catch (Exception e) {
            e.printStackTrace();
            Sponge.getServer().getBroadcastChannel().send(Text.of(TextColors.RED,"ERROR LOADING SCHEM FILE"));
        }

        if(schematicData != null){

            player.sendMessage(Text.of("attempting data translating"));

            Schematic schematic = DataTranslators.LEGACY_SCHEMATIC.translate(schematicData);

            player.sendMessage(Text.of("Data tranlated"));

            schematic.apply(player.getLocation(), BlockChangeFlags.NONE);
            player.sendMessage(Text.of("Data pasted"));

        }else{
            player.sendMessage(Text.of("Schem data is null"));
        }


    }

}

I get the message “attempting data translating” which then leads to the error with no other of the checks firing. so which means it must have something to do with the translation of the data correct?

java.lang.ClassCastException: net.minecraft.block.BlockAir cannot be cast to org.spongepowered.api.block.BlockState
        at org.spongepowered.common.data.persistence.LegacySchematicTranslator.translate(LegacySchematicTranslator.java:132) ~[LegacySchematicTranslator.class:1.12.2-7.1.5]

That would be a Sponge bug. I’ll fix it.

I just uploaded a fix. It should be available in a few minutes as SpongeForge 3717 or SpongeVanilla 182.

Seems to still be getting the error on the latest version of spongeforge-1.12.2-2825-7.1.6-RC3718. Not sure about vanilla as I have not test that.

[22:03:45 ERROR] [Sponge]: Error occurred while executing command 'bp gen' for source EntityPlayerMP['itsTyxD'/347, l='world', x=-11.10, y=105.77, z=264.07]: net.minecraft.block.BlockAir cannot be cast to org.spongepowered.api.block.BlockState
java.lang.ClassCastException: net.minecraft.block.BlockAir cannot be cast to org.spongepowered.api.block.BlockState
        at org.spongepowered.common.data.persistence.LegacySchematicTranslator.translate(LegacySchematicTranslator.java:132) ~[LegacySchematicTranslator.class:1.12.2-7.1.5]
        at org.spongepowered.common.data.persistence.LegacySchematicTranslator.translate(LegacySchematicTranslator.java:60) ~[LegacySchematicTranslator.class:1.12.2-7.1.5]
        at Commands.Generate.loadSchem(Generate.java:59) ~[Generate.class:?]
        at Commands.Generate.execute(Generate.java:38) ~[Generate.class:?]
        at org.spongepowered.api.command.args.ChildCommandElementExecutor.execute(ChildCommandElementExecutor.java:255) ~[ChildCommandElementExecutor.class:1.12.2-7.1.5]
        at org.spongepowered.api.command.spec.CommandSpec.process(CommandSpec.java:388) ~[CommandSpec.class:1.12.2-7.1.5]
        at org.spongepowered.api.command.dispatcher.SimpleDispatcher.process(SimpleDispatcher.java:340) ~[SimpleDispatcher.class:1.12.2-7.1.5]
        at org.spongepowered.common.command.SpongeCommandManager.process(SpongeCommandManager.java:334) ~[SpongeCommandManager.class:1.12.2-7.1.5]
        at net.minecraft.command.ServerCommandManager.func_71556_a(SourceFile:1083) ~[dh.class:?]
        at net.minecraft.network.NetHandlerPlayServer.func_147361_d(SourceFile:855) ~[pa.class:?]
        at net.minecraft.network.NetHandlerPlayServer.func_147354_a(SourceFile:842) ~[pa.class:?]
        at net.minecraft.network.play.client.CPacketChatMessage.func_148833_a(SourceFile:37) ~[la.class:?]
        at net.minecraft.network.play.client.CPacketChatMessage.func_148833_a(SourceFile:9) ~[la.class:?]
        at org.spongepowered.common.event.tracking.phase.packet.PacketPhaseUtil.onProcessPacket(PacketPhaseUtil.java:193) ~[PacketPhaseUtil.class:1.12.2-7.1.5]
        at net.minecraft.network.PacketThreadUtil$1.redirect$onProcessPacket$zle000(SourceFile:539) ~[hv$1.class:?]
        at net.minecraft.network.PacketThreadUtil$1.run(SourceFile:13) ~[hv$1.class:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_201]
        at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_201]
        at net.minecraft.util.Util.func_181617_a(SourceFile:46) ~[h.class:?]
        at org.spongepowered.common.SpongeImplHooks.onUtilRunTask(SpongeImplHooks.java:297) ~[SpongeImplHooks.class:1.12.2-7.1.5]
        at net.minecraft.server.MinecraftServer.redirect$onRun$zji000(SourceFile:4123) ~[MinecraftServer.class:?]
        at net.minecraft.server.MinecraftServer.func_71190_q(SourceFile:1581) ~[MinecraftServer.class:?]
        at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(SourceFile:349) ~[nz.class:?]
        at net.minecraft.server.MinecraftServer.func_71217_p(SourceFile:560) ~[MinecraftServer.class:?]
        at net.minecraft.server.MinecraftServer.run(SourceFile:464) ~[MinecraftServer.class:?]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_201]

Here is my function once again.

private void loadSchem(String schemName){

        File inputFile = new File(MainClass.getSchematicsDir(),schemName + ".schematic");
        if(!inputFile.exists()){
            Sponge.getServer().getBroadcastChannel().send(Text.of(TextColors.RED,"SCHEM", schemName , " NOT FOUND!"));
        }else{
            DataContainer schematicData = null;
            try {
                schematicData = DataFormats.NBT.readFrom(new GZIPInputStream(new FileInputStream(inputFile)));
            } catch (Exception e) {
                e.printStackTrace();
                Sponge.getServer().getBroadcastChannel().send(Text.of(TextColors.RED,"ERROR LOADING SCHEM FILE"));
            }

            if(schematicData != null){
                Schematic schematic = DataTranslators.LEGACY_SCHEMATIC.translate(schematicData);
                schematic.apply(player.getLocation(), BlockChangeFlags.NONE);

            }else{
                player.sendMessage(Text.of("Schem data is null"));
            }
        }
    }

Never mind. Regard that last reply. The Translator works now. I was just dumb and forgot to replace the jar files LOL.

although, concrete does not get placed once I apply a schematic. Everything but the concrete will show up. I made a post about it under the sponge support section.