Jump to content

[1.12.2] Custom ore generate in cave?


StudioMaker

Recommended Posts

Well i added this 

{
    public static final PropertyDirection FACING = PropertyDirection.create("facing", new Predicate<EnumFacing>()
    {
        public boolean apply(@Nullable EnumFacing p_apply_1_)
        {
            return p_apply_1_ != EnumFacing.DOWN;
        }
    });
    protected static final AxisAlignedBB STANDING_AABB = new AxisAlignedBB(0.4000000059604645D, 0.0D, 0.4000000059604645D, 0.6000000238418579D, 0.6000000238418579D, 0.6000000238418579D);
    protected static final AxisAlignedBB CRYSTAL_NORTH_AABB = new AxisAlignedBB(0.3499999940395355D, 0.20000000298023224D, 0.699999988079071D, 0.6499999761581421D, 0.800000011920929D, 1.0D);
    protected static final AxisAlignedBB CRYSTAL_SOUTH_AABB = new AxisAlignedBB(0.3499999940395355D, 0.20000000298023224D, 0.0D, 0.6499999761581421D, 0.800000011920929D, 0.30000001192092896D);
    protected static final AxisAlignedBB CRYSTAL_WEST_AABB = new AxisAlignedBB(0.699999988079071D, 0.20000000298023224D, 0.3499999940395355D, 1.0D, 0.800000011920929D, 0.6499999761581421D);
    protected static final AxisAlignedBB CRYSTAL_EAST_AABB = new AxisAlignedBB(0.0D, 0.20000000298023224D, 0.3499999940395355D, 0.30000001192092896D, 0.800000011920929D, 0.6499999761581421D);
    AxisAlignedBB getStateForPlacement() 
    {
		IBlockState state = null;
		switch ((EnumFacing)state.getValue(FACING))
        {
            case EAST:
                return CRYSTAL_EAST_AABB;
            case WEST:
                return CRYSTAL_WEST_AABB;
            case SOUTH:
                return CRYSTAL_SOUTH_AABB;
            case NORTH:
                return CRYSTAL_NORTH_AABB;
            default:
                return STANDING_AABB;
        }
	}

And it didn't do anything. This is what i mean i have tried like everything and im doing something wrong

Link to comment
Share on other sites

You're too impatient. In programming you build things up carefully step by step. This is the first step -- you logically need your block to have a property that indicates the direction, which you now have.

 

Also you need to show your whole code. How can I help if I can't see if you also implemented the other methods for converting the property to meta data and back?

 

Then, once you have the property working you still have many steps to take. You have to make sure your state responds based on what is surrounding it both when placing and if other blocks change around it, then you have to make sure your blockstate and model JSON files are correctly mapping your properties to the visual look.

 

Anyway, next step should be to finish your block class. Make sure you have all the state to meta and meta to state methods implemented and post your WHOLE class code.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Find a block of stone with air above it.

pos = pos.up()

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I don't know how that was so hard.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Nope didnt work, something is wrong or that isnt the solve. Here is my code 

package com.studiomaker.poweredelements2.world.gen;

import java.util.Random;

import com.studiomaker.poweredelements2.init.ModBlocks;
import com.studiomaker.poweredelements2.util.handlers.EnumHandler;

import net.minecraft.block.state.pattern.BlockMatcher;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraft.world.gen.feature.WorldGenMinable;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.fml.common.IWorldGenerator;
import net.minecraftforge.fml.common.Mod.EventHandler;

public class WorldGenCrystal implements IWorldGenerator
{	
	
	
	
	private WorldGenerator crystal;
	
	public WorldGenCrystal() 
	{
		crystal = new WorldGenMinable(ModBlocks.CRYSTAL.getDefaultState(), 5, BlockMatcher.forBlock(Blocks.STONE));
	}
	
	@Override
	public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) 
	{
		switch(world.provider.getDimension())
		{
		case 0:
			
			runGenerator(crystal, world, random, chunkX, chunkZ, 50, 0, 35);
			
		}
	}
	
	private void runGenerator(WorldGenerator gen, World world, Random rand, int chunkX, int chunkZ, int chance, int minHeight, int maxHeight)
	{
		if(minHeight > maxHeight || minHeight < 0 || maxHeight > 256) throw new IllegalArgumentException("Ore generated out of bounds");
		
		int heightDiff = maxHeight - minHeight + 1;
	      for (int i = 0; i < 128; ++i)
		{
			int x = chunkX * 16 + rand.nextInt(16);
			int y = minHeight + rand.nextInt(heightDiff);
			int z = chunkZ * 16 + rand.nextInt(16);
			
			pos = pos.up();
			
			gen.generate(world, rand, new BlockPos(x,y,z));
		}
	}
}

 

Link to comment
Share on other sites

1) You haven't located

24 minutes ago, Draco18s said:

a block of stone with air above it.

2) You don't pass pos to your gen.generate method.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Do you know how to check what block exists in the world?

Do that.

Find some stone with air above it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

And the code that does that?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I tried using some weird methods to try out new stuff 

package com.studiomaker.poweredelements2.world.gen;

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

import com.studiomaker.poweredelements2.init.ModBlocks;
import com.studiomaker.poweredelements2.util.handlers.EnumHandler;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.state.pattern.BlockMatcher;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraft.world.gen.feature.WorldGenMinable;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.fml.common.IWorldGenerator;
import net.minecraftforge.fml.common.Mod.EventHandler;

public class WorldGenCrystal implements IWorldGenerator
{	
	
	
	
	private WorldGenerator crystal;
	
	public WorldGenCrystal() 
	{
		crystal = new WorldGenMinable(ModBlocks.CRYSTAL.getDefaultState(), 1, BlockMatcher.forBlock(Blocks.STONE));
	}
	
