Jump to content

[1.8.9] NPE while reading Schematics


BusyBeever

Recommended Posts

Hello everyone,

I am triing to code my own Schematic creator. I already got a working Schematic reader that works like a charm.

The problem is that when I try to read my own schematics I get an NPE for the InflaterInputStream, and I have no idea why.

 

 

 

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: java.lang.NullPointerException

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at java.util.zip.InflaterInputStream.<init>(Unknown Source)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at java.util.zip.GZIPInputStream.<init>(Unknown Source)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at java.util.zip.GZIPInputStream.<init>(Unknown Source)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at net.minecraft.nbt.CompressedStreamTools.readCompressed(CompressedStreamTools.java:28)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at de.busybeever.extendedvillages.schematics.Schematic.<init>(Schematic.java:31)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at de.busybeever.extendedvillages.village.ServerVillage.<init>(ServerVillage.java:37)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at de.busybeever.extendedvillages.networking.PacketCreateVillage$Handler.onMessage(PacketCreateVillage.java:46)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at de.busybeever.extendedvillages.networking.PacketCreateVillage$Handler.onMessage(PacketCreateVillage.java:1)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at net.minecraftforge.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:37)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at net.minecraftforge.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:17)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:108)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:108)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at net.minecraftforge.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:90)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:158)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:54)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.handleServerSideCustomPacket(NetworkDispatcher.java:428)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:251)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:53)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.channel.local.LocalChannel.finishPeerRead(LocalChannel.java:326)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.channel.local.LocalChannel.access$400(LocalChannel.java:45)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.channel.local.LocalChannel$5.run(LocalChannel.java:312)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:380)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)

[14:43:22] [Netty Server IO #1/INFO] [sTDERR]: [de.busybeever.extendedvillages.schematics.Schematic:<init>:59]: at java.lang.Thread.run(Unknown Source)

[14:43:22] [Netty Server IO #1/ERROR] [FML]: SimpleChannelHandlerWrapper exception

 

 

 

Here is my code for creating the schematic

private boolean createSchematic(String path, BlockPos first, BlockPos second, World world) {
	try {
		int smallerY, smallerX, smallerZ;
		int biggerY, biggerX, biggerZ;

		if(first.getX()>second.getX()) {
			smallerX= second.getX();
			biggerX = first.getX();
		}
		else {
			smallerX = first.getX();
			biggerX = second.getX();
		}
		if(first.getY()>second.getY()) {
			smallerY= second.getY();
			biggerY = first.getY();
		}
		else {
			smallerY = first.getY();
			biggerY = second.getY();
		}
		if(first.getZ()>second.getZ()) {
			smallerZ= second.getZ();
			biggerZ = first.getZ();
		}
		else {
			smallerZ = first.getZ();
			biggerZ = second.getZ();
		}

		NBTTagCompound compound = new NBTTagCompound();
		int width = biggerX-smallerX+1;
		int height = biggerY-smallerY+1;
		int length = biggerZ-smallerZ+1;
		compound.setInteger("Width", width);
		compound.setInteger("Height", height);
		compound.setInteger("Length", length);



		byte[] blockIDS = new byte[width*height*length];
		byte[] metadata = new byte[width*height*length];

		int counter=0;



		for(int y=smallerY; y<=biggerY;y++) {
			for (int z = smallerZ; z <= biggerZ; z++) {
				for (int x = smallerX; x <= biggerX; x++) {
					IBlockState state = world.getBlockState(new BlockPos(x,y,z));
					blockIDS[counter] = (byte) Block.getIdFromBlock(state.getBlock());
					metadata[counter] = (byte) state.getBlock().getMetaFromState(state);
					counter++;
				}
			}
		}
		compound.setByteArray("Blocks", blockIDS);
		compound.setByteArray("Data", metadata);
		FileOutputStream fos = new FileOutputStream(path);
		CompressedStreamTools.writeCompressed(compound, fos);
		fos.close();

		return true;
	} catch (FileNotFoundException e) {
		e.printStackTrace();
		return false;
	} catch (IOException e) {
		e.printStackTrace();
		return false;
	}




}

 

And for creating the schematic

 

public Schematic(String name) { 
	try {
		InputStream is = Schematic.class.getResourceAsStream("/assets/extendedvillages/schematics/"+name+".schematic");
		NBTTagCompound compound = CompressedStreamTools.readCompressed(is);
		is.close();
		width = compound.getShort("Width"); //This is where it crashes
		height = compound.getShort("Height");
		length = compound.getShort("Length");
		blocks = new BlockInf[width*height*length];

		byte[] blockIDS = compound.getByteArray("Blocks");
		byte[] metadata = compound.getByteArray("Data");
		int counter=0;
		for (int y = 0; y < height; y++) {
			for (int z = 0; z < length; z++) {
				for (int x = 0; x < width; x++) {
					BlockPos pos = new BlockPos(x,y,z);
					IBlockState state = Block.getBlockById(blockIDS[counter]!=-92?blockIDS[counter] : 53).getStateFromMeta(metadata[counter]);

					counter++;
					blocks[counter] = new BlockInf(pos, state);
					System.out.println(blocks[counter]);

				}
			}

		}


	}
	catch(Exception e) {
		e.printStackTrace();
	}
}

Link to comment
Share on other sites

If getResourceAsStream is returning null, then you want to set a break point there and (if possible) step into the method using the debugger. Do a double check that the asset path you're trying to read is correct (including case, because "files" inside jars are case sensitive even on Windoze systems).

 

The logs will have more info than the console. Is there a log complaint about an asset not found?

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.