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

Hello, I made a tower.schematic file with MC Edit so now i want to generate this in my world so first of all i created a BlockObject class wich represent a single block in the schematic

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 getPositonWithOffset(int x, int y, int z){

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

}

next i created a .schematic reader that makes a array of block objects:

 

private short width;
private short length;
private short heigth;
private int size;
private BlockObject[] blockObjects;

public Schematic(String name) {

	try{


		InputStream is = Schematic.class.getResourceAsStream("/assets/zaubermod/schematics/" + name);
		NBTTagCompound nbtdata = CompressedStreamTools.readCompressed(is);
		is.close();
		width = nbtdata.getShort("Width");
		length = nbtdata.getShort("Length");
		heigth = nbtdata.getShort("Heigth");

		size = width * length * heigth;

		blockObjects = new BlockObject[size];

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

		int counter = 0;

		for(int i = 0; i < heigth; 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.getPositonWithOffset(x, y, z), obj.getState());
	}
}

}

 

So now i create a object of the schematic class in the main class:

 

@Mod(modid = ZauberMod.MODID)
public class ZauberMod {

public static final String MODID = "zaubermod";


public static final Schematic TOWER_SCHEMATIC = new Schematic("tower.schematic");


@Instance
public ZauberMod instance;

@EventHandler
public void preInit(FMLPreInitializationEvent event){

}



@EventHandler
public void Init(FMLInitializationEvent event){


	GameRegistry.registerWorldGenerator(new SchematicGenereator(TOWER_SCHEMATIC), 0);
}


@EventHandler
public void postInit(FMLPostInitializationEvent event){


}

 

    at the end  i created a world generator that should create this structure every chunk:

 

public class SchematicGenereator implements IWorldGenerator{


private Schematic schematic;

public SchematicGenereator(Schematic schematic) {

	this.schematic = schematic;
}

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



		int x = chunkX * 16 + random.nextInt(16);
		int z = chunkZ * 16 + random.nextInt(16);
	    int y = getWorldHeightAt(world, x, z);
	    schematic.generate(world, x, y, z);




}


private static int getWorldHeightAt(World worldIn, int x, int z){
	int heigth = 0;
	for(int i = 0; i < 255; i++){
		if(worldIn.getBlockState(new BlockPos(x, i, z)).getBlock().isSolidFullCube()){
			heigth = i;

		}
	}

	return heigth;

}


}

 

 

now my problem: it just doesnt create i can fly every where in the world but the Structure doesnt create

 

thank you for your answers :-*

 

 

 

 

 

First off you misspelled "Height" in your schematic reader. Other than that I'm not in a position to answer, seeing as I don't know anything about worldgen, just thought I'd point that out as that might be related.

Who are you? Why have you brought me here? And why are there so many PewDiePie fanboys surrounding meeeeeeeee....... *falls into pit and dies*.

 

Also this. Check it out.

width=700 height=200http://i.imgur.com/J4rrGt6.png[/img]

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.