Search in sources :

Example 1 with WorldProvider

use of net.minecraft.world.WorldProvider in project MinecraftForge by MinecraftForge.

the class DimensionManager method createProviderFor.

public static WorldProvider createProviderFor(int dim) {
    try {
        if (dimensions.containsKey(dim)) {
            WorldProvider ret = getProviderType(dim).createDimension();
            ret.setDimension(dim);
            return ret;
        } else {
            //It's going to crash anyway at this point.  Might as well be informative
            throw new RuntimeException(String.format("No WorldProvider bound for dimension %d", dim));
        }
    } catch (Exception e) {
        FMLCommonHandler.instance().getFMLLogger().log(Level.ERROR, String.format("An error occurred trying to create an instance of WorldProvider %d (%s)", dim, getProviderType(dim)), e);
        throw new RuntimeException(e);
    }
}
Also used : WorldProvider(net.minecraft.world.WorldProvider) MinecraftException(net.minecraft.world.MinecraftException)

Example 2 with WorldProvider

use of net.minecraft.world.WorldProvider in project RFToolsDimensions by McJty.

the class ForgeEventHandlers method onOreGenEvent.

@SubscribeEvent
public void onOreGenEvent(OreGenEvent.GenerateMinable event) {
    World world = event.getWorld();
    if (world == null) {
        return;
    }
    WorldProvider provider = world.provider;
    if (!(provider instanceof GenericWorldProvider))
        return;
    DimensionInformation information = ((GenericWorldProvider) provider).getDimensionInformation();
    if (information != null && information.hasFeatureType(FeatureType.FEATURE_CLEAN)) {
        event.setResult(Event.Result.DENY);
    }
}
Also used : GenericWorldProvider(mcjty.rftoolsdim.dimensions.world.GenericWorldProvider) WorldProvider(net.minecraft.world.WorldProvider) World(net.minecraft.world.World) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) GenericWorldProvider(mcjty.rftoolsdim.dimensions.world.GenericWorldProvider) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with WorldProvider

use of net.minecraft.world.WorldProvider in project SpongeCommon by SpongePowered.

the class EntityUtil method adjustEntityPostionForTeleport.

public static void adjustEntityPostionForTeleport(IMixinPlayerList playerList, Entity entity, WorldServer fromWorld, WorldServer toWorld) {
    fromWorld.profiler.startSection("moving");
    WorldProvider pOld = fromWorld.provider;
    WorldProvider pNew = toWorld.provider;
    double moveFactor = playerList.getMovementFactor(pOld) / playerList.getMovementFactor(pNew);
    double x = entity.posX * moveFactor;
    double y = entity.posY;
    double z = entity.posZ * moveFactor;
    if (pNew instanceof WorldProviderEnd) {
        BlockPos blockpos;
        if (pOld instanceof WorldProviderEnd) {
            blockpos = toWorld.getSpawnPoint();
        } else {
            blockpos = toWorld.getSpawnCoordinate();
        }
        x = blockpos.getX();
        y = blockpos.getY();
        z = blockpos.getZ();
        entity.setLocationAndAngles(x, y, z, 90.0F, 0.0F);
    }
    if (!(pOld instanceof WorldProviderEnd)) {
        fromWorld.profiler.startSection("placing");
        x = MathHelper.clamp((int) x, -29999872, 29999872);
        z = MathHelper.clamp((int) z, -29999872, 29999872);
        if (entity.isEntityAlive()) {
            entity.setLocationAndAngles(x, y, z, entity.rotationYaw, entity.rotationPitch);
        }
        fromWorld.profiler.endSection();
    }
    if (entity.isEntityAlive()) {
        fromWorld.updateEntityWithOptionalForce(entity, false);
    }
    fromWorld.profiler.endSection();
}
Also used : WorldProviderEnd(net.minecraft.world.WorldProviderEnd) WorldProvider(net.minecraft.world.WorldProvider) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with WorldProvider

use of net.minecraft.world.WorldProvider in project SpongeCommon by SpongePowered.

the class MixinMinecraftServer method onUpdateTimeLightAndEntitiesHead.

// All chunk unload queuing needs to be processed BEFORE the future tasks are run as mods/plugins may have tasks that request chunks.
// This prevents a situation where a chunk is requested to load then unloads at end of tick.
@Inject(method = "updateTimeLightAndEntities", at = @At("HEAD"))
public void onUpdateTimeLightAndEntitiesHead(CallbackInfo ci) {
    for (int i = 0; i < this.worlds.length; ++i) {
        WorldServer worldServer = this.worlds[i];
        // ChunkGC needs to be processed before a world tick in order to guarantee any chunk  queued for unload
        // can still be marked active and avoid unload if accessed during the same tick.
        // Note: This injection must come before Forge's pre world tick event or it will cause issues with mods.
        IMixinWorldServer spongeWorld = (IMixinWorldServer) worldServer;
        if (spongeWorld.getChunkGCTickInterval() > 0) {
            spongeWorld.doChunkGC();
        }
        // Moved from PlayerChunkMap to avoid chunks from unloading after being requested in same tick
        if (worldServer.getPlayerChunkMap().players.isEmpty()) {
            WorldProvider worldprovider = worldServer.provider;
            if (!worldprovider.canRespawnHere()) {
                worldServer.getChunkProvider().queueUnloadAll();
            }
        }
    }
}
Also used : WorldProvider(net.minecraft.world.WorldProvider) WorldServer(net.minecraft.world.WorldServer) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with WorldProvider

use of net.minecraft.world.WorldProvider in project SpongeCommon by SpongePowered.

the class MixinWorldServer method createWorldGenerator.

@Override
public SpongeWorldGenerator createWorldGenerator(String settings) {
    final WorldServer worldServer = (WorldServer) (Object) this;
    final WorldType worldType = worldServer.getWorldType();
    final IChunkGenerator chunkGenerator;
    final BiomeProvider biomeProvider;
    if (worldType instanceof SpongeWorldType) {
        chunkGenerator = ((SpongeWorldType) worldType).getChunkGenerator(worldServer, settings);
        biomeProvider = ((SpongeWorldType) worldType).getBiomeProvider(worldServer);
    } else {
        final IChunkGenerator currentGenerator = this.getChunkProvider().chunkGenerator;
        if (currentGenerator != null) {
            chunkGenerator = currentGenerator;
        } else {
            final WorldProvider worldProvider = worldServer.provider;
            ((IMixinWorldProvider) worldProvider).setGeneratorSettings(settings);
            chunkGenerator = worldProvider.createChunkGenerator();
        }
        biomeProvider = worldServer.provider.biomeProvider;
    }
    return new SpongeWorldGenerator(worldServer, (BiomeGenerator) biomeProvider, SpongeGenerationPopulator.of(worldServer, chunkGenerator));
}
Also used : BiomeProvider(net.minecraft.world.biome.BiomeProvider) IMixinWorldProvider(org.spongepowered.common.interfaces.world.IMixinWorldProvider) SpongeWorldType(org.spongepowered.common.world.type.SpongeWorldType) WorldType(net.minecraft.world.WorldType) IChunkGenerator(net.minecraft.world.gen.IChunkGenerator) IMixinWorldProvider(org.spongepowered.common.interfaces.world.IMixinWorldProvider) WorldProvider(net.minecraft.world.WorldProvider) WorldServer(net.minecraft.world.WorldServer) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) SpongeWorldGenerator(org.spongepowered.common.world.gen.SpongeWorldGenerator) SpongeWorldType(org.spongepowered.common.world.type.SpongeWorldType)

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