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

The title is a bit irritating. To better explain: I have created a structure which contains a chest to generate in my biome and most of it works, but I have trouble getting the loot to stay in the chest. I have added a few items to it, they are being generated in the chest as wanted, but the problem is that they multiply around of it. I noticed this happens to the torches, too, as you can see in the picture. First, I tried it by simply adding the item stacks to the tile entity's inventory, now I tried it with the WeightedRandomChestContent function used in WorldGenDungeons, same result.

A screenshot:

 

EpVkhNL.png

 

My code for the structure:

package com.nignog.mymod.world.gen.structure;

import java.util.Random;

import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.WeightedRandomChestContent;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;

import com.nignog.mymod.MainClass;

public class WorldGenCustomStructure extends WorldGenerator {
public static final WeightedRandomChestContent[] snipersChestContent = new WeightedRandomChestContent[] {
		new WeightedRandomChestContent(MainClass.jarate, 0, 5, 10, 10),
		new WeightedRandomChestContent(Items.bow, 150, 1, 1, 10),
		new WeightedRandomChestContent(Items.arrow, 0, 10, 15, 15),
		new WeightedRandomChestContent(MainClass.flyingStaff, 0, 1, 1, 4),
		new WeightedRandomChestContent(MainClass.australiumIngot, 0, 1, 5, 12),
		new WeightedRandomChestContent(new ItemStack(
				MainClass.hardenedObsidian), 2, 4, 15) };

public boolean generate(World world, Random rand, int x, int y, int z) {
	if (world.getBlock(x, y, z) != MainClass.australiumDust
			|| world.getBlock(x, y + 1, z) != Blocks.air
			|| world.getBlock(x + 5, y, z) != MainClass.australiumDust
			|| world.getBlock(x + 5, y, z + 6) != MainClass.australiumDust
			|| world.getBlock(x, y, z + 6) != MainClass.australiumDust
			|| world.getBlock(x + 5, y + 1, z) != Blocks.air
			|| world.getBlock(x + 5, y + 1, z + 6) != Blocks.air
			|| world.getBlock(x, y + 1, z + 6) != Blocks.air) {
		return false;
	}
	for (int x1 = 0; x1 < 5; x1++) {
		for (int y1 = 0; y1 < 5; y1++) {
			for (int z1 = 0; z1 < 6; z1++) {
				if ((x1 >= 1 && x1 <= 4) && (y1 >= 1 && y1 <= 4)
						&& (z1 >= 1 && z1 <= 5)) {
					continue;
				}

				world.setBlock(x, y + y1 + 1, z, Blocks.planks);

				world.setBlock(x + x1, y + 1, z, Blocks.planks);
				world.setBlock(x + x1, y + 2, z, Blocks.planks);
				world.setBlock(x + x1, y + 3, z, Blocks.planks);
				world.setBlock(x + x1, y + 4, z, Blocks.planks);
				world.setBlock(x + x1, y + 5, z, Blocks.planks);

				world.setBlock(x, y + 1, z + z1, Blocks.planks);
				world.setBlock(x, y + 2, z + z1, Blocks.planks);
				world.setBlock(x, y + 3, z + z1, Blocks.planks);
				world.setBlock(x, y + 4, z + z1, Blocks.planks);
				world.setBlock(x, y + 5, z + z1, Blocks.planks);

				world.setBlock(x + 4, y + y1 + 1, z, Blocks.planks);
				world.setBlock(x + 4, y + y1 + 1, z + 1, Blocks.planks);
				world.setBlock(x + 4, y + y1 + 1, z + 2, Blocks.planks);
				world.setBlock(x + 4, y + y1 + 1, z + 3, Blocks.planks);
				world.setBlock(x + 4, y + y1 + 1, z + 4, Blocks.planks);

				world.setBlock(x + 4, y + y1 + 1, z + 5, Blocks.planks);
				world.setBlock(x + 3, y + y1 + 1, z + 5, Blocks.planks);
				world.setBlock(x + 1, y + y1 + 1, z + 5, Blocks.planks);

				world.setBlock(x + 2, y + 3, z + 5, Blocks.planks);
				world.setBlock(x + 2, y + 4, z + 5, Blocks.planks);
				world.setBlock(x + 2, y + 5, z + 5, Blocks.planks);

				for (int xx = 0; xx < 4; xx++) {
					for (int zz = 0; zz < 4; zz++) {
						world.setBlock(x + xx + 1, y + 5, z + zz + 1,
								Blocks.planks);
					}
				}

				world.setBlock(x + x1, y, z + z1, MainClass.australiumDust);

				for (int z5 = 0; z5 < 5; z5++) {
					world.setBlock(x, y, z + z5, MainClass.australiumDust);
				}

				for (int x5 = 0; x5 < 5; x5++) {
					world.setBlock(x + x5, y, z, MainClass.australiumDust);
				}

				world.setBlock(x + 2, y + 2, z, Blocks.air);
				world.setBlock(x + 2, y, z + 2, MainClass.australiumBlock);
				world.setBlock(x + 1, y + 3, z + 2, Blocks.torch);
				world.setBlock(x + 3, y + 3, z + 2, Blocks.torch);

				world.setBlock(x + 1, y + 1, z + 1, Blocks.chest);
				TileEntityChest entityChest = (TileEntityChest) world
						.getTileEntity(x + 1, y + 1, z + 1);
				if (entityChest != null) {
					WeightedRandomChestContent.generateChestContents(rand,
							snipersChestContent, entityChest, ;
				}
			}
		}
	}
	return true;
}
}

 

My code for the World Generator:

 

package com.nignog.mymod.world.gen;

import java.util.Random;

import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;

import com.nignog.mymod.world.gen.structure.WorldGenSniper;

import cpw.mods.fml.common.IWorldGenerator;

public class WorldGeneratorCustom implements IWorldGenerator {
public void generate(Random random, int chunkX, int chunkZ, World world,
		IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {
	if (world.provider.dimensionId == 0) {
		generateSurface(world, random, chunkX * 16, chunkZ * 16);
	}
}

private void generateSurface(World world, Random random, int blockX,
		int blockZ) {
	int Xcoord = blockX + random.nextInt(16);
	int Ycoord = random.nextInt(128);
	int Zcoord = blockZ + random.nextInt(16);
	(new WorldGenCustomStructure()).generate(world, random, Xcoord, Ycoord, Zcoord);
}
}

 

In my preinit fuction in the MainClass:

 

GameRegistry.registerWorldGenerator(new WorldGeneratorCustom(), 1);

 

Any ideas?

 

Thanks in advance.

  • Author

For the chest content code inside the structure code, do a

 

if(!world.isRemote){
CODE
}

 

Apparently, it didn't seem to work.

 

I put it like this:

 

world.setBlock(x + 1, y + 1, z + 1, Blocks.chest);
TileEntityChest entityChest = (TileEntityChest) world.getTileEntity(x + 1, y + 1, z + 1);
if (entityChest != null) {
if (!world.isRemote) {
	WeightedRandomChestContent.generateChestContents(rand, snipersChestContent, entityChest, 6);
}
}

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.