Skip to content

Instantly share code, notes, and snippets.

@EDDxample
Created January 4, 2019 00:19
Show Gist options
  • Save EDDxample/1019107f377181ab9d888a5d04f56215 to your computer and use it in GitHub Desktop.
Save EDDxample/1019107f377181ab9d888a5d04f56215 to your computer and use it in GitHub Desktop.
Minecraft mod that adds tools for dungeon generation
package edd;
import java.util.ArrayList;
import java.util.Random;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class DungeonTool
{
private static long seed;
private static int cx, cz;
private static World world;
private static ArrayList<BlockPos> spawners = new ArrayList<BlockPos>(8);
private static final IBlockState A = Blocks.AIR.getDefaultState(),
B = Blocks.STAINED_GLASS.getStateFromMeta(15),
W = Blocks.STAINED_GLASS.getStateFromMeta(0),
R = Blocks.STAINED_GLASS.getStateFromMeta(14),
Y = Blocks.STAINED_GLASS.getStateFromMeta(4),
G = Blocks.STAINED_GLASS.getStateFromMeta(8),
O = Blocks.STAINED_GLASS.getStateFromMeta(1);
private static Random rng = new Random();
public static void setChunk(int x, int z)
{
cx = x;
cz = z;
}
public static void setAndSkip()
{
rng.setSeed(seed);
long i = rng.nextLong() / 2L * 2L + 1L,
j = rng.nextLong() / 2L * 2L + 1L;
rng.setSeed((long)cx * i + (long)cz * j ^ seed);
/* Water Lakes*/
if (rng.nextInt(4) == 0)
{
rng.nextInt();
rng.nextInt();
rng.nextInt();
for (int k = 0; k < (rng.nextInt(4) + 4) * 6; k++) rng.nextDouble();
}
/* Lava Lakes */
if (rng.nextInt(8) == 0)
{
rng.nextInt();
int k = rng.nextInt(rng.nextInt(248) + 8);
rng.nextInt();
if ((k < 63) || (rng.nextInt(10) == 0))
{
k = rng.nextInt(4) + 4;
for (int i1 = 0; i1 < k * 6; i1++) rng.nextDouble();
}
}
}
public static void clearSpawners()
{
for (BlockPos pos : spawners)
{
for (int iterX = -4; iterX <= 4; iterX++)
{
for (int iterY = -2; iterY <= 0; iterY++)
{
for (int iterZ = -4; iterZ <= 4; iterZ++)
{
BlockPos tempPos = pos.add(iterX, iterY == -2 ? 4 : iterY, iterZ);
if (world.getBlockState(tempPos) != R && world.getBlockState(tempPos).getBlock() == Blocks.STAINED_GLASS) world.setBlockState(tempPos, A);
}
}
}
}
spawners.clear();
}
public static void populate()
{
world.provider.createChunkGenerator().populate(cx, cz);
}
public static void recreate()
{
loadStuff();
clearSpawners();
setAndSkip();
for (int i = 0; i < 8; i++)
{
int x = rng.nextInt(16) + 8 + (cx << 4),
y = rng.nextInt(256),
z = rng.nextInt(16) + 8 + (cz << 4);
int radX = rng.nextInt(2) + 2,
radZ = rng.nextInt(2) + 2;
int fromX = -radX - 1,
fromZ = -radZ - 1,
toX = radX + 1,
toZ = radZ + 1;
BlockPos spawnerPos = new BlockPos(x, y, z);
spawners.add(spawnerPos);
if (i == 0 && world.getBlockState(spawnerPos) == A) {world.setBlockState(spawnerPos, Blocks.STAINED_GLASS.getStateFromMeta(9));}
else if (world.getBlockState(spawnerPos) == A) {world.setBlockState(spawnerPos, B);}
/* Stone Check and Structure Generation */
for (int iterX = fromX; iterX <= toX; iterX++)
{
for (int iterZ = fromZ; iterZ <= toZ; iterZ++)
{
BlockPos tempPos = spawnerPos.add(iterX, -1, iterZ);
if (world.getBlockState(tempPos) == R) rng.nextInt(4);
else if (world.getBlockState(tempPos) == A) world.setBlockState(tempPos, W);
if (world.getBlockState(tempPos.add(0, 5, 0)) == A) world.setBlockState(tempPos.add(0, 5, 0), G);
}
}
/* Chest Check */
if (world.getBlockState(spawnerPos) == Blocks.DIAMOND_BLOCK.getDefaultState())
{
for (int j = 0; j < 2; j++)
{
for (int k = 0; k < 3; k++)
{
int chestX = x + rng.nextInt(radX * 2 + 1) - radX,
chestZ = z + rng.nextInt(radZ * 2 + 1) - radZ;
BlockPos chestPos = new BlockPos(chestX, y, chestZ);
if (world.isAirBlock(chestPos))
{
int j3 = 0;
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
{
if (world.getBlockState(chestPos.offset(enumfacing)).getMaterial().isSolid())
{
++j3;
}
}
if (j3 == 1)
{
rng.nextLong();
world.setBlockState(chestPos, Y);
break;
}
else
{
world.setBlockState(chestPos, O);
}
}
}
}
/* Spawner Check */
rng.nextInt(4);
}
}
}
public static void loadStuff()
{
world = Minecraft.getMinecraft().getIntegratedServer().getWorld(0);
seed = world.getSeed();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment