Jump to content

[1.8][Solved?] Prevent Vanilla Structures from Conflicts with Custom Structure?


Recommended Posts

Posted

I have a huge maze structure in my mod where alterations caused by vanilla generation can cut across large distances or destroy paths which can ruin the experience. I'd like to know how I can either: (1) prevent my structure from being altered after its generation OR (2) set my structure to generate after the generation of all vanilla structures and anything else that could overwrite the block states of my structure.

 

Image of what I want to prevent (that opening should not be there):

 

iFmdH3U.jpg

 

 

WorldGenChaosLabyrinth.java

 

package com.samuel.chaosblock;

 

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.ArrayDeque;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import java.util.Random;

 

import com.google.common.collect.ArrayListMultimap;

import com.google.common.collect.Multimap;

import com.samuel.chaosblock.tileentities.TileEntityChaosChest;

import com.samuel.chaosblock.etc.ChaosLabyrinthData;

 

import net.minecraft.block.Block;

import net.minecraft.block.state.IBlockState;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.player.EntityPlayerMP;

import net.minecraft.init.Blocks;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.tileentity.TileEntityChest;

import net.minecraft.util.BlockPos;

import net.minecraft.util.EnumFacing;

import net.minecraft.util.WeightedRandomChestContent;

import net.minecraft.world.World;

import net.minecraft.world.chunk.IChunkProvider;

import net.minecraft.world.gen.feature.WorldGenMinable;

import net.minecraftforge.common.ChestGenHooks;

import net.minecraftforge.fml.common.IWorldGenerator;

 

 

public class WorldGenChaosLabyrinth implements IWorldGenerator {

 

private Map<Integer, Map<Integer, IBlockState>> chunkData = null;

private Map<Integer, ArrayDeque<Integer>> chunkChest = null;

private Map<Integer, ArrayDeque<Integer>> chunkChaosChest = null;

private Multimap<Integer, BlockPos> specialBlocks = ArrayListMultimap.create();

private List<BlockPos> specialChoices = new ArrayList<BlockPos>();

private int chunksGenerated = 0;

private int chunkDistanceX = 0;

private int blockDistanceY = 0;

private int chunkDistanceZ = 0;

private World curWorld;

public BlockPos spawnPos = new BlockPos(-1,-1,-1);

public BlockPos compassPos = new BlockPos(-1,-1,-1);

private boolean generated;

private boolean spawnPosLoaded = false;

private ChaosLabyrinthData ChaosLabyrinthData;

private ChestGenHooks info = ChestGenHooks.getInfo("Chaos");

private ChestGenHooks info_high = ChestGenHooks.getInfo("Chaos_High");

 

public WorldGenChaosLabyrinth() { }

   

@Override

public void generate(Random random, int chunkX, int chunkZ, World world,

IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {

loadOrCreateData(world);

if (generated || !ChaosBlock.enableChaosLabyrinth)

return;

if (!spawnPosLoaded && (chunkDistanceX == 0 || blockDistanceY <= 0 || chunkDistanceZ == 0)) {

int failCount = 0;

ChaosLabyrinthData.setIsGenerated(false);

findNewSpawnPos(world, random, 0);

BlockPos oppPos = new BlockPos(this.spawnPos.getX() + 31, this.spawnPos.getY() + 45, this.spawnPos.getZ() + 31);

while ((world.getBiomeGenForCoords(this.spawnPos).biomeName == "Ocean" ||

world.getBiomeGenForCoords(this.spawnPos).biomeName == "Deep Ocean" ||

world.getBiomeGenForCoords(this.spawnPos).biomeName == "Beach" ||

world.getBiomeGenForCoords(this.spawnPos).biomeName == "Mushroom Island Shore" ||

world.getBiomeGenForCoords(this.spawnPos).biomeName == "River" ||

world.getBiomeGenForCoords(oppPos).biomeName == "Ocean" ||

world.getBiomeGenForCoords(oppPos).biomeName == "Deep Ocean" ||

world.getBiomeGenForCoords(oppPos).biomeName == "Beach" ||

world.getBiomeGenForCoords(oppPos).biomeName == "Mushroom Island Shore" ||

world.getBiomeGenForCoords(oppPos).biomeName == "River") &&

failCount < 200) {

failCount++;

findNewSpawnPos(world, random, failCount);

oppPos = new BlockPos(this.spawnPos.getX() + 31, this.spawnPos.getY() + 45, this.spawnPos.getZ() + 31);

}

}

 

int spawnPosChunkX = spawnPos.getX() >> 4;

int spawnPosChunkZ = spawnPos.getZ() >> 4;

 

if ((chunkX >= spawnPosChunkX - 4 && chunkX <= spawnPosChunkX + 3) &&

(chunkZ >= spawnPosChunkZ - 4 && chunkZ <= spawnPosChunkZ + 3)) {

 

int distance = (int) ((chunkX + chunkZ) * 0.5);

 

if ((chunkX == spawnPos.getX() >> 4 ||

chunkX - 1 == spawnPos.getX() >> 4) &&

(chunkZ == spawnPos.getZ() >> 4 ||

chunkZ - 1 == spawnPos.getZ() >> 4) &&

world.provider.getDimensionId() == 0)

generateSurface(world, random, chunkX*16, chunkZ*16, true, distance);

else

generateSurface(world, random, chunkX*16, chunkZ*16, false, distance);

}

    }

 

private void findNewSpawnPos(World world, Random random, int failCount) {

chunkDistanceX = (int) (random.nextGaussian() * 25 + (failCount < 20 ? 15 : 20)) * ((Math.round(Math.random()) == 0) ? -1 : 1);

chunkDistanceZ = (int) (random.nextGaussian() * 12.5 +  (failCount < 20 ? 7.5 : 10)) * ((Math.round(Math.random()) == 0) ? -1 : 1) * 2;

blockDistanceY = 1;

spawnPos = new BlockPos((((world.getSpawnPoint().getX() >> 4) + (chunkDistanceX + 1)) * 16),

blockDistanceY, (((world.getSpawnPoint().getZ() >> 4) + (chunkDistanceZ + 1)) * 16));

compassPos = new BlockPos(spawnPos.getX() + 17, spawnPos.getY() + 45, spawnPos.getZ() + 15);

ChaosLabyrinthData.setSpawnPoint(spawnPos.getX(), spawnPos.getY(), spawnPos.getZ());

ChaosLabyrinthData.setCompassPoint(compassPos.getX(), compassPos.getY(), compassPos.getZ());

}

   

 

    private void generateSurface(World world, Random random, int x, int z, boolean isStructure, int distance) {

if (isStructure) {

    int chunkIndex = (z >> 4 == spawnPos.getZ() >> 4) ? 0 : 2;

if (x >> 4 != spawnPos.getX() >> 4)

chunkIndex++;

this.spawn(world, x, spawnPos.getY(), z, chunkIndex);

    } else {

    if (x >> 4 == (spawnPos.getX() >> 4) + 2 && z >> 4 == spawnPos.getZ() >> 4) {

    for (int b = 0; b <= 10; b++)

    world.setBlockState(new BlockPos(x, this.spawnPos.getY() + 27 + b, z + 10), ChaosBlock.blockChaos.getStateFromMeta(2), 0);

    }

    }

    }

   

    public boolean getGenerated(World worldIn) {

    loadOrCreateData(worldIn);

    return generated;

    }

   

    public BlockPos getSpawnPos(World worldIn) {

    loadOrCreateData(worldIn);

    return spawnPos;

    }

   

    public List<BlockPos> getSpecialChoices(World worldIn) {

    loadOrCreateData(worldIn);

    return specialChoices;

    }

   

    public Multimap<Integer, BlockPos> getSpecialBlocks(World worldIn) {

    loadOrCreateData(worldIn);

    return specialBlocks;

    }

   

protected final void loadOrCreateData(World world) {

if (this.ChaosLabyrinthData == null || curWorld == null || (world.getWorldInfo().getSeed() != 0 &&

curWorld.getWorldInfo().getSeed() != world.getWorldInfo().getSeed())) {

curWorld = world;

this.ChaosLabyrinthData = (ChaosLabyrinthData) world.loadItemData(ChaosLabyrinthData.class, "ChaosLabyrinth");

if (this.ChaosLabyrinthData == null) {

this.ChaosLabyrinthData = new ChaosLabyrinthData("ChaosLabyrinth");

world.setItemData("ChaosLabyrinth", ChaosLabyrinthData);

this.generated = false;

this.chunksGenerated = 0;

this.chunkDistanceX = 0;

this.blockDistanceY = 0;

this.chunkDistanceZ = 0;

this.spawnPos = new BlockPos(-1,-1,-1);

this.compassPos = this.spawnPos;

this.specialChoices = new ArrayList<BlockPos>();

this.specialBlocks = ArrayListMultimap.create();

} else {

this.generated = ChaosLabyrinthData.getIsGenerated();

this.spawnPos = ChaosLabyrinthData.getSpawnPoint();

this.compassPos = ChaosLabyrinthData.getCompassPoint();

this.spawnPosLoaded = true;

IBlockState spawnBlock;

if (this.spawnPos.getY() > 0 && (spawnBlock = world.getBlockState(this.spawnPos)) != ChaosBlock.blockChaos.getStateFromMeta(2)) {

this.generated = false;

this.chunksGenerated = 0;

this.chunkDistanceX = 0;

this.blockDistanceY = 0;

this.chunkDistanceZ = 0;

this.specialChoices = new ArrayList<BlockPos>();

this.specialBlocks = ArrayListMultimap.create();

} else {

chunksGenerated = 4;

this.specialChoices = ChaosLabyrinthData.getSpecialChoices();

this.specialBlocks = ChaosLabyrinthData.getSpecialBlocks();

}

}

 

}

}

 

public ChaosLabyrinthData getData() {

return this.ChaosLabyrinthData;

}

 

    public void spawn(World world, int ix, int iy, int iz, int chunk) {

int index = 0;

int blockID = 0;

int meta = 0;

int curByte = 0;

int forChunk = 0;

String byteStr = "";

IBlockState blockState;

IBlockState air = Blocks.air.getDefaultState();

IBlockState ladder = Blocks.ladder.getDefaultState();

IBlockState chaos = ChaosBlock.blockChaos.getDefaultState();

IBlockState chaos_unbreakable = ChaosBlock.blockChaos.getStateFromMeta(2);

IBlockState chaos_volatile_high = ChaosBlock.blockChaos.getStateFromMeta(4);

IBlockState chaos_special1 = ChaosBlock.blockChaos.getStateFromMeta(5);

IBlockState chaos_special2 = ChaosBlock.blockChaos.getStateFromMeta(6);

IBlockState chaos_special3 = ChaosBlock.blockChaos.getStateFromMeta(7);

IBlockState chaos_special4 = ChaosBlock.blockChaos.getStateFromMeta(8);

IBlockState chaos_special5 = ChaosBlock.blockChaos.getStateFromMeta(9);

BlockPos curPos;

List<Integer[]> blockIDs = new ArrayList<Integer[]>();

List<IBlockState> blockStates = new ArrayList<IBlockState>();

Map<Integer[], Integer> blockMap = new HashMap<Integer[], Integer>();

 

blockIDs.add(new Integer[]{202,2});

blockStates.add(chaos_unbreakable);

blockMap.put(new Integer[]{202,2}, 0);

 

if (chunksGenerated == 0) {

chunkChest = new HashMap<Integer, ArrayDeque<Integer>>();

chunkChaosChest = new HashMap<Integer, ArrayDeque<Integer>>();

for (int c = 0; c < 4; c++) {

chunkChest.put(c, new ArrayDeque<Integer>());

chunkChaosChest.put(c, new ArrayDeque<Integer>());

}

}

 

try {

 

BufferedReader is = new BufferedReader(new InputStreamReader(ChaosBlock.instance.getClass().getClassLoader()

      .getResourceAsStream("assets/chaosblock/structures/ChaosLabyrinth.txt"), "UTF-8"));

 

for (int y = 0; y < 46; y++) {

 

forChunk = 0;

 

for (int z = 0; z < 32; z++) {

 

if (z == 16)

forChunk += 2;

 

for (int x = 0; x < 32; x++) {

 

if (x == 16)

forChunk++;

 

curPos = new BlockPos(ix + (x % 16), iy + y , iz + (z % 16));

 

if (chunksGenerated > 0) {

if (chunk == forChunk) {

index = (y * 1024) + (z * 32) + x;

blockState = chunkData.get(chunk).get(index);

world.setBlockState(curPos, blockState, 0);

if (!chunkChest.get(chunk).isEmpty() && chunkChest.get(chunk).peekFirst() == index) {

initChest(world, curPos, false);

chunkChest.get(chunk).pollFirst();

} else if (!chunkChaosChest.get(chunk).isEmpty() && chunkChaosChest.get(chunk).peekFirst() == index) {

initChest(world, curPos, true);

chunkChaosChest.get(chunk).pollFirst();

}

}

continue;

} else {

 

while ((curByte = is.read() - 48) > -1)

byteStr += curByte;

blockID = Integer.parseInt(byteStr);

 

byteStr = "";

 

while ((curByte = is.read() - 48) > -1)

byteStr += curByte;

meta = Integer.parseInt(byteStr);

 

byteStr = "";

 

if (blockID == 202 && meta == 2) {

boolean isOutsideVisible = x == 0 || x == 31 || y == 0 || y == 45 || z == 0 || z == 31;

boolean isSpecial = !isOutsideVisible &&

world.getBlockState(curPos.up()).getBlock() != ChaosBlock.blockChaosLabyrinthThreshold &&

(world.getBlockState(curPos.up()) == air || world.getBlockState(curPos.down()) == air ||

world.getBlockState(curPos.north()) == air || world.getBlockState(curPos.south()) == air ||

world.getBlockState(curPos.east()) == air || world.getBlockState(curPos.west()) == air);

if (isSpecial) {

specialChoices.add(new BlockPos(this.spawnPos.getX() + x, this.spawnPos.getY() + y, this.spawnPos.getZ() + z));

isSpecial = false;

}

if (chunk == forChunk) {

if (!isSpecial)

world.setBlockState(curPos, chaos_unbreakable, 0);

else {

switch(meta) {

case 5:

world.setBlockState(curPos, chaos_special1, 0);

break;

case 6:

world.setBlockState(curPos, chaos_special2, 0);

break;

case 7:

world.setBlockState(curPos, chaos_special3, 0);

break;

}

}

} else {

if (chunkData == null)

chunkData = new HashMap<Integer, Map<Integer, IBlockState>>();

if (chunkData.get(forChunk) == null)

chunkData.put(forChunk, new HashMap<Integer, IBlockState>());

if (!isSpecial)

chunkData.get(forChunk).put((y * 1024) + (z * 32) + x, chaos_unbreakable);

else {

switch(meta) {

case 5:

chunkData.get(forChunk).put((y * 1024) + (z * 32) + x, chaos_special1);

break;

case 6:

chunkData.get(forChunk).put((y * 1024) + (z * 32) + x, chaos_special2);

break;

case 7:

chunkData.get(forChunk).put((y * 1024) + (z * 32) + x, chaos_special3);

break;

}

}

 

}

continue;

} else if (blockID == 0) {

if (chunk == forChunk) {

world.setBlockState(curPos, air, 0);

} else {

if (chunkData == null)

chunkData = new HashMap<Integer, Map<Integer, IBlockState>>();

if (chunkData.get(forChunk) == null)

chunkData.put(forChunk, new HashMap<Integer, IBlockState>());

chunkData.get(forChunk).put((y * 1024) + (z * 32) + x, air);

}

continue;

} else if (meta == 5 && blockID == 202) {

if (world.rand.nextInt(4) >= 3) {

meta++;

if (world.rand.nextInt(4) >= 3)

meta++;

}

if (chunk == forChunk) {

switch(meta) {

case 5:

world.setBlockState(curPos, chaos_special1, 0);

break;

case 6:

world.setBlockState(curPos, chaos_special2, 0);

break;

case 7:

world.setBlockState(curPos, chaos_special3, 0);

break;

}

} else {

if (chunkData == null)

chunkData = new HashMap<Integer, Map<Integer, IBlockState>>();

if (chunkData.get(forChunk) == null)

chunkData.put(forChunk, new HashMap<Integer, IBlockState>());

switch(meta) {

case 5:

chunkData.get(forChunk).put((y * 1024) + (z * 32) + x, chaos_special1);

break;

case 6:

chunkData.get(forChunk).put((y * 1024) + (z * 32) + x, chaos_special2);

break;

case 7:

chunkData.get(forChunk).put((y * 1024) + (z * 32) + x, chaos_special3);

break;

}

}

continue;

}

 

if (blockMap.get(new Integer[]{blockID, meta}) != null)

blockState = blockStates.get(blockMap.get(new Integer[]{blockID, meta}));

else {

blockMap.put(new Integer[]{blockID, meta}, blockIDs.size());

blockIDs.add(new Integer[]{blockID, meta});

switch (blockID) {

case 202:

blockState = ChaosBlock.blockChaos.getStateFromMeta(meta);

break;

case 211:

blockState = ChaosBlock.blockChaosStairsUnbreakable.getStateFromMeta(meta);

break;

case 235:

blockState = ChaosBlock.blockChaosDoorUnbreakableNormal.getStateFromMeta(meta)

.withProperty(ChaosBlock.blockChaosDoorUnbreakableNormal.POWERED, false);

break;

case 215:

blockState = ChaosBlock.blockChaosTrapdoorUnbreakable.getStateFromMeta(meta);

break;

case 217:

blockState = ChaosBlock.blockChaosLabyrinthThreshold.getStateFromMeta(meta);

break;

case 216:

blockState = ChaosBlock.blockChaosChestUnbreakable.getStateFromMeta(meta);

break;

case 218:

blockState = ChaosBlock.blockChaosGlass.getDefaultState();

break;

case 228:

blockState = ChaosBlock.blockChaosLabyrinthMobSpawner.getStateFromMeta(meta);

break;

case 237:

blockState = ChaosBlock.blockChaosDoorUnbreakableSpecial1.getStateFromMeta(meta)

.withProperty(ChaosBlock.blockChaosDoorUnbreakableSpecial1.POWERED, false);

break;

case 236:

blockState = ChaosBlock.blockChaosDoorUnbreakableSpecial2.getStateFromMeta(meta)

.withProperty(ChaosBlock.blockChaosDoorUnbreakableSpecial2.POWERED, false);

break;

case 234:

blockState = ChaosBlock.blockChaosDoorUnbreakableSpecial3.getStateFromMeta(meta)

.withProperty(ChaosBlock.blockChaosDoorUnbreakableSpecial3.POWERED, false);

break;

case 219:

blockState = ChaosBlock.blockChaosGlassPane.getDefaultState();

break;

case 220:

blockState = ChaosBlock.blockChaosSand.getDefaultState();

break;

case 243:

blockState = ChaosBlock.blockChaosDoorUnbreakableSpecial4.getStateFromMeta(meta)

.withProperty(ChaosBlock.blockChaosDoorUnbreakableSpecial4.POWERED, false);

break;

default:

blockState = Block.getBlockById(blockID).getStateFromMeta(meta);

}

blockStates.add(blockState);

}

if ((chunk == forChunk)) {

if (blockID == 202 && meta == 3 && world.rand.nextInt(16) >= 15)

blockState = chaos_volatile_high;

world.setBlockState(curPos, blockState, 0);

if (blockID == 54)

initChest(world, curPos, false);

else if (blockID == 216)

initChest(world, curPos, true);

} else {

if (chunkData == null)

chunkData = new HashMap<Integer, Map<Integer, IBlockState>>();

if (chunkData.get(forChunk) == null)

chunkData.put(forChunk, new HashMap<Integer, IBlockState>());

index = (y * 1024) + (z * 32) + x;

if (blockID == 202 && meta == 3 && world.rand.nextInt(16) >= 15)

blockState = chaos_volatile_high;

chunkData.get(forChunk).put(index, blockState);

 

if (blockID == 54)

chunkChest.get(forChunk).add(index);

else if (blockID == 216)

chunkChaosChest.get(forChunk).add(index);

}

 

}

}

 

forChunk --;

}

 

}

 

chunksGenerated++;

 

if (chunksGenerated == 4) {

 

int entranceY = this.spawnPos.getY() + 46;

int compassX = this.compassPos.getX();

int compassY = this.compassPos.getY();

int compassZ = this.compassPos.getZ();

int checkY = entranceY;

boolean nextY = false;

 

for (int cy = entranceY - 2; cy < 127; cy++) {

for (int cz = compassZ - 3; cz < compassZ + 3; cz++) {

for (int cx = compassX - 3; cx < compassX + 3; cx++) {

if (entranceY < cy) {

BlockPos cpos = new BlockPos(cx, cy, cz);

IBlockState cstate = world.getBlockState(cpos);

if (cstate != air && cstate.getBlock() != Blocks.leaves &&

cstate.getBlock() != Blocks.leaves2) {

nextY = true;

for (int by = entranceY; by <= cy; by++) {

for (int bz = compassZ + 2; bz >= compassZ - 3; bz--) {

for (int bx = compassX - 3; bx <= compassX + 2; bx++) {

BlockPos bpos = new BlockPos(bx, by, bz);

if ((bx == compassX - 1 || bx == compassX) && (bz == compassZ - 1 || bz == compassZ)) {

if (bz == compassZ)

world.setBlockState(bpos, ladder);

else

world.setBlockState(bpos, air);

} else {

world.setBlockState(bpos, chaos_unbreakable);

 

if (bx == compassX - 3 || bx == compassX + 2 || bz == compassZ - 3 || bz == compassZ + 2) {

 

float chance = 0.618f;

int extend = 0;

EnumFacing facing = null;

EnumFacing facing2 = null;

 

while (world.rand.nextFloat() <= chance) {

 

if (bx == compassX - 3) {

facing = EnumFacing.WEST;

if (bz == compassZ - 3)

facing2 = EnumFacing.NORTH;

else if (bz == compassZ + 2)

facing2 = EnumFacing.SOUTH;

} else if (bz == compassZ - 3) {

facing = EnumFacing.NORTH;

if (bx == compassX + 2)

facing2 = EnumFacing.EAST;

} else if (bx == compassX + 2) {

facing = EnumFacing.EAST;

if (bz == compassZ + 2)

facing2 = EnumFacing.SOUTH;

} else

facing = EnumFacing.SOUTH;

 

world.setBlockState(bpos.offset(facing, ++extend), chaos);

if (facing2 != null)

world.setBlockState(bpos.offset(facing2, extend), chaos);

chance *= chance;

}

}

}

}

}

 

}

 

entranceY = cy;

break;

}

} else if (cy < entranceY && cz == compassZ &&

cx > compassX - 2 && cx < compassX + 1)

world.setBlockState(new BlockPos(cx, cy, cz), ladder);

}

 

if (nextY) {

nextY = false;

break;

}

}

}

 

for (int t = 0; t < 5; t++) {

 

int limit = 0;

IBlockState state = ChaosBlock.blockChaos.getStateFromMeta(t + 5);

 

switch(t) {

case 0:

limit = 25;

break;

case 1:

limit = 13;

break;

case 2:

limit = 6;

break;

case 3:

limit = 4;

break;

case 4:

limit = 2;

break;

}

 

for (int b = 0; b < limit; b++) {

int randPos = world.rand.nextInt(specialChoices.size());

BlockPos pos = specialChoices.get(randPos);

specialBlocks.put(t, pos);

specialChoices.remove(randPos);

world.setBlockState(pos, state, 0);

 

}

 

this.ChaosLabyrinthData.setSpecialBlocks(specialBlocks);

}

BlockPos deepExitPos = new BlockPos(spawnPos.getX() - 1, spawnPos.getY() + 1, spawnPos.getZ() + 30);

world.setBlockState(deepExitPos, air, 0);

world.setBlockState(deepExitPos.up(), air, 0);

ChaosLabyrinthData.setIsGenerated(true);

this.generated = true;

} else if (chunksGenerated == 1)

this.ChaosLabyrinthData.setSpecialChoices(specialChoices);

 

} catch (IOException e) {

}

    }

   

    public void initChest(World world, BlockPos pos, boolean isHighChest) {

    if (!isHighChest) {

TileEntityChest chestTE = (TileEntityChest) world.getTileEntity(pos);

boolean isDoubleChest = chestTE.adjacentChestXNeg != null || chestTE.adjacentChestXPos != null ||

chestTE.adjacentChestZNeg != null || chestTE.adjacentChestZPos != null;

WeightedRandomChestContent.generateChestContents(world.rand, info.getItems(world.rand), chestTE, info.getCount(world.rand) * ((!isDoubleChest) ? 1 : 2));

world.setTileEntity(pos, chestTE);

    } else {

    TileEntityChaosChest chestTEC = (TileEntityChaosChest) world.getTileEntity(pos);

    boolean isDoubleChaosChest = chestTEC.adjacentChestXNeg != null || chestTEC.adjacentChestXPos != null ||

chestTEC.adjacentChestZNeg != null || chestTEC.adjacentChestZPos != null;

    WeightedRandomChestContent.generateChestContents(world.rand, info_high.getItems(world.rand), chestTEC, info_high.getCount(world.rand) * ((!isDoubleChaosChest) ? 1 : 2));

world.setTileEntity(pos, chestTEC);

    }

    }

}

 

 

Posted

When you register your worldGenerator (using GameRegistry.registerWorldGenerator()), you can specify a 'weight', which basically means the higher the number, the later your generator will generate.

If you use a high number there (Integer.MAX_VALUE ;)) your generator should be the last one to add it's worldGen.

