Jump to content

[1.7.10] Exception getting block type in world


OUGHT

Recommended Posts

Hello!

I have a very strange problems.

I made my custom dimension, and I try to cover my biome with layer of radioactive ash.

I cannot make it in genTerrainBlocks() - ravines and lakes are generating underneath my layer, and ash blocks are suspended in the air. So I must generate it in decorate().

But when I place the generation in decorate(), the game crashes with a strange error: http://pastebin.com/b5k9jabF

Code of ash WorldGen:

 

package refugeecraft.world.dimension.generators;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;
import refugeecraft.blocks.RModBlocks;
import refugeecraft.blocks.environmental.BlockFalloutAshLayer;
import refugeecraft.lib.utils.RUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
* Package refugeecraft.world.dimension.generators.
* Created by OUGHT on 10.07.2014 in 7:45.
*/
public class WorldGenFalloutAsh extends WorldGenerator
{
private FalloutInfo falloutInfo;
private final int maxHeightOfStructures;
public static List<Byte> metas;
public static List<Double> noises;


static
{
	metas = new ArrayList<Byte>();
	noises = new ArrayList<Double>();
}

public WorldGenFalloutAsh(FalloutInfo falloutInfo, int maxHeightOfStructures)
{
	this.falloutInfo = falloutInfo;
	this.maxHeightOfStructures = maxHeightOfStructures;
}

@Override
public boolean generate(World world, Random random, int xg, int yg, int zg)
{
	int xc1 = xg - 7;
	int xc2 = xg + 8;
	int zc1 = zg - 7;
	int zc2 = zg + 8;

	for (int x = xc1; x <= xc2; x++ )
	{
		for (int z = zc1; z <= zc2; z++ )
		{
			double chance = this.falloutInfo.getFalloutNoise().func_151601_a((double)x * 0.25D, (double)z * 0.25D);
			noises.add(chance);
			chance = (chance + 1)/2;
			if (chance <= this.falloutInfo.getFalloutChance())
			{
				int y = RUtil.findTop(world, x, z, yg + maxHeightOfStructures);
				Block topBlock = world.getBlock(x, y, z);
				Block airBlock = world.getBlock(x, y + 1, z);
				boolean canPlaceAshOn = topBlock != null && BlockFalloutAshLayer.canPlaceBlockOn(topBlock);
				boolean canPlaceAshInstead = airBlock == null || airBlock.getMaterial() == Material.air;
				if (canPlaceAshOn && canPlaceAshInstead)
				{
					byte meta = generateThickness(random);
					metas.add(meta);
					world.setBlock(x, y + 1, z, RModBlocks.ashLayer, meta, 3);
				}

			}
		}
	}
	return true;
}


private byte generateThickness(Random random)
{
	double rnd = random.nextDouble();
	double border = 0.1d;
	byte meta = -1;
	for (int i = 0; i < 7; i++)
	{
		if (rnd >= border)
		{
			meta = (byte) i;
			break;
		}
		border /= 2;
	}

	return (byte) (meta & 7);
}
}

 

Firstly I thought this crash occures because of too heavy alghoritm, but when I tried to simply adapt Tall Grass Generator I had the same crash.

Code of TallGrassLike Worldgen:

 

package refugeecraft.world.dimension.generators;

import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;
import refugeecraft.blocks.RModBlocks;

import java.util.Random;

