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 am trying to get the current block of some cords: namely (x,y,z) and then return if the block is different then the one listed. However, I do not know how to check for multiple blocks. I have tried the java "or" function and tried an array, how does one go about this, nighscout01

 

My world.getblock code:

if (world.getBlock(x, y, z) !=Blocks.grass) return;
if (world.getBlock(x + 15, y, z) != Blocks.grass) return;
if (world.getBlock(x + 15, y, z + 12) != Blocks.grass) return;
if (world.getBlock(x, y, z + 12) != Blocks.grass) return;

 

On a similar note, this is the "check room and blocks for spawning" file the converter gives me, however, I cannot figure out on how to implement this method of doing it into my current structure gen code.

 

protected Block[] GetValidSpawnBlocks()
{
	return new Block[]
	{
		Blocks.grass,
	};
}

public boolean LocationIsValidSpawn(World world, int i, int j, int k)
{
	int distanceToAir = 0;
	Block checkBlock = world.getBlock(i, j, k);

	while (checkBlock != Blocks.air)
	{
		distanceToAir++;
		checkBlock = world.getBlock(i, j + distanceToAir, k);
	}
	if (distanceToAir > 1)
	{
		return false;
	}
	j += distanceToAir - 1;

	Block block = world.getBlock(i, j, k);
	Block blockAbove = world.getBlock(i, j + 1, k);
	Block blockBelow = world.getBlock(i, j - 1, k);

	for (Block l : GetValidSpawnBlocks())
	{
		if (blockAbove != Blocks.air)
		{
			return false;
		}
		if (block == l)
		{
			return true;
		}
		else if (block == Blocks.snow_layer && blockBelow == l)
		{
			return true;
		}
		else if (block.getMaterial() == Material.plants && blockBelow == l)
		{
			return true;
		}
	}
	return false;
}

 

My current structure gen file

 

 

package net.morestructures.mod.worldgen;

import static net.minecraftforge.common.ChestGenHooks.DUNGEON_CHEST;
import static net.minecraftforge.common.ChestGenHooks.PYRAMID_JUNGLE_CHEST;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.tileentity.TileEntityMobSpawner;
import net.minecraft.util.WeightedRandomChestContent;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraftforge.common.ChestGenHooks;
import cpw.mods.fml.common.IWorldGenerator;

public class SwampTemple 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 i, int k)
{

int N = 1;


if(random.nextInt(N) != 0) return;


int x = i + random.nextInt(15);
int z = k + random.nextInt(15);

int y = world.getHeightValue(x, z)-1; //Get the top block



if(world.getWorldChunkManager().getBiomeGenAt(x, y)!=BiomeGenBase.swampland) return;

//Get the right block
if (world.getBlock(x, y, z) !=Blocks.grass) return;
if (world.getBlock(x + 15, y, z) != Blocks.grass) return;
if (world.getBlock(x + 15, y, z + 12) != Blocks.grass) return;
if (world.getBlock(x, y, z + 12) != Blocks.grass) return;



//debugging information
System.out.println("Generating a structure");


generate0(world, random, x, y, z);
}


private void generate0(World world, Random random, int x, int y, int z) //I recommend replacing i,j,k with x,y,z. More intuitive
{
world.setBlock.blockname
ect ect ect

 

 

Thanks, and please help, nightscout01

I'm not exactly sure what you want to do.

 

From what I understood you want a function that checks if there are certain blocks in certain locations, and return if there isn't?

 

If so your method should be a boolean rather than a void, and then return false if any block isn't what you want it to be, and then otherwise return true.

 

Something like

public boolean blockCheck(World world, int x, int y, int z)
{
    if(world.getBlock(x,y,z) != Blocks.grass
                || world.getBlock(x + 15, y, z) != Blocks.grass
                || world.getBlock(x + 15, y, z + 12) != Blocks.grass
                || world.getBlock(x, y, z + 12) != Blocks.grass)
    {
        return false;
    }
    return true;
}

BEFORE ASKING FOR HELP READ THE EAQ!

 

I'll help if I can. Apologies if I do something obviously stupid. :D

 

If you don't know basic Java yet, go and follow these tutorials.

  • Author

Pretty much all I'm trying to do right now, is trying to make it check for two blocks. Such as a list of Valid spawn blocks, like "It can spawn on grass or dirt or stone". Thanks for your help, nightscout01.

You could do something like this:

public Block[] array = {Blocks.grass, whateverOtherBlocks}

 

and then later to check if it's in the array:

boolean flag = false;

for(Block block : array)
{
    if(world.getBlock(x, y, z) == block)
    {
        flag = true;
    }
}

if(!flag)
{
    return;
}

 

If you're only using the array once, or it's really small, then you could just use the || (or) operator. I'm not sure what you mean by it not working, but it would look something like

Block block = world.getBlock(x,y,z);

if(block == Blocks.grass || block == anotherBlock || block == anotherBlockAsWell)
{
    //DO WHATEVER
}
else
{
    return;
}

BEFORE ASKING FOR HELP READ THE EAQ!

 

I'll help if I can. Apologies if I do something obviously stupid. :D

 

If you don't know basic Java yet, go and follow these tutorials.

  • Author

Thank you very much for all your help  :D. I am currently only using the array once, so I will use your second option. Thanks again, nightscout01.

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.