Jump to content

[SOLVED] [1.8] (Schematic reader, id too high for byte)


DaryBob

Recommended Posts

So I made a schematic reader that reads schematics..

It works, everything generates, but the only things

that doesn't generate are the walls..

 

I think the IDs are to high for the bytes or something..

Does someone have a solution for this?

 

Schematic

 

 

package netcrafter.mods.aoto.util;

 

import java.io.FileInputStream;

import java.io.InputStream;

 

import net.minecraft.block.Block;

import net.minecraft.block.state.IBlockState;

import net.minecraft.init.Blocks;

import net.minecraft.nbt.CompressedStreamTools;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.util.BlockPos;

import net.minecraft.world.World;

 

public class Schematic {

 

private short width;

private short height;

private short length;

private int size;

private BlockObject[] blockObjects;

 

public Schematic(String fileName) {

try {

InputStream is = Schematic.class.getResourceAsStream("/assets/aoto/schematics/" + fileName);

NBTTagCompound nbtdata = CompressedStreamTools.readCompressed(is);

 

is.close();

 

width = nbtdata.getShort("Width");

height = nbtdata.getShort("Height");

length = nbtdata.getShort("Length");

size = width * height * length;

blockObjects = new BlockObject;

 

byte[] blockIDs = nbtdata.getByteArray("Blocks");

byte[] metadata = nbtdata.getByteArray("Data");

 

int counter = 0;

for(int i = 0; i < height; i++) {

for(int j = 0; j < length; j++) {

for(int k = 0; k < width; k++) {

BlockPos pos = new BlockPos(k, i, j);

IBlockState state = Block.getBlockById(blockIDs[counter]).getStateFromMeta(metadata[counter]);

blockObjects[counter] = new BlockObject(pos, state);

counter++;

}

}

}

 

} catch(Exception e) {

e.printStackTrace();

}

}

 

public void generate(World world, int x, int y, int z) {

for(BlockObject obj : blockObjects) {

world.setBlockState(obj.getPosWithOffset(x, y, z), obj.getState());

}

}

 

}

 

 

 

ForestGen

 

 

package netcrafter.mods.aoto.world.gen.feature;

 

import java.util.Random;

 

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.init.Blocks;

import net.minecraft.util.BlockPos;

import net.minecraft.world.World;

import net.minecraft.world.biome.BiomeGenBase;

import net.minecraft.world.chunk.IChunkProvider;

import net.minecraftforge.fml.common.IWorldGenerator;

import netcrafter.mods.aoto.util.Schematic;

 

public class ForestGen implements IWorldGenerator {

 

private Schematic schematic;

 

public ForestGen(Schematic schematic) {

this.schematic = schematic;

}

 

@Override

public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {

 

if(random.nextInt(100) == 0) {

int x = chunkX * 16 + random.nextInt(16);

int z = chunkZ * 16 + random.nextInt(16);

int y = getWorldHeightAt(world, x, z);

if(world.getBiomeGenForCoords(new BlockPos(x, y, z)) == BiomeGenBase.forest) {

schematic.generate(world, x, y, z);

}

}

}

 

private static int getWorldHeightAt(World world, int x, int z) {

int height = 0;

for(int i = 0; i < 255; i++) {

if(world.getBlockState(new BlockPos(x, i, z)).getBlock().isSolidFullCube()) {

height = i;

}

}

return height;

}

 

}

 

 

 

 

Registry stuff:

public static final Schematic FOREST_DUNGEON = new Schematic("ForestDungeon.schematic");

GameRegistry.registerWorldGenerator(new ForestGen(Main.FOREST_DUNGEON), 0);

 

Thanks for your support!

Link to comment
Share on other sites

everything generates, but the only things

that doesn't generate are the walls..

 

It works, but it doesn't.

 

1. While I am looking deeper - Ids can't be saved in byte[]. Ids expand much further.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Oh yeah, forget to mention the block object class I made.

 

BlockObject

 

 

package netcrafter.mods.aoto.util;

 

import net.minecraft.block.state.IBlockState;

import net.minecraft.util.BlockPos;

 

public class BlockObject {

 

private BlockPos pos;

private IBlockState state;

 

public BlockObject(BlockPos pos, IBlockState state) {

this.pos = pos;

this.state = state;

}

 

public BlockPos getPos() {

return pos;

}

 

public IBlockState getState() {

return state;

}

 

public BlockPos getPosWithOffset(int x, int y, int z) {

return new BlockPos(x + pos.getX(), y + pos.getY(), z + pos.getZ());

}

 

}

 

 

Link to comment
Share on other sites

solved it..

 

int counter = 0;

for(int i = 0; i < height; i++) {

for(int j = 0; j < length; j++) {

for(int k = 0; k < width; k++) {

    int blockId = UnsignedBytes.toInt(blockIDs[counter]);

BlockPos pos = new BlockPos(k, i, j);

IBlockState state = Block.getBlockById(blockId).getStateFromMeta(metadata[counter]);

blockObjects[counter] = new BlockObject(pos, state);

counter++;

}

}

}

 

made an int blockId that returns blockIDs[counter].

Now it can generate blocks with higher ids.

 

Thanks to Resinresin for sharing he's code (just

took the part with the blockId and updated it

so it can run on forge 1.8).

http://www.minecraftforge.net/forum/index.php?topic=30800.0

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.