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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello, Hi and I am making a forge 1.12.2 mod and also trying to get a custom model helmet item (I made a joker mask) and exported it to .json format and put it in the ~/namespace/models/item folder. Though, I'm struggling to get the item to render what I want it to be rendered like as I've positioned it in the 'head' window view in blockbench. How did you render out your model? I checked your code and it looks like no references to the actual model are being made. I'm new to this forge modding stuff (was a fabric modder) and I desperately need some help. Is there a way to standardly render out armor models made using blockbench? any methods that one can use? My model in JSON: ```json { "credit": "Made with Blockbench", "texture_size": [160, 160], "textures": { "0": "ydyrn:items/joker_mask_texture", "particle": "ydyrn:items/joker_mask_texture" }, "elements": [ { "from": [0, 0, 0], "to": [16, 16, 1], "faces": { "north": {"uv": [0, 1.7, 16, 14.2], "texture": "#0"}, "east": {"uv": [0, 4, 0.9, 5.6], "texture": "#0"}, "south": {"uv": [0, 5.8, 1.6, 7.4], "texture": "#0"}, "west": {"uv": [0, 1.9, 1.3, 3.5], "texture": "#0"}, "up": {"uv": [0, 3.4, 1.6, 4.2], "texture": "#0"}, "down": {"uv": [0, 9, 1.6, 9.7], "texture": "#0"} } }, { "from": [15.8, 11, 0.5], "to": [16.2, 13, 15], "faces": { "north": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "east": {"uv": [7.9, 7.9, 9.35, 8.1], "texture": "#0"}, "south": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "west": {"uv": [7.9, 7.9, 9.35, 8.1], "texture": "#0"}, "up": {"uv": [7.9, 7.9, 7.94, 9.35], "texture": "#0"}, "down": {"uv": [7.9, 7.9, 7.94, 9.35], "texture": "#0"} } }, { "from": [0.2, 11, 14.6], "to": [15.8, 13, 15], "faces": { "north": {"uv": [7.9, 7.9, 9.46, 8.1], "texture": "#0"}, "east": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "south": {"uv": [7.9, 7.9, 9.46, 8.1], "texture": "#0"}, "west": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "up": {"uv": [7.9, 7.9, 9.46, 7.94], "texture": "#0"}, "down": {"uv": [7.9, 7.9, 9.46, 7.94], "texture": "#0"} } }, { "from": [-0.2, 11, 0.5], "to": [0.2, 13, 15], "faces": { "north": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "east": {"uv": [7.9, 7.9, 9.35, 8.1], "texture": "#0"}, "south": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "west": {"uv": [7.9, 7.9, 9.35, 8.1], "texture": "#0"}, "up": {"uv": [7.9, 7.9, 7.94, 9.35], "texture": "#0"}, "down": {"uv": [7.9, 7.9, 7.94, 9.35], "texture": "#0"} } } ], "display": { "thirdperson_righthand": { "translation": [-0.25, -2.75, 0], "scale": [0.3, 0.3, 0.3] }, "thirdperson_lefthand": { "translation": [-0.25, -2.75, 0], "scale": [0.3, 0.3, 0.3] }, "firstperson_righthand": { "rotation": [-9, 115, 15], "translation": [0, 1.25, -1.75], "scale": [0.5, 0.5, 0.5] }, "firstperson_lefthand": { "rotation": [-9, 115, 15], "translation": [0, 1.25, -1.75], "scale": [0.5, 0.5, 0.5] }, "ground": { "rotation": [40, 0, 0], "translation": [0, -2.5, 0], "scale": [0.5, 0.5, 0.5] }, "gui": { "rotation": [0, 180, 0] }, "head": { "translation": [0, 0, 0.25], "scale": [0.82773, 0.73594, 0.9] }, "fixed": { "translation": [0, 0, 8.75] } }, "groups": [ 0, { "name": "straps", "origin": [0, 0, 0], "color": 0, "children": [1, 2, 3] } ] } ```
    • Add the crash-report or latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
    • In your config folder, delete the sophisticatedcore-common.toml file and test it again
    • Add the crash-report or latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
    • I am getting an error message that my mods and my server are not on the same minecraft version when they clearly are. My server and my mods are on 1.20.1 and the error says that the server is 1.20 even though it's on forge 47.2.30.  
  • Topics

×
×
  • Create New...

Important Information

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