Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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!

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.

  • Author

By "Cobblestone Wall" I actually meant the block.. minecraft:cobblestone_wall

 

 

  • Author

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());

}

 

}

 

 

  • Author

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

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.