	public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {

		int x = chunkX * 50 + random.nextInt(50);
		int z = chunkZ * 50 + random.nextInt(50);

		for(int i = 15; i < 50; i++) {
			BlockPos pos = new BlockPos(x, i, z);
			BlockPos belowPos = pos.down();
			IBlockState state = world.getBlockState(pos);
			IBlockState stateBelow = world.getBlockState(belowPos);
			if(state.getBlock().isAir(state, world, pos) && stateBelow.getBlock() == Blocks.STONE) {
				makeCrystalCaveAt(world, pos, random);
				return;
			}
		}
	}

	public void makeCrystalCaveAt(World world, BlockPos source, Random rand) {
		double expandX = (rand.nextDouble() - 0.5) * 2;
		double expandY = (rand.nextDouble() - 0.5) * 0.1F;
		double expandZ = (rand.nextDouble() - 0.5) * 2;
		
		double curveAngle = rand.nextDouble() *  Math.PI * 2;
		double curveRatio = rand.nextDouble() * 0.25 + 0.1;
		double curveX = Math.cos(curveAngle) * curveRatio;
		double curveY = (rand.nextFloat() - 0.5F) * 0.05F;
		double curveZ = Math.sin(curveAngle) * curveRatio;

		BlockPos hollowingCenter = source;
		Vec3d expansion = new Vec3d(expandX, expandY, expandZ).normalize();
		Vec3d curvature = new Vec3d(curveX, curveY, curveZ);

		int color1 = rand.nextInt(12);
		int color2;
		do {
			color2 = rand.nextInt(12);
		} while(color2 == color1);

		IBlockState crystal1 = ModBlocks.CRYSTAL.getStateFromMeta(color1);
		IBlockState crystal2 = ModBlocks.CRYSTAL.getStateFromMeta(color2);

		int length = 12 + rand.nextInt(10);
		int size = 4 + rand.nextInt(11);
		for(int i = 0; i < length; i++) {
			hollowOut(world, hollowingCenter, rand, size, crystal1, crystal2);
			
			BlockPos currentCenter = hollowingCenter;
			
			if(hollowingCenter.getY() < 10) {
				expansion = new Vec3d(expansion.x, -expansion.y, expansion.z);
				curvature = new Vec3d(curvature.x, -curvature.y, curvature.z);
			}
			
			expansion = expansion.add(curvature).normalize();
		}
	}

	private void hollowOut(World world, BlockPos source, Random rand, int width, IBlockState crystal1, IBlockState crystal2) {
		List<BlockPos> crystals = new ArrayList();
		
		int max = width * width;
		for(int i = -width; i <= width; i++)
			for(int j = -width; j <= width; j++)
				for(int k = -width; k <= width; k++) {
					BlockPos pos = source.add(i, j, k);
					int dist = i * i + j * j + k * k;

					if(dist < max) {
						IBlockState state = world.getBlockState(pos);
						Block block = state.getBlock();

						if(block.getBlockHardness(state, world, pos) != -1)
							world.setBlockToAir(pos);
					} else if(dist - 1 < max)
						crystals.add(pos);
				}
		
		for(BlockPos pos : crystals) {
			if(rand.nextInt(3) == 0)
				makeCrystal(world, pos, rand, rand.nextBoolean() ? crystal1 : crystal2);
			else if(rand.nextInt(2) == 0) {
				IBlockState stateAt = world.getBlockState(pos);
				Block blockAt = stateAt.getBlock();
				if(blockAt.isAir(stateAt, world, pos) || blockAt == ModBlocks.CRYSTAL || blockAt.getBlockHardness(stateAt, world, pos) == -1)
					continue;
				
				IBlockState oreState = Blocks.GOLD_ORE.getDefaultState();
				if(rand.nextInt(3) == 0) {
					if(rand.nextInt(3) == 0)
						oreState = Blocks.DIAMOND_ORE.getDefaultState();
					else oreState = Blocks.EMERALD_ORE.getDefaultState();
				}
				
				world.setBlockState(pos, oreState);
			}
		}
			
	}

	private void makeCrystal(World world, BlockPos source, Random rand, IBlockState crystal) {
		boolean up = rand.nextBoolean();
		EnumFacing shift = up ? EnumFacing.UP : EnumFacing.DOWN;
		
		BlockPos startPos = source;
		IBlockState state = world.getBlockState(startPos);
		if(state.getBlock() == ModBlocks.CRYSTAL)
			return;
		
		int tests = 0;
		
		while(state.getBlock().isAir(state, world, startPos)) {
			startPos = startPos.offset(shift.getOpposite());
			state = world.getBlockState(startPos);

			tests++;
			if(tests >= 10)
				return;
		}

		int size = 3 + rand.nextInt(4);
		
		BlockPos pos = startPos;
		for(int i = 0; i < size; i++) {
			IBlockState stateAt = world.getBlockState(pos);
			Block block = stateAt.getBlock();
			if(block.getBlockHardness(stateAt, world, pos) == -1)
				break;
			
			world.setBlockState(pos, crystal);
			pos = pos.offset(shift);
		}
	}
}

 

Link to comment
Share on other sites

I don't know what your hollow-out and make-crystal are supposed to be doing. Your crystals are clearly one block in size, so why are you placing several of them at once?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

		for(int i = 0; i < size; i++) {
			IBlockState stateAt = world.getBlockState(pos);
			Block block = stateAt.getBlock();
			if(block.getBlockHardness(stateAt, world, pos) == -1)
				break;
			
			world.setBlockState(pos, crystal);
			pos = pos.offset(shift);
		}

What do you think this loop does?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.