Jump to content

Recommended Posts

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

Posted

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.

Posted

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.

Posted

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.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I've been using this modpack for a few days now with no issues, it was working properly just an hour or two ago and now all of a sudden when I try to load it I get this error: 'The game crashed: exception in server tick loop Error: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $' debug log: https://pastebin.com/1htBuhsP crash report: https://pastebin.com/QggHKYDg
    • Everything worked fine until I decided to install supplementaries squared, amendments and a couple other mods like artifacts, and compats for it. I'm having a hard time fixing this, and I get this crash whenever I try to enter a world. Not even a new world is feasible. Any help would be highly appreciated!! https://pastebin.com/7KXYZ6fM
    • Internal Exception: com.google.gson.JsonParseException: Error loading registry data: Unknown element: ResourceKey[minecraft:worldgen/configured_feature / minecraft:crimson_forest_vegetation]   This error is there when i try to join my friends server. We had some mods and it was okay but after 3 days i cant join.
    • It just says the mod i had but i dont have now.. and i didnt even use these mods and it still was crashing with the mods  
    • Hello,   I've been back and forth in emails with some CurseForge support staff on the issue but there's been no progress. In the CurseForge app, I have custom profiles and some public modpacks that will not load no matter what. I've goen through every link sent to me, I've reinstalled Minecraft, reinstalled the launcher, repaired the installations individually, uninstalled and reinstalled the public modpacks, downloaded the latest Java--all of it. But each time, I'm always met with either "java runtime exception", "exit code 1" on the rare occasions Minecraft does launch, or "java is out of date" (which literally cannot be possible since I reinstalled the latest version a few different times.) Making a new profile works, but I want to be able to play the ones I had before.  I had gotten one of the old public Minecraft modpacks to work, the prehistoric one about dinosaurs being featured right now, but then it only worked once. I've tried to retrace my steps and it just would not work. I have genuinely no clue what's going on.
  • Topics

×
×
  • Create New...

Important Information

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