Search in sources :

Example 6 with WorldProvider

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);
}
Also used : WorldProvider(net.minecraft.world.WorldProvider)

Example 7 with WorldProvider

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 + "]!");
    }
}
Also used : DimensionType(net.minecraft.world.DimensionType) WorldProvider(net.minecraft.world.WorldProvider) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 8 with WorldProvider

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());
    }
}
Also used : Path(java.nio.file.Path) DimensionType(net.minecraft.world.DimensionType) IMixinWorldInfo(org.spongepowered.common.interfaces.world.IMixinWorldInfo) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) WorldServer(net.minecraft.world.WorldServer) WorldArchetype(org.spongepowered.api.world.WorldArchetype) WorldProvider(net.minecraft.world.WorldProvider) IMixinWorldSettings(org.spongepowered.common.interfaces.world.IMixinWorldSettings) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 9 with WorldProvider

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);
    }
}
Also used : WorldProvider(net.minecraft.world.WorldProvider) LinkedList(java.util.LinkedList) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 10 with WorldProvider

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;
}
Also used : EnumAtmosphericGas(micdoodle8.mods.galacticraft.api.world.EnumAtmosphericGas) WorldProvider(net.minecraft.world.WorldProvider) WorldProviderSpace(micdoodle8.mods.galacticraft.api.prefab.world.gen.WorldProviderSpace)

Aggregations

WorldProvider (net.minecraft.world.WorldProvider)30 WorldServer (net.minecraft.world.WorldServer)7 World (net.minecraft.world.World)6 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)6 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)4 IOException (java.io.IOException)3 GenericWorldProvider (mcjty.rftoolsdim.dimensions.world.GenericWorldProvider)3 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)3 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)3 WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)3 Entity (net.minecraft.entity.Entity)3 BlockPos (net.minecraft.util.math.BlockPos)3 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)3 Path (java.nio.file.Path)2 LinkedList (java.util.LinkedList)2 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)2 ZeroGravityEvent (micdoodle8.mods.galacticraft.api.event.ZeroGravityEvent)2 CelestialBody (micdoodle8.mods.galacticraft.api.galaxies.CelestialBody)2 WorldProviderSpace (micdoodle8.mods.galacticraft.api.prefab.world.gen.WorldProviderSpace)2 IZeroGDimension (micdoodle8.mods.galacticraft.api.world.IZeroGDimension)2