/**
* Package refugeecraft.world.dimension.generators.
* Created by OUGHT on 10.07.2014 in 22:25.
*/
public class WorldGenRandomBlocks extends WorldGenerator
{
@Override
public boolean generate(World world, Random random, int xg, int yg, int zg)
{
	Block block;

	do
	{
		block = world.getBlock(xg, yg, zg);
		if (!(block.isLeaves(world, xg, yg, zg) || block.isAir(world, xg, yg, zg)))
		{
			break;
		}
		--yg;
	} while (yg > 0);

	for (int l = 0; l < 128; ++l)
	{
		int i1 = xg + random.nextInt( - random.nextInt(;
		int j1 = yg + random.nextInt(4) - random.nextInt(4);
		int k1 = zg + random.nextInt( - random.nextInt(;

		if (world.isAirBlock(i1, j1, k1) && RModBlocks.ashLayer.canPlaceBlockAt(world, i1, j1, k1))
		{
			world.setBlock(i1, j1, k1, RModBlocks.ashLayer, 1, 2);
		}
	}

	return true;
}
}

 

Please, help me!

The Mary Sue is not defined by her power, but by her lack of an even more powerful opponent. ©LessWrong

Link to comment
Share on other sites

You risk yg + random.nextInt(4) - random.nextInt(4); being negative.

It is jusy a copy-paste from WorldGenTallGrass) If it not works in my mod, it must not work in vanilla.

And what about my normal not copypasted worldgen? Why the stack is overflowing?..

 

The Mary Sue is not defined by her power, but by her lack of an even more powerful opponent. ©LessWrong

Link to comment
Share on other sites

Is your

RModBlocks.ashLayer.canPlaceBlockAt

method fit to handle negative Y-values without trying to set or get them?

Nope, it tries to get block underneath.

Inserted negative-check on this method, still crashing: http://pastebin.com/7eGxjnHW

BlockFalloutAshLayer:

 

package refugeecraft.blocks.environmental;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import refugeecraft.blocks.BlockRM;
import refugeecraft.blocks.RModBlocks;
import refugeecraft.items.RModItems;
import refugeecraft.lib.Strings;

import java.util.Random;

/**
* Package refugeecraft.blocks.environmental.
* Created by OUGHT on 06.07.2014 in 13:14.
*/
public class BlockFalloutAshLayer extends BlockRM
{
public BlockFalloutAshLayer()
{
	super(Material.sand);
	this.setBlockName(Strings.BlockFalloutAshLayerName);
	this.setStepSound(Block.soundTypeSand);
	this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.125F, 1.0F);
	this.setThickness(0);
	this.setHardness(0.2F);
	this.setLightOpacity(0);
	RModBlocks.register(this);
}

/**
 * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
 * cleared to be reused)
 */
public AxisAlignedBB getCollisionBoundingBoxFromPool(World p_149668_1_, int p_149668_2_, int p_149668_3_, int p_149668_4_)
{
	int size = p_149668_1_.getBlockMetadata(p_149668_2_, p_149668_3_, p_149668_4_) & 7;
	float f = 0.125F;
	return AxisAlignedBB.getBoundingBox((double)p_149668_2_ + this.minX, (double)p_149668_3_ + this.minY,
	                                    (double)p_149668_4_ + this.minZ, (double)p_149668_2_ + this.maxX,
	                                    (double)((float)p_149668_3_ + (float)size * f), (double)p_149668_4_ + this.maxZ);
}

/**
 * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
 * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
 */
public boolean isOpaqueCube()
{
	return false;
}

/**
 * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
 */
public boolean renderAsNormalBlock()
{
	return false;
}

/**
 * Sets the block's bounds for rendering it as an item
 */
public void setBlockBoundsForItemRender()
{
	this.setThickness(0);
}

/**
 * Updates the blocks bounds based on its current state. Args: world, x, y, z
 */
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z)
{
	this.setThickness(world.getBlockMetadata(x, y, z));
}

protected void setThickness(int metadata)
{
	int j = metadata & 7;
	float f = (float)(2 * (1 + j)) / 16.0F;
	this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, f, 1.0F);
}

/**
 * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
 */
public boolean canPlaceBlockAt(World world, int x, int y, int z)
{
	if (y - 1 < 0) return false;
	Block block = world.getBlock(x, y - 1, z);
	return canPlaceBlockOn(block);
}

/**
 * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
 */
public static boolean canPlaceBlockOn(Block block)
{
	if (block == null) return false;
	boolean isLiquid = (block == Blocks.water) || (block == Blocks.lava) ||
			(block == Blocks.flowing_water) || (block == Blocks.flowing_lava);
	boolean isLeaves = block.getMaterial() == Material.leaves;
	boolean isAshLayer = block == RModBlocks.ashLayer;
	boolean isNormalCube = block.isOpaqueCube() && block.getMaterial().blocksMovement();

	return !isLiquid && (isLeaves || isAshLayer || isNormalCube);
}

/**
 * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
 * their own) Args: x, y, z, neighbor Block
 */
public void onNeighborBlockChange(World world, int x, int y, int z, Block block)
{
	this.retryPlacing(world, x, y, z, block);
}

@Override
public void onBlockAdded(World world, int x, int y, int z)
{
	if (world.getBlock(x, y - 1, z).getMaterial() == Material.air)
	{
		int meta = world.getBlockMetadata(x, y, z);
		world.setBlockToAir(x, y, z);
		world.setBlock(x, y - 1, z, this, meta, 3);
	}
	else if (addThickness(world, x, y - 1, z, 1))
	{
		world.setBlockToAir(x, y, z);
	}
}

private boolean retryPlacing(World world, int x, int y, int z, Block block)
{
	if (!this.canPlaceBlockAt(world, x, y, z))
	{
		world.setBlockToAir(x, y, z);
		return false;
	}
	else
	{
		return true;
	}
}

/**
 * Called when the player destroys a block with an item that can harvest it. (i, j, k) are the coordinates of the
 * block and l is the block's subtype/damage.
 */
public void harvestBlock(World world, EntityPlayer player, int x, int y, int z, int metadata)
{
	super.harvestBlock(world, player, x, y, z, metadata);
	world.setBlockToAir(x, y, z);
}

public Item getItemDropped(int meta, Random random, int fortune)
{
	return RModItems.falloutAsh;
}

/**
 * Metadata and fortune sensitive version, this replaces the old (int meta, Random rand)
 * version in 1.1.
 *
 * @param meta Blocks Metadata
 * @param fortune Current item fortune level
 * @param random Random number generator
 * @return The number of items to drop
 */
public int quantityDropped(int meta, int fortune, Random random)
{
	int max = (meta & 7) + 1;
	return Math.round(random.nextFloat() * max);
}

public static boolean addThickness(World world, int x, int y, int z, int amount)
{
	if (!(world.getBlock(x, y, z) == RModBlocks.ashLayer))
	{
		return false;
	}
	else
	{
		int metadata = world.getBlockMetadata(x, y, z) & 7;
		metadata += amount;
		if ((metadata < 0) || (metadata > 7))
		{
			return false;
		}
		else if (metadata < 7)
		{
			world.setBlockMetadataWithNotify(x, y, z, metadata, 3);
			return true;
		}
		else
		{
			world.setBlockToAir(x, y, z);
			world.setBlock(x, y, z, RModBlocks.ashBlock);
			return true;
		}
	}
}



/**
 * Returns true if the given side of this block type should be rendered, if the adjacent block is at the given
 * coordinates.  Args: blockAccess, x, y, z, side
 */
@SideOnly (Side.CLIENT)
public boolean shouldSideBeRendered(IBlockAccess p_149646_1_, int p_149646_2_, int p_149646_3_, int p_149646_4_, int p_149646_5_)
{
	return p_149646_5_ == 1 ? true : super.shouldSideBeRendered(p_149646_1_, p_149646_2_, p_149646_3_, p_149646_4_, p_149646_5_);
}



/**
 * Determines if a new block can be replace the space occupied by this one,
 * Used in the player's placement code to make the block act like water, and lava.
 *
 * @param world The current world
 * @param x X Position
 * @param y Y position
 * @param z Z position
 * @return True if the block is replaceable by another block
 */
public boolean isReplaceable(IBlockAccess world, int x, int y, int z)
{
	int meta = world.getBlockMetadata(x, y, z);
	return meta >= 7 ? false : blockMaterial.isReplaceable();
}
}

 

The Mary Sue is not defined by her power, but by her lack of an even more powerful opponent. ©LessWrong

Link to comment
Share on other sites

java.lang.StackOverflowError: Exception getting block type in world

        [snip]

        at refugeecraft.world.dimension.generators.WorldGenFalloutAsh.generate(WorldGenFalloutAsh.java:65)

 

Line 65 of

WorldGenFalloutAsh.java

is not fit to handle Y-values above the height of the nether.

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.