use of net.minecraft.world.gen.ChunkProviderServer in project BuildCraft by BuildCraft.
the class ThreadSafeUtils method getChunk.
public static Chunk getChunk(World world, int x, int z) {
Chunk chunk;
chunk = lastChunk.get();
if (chunk != null) {
if (chunk.isChunkLoaded) {
if (chunk.worldObj == world && chunk.xPosition == x && chunk.zPosition == z) {
return chunk;
}
} else {
lastChunk.set(null);
}
}
IChunkProvider provider = world.getChunkProvider();
// These probably won't guarantee full thread safety, but it's our best bet.
if (!Utils.CAULDRON_DETECTED && provider instanceof ChunkProviderServer) {
// Slight optimization
chunk = (Chunk) ((ChunkProviderServer) provider).loadedChunkHashMap.getValueByKey(ChunkCoordIntPair.chunkXZ2Int(x, z));
} else {
chunk = provider.chunkExists(x, z) ? provider.provideChunk(x, z) : null;
}
if (chunk != null) {
lastChunk.set(chunk);
}
return chunk;
}
use of net.minecraft.world.gen.ChunkProviderServer in project dynmap by webbukkit.
the class ForgeMapChunkCache method setChunks.
public void setChunks(ForgeWorld dw, List<DynmapChunk> chunks) {
this.dw = dw;
this.w = dw.getWorld();
if (dw.isLoaded()) {
/* Check if world's provider is ChunkProviderServer */
IChunkProvider cp = this.w.getChunkProvider();
if (cp instanceof ChunkProviderServer) {
cps = (ChunkProviderServer) cp;
} else {
Log.severe("Error: world " + dw.getName() + " has unsupported chunk provider");
}
} else {
chunks = new ArrayList<DynmapChunk>();
}
nsect = dw.worldheight >> 4;
this.chunks = chunks;
/* Compute range */
if (chunks.size() == 0) {
this.x_min = 0;
this.x_max = 0;
this.z_min = 0;
this.z_max = 0;
x_dim = 1;
} else {
x_min = x_max = chunks.get(0).x;
z_min = z_max = chunks.get(0).z;
for (DynmapChunk c : chunks) {
if (c.x > x_max) {
x_max = c.x;
}
if (c.x < x_min) {
x_min = c.x;
}
if (c.z > z_max) {
z_max = c.z;
}
if (c.z < z_min) {
z_min = c.z;
}
}
x_dim = x_max - x_min + 1;
}
snapcnt = x_dim * (z_max - z_min + 1);
snaparray = new ChunkSnapshot[snapcnt];
snaptile = new DynIntHashMap[snapcnt];
isSectionNotEmpty = new boolean[snapcnt][];
try {
if ((unloadqueue != null) && (cps != null)) {
queue = (Set<?>) unloadqueue.get(cps);
}
} catch (IllegalArgumentException iax) {
} catch (IllegalAccessException e) {
}
}
use of net.minecraft.world.gen.ChunkProviderServer in project UtilityClient2 by Utility-Client.
the class WorldServer method createChunkProvider.
/**
* Creates the chunk provider for this world. Called in the constructor. Retrieves provider from worldProvider?
*/
protected IChunkProvider createChunkProvider() {
IChunkLoader ichunkloader = this.saveHandler.getChunkLoader(this.provider);
this.theChunkProviderServer = new ChunkProviderServer(this, ichunkloader, this.provider.createChunkGenerator());
return this.theChunkProviderServer;
}
use of net.minecraft.world.gen.ChunkProviderServer in project Hbm-s-Nuclear-Tech-GIT by HbmMods.
the class ChunkRadiationHandlerSimple method handleWorldDestruction.
@Override
public void handleWorldDestruction() {
int count = 10;
int threshold = 10;
int chunks = 5;
// for all worlds
for (Entry<World, SimpleRadiationPerWorld> per : perWorld.entrySet()) {
World world = per.getKey();
SimpleRadiationPerWorld list = per.getValue();
Object[] entries = list.radiation.entrySet().toArray();
if (entries.length == 0)
continue;
// chose this many random chunks
for (int c = 0; c < chunks; c++) {
Entry<ChunkCoordIntPair, Float> randEnt = (Entry<ChunkCoordIntPair, Float>) entries[world.rand.nextInt(entries.length)];
ChunkCoordIntPair coords = randEnt.getKey();
WorldServer serv = (WorldServer) world;
ChunkProviderServer provider = (ChunkProviderServer) serv.getChunkProvider();
// choose this many random locations within the chunk
for (int i = 0; i < count; i++) {
if (randEnt == null || randEnt.getValue() < threshold)
continue;
if (provider.chunkExists(coords.chunkXPos, coords.chunkZPos)) {
for (int a = 0; a < 16; a++) {
for (int b = 0; b < 16; b++) {
if (world.rand.nextInt(3) != 0)
continue;
int x = coords.getCenterXPos() - 8 + a;
int z = coords.getCenterZPosition() - 8 + b;
int y = world.getHeightValue(x, z) - world.rand.nextInt(2);
if (world.getBlock(x, y, z) == Blocks.grass) {
world.setBlock(x, y, z, ModBlocks.waste_earth);
} else if (world.getBlock(x, y, z) == Blocks.tallgrass) {
world.setBlock(x, y, z, Blocks.air);
} else if (world.getBlock(x, y, z).getMaterial() == Material.leaves && !(world.getBlock(x, y, z) == ModBlocks.waste_leaves)) {
if (world.rand.nextInt(7) <= 5) {
world.setBlock(x, y, z, ModBlocks.waste_leaves);
} else {
world.setBlock(x, y, z, Blocks.air);
}
}
}
}
}
}
}
}
}
use of net.minecraft.world.gen.ChunkProviderServer in project ElementalSorcery by Yuzunyannn.
the class ExploreStructureFind method explore.
@Override
public boolean explore(NBTTagCompound data, World world, BlockPos pos, int level, IBlockState state, EntityLivingBase portrait) {
// 在方块模式下也会获取
if (level < 2 && state == null)
return true;
if (!data.hasKey("archi")) {
ChunkProviderServer cp = ((WorldServer) world).getChunkProvider();
String in = null;
List<String> list = getStructureList(world);
for (String str : list) {
BlockPos to = cp.getNearestStructurePos(world, str, pos, false);
if (to == null)
continue;
int length = 160;
// 有方块的情况下,多判断一步
if (state != null) {
BlockPos at;
// 加大y轴区间
if (Math.abs(to.getY() - pos.getY()) <= 30)
at = new BlockPos(pos.getX(), to.getY(), pos.getZ());
else
at = pos;
if (cp.isInsideStructure(world, str, at)) {
in = str;
break;
}
switch(str) {
case "Fortress":
length = 90;
break;
case "Mineshaft":
length = 64;
break;
default:
length = 16;
break;
}
}
Vec3d x1 = new Vec3d(pos);
Vec3d x2 = new Vec3d(to);
if (x1.squareDistanceTo(x2) <= length * length) {
in = str;
break;
}
}
if (in != null)
data.setString("archi", in);
else
data.setString("archi", "");
return false;
}
return true;
}
Aggregations