use of net.minecraft.server.MinecraftServer in project malmo by Microsoft.
the class DefaultWorldGeneratorImplementation method shouldCreateWorld.
@Override
public boolean shouldCreateWorld(MissionInit missionInit) {
if (this.dwparams != null && this.dwparams.isForceReset())
return true;
World world = null;
MinecraftServer server = MinecraftServer.getServer();
if (server.worldServers != null && server.worldServers.length != 0)
world = server.getEntityWorld();
if (Minecraft.getMinecraft().theWorld == null || world == null)
// Definitely need to create a world if there isn't one in existence!
return true;
String genOptions = world.getWorldInfo().getGeneratorOptions();
if (genOptions != null && !genOptions.isEmpty())
// Default world has no generator options.
return true;
return false;
}
use of net.minecraft.server.MinecraftServer in project malmo by Microsoft.
the class ServerQuitFromTimeUpImplementation method getWorldTime.
@Override
protected long getWorldTime() {
World world = null;
MinecraftServer server = MinecraftServer.getServer();
if (server.worldServers != null && server.worldServers.length != 0)
world = server.getEntityWorld();
return (world != null) ? world.getTotalWorldTime() : 0;
}
use of net.minecraft.server.MinecraftServer in project MinecraftForge by MinecraftForge.
the class DimensionManager method initDimension.
public static void initDimension(int dim) {
WorldServer overworld = getWorld(0);
if (overworld == null) {
throw new RuntimeException("Cannot Hotload Dim: Overworld is not Loaded!");
}
try {
DimensionManager.getProviderType(dim);
} catch (Exception e) {
System.err.println("Cannot Hotload Dim: " + e.getMessage());
// If a provider hasn't been registered then we can't hotload the dim
return;
}
MinecraftServer mcServer = overworld.getMinecraftServer();
ISaveHandler savehandler = overworld.getSaveHandler();
//WorldSettings worldSettings = new WorldSettings(overworld.getWorldInfo());
WorldServer world = (dim == 0 ? overworld : (WorldServer) (new WorldServerMulti(mcServer, savehandler, dim, overworld, mcServer.theProfiler).init()));
world.addEventListener(new ServerWorldEventHandler(mcServer, world));
MinecraftForge.EVENT_BUS.post(new WorldEvent.Load(world));
if (!mcServer.isSinglePlayer()) {
world.getWorldInfo().setGameType(mcServer.getGameType());
}
mcServer.setDifficultyForAllWorlds(mcServer.getDifficulty());
}
use of net.minecraft.server.MinecraftServer in project MinecraftForge by MinecraftForge.
the class FMLCommonHandler method handleServerStopped.
public void handleServerStopped() {
sidedDelegate.serverStopped();
MinecraftServer server = getMinecraftServerInstance();
Loader.instance().serverStopped();
// FORCE the internal server to stop: hello optifine workaround!
if (server != null)
ObfuscationReflectionHelper.setPrivateValue(MinecraftServer.class, server, false, "field_71316" + "_v", "u", "serverStopped");
// allow any pending exit to continue, clear exitLatch
CountDownLatch latch = exitLatch;
if (latch != null) {
latch.countDown();
exitLatch = null;
}
}
use of net.minecraft.server.MinecraftServer in project NetherEx by LogicTechCorp.
the class WorldGenElderMushroom method generate.
@Override
public boolean generate(World world, Random rand, BlockPos pos) {
while (isWorldGen && world.isAirBlock(pos) && pos.getY() > 32) {
pos = pos.down();
}
for (int posX = -1; posX < 2; posX++) {
for (int posZ = -1; posZ < 2; posZ++) {
BlockPos newPos = pos.add(posX, 0, posZ);
IBlockState state = world.getBlockState(newPos);
if (!state.getBlock().canSustainPlant(state, world, newPos, EnumFacing.UP, NetherExBlocks.PLANT_MUSHROOM_ELDER) && state.getBlock() != Blocks.SOUL_SAND) {
return false;
}
}
}
pos = pos.up();
Mirror[] mirrors = Mirror.values();
Mirror mirror = mirrors[rand.nextInt(mirrors.length)];
Rotation[] rotations = Rotation.values();
Rotation rotation = rotations[rand.nextInt(rotations.length)];
MinecraftServer minecraftServer = world.getMinecraftServer();
TemplateManager templateManager = world.getSaveHandler().getStructureTemplateManager();
Template template = templateManager.getTemplate(minecraftServer, WeightedUtil.getRandomStructure(rand, variants));
PlacementSettings placementSettings = new PlacementSettings().setMirror(mirror).setRotation(rotation).setReplacedBlock(Blocks.AIR);
BlockPos structureSize = Template.transformedBlockPos(placementSettings.copy(), template.getSize());
float airAmount = 0;
float blockAmount = MathHelper.abs((structureSize.getX() + 2) * (structureSize.getY() + 1) * (structureSize.getZ() + 2));
for (int posX = -1; posX < structureSize.getX() + 1; posX++) {
for (int posZ = -1; posZ < structureSize.getZ() + 1; posZ++) {
for (int posY = 0; posY < structureSize.getY() + 1; posY++) {
BlockPos newPos = pos.add(-(posX / 2), posY, -(posZ / 2));
Block block = world.getBlockState(newPos).getBlock();
if (world.isAirBlock(newPos)) {
airAmount += 1.0F;
} else if (block == Blocks.NETHERRACK || block == Blocks.GLOWSTONE || block == NetherExBlocks.BLOCK_NETHERRACK || block == NetherExBlocks.PLANT_MUSHROOM_ELDER_CAP || block == NetherExBlocks.PLANT_MUSHROOM_ELDER_STEM) {
return false;
}
}
}
}
if (MathHelper.abs(airAmount) / MathHelper.abs(blockAmount) >= 0.75F) {
if (!isWorldGen) {
world.setBlockToAir(pos);
}
template.addBlocksToWorld(world, pos.add(-(structureSize.getX() / 2), 0, -(structureSize.getZ() / 2)), placementSettings.copy());
return true;
}
return false;
}
Aggregations