server client split world classes

This commit is contained in:
Sen 2025-05-13 17:02:57 +02:00
parent 66e9f68eee
commit 6e77090c5b
247 changed files with 1309 additions and 1187 deletions

View file

@ -20,7 +20,6 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
import common.IServer;
import common.collect.Lists;
import common.collect.Maps;
import common.color.TextColor;
@ -73,9 +72,7 @@ import common.util.Position;
import common.util.Tuple;
import common.util.Util;
import common.util.WorldPos;
import common.world.Region;
import common.world.World;
import common.world.WorldServer;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelException;
@ -94,8 +91,10 @@ import server.command.FixedExecutor;
import server.network.HandshakeHandler;
import server.network.Player;
import server.world.Converter;
import server.world.Region;
import server.world.WorldServer;
public final class Server implements IThreadListener, IServer {
public final class Server implements IThreadListener {
private static final LazyLoadBase<NioEventLoopGroup> SERVER_NIO_EVENTLOOP = new LazyLoadBase<NioEventLoopGroup>() {
protected NioEventLoopGroup load() {
return new NioEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Server IO #%d").setDaemon(true).build());
@ -144,7 +143,7 @@ public final class Server implements IThreadListener, IServer {
Util.checkOs();
Registry.setup("Server thread");
boolean debug = System.getProperty("server.debug", null) != null;
boolean ipc = debug || System.getProperty("server.pipe", null) != null;
boolean ipc = System.getProperty("server.pipe", null) != null;
int port = Integer.parseInt(System.getProperty("server.port", "" + Config.PORT));
final Server server = new Server(debug, ipc);
Registry.addShutdownHook(new Runnable() {
@ -192,7 +191,7 @@ public final class Server implements IThreadListener, IServer {
NBTTagCompound tag = NBTLoader.readGZip(file);
NBTTagCompound cfg = tag.getCompoundTag("Config");
for(String key : cfg.getKeySet()) {
Config.set(key, cfg.getString(key), null);
Config.set(key, cfg.getString(key), false);
}
UniverseRegistry.loadNbt(tag.getCompoundTag("Universe"));
long lastPlayed = tag.getLong("LastAccess");
@ -217,6 +216,21 @@ public final class Server implements IThreadListener, IServer {
private Server(boolean debug, boolean ipc) {
this.debug = debug;
this.ipcpipe = ipc;
Config.setCallback(new Runnable() {
public void run() {
for(WorldServer world : Server.this.getWorlds()) {
world.updatePhysics();
}
Server.this.sendPacket(new SPacketWorld(WorldServer.clampGravity(), Config.dayCycle, Config.timeFlow));
}
}, "daylightCycle", "timeFlow", "gravity");
Config.setCallback(new Runnable() {
public void run() {
for(WorldServer world : Server.this.getWorlds()) {
world.updateViewRadius();
}
}
}, "viewDistance");
}
public CommandEnvironment getScriptEnvironment() {
@ -353,10 +367,10 @@ public final class Server implements IThreadListener, IServer {
else {
Config.clear();
UniverseRegistry.clear();
Config.set("daylightCycle", "false", null);
Config.set("weatherChanges", "false", null);
Config.set("mobSpawning", "false", null);
Config.set("spawnRadius", "0", null);
Config.set("daylightCycle", "false", false);
Config.set("weatherChanges", "false", false);
Config.set("mobSpawning", "false", false);
Config.set("spawnRadius", "0", false);
this.worlds.add(this.space = new WorldServer(this, World.START_TIME,
Space.INSTANCE, true));
this.dimensions.put(this.space.dimension.getDimensionId(), this.space);
@ -565,7 +579,7 @@ public final class Server implements IThreadListener, IServer {
}
this.networkTick();
if(++this.pingTimer > 600) {
this.sendPacket(new S38PacketPlayerListItem(this.getIPlayers()));
this.sendPacket(new S38PacketPlayerListItem((List)this.getPlayers()));
this.pingTimer = 0;
}
if(Config.saveInterval > 0 && ++this.saveTimer >= Config.saveInterval) {
@ -653,10 +667,6 @@ public final class Server implements IThreadListener, IServer {
return this.players;
}
public List<IPlayer> getIPlayers() {
return (List)this.players;
}
public Player getPlayer(String user) {
return this.usermap.get(user);
}
@ -676,7 +686,7 @@ public final class Server implements IThreadListener, IServer {
public void setVar(String cv, String value) {
this.schedule(new Runnable() {
public void run() {
Config.set(cv, value, Server.this);
Config.set(cv, value, true);
}
});
}
@ -773,7 +783,7 @@ public final class Server implements IThreadListener, IServer {
}
});
}
connection.sendPacket(new RPacketLoginSuccess());
connection.sendPacket(new RPacketLoginSuccess(this.debug));
connection.setNetHandler(conn);
this.players.add(conn);
this.usermap.put(loginUser, conn);
@ -827,7 +837,7 @@ public final class Server implements IThreadListener, IServer {
EntityNPC player = conn.getEntity();
player.unmount();
this.writePlayer(conn);
WorldServer world = player.getServerWorld();
WorldServer world = (WorldServer)player.getServerWorld();
world.removeEntity(player);
world.removePlayer(player);
this.players.remove(conn);
@ -836,7 +846,7 @@ public final class Server implements IThreadListener, IServer {
}
private void preparePlayer(EntityNPC player, WorldServer oldWorld) {
WorldServer newWorld = player.getServerWorld();
WorldServer newWorld = (WorldServer)player.getServerWorld();
if(oldWorld != null) {
oldWorld.removePlayer(player);
}
@ -1000,7 +1010,7 @@ public final class Server implements IThreadListener, IServer {
}
public void transferToDimension(EntityNPC player, int dimension, BlockPos pos, float yaw, float pitch, PortalType portal) {
WorldServer oldWorld = player.getServerWorld(); // this.getWorld(player.dimension);
WorldServer oldWorld = (WorldServer)player.getServerWorld(); // this.getWorld(player.dimension);
// player.dimension = dimension;
WorldServer newWorld = this.getWorld(dimension);
player.connection.sendPacket(new SPacketRespawn(newWorld.dimension, EntityRegistry.getEntityID(player), player.connection.isInEditor()));

View file

@ -0,0 +1,167 @@
package server.clipboard;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import common.block.Block;
import common.block.BlockDoor;
import common.block.BlockRailBase;
import common.block.ITileEntityProvider;
import common.clipboard.ClipboardBlock;
import common.collect.Lists;
import common.init.Blocks;
import common.init.ReorderRegistry;
import common.inventory.IInventory;
import common.tileentity.TileEntity;
import common.util.BlockPos;
import common.util.Vec3i;
import server.world.WorldServer;
public class ClipboardPlacer {
private static class BlockEntry {
private final BlockPos pos;
private final ClipboardBlock block;
private BlockEntry(BlockPos pos, ClipboardBlock block) {
this.pos = pos;
this.block = block;
}
}
private final WorldServer world;
private final List<BlockEntry> stage1 = Lists.newArrayList();
private final List<BlockEntry> stage2 = Lists.newArrayList();
private final List<BlockEntry> stage3 = Lists.newArrayList();
public ClipboardPlacer(WorldServer world) {
this.world = world;
}
public void setBlock(BlockPos location, ClipboardBlock block) {
if(location.getY() < 0 || location.getY() > 511)
return;
Block type = block.getState().getBlock();
if (ReorderRegistry.shouldPlaceLast(type)) {
// Place torches, etc. last
this.stage2.add(new BlockEntry(location, block));
} else if (ReorderRegistry.shouldPlaceFinal(type)) {
// Place signs, reed, etc even later
this.stage3.add(new BlockEntry(location, block));
} else if (ReorderRegistry.shouldPlaceLast(this.world.getState(location).getBlock())) {
// Destroy torches, etc. first
this.setBlockQuirk(location, new ClipboardBlock(Blocks.air.getState()));
this.setBlockQuirk(location, block);
} else {
this.stage1.add(new BlockEntry(location, block));
}
}
private boolean setBlockQuirk(BlockPos location, ClipboardBlock block) {
Block existing = this.world.getState(location).getBlock();
if (existing instanceof ITileEntityProvider) {
TileEntity tile = this.world.getTileEntity(location);
if ((tile instanceof IInventory)) {
IInventory inv = (IInventory) tile;
int size = inv.getSizeInventory();
for (int i = 0; i < size; i++) {
inv.setInventorySlotContents(i, null);
}
}
}
else if (existing == Blocks.ice) {
this.world.setBlock(location, new ClipboardBlock(Blocks.air.getState())); // Ice turns until water so this has to be done first
}
return this.world.setBlock(location, block);
}
public void commit() {
// Iterator<Entry<BlockEntry>> iterator = Iterators.concat(this.stage1.iterator(), this.stage2.iterator());
// while (iterator.hasNext()) {
// Map.Entry<BlockPos, EditBlock> entry = iterator.next();
//
// }
for(BlockEntry entry : this.stage1) {
this.setBlockQuirk(entry.pos, entry.block);
}
this.stage1.clear();
for(BlockEntry entry : this.stage2) {
this.setBlockQuirk(entry.pos, entry.block);
}
this.stage2.clear();
final Set<BlockPos> blocks = new HashSet<BlockPos>();
final Map<BlockPos, ClipboardBlock> blockTypes = new HashMap<BlockPos, ClipboardBlock>();
for(BlockEntry entry : this.stage3) {
// final BlockPos pt = entry.getKey();
blocks.add(entry.pos);
blockTypes.put(entry.pos, entry.block);
}
this.stage3.clear();
while (!blocks.isEmpty()) {
BlockPos current = blocks.iterator().next();
if (!blocks.contains(current)) {
continue;
}
final Deque<BlockPos> walked = new LinkedList<BlockPos>();
while (true) {
walked.addFirst(current);
assert (blockTypes.containsKey(current));
final ClipboardBlock baseBlock = blockTypes.get(current);
final Block type = baseBlock.getState().getBlock();
if(type instanceof BlockDoor) {
if (baseBlock.getState().getValue(BlockDoor.HALF) == BlockDoor.EnumDoorHalf.LOWER) {
// Deal with lower door halves being attached to the floor AND the upper half
BlockPos upperBlock = current.add(0, 1, 0);
if (blocks.contains(upperBlock) && !walked.contains(upperBlock)) {
walked.addFirst(upperBlock);
}
}
}
else if(type instanceof BlockRailBase) {
// Here, rails are hardcoded to be attached to the block below them.
// They're also attached to the block they're ascending towards via BlockType.getAttachment.
BlockPos lowerBlock = current.add(0, -1, 0);
if (blocks.contains(lowerBlock) && !walked.contains(lowerBlock)) {
walked.addFirst(lowerBlock);
}
break;
}
final Vec3i attachment = ReorderRegistry.getAttachment(baseBlock.getState());
if (attachment == null) {
// Block is not attached to anything => we can place it
break;
}
current = current.add(attachment);
if (!blocks.contains(current)) {
// We ran outside the remaining set => assume we can place blocks on this
break;
}
if (walked.contains(current)) {
// Cycle detected => This will most likely go wrong, but there's nothing we can do about it.
break;
}
}
for(BlockPos pt : walked) {
this.setBlockQuirk(pt, blockTypes.get(pt));
blocks.remove(pt);
}
}
}
}

View file

@ -11,8 +11,8 @@ import common.entity.Entity;
import common.entity.EntityType;
import common.entity.types.EntityLiving;
import common.init.EntityRegistry;
import common.world.WorldServer;
import server.network.Player;
import server.world.WorldServer;
public class EntityListParser extends EntityParser {
public EntityListParser(String name, boolean useSender, boolean livingOnly) {

View file

@ -6,7 +6,7 @@ import java.util.List;
import common.collect.Lists;
import common.entity.Entity;
import common.entity.types.EntityLiving;
import common.world.WorldServer;
import server.world.WorldServer;
public class EntityParser extends PlayerEntityParser {
protected final boolean livingOnly;

View file

@ -5,7 +5,7 @@ import java.util.List;
import common.collect.Lists;
import common.dimension.Dimension;
import common.world.WorldServer;
import server.world.WorldServer;
public class WorldParser extends DimensionParser {
private final boolean loadedOnly;

View file

@ -11,12 +11,12 @@ import common.init.EntityRegistry;
import common.nbt.NBTTagCompound;
import common.util.Util;
import common.util.Vec3;
import common.world.WorldServer;
import server.command.Command;
import server.command.CommandEnvironment;
import server.command.Executor;
import server.command.RunException;
import server.network.Player;
import server.world.WorldServer;
public class CommandSpawn extends Command {
public CommandSpawn() {

View file

@ -3,11 +3,11 @@ package server.command.commands;
import common.dimension.Dimension;
import common.item.ItemSpaceNavigator;
import common.util.Position;
import common.world.WorldServer;
import server.command.Command;
import server.command.CommandEnvironment;
import server.command.Executor;
import server.command.RunException;
import server.world.WorldServer;
public class CommandTime extends Command {
public CommandTime() {

View file

@ -1,11 +1,11 @@
package server.command.commands;
import common.world.Weather;
import common.world.WorldServer;
import server.command.Command;
import server.command.CommandEnvironment;
import server.command.Executor;
import server.command.RunException;
import server.world.WorldServer;
public class CommandWeather extends Command {
public CommandWeather() {

View file

@ -4,10 +4,10 @@ import java.util.List;
import common.entity.Entity;
import common.util.BlockPos;
import common.world.WorldServer;
import server.command.Command;
import server.command.CommandEnvironment;
import server.command.Executor;
import server.world.WorldServer;
public class CommandWorld extends Command {
public CommandWorld() {

View file

@ -14,7 +14,6 @@ import common.block.BlockFenceGate;
import common.block.BlockWall;
import common.clipboard.BlockTransform;
import common.clipboard.ClipboardBlock;
import common.clipboard.ClipboardPlacer;
import common.clipboard.Rotation;
import common.clipboard.RotationValue;
import common.clipboard.Vector;
@ -126,14 +125,15 @@ import common.util.Vec3i;
import common.util.WorldPos;
import common.village.MerchantRecipeList;
import common.world.Chunk;
import common.world.Region;
import common.world.State;
import common.world.World;
import common.world.WorldServer;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import server.Server;
import server.clipboard.ClipboardPlacer;
import server.command.Executor;
import server.world.Region;
import server.world.WorldServer;
public class Player extends NetHandler implements ICrafting, Executor, IPlayer
{
@ -580,6 +580,10 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer
this.sendPacket(new SPacketMessage(String.format(format, args), Type.HOTBAR));
}
private WorldServer getEntityWorld() {
return (WorldServer)this.entity.getServerWorld();
}
public void sendPickupMessage(Entity entity, int amount) {
if(entity instanceof EntityItem)
if(amount == 1)
@ -1363,7 +1367,7 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer
int ny = this.clipboard[0].length;
int nz = this.clipboard[0][0].length;
BlockPos to = this.entity.getPosition();
ClipboardPlacer placer = new ClipboardPlacer(this.entity.getServerWorld());
ClipboardPlacer placer = new ClipboardPlacer((WorldServer)this.entity.getServerWorld());
BlockTransform transform = null;
if(this.rotation != 0 || this.flipX || this.flipZ) {
transform = new BlockTransform();
@ -1448,7 +1452,7 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer
if(this.selectionDim == Integer.MIN_VALUE || this.selectionDim != this.entity.worldObj.dimension.getDimensionId() ||
this.selPos1 == null || this.selPos2 == null)
return false;
WorldServer source = this.entity.getServerWorld();
WorldServer source = this.getEntityWorld();
int mx = Math.min(this.selPos1.getX(), this.selPos2.getX());
int my = Math.min(this.selPos1.getY(), this.selPos2.getY());
int mz = Math.min(this.selPos1.getZ(), this.selPos2.getZ());
@ -1749,7 +1753,7 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer
return true;
}
}
Config.set(args[0], value, this.server);
Config.set(args[0], value, true);
this.addConsole(TextColor.YELLOW + "%s" + TextColor.GRAY + " -> " + ((cv.type == ValueType.BOOLEAN ? (cv.getValue().equals("true") ? TextColor.GREEN : TextColor.RED) : (cv.type == ValueType.STRING ? TextColor.NEON : TextColor.BLUE))) + "%s", args[0], cv.type == ValueType.STRING ? ("'" + cv.getValue() + "'") : cv.getValue());
}
return true;
@ -2071,7 +2075,7 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer
}
else
{
WorldServer worldserver = this.entity.getServerWorld(); // this.serverController.getWorld(this.playerEntity.dimension);
WorldServer worldserver = this.getEntityWorld(); // this.serverController.getWorld(this.playerEntity.dimension);
// this.updated = true;
double d0 = this.entity.posX;
@ -2308,7 +2312,7 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer
NetHandler.checkThread(packetIn, this, this.server);
if(this.charEditor)
return;
WorldServer worldserver = this.entity.getServerWorld(); // this.serverController.getWorld(this.playerEntity.dimension);
WorldServer worldserver = this.getEntityWorld(); // this.serverController.getWorld(this.playerEntity.dimension);
BlockPos blockpos = packetIn.getPosition();
switch (packetIn.getStatus())
@ -2394,7 +2398,7 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer
NetHandler.checkThread(packetIn, this, this.server);
if(this.charEditor)
return;
WorldServer worldserver = this.entity.getServerWorld(); // this.serverController.getWorld(this.playerEntity.dimension);
WorldServer worldserver = this.getEntityWorld(); // this.serverController.getWorld(this.playerEntity.dimension);
ItemStack itemstack = this.entity.inventory.getCurrentItem();
boolean flag = false;
BlockPos blockpos = packetIn.getPosition();
@ -2461,7 +2465,7 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer
private void useEntity(int entityId, boolean interact)
{
WorldServer worldserver = this.entity.getServerWorld(); // this.serverController.getWorld(this.playerEntity.dimension);
WorldServer worldserver = this.getEntityWorld(); // this.serverController.getWorld(this.playerEntity.dimension);
Entity entity = worldserver.getEntityByID(entityId);
if (entity != null)
{
@ -3041,7 +3045,7 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer
if(this.charEditor)
return;
WorldServer worldserver = this.entity.getServerWorld(); // this.serverController.getWorld(this.playerEntity.dimension);
WorldServer worldserver = this.getEntityWorld(); // this.serverController.getWorld(this.playerEntity.dimension);
BlockPos blockpos = packetIn.getPosition();
if (worldserver.isBlockLoaded(blockpos))

View file

@ -0,0 +1,273 @@
package server.village;
import java.util.Iterator;
import java.util.List;
import common.block.Block;
import common.block.BlockDoor;
import common.collect.Lists;
import common.material.Material;
import common.nbt.NBTTagCompound;
import common.nbt.NBTTagList;
import common.util.BlockPos;
import common.util.Facing;
import common.village.Village;
import common.village.VillageDoorInfo;
import server.world.WorldServer;
public class VillageCollection
{
private final List<BlockPos> villagerPositionsList = Lists.<BlockPos>newArrayList();
private final List<VillageDoorInfo> newDoors = Lists.<VillageDoorInfo>newArrayList();
private final List<Village> villageList = Lists.<Village>newArrayList();
private int tickCounter;
private boolean dirty;
public VillageCollection(NBTTagCompound nbt) {
if(nbt != null) {
this.tickCounter = nbt.getInteger("Tick");
NBTTagList nbttaglist = nbt.getTagList("Villages", 10);
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
Village village = new Village();
village.readVillageDataFromNBT(nbttagcompound);
this.villageList.add(village);
}
}
}
public void addToVillagerPositionList(BlockPos pos)
{
if (this.villagerPositionsList.size() <= 64)
{
if (!this.positionInList(pos))
{
this.villagerPositionsList.add(pos);
}
}
}
public void tick(WorldServer world)
{
++this.tickCounter;
for (Village village : this.villageList)
{
village.tick(world, this.tickCounter);
}
this.removeAnnihilatedVillages();
this.dropOldestVillagerPosition(world);
this.addNewDoorsToVillageOrCreateVillage();
if (this.tickCounter % 400 == 0)
{
this.dirty = true;
}
}
private void removeAnnihilatedVillages()
{
Iterator<Village> iterator = this.villageList.iterator();
while (iterator.hasNext())
{
Village village = (Village)iterator.next();
if (village.isAnnihilated())
{
iterator.remove();
this.dirty = true;
}
}
}
public List<Village> getVillageList()
{
return this.villageList;
}
public Village getNearestVillage(BlockPos doorBlock, int radius)
{
Village village = null;
double d0 = 3.4028234663852886E38D;
for (Village village1 : this.villageList)
{
double d1 = village1.getCenter().distanceSq(doorBlock);
if (d1 < d0)
{
float f = (float)(radius + village1.getRadius());
if (d1 <= (double)(f * f))
{
village = village1;
d0 = d1;
}
}
}
return village;
}
private void dropOldestVillagerPosition(WorldServer world)
{
if (!this.villagerPositionsList.isEmpty())
{
this.addDoorsAround(world, this.villagerPositionsList.remove(0));
}
}
private void addNewDoorsToVillageOrCreateVillage()
{
for (int i = 0; i < this.newDoors.size(); ++i)
{
VillageDoorInfo villagedoorinfo = (VillageDoorInfo)this.newDoors.get(i);
Village village = this.getNearestVillage(villagedoorinfo.getDoorBlockPos(), 32);
if (village == null)
{
village = new Village();
this.villageList.add(village);
this.dirty = true;
}
village.addDoor(villagedoorinfo);
}
this.newDoors.clear();
}
private void addDoorsAround(WorldServer world, BlockPos central)
{
int i = 16;
int j = 4;
int k = 16;
for (int l = -i; l < i; ++l)
{
for (int i1 = -j; i1 < j; ++i1)
{
for (int j1 = -k; j1 < k; ++j1)
{
BlockPos blockpos = central.add(l, i1, j1);
if (this.isWoodDoor(world, blockpos))
{
VillageDoorInfo villagedoorinfo = this.checkDoorExistence(blockpos);
if (villagedoorinfo == null)
{
this.addToNewDoorsList(world, blockpos);
}
else
{
villagedoorinfo.func_179849_a(this.tickCounter);
}
}
}
}
}
}
private VillageDoorInfo checkDoorExistence(BlockPos doorBlock)
{
for (VillageDoorInfo villagedoorinfo : this.newDoors)
{
if (villagedoorinfo.getDoorBlockPos().getX() == doorBlock.getX() && villagedoorinfo.getDoorBlockPos().getZ() == doorBlock.getZ() && Math.abs(villagedoorinfo.getDoorBlockPos().getY() - doorBlock.getY()) <= 1)
{
return villagedoorinfo;
}
}
for (Village village : this.villageList)
{
VillageDoorInfo villagedoorinfo1 = village.getExistedDoor(doorBlock);
if (villagedoorinfo1 != null)
{
return villagedoorinfo1;
}
}
return null;
}
private void addToNewDoorsList(WorldServer world, BlockPos doorBlock)
{
Facing enumfacing = BlockDoor.getFacing(world, doorBlock);
Facing enumfacing1 = enumfacing.getOpposite();
int i = this.countBlocksCanSeeSky(world, doorBlock, enumfacing, 5);
int j = this.countBlocksCanSeeSky(world, doorBlock, enumfacing1, i + 1);
if (i != j)
{
this.newDoors.add(new VillageDoorInfo(doorBlock, i < j ? enumfacing : enumfacing1, this.tickCounter));
}
}
private int countBlocksCanSeeSky(WorldServer world, BlockPos centerPos, Facing direction, int limitation)
{
int i = 0;
for (int j = 1; j <= 5; ++j)
{
if (world.canSeeSky(centerPos.offset(direction, j)))
{
++i;
if (i >= limitation)
{
return i;
}
}
}
return i;
}
private boolean positionInList(BlockPos pos)
{
for (BlockPos blockpos : this.villagerPositionsList)
{
if (blockpos.equals(pos))
{
return true;
}
}
return false;
}
private boolean isWoodDoor(WorldServer world, BlockPos doorPos)
{
Block block = world.getState(doorPos).getBlock();
return block instanceof BlockDoor ? block.getMaterial() == Material.wood : false;
}
public NBTTagCompound writeToNBT()
{
NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger("Tick", this.tickCounter);
NBTTagList nbttaglist = new NBTTagList();
for (Village village : this.villageList)
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
village.writeVillageDataToNBT(nbttagcompound);
nbttaglist.appendTag(nbttagcompound);
}
nbt.setTag("Villages", nbttaglist);
this.dirty = false;
return nbt;
}
public boolean isDirty()
{
return this.dirty;
}
}

View file

@ -86,7 +86,6 @@ import common.tileentity.TileEntitySign;
import common.tileentity.TileEntitySkull;
import common.util.Facing;
import common.util.NibbleArray;
import common.world.Region;
import common.world.State;
import common.world.Weather;
import common.world.World;
@ -1148,7 +1147,7 @@ public abstract class Converter {
NBTTagCompound rules = nbt.getCompoundTag("GameRules");
for(Entry<String, String> rule : OLD_GAMERULES.entrySet()) {
if(rules.hasKey(rule.getKey(), 8))
Config.set(rule.getValue(), rules.getString(rule.getKey()), null);
Config.set(rule.getValue(), rules.getString(rule.getKey()), false);
}
}
Log.JNI.info("Speichere neue server.nbt ...");

View file

@ -0,0 +1,635 @@
package server.world;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;
import common.block.Block;
import common.collect.Lists;
import common.collect.Maps;
import common.entity.Entity;
import common.init.BlockRegistry;
import common.init.EntityRegistry;
import common.log.Log;
import common.nbt.NBTLoader;
import common.nbt.NBTTagCompound;
import common.nbt.NBTTagList;
import common.tileentity.TileEntity;
import common.util.BlockPos;
import common.util.NextTickListEntry;
import common.util.NibbleArray;
import common.util.Util;
import common.world.BlockArray;
import common.world.Chunk;
public class Region {
private static class ChunkBuffer extends ByteArrayOutputStream {
public ChunkBuffer() {
super(8096);
}
public byte[] getData() {
return this.buf;
}
}
static {
Thread thread = new Thread(new Runnable() {
public void run() {
while(!killed) {
processQueue();
}
}
}, "File IO Thread");
thread.setPriority(1);
thread.start();
}
private static final Map<String, Region> CACHE = Maps.<String, Region>newHashMap();
private static final List<WorldServer> QUEUE = Collections.<WorldServer>synchronizedList(Lists.<WorldServer>newArrayList());
private static volatile long queued;
private static volatile long saved;
private static volatile boolean waiting;
private static volatile boolean killed;
private final int[] timestamps = new int[64];
private final int[] positions = new int[64];
private final int[] sizes = new int[64];
private final File regFile;
private final File folder;
private final int xPos;
private final int zPos;
private RandomAccessFile file;
private long lastModified;
private int offset;
private boolean modified;
public Region(File dir, int x, int z) {
File sdir = new File(dir, Util.getRegionFolder(x << 3, z << 3));
if(!sdir.exists())
sdir.mkdirs();
this.regFile = new File(sdir, Util.getRegionName(x << 3, z << 3));
this.folder = dir;
this.xPos = x;
this.zPos = z;
try {
if(this.regFile.exists())
this.lastModified = this.regFile.lastModified();
this.file = new RandomAccessFile(this.regFile, "rw");
this.file.seek(0L);
if(this.file.length() < 512L) {
for(int i = 0; i < 64; i++) {
this.file.writeLong(0L);
}
}
else {
for(int i = 0; i < 64; i++) {
int end = this.positions[i] = this.file.readUnsignedShort();
end += ((this.sizes[i] = this.file.readUnsignedShort()) + 255) >> 8;
this.timestamps[i] = this.file.readInt();
if(end > this.offset)
this.offset = end;
}
}
}
catch(IOException e) {
e.printStackTrace();
}
}
private void reorganize(boolean reopen) throws IOException {
byte[] buffer = new byte[8192];
File tmp = new File(this.folder, this.regFile.getName() + ".tmp");
RandomAccessFile file = new RandomAccessFile(tmp, "rw");
int offset = 0;
for(int i = 0; i < 64; i++) {
file.writeShort(this.sizes[i] == 0 ? 0 : offset);
file.writeShort(this.sizes[i]);
file.writeInt(this.timestamps[i]);
offset += (this.sizes[i] + 255) >> 8;
}
this.offset = offset;
offset = 0;
for(int i = 0; i < 64; i++) {
int size = this.sizes[i];
if(size == 0) {
this.positions[i] = 0;
continue;
}
this.file.seek(512L + (long)(this.positions[i] << 8));
this.file.read(buffer, 0, size);
file.write(buffer, 0, size);
this.positions[i] = offset;
offset += (size + 255) >> 8;
file.seek(512L + (long)(offset << 8));
}
file.close();
this.file.close();
tmp.renameTo(this.regFile);
this.file = reopen ? new RandomAccessFile(this.regFile, "rw") : null;
this.modified = false;
}
private synchronized byte[] read(int x, int z) {
if(this.timestamps[x + z * 8] == 0)
return null;
FileInputStream in = null;
try {
// this.file.seek((long)(512 + (x + z * 8) * 8192));
int size = this.sizes[x + z * 8]; // this.file.readShort();
if(size > 8192 /* - 2 */ || size < 0) {
Log.JNI.warn("Chunk-Region-Datei " + this.regFile + " hat eine ungültige Größe bei " + x + ", " + z + ", überspringe");
return null;
}
byte[] data;
if(size == 0) {
File expand = getExpansionFile(this.folder, this.xPos * 8 + x, this.zPos * 8 + z);
if(!expand.exists()) {
Log.JNI.warn("Chunk-Erweiterungs-Datei " + expand + " ist nicht vorhanden oder nicht lesbar, überspringe");
return null;
}
in = new FileInputStream(expand);
data = new byte[(int)expand.length()];
int remain = data.length;
while(remain > 0) {
int n = Math.min(remain, 8192);
in.read(data, (data.length - remain), n);
remain -= n;
}
try {
if(in != null) {
in.close();
}
}
catch(IOException e) {
}
in = null;
}
else {
int pos = this.positions[x + z * 8] << 8;
if(pos + size > this.file.length() - 512L || pos < 0) {
Log.JNI.warn("Chunk-Region-Datei " + this.regFile + " hat eine ungültige Position bei " + x + ", " + z + ", überspringe");
return null;
}
this.file.seek(512L + (long)pos);
data = new byte[size]; // - 2];
this.file.read(data);
}
return data;
}
catch(IOException e) {
try {
if(in != null) {
in.close();
}
}
catch(IOException e1) {
}
Log.JNI.error(e, "Fehler beim lesen von Chunk-Region-Datei " + this.regFile + " bei " + x + ", " + z + ", überspringe");
return null;
}
}
private synchronized void write(int x, int z, byte[] data, int size) {
try {
if(((int)this.file.length() - 512) >= 1048576)
this.reorganize(true);
this.modified = true;
// if(size >= 8192)
// Log.DATA.info("REG " + x + ", " + z + ": " + size);
int pos = 0;
if(size /* + 2 */ > 8192) {
FileOutputStream out = null;
try {
out = new FileOutputStream(getExpansionFile(this.folder, this.xPos * 8 + x, this.zPos * 8 + z));
int remain = size;
while(remain > 0) {
int n = Math.min(remain, 8192);
out.write(data, (size - remain), n);
remain -= n;
}
}
catch(IOException e) {
e.printStackTrace();
}
try {
if(out != null) {
out.close();
}
}
catch(IOException e) {
}
data = new byte[0];
size = 0;
}
else {
pos = this.offset;
this.offset += (size + 255) >> 8;
this.file.seek(512L + (long)(pos << 8)); // (512 + (x + z * 8) * 8192));
// this.file.writeShort(size);
this.file.write(data, 0, size);
}
int time = (int)(System.currentTimeMillis() / 10000L);
this.timestamps[x + z * 8] = time;
this.positions[x + z * 8] = pos;
this.sizes[x + z * 8] = size;
this.file.seek((long)((x + z * 8) * 8));
this.file.writeShort(pos);
this.file.writeShort(size);
this.file.writeInt(time);
}
catch(IOException e) {
e.printStackTrace();
}
}
public synchronized void close(boolean reorg) throws IOException { // FIX ??
if(this.file != null) {
if(reorg && this.modified)
this.reorganize(false);
else
this.file.close();
this.file = null;
}
}
public long getTimestamp(int x, int z) {
return (long)this.timestamps[x + z * 8] * 10000L;
}
public void writeTag(int x, int z, NBTTagCompound tag) throws IOException {
ChunkBuffer buf = new ChunkBuffer();
DataOutputStream out = new DataOutputStream(new DeflaterOutputStream(buf));
NBTLoader.write(tag, out);
out.close();
this.write(x, z, buf.getData(), buf.size());
}
public File getFile() {
return this.regFile;
}
private static synchronized Region getRegionFile(File dir, int x, int z) {
Region reg = CACHE.get(dir + "." + x + "." + z);
if(reg != null)
return reg;
if(CACHE.size() >= 256)
clearCache(false);
Region nreg = new Region(dir, x, z);
CACHE.put(dir + "." + x + "." + z, nreg);
return nreg;
}
private static File getExpansionFile(File dir, int x, int z) {
File sdir = new File(dir, Util.getRegionFolder(x, z));
if(!sdir.exists())
sdir.mkdirs();
return new File(sdir, String.format("c.%c%X%c%X.chk", x < 0 ? 'n' : 'p', (x < 0) ? -x : x, z < 0 ? 'n' : 'p', (z < 0) ? -z : z));
}
private static synchronized void clearCache(boolean all) {
if(all) {
for(Region reg : CACHE.values()) {
try {
reg.close(true);
}
catch(IOException e) {
e.printStackTrace();
}
}
CACHE.clear();
}
else {
Iterator<Region> iter = CACHE.values().iterator();
for(int z = 0; z < 8 && iter.hasNext(); z++) {
try {
iter.next().close(true);
}
catch(IOException e) {
e.printStackTrace();
}
iter.remove();
}
}
}
public static void finishWrite() {
waiting = true;
try {
while(queued != saved) {
Thread.sleep(10L);
}
}
catch(InterruptedException e) {
e.printStackTrace();
}
waiting = false;
clearCache(true);
}
public static /* synchronized */ NBTTagCompound readChunk(File dir, int x, int z) throws IOException {
// return getRegionFile(dir, x >> 3, z >> 3).readTag(x & 7, z & 7);
byte[] data = getRegionFile(dir, x >> 3, z >> 3).read(x & 7, z & 7);
if(data == null)
return null;
return NBTLoader.read(new DataInputStream(new BufferedInputStream(new InflaterInputStream(new ByteArrayInputStream(data)))));
}
public static /* synchronized */ void writeChunk(File dir, int x, int z, NBTTagCompound tag) throws IOException {
ChunkBuffer buf = new ChunkBuffer();
DataOutputStream out = new DataOutputStream(new DeflaterOutputStream(buf));
NBTLoader.write(tag, out);
out.close();
getRegionFile(dir, x >> 3, z >> 3).write(x & 7, z & 7, buf.getData(), buf.size());
// getRegionFile(dir, x >> 3, z >> 3).writeTag(x & 7, z & 7, tag);
}
public static Chunk readNbt(WorldServer world, int x, int z, NBTTagCompound tag) {
// if(!tag.hasKey("Level", 10)) {
// Log.error("Chunk-Datei bei " + x + "," + z + " hat keine Level-Daten, überspringe");
// return null;
// }
// tag = tag.getCompoundTag("Level");
if(!tag.hasKey("Sections", 9)) {
Log.JNI.warn("Chunk-Datei bei " + x + "," + z + " hat keine Block-Daten, überspringe");
return null;
}
Chunk chunk = new Chunk(world, x, z);
chunk.setHeights(tag.getIntArray("HeightMap"));
chunk.setTerrainPopulated(tag.getBoolean("TerrainPopulated"));
chunk.setLightPopulated(tag.getBoolean("LightPopulated"));
chunk.setInhabited(tag.getLong("InhabitedTime"));
NBTTagList sects = tag.getTagList("Sections", 10);
int stor = 32;
BlockArray[] sections = new BlockArray[stor];
boolean light = !world.dimension.hasNoLight();
for(int n = 0; n < sects.tagCount(); ++n) {
NBTTagCompound sect = sects.getCompoundTagAt(n);
int y = sect.getByte("Y");
BlockArray storage = new BlockArray(y << 4, light);
byte[] blocks = sect.getByteArray("Blocks");
NibbleArray data = new NibbleArray(sect.getByteArray("Data"));
NibbleArray adddata = sect.hasKey("Add", 7) ? new NibbleArray(sect.getByteArray("Add")) : null;
char[] seg = new char[blocks.length];
for(int c = 0; c < seg.length; ++c) {
int cx = c & 15;
int cy = c >> 8 & 15;
int cz = c >> 4 & 15;
int ca = adddata != null ? adddata.get(cx, cy, cz) : 0;
seg[c] = (char)(ca << 12 | (blocks[c] & 255) << 4 | data.get(cx, cy, cz));
}
storage.setData(seg);
storage.setBlocklight(new NibbleArray(sect.getByteArray("BlockLight")));
if(light) {
storage.setSkylight(new NibbleArray(sect.getByteArray("SkyLight")));
}
storage.update();
sections[y] = storage;
}
chunk.setStorage(sections);
if(tag.hasKey("Biomes", 7)) {
chunk.setBiomes(tag.getByteArray("Biomes"));
}
NBTTagList entities = tag.getTagList("Entities", 10);
if(entities != null) {
for(int n = 0; n < entities.tagCount(); ++n) {
NBTTagCompound ent = entities.getCompoundTagAt(n);
Entity entity = EntityRegistry.createEntityFromNBT(ent, world);
chunk.setHasEntities(true);
if(entity != null) {
chunk.addEntity(entity);
Entity rider = entity;
for(NBTTagCompound ride = ent; ride.hasKey("Riding", 10); ride = ride.getCompoundTag("Riding")) {
Entity pass = EntityRegistry.createEntityFromNBT(ride.getCompoundTag("Riding"), world);
if(pass != null) {
chunk.addEntity(pass);
rider.mountEntity(pass);
}
rider = pass;
}
}
}
}
NBTTagList tiles = tag.getTagList("TileEntities", 10);
if(tiles != null) {
for(int n = 0; n < tiles.tagCount(); ++n) {
NBTTagCompound tile = tiles.getCompoundTagAt(n);
TileEntity tileentity = TileEntity.createAndLoadEntity(tile);
if(tileentity != null) {
chunk.addTileEntity(tileentity);
}
}
}
if(tag.hasKey("TileTicks", 9)) {
NBTTagList ticks = tag.getTagList("TileTicks", 10);
if(ticks != null) {
int invalid = 0;
for(int n = 0; n < ticks.tagCount(); ++n) {
NBTTagCompound tick = ticks.getCompoundTagAt(n);
Block block;
if(tick.hasKey("i", 8)) {
block = BlockRegistry.getByIdFallback(tick.getString("i"));
}
else {
block = BlockRegistry.getBlockById(tick.getInteger("i"));
}
if(block != null) { // FIX
world.scheduleBlockUpdate(new BlockPos(tick.getInteger("x"), tick.getInteger("y"), tick.getInteger("z")), block,
tick.getInteger("t"), tick.getInteger("p"));
}
else if(invalid++ < 10) {
Log.JNI.warn("Unbekannter Block-Tick in Chunk " + x + "," + z + ": " +
(tick.hasKey("i", 8) ? ("'" + tick.getString("i") + "'") : ("#" + tick.getInteger("i"))));
}
}
if(invalid > 10) {
Log.JNI.warn((invalid - 10) + " weitere ...");
}
}
}
return chunk;
}
public static NBTTagCompound writeNbt(WorldServer world, Chunk chunk) {
NBTTagCompound tag = new NBTTagCompound();
// tag.setShort("V", (short)Config.PROTOCOL);
tag.setLong("LastUpdate", world.getTime());
tag.setIntArray("HeightMap", chunk.getHeights());
tag.setBoolean("TerrainPopulated", chunk.isTerrainPopulated());
tag.setBoolean("LightPopulated", chunk.isLightPopulated());
tag.setLong("InhabitedTime", chunk.getInhabited());
BlockArray[] sections = chunk.getStorage();
NBTTagList sects = new NBTTagList();
boolean light = !world.dimension.hasNoLight();
for(BlockArray storage : sections) {
if(storage != null) {
NBTTagCompound sect = new NBTTagCompound();
sect.setByte("Y", (byte)(storage.getY() >> 4 & 511));
byte[] blocks = new byte[storage.getData().length];
NibbleArray data = new NibbleArray();
NibbleArray adddata = null;
for(int c = 0; c < storage.getData().length; ++c) {
char cd = storage.getData()[c];
int cx = c & 15;
int cy = c >> 8 & 15;
int cz = c >> 4 & 15;
if(cd >> 12 != 0) {
if(adddata == null) {
adddata = new NibbleArray();
}
adddata.set(cx, cy, cz, cd >> 12);
}
blocks[c] = (byte)(cd >> 4 & 255);
data.set(cx, cy, cz, cd & 15);
}
sect.setByteArray("Blocks", blocks);
sect.setByteArray("Data", data.getData());
if(adddata != null) {
sect.setByteArray("Add", adddata.getData());
}
sect.setByteArray("BlockLight", storage.getBlocklight().getData());
if(light) {
sect.setByteArray("SkyLight", storage.getSkylight().getData());
}
else {
sect.setByteArray("SkyLight", new byte[storage.getBlocklight().getData().length]);
}
sects.appendTag(sect);
}
}
tag.setTag("Sections", sects);
tag.setByteArray("Biomes", chunk.getBiomes());
chunk.setHasEntities(false);
NBTTagList entities = new NBTTagList();
for(int n = 0; n < chunk.getEntities().length; ++n) {
for(Entity entity : chunk.getEntities()[n]) {
NBTTagCompound ent = new NBTTagCompound();
if(entity.writeToNBTOptional(ent)) {
chunk.setHasEntities(true);
entities.appendTag(ent);
}
}
}
tag.setTag("Entities", entities);
NBTTagList tiles = new NBTTagList();
for(TileEntity tileentity : chunk.getTiles().values()) {
NBTTagCompound tile = new NBTTagCompound();
tileentity.writeToNBT(tile);
tiles.appendTag(tile);
}
tag.setTag("TileEntities", tiles);
List<NextTickListEntry> tics = world.getPendingBlockUpdates(chunk);
if(tics != null) {
long time = world.getTime();
NBTTagList ticks = new NBTTagList();
for(NextTickListEntry tic : tics) {
NBTTagCompound tick = new NBTTagCompound();
String res = BlockRegistry.REGISTRY.getNameForObject(tic.getBlock());
tick.setString("i", res == null ? "" : res.toString());
tick.setInteger("x", tic.position.getX());
tick.setInteger("y", tic.position.getY());
tick.setInteger("z", tic.position.getZ());
tick.setInteger("t", (int)(tic.scheduledTime - time));
tick.setInteger("p", tic.priority);
ticks.appendTag(tick);
}
tag.setTag("TileTicks", ticks);
}
return tag;
}
private static void processQueue() {
for(int i = 0; i < QUEUE.size(); ++i) {
WorldServer loader = QUEUE.get(i);
boolean flag = loader.writeNextIO();
if(!flag) {
QUEUE.remove(i--);
++saved;
}
try {
Thread.sleep(waiting ? 0L : 10L);
}
catch(InterruptedException e) {
e.printStackTrace();
}
}
if(QUEUE.isEmpty()) {
try {
Thread.sleep(25L);
}
catch(InterruptedException e) {
e.printStackTrace();
}
}
}
public static void queueIO(WorldServer loader) {
if(!QUEUE.contains(loader)) {
++queued;
QUEUE.add(loader);
}
}
public static void killIO() {
killed = true;
}
}

View file

@ -0,0 +1,214 @@
package server.world;
import java.util.Set;
import common.biome.Biome;
import common.biome.RngSpawn;
import common.block.Block;
import common.collect.Sets;
import common.entity.npc.EntityNPC;
import common.entity.types.EntityLiving;
import common.entity.types.EntityWaterMob;
import common.init.Blocks;
import common.init.Config;
import common.rng.Random;
import common.rng.WeightedList;
import common.util.BlockPos;
import common.util.ChunkPos;
import common.util.ExtMath;
import common.world.Chunk;
import common.world.World;
public abstract class Spawner {
private static final int MOB_COUNT_DIV = (int)Math.pow(17.0D, 2.0D);
private static final Set<ChunkPos> CHUNKS = Sets.<ChunkPos>newHashSet();
public static boolean canSpawnAt(boolean water, WorldServer world, BlockPos pos) {
if(!World.isValidXZ(pos)) {
return false;
}
Block block = world.getState(pos).getBlock();
if(water) {
return block.getMaterial().isLiquid() && world.getState(pos.down()).getBlock().getMaterial().isLiquid()
&& !world.getState(pos.up()).getBlock().isNormalCube();
}
// else if(place == SpawnRegistry.Placement.IN_AIR) {
// return pos.getY() >= 118;
// }
else {
BlockPos down = pos.down();
if(!world.isBlockSolid(down)) {
return false;
}
else {
Block below = world.getState(down).getBlock();
return below != Blocks.bedrock && !block.isNormalCube() && !block.getMaterial().isLiquid()
&& !world.getState(pos.up()).getBlock().isNormalCube();
}
}
}
public static int spawn(WorldServer world) {
// if(!hostile && !peaceful) {
// return 0;
// }
CHUNKS.clear();
int locs = 0;
int range = Math.max(Config.mobSpawnDist, 1);
for(EntityNPC player : world.players) {
// if(Config.spectatorSpawning || !player.isSpectator()) {
int x = ExtMath.floord(player.posX / 16.0D);
int z = ExtMath.floord(player.posZ / 16.0D);
for(int cx = -range; cx <= range; ++cx) {
for(int cz = -range; cz <= range; ++cz) {
boolean flag = cx == -range || cx == range || cz == -range || cz == range;
ChunkPos coord = new ChunkPos(cx + x, cz + z);
if(!CHUNKS.contains(coord)) {
++locs;
if(!flag && coord.x << 4 >= -World.MAX_SIZE + 64 && coord.z << 4 >= -World.MAX_SIZE + 64
&& coord.x << 4 < World.MAX_SIZE - 64 && coord.z << 4 < World.MAX_SIZE - 64) {
CHUNKS.add(coord);
}
}
}
}
// }
}
// boolean animals = (time % Math.max(Config.animalSpawnDelay, 1)) == 0;
int spawned = 0;
int mobSpread = Math.max(Config.spawnGroupDist, 1);
// double spawnDist = (double)Config.mobSpawnDistance;
double playerDist = (double)Config.mobPlayerDist;
// BlockPos spawn = world.isPrimary() ? Server.getSpawnPoint() : null;
// for(EnumCreatureType type : EnumCreatureType.values()) {
// if((!type.isPeaceful() || peaceful) && (type.isPeaceful() || hostile) && (!type.isAnimal() || animals)) {
int cur = world.countEntities(EntityLiving.class);
int max = Config.maxMobs * locs / MOB_COUNT_DIV;
if(cur <= max) {
typeLabel:
for(ChunkPos coord : CHUNKS) {
Chunk chunk = world.getChunk(coord.x, coord.z);
int x = coord.x * 16 + world.rand.zrange(16);
int z = coord.z * 16 + world.rand.zrange(16);
int h = chunk.getHeight(new BlockPos(x, 0, z)) + 1;
if(h > 0) {
int m = h % 16;
h = m == 0 ? h : h + 16 - m;
}
h = h == 0 ? 16 : (h > 0 ? h : chunk.getTopSegment() + 16 - 1);
int y = world.rand.excl(h <= 8 ? 0 : 8, h);
BlockPos pos = new BlockPos(x, y, z);
Block block = world.getState(pos).getBlock();
if(!block.isNormalCube()) {
int group = 0;
Object data = null;
for(int n = 0; n < Config.spawnGroups; ++n) {
int mx = x;
int my = y;
int mz = z;
RngSpawn entry = null;
int cmax = 4;
for(int m = 0; m < cmax; ++m) {
mx += world.rand.zrange(mobSpread) - world.rand.zrange(mobSpread);
my += world.rand.zrange(1) - world.rand.zrange(1);
mz += world.rand.zrange(mobSpread) - world.rand.zrange(mobSpread);
BlockPos mpos = new BlockPos(mx, my, mz);
float fx = (float)mx + 0.5F;
float fz = (float)mz + 0.5F;
if(!world.isAnyPlayerWithinRangeAt((double)fx, (double)my, (double)fz, playerDist)) {
// && (spawn == null || spawn.distanceSq((double)fx, (double)my, (double)fz) >= spawnDist)) {
if(entry == null) {
entry = world.getSpawnListEntryForTypeAt(mpos);
if(entry == null) {
break;
}
cmax = m + entry.min + world.rand.zrange(1 + entry.max - entry.min);
}
if(world.canCreatureTypeSpawnHere(entry, mpos)
&& canSpawnAt(EntityWaterMob.class.isAssignableFrom(entry.type), world, mpos)) {
EntityLiving entity;
try {
entity = entry.type.getConstructor(World.class).newInstance(world);
}
catch(Exception e) {
e.printStackTrace();
return spawned + group;
}
entity.setLocationAndAngles((double)fx, (double)my, (double)fz, world.rand.floatv() * 360.0F, 0.0F);
if(entity.getCanSpawnHere() && entity.isNotColliding()) {
data = entity.onInitialSpawn(data);
if(entity.isNotColliding()) {
++group;
world.spawnEntityInWorld(entity);
}
if(group >= entity.getMaxChunkSpawns()) {
spawned += group;
continue typeLabel;
}
else if(!entity.isPropogatingSpawnData(m >= cmax - 1)) {
data = null;
}
}
}
}
}
}
spawned += group;
}
}
// }
// }
}
return spawned;
}
public static void generate(WorldServer world, Biome biome, int x, int z, int sx, int sz, Random rand) {
int iters = 0;
while(rand.floatv() < biome.getMobGenChance()) {
if(iters++ == 10)
break;
WeightedList<RngSpawn> list = biome.getMobs();
if(list.isEmpty()) {
continue;
}
RngSpawn entry = list.pick(world.rand);
int count = entry.min + rand.zrange(1 + entry.max - entry.min);
Object data = null;
int mx = x + rand.zrange(sx);
int mz = z + rand.zrange(sz);
int gx = mx;
int gz = mz;
for(int n = 0; n < count; ++n) {
boolean flag = false;
for(int m = 0; !flag && m < 4; ++m) {
BlockPos pos = world.getTopSolidOrLiquidBlock(new BlockPos(mx, 0, mz));
if(canSpawnAt(EntityWaterMob.class.isAssignableFrom(entry.type), world, pos)) {
EntityLiving entity;
try {
entity = entry.type.getConstructor(World.class).newInstance(world);
}
catch(Exception e) {
e.printStackTrace();
continue;
}
entity.setLocationAndAngles((double)((float)mx + 0.5F), (double)pos.getY(), (double)((float)mz + 0.5F),
rand.floatv() * 360.0F, 0.0F);
if(entity.getCanSpawnHere() && entity.isNotColliding()) {
data = entity.onInitialSpawn(data);
if(entity.isNotColliding())
world.spawnEntityInWorld(entity);
if(!entity.isPropogatingSpawnData(false))
data = null;
flag = true;
}
}
mx += rand.zrange(5) - rand.zrange(5);
for(mz += rand.zrange(5) - rand.zrange(5); mx < x || mx >= x + sx || mz < z
|| mz >= z + sx; mz = gz + rand.zrange(5) - rand.zrange(5)) {
mx = gx + rand.zrange(5) - rand.zrange(5);
}
}
}
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,54 @@
package server.worldgen.structure;
import java.util.List;
import common.rng.Random;
import server.world.WorldServer;
public class MapGenBridge extends MapGenStructure
{
public String getStructureName()
{
return "Fortress";
}
protected boolean canSpawnStructureAtCoords(int chunkX, int chunkZ)
{
int i = chunkX >> 4;
int j = chunkZ >> 4;
this.rand.setSeed((long)(i ^ j << 4) ^ this.worldObj.getSeed());
this.rand.intv();
return this.rand.zrange(3) != 0 ? false : (chunkX != (i << 4) + 4 + this.rand.zrange(8) ? false : chunkZ == (j << 4) + 4 + this.rand.zrange(8));
}
protected StructureStart getStructureStart(int chunkX, int chunkZ)
{
return new MapGenBridge.Start(this.worldObj, this.rand, chunkX, chunkZ);
}
public static class Start extends StructureStart
{
public Start()
{
}
public Start(WorldServer worldIn, Random p_i2040_2_, int p_i2040_3_, int p_i2040_4_)
{
super(p_i2040_3_, p_i2040_4_);
StructureBridge.Start start = new StructureBridge.Start(p_i2040_2_, (p_i2040_3_ << 4) + 2, (p_i2040_4_ << 4) + 2);
this.components.add(start);
start.buildComponent(start, this.components, p_i2040_2_);
List<StructureComponent> list = start.field_74967_d;
while (!list.isEmpty())
{
int i = p_i2040_2_.zrange(list.size());
StructureComponent structurecomponent = (StructureComponent)list.remove(i);
structurecomponent.buildComponent(start, this.components, p_i2040_2_);
}
this.updateBoundingBox();
this.setRandomHeight(worldIn, p_i2040_2_, 48, 70);
}
}
}

View file

@ -0,0 +1,36 @@
package server.worldgen.structure;
public class MapGenMineshaft extends MapGenStructure
{
private double chance = 0.004D;
// public MapGenMineshaft()
// {
// }
public String getStructureName()
{
return "Mineshaft";
}
// public MapGenMineshaft(Map<String, String> p_i2034_1_)
// {
// for (Entry<String, String> entry : p_i2034_1_.entrySet())
// {
// if (((String)entry.getKey()).equals("chance"))
// {
// this.field_82673_e = MathHelper.parseDoubleWithDefault((String)entry.getValue(), this.field_82673_e);
// }
// }
// }
protected boolean canSpawnStructureAtCoords(int chunkX, int chunkZ)
{
return this.rand.doublev() < this.chance && this.rand.zrange(80) < Math.max(Math.abs(chunkX), Math.abs(chunkZ));
}
protected StructureStart getStructureStart(int chunkX, int chunkZ)
{
return new StructureMineshaftStart(this.worldObj, this.rand, chunkX, chunkZ);
}
}

View file

@ -0,0 +1,119 @@
package server.worldgen.structure;
import java.util.Arrays;
import java.util.List;
import common.biome.Biome;
import common.rng.Random;
import common.util.BlockPos;
import server.world.WorldServer;
public class MapGenScatteredFeature extends MapGenStructure
{
private static final List<Biome> biomelist = Arrays.<Biome>asList(new Biome[] {Biome.desert, Biome.desertHills, Biome.jungle, Biome.jungleHills, Biome.swampland});
private static final int MAX_DISTANCE = 32;
private static final int MIN_DISTANCE = 8;
public String getStructureName()
{
return "Temple";
}
protected boolean canSpawnStructureAtCoords(int chunkX, int chunkZ)
{
int i = chunkX;
int j = chunkZ;
if (chunkX < 0)
{
chunkX -= MapGenScatteredFeature.MAX_DISTANCE - 1;
}
if (chunkZ < 0)
{
chunkZ -= MapGenScatteredFeature.MAX_DISTANCE - 1;
}
int k = chunkX / MapGenScatteredFeature.MAX_DISTANCE;
int l = chunkZ / MapGenScatteredFeature.MAX_DISTANCE;
Random random = this.worldObj.getRng(k, l, 14357617);
k = k * MapGenScatteredFeature.MAX_DISTANCE;
l = l * MapGenScatteredFeature.MAX_DISTANCE;
k = k + random.zrange(MapGenScatteredFeature.MAX_DISTANCE - MapGenScatteredFeature.MIN_DISTANCE);
l = l + random.zrange(MapGenScatteredFeature.MAX_DISTANCE - MapGenScatteredFeature.MIN_DISTANCE);
if (i == k && j == l)
{
Biome biomegenbase = this.worldObj.getBiomeGenerator().getBiomeGenerator(new BlockPos(i * 16 + 8, 0, j * 16 + 8), null);
if (biomegenbase == null)
{
return false;
}
for (Biome biomegenbase1 : biomelist)
{
if (biomegenbase == biomegenbase1)
{
return true;
}
}
}
return false;
}
protected StructureStart getStructureStart(int chunkX, int chunkZ)
{
return new MapGenScatteredFeature.Start(this.worldObj, this.rand, chunkX, chunkZ);
}
public boolean hasMageHut(BlockPos pos)
{
StructureStart structurestart = this.func_175797_c(pos);
if (structurestart != null && structurestart instanceof MapGenScatteredFeature.Start && !structurestart.components.isEmpty())
{
StructureComponent structurecomponent = (StructureComponent)structurestart.components.getFirst();
return structurecomponent instanceof StructureScattered.SwampHut;
}
else
{
return false;
}
}
public static class Start extends StructureStart
{
public Start()
{
}
public Start(WorldServer worldIn, Random p_i2060_2_, int p_i2060_3_, int p_i2060_4_)
{
super(p_i2060_3_, p_i2060_4_);
Biome biomegenbase = worldIn.getBiomeGenForCoords(new BlockPos(p_i2060_3_ * 16 + 8, 0, p_i2060_4_ * 16 + 8));
if (biomegenbase != Biome.jungle && biomegenbase != Biome.jungleHills)
{
if (biomegenbase == Biome.swampland)
{
StructureScattered.SwampHut componentscatteredfeaturepieces$swamphut = new StructureScattered.SwampHut(p_i2060_2_, p_i2060_3_ * 16, p_i2060_4_ * 16);
this.components.add(componentscatteredfeaturepieces$swamphut);
}
else if (biomegenbase == Biome.desert || biomegenbase == Biome.desertHills)
{
StructureScattered.DesertPyramid componentscatteredfeaturepieces$desertpyramid = new StructureScattered.DesertPyramid(p_i2060_2_, p_i2060_3_ * 16, p_i2060_4_ * 16);
this.components.add(componentscatteredfeaturepieces$desertpyramid);
}
}
else
{
StructureScattered.JunglePyramid componentscatteredfeaturepieces$junglepyramid = new StructureScattered.JunglePyramid(p_i2060_2_, p_i2060_3_ * 16, p_i2060_4_ * 16);
this.components.add(componentscatteredfeaturepieces$junglepyramid);
}
this.updateBoundingBox();
}
}
}

View file

@ -0,0 +1,167 @@
package server.worldgen.structure;
import java.util.List;
import common.rng.Random;
import server.world.WorldServer;
public class MapGenStronghold extends MapGenStructure
{
private double chance = 0.001D;
// private Set<Biome> biomeList;
//
// /**
// * is spawned false and set true once the defined BiomeGenBases were compared with the present ones
// */
// private boolean ranBiomeCheck;
// private ChunkPos[] structureCoords;
// private double field_82671_h;
// private int field_82672_i;
// public MapGenStronghold()
// {
// this.structureCoords = new ChunkPos[3];
// this.field_82671_h = 32.0D;
// this.field_82672_i = 3;
// this.biomeList = Sets.<Biome>newHashSet();
//
// for (Biome biomegenbase : Biome.getBiomeGenArray())
// {
// if (biomegenbase != null && biomegenbase.minHeight > 0.0F)
// {
// this.biomeList.add(biomegenbase);
// }
// }
// }
// public MapGenStronghold(Map<String, String> p_i2068_1_)
// {
// this();
//
// for (Entry<String, String> entry : p_i2068_1_.entrySet())
// {
// if (((String)entry.getKey()).equals("distance"))
// {
// this.field_82671_h = MathHelper.parseDoubleWithDefaultAndMax((String)entry.getValue(), this.field_82671_h, 1.0D);
// }
// else if (((String)entry.getKey()).equals("count"))
// {
// this.structureCoords = new ChunkPos[MathHelper.parseIntWithDefaultAndMax((String)entry.getValue(), this.structureCoords.length, 1)];
// }
// else if (((String)entry.getKey()).equals("spread"))
// {
// this.field_82672_i = MathHelper.parseIntWithDefaultAndMax((String)entry.getValue(), this.field_82672_i, 1);
// }
// }
// }
public String getStructureName()
{
return "Stronghold";
}
protected boolean canSpawnStructureAtCoords(int chunkX, int chunkZ)
{
return this.rand.doublev() < this.chance && this.rand.zrange(80) < Math.max(Math.abs(chunkX), Math.abs(chunkZ));
}
// protected boolean canSpawnStructureAtCoords(int chunkX, int chunkZ)
// {
// if (!this.ranBiomeCheck)
// {
// Random random = new Random();
// random.setSeed(this.worldObj.getSeed());
// double d0 = random.doublev() * Math.PI * 2.0D;
// int i = 1;
//
// for (int j = 0; j < this.structureCoords.length; ++j)
// {
// double d1 = (1.25D * (double)i + random.doublev()) * this.field_82671_h * (double)i;
// int k = (int)Math.round(Math.cos(d0) * d1);
// int l = (int)Math.round(Math.sin(d0) * d1);
// BlockPos blockpos = this.worldObj.getBiomeGenerator().findBiomePosition((k << 4) + 8, (l << 4) + 8, 112, this.biomeList, random);
//
// if (blockpos != null)
// {
// k = blockpos.getX() >> 4;
// l = blockpos.getZ() >> 4;
// }
//
// this.structureCoords[j] = new ChunkPos(k, l);
// d0 += (Math.PI * 2D) * (double)i / (double)this.field_82672_i;
//
// if (j == this.field_82672_i)
// {
// i += 2 + random.zrange(5);
// this.field_82672_i += 1 + random.zrange(2);
// }
// }
//
// this.ranBiomeCheck = true;
// }
//
// for (ChunkPos chunkcoordintpair : this.structureCoords)
// {
// if (chunkX == chunkcoordintpair.x && chunkZ == chunkcoordintpair.z)
// {
// return true;
// }
// }
//
// return false;
// }
// protected List<BlockPos> getCoordList()
// {
// List<BlockPos> list = Lists.<BlockPos>newArrayList();
//
// for (ChunkPos chunkcoordintpair : this.structureCoords)
// {
// if (chunkcoordintpair != null)
// {
// list.add(new BlockPos((chunkcoordintpair.x << 4) + 8, 64, (chunkcoordintpair.z << 4) + 8));
// }
// }
//
// return list;
// }
protected StructureStart getStructureStart(int chunkX, int chunkZ)
{
MapGenStronghold.Start mapgenstronghold$start;
for (mapgenstronghold$start = new MapGenStronghold.Start(this.worldObj, this.rand, chunkX, chunkZ); mapgenstronghold$start.getComponents().isEmpty() || ((StructureStronghold.Stairs2)mapgenstronghold$start.getComponents().get(0)).strongholdPortalRoom == null; mapgenstronghold$start = new MapGenStronghold.Start(this.worldObj, this.rand, chunkX, chunkZ))
{
;
}
return mapgenstronghold$start;
}
public static class Start extends StructureStart
{
public Start()
{
}
public Start(WorldServer worldIn, Random p_i2067_2_, int p_i2067_3_, int p_i2067_4_)
{
super(p_i2067_3_, p_i2067_4_);
StructureStronghold.prepareStructurePieces();
StructureStronghold.Stairs2 structurestrongholdpieces$stairs2 = new StructureStronghold.Stairs2(0, p_i2067_2_, (p_i2067_3_ << 4) + 2, (p_i2067_4_ << 4) + 2);
this.components.add(structurestrongholdpieces$stairs2);
structurestrongholdpieces$stairs2.buildComponent(structurestrongholdpieces$stairs2, this.components, p_i2067_2_);
List<StructureComponent> list = structurestrongholdpieces$stairs2.field_75026_c;
while (!list.isEmpty())
{
int i = p_i2067_2_.zrange(list.size());
StructureComponent structurecomponent = (StructureComponent)list.remove(i);
structurecomponent.buildComponent(structurestrongholdpieces$stairs2, this.components, p_i2067_2_);
}
this.updateBoundingBox();
this.markAvailableHeight(worldIn, p_i2067_2_, 10);
}
}
}

View file

@ -0,0 +1,250 @@
package server.worldgen.structure;
import java.util.Iterator;
import java.util.Map;
import common.collect.Maps;
import common.nbt.NBTBase;
import common.nbt.NBTTagCompound;
import common.rng.Random;
import common.util.BlockPos;
import common.util.ChunkPos;
import common.util.LongHashMap;
import common.world.AWorldServer;
import common.world.World;
import common.worldgen.ChunkPrimer;
import common.worldgen.caves.MapGenBase;
import server.world.WorldServer;
import server.world.WorldServer.WorldSavedData;
public abstract class MapGenStructure extends MapGenBase
{
private WorldSavedData structureData;
protected Map<Long, StructureStart> structureMap = Maps.<Long, StructureStart>newHashMap();
protected WorldServer worldObj;
public void generate(AWorldServer worldIn, int x, int z, ChunkPrimer chunkPrimerIn)
{
this.worldObj = (WorldServer)worldIn;
super.generate(worldIn, x, z, chunkPrimerIn);
}
public abstract String getStructureName();
/**
* Recursively called by generate()
*/
protected final void recursiveGenerate(WorldServer worldIn, final int chunkX, final int chunkZ, int p_180701_4_, int p_180701_5_, ChunkPrimer chunkPrimerIn)
{
int i = (chunkX << 4) + 8;
int j = (chunkZ << 4) + 8;
if(i < -World.MAX_SIZE + 2048 || j < -World.MAX_SIZE + 2048 || i >= World.MAX_SIZE - 2048 || j >= World.MAX_SIZE - 2048)
return;
this.initializeStructureData(worldIn);
if (!this.structureMap.containsKey(Long.valueOf(LongHashMap.packInt(chunkX, chunkZ))))
{
this.rand.intv();
if (this.canSpawnStructureAtCoords(chunkX, chunkZ))
{
StructureStart structurestart = this.getStructureStart(chunkX, chunkZ);
this.structureMap.put(Long.valueOf(LongHashMap.packInt(chunkX, chunkZ)), structurestart);
this.setStructureStart(chunkX, chunkZ, structurestart);
}
}
}
public boolean generateStructure(WorldServer worldIn, Random randomIn, ChunkPos chunkCoord)
{
int i = (chunkCoord.x << 4) + 8;
int j = (chunkCoord.z << 4) + 8;
if(i < -World.MAX_SIZE + 2048 || j < -World.MAX_SIZE + 2048 || i >= World.MAX_SIZE - 2048 || j >= World.MAX_SIZE - 2048)
return false;
this.initializeStructureData(worldIn);
boolean flag = false;
for (StructureStart structurestart : this.structureMap.values())
{
if (structurestart.isSizeableStructure() && structurestart.func_175788_a(chunkCoord) && structurestart.getBoundingBox().intersectsWith(i, j, i + 15, j + 15))
{
structurestart.generateStructure(worldIn, randomIn, new StructureBoundingBox(i, j, i + 15, j + 15));
structurestart.func_175787_b(chunkCoord);
flag = true;
this.setStructureStart(structurestart.getChunkPosX(), structurestart.getChunkPosZ(), structurestart);
}
}
return flag;
}
public boolean isPresent(BlockPos pos)
{
this.initializeStructureData(this.worldObj);
return this.func_175797_c(pos) != null;
}
protected StructureStart func_175797_c(BlockPos pos)
{
label24:
for (StructureStart structurestart : this.structureMap.values())
{
if (structurestart.isSizeableStructure() && structurestart.getBoundingBox().isVecInside(pos))
{
Iterator<StructureComponent> iterator = structurestart.getComponents().iterator();
while (true)
{
if (!iterator.hasNext())
{
continue label24;
}
StructureComponent structurecomponent = (StructureComponent)iterator.next();
if (structurecomponent.getBoundingBox().isVecInside(pos))
{
break;
}
}
return structurestart;
}
}
return null;
}
public boolean isPositionInStructure(WorldServer worldIn, BlockPos pos)
{
this.initializeStructureData(worldIn);
for (StructureStart structurestart : this.structureMap.values())
{
if (structurestart.isSizeableStructure() && structurestart.getBoundingBox().isVecInside(pos))
{
return true;
}
}
return false;
}
// public BlockPos getClosestStrongholdPos(WorldServer worldIn, BlockPos pos)
// {
// this.worldObj = worldIn;
// this.initializeStructureData(worldIn);
// this.rand.setSeed(worldIn.getSeed());
// long i = this.rand.longv();
// long j = this.rand.longv();
// long k = (long)(pos.getX() >> 4) * i;
// long l = (long)(pos.getZ() >> 4) * j;
// this.rand.setSeed(k ^ l ^ worldIn.getSeed());
// this.recursiveGenerate(worldIn, pos.getX() >> 4, pos.getZ() >> 4, 0, 0, (ChunkPrimer)null);
// double d0 = Double.MAX_VALUE;
// BlockPos blockpos = null;
//
// for (StructureStart structurestart : this.structureMap.values())
// {
// if (structurestart.isSizeableStructure())
// {
// StructureComponent structurecomponent = (StructureComponent)structurestart.getComponents().get(0);
// BlockPos blockpos1 = structurecomponent.getBoundingBoxCenter();
// double d1 = blockpos1.distanceSq(pos);
//
// if (d1 < d0)
// {
// d0 = d1;
// blockpos = blockpos1;
// }
// }
// }
//
// if (blockpos != null)
// {
// return blockpos;
// }
// else
// {
// List<BlockPos> list = this.getCoordList();
//
// if (list != null)
// {
// BlockPos blockpos2 = null;
//
// for (BlockPos blockpos3 : list)
// {
// double d2 = blockpos3.distanceSq(pos);
//
// if (d2 < d0)
// {
// d0 = d2;
// blockpos2 = blockpos3;
// }
// }
//
// return blockpos2;
// }
// else
// {
// return null;
// }
// }
// }
// protected List<BlockPos> getCoordList()
// {
// return null;
// }
private void initializeStructureData(WorldServer worldIn)
{
if (this.structureData == null)
{
this.structureData = worldIn.loadItemData(this.getStructureName());
if (this.structureData == null)
{
this.structureData = new WorldSavedData(this.getStructureName(), new NBTTagCompound());
worldIn.setItemData(this.getStructureName(), this.structureData);
}
else
{
NBTTagCompound tag = this.structureData.tag;
for (String s : tag.getKeySet())
{
NBTBase nbtbase = tag.getTag(s);
if (nbtbase.getId() == 10)
{
NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbtbase;
if (nbttagcompound1.hasKey("ChunkX") && nbttagcompound1.hasKey("ChunkZ"))
{
int i = nbttagcompound1.getInteger("ChunkX");
int j = nbttagcompound1.getInteger("ChunkZ");
StructureStart structurestart = MapGenStructureIO.getStructureStart(nbttagcompound1, worldIn);
if (structurestart != null)
{
this.structureMap.put(Long.valueOf(LongHashMap.packInt(i, j)), structurestart);
}
}
}
}
}
}
}
private void setStructureStart(int chunkX, int chunkZ, StructureStart start)
{
this.structureData.tag.setTag("[" + chunkX + "," + chunkZ + "]", start.writeStructureComponentsToNBT(chunkX, chunkZ));
this.structureData.dirty = true;
}
protected abstract boolean canSpawnStructureAtCoords(int chunkX, int chunkZ);
protected abstract StructureStart getStructureStart(int chunkX, int chunkZ);
}

View file

@ -0,0 +1,114 @@
package server.worldgen.structure;
import java.util.Map;
import common.collect.Maps;
import common.log.Log;
import common.nbt.NBTTagCompound;
import server.world.WorldServer;
public class MapGenStructureIO
{
private static Map < String, Class <? extends StructureStart >> startNameToClassMap = Maps. < String, Class <? extends StructureStart >> newHashMap();
private static Map < Class <? extends StructureStart > , String > startClassToNameMap = Maps. < Class <? extends StructureStart > , String > newHashMap();
private static Map < String, Class <? extends StructureComponent >> componentNameToClassMap = Maps. < String, Class <? extends StructureComponent >> newHashMap();
private static Map < Class <? extends StructureComponent > , String > componentClassToNameMap = Maps. < Class <? extends StructureComponent > , String > newHashMap();
private static void registerStructure(Class <? extends StructureStart > startClass, String structureName)
{
startNameToClassMap.put(structureName, startClass);
startClassToNameMap.put(startClass, structureName);
}
static void registerStructureComponent(Class <? extends StructureComponent > componentClass, String componentName)
{
componentNameToClassMap.put(componentName, componentClass);
componentClassToNameMap.put(componentClass, componentName);
}
public static String getStructureStartName(StructureStart start)
{
return (String)startClassToNameMap.get(start.getClass());
}
public static String getStructureComponentName(StructureComponent component)
{
return (String)componentClassToNameMap.get(component.getClass());
}
public static StructureStart getStructureStart(NBTTagCompound tagCompound, WorldServer worldIn)
{
StructureStart structurestart = null;
try
{
Class <? extends StructureStart > oclass = (Class)startNameToClassMap.get(tagCompound.getString("id"));
if (oclass != null)
{
structurestart = (StructureStart)oclass.newInstance();
}
}
catch (Exception exception)
{
Log.JNI.warn("Fehler bei Strukturanfang mit ID " + tagCompound.getString("id"));
exception.printStackTrace();
}
if (structurestart != null)
{
structurestart.readStructureComponentsFromNBT(worldIn, tagCompound);
}
else
{
Log.JNI.warn("Überspringe Struktur mit ID " + tagCompound.getString("id"));
}
return structurestart;
}
public static StructureComponent getStructureComponent(NBTTagCompound tagCompound, WorldServer worldIn)
{
StructureComponent structurecomponent = null;
try
{
Class <? extends StructureComponent > oclass = (Class)componentNameToClassMap.get(tagCompound.getString("id"));
if (oclass != null)
{
structurecomponent = (StructureComponent)oclass.newInstance();
}
}
catch (Exception exception)
{
Log.JNI.warn("Fehler bei Strukturteil mit ID " + tagCompound.getString("id"));
exception.printStackTrace();
}
if (structurecomponent != null)
{
structurecomponent.readStructureBaseNBT(worldIn, tagCompound);
}
else
{
Log.JNI.warn("Überspringe Strukturteil mit ID " + tagCompound.getString("id"));
}
return structurecomponent;
}
static
{
registerStructure(StructureMineshaftStart.class, "Mineshaft");
registerStructure(MapGenVillage.Start.class, "Village");
registerStructure(MapGenBridge.Start.class, "Fortress");
registerStructure(MapGenStronghold.Start.class, "Stronghold");
registerStructure(MapGenScatteredFeature.Start.class, "Temple");
StructureMineshaft.registerStructurePieces();
StructureVillage.registerVillagePieces();
StructureBridge.registerFortressPieces();
StructureStronghold.registerStrongholdPieces();
StructureScattered.registerScatteredFeaturePieces();
}
}

View file

@ -0,0 +1,155 @@
package server.worldgen.structure;
import java.util.List;
import java.util.Set;
import common.biome.Biome;
import common.collect.Sets;
import common.nbt.NBTTagCompound;
import common.rng.Random;
import server.world.WorldServer;
public class MapGenVillage extends MapGenStructure
{
public static final Set<Biome> villageSpawnBiomes = Sets.<Biome>newHashSet(Biome.plains, Biome.desert, Biome.savanna);
/** World terrain type, 0 for normal, 1 for flat map */
private int terrainType;
private int distance;
private int field_82666_h;
public MapGenVillage()
{
this.distance = 32;
this.field_82666_h = 8;
}
// public MapGenVillage(Map<String, String> p_i2093_1_)
// {
// this();
//
// for (Entry<String, String> entry : p_i2093_1_.entrySet())
// {
// if (((String)entry.getKey()).equals("size"))
// {
// this.terrainType = MathHelper.parseIntWithDefaultAndMax((String)entry.getValue(), this.terrainType, 0);
// }
// else if (((String)entry.getKey()).equals("distance"))
// {
// this.distance = MathHelper.parseIntWithDefaultAndMax((String)entry.getValue(), this.distance, this.field_82666_h + 1);
// }
// }
// }
public String getStructureName()
{
return "Village";
}
protected boolean canSpawnStructureAtCoords(int chunkX, int chunkZ)
{
int i = chunkX;
int j = chunkZ;
if (chunkX < 0)
{
chunkX -= this.distance - 1;
}
if (chunkZ < 0)
{
chunkZ -= this.distance - 1;
}
int k = chunkX / this.distance;
int l = chunkZ / this.distance;
Random random = this.worldObj.getRng(k, l, 10387312);
k = k * this.distance;
l = l * this.distance;
k = k + random.zrange(this.distance - this.field_82666_h);
l = l + random.zrange(this.distance - this.field_82666_h);
if (i == k && j == l)
{
boolean flag = this.worldObj.getBiomeGenerator().areBiomesViable(i * 16 + 8, j * 16 + 8, 0, villageSpawnBiomes);
if (flag)
{
return true;
}
}
return false;
}
protected StructureStart getStructureStart(int chunkX, int chunkZ)
{
return new MapGenVillage.Start(this.worldObj, this.rand, chunkX, chunkZ, this.terrainType);
}
public static class Start extends StructureStart
{
private boolean hasMoreThanTwoComponents;
public Start()
{
}
public Start(WorldServer worldIn, Random rand, int x, int z, int size)
{
super(x, z);
List<StructureVillage.PieceWeight> list = StructureVillage.getStructureVillageWeightedPieceList(rand, size);
StructureVillage.Start structurevillagepieces$start = new StructureVillage.Start(worldIn.getBiomeGenerator(), 0, rand, (x << 4) + 2, (z << 4) + 2, list, size);
this.components.add(structurevillagepieces$start);
structurevillagepieces$start.buildComponent(structurevillagepieces$start, this.components, rand);
List<StructureComponent> list1 = structurevillagepieces$start.field_74930_j;
List<StructureComponent> list2 = structurevillagepieces$start.field_74932_i;
while (!list1.isEmpty() || !list2.isEmpty())
{
if (list1.isEmpty())
{
int i = rand.zrange(list2.size());
StructureComponent structurecomponent = (StructureComponent)list2.remove(i);
structurecomponent.buildComponent(structurevillagepieces$start, this.components, rand);
}
else
{
int j = rand.zrange(list1.size());
StructureComponent structurecomponent2 = (StructureComponent)list1.remove(j);
structurecomponent2.buildComponent(structurevillagepieces$start, this.components, rand);
}
}
this.updateBoundingBox();
int k = 0;
for (StructureComponent structurecomponent1 : this.components)
{
if (!(structurecomponent1 instanceof StructureVillage.Road))
{
++k;
}
}
this.hasMoreThanTwoComponents = k > 2;
}
public boolean isSizeableStructure()
{
return this.hasMoreThanTwoComponents;
}
public void writeToNBT(NBTTagCompound tagCompound)
{
super.writeToNBT(tagCompound);
tagCompound.setBoolean("Valid", this.hasMoreThanTwoComponents);
}
public void readFromNBT(NBTTagCompound tagCompound)
{
super.readFromNBT(tagCompound);
this.hasMoreThanTwoComponents = tagCompound.getBoolean("Valid");
}
}
}

View file

@ -0,0 +1,216 @@
package server.worldgen.structure;
import common.nbt.NBTTagIntArray;
import common.util.BlockPos;
import common.util.Facing;
import common.util.Vec3i;
public class StructureBoundingBox
{
/** The first x coordinate of a bounding box. */
public int minX;
/** The first y coordinate of a bounding box. */
public int minY;
/** The first z coordinate of a bounding box. */
public int minZ;
/** The second x coordinate of a bounding box. */
public int maxX;
/** The second y coordinate of a bounding box. */
public int maxY;
/** The second z coordinate of a bounding box. */
public int maxZ;
public StructureBoundingBox()
{
}
public StructureBoundingBox(int[] coords)
{
if (coords.length == 6)
{
this.minX = coords[0];
this.minY = coords[1];
this.minZ = coords[2];
this.maxX = coords[3];
this.maxY = coords[4];
this.maxZ = coords[5];
}
}
/**
* returns a new StructureBoundingBox with MAX values
*/
public static StructureBoundingBox getNewBoundingBox()
{
return new StructureBoundingBox(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE);
}
/**
* Create a bounding box with the specified dimensions and rotate it. Used to project a possible new component
* Bounding Box - to check if it would cut anything already spawned
*/
public static StructureBoundingBox getComponentToAddBoundingBox(int p_175897_0_, int p_175897_1_, int p_175897_2_, int p_175897_3_, int p_175897_4_, int p_175897_5_, int p_175897_6_, int p_175897_7_, int p_175897_8_, Facing p_175897_9_)
{
switch (p_175897_9_)
{
case NORTH:
return new StructureBoundingBox(p_175897_0_ + p_175897_3_, p_175897_1_ + p_175897_4_, p_175897_2_ - p_175897_8_ + 1 + p_175897_5_, p_175897_0_ + p_175897_6_ - 1 + p_175897_3_, p_175897_1_ + p_175897_7_ - 1 + p_175897_4_, p_175897_2_ + p_175897_5_);
case SOUTH:
return new StructureBoundingBox(p_175897_0_ + p_175897_3_, p_175897_1_ + p_175897_4_, p_175897_2_ + p_175897_5_, p_175897_0_ + p_175897_6_ - 1 + p_175897_3_, p_175897_1_ + p_175897_7_ - 1 + p_175897_4_, p_175897_2_ + p_175897_8_ - 1 + p_175897_5_);
case WEST:
return new StructureBoundingBox(p_175897_0_ - p_175897_8_ + 1 + p_175897_5_, p_175897_1_ + p_175897_4_, p_175897_2_ + p_175897_3_, p_175897_0_ + p_175897_5_, p_175897_1_ + p_175897_7_ - 1 + p_175897_4_, p_175897_2_ + p_175897_6_ - 1 + p_175897_3_);
case EAST:
return new StructureBoundingBox(p_175897_0_ + p_175897_5_, p_175897_1_ + p_175897_4_, p_175897_2_ + p_175897_3_, p_175897_0_ + p_175897_8_ - 1 + p_175897_5_, p_175897_1_ + p_175897_7_ - 1 + p_175897_4_, p_175897_2_ + p_175897_6_ - 1 + p_175897_3_);
default:
return new StructureBoundingBox(p_175897_0_ + p_175897_3_, p_175897_1_ + p_175897_4_, p_175897_2_ + p_175897_5_, p_175897_0_ + p_175897_6_ - 1 + p_175897_3_, p_175897_1_ + p_175897_7_ - 1 + p_175897_4_, p_175897_2_ + p_175897_8_ - 1 + p_175897_5_);
}
}
public static StructureBoundingBox func_175899_a(int p_175899_0_, int p_175899_1_, int p_175899_2_, int p_175899_3_, int p_175899_4_, int p_175899_5_)
{
return new StructureBoundingBox(Math.min(p_175899_0_, p_175899_3_), Math.min(p_175899_1_, p_175899_4_), Math.min(p_175899_2_, p_175899_5_), Math.max(p_175899_0_, p_175899_3_), Math.max(p_175899_1_, p_175899_4_), Math.max(p_175899_2_, p_175899_5_));
}
public StructureBoundingBox(StructureBoundingBox structurebb)
{
this.minX = structurebb.minX;
this.minY = structurebb.minY;
this.minZ = structurebb.minZ;
this.maxX = structurebb.maxX;
this.maxY = structurebb.maxY;
this.maxZ = structurebb.maxZ;
}
public StructureBoundingBox(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax)
{
this.minX = xMin;
this.minY = yMin;
this.minZ = zMin;
this.maxX = xMax;
this.maxY = yMax;
this.maxZ = zMax;
}
public StructureBoundingBox(Vec3i vec1, Vec3i vec2)
{
this.minX = Math.min(vec1.getX(), vec2.getX());
this.minY = Math.min(vec1.getY(), vec2.getY());
this.minZ = Math.min(vec1.getZ(), vec2.getZ());
this.maxX = Math.max(vec1.getX(), vec2.getX());
this.maxY = Math.max(vec1.getY(), vec2.getY());
this.maxZ = Math.max(vec1.getZ(), vec2.getZ());
}
public StructureBoundingBox(int xMin, int zMin, int xMax, int zMax)
{
this.minX = xMin;
this.minZ = zMin;
this.maxX = xMax;
this.maxZ = zMax;
this.minY = 1;
this.maxY = 512;
}
/**
* Discover if bounding box can fit within the current bounding box object.
*/
public boolean intersectsWith(StructureBoundingBox structurebb)
{
return this.maxX >= structurebb.minX && this.minX <= structurebb.maxX && this.maxZ >= structurebb.minZ && this.minZ <= structurebb.maxZ && this.maxY >= structurebb.minY && this.minY <= structurebb.maxY;
}
/**
* Discover if a coordinate is inside the bounding box area.
*/
public boolean intersectsWith(int minXIn, int minZIn, int maxXIn, int maxZIn)
{
return this.maxX >= minXIn && this.minX <= maxXIn && this.maxZ >= minZIn && this.minZ <= maxZIn;
}
/**
* Expands a bounding box's dimensions to include the supplied bounding box.
*/
public void expandTo(StructureBoundingBox sbb)
{
this.minX = Math.min(this.minX, sbb.minX);
this.minY = Math.min(this.minY, sbb.minY);
this.minZ = Math.min(this.minZ, sbb.minZ);
this.maxX = Math.max(this.maxX, sbb.maxX);
this.maxY = Math.max(this.maxY, sbb.maxY);
this.maxZ = Math.max(this.maxZ, sbb.maxZ);
}
/**
* Offsets the current bounding box by the specified coordinates. Args: x, y, z
*/
public void offset(int x, int y, int z)
{
this.minX += x;
this.minY += y;
this.minZ += z;
this.maxX += x;
this.maxY += y;
this.maxZ += z;
}
/**
* Checks if given Vec3i is inside of StructureBoundingBox
*/
public boolean isVecInside(Vec3i vec)
{
return vec.getX() >= this.minX && vec.getX() <= this.maxX && vec.getZ() >= this.minZ && vec.getZ() <= this.maxZ && vec.getY() >= this.minY && vec.getY() <= this.maxY;
}
public Vec3i func_175896_b()
{
return new Vec3i(this.maxX - this.minX, this.maxY - this.minY, this.maxZ - this.minZ);
}
/**
* Get dimension of the bounding box in the x direction.
*/
public int getXSize()
{
return this.maxX - this.minX + 1;
}
/**
* Get dimension of the bounding box in the y direction.
*/
public int getYSize()
{
return this.maxY - this.minY + 1;
}
/**
* Get dimension of the bounding box in the z direction.
*/
public int getZSize()
{
return this.maxZ - this.minZ + 1;
}
public Vec3i getCenter()
{
return new BlockPos(this.minX + (this.maxX - this.minX + 1) / 2, this.minY + (this.maxY - this.minY + 1) / 2, this.minZ + (this.maxZ - this.minZ + 1) / 2);
}
// public String toString()
// {
// return Objects.toStringHelper(this).add("x0", this.minX).add("y0", this.minY).add("z0", this.minZ).add("x1", this.maxX).add("y1", this.maxY).add("z1", this.maxZ).toString();
// }
public NBTTagIntArray toNBTTagIntArray()
{
return new NBTTagIntArray(new int[] {this.minX, this.minY, this.minZ, this.maxX, this.maxY, this.maxZ});
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,855 @@
package server.worldgen.structure;
import java.util.List;
import common.block.Block;
import common.block.BlockDirectional;
import common.block.BlockDoor;
import common.init.Blocks;
import common.item.ItemDoor;
import common.item.RngLoot;
import common.material.Material;
import common.nbt.NBTTagCompound;
import common.rng.Random;
import common.rng.WeightedList;
import common.tileentity.TileEntity;
import common.tileentity.TileEntityChest;
import common.tileentity.TileEntityDispenser;
import common.util.BlockPos;
import common.util.Facing;
import common.world.State;
import server.world.WorldServer;
public abstract class StructureComponent
{
protected StructureBoundingBox boundingBox;
/** switches the Coordinate System base off the Bounding Box */
protected Facing coordBaseMode;
/** The type ID of this component. */
protected int componentType;
public StructureComponent()
{
}
protected StructureComponent(int type)
{
this.componentType = type;
}
/**
* Writes structure base data (id, boundingbox, {@link
* game.worldgen.structure.StructureComponent#coordBaseMode coordBase} and {@link
* game.worldgen.structure.StructureComponent#componentType componentType}) to new NBTTagCompound and
* returns it.
*/
public NBTTagCompound createStructureBaseNBT()
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setString("id", MapGenStructureIO.getStructureComponentName(this));
nbttagcompound.setTag("BB", this.boundingBox.toNBTTagIntArray());
nbttagcompound.setInteger("O", this.coordBaseMode == null ? -1 : this.coordBaseMode.getHorizontalIndex());
nbttagcompound.setInteger("GD", this.componentType);
this.writeStructureToNBT(nbttagcompound);
return nbttagcompound;
}
/**
* (abstract) Helper method to write subclass data to NBT
*/
protected abstract void writeStructureToNBT(NBTTagCompound tagCompound);
/**
* Reads and sets structure base data (boundingbox, {@link
* game.worldgen.structure.StructureComponent#coordBaseMode coordBase} and {@link
* game.worldgen.structure.StructureComponent#componentType componentType})
*/
public void readStructureBaseNBT(WorldServer worldIn, NBTTagCompound tagCompound)
{
if (tagCompound.hasKey("BB"))
{
this.boundingBox = new StructureBoundingBox(tagCompound.getIntArray("BB"));
}
int i = tagCompound.getInteger("O");
this.coordBaseMode = i == -1 ? null : Facing.getHorizontal(i);
this.componentType = tagCompound.getInteger("GD");
this.readStructureFromNBT(tagCompound);
}
/**
* (abstract) Helper method to read subclass data from NBT
*/
protected abstract void readStructureFromNBT(NBTTagCompound tagCompound);
/**
* Initiates construction of the Structure Component picked, at the current Location of StructGen
*/
public void buildComponent(StructureComponent componentIn, List<StructureComponent> listIn, Random rand)
{
}
/**
* second Part of Structure generating, this for example places Spiderwebs, Mob Spawners, it closes Mineshafts at
* the end, it adds Fences...
*/
public abstract boolean addComponentParts(WorldServer worldIn, Random randomIn, StructureBoundingBox structureBoundingBoxIn);
public StructureBoundingBox getBoundingBox()
{
return this.boundingBox;
}
/**
* Returns the component type ID of this component.
*/
public int getComponentType()
{
return this.componentType;
}
/**
* Discover if bounding box can fit within the current bounding box object.
*/
public static StructureComponent findIntersecting(List<StructureComponent> listIn, StructureBoundingBox boundingboxIn)
{
for (StructureComponent structurecomponent : listIn)
{
if (structurecomponent.getBoundingBox() != null && structurecomponent.getBoundingBox().intersectsWith(boundingboxIn))
{
return structurecomponent;
}
}
return null;
}
public BlockPos getBoundingBoxCenter()
{
return new BlockPos(this.boundingBox.getCenter());
}
/**
* checks the entire StructureBoundingBox for Liquids
*/
protected boolean isLiquidInStructureBoundingBox(WorldServer worldIn, StructureBoundingBox boundingboxIn)
{
int i = Math.max(this.boundingBox.minX - 1, boundingboxIn.minX);
int j = Math.max(this.boundingBox.minY - 1, boundingboxIn.minY);
int k = Math.max(this.boundingBox.minZ - 1, boundingboxIn.minZ);
int l = Math.min(this.boundingBox.maxX + 1, boundingboxIn.maxX);
int i1 = Math.min(this.boundingBox.maxY + 1, boundingboxIn.maxY);
int j1 = Math.min(this.boundingBox.maxZ + 1, boundingboxIn.maxZ);
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
for (int k1 = i; k1 <= l; ++k1)
{
for (int l1 = k; l1 <= j1; ++l1)
{
if (worldIn.getState(blockpos$mutableblockpos.set(k1, j, l1)).getBlock().getMaterial().isLiquid())
{
return true;
}
if (worldIn.getState(blockpos$mutableblockpos.set(k1, i1, l1)).getBlock().getMaterial().isLiquid())
{
return true;
}
}
}
for (int i2 = i; i2 <= l; ++i2)
{
for (int k2 = j; k2 <= i1; ++k2)
{
if (worldIn.getState(blockpos$mutableblockpos.set(i2, k2, k)).getBlock().getMaterial().isLiquid())
{
return true;
}
if (worldIn.getState(blockpos$mutableblockpos.set(i2, k2, j1)).getBlock().getMaterial().isLiquid())
{
return true;
}
}
}
for (int j2 = k; j2 <= j1; ++j2)
{
for (int l2 = j; l2 <= i1; ++l2)
{
if (worldIn.getState(blockpos$mutableblockpos.set(i, l2, j2)).getBlock().getMaterial().isLiquid())
{
return true;
}
if (worldIn.getState(blockpos$mutableblockpos.set(l, l2, j2)).getBlock().getMaterial().isLiquid())
{
return true;
}
}
}
return false;
}
protected int getXWithOffset(int x, int z)
{
if (this.coordBaseMode == null)
{
return x;
}
else
{
switch (this.coordBaseMode)
{
case NORTH:
case SOUTH:
return this.boundingBox.minX + x;
case WEST:
return this.boundingBox.maxX - z;
case EAST:
return this.boundingBox.minX + z;
default:
return x;
}
}
}
protected int getYWithOffset(int y)
{
return this.coordBaseMode == null ? y : y + this.boundingBox.minY;
}
protected int getZWithOffset(int x, int z)
{
if (this.coordBaseMode == null)
{
return z;
}
else
{
switch (this.coordBaseMode)
{
case NORTH:
return this.boundingBox.maxZ - z;
case SOUTH:
return this.boundingBox.minZ + z;
case WEST:
case EAST:
return this.boundingBox.minZ + x;
default:
return z;
}
}
}
/**
* Returns the direction-shifted metadata for blocks that require orientation, e.g. doors, stairs, ladders.
*/
protected int getMetadataWithOffset(Block blockIn, int meta)
{
if (blockIn == Blocks.rail)
{
if (this.coordBaseMode == Facing.WEST || this.coordBaseMode == Facing.EAST)
{
if (meta == 1)
{
return 0;
}
return 1;
}
}
else if (blockIn instanceof BlockDoor)
{
if (this.coordBaseMode == Facing.SOUTH)
{
if (meta == 0)
{
return 2;
}
if (meta == 2)
{
return 0;
}
}
else
{
if (this.coordBaseMode == Facing.WEST)
{
return meta + 1 & 3;
}
if (this.coordBaseMode == Facing.EAST)
{
return meta + 3 & 3;
}
}
}
else if (blockIn != Blocks.cobblestone_stairs && blockIn != Blocks.oak_stairs && blockIn != Blocks.blood_brick_stairs && blockIn != Blocks.stonebrick_stairs && blockIn != Blocks.sandstone_stairs)
{
if (blockIn == Blocks.ladder)
{
if (this.coordBaseMode == Facing.SOUTH)
{
if (meta == Facing.NORTH.getIndex())
{
return Facing.SOUTH.getIndex();
}
if (meta == Facing.SOUTH.getIndex())
{
return Facing.NORTH.getIndex();
}
}
else if (this.coordBaseMode == Facing.WEST)
{
if (meta == Facing.NORTH.getIndex())
{
return Facing.WEST.getIndex();
}
if (meta == Facing.SOUTH.getIndex())
{
return Facing.EAST.getIndex();
}
if (meta == Facing.WEST.getIndex())
{
return Facing.NORTH.getIndex();
}
if (meta == Facing.EAST.getIndex())
{
return Facing.SOUTH.getIndex();
}
}
else if (this.coordBaseMode == Facing.EAST)
{
if (meta == Facing.NORTH.getIndex())
{
return Facing.EAST.getIndex();
}
if (meta == Facing.SOUTH.getIndex())
{
return Facing.WEST.getIndex();
}
if (meta == Facing.WEST.getIndex())
{
return Facing.NORTH.getIndex();
}
if (meta == Facing.EAST.getIndex())
{
return Facing.SOUTH.getIndex();
}
}
}
else if (blockIn == Blocks.stone_button)
{
if (this.coordBaseMode == Facing.SOUTH)
{
if (meta == 3)
{
return 4;
}
if (meta == 4)
{
return 3;
}
}
else if (this.coordBaseMode == Facing.WEST)
{
if (meta == 3)
{
return 1;
}
if (meta == 4)
{
return 2;
}
if (meta == 2)
{
return 3;
}
if (meta == 1)
{
return 4;
}
}
else if (this.coordBaseMode == Facing.EAST)
{
if (meta == 3)
{
return 2;
}
if (meta == 4)
{
return 1;
}
if (meta == 2)
{
return 3;
}
if (meta == 1)
{
return 4;
}
}
}
else if (blockIn != Blocks.tripwire_hook && !(blockIn instanceof BlockDirectional))
{
if (blockIn == Blocks.piston || blockIn == Blocks.sticky_piston || blockIn == Blocks.lever || blockIn == Blocks.dispenser)
{
if (this.coordBaseMode == Facing.SOUTH)
{
if (meta == Facing.NORTH.getIndex() || meta == Facing.SOUTH.getIndex())
{
return Facing.getFront(meta).getOpposite().getIndex();
}
}
else if (this.coordBaseMode == Facing.WEST)
{
if (meta == Facing.NORTH.getIndex())
{
return Facing.WEST.getIndex();
}
if (meta == Facing.SOUTH.getIndex())
{
return Facing.EAST.getIndex();
}
if (meta == Facing.WEST.getIndex())
{
return Facing.NORTH.getIndex();
}
if (meta == Facing.EAST.getIndex())
{
return Facing.SOUTH.getIndex();
}
}
else if (this.coordBaseMode == Facing.EAST)
{
if (meta == Facing.NORTH.getIndex())
{
return Facing.EAST.getIndex();
}
if (meta == Facing.SOUTH.getIndex())
{
return Facing.WEST.getIndex();
}
if (meta == Facing.WEST.getIndex())
{
return Facing.NORTH.getIndex();
}
if (meta == Facing.EAST.getIndex())
{
return Facing.SOUTH.getIndex();
}
}
}
}
else
{
Facing enumfacing = Facing.getHorizontal(meta);
if (this.coordBaseMode == Facing.SOUTH)
{
if (enumfacing == Facing.SOUTH || enumfacing == Facing.NORTH)
{
return enumfacing.getOpposite().getHorizontalIndex();
}
}
else if (this.coordBaseMode == Facing.WEST)
{
if (enumfacing == Facing.NORTH)
{
return Facing.WEST.getHorizontalIndex();
}
if (enumfacing == Facing.SOUTH)
{
return Facing.EAST.getHorizontalIndex();
}
if (enumfacing == Facing.WEST)
{
return Facing.NORTH.getHorizontalIndex();
}
if (enumfacing == Facing.EAST)
{
return Facing.SOUTH.getHorizontalIndex();
}
}
else if (this.coordBaseMode == Facing.EAST)
{
if (enumfacing == Facing.NORTH)
{
return Facing.EAST.getHorizontalIndex();
}
if (enumfacing == Facing.SOUTH)
{
return Facing.WEST.getHorizontalIndex();
}
if (enumfacing == Facing.WEST)
{
return Facing.NORTH.getHorizontalIndex();
}
if (enumfacing == Facing.EAST)
{
return Facing.SOUTH.getHorizontalIndex();
}
}
}
}
else if (this.coordBaseMode == Facing.SOUTH)
{
if (meta == 2)
{
return 3;
}
if (meta == 3)
{
return 2;
}
}
else if (this.coordBaseMode == Facing.WEST)
{
if (meta == 0)
{
return 2;
}
if (meta == 1)
{
return 3;
}
if (meta == 2)
{
return 0;
}
if (meta == 3)
{
return 1;
}
}
else if (this.coordBaseMode == Facing.EAST)
{
if (meta == 0)
{
return 2;
}
if (meta == 1)
{
return 3;
}
if (meta == 2)
{
return 1;
}
if (meta == 3)
{
return 0;
}
}
return meta;
}
protected void setBlockState(WorldServer worldIn, State blockstateIn, int x, int y, int z, StructureBoundingBox boundingboxIn)
{
BlockPos blockpos = new BlockPos(this.getXWithOffset(x, z), this.getYWithOffset(y), this.getZWithOffset(x, z));
if (boundingboxIn.isVecInside(blockpos))
{
worldIn.setState(blockpos, blockstateIn, 2);
}
}
protected State getBlockStateFromPos(WorldServer worldIn, int x, int y, int z, StructureBoundingBox boundingboxIn)
{
int i = this.getXWithOffset(x, z);
int j = this.getYWithOffset(y);
int k = this.getZWithOffset(x, z);
BlockPos blockpos = new BlockPos(i, j, k);
return !boundingboxIn.isVecInside(blockpos) ? Blocks.air.getState() : worldIn.getState(blockpos);
}
/**
* arguments: (World worldObj, StructureBoundingBox structBB, int minX, int minY, int minZ, int maxX, int maxY, int
* maxZ)
*/
protected void fillWithAir(WorldServer worldIn, StructureBoundingBox structurebb, int minX, int minY, int minZ, int maxX, int maxY, int maxZ)
{
for (int i = minY; i <= maxY; ++i)
{
for (int j = minX; j <= maxX; ++j)
{
for (int k = minZ; k <= maxZ; ++k)
{
this.setBlockState(worldIn, Blocks.air.getState(), j, i, k, structurebb);
}
}
}
}
/**
* Fill the given area with the selected blocks
*/
protected void fillWithBlocks(WorldServer worldIn, StructureBoundingBox boundingboxIn, int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, State boundaryBlockState, State insideBlockState, boolean existingOnly)
{
for (int i = yMin; i <= yMax; ++i)
{
for (int j = xMin; j <= xMax; ++j)
{
for (int k = zMin; k <= zMax; ++k)
{
if (!existingOnly || this.getBlockStateFromPos(worldIn, j, i, k, boundingboxIn).getBlock().getMaterial() != Material.air)
{
if (i != yMin && i != yMax && j != xMin && j != xMax && k != zMin && k != zMax)
{
this.setBlockState(worldIn, insideBlockState, j, i, k, boundingboxIn);
}
else
{
this.setBlockState(worldIn, boundaryBlockState, j, i, k, boundingboxIn);
}
}
}
}
}
}
/**
* arguments: World worldObj, StructureBoundingBox structBB, int minX, int minY, int minZ, int maxX, int maxY, int
* maxZ, boolean alwaysreplace, Random rand, StructurePieceBlockSelector blockselector
*/
protected void fillWithRandomizedBlocks(WorldServer worldIn, StructureBoundingBox boundingboxIn, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, boolean alwaysReplace, Random rand, StructureComponent.BlockSelector blockselector)
{
for (int i = minY; i <= maxY; ++i)
{
for (int j = minX; j <= maxX; ++j)
{
for (int k = minZ; k <= maxZ; ++k)
{
if (!alwaysReplace || this.getBlockStateFromPos(worldIn, j, i, k, boundingboxIn).getBlock().getMaterial() != Material.air)
{
blockselector.selectBlocks(rand, j, i, k, i == minY || i == maxY || j == minX || j == maxX || k == minZ || k == maxZ);
this.setBlockState(worldIn, blockselector.getBlockState(), j, i, k, boundingboxIn);
}
}
}
}
}
protected void func_175805_a(WorldServer worldIn, StructureBoundingBox boundingboxIn, Random rand, float chance, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, State blockstate1, State blockstate2, boolean p_175805_13_)
{
for (int i = minY; i <= maxY; ++i)
{
for (int j = minX; j <= maxX; ++j)
{
for (int k = minZ; k <= maxZ; ++k)
{
if (rand.floatv() <= chance && (!p_175805_13_ || this.getBlockStateFromPos(worldIn, j, i, k, boundingboxIn).getBlock().getMaterial() != Material.air))
{
if (i != minY && i != maxY && j != minX && j != maxX && k != minZ && k != maxZ)
{
this.setBlockState(worldIn, blockstate2, j, i, k, boundingboxIn);
}
else
{
this.setBlockState(worldIn, blockstate1, j, i, k, boundingboxIn);
}
}
}
}
}
}
protected void randomlyPlaceBlock(WorldServer worldIn, StructureBoundingBox boundingboxIn, Random rand, float chance, int x, int y, int z, State blockstateIn)
{
if (rand.floatv() < chance)
{
this.setBlockState(worldIn, blockstateIn, x, y, z, boundingboxIn);
}
}
protected void randomlyRareFillWithBlocks(WorldServer worldIn, StructureBoundingBox boundingboxIn, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, State blockstateIn, boolean p_180777_10_)
{
float f = (float)(maxX - minX + 1);
float f1 = (float)(maxY - minY + 1);
float f2 = (float)(maxZ - minZ + 1);
float f3 = (float)minX + f / 2.0F;
float f4 = (float)minZ + f2 / 2.0F;
for (int i = minY; i <= maxY; ++i)
{
float f5 = (float)(i - minY) / f1;
for (int j = minX; j <= maxX; ++j)
{
float f6 = ((float)j - f3) / (f * 0.5F);
for (int k = minZ; k <= maxZ; ++k)
{
float f7 = ((float)k - f4) / (f2 * 0.5F);
if (!p_180777_10_ || this.getBlockStateFromPos(worldIn, j, i, k, boundingboxIn).getBlock().getMaterial() != Material.air)
{
float f8 = f6 * f6 + f5 * f5 + f7 * f7;
if (f8 <= 1.05F)
{
this.setBlockState(worldIn, blockstateIn, j, i, k, boundingboxIn);
}
}
}
}
}
}
/**
* Deletes all continuous blocks from selected position upwards. Stops at hitting air.
*/
protected void clearCurrentPositionBlocksUpwards(WorldServer worldIn, int x, int y, int z, StructureBoundingBox structurebb)
{
BlockPos blockpos = new BlockPos(this.getXWithOffset(x, z), this.getYWithOffset(y), this.getZWithOffset(x, z));
if (structurebb.isVecInside(blockpos))
{
while (!worldIn.isAirBlock(blockpos) && blockpos.getY() < 511)
{
worldIn.setState(blockpos, Blocks.air.getState(), 2);
blockpos = blockpos.up();
}
}
}
/**
* Replaces air and liquid from given position downwards. Stops when hitting anything else than air or liquid
*/
protected void replaceAirAndLiquidDownwards(WorldServer worldIn, State blockstateIn, int x, int y, int z, StructureBoundingBox boundingboxIn)
{
int i = this.getXWithOffset(x, z);
int j = this.getYWithOffset(y);
int k = this.getZWithOffset(x, z);
if (boundingboxIn.isVecInside(new BlockPos(i, j, k)))
{
while ((worldIn.isAirBlock(new BlockPos(i, j, k)) || worldIn.getState(new BlockPos(i, j, k)).getBlock().getMaterial().isLiquid()) && j > 1)
{
worldIn.setState(new BlockPos(i, j, k), blockstateIn, 2);
--j;
}
}
}
protected boolean generateChestContents(WorldServer worldIn, StructureBoundingBox boundingBoxIn, Random rand, int x, int y, int z, WeightedList<RngLoot> listIn, int max)
{
BlockPos blockpos = new BlockPos(this.getXWithOffset(x, z), this.getYWithOffset(y), this.getZWithOffset(x, z));
if (boundingBoxIn.isVecInside(blockpos) && worldIn.getState(blockpos).getBlock() != Blocks.chest)
{
State iblockstate = Blocks.chest.getState();
worldIn.setState(blockpos, Blocks.chest.correctFacing(worldIn, blockpos, iblockstate), 2);
TileEntity tileentity = worldIn.getTileEntity(blockpos);
if (tileentity instanceof TileEntityChest)
{
RngLoot.generateChestContents(rand, listIn, (TileEntityChest)tileentity, max);
}
return true;
}
else
{
return false;
}
}
protected boolean generateDispenserContents(WorldServer worldIn, StructureBoundingBox boundingBoxIn, Random rand, int x, int y, int z, int meta, WeightedList<RngLoot> listIn, int max)
{
BlockPos blockpos = new BlockPos(this.getXWithOffset(x, z), this.getYWithOffset(y), this.getZWithOffset(x, z));
if (boundingBoxIn.isVecInside(blockpos) && worldIn.getState(blockpos).getBlock() != Blocks.dispenser)
{
worldIn.setState(blockpos, Blocks.dispenser.getStateFromMeta(this.getMetadataWithOffset(Blocks.dispenser, meta)), 2);
TileEntity tileentity = worldIn.getTileEntity(blockpos);
if (tileentity instanceof TileEntityDispenser)
{
RngLoot.generateDispenserContents(rand, listIn, (TileEntityDispenser)tileentity, max);
}
return true;
}
else
{
return false;
}
}
/**
* Places door on given position
*/
protected void placeDoorCurrentPosition(WorldServer worldIn, StructureBoundingBox boundingBoxIn, Random rand, int x, int y, int z, Facing facing)
{
BlockPos blockpos = new BlockPos(this.getXWithOffset(x, z), this.getYWithOffset(y), this.getZWithOffset(x, z));
if (boundingBoxIn.isVecInside(blockpos))
{
ItemDoor.placeDoor(worldIn, blockpos, facing.rotateYCCW(), Blocks.oak_door, true);
}
}
public void func_181138_a(int p_181138_1_, int p_181138_2_, int p_181138_3_)
{
this.boundingBox.offset(p_181138_1_, p_181138_2_, p_181138_3_);
}
public abstract static class BlockSelector
{
protected State blockstate = Blocks.air.getState();
public abstract void selectBlocks(Random rand, int x, int y, int z, boolean p_75062_5_);
public State getBlockState()
{
return this.blockstate;
}
}
}

View file

@ -0,0 +1,833 @@
package server.worldgen.structure;
import java.util.LinkedList;
import java.util.List;
import common.entity.item.EntityChestCart;
import common.init.Blocks;
import common.init.Items;
import common.item.RngLoot;
import common.material.Material;
import common.nbt.NBTTagCompound;
import common.nbt.NBTTagList;
import common.rng.Random;
import common.rng.WeightedList;
import common.tileentity.TileEntity;
import common.tileentity.TileEntityMobSpawner;
import common.util.BlockPos;
import common.util.Facing;
import common.world.State;
import common.worldgen.LootConstants;
import server.world.WorldServer;
public class StructureMineshaft
{
public static void registerStructurePieces()
{
MapGenStructureIO.registerStructureComponent(StructureMineshaft.Corridor.class, "MSCorridor");
MapGenStructureIO.registerStructureComponent(StructureMineshaft.Cross.class, "MSCrossing");
MapGenStructureIO.registerStructureComponent(StructureMineshaft.Room.class, "MSRoom");
MapGenStructureIO.registerStructureComponent(StructureMineshaft.Stairs.class, "MSStairs");
}
private static StructureComponent func_175892_a(List<StructureComponent> listIn, Random rand, int x, int y, int z, Facing facing, int type)
{
int i = rand.zrange(100);
if (i >= 80)
{
StructureBoundingBox structureboundingbox = StructureMineshaft.Cross.func_175813_a(listIn, rand, x, y, z, facing);
if (structureboundingbox != null)
{
return new StructureMineshaft.Cross(type, rand, structureboundingbox, facing);
}
}
else if (i >= 70)
{
StructureBoundingBox structureboundingbox1 = StructureMineshaft.Stairs.func_175812_a(listIn, rand, x, y, z, facing);
if (structureboundingbox1 != null)
{
return new StructureMineshaft.Stairs(type, rand, structureboundingbox1, facing);
}
}
else
{
StructureBoundingBox structureboundingbox2 = StructureMineshaft.Corridor.func_175814_a(listIn, rand, x, y, z, facing);
if (structureboundingbox2 != null)
{
return new StructureMineshaft.Corridor(type, rand, structureboundingbox2, facing);
}
}
return null;
}
private static StructureComponent func_175890_b(StructureComponent componentIn, List<StructureComponent> listIn, Random rand, int x, int y, int z, Facing facing, int type)
{
if (type > 8)
{
return null;
}
else if (Math.abs(x - componentIn.getBoundingBox().minX) <= 80 && Math.abs(z - componentIn.getBoundingBox().minZ) <= 80)
{
StructureComponent structurecomponent = func_175892_a(listIn, rand, x, y, z, facing, type + 1);
if (structurecomponent != null)
{
listIn.add(structurecomponent);
structurecomponent.buildComponent(componentIn, listIn, rand);
}
return structurecomponent;
}
else
{
return null;
}
}
public static class Corridor extends StructureComponent
{
private boolean hasRails;
private boolean hasSpiders;
private boolean spawnerPlaced;
private int sectionCount;
public Corridor()
{
}
protected void writeStructureToNBT(NBTTagCompound tagCompound)
{
tagCompound.setBoolean("hr", this.hasRails);
tagCompound.setBoolean("sc", this.hasSpiders);
tagCompound.setBoolean("hps", this.spawnerPlaced);
tagCompound.setInteger("Num", this.sectionCount);
}
protected void readStructureFromNBT(NBTTagCompound tagCompound)
{
this.hasRails = tagCompound.getBoolean("hr");
this.hasSpiders = tagCompound.getBoolean("sc");
this.spawnerPlaced = tagCompound.getBoolean("hps");
this.sectionCount = tagCompound.getInteger("Num");
}
public Corridor(int type, Random rand, StructureBoundingBox structurebb, Facing facing)
{
super(type);
this.coordBaseMode = facing;
this.boundingBox = structurebb;
this.hasRails = rand.zrange(3) == 0;
this.hasSpiders = !this.hasRails && rand.zrange(23) == 0;
if (this.coordBaseMode != Facing.NORTH && this.coordBaseMode != Facing.SOUTH)
{
this.sectionCount = structurebb.getXSize() / 5;
}
else
{
this.sectionCount = structurebb.getZSize() / 5;
}
}
public static StructureBoundingBox func_175814_a(List<StructureComponent> p_175814_0_, Random rand, int x, int y, int z, Facing facing)
{
StructureBoundingBox structureboundingbox = new StructureBoundingBox(x, y, z, x, y + 2, z);
int i;
for (i = rand.zrange(3) + 2; i > 0; --i)
{
int j = i * 5;
switch (facing)
{
case NORTH:
structureboundingbox.maxX = x + 2;
structureboundingbox.minZ = z - (j - 1);
break;
case SOUTH:
structureboundingbox.maxX = x + 2;
structureboundingbox.maxZ = z + (j - 1);
break;
case WEST:
structureboundingbox.minX = x - (j - 1);
structureboundingbox.maxZ = z + 2;
break;
case EAST:
structureboundingbox.maxX = x + (j - 1);
structureboundingbox.maxZ = z + 2;
}
if (StructureComponent.findIntersecting(p_175814_0_, structureboundingbox) == null)
{
break;
}
}
return i > 0 ? structureboundingbox : null;
}
public void buildComponent(StructureComponent componentIn, List<StructureComponent> listIn, Random rand)
{
int i = this.getComponentType();
int j = rand.zrange(4);
if (this.coordBaseMode != null)
{
switch (this.coordBaseMode)
{
case NORTH:
if (j <= 1)
{
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX, this.boundingBox.minY - 1 + rand.zrange(3), this.boundingBox.minZ - 1, this.coordBaseMode, i);
}
else if (j == 2)
{
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX - 1, this.boundingBox.minY - 1 + rand.zrange(3), this.boundingBox.minZ, Facing.WEST, i);
}
else
{
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.maxX + 1, this.boundingBox.minY - 1 + rand.zrange(3), this.boundingBox.minZ, Facing.EAST, i);
}
break;
case SOUTH:
if (j <= 1)
{
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX, this.boundingBox.minY - 1 + rand.zrange(3), this.boundingBox.maxZ + 1, this.coordBaseMode, i);
}
else if (j == 2)
{
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX - 1, this.boundingBox.minY - 1 + rand.zrange(3), this.boundingBox.maxZ - 3, Facing.WEST, i);
}
else
{
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.maxX + 1, this.boundingBox.minY - 1 + rand.zrange(3), this.boundingBox.maxZ - 3, Facing.EAST, i);
}
break;
case WEST:
if (j <= 1)
{
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX - 1, this.boundingBox.minY - 1 + rand.zrange(3), this.boundingBox.minZ, this.coordBaseMode, i);
}
else if (j == 2)
{
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX, this.boundingBox.minY - 1 + rand.zrange(3), this.boundingBox.minZ - 1, Facing.NORTH, i);
}
else
{
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX, this.boundingBox.minY - 1 + rand.zrange(3), this.boundingBox.maxZ + 1, Facing.SOUTH, i);
}
break;
case EAST:
if (j <= 1)
{
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.maxX + 1, this.boundingBox.minY - 1 + rand.zrange(3), this.boundingBox.minZ, this.coordBaseMode, i);
}
else if (j == 2)
{
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.maxX - 3, this.boundingBox.minY - 1 + rand.zrange(3), this.boundingBox.minZ - 1, Facing.NORTH, i);
}
else
{
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.maxX - 3, this.boundingBox.minY - 1 + rand.zrange(3), this.boundingBox.maxZ + 1, Facing.SOUTH, i);
}
}
}
if (i < 8)
{
if (this.coordBaseMode != Facing.NORTH && this.coordBaseMode != Facing.SOUTH)
{
for (int i1 = this.boundingBox.minX + 3; i1 + 3 <= this.boundingBox.maxX; i1 += 5)
{
int j1 = rand.zrange(5);
if (j1 == 0)
{
StructureMineshaft.func_175890_b(componentIn, listIn, rand, i1, this.boundingBox.minY, this.boundingBox.minZ - 1, Facing.NORTH, i + 1);
}
else if (j1 == 1)
{
StructureMineshaft.func_175890_b(componentIn, listIn, rand, i1, this.boundingBox.minY, this.boundingBox.maxZ + 1, Facing.SOUTH, i + 1);
}
}
}
else
{
for (int k = this.boundingBox.minZ + 3; k + 3 <= this.boundingBox.maxZ; k += 5)
{
int l = rand.zrange(5);
if (l == 0)
{
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX - 1, this.boundingBox.minY, k, Facing.WEST, i + 1);
}
else if (l == 1)
{
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.maxX + 1, this.boundingBox.minY, k, Facing.EAST, i + 1);
}
}
}
}
}
protected boolean generateChestContents(WorldServer worldIn, StructureBoundingBox boundingBoxIn, Random rand, int x, int y, int z, WeightedList<RngLoot> listIn, int max)
{
BlockPos blockpos = new BlockPos(this.getXWithOffset(x, z), this.getYWithOffset(y), this.getZWithOffset(x, z));
if (boundingBoxIn.isVecInside(blockpos) && worldIn.getState(blockpos).getBlock().getMaterial() == Material.air)
{
int i = rand.chance() ? 1 : 0;
worldIn.setState(blockpos, Blocks.rail.getStateFromMeta(this.getMetadataWithOffset(Blocks.rail, i)), 2);
EntityChestCart entityminecartchest = new EntityChestCart(worldIn, (double)((float)blockpos.getX() + 0.5F), (double)((float)blockpos.getY() + 0.5F), (double)((float)blockpos.getZ() + 0.5F));
RngLoot.generateChestContents(rand, listIn, entityminecartchest, max);
worldIn.spawnEntityInWorld(entityminecartchest);
return true;
}
else
{
return false;
}
}
public boolean addComponentParts(WorldServer worldIn, Random randomIn, StructureBoundingBox structureBoundingBoxIn)
{
if (this.isLiquidInStructureBoundingBox(worldIn, structureBoundingBoxIn))
{
return false;
}
else
{
int i = 0;
int j = 2;
int k = 0;
int l = 2;
int i1 = this.sectionCount * 5 - 1;
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 0, 0, 0, 2, 1, i1, Blocks.air.getState(), Blocks.air.getState(), false);
this.func_175805_a(worldIn, structureBoundingBoxIn, randomIn, 0.8F, 0, 2, 0, 2, 2, i1, Blocks.air.getState(), Blocks.air.getState(), false);
if (this.hasSpiders)
{
this.func_175805_a(worldIn, structureBoundingBoxIn, randomIn, 0.6F, 0, 0, 0, 2, 1, i1, Blocks.web.getState(), Blocks.air.getState(), false);
}
for (int j1 = 0; j1 < this.sectionCount; ++j1)
{
int k1 = 2 + j1 * 5;
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 0, 0, k1, 0, 1, k1, Blocks.oak_fence.getState(), Blocks.air.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 2, 0, k1, 2, 1, k1, Blocks.oak_fence.getState(), Blocks.air.getState(), false);
if (randomIn.zrange(4) == 0)
{
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 0, 2, k1, 0, 2, k1, Blocks.oak_planks.getState(), Blocks.air.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 2, 2, k1, 2, 2, k1, Blocks.oak_planks.getState(), Blocks.air.getState(), false);
}
else
{
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 0, 2, k1, 2, 2, k1, Blocks.oak_planks.getState(), Blocks.air.getState(), false);
}
this.randomlyPlaceBlock(worldIn, structureBoundingBoxIn, randomIn, 0.1F, 0, 2, k1 - 1, Blocks.web.getState());
this.randomlyPlaceBlock(worldIn, structureBoundingBoxIn, randomIn, 0.1F, 2, 2, k1 - 1, Blocks.web.getState());
this.randomlyPlaceBlock(worldIn, structureBoundingBoxIn, randomIn, 0.1F, 0, 2, k1 + 1, Blocks.web.getState());
this.randomlyPlaceBlock(worldIn, structureBoundingBoxIn, randomIn, 0.1F, 2, 2, k1 + 1, Blocks.web.getState());
this.randomlyPlaceBlock(worldIn, structureBoundingBoxIn, randomIn, 0.05F, 0, 2, k1 - 2, Blocks.web.getState());
this.randomlyPlaceBlock(worldIn, structureBoundingBoxIn, randomIn, 0.05F, 2, 2, k1 - 2, Blocks.web.getState());
this.randomlyPlaceBlock(worldIn, structureBoundingBoxIn, randomIn, 0.05F, 0, 2, k1 + 2, Blocks.web.getState());
this.randomlyPlaceBlock(worldIn, structureBoundingBoxIn, randomIn, 0.05F, 2, 2, k1 + 2, Blocks.web.getState());
this.randomlyPlaceBlock(worldIn, structureBoundingBoxIn, randomIn, 0.05F, 1, 2, k1 - 1, Blocks.torch.getStateFromMeta(Facing.UP.getIndex()));
this.randomlyPlaceBlock(worldIn, structureBoundingBoxIn, randomIn, 0.05F, 1, 2, k1 + 1, Blocks.torch.getStateFromMeta(Facing.UP.getIndex()));
if (randomIn.zrange(100) == 0)
{
this.generateChestContents(worldIn, structureBoundingBoxIn, randomIn, 2, 0, k1 - 1, RngLoot.addToList(LootConstants.MINESHAFT_CHEST, Items.enchanted_book.getRandom(randomIn)), 3 + randomIn.zrange(4));
}
if (randomIn.zrange(100) == 0)
{
this.generateChestContents(worldIn, structureBoundingBoxIn, randomIn, 0, 0, k1 + 1, RngLoot.addToList(LootConstants.MINESHAFT_CHEST, Items.enchanted_book.getRandom(randomIn)), 3 + randomIn.zrange(4));
}
if (this.hasSpiders && !this.spawnerPlaced)
{
int l1 = this.getYWithOffset(0);
int i2 = k1 - 1 + randomIn.zrange(3);
int j2 = this.getXWithOffset(1, i2);
i2 = this.getZWithOffset(1, i2);
BlockPos blockpos = new BlockPos(j2, l1, i2);
if (structureBoundingBoxIn.isVecInside(blockpos))
{
this.spawnerPlaced = true;
worldIn.setState(blockpos, Blocks.mob_spawner.getState(), 2);
TileEntity tileentity = worldIn.getTileEntity(blockpos);
if (tileentity instanceof TileEntityMobSpawner)
{
((TileEntityMobSpawner)tileentity).setEntityName("Arachnoid");
}
}
}
}
for (int k2 = 0; k2 <= 2; ++k2)
{
for (int i3 = 0; i3 <= i1; ++i3)
{
int j3 = -1;
State iblockstate1 = this.getBlockStateFromPos(worldIn, k2, j3, i3, structureBoundingBoxIn);
if (iblockstate1.getBlock().getMaterial() == Material.air)
{
int k3 = -1;
this.setBlockState(worldIn, Blocks.oak_planks.getState(), k2, k3, i3, structureBoundingBoxIn);
}
}
}
if (this.hasRails)
{
for (int l2 = 0; l2 <= i1; ++l2)
{
State iblockstate = this.getBlockStateFromPos(worldIn, 1, -1, l2, structureBoundingBoxIn);
if (iblockstate.getBlock().getMaterial() != Material.air && iblockstate.getBlock().isFullBlock())
{
this.randomlyPlaceBlock(worldIn, structureBoundingBoxIn, randomIn, 0.7F, 1, 0, l2, Blocks.rail.getStateFromMeta(this.getMetadataWithOffset(Blocks.rail, 0)));
}
}
}
return true;
}
}
}
public static class Cross extends StructureComponent
{
private Facing corridorDirection;
private boolean isMultipleFloors;
public Cross()
{
}
protected void writeStructureToNBT(NBTTagCompound tagCompound)
{
tagCompound.setBoolean("tf", this.isMultipleFloors);
tagCompound.setInteger("D", this.corridorDirection.getHorizontalIndex());
}
protected void readStructureFromNBT(NBTTagCompound tagCompound)
{
this.isMultipleFloors = tagCompound.getBoolean("tf");
this.corridorDirection = Facing.getHorizontal(tagCompound.getInteger("D"));
}
public Cross(int type, Random rand, StructureBoundingBox structurebb, Facing facing)
{
super(type);
this.corridorDirection = facing;
this.boundingBox = structurebb;
this.isMultipleFloors = structurebb.getYSize() > 3;
}
public static StructureBoundingBox func_175813_a(List<StructureComponent> listIn, Random rand, int x, int y, int z, Facing facing)
{
StructureBoundingBox structureboundingbox = new StructureBoundingBox(x, y, z, x, y + 2, z);
if (rand.zrange(4) == 0)
{
structureboundingbox.maxY += 4;
}
switch (facing)
{
case NORTH:
structureboundingbox.minX = x - 1;
structureboundingbox.maxX = x + 3;
structureboundingbox.minZ = z - 4;
break;
case SOUTH:
structureboundingbox.minX = x - 1;
structureboundingbox.maxX = x + 3;
structureboundingbox.maxZ = z + 4;
break;
case WEST:
structureboundingbox.minX = x - 4;
structureboundingbox.minZ = z - 1;
structureboundingbox.maxZ = z + 3;
break;
case EAST:
structureboundingbox.maxX = x + 4;
structureboundingbox.minZ = z - 1;
structureboundingbox.maxZ = z + 3;
}
return StructureComponent.findIntersecting(listIn, structureboundingbox) != null ? null : structureboundingbox;
}
public void buildComponent(StructureComponent componentIn, List<StructureComponent> listIn, Random rand)
{
int i = this.getComponentType();
switch (this.corridorDirection)
{
case NORTH:
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.minZ - 1, Facing.NORTH, i);
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX - 1, this.boundingBox.minY, this.boundingBox.minZ + 1, Facing.WEST, i);
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.maxX + 1, this.boundingBox.minY, this.boundingBox.minZ + 1, Facing.EAST, i);
break;
case SOUTH:
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.maxZ + 1, Facing.SOUTH, i);
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX - 1, this.boundingBox.minY, this.boundingBox.minZ + 1, Facing.WEST, i);
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.maxX + 1, this.boundingBox.minY, this.boundingBox.minZ + 1, Facing.EAST, i);
break;
case WEST:
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.minZ - 1, Facing.NORTH, i);
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.maxZ + 1, Facing.SOUTH, i);
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX - 1, this.boundingBox.minY, this.boundingBox.minZ + 1, Facing.WEST, i);
break;
case EAST:
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.minZ - 1, Facing.NORTH, i);
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.maxZ + 1, Facing.SOUTH, i);
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.maxX + 1, this.boundingBox.minY, this.boundingBox.minZ + 1, Facing.EAST, i);
}
if (this.isMultipleFloors)
{
if (rand.chance())
{
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX + 1, this.boundingBox.minY + 3 + 1, this.boundingBox.minZ - 1, Facing.NORTH, i);
}
if (rand.chance())
{
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX - 1, this.boundingBox.minY + 3 + 1, this.boundingBox.minZ + 1, Facing.WEST, i);
}
if (rand.chance())
{
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.maxX + 1, this.boundingBox.minY + 3 + 1, this.boundingBox.minZ + 1, Facing.EAST, i);
}
if (rand.chance())
{
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX + 1, this.boundingBox.minY + 3 + 1, this.boundingBox.maxZ + 1, Facing.SOUTH, i);
}
}
}
public boolean addComponentParts(WorldServer worldIn, Random randomIn, StructureBoundingBox structureBoundingBoxIn)
{
if (this.isLiquidInStructureBoundingBox(worldIn, structureBoundingBoxIn))
{
return false;
}
else
{
if (this.isMultipleFloors)
{
this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.minZ, this.boundingBox.maxX - 1, this.boundingBox.minY + 3 - 1, this.boundingBox.maxZ, Blocks.air.getState(), Blocks.air.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.boundingBox.minX, this.boundingBox.minY, this.boundingBox.minZ + 1, this.boundingBox.maxX, this.boundingBox.minY + 3 - 1, this.boundingBox.maxZ - 1, Blocks.air.getState(), Blocks.air.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.boundingBox.minX + 1, this.boundingBox.maxY - 2, this.boundingBox.minZ, this.boundingBox.maxX - 1, this.boundingBox.maxY, this.boundingBox.maxZ, Blocks.air.getState(), Blocks.air.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.boundingBox.minX, this.boundingBox.maxY - 2, this.boundingBox.minZ + 1, this.boundingBox.maxX, this.boundingBox.maxY, this.boundingBox.maxZ - 1, Blocks.air.getState(), Blocks.air.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.boundingBox.minX + 1, this.boundingBox.minY + 3, this.boundingBox.minZ + 1, this.boundingBox.maxX - 1, this.boundingBox.minY + 3, this.boundingBox.maxZ - 1, Blocks.air.getState(), Blocks.air.getState(), false);
}
else
{
this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.minZ, this.boundingBox.maxX - 1, this.boundingBox.maxY, this.boundingBox.maxZ, Blocks.air.getState(), Blocks.air.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.boundingBox.minX, this.boundingBox.minY, this.boundingBox.minZ + 1, this.boundingBox.maxX, this.boundingBox.maxY, this.boundingBox.maxZ - 1, Blocks.air.getState(), Blocks.air.getState(), false);
}
this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.minZ + 1, this.boundingBox.minX + 1, this.boundingBox.maxY, this.boundingBox.minZ + 1, Blocks.oak_planks.getState(), Blocks.air.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.boundingBox.minX + 1, this.boundingBox.minY, this.boundingBox.maxZ - 1, this.boundingBox.minX + 1, this.boundingBox.maxY, this.boundingBox.maxZ - 1, Blocks.oak_planks.getState(), Blocks.air.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.boundingBox.maxX - 1, this.boundingBox.minY, this.boundingBox.minZ + 1, this.boundingBox.maxX - 1, this.boundingBox.maxY, this.boundingBox.minZ + 1, Blocks.oak_planks.getState(), Blocks.air.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.boundingBox.maxX - 1, this.boundingBox.minY, this.boundingBox.maxZ - 1, this.boundingBox.maxX - 1, this.boundingBox.maxY, this.boundingBox.maxZ - 1, Blocks.oak_planks.getState(), Blocks.air.getState(), false);
for (int i = this.boundingBox.minX; i <= this.boundingBox.maxX; ++i)
{
for (int j = this.boundingBox.minZ; j <= this.boundingBox.maxZ; ++j)
{
if (this.getBlockStateFromPos(worldIn, i, this.boundingBox.minY - 1, j, structureBoundingBoxIn).getBlock().getMaterial() == Material.air)
{
this.setBlockState(worldIn, Blocks.oak_planks.getState(), i, this.boundingBox.minY - 1, j, structureBoundingBoxIn);
}
}
}
return true;
}
}
}
public static class Room extends StructureComponent
{
private List<StructureBoundingBox> roomsLinkedToTheRoom = new LinkedList<StructureBoundingBox>();
public Room()
{
}
public Room(int type, Random rand, int x, int z)
{
super(type);
this.boundingBox = new StructureBoundingBox(x, 50, z, x + 7 + rand.zrange(6), 54 + rand.zrange(6), z + 7 + rand.zrange(6));
}
public void buildComponent(StructureComponent componentIn, List<StructureComponent> listIn, Random rand)
{
int i = this.getComponentType();
int j = this.boundingBox.getYSize() - 3 - 1;
if (j <= 0)
{
j = 1;
}
int k;
for (k = 0; k < this.boundingBox.getXSize(); k = k + 4)
{
k = k + rand.zrange(this.boundingBox.getXSize());
if (k + 3 > this.boundingBox.getXSize())
{
break;
}
StructureComponent structurecomponent = StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX + k, this.boundingBox.minY + rand.zrange(j) + 1, this.boundingBox.minZ - 1, Facing.NORTH, i);
if (structurecomponent != null)
{
StructureBoundingBox structureboundingbox = structurecomponent.getBoundingBox();
this.roomsLinkedToTheRoom.add(new StructureBoundingBox(structureboundingbox.minX, structureboundingbox.minY, this.boundingBox.minZ, structureboundingbox.maxX, structureboundingbox.maxY, this.boundingBox.minZ + 1));
}
}
for (k = 0; k < this.boundingBox.getXSize(); k = k + 4)
{
k = k + rand.zrange(this.boundingBox.getXSize());
if (k + 3 > this.boundingBox.getXSize())
{
break;
}
StructureComponent structurecomponent1 = StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX + k, this.boundingBox.minY + rand.zrange(j) + 1, this.boundingBox.maxZ + 1, Facing.SOUTH, i);
if (structurecomponent1 != null)
{
StructureBoundingBox structureboundingbox1 = structurecomponent1.getBoundingBox();
this.roomsLinkedToTheRoom.add(new StructureBoundingBox(structureboundingbox1.minX, structureboundingbox1.minY, this.boundingBox.maxZ - 1, structureboundingbox1.maxX, structureboundingbox1.maxY, this.boundingBox.maxZ));
}
}
for (k = 0; k < this.boundingBox.getZSize(); k = k + 4)
{
k = k + rand.zrange(this.boundingBox.getZSize());
if (k + 3 > this.boundingBox.getZSize())
{
break;
}
StructureComponent structurecomponent2 = StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX - 1, this.boundingBox.minY + rand.zrange(j) + 1, this.boundingBox.minZ + k, Facing.WEST, i);
if (structurecomponent2 != null)
{
StructureBoundingBox structureboundingbox2 = structurecomponent2.getBoundingBox();
this.roomsLinkedToTheRoom.add(new StructureBoundingBox(this.boundingBox.minX, structureboundingbox2.minY, structureboundingbox2.minZ, this.boundingBox.minX + 1, structureboundingbox2.maxY, structureboundingbox2.maxZ));
}
}
for (k = 0; k < this.boundingBox.getZSize(); k = k + 4)
{
k = k + rand.zrange(this.boundingBox.getZSize());
if (k + 3 > this.boundingBox.getZSize())
{
break;
}
StructureComponent structurecomponent3 = StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.maxX + 1, this.boundingBox.minY + rand.zrange(j) + 1, this.boundingBox.minZ + k, Facing.EAST, i);
if (structurecomponent3 != null)
{
StructureBoundingBox structureboundingbox3 = structurecomponent3.getBoundingBox();
this.roomsLinkedToTheRoom.add(new StructureBoundingBox(this.boundingBox.maxX - 1, structureboundingbox3.minY, structureboundingbox3.minZ, this.boundingBox.maxX, structureboundingbox3.maxY, structureboundingbox3.maxZ));
}
}
}
public boolean addComponentParts(WorldServer worldIn, Random randomIn, StructureBoundingBox structureBoundingBoxIn)
{
if (this.isLiquidInStructureBoundingBox(worldIn, structureBoundingBoxIn))
{
return false;
}
else
{
this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.boundingBox.minX, this.boundingBox.minY, this.boundingBox.minZ, this.boundingBox.maxX, this.boundingBox.minY, this.boundingBox.maxZ, Blocks.dirt.getState(), Blocks.air.getState(), true);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.boundingBox.minX, this.boundingBox.minY + 1, this.boundingBox.minZ, this.boundingBox.maxX, Math.min(this.boundingBox.minY + 3, this.boundingBox.maxY), this.boundingBox.maxZ, Blocks.air.getState(), Blocks.air.getState(), false);
for (StructureBoundingBox structureboundingbox : this.roomsLinkedToTheRoom)
{
this.fillWithBlocks(worldIn, structureBoundingBoxIn, structureboundingbox.minX, structureboundingbox.maxY - 2, structureboundingbox.minZ, structureboundingbox.maxX, structureboundingbox.maxY, structureboundingbox.maxZ, Blocks.air.getState(), Blocks.air.getState(), false);
}
this.randomlyRareFillWithBlocks(worldIn, structureBoundingBoxIn, this.boundingBox.minX, this.boundingBox.minY + 4, this.boundingBox.minZ, this.boundingBox.maxX, this.boundingBox.maxY, this.boundingBox.maxZ, Blocks.air.getState(), false);
return true;
}
}
public void func_181138_a(int p_181138_1_, int p_181138_2_, int p_181138_3_)
{
super.func_181138_a(p_181138_1_, p_181138_2_, p_181138_3_);
for (StructureBoundingBox structureboundingbox : this.roomsLinkedToTheRoom)
{
structureboundingbox.offset(p_181138_1_, p_181138_2_, p_181138_3_);
}
}
protected void writeStructureToNBT(NBTTagCompound tagCompound)
{
NBTTagList nbttaglist = new NBTTagList();
for (StructureBoundingBox structureboundingbox : this.roomsLinkedToTheRoom)
{
nbttaglist.appendTag(structureboundingbox.toNBTTagIntArray());
}
tagCompound.setTag("Entrances", nbttaglist);
}
protected void readStructureFromNBT(NBTTagCompound tagCompound)
{
NBTTagList nbttaglist = tagCompound.getTagList("Entrances", 11);
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
this.roomsLinkedToTheRoom.add(new StructureBoundingBox(nbttaglist.getIntArrayAt(i)));
}
}
}
public static class Stairs extends StructureComponent
{
public Stairs()
{
}
public Stairs(int type, Random rand, StructureBoundingBox structurebb, Facing facing)
{
super(type);
this.coordBaseMode = facing;
this.boundingBox = structurebb;
}
protected void writeStructureToNBT(NBTTagCompound tagCompound)
{
}
protected void readStructureFromNBT(NBTTagCompound tagCompound)
{
}
public static StructureBoundingBox func_175812_a(List<StructureComponent> listIn, Random rand, int x, int y, int z, Facing facing)
{
StructureBoundingBox structureboundingbox = new StructureBoundingBox(x, y - 5, z, x, y + 2, z);
switch (facing)
{
case NORTH:
structureboundingbox.maxX = x + 2;
structureboundingbox.minZ = z - 8;
break;
case SOUTH:
structureboundingbox.maxX = x + 2;
structureboundingbox.maxZ = z + 8;
break;
case WEST:
structureboundingbox.minX = x - 8;
structureboundingbox.maxZ = z + 2;
break;
case EAST:
structureboundingbox.maxX = x + 8;
structureboundingbox.maxZ = z + 2;
}
return StructureComponent.findIntersecting(listIn, structureboundingbox) != null ? null : structureboundingbox;
}
public void buildComponent(StructureComponent componentIn, List<StructureComponent> listIn, Random rand)
{
int i = this.getComponentType();
if (this.coordBaseMode != null)
{
switch (this.coordBaseMode)
{
case NORTH:
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX, this.boundingBox.minY, this.boundingBox.minZ - 1, Facing.NORTH, i);
break;
case SOUTH:
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX, this.boundingBox.minY, this.boundingBox.maxZ + 1, Facing.SOUTH, i);
break;
case WEST:
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.minX - 1, this.boundingBox.minY, this.boundingBox.minZ, Facing.WEST, i);
break;
case EAST:
StructureMineshaft.func_175890_b(componentIn, listIn, rand, this.boundingBox.maxX + 1, this.boundingBox.minY, this.boundingBox.minZ, Facing.EAST, i);
}
}
}
public boolean addComponentParts(WorldServer worldIn, Random randomIn, StructureBoundingBox structureBoundingBoxIn)
{
if (this.isLiquidInStructureBoundingBox(worldIn, structureBoundingBoxIn))
{
return false;
}
else
{
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 0, 5, 0, 2, 7, 1, Blocks.air.getState(), Blocks.air.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 0, 0, 7, 2, 2, 8, Blocks.air.getState(), Blocks.air.getState(), false);
for (int i = 0; i < 5; ++i)
{
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 0, 5 - i - (i < 4 ? 1 : 0), 2 + i, 2, 7 - i, 2 + i, Blocks.air.getState(), Blocks.air.getState(), false);
}
return true;
}
}
}
}

View file

@ -0,0 +1,21 @@
package server.worldgen.structure;
import common.rng.Random;
import server.world.WorldServer;
public class StructureMineshaftStart extends StructureStart
{
public StructureMineshaftStart()
{
}
public StructureMineshaftStart(WorldServer worldIn, Random rand, int chunkX, int chunkZ)
{
super(chunkX, chunkZ);
StructureMineshaft.Room structuremineshaftpieces$room = new StructureMineshaft.Room(0, rand, (chunkX << 4) + 2, (chunkZ << 4) + 2);
this.components.add(structuremineshaftpieces$room);
structuremineshaftpieces$room.buildComponent(structuremineshaftpieces$room, this.components, rand);
this.updateBoundingBox();
this.markAvailableHeight(worldIn, rand, 10);
}
}

View file

@ -0,0 +1,694 @@
package server.worldgen.structure;
import common.block.BlockFlower;
import common.block.BlockFlowerPot;
import common.block.BlockLever;
import common.block.BlockSandStone;
import common.block.BlockStoneBrick;
import common.block.BlockTripWire;
import common.block.BlockTripWireHook;
import common.color.DyeColor;
import common.entity.npc.EntityMage;
import common.init.Blocks;
import common.init.Config;
import common.init.Items;
import common.item.RngLoot;
import common.nbt.NBTTagCompound;
import common.rng.Random;
import common.util.BlockPos;
import common.util.Facing;
import common.worldgen.LootConstants;
import server.world.WorldServer;
public class StructureScattered
{
public static void registerScatteredFeaturePieces()
{
MapGenStructureIO.registerStructureComponent(StructureScattered.DesertPyramid.class, "TeDP");
MapGenStructureIO.registerStructureComponent(StructureScattered.JunglePyramid.class, "TeJP");
MapGenStructureIO.registerStructureComponent(StructureScattered.SwampHut.class, "TeSH");
}
public static class DesertPyramid extends StructureScattered.Feature
{
private boolean[] hasPlacedChest = new boolean[4];
public DesertPyramid()
{
}
public DesertPyramid(Random p_i2062_1_, int p_i2062_2_, int p_i2062_3_)
{
super(p_i2062_1_, p_i2062_2_, 64, p_i2062_3_, 21, 15, 21);
}
protected void writeStructureToNBT(NBTTagCompound tagCompound)
{
super.writeStructureToNBT(tagCompound);
tagCompound.setBoolean("hasPlacedChest0", this.hasPlacedChest[0]);
tagCompound.setBoolean("hasPlacedChest1", this.hasPlacedChest[1]);
tagCompound.setBoolean("hasPlacedChest2", this.hasPlacedChest[2]);
tagCompound.setBoolean("hasPlacedChest3", this.hasPlacedChest[3]);
}
protected void readStructureFromNBT(NBTTagCompound tagCompound)
{
super.readStructureFromNBT(tagCompound);
this.hasPlacedChest[0] = tagCompound.getBoolean("hasPlacedChest0");
this.hasPlacedChest[1] = tagCompound.getBoolean("hasPlacedChest1");
this.hasPlacedChest[2] = tagCompound.getBoolean("hasPlacedChest2");
this.hasPlacedChest[3] = tagCompound.getBoolean("hasPlacedChest3");
}
public boolean addComponentParts(WorldServer worldIn, Random randomIn, StructureBoundingBox structureBoundingBoxIn)
{
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 0, -4, 0, this.scatteredFeatureSizeX - 1, 0, this.scatteredFeatureSizeZ - 1, Blocks.sandstone.getState(), Blocks.sandstone.getState(), false);
for (int i = 1; i <= 9; ++i)
{
this.fillWithBlocks(worldIn, structureBoundingBoxIn, i, i, i, this.scatteredFeatureSizeX - 1 - i, i, this.scatteredFeatureSizeZ - 1 - i, Blocks.sandstone.getState(), Blocks.sandstone.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, i + 1, i, i + 1, this.scatteredFeatureSizeX - 2 - i, i, this.scatteredFeatureSizeZ - 2 - i, Blocks.air.getState(), Blocks.air.getState(), false);
}
for (int j2 = 0; j2 < this.scatteredFeatureSizeX; ++j2)
{
for (int j = 0; j < this.scatteredFeatureSizeZ; ++j)
{
int k = -5;
this.replaceAirAndLiquidDownwards(worldIn, Blocks.sandstone.getState(), j2, k, j, structureBoundingBoxIn);
}
}
int k2 = this.getMetadataWithOffset(Blocks.sandstone_stairs, 3);
int l2 = this.getMetadataWithOffset(Blocks.sandstone_stairs, 2);
int i3 = this.getMetadataWithOffset(Blocks.sandstone_stairs, 0);
int l = this.getMetadataWithOffset(Blocks.sandstone_stairs, 1);
int i1 = ~DyeColor.ORANGE.getDyeDamage() & 15;
int j1 = ~DyeColor.BLUE.getDyeDamage() & 15;
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 0, 0, 0, 4, 9, 4, Blocks.sandstone.getState(), Blocks.air.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 1, 10, 1, 3, 10, 3, Blocks.sandstone.getState(), Blocks.sandstone.getState(), false);
this.setBlockState(worldIn, Blocks.sandstone_stairs.getStateFromMeta(k2), 2, 10, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone_stairs.getStateFromMeta(l2), 2, 10, 4, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone_stairs.getStateFromMeta(i3), 0, 10, 2, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone_stairs.getStateFromMeta(l), 4, 10, 2, structureBoundingBoxIn);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.scatteredFeatureSizeX - 5, 0, 0, this.scatteredFeatureSizeX - 1, 9, 4, Blocks.sandstone.getState(), Blocks.air.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.scatteredFeatureSizeX - 4, 10, 1, this.scatteredFeatureSizeX - 2, 10, 3, Blocks.sandstone.getState(), Blocks.sandstone.getState(), false);
this.setBlockState(worldIn, Blocks.sandstone_stairs.getStateFromMeta(k2), this.scatteredFeatureSizeX - 3, 10, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone_stairs.getStateFromMeta(l2), this.scatteredFeatureSizeX - 3, 10, 4, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone_stairs.getStateFromMeta(i3), this.scatteredFeatureSizeX - 5, 10, 2, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone_stairs.getStateFromMeta(l), this.scatteredFeatureSizeX - 1, 10, 2, structureBoundingBoxIn);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 8, 0, 0, 12, 4, 4, Blocks.sandstone.getState(), Blocks.air.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 9, 1, 0, 11, 3, 4, Blocks.air.getState(), Blocks.air.getState(), false);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), 9, 1, 1, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), 9, 2, 1, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), 9, 3, 1, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), 10, 3, 1, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), 11, 3, 1, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), 11, 2, 1, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), 11, 1, 1, structureBoundingBoxIn);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 4, 1, 1, 8, 3, 3, Blocks.sandstone.getState(), Blocks.air.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 4, 1, 2, 8, 2, 2, Blocks.air.getState(), Blocks.air.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 12, 1, 1, 16, 3, 3, Blocks.sandstone.getState(), Blocks.air.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 12, 1, 2, 16, 2, 2, Blocks.air.getState(), Blocks.air.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 5, 4, 5, this.scatteredFeatureSizeX - 6, 4, this.scatteredFeatureSizeZ - 6, Blocks.sandstone.getState(), Blocks.sandstone.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 9, 4, 9, 11, 4, 11, Blocks.air.getState(), Blocks.air.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 8, 1, 8, 8, 3, 8, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 12, 1, 8, 12, 3, 8, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 8, 1, 12, 8, 3, 12, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 12, 1, 12, 12, 3, 12, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 1, 1, 5, 4, 4, 11, Blocks.sandstone.getState(), Blocks.sandstone.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.scatteredFeatureSizeX - 5, 1, 5, this.scatteredFeatureSizeX - 2, 4, 11, Blocks.sandstone.getState(), Blocks.sandstone.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 6, 7, 9, 6, 7, 11, Blocks.sandstone.getState(), Blocks.sandstone.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.scatteredFeatureSizeX - 7, 7, 9, this.scatteredFeatureSizeX - 7, 7, 11, Blocks.sandstone.getState(), Blocks.sandstone.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 5, 5, 9, 5, 7, 11, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.scatteredFeatureSizeX - 6, 5, 9, this.scatteredFeatureSizeX - 6, 7, 11, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), false);
this.setBlockState(worldIn, Blocks.air.getState(), 5, 5, 10, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.air.getState(), 5, 6, 10, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.air.getState(), 6, 6, 10, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.air.getState(), this.scatteredFeatureSizeX - 6, 5, 10, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.air.getState(), this.scatteredFeatureSizeX - 6, 6, 10, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.air.getState(), this.scatteredFeatureSizeX - 7, 6, 10, structureBoundingBoxIn);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 2, 4, 4, 2, 6, 4, Blocks.air.getState(), Blocks.air.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.scatteredFeatureSizeX - 3, 4, 4, this.scatteredFeatureSizeX - 3, 6, 4, Blocks.air.getState(), Blocks.air.getState(), false);
this.setBlockState(worldIn, Blocks.sandstone_stairs.getStateFromMeta(k2), 2, 4, 5, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone_stairs.getStateFromMeta(k2), 2, 3, 4, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone_stairs.getStateFromMeta(k2), this.scatteredFeatureSizeX - 3, 4, 5, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone_stairs.getStateFromMeta(k2), this.scatteredFeatureSizeX - 3, 3, 4, structureBoundingBoxIn);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 1, 1, 3, 2, 2, 3, Blocks.sandstone.getState(), Blocks.sandstone.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.scatteredFeatureSizeX - 3, 1, 3, this.scatteredFeatureSizeX - 2, 2, 3, Blocks.sandstone.getState(), Blocks.sandstone.getState(), false);
this.setBlockState(worldIn, Blocks.sandstone_stairs.getState(), 1, 1, 2, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone_stairs.getState(), this.scatteredFeatureSizeX - 2, 1, 2, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone_slab.getState(), 1, 2, 2, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone_slab.getState(), this.scatteredFeatureSizeX - 2, 2, 2, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone_stairs.getStateFromMeta(l), 2, 1, 2, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone_stairs.getStateFromMeta(i3), this.scatteredFeatureSizeX - 3, 1, 2, structureBoundingBoxIn);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 4, 3, 5, 4, 3, 18, Blocks.sandstone.getState(), Blocks.sandstone.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.scatteredFeatureSizeX - 5, 3, 5, this.scatteredFeatureSizeX - 5, 3, 17, Blocks.sandstone.getState(), Blocks.sandstone.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 3, 1, 5, 4, 2, 16, Blocks.air.getState(), Blocks.air.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, this.scatteredFeatureSizeX - 6, 1, 5, this.scatteredFeatureSizeX - 5, 2, 16, Blocks.air.getState(), Blocks.air.getState(), false);
for (int k1 = 5; k1 <= 17; k1 += 2)
{
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), 4, 1, k1, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.CHISELED.getMetadata()), 4, 2, k1, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), this.scatteredFeatureSizeX - 5, 1, k1, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.CHISELED.getMetadata()), this.scatteredFeatureSizeX - 5, 2, k1, structureBoundingBoxIn);
}
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), 10, 0, 7, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), 10, 0, 8, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), 9, 0, 9, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), 11, 0, 9, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), 8, 0, 10, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), 12, 0, 10, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), 7, 0, 10, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), 13, 0, 10, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), 9, 0, 11, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), 11, 0, 11, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), 10, 0, 12, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), 10, 0, 13, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(j1), 10, 0, 10, structureBoundingBoxIn);
for (int j3 = 0; j3 <= this.scatteredFeatureSizeX - 1; j3 += this.scatteredFeatureSizeX - 1)
{
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), j3, 2, 1, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), j3, 2, 2, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), j3, 2, 3, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), j3, 3, 1, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), j3, 3, 2, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), j3, 3, 3, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), j3, 4, 1, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.CHISELED.getMetadata()), j3, 4, 2, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), j3, 4, 3, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), j3, 5, 1, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), j3, 5, 2, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), j3, 5, 3, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), j3, 6, 1, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.CHISELED.getMetadata()), j3, 6, 2, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), j3, 6, 3, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), j3, 7, 1, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), j3, 7, 2, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), j3, 7, 3, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), j3, 8, 1, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), j3, 8, 2, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), j3, 8, 3, structureBoundingBoxIn);
}
for (int k3 = 2; k3 <= this.scatteredFeatureSizeX - 3; k3 += this.scatteredFeatureSizeX - 3 - 2)
{
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), k3 - 1, 2, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), k3, 2, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), k3 + 1, 2, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), k3 - 1, 3, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), k3, 3, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), k3 + 1, 3, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), k3 - 1, 4, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.CHISELED.getMetadata()), k3, 4, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), k3 + 1, 4, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), k3 - 1, 5, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), k3, 5, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), k3 + 1, 5, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), k3 - 1, 6, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.CHISELED.getMetadata()), k3, 6, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), k3 + 1, 6, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), k3 - 1, 7, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), k3, 7, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), k3 + 1, 7, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), k3 - 1, 8, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), k3, 8, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), k3 + 1, 8, 0, structureBoundingBoxIn);
}
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 8, 4, 0, 12, 6, 0, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), false);
this.setBlockState(worldIn, Blocks.air.getState(), 8, 6, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.air.getState(), 12, 6, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), 9, 5, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.CHISELED.getMetadata()), 10, 5, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stained_hardened_clay.getStateFromMeta(i1), 11, 5, 0, structureBoundingBoxIn);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 8, -14, 8, 12, -11, 12, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 8, -10, 8, 12, -10, 12, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.CHISELED.getMetadata()), Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.CHISELED.getMetadata()), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 8, -9, 8, 12, -9, 12, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 8, -8, 8, 12, -1, 12, Blocks.sandstone.getState(), Blocks.sandstone.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 9, -11, 9, 11, -1, 11, Blocks.air.getState(), Blocks.air.getState(), false);
this.setBlockState(worldIn, Blocks.stone_pressure_plate.getState(), 10, -11, 10, structureBoundingBoxIn);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 9, -13, 9, 11, -13, 11, Blocks.tnt.getState(), Blocks.air.getState(), false);
this.setBlockState(worldIn, Blocks.air.getState(), 8, -11, 10, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.air.getState(), 8, -10, 10, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.CHISELED.getMetadata()), 7, -10, 10, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), 7, -11, 10, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.air.getState(), 12, -11, 10, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.air.getState(), 12, -10, 10, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.CHISELED.getMetadata()), 13, -10, 10, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), 13, -11, 10, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.air.getState(), 10, -11, 8, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.air.getState(), 10, -10, 8, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.CHISELED.getMetadata()), 10, -10, 7, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), 10, -11, 7, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.air.getState(), 10, -11, 12, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.air.getState(), 10, -10, 12, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.CHISELED.getMetadata()), 10, -10, 13, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sandstone.getStateFromMeta(BlockSandStone.EnumType.SMOOTH.getMetadata()), 10, -11, 13, structureBoundingBoxIn);
for (Facing enumfacing : Facing.Plane.HORIZONTAL)
{
if (!this.hasPlacedChest[enumfacing.getHorizontalIndex()])
{
int l1 = enumfacing.getFrontOffsetX() * 2;
int i2 = enumfacing.getFrontOffsetZ() * 2;
this.hasPlacedChest[enumfacing.getHorizontalIndex()] = this.generateChestContents(worldIn, structureBoundingBoxIn, randomIn, 10 + l1, -11, 10 + i2, RngLoot.addToList(LootConstants.DESERT_PYRAMID, Items.enchanted_book.getRandom(randomIn)), 2 + randomIn.zrange(5));
}
}
return true;
}
}
abstract static class Feature extends StructureComponent
{
protected int scatteredFeatureSizeX;
protected int scatteredFeatureSizeY;
protected int scatteredFeatureSizeZ;
protected int field_74936_d = -1;
public Feature()
{
}
protected Feature(Random p_i2065_1_, int p_i2065_2_, int p_i2065_3_, int p_i2065_4_, int p_i2065_5_, int p_i2065_6_, int p_i2065_7_)
{
super(0);
this.scatteredFeatureSizeX = p_i2065_5_;
this.scatteredFeatureSizeY = p_i2065_6_;
this.scatteredFeatureSizeZ = p_i2065_7_;
this.coordBaseMode = Facing.Plane.HORIZONTAL.random(p_i2065_1_);
switch (this.coordBaseMode)
{
case NORTH:
case SOUTH:
this.boundingBox = new StructureBoundingBox(p_i2065_2_, p_i2065_3_, p_i2065_4_, p_i2065_2_ + p_i2065_5_ - 1, p_i2065_3_ + p_i2065_6_ - 1, p_i2065_4_ + p_i2065_7_ - 1);
break;
default:
this.boundingBox = new StructureBoundingBox(p_i2065_2_, p_i2065_3_, p_i2065_4_, p_i2065_2_ + p_i2065_7_ - 1, p_i2065_3_ + p_i2065_6_ - 1, p_i2065_4_ + p_i2065_5_ - 1);
}
}
protected void writeStructureToNBT(NBTTagCompound tagCompound)
{
tagCompound.setInteger("Width", this.scatteredFeatureSizeX);
tagCompound.setInteger("Height", this.scatteredFeatureSizeY);
tagCompound.setInteger("Depth", this.scatteredFeatureSizeZ);
tagCompound.setInteger("HPos", this.field_74936_d);
}
protected void readStructureFromNBT(NBTTagCompound tagCompound)
{
this.scatteredFeatureSizeX = tagCompound.getInteger("Width");
this.scatteredFeatureSizeY = tagCompound.getInteger("Height");
this.scatteredFeatureSizeZ = tagCompound.getInteger("Depth");
this.field_74936_d = tagCompound.getInteger("HPos");
}
protected boolean func_74935_a(WorldServer worldIn, StructureBoundingBox p_74935_2_, int p_74935_3_)
{
if (this.field_74936_d >= 0)
{
return true;
}
else
{
int i = 0;
int j = 0;
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
for (int k = this.boundingBox.minZ; k <= this.boundingBox.maxZ; ++k)
{
for (int l = this.boundingBox.minX; l <= this.boundingBox.maxX; ++l)
{
blockpos$mutableblockpos.set(l, 64, k);
if (p_74935_2_.isVecInside(blockpos$mutableblockpos))
{
i += Math.max(worldIn.getTopSolidOrLiquidBlock(blockpos$mutableblockpos).getY(), worldIn.getSeaLevel());
++j;
}
}
}
if (j == 0)
{
return false;
}
else
{
this.field_74936_d = i / j;
this.boundingBox.offset(0, this.field_74936_d - this.boundingBox.minY + p_74935_3_, 0);
return true;
}
}
}
}
public static class JunglePyramid extends StructureScattered.Feature
{
private boolean placedMainChest;
private boolean placedHiddenChest;
private boolean placedTrap1;
private boolean placedTrap2;
private static StructureScattered.JunglePyramid.Stones junglePyramidsRandomScatteredStones = new StructureScattered.JunglePyramid.Stones();
public JunglePyramid()
{
}
public JunglePyramid(Random p_i2064_1_, int p_i2064_2_, int p_i2064_3_)
{
super(p_i2064_1_, p_i2064_2_, 64, p_i2064_3_, 12, 10, 15);
}
protected void writeStructureToNBT(NBTTagCompound tagCompound)
{
super.writeStructureToNBT(tagCompound);
tagCompound.setBoolean("placedMainChest", this.placedMainChest);
tagCompound.setBoolean("placedHiddenChest", this.placedHiddenChest);
tagCompound.setBoolean("placedTrap1", this.placedTrap1);
tagCompound.setBoolean("placedTrap2", this.placedTrap2);
}
protected void readStructureFromNBT(NBTTagCompound tagCompound)
{
super.readStructureFromNBT(tagCompound);
this.placedMainChest = tagCompound.getBoolean("placedMainChest");
this.placedHiddenChest = tagCompound.getBoolean("placedHiddenChest");
this.placedTrap1 = tagCompound.getBoolean("placedTrap1");
this.placedTrap2 = tagCompound.getBoolean("placedTrap2");
}
public boolean addComponentParts(WorldServer worldIn, Random randomIn, StructureBoundingBox structureBoundingBoxIn)
{
if (!this.func_74935_a(worldIn, structureBoundingBoxIn, 0))
{
return false;
}
else
{
int i = this.getMetadataWithOffset(Blocks.cobblestone_stairs, 3);
int j = this.getMetadataWithOffset(Blocks.cobblestone_stairs, 2);
int k = this.getMetadataWithOffset(Blocks.cobblestone_stairs, 0);
int l = this.getMetadataWithOffset(Blocks.cobblestone_stairs, 1);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 0, -4, 0, this.scatteredFeatureSizeX - 1, 0, this.scatteredFeatureSizeZ - 1, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 2, 1, 2, 9, 2, 2, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 2, 1, 12, 9, 2, 12, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 2, 1, 3, 2, 2, 11, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 9, 1, 3, 9, 2, 11, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 1, 3, 1, 10, 6, 1, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 1, 3, 13, 10, 6, 13, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 1, 3, 2, 1, 6, 12, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 10, 3, 2, 10, 6, 12, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 2, 3, 2, 9, 3, 12, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 2, 6, 2, 9, 6, 12, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 3, 7, 3, 8, 7, 11, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 4, 8, 4, 7, 8, 10, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithAir(worldIn, structureBoundingBoxIn, 3, 1, 3, 8, 2, 11);
this.fillWithAir(worldIn, structureBoundingBoxIn, 4, 3, 6, 7, 3, 9);
this.fillWithAir(worldIn, structureBoundingBoxIn, 2, 4, 2, 9, 5, 12);
this.fillWithAir(worldIn, structureBoundingBoxIn, 4, 6, 5, 7, 6, 9);
this.fillWithAir(worldIn, structureBoundingBoxIn, 5, 7, 6, 6, 7, 8);
this.fillWithAir(worldIn, structureBoundingBoxIn, 5, 1, 2, 6, 2, 2);
this.fillWithAir(worldIn, structureBoundingBoxIn, 5, 2, 12, 6, 2, 12);
this.fillWithAir(worldIn, structureBoundingBoxIn, 5, 5, 1, 6, 5, 1);
this.fillWithAir(worldIn, structureBoundingBoxIn, 5, 5, 13, 6, 5, 13);
this.setBlockState(worldIn, Blocks.air.getState(), 1, 5, 5, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.air.getState(), 10, 5, 5, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.air.getState(), 1, 5, 9, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.air.getState(), 10, 5, 9, structureBoundingBoxIn);
for (int i1 = 0; i1 <= 14; i1 += 14)
{
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 2, 4, i1, 2, 5, i1, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 4, 4, i1, 4, 5, i1, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 7, 4, i1, 7, 5, i1, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 9, 4, i1, 9, 5, i1, false, randomIn, junglePyramidsRandomScatteredStones);
}
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 5, 6, 0, 6, 6, 0, false, randomIn, junglePyramidsRandomScatteredStones);
for (int k1 = 0; k1 <= 11; k1 += 11)
{
for (int j1 = 2; j1 <= 12; j1 += 2)
{
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, k1, 4, j1, k1, 5, j1, false, randomIn, junglePyramidsRandomScatteredStones);
}
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, k1, 6, 5, k1, 6, 5, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, k1, 6, 9, k1, 6, 9, false, randomIn, junglePyramidsRandomScatteredStones);
}
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 2, 7, 2, 2, 9, 2, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 9, 7, 2, 9, 9, 2, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 2, 7, 12, 2, 9, 12, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 9, 7, 12, 9, 9, 12, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 4, 9, 4, 4, 9, 4, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 7, 9, 4, 7, 9, 4, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 4, 9, 10, 4, 9, 10, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 7, 9, 10, 7, 9, 10, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 5, 9, 7, 6, 9, 7, false, randomIn, junglePyramidsRandomScatteredStones);
this.setBlockState(worldIn, Blocks.cobblestone_stairs.getStateFromMeta(i), 5, 9, 6, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.cobblestone_stairs.getStateFromMeta(i), 6, 9, 6, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.cobblestone_stairs.getStateFromMeta(j), 5, 9, 8, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.cobblestone_stairs.getStateFromMeta(j), 6, 9, 8, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.cobblestone_stairs.getStateFromMeta(i), 4, 0, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.cobblestone_stairs.getStateFromMeta(i), 5, 0, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.cobblestone_stairs.getStateFromMeta(i), 6, 0, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.cobblestone_stairs.getStateFromMeta(i), 7, 0, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.cobblestone_stairs.getStateFromMeta(i), 4, 1, 8, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.cobblestone_stairs.getStateFromMeta(i), 4, 2, 9, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.cobblestone_stairs.getStateFromMeta(i), 4, 3, 10, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.cobblestone_stairs.getStateFromMeta(i), 7, 1, 8, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.cobblestone_stairs.getStateFromMeta(i), 7, 2, 9, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.cobblestone_stairs.getStateFromMeta(i), 7, 3, 10, structureBoundingBoxIn);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 4, 1, 9, 4, 1, 9, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 7, 1, 9, 7, 1, 9, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 4, 1, 10, 7, 2, 10, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 5, 4, 5, 6, 4, 5, false, randomIn, junglePyramidsRandomScatteredStones);
this.setBlockState(worldIn, Blocks.cobblestone_stairs.getStateFromMeta(k), 4, 4, 5, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.cobblestone_stairs.getStateFromMeta(l), 7, 4, 5, structureBoundingBoxIn);
for (int l1 = 0; l1 < 4; ++l1)
{
this.setBlockState(worldIn, Blocks.cobblestone_stairs.getStateFromMeta(j), 5, 0 - l1, 6 + l1, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.cobblestone_stairs.getStateFromMeta(j), 6, 0 - l1, 6 + l1, structureBoundingBoxIn);
this.fillWithAir(worldIn, structureBoundingBoxIn, 5, 0 - l1, 7 + l1, 6, 0 - l1, 9 + l1);
}
this.fillWithAir(worldIn, structureBoundingBoxIn, 1, -3, 12, 10, -1, 13);
this.fillWithAir(worldIn, structureBoundingBoxIn, 1, -3, 1, 3, -1, 13);
this.fillWithAir(worldIn, structureBoundingBoxIn, 1, -3, 1, 9, -1, 5);
for (int i2 = 1; i2 <= 13; i2 += 2)
{
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 1, -3, i2, 1, -2, i2, false, randomIn, junglePyramidsRandomScatteredStones);
}
for (int j2 = 2; j2 <= 12; j2 += 2)
{
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 1, -1, j2, 3, -1, j2, false, randomIn, junglePyramidsRandomScatteredStones);
}
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 2, -2, 1, 5, -2, 1, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 7, -2, 1, 9, -2, 1, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 6, -3, 1, 6, -3, 1, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 6, -1, 1, 6, -1, 1, false, randomIn, junglePyramidsRandomScatteredStones);
this.setBlockState(worldIn, Blocks.tripwire_hook.getStateFromMeta(this.getMetadataWithOffset(Blocks.tripwire_hook, Facing.EAST.getHorizontalIndex())).withProperty(BlockTripWireHook.ATTACHED, Boolean.valueOf(true)), 1, -3, 8, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.tripwire_hook.getStateFromMeta(this.getMetadataWithOffset(Blocks.tripwire_hook, Facing.WEST.getHorizontalIndex())).withProperty(BlockTripWireHook.ATTACHED, Boolean.valueOf(true)), 4, -3, 8, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.string.getState().withProperty(BlockTripWire.ATTACHED, Boolean.valueOf(true)), 2, -3, 8, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.string.getState().withProperty(BlockTripWire.ATTACHED, Boolean.valueOf(true)), 3, -3, 8, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.redstone.getState(), 5, -3, 7, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.redstone.getState(), 5, -3, 6, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.redstone.getState(), 5, -3, 5, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.redstone.getState(), 5, -3, 4, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.redstone.getState(), 5, -3, 3, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.redstone.getState(), 5, -3, 2, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.redstone.getState(), 5, -3, 1, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.redstone.getState(), 4, -3, 1, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.mossy_cobblestone.getState(), 3, -3, 1, structureBoundingBoxIn);
if (!this.placedTrap1)
{
this.placedTrap1 = this.generateDispenserContents(worldIn, structureBoundingBoxIn, randomIn, 3, -2, 1, Facing.NORTH.getIndex(), LootConstants.JUNGLE_TRAP, 2);
}
this.setBlockState(worldIn, Blocks.vine.getStateFromMeta(15), 3, -2, 2, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.tripwire_hook.getStateFromMeta(this.getMetadataWithOffset(Blocks.tripwire_hook, Facing.NORTH.getHorizontalIndex())).withProperty(BlockTripWireHook.ATTACHED, Boolean.valueOf(true)), 7, -3, 1, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.tripwire_hook.getStateFromMeta(this.getMetadataWithOffset(Blocks.tripwire_hook, Facing.SOUTH.getHorizontalIndex())).withProperty(BlockTripWireHook.ATTACHED, Boolean.valueOf(true)), 7, -3, 5, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.string.getState().withProperty(BlockTripWire.ATTACHED, Boolean.valueOf(true)), 7, -3, 2, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.string.getState().withProperty(BlockTripWire.ATTACHED, Boolean.valueOf(true)), 7, -3, 3, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.string.getState().withProperty(BlockTripWire.ATTACHED, Boolean.valueOf(true)), 7, -3, 4, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.redstone.getState(), 8, -3, 6, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.redstone.getState(), 9, -3, 6, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.redstone.getState(), 9, -3, 5, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.mossy_cobblestone.getState(), 9, -3, 4, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.redstone.getState(), 9, -2, 4, structureBoundingBoxIn);
if (!this.placedTrap2)
{
this.placedTrap2 = this.generateDispenserContents(worldIn, structureBoundingBoxIn, randomIn, 9, -2, 3, Facing.WEST.getIndex(), LootConstants.JUNGLE_TRAP, 2);
}
this.setBlockState(worldIn, Blocks.vine.getStateFromMeta(15), 8, -1, 3, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.vine.getStateFromMeta(15), 8, -2, 3, structureBoundingBoxIn);
if (!this.placedMainChest)
{
this.placedMainChest = this.generateChestContents(worldIn, structureBoundingBoxIn, randomIn, 8, -3, 3, RngLoot.addToList(LootConstants.JUNGLE_MAIN, Items.enchanted_book.getRandom(randomIn)), 2 + randomIn.zrange(5));
}
this.setBlockState(worldIn, Blocks.mossy_cobblestone.getState(), 9, -3, 2, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.mossy_cobblestone.getState(), 8, -3, 1, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.mossy_cobblestone.getState(), 4, -3, 5, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.mossy_cobblestone.getState(), 5, -2, 5, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.mossy_cobblestone.getState(), 5, -1, 5, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.mossy_cobblestone.getState(), 6, -3, 5, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.mossy_cobblestone.getState(), 7, -2, 5, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.mossy_cobblestone.getState(), 7, -1, 5, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.mossy_cobblestone.getState(), 8, -3, 5, structureBoundingBoxIn);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 9, -1, 1, 9, -1, 5, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithAir(worldIn, structureBoundingBoxIn, 8, -3, 8, 10, -1, 10);
this.setBlockState(worldIn, Blocks.stonebrick.getStateFromMeta(BlockStoneBrick.CHISELED_META), 8, -2, 11, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stonebrick.getStateFromMeta(BlockStoneBrick.CHISELED_META), 9, -2, 11, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.stonebrick.getStateFromMeta(BlockStoneBrick.CHISELED_META), 10, -2, 11, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.lever.getStateFromMeta(BlockLever.getMetadataForFacing(Facing.getFront(this.getMetadataWithOffset(Blocks.lever, Facing.NORTH.getIndex())))), 8, -2, 12, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.lever.getStateFromMeta(BlockLever.getMetadataForFacing(Facing.getFront(this.getMetadataWithOffset(Blocks.lever, Facing.NORTH.getIndex())))), 9, -2, 12, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.lever.getStateFromMeta(BlockLever.getMetadataForFacing(Facing.getFront(this.getMetadataWithOffset(Blocks.lever, Facing.NORTH.getIndex())))), 10, -2, 12, structureBoundingBoxIn);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 8, -3, 8, 8, -3, 10, false, randomIn, junglePyramidsRandomScatteredStones);
this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 10, -3, 8, 10, -3, 10, false, randomIn, junglePyramidsRandomScatteredStones);
this.setBlockState(worldIn, Blocks.mossy_cobblestone.getState(), 10, -2, 9, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.redstone.getState(), 8, -2, 9, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.redstone.getState(), 8, -2, 10, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.redstone.getState(), 10, -1, 9, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sticky_piston.getStateFromMeta(Facing.UP.getIndex()), 9, -2, 8, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sticky_piston.getStateFromMeta(this.getMetadataWithOffset(Blocks.sticky_piston, Facing.WEST.getIndex())), 10, -2, 8, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.sticky_piston.getStateFromMeta(this.getMetadataWithOffset(Blocks.sticky_piston, Facing.WEST.getIndex())), 10, -1, 8, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.repeater.getStateFromMeta(this.getMetadataWithOffset(Blocks.repeater, Facing.NORTH.getHorizontalIndex())), 10, -2, 10, structureBoundingBoxIn);
if (!this.placedHiddenChest)
{
this.placedHiddenChest = this.generateChestContents(worldIn, structureBoundingBoxIn, randomIn, 9, -3, 10, RngLoot.addToList(LootConstants.JUNGLE_MAIN, Items.enchanted_book.getRandom(randomIn)), 2 + randomIn.zrange(5));
}
return true;
}
}
static class Stones extends StructureComponent.BlockSelector
{
private Stones()
{
}
public void selectBlocks(Random rand, int x, int y, int z, boolean p_75062_5_)
{
if (rand.floatv() < 0.4F)
{
this.blockstate = Blocks.cobblestone.getState();
}
else
{
this.blockstate = Blocks.mossy_cobblestone.getState();
}
}
}
}
public static class SwampHut extends StructureScattered.Feature
{
private boolean hasMage;
public SwampHut()
{
}
public SwampHut(Random p_i2066_1_, int p_i2066_2_, int p_i2066_3_)
{
super(p_i2066_1_, p_i2066_2_, 64, p_i2066_3_, 7, 7, 9);
}
protected void writeStructureToNBT(NBTTagCompound tagCompound)
{
super.writeStructureToNBT(tagCompound);
tagCompound.setBoolean("Mage", this.hasMage);
}
protected void readStructureFromNBT(NBTTagCompound tagCompound)
{
super.readStructureFromNBT(tagCompound);
this.hasMage = tagCompound.getBoolean("Mage");
}
public boolean addComponentParts(WorldServer worldIn, Random randomIn, StructureBoundingBox structureBoundingBoxIn)
{
if (!this.func_74935_a(worldIn, structureBoundingBoxIn, 0))
{
return false;
}
else
{
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 1, 1, 1, 5, 1, 7, Blocks.spruce_planks.getState(), Blocks.spruce_planks.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 1, 4, 2, 5, 4, 7, Blocks.spruce_planks.getState(), Blocks.spruce_planks.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 2, 1, 0, 4, 1, 0, Blocks.spruce_planks.getState(), Blocks.spruce_planks.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 2, 2, 2, 3, 3, 2, Blocks.spruce_planks.getState(), Blocks.spruce_planks.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 1, 2, 3, 1, 3, 6, Blocks.spruce_planks.getState(), Blocks.spruce_planks.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 5, 2, 3, 5, 3, 6, Blocks.spruce_planks.getState(), Blocks.spruce_planks.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 2, 2, 7, 4, 3, 7, Blocks.spruce_planks.getState(), Blocks.spruce_planks.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 1, 0, 2, 1, 3, 2, Blocks.oak_log.getState(), Blocks.oak_log.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 5, 0, 2, 5, 3, 2, Blocks.oak_log.getState(), Blocks.oak_log.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 1, 0, 7, 1, 3, 7, Blocks.oak_log.getState(), Blocks.oak_log.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 5, 0, 7, 5, 3, 7, Blocks.oak_log.getState(), Blocks.oak_log.getState(), false);
this.setBlockState(worldIn, Blocks.oak_fence.getState(), 2, 3, 2, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.oak_fence.getState(), 3, 3, 7, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.air.getState(), 1, 3, 4, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.air.getState(), 5, 3, 4, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.air.getState(), 5, 3, 5, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.flower_pot.getState().withProperty(BlockFlowerPot.CONTENTS, 2 + BlockFlower.EnumFlowerType.BLACK_LOTUS.getMeta()), 1, 3, 5, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.crafting_table.getState(), 3, 2, 6, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.cauldron.getState(), 4, 2, 6, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.oak_fence.getState(), 1, 2, 1, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.oak_fence.getState(), 5, 2, 1, structureBoundingBoxIn);
int i = this.getMetadataWithOffset(Blocks.oak_stairs, 3);
int j = this.getMetadataWithOffset(Blocks.oak_stairs, 1);
int k = this.getMetadataWithOffset(Blocks.oak_stairs, 0);
int l = this.getMetadataWithOffset(Blocks.oak_stairs, 2);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 0, 4, 1, 6, 4, 1, Blocks.spruce_stairs.getStateFromMeta(i), Blocks.spruce_stairs.getStateFromMeta(i), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 0, 4, 2, 0, 4, 7, Blocks.spruce_stairs.getStateFromMeta(k), Blocks.spruce_stairs.getStateFromMeta(k), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 6, 4, 2, 6, 4, 7, Blocks.spruce_stairs.getStateFromMeta(j), Blocks.spruce_stairs.getStateFromMeta(j), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 0, 4, 8, 6, 4, 8, Blocks.spruce_stairs.getStateFromMeta(l), Blocks.spruce_stairs.getStateFromMeta(l), false);
for (int i1 = 2; i1 <= 7; i1 += 5)
{
for (int j1 = 1; j1 <= 5; j1 += 4)
{
this.replaceAirAndLiquidDownwards(worldIn, Blocks.oak_log.getState(), j1, -1, i1, structureBoundingBoxIn);
}
}
if (!this.hasMage && Config.mobs && Config.spawnHutMage)
{
int l1 = this.getXWithOffset(2, 5);
int i2 = this.getYWithOffset(2);
int k1 = this.getZWithOffset(2, 5);
if (structureBoundingBoxIn.isVecInside(new BlockPos(l1, i2, k1)))
{
this.hasMage = true;
EntityMage mage = new EntityMage(worldIn);
mage.setLocationAndAngles((double)l1 + 0.5D, (double)i2, (double)k1 + 0.5D, 0.0F, 0.0F);
mage.onInitialSpawn(null);
worldIn.spawnEntityInWorld(mage);
}
}
return true;
}
}
}
}

View file

@ -0,0 +1,188 @@
package server.worldgen.structure;
import java.util.Iterator;
import java.util.LinkedList;
import common.nbt.NBTTagCompound;
import common.nbt.NBTTagList;
import common.rng.Random;
import common.util.ChunkPos;
import server.world.WorldServer;
public abstract class StructureStart
{
protected LinkedList<StructureComponent> components = new LinkedList();
protected StructureBoundingBox boundingBox;
private int chunkPosX;
private int chunkPosZ;
public StructureStart()
{
}
public StructureStart(int chunkX, int chunkZ)
{
this.chunkPosX = chunkX;
this.chunkPosZ = chunkZ;
}
public StructureBoundingBox getBoundingBox()
{
return this.boundingBox;
}
public LinkedList<StructureComponent> getComponents()
{
return this.components;
}
/**
* Keeps iterating Structure Pieces and spawning them until the checks tell it to stop
*/
public void generateStructure(WorldServer worldIn, Random rand, StructureBoundingBox structurebb)
{
Iterator<StructureComponent> iterator = this.components.iterator();
while (iterator.hasNext())
{
StructureComponent structurecomponent = (StructureComponent)iterator.next();
if (structurecomponent.getBoundingBox().intersectsWith(structurebb) && !structurecomponent.addComponentParts(worldIn, rand, structurebb))
{
iterator.remove();
}
}
}
/**
* Calculates total bounding box based on components' bounding boxes and saves it to boundingBox
*/
protected void updateBoundingBox()
{
this.boundingBox = StructureBoundingBox.getNewBoundingBox();
for (StructureComponent structurecomponent : this.components)
{
this.boundingBox.expandTo(structurecomponent.getBoundingBox());
}
}
public NBTTagCompound writeStructureComponentsToNBT(int chunkX, int chunkZ)
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setString("id", MapGenStructureIO.getStructureStartName(this));
nbttagcompound.setInteger("ChunkX", chunkX);
nbttagcompound.setInteger("ChunkZ", chunkZ);
nbttagcompound.setTag("BB", this.boundingBox.toNBTTagIntArray());
NBTTagList nbttaglist = new NBTTagList();
for (StructureComponent structurecomponent : this.components)
{
nbttaglist.appendTag(structurecomponent.createStructureBaseNBT());
}
nbttagcompound.setTag("Children", nbttaglist);
this.writeToNBT(nbttagcompound);
return nbttagcompound;
}
public void writeToNBT(NBTTagCompound tagCompound)
{
}
public void readStructureComponentsFromNBT(WorldServer worldIn, NBTTagCompound tagCompound)
{
this.chunkPosX = tagCompound.getInteger("ChunkX");
this.chunkPosZ = tagCompound.getInteger("ChunkZ");
if (tagCompound.hasKey("BB"))
{
this.boundingBox = new StructureBoundingBox(tagCompound.getIntArray("BB"));
}
NBTTagList nbttaglist = tagCompound.getTagList("Children", 10);
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
this.components.add(MapGenStructureIO.getStructureComponent(nbttaglist.getCompoundTagAt(i), worldIn));
}
this.readFromNBT(tagCompound);
}
public void readFromNBT(NBTTagCompound tagCompound)
{
}
/**
* offsets the structure Bounding Boxes up to a certain height, typically 63 - 10
*/
protected void markAvailableHeight(WorldServer worldIn, Random rand, int p_75067_3_)
{
int i = worldIn.getSeaLevel() - p_75067_3_;
int j = this.boundingBox.getYSize() + 1;
if (j < i)
{
j += rand.zrange(i - j);
}
int k = j - this.boundingBox.maxY;
this.boundingBox.offset(0, k, 0);
for (StructureComponent structurecomponent : this.components)
{
structurecomponent.func_181138_a(0, k, 0);
}
}
protected void setRandomHeight(WorldServer worldIn, Random rand, int p_75070_3_, int p_75070_4_)
{
int i = p_75070_4_ - p_75070_3_ + 1 - this.boundingBox.getYSize();
int j = 1;
if (i > 1)
{
j = p_75070_3_ + rand.zrange(i);
}
else
{
j = p_75070_3_;
}
int k = j - this.boundingBox.minY;
this.boundingBox.offset(0, k, 0);
for (StructureComponent structurecomponent : this.components)
{
structurecomponent.func_181138_a(0, k, 0);
}
}
/**
* currently only defined for Villages, returns true if Village has more than 2 non-road components
*/
public boolean isSizeableStructure()
{
return true;
}
public boolean func_175788_a(ChunkPos pair)
{
return true;
}
public void func_175787_b(ChunkPos pair)
{
}
public int getChunkPosX()
{
return this.chunkPosX;
}
public int getChunkPosZ()
{
return this.chunkPosZ;
}
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff