Jump to content

[1.10] Structures being overwritten by vanilla worldgen


Recommended Posts

Posted (edited)

In the mod that I'm working on I want to implement a bunch of structures. The spawning of the structures is working as planned with one large exception. As soon as I start moving away from spawn, the blocks within my structure are being replaced by other world generation (as far as I can tell this is what happens). To give an example here is an image of what it is supposed to look like:

 

Spoiler

CiVfUar.png

To give an example what is happening:
 

Spoiler

aDUOLOu.png

So I figured out it had something to do with the WorldGenMinable Class. This class is what replaces stone with ores,dirt and stone varients. In particular the part:

    public WorldGenMinable(IBlockState state, int blockCount)
    {
        this(state, blockCount, BlockMatcher.forBlock(Blocks.STONE));
    }

This part is, I believe, what checks for stone and then replaces it with other stuff found in normal generation.

Is there anyway to stop minecraft from generating into a structure? I tried to somehow setup a way to either:
1. Ignore all my structures during this process
2. Place my structures after this process has completed.

I have gotten no luck with trying to complete either option... Am I just blind? I tried looking at other mods and at lots of forums but I can't find anything related to this issue anywhere?

Here are are my classes dealing with the structure spawning:
 

Spoiler

package com.MushWolf.Adventura;

import java.util.Random;

import com.MushWolf.Adventura.block.ModBlocks;
import com.MushWolf.Adventura.item.ModItems;
import com.MushWolf.Adventura.proxy.CommonProxy;
import com.MushWolf.Adventura.tab.CreativeTabAdventura;
import com.MushWolf.Adventura.worldgen.ModStructures;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;

@Mod(modid = Adventura.MOD_ID, name = Adventura.NAME, version = Adventura.VERSION, acceptedMinecraftVersions = Adventura.ACCEPTED_VERSIONS)
public class Adventura {
	
	public static final String MOD_ID = "adventura";
	public static final String NAME = "MushWolf's Adventura Mod";
	public static final String VERSION = "Alpha 1.0";
	public static final String ACCEPTED_VERSIONS = "[1.10.2,)";

	public static final String CLIENT_PROXY_CLASS = "com.MushWolf.Adventura.proxy.ClientProxy";
	public static final String COMMON_PROXY_CLASS = "com.MushWolf.Adventura.proxy.CommonProxy";
	public static Random rand;
	
	@SidedProxy(clientSide = Adventura.CLIENT_PROXY_CLASS, serverSide = Adventura.COMMON_PROXY_CLASS)
	public static CommonProxy proxy;
	
	@Mod.Instance(Adventura.MOD_ID)
	public static Adventura instance; //GUI and Entities
	
	public static CreativeTabAdventura tabAdventura;
	
	@EventHandler
	public void preInit(FMLPreInitializationEvent event) 
	{
		tabAdventura = new CreativeTabAdventura(CreativeTabs.getNextID(), "tab_adventura");
		ModItems.preInit();
		ModBlocks.preInit();		
		proxy.preInit(event);		
	}
	
	@EventHandler
	public void init(FMLInitializationEvent event) 
	{
		GameRegistry.registerWorldGenerator(new ModStructures(), 77);
		proxy.init(event);
	}
	
	@EventHandler
	public void postInit(FMLPostInitializationEvent event) 
	{
		//MinecraftForge.EVENT_BUS.register(new AdventuraModEventHandler());
		proxy.postInit(event);
	}
}

 

An example of one of the classes for the individual structures:
 

Spoiler

package com.MushWolf.Adventura.worldgen;

import java.util.Random;

import com.MushWolf.Adventura.Adventura;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.Mirror;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraft.world.gen.structure.template.PlacementSettings;
import net.minecraft.world.gen.structure.template.Template;
import net.minecraft.world.gen.structure.template.TemplateManager;

public class Adventura1stonetemple extends WorldGenerator
{
private static final ResourceLocation Adv1 = new ResourceLocation(Adventura.MOD_ID+":/Adv1");
@Override
public boolean generate(World world, Random rand, BlockPos position) 
{
WorldServer worldserver = (WorldServer) world;
MinecraftServer minecraftserver = world.getMinecraftServer();
TemplateManager templatemanager = worldserver.getStructureTemplateManager();
Template template = templatemanager.getTemplate(minecraftserver, Adv1);

if(template == null)
{

System.out.println("NO STRUCTURE");

return false;
}


if(CanSpawnHere(template, worldserver, position)) 
{

IBlockState iblockstate = world.getBlockState(position);
world.notifyBlockUpdate(position, iblockstate, iblockstate, 3);
PlacementSettings placementsettings = (new PlacementSettings()).setMirror(Mirror.NONE)
.setRotation(Rotation.NONE).setIgnoreEntities(false).setChunk((ChunkPos) null)
.setReplacedBlock((Block) null).setIgnoreStructureBlock(false);
template.addBlocksToWorld(world, position.add(0, 1, 0), placementsettings);

return true;

}

return false;

}

public static int areAllCornersLand(World world, int x, int z) 
//checks to see if both corners of the template are going to be placed on land.
{
WorldServer worldserver = (WorldServer) world;
MinecraftServer minecraftserver = world.getMinecraftServer();
TemplateManager templatemanager = worldserver.getStructureTemplateManager();
Template template = templatemanager.getTemplate(minecraftserver, Adv1);

int zwidth = template.getSize().getZ();
int xwidth = template.getSize().getX();
int y = 255;

boolean foundLand = false;
boolean foundLand2 = false;
while (!foundLand && !foundLand2 && y-- >= 63)
{
BlockPos pos = new BlockPos(x,y,z);
BlockPos pos2 = new BlockPos(pos.add(xwidth, y, zwidth));
Block blockAt = world.getBlockState(pos).getBlock();
Block blockOp = world.getBlockState(pos2).getBlock();;

foundLand = ((blockAt == Blocks.DIRT || blockAt == Blocks.GRASS || blockAt == Blocks.SAND || blockAt == Blocks.SNOW || blockAt == Blocks.SNOW_LAYER || blockAt == Blocks.STONE || blockAt == Blocks.GLASS) && blockAt != Blocks.AIR); 
foundLand2 = ((blockOp == Blocks.DIRT || blockAt == Blocks.GRASS || blockAt == Blocks.SAND || blockAt == Blocks.SNOW || blockAt == Blocks.SNOW_LAYER || blockAt == Blocks.STONE || blockAt == Blocks.GLASS) && blockAt != Blocks.AIR);

}
return y;
}

public static boolean isCornerValid(World world, Template template, BlockPos pos)
{ 
int variation = 3;
int highestBlock = areAllCornersLand(world, pos.getX(), pos.getZ());

if (highestBlock > pos.getY() - variation && highestBlock < pos.getY() + variation)
return true;

return false;
}

public static boolean CanSpawnHere(Template template, World world, BlockPos posIsAbove) 
{
int zwidth = template.getSize().getZ();
int xwidth = template.getSize().getX(); 

boolean corner1 = isCornerValid(world, template, posIsAbove); 
boolean corner2 = isCornerValid(world, template, posIsAbove.add(xwidth, 0, zwidth)); 

return posIsAbove.getY() > 63 && corner1 && corner2;
}

}

 

 

My structure spawn class, that spawns all my structures and is registered in the init.

Spoiler

package com.MushWolf.Adventura.worldgen;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.BlockLog;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkGenerator;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.fml.common.IWorldGenerator;

public class ModStructures implements IWorldGenerator{

@Override
public void generate(Random rand, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) 
{
switch (world.provider.getDimension())
{
case -1: 
generateNether(world, rand, chunkX, chunkZ);
break;
case 0: 
generateOverworld(world, rand, chunkX * 16, chunkZ* 16);
break;
case 1: 
generateEnd(world, rand, chunkX, chunkZ);
break;
}

}

private void generateOverworld(World world, Random rand, int x, int z)
{
int randomX = x + rand.nextInt(16);
int randomZ = z + rand.nextInt(16);

if (rand.nextInt(100) % 5 == 3000) //Test structure 
{ 
int y = Test.getGroundFromAbove(world, x, z); 
BlockPos posiT = new BlockPos(x, y , z); 
WorldGenerator test = new Test(); 
test.generate(world, rand, posiT); 
}

if (rand.nextInt(100) % 5 == 0) //#1: Stone Temple 
{
int y = Adventura1stonetemple.areAllCornersLand(world, x, z); 
BlockPos posiA1 = new BlockPos(x, y - 1, z); 
WorldGenerator A1 = new Adventura1stonetemple(); 
A1.generate(world, rand, posiA1); 
}

if (rand.nextInt(100) % 5 == 3000) //#5: Sun Dial 
{
int y = Adventura5sundial.getGroundFromAbove(world, x, z); 
BlockPos posiA5 = new BlockPos(x, y - 1, z); 
WorldGenerator A5 = new Adventura5sundial(); 
A5.generate(world, rand, posiA5); 
}
}

private void generateNether(World world, Random rand, int chunkX, int chunkZ) {}
private void generateEnd(World world, Random rand, int chunkX, int chunkZ) {}

}
Edited by MushWolf

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.