I made the Mob Particles mod, you can check it out here: http://www.minecraftforum.net/topic/2709242-172-forge-mob-particles/

Posted

When you register your worldGenerator (using GameRegistry.registerWorldGenerator()), you can specify a 'weight', which basically means the higher the number, the later your generator will generate.

If you use a high number there (Integer.MAX_VALUE ;)) your generator should be the last one to add it's worldGen.

 

Thank you! I will try this.

 

Edit: I have only tried a few generations but it hasn't happened so far. If I don't come back to this thread then that likely means it worked.

Posted

You can stop trying, it won't.

The number only relates to the order of IWorldGenerators, so modded generators. Vanilla has nothing to do with this.

 

Yeah, I figured out it doesn't work. So how can it be done then? (assuming it's possible)

Posted

I've tried every Forge world gen event hook there is and none of them work 100% - mineshafts, ravines, and other multi-chunk structures / terrain features (such as lakes >.<) still destroy my structures from time to time.

 

PopulateChunkEvent.Post is supposed to fire after everything else has generated (and it does, in the code), but it's still not bulletproof.

 

You can stop lakes from breaking your stuff setting PopulateChunkEvent.Populate to DENY for EventType.LAKE if your structure is in or around the current chunk.

 

Based on my experiences testing various things (as opposed to minutely dissecting the actual code, though I've done a fair amount of that as well), it seems that mineshafts and other such features have a 'start' chunk that triggers them to generate in their entirety, so in that one chunk you have the normal Forge event hook progression, but every other chunk that it generates in is completely outside of the normal flow.

 

Obviously that's not completely true, otherwise lakes wouldn't be posting the Populate event, but I haven't been able to figure out in all this time how to stop mineshafts and such from doing what they do. I'm probably just not looking in the right places, but I've traced the hell out of the world gen code multiple times and still can't figure out how to prevent it, so if you (or anyone else) does figure it out, please share!

Posted

I've tried every Forge world gen event hook there is and none of them work 100% - mineshafts, ravines, and other multi-chunk structures / terrain features (such as lakes >.<) still destroy my structures from time to time.

 

PopulateChunkEvent.Post is supposed to fire after everything else has generated (and it does, in the code), but it's still not bulletproof.

 

You can stop lakes from breaking your stuff setting PopulateChunkEvent.Populate to DENY for EventType.LAKE if your structure is in or around the current chunk.

 

Based on my experiences testing various things (as opposed to minutely dissecting the actual code, though I've done a fair amount of that as well), it seems that mineshafts and other such features have a 'start' chunk that triggers them to generate in their entirety, so in that one chunk you have the normal Forge event hook progression, but every other chunk that it generates in is completely outside of the normal flow.

 

Obviously that's not completely true, otherwise lakes wouldn't be posting the Populate event, but I haven't been able to figure out in all this time how to stop mineshafts and such from doing what they do. I'm probably just not looking in the right places, but I've traced the hell out of the world gen code multiple times and still can't figure out how to prevent it, so if you (or anyone else) does figure it out, please share!

 

I found your thread about this earlier and also saw the disappointing results of other threads. Doing something like this really should be possible. I doubt I'll be the one to figure it out if there even is a way so I hope someone comes along that has. If there isn't a way then maybe forge needs a new event hook?

Posted

As a really hacky solution that might work, what if you used the chunk populate event to start a timer, and instead of immediately building your structure, build it some ticks later. I'm not sure if a chunk can be guaranteed to complete generation in a certain number of ticks, but worst case it still might work. Actually, possibly better would be to both build your structure once during the generation and then again after some time. That should avoid making visual glitches most of the times.

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

Posted

As a really hacky solution that might work, what if you used the chunk populate event to start a timer, and instead of immediately building your structure, build it some ticks later. I'm not sure if a chunk can be guaranteed to complete generation in a certain number of ticks, but worst case it still might work. Actually, possibly better would be to both build your structure once during the generation and then again after some time. That should avoid making visual glitches most of the times.

 

Building my structure in chunk populate seems to have worked judging by the image below. I've seen mine shafts stop right before my structure before so I'm not entirely sure my problem is solved but I haven't had it happen since so it looks promising.

 

uMPMN7H.png

Posted

Building my structure in chunk populate seems to have worked judging by the image below. I've seen mine shafts stop right before my structure before so I'm not entirely sure my problem is solved but I haven't had it happen since so it looks promising.

 

Awesome. Always good to learn a new trick that is useful to the modding community.

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

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.