use of net.minecraft.world.WorldProvider in project Waystones by blay09.
the class WaystoneManager method transferEntityToWorld.
/**
* Taken from CoFHCore's EntityHelper (https://github.com/CoFH/CoFHCore/blob/1.12/src/main/java/cofh/core/util/helpers/EntityHelper.java)
*/
private static void transferEntityToWorld(Entity entity, WorldServer oldWorld, WorldServer newWorld) {
WorldProvider oldWorldProvider = oldWorld.provider;
WorldProvider newWorldProvider = newWorld.provider;
double moveFactor = oldWorldProvider.getMovementFactor() / newWorldProvider.getMovementFactor();
double x = entity.posX * moveFactor;
double z = entity.posZ * moveFactor;
oldWorld.profiler.startSection("placing");
x = MathHelper.clamp(x, -29999872, 29999872);
z = MathHelper.clamp(z, -29999872, 29999872);
if (entity.isEntityAlive()) {
entity.setLocationAndAngles(x, entity.posY, z, entity.rotationYaw, entity.rotationPitch);
newWorld.spawnEntity(entity);
newWorld.updateEntityWithOptionalForce(entity, false);
}
oldWorld.profiler.endSection();
entity.setWorld(newWorld);
}
use of net.minecraft.world.WorldProvider in project SpongeForge by SpongePowered.
the class MixinDimensionManager method createProviderFor.
@Overwrite
public static WorldProvider createProviderFor(int dim) {
final DimensionType dimensionType = WorldManager.getDimensionType(dim).orElseThrow(() -> new RuntimeException("Attempt to create " + "provider for dimension id [" + dim + "] failed because it has not been registered!"));
try {
final WorldProvider provider = dimensionType.createDimension();
provider.setDimension(dim);
return provider;
} catch (Exception e) {
throw new RuntimeException("Failed to create provider for dimension id [" + dim + "]!");
}
}
use of net.minecraft.world.WorldProvider in project SpongeForge by SpongePowered.
the class MixinDimensionManager method initDimension.
/**
* @author Zidane - June 2nd, 2016
* @reason Forge's initDimension is very different from Sponge's multi-world. We basically rig it into our system so mods work.
* @param dim The dimension to load
*/
@Overwrite
public static void initDimension(int dim) {
// World is already loaded, bail
if (WorldManager.getWorldByDimensionId(dim).isPresent()) {
return;
}
if (dim == 0) {
throw new RuntimeException("Attempt made to initialize overworld!");
}
WorldManager.getWorldByDimensionId(0).orElseThrow(() -> new RuntimeException("Attempt made to initialize " + "dimension before overworld is loaded!"));
DimensionType dimensionType = WorldManager.getDimensionType(dim).orElse(null);
if (dimensionType == null) {
SpongeImpl.getLogger().warn("Attempt made to initialize dimension id {} which isn't registered!" + ", falling back to overworld.", dim);
return;
}
final WorldProvider provider = dimensionType.createDimension();
// make sure to set the dimension id to avoid getting a null save folder
provider.setDimension(dim);
String worldFolder = WorldManager.getWorldFolderByDimensionId(dim).orElse(provider.getSaveFolder());
WorldProperties properties = WorldManager.getWorldProperties(worldFolder).orElse(null);
final Path worldPath = WorldManager.getCurrentSavesDirectory().get().resolve(worldFolder);
if (properties == null || !Files.isDirectory(worldPath)) {
if (properties != null) {
WorldManager.unregisterWorldProperties(properties, false);
}
String modId = StaticMixinForgeHelper.getModIdFromClass(provider.getClass());
WorldArchetype archetype = Sponge.getRegistry().getType(WorldArchetype.class, modId + ":" + dimensionType.getName().toLowerCase()).orElse(null);
if (archetype == null) {
final WorldArchetype.Builder builder = WorldArchetype.builder().dimension((org.spongepowered.api.world.DimensionType) (Object) dimensionType).keepsSpawnLoaded(dimensionType.shouldLoadSpawn());
archetype = builder.build(modId + ":" + dimensionType.getName().toLowerCase(), dimensionType.getName());
}
IMixinWorldSettings worldSettings = (IMixinWorldSettings) archetype;
worldSettings.setDimensionType((org.spongepowered.api.world.DimensionType) (Object) dimensionType);
worldSettings.setLoadOnStartup(false);
properties = WorldManager.createWorldProperties(worldFolder, archetype, dim);
((IMixinWorldInfo) properties).setDimensionId(dim);
((IMixinWorldInfo) properties).setIsMod(true);
}
if (!properties.isEnabled()) {
return;
}
Optional<WorldServer> optWorld = WorldManager.loadWorld(properties);
if (!optWorld.isPresent()) {
SpongeImpl.getLogger().error("Could not load world [{}]!", properties.getWorldName());
}
}
use of net.minecraft.world.WorldProvider in project Galacticraft by micdoodle8.
the class AsteroidsTickHandlerServer method loadAstroChunkList.
/**
* How this works: every spawned or saved (in player stats) miner is added to the
* activeMiners list here.
* Once per server tick its position will be saved to player stats.
* When the player quits, the saved miner positions will be saved with the player's stats NBT
* When the player next loads, loadAstroChunkList will force load those chunks, therefore
* reactivating AstroMiners if those chunks weren't already loaded.
*/
public static void loadAstroChunkList(List<BlockVec3> activeChunks) {
List<BlockVec3> copyList = new LinkedList<>(activeChunks);
activeChunks.clear();
if (!(AsteroidsTickHandlerServer.loadingSavedChunks.getAndSet(true))) {
for (BlockVec3 data : copyList) {
WorldProvider p = WorldUtil.getProviderForDimensionServer(data.y);
if (p != null && p.worldObj != null) {
GCLog.debug("Loading chunk " + data.y + ": " + data.x + "," + data.z + " - should contain a miner!");
((WorldServer) p.worldObj).theChunkProviderServer.loadChunk(data.x, data.z);
}
}
AsteroidsTickHandlerServer.loadingSavedChunks.set(false);
}
}
use of net.minecraft.world.WorldProvider in project Galacticraft by micdoodle8.
the class TileEntityGasLiquefier method getAirProducts.
public int getAirProducts() {
WorldProvider WP = this.worldObj.provider;
if (WP instanceof WorldProviderSpace) {
int result = 0;
ArrayList<EnumAtmosphericGas> atmos = ((WorldProviderSpace) WP).getCelestialBody().atmosphere.composition;
if (atmos.size() > 0) {
result = this.getIdFromName(atmos.get(0).name().toLowerCase()) + 1;
}
if (atmos.size() > 1) {
result += 16 * (this.getIdFromName(atmos.get(1).name().toLowerCase()) + 1);
}
if (atmos.size() > 2) {
result += 256 * (this.getIdFromName(atmos.get(2).name().toLowerCase()) + 1);
}
return result;
}
return 35;
}
Aggregations