Search in sources :

Example 16 with DimensionType

use of net.minecraft.world.DimensionType in project BiomesOPlenty by Glitchfiend.

the class ModBiomes method registerNetherOverride.

public static void registerNetherOverride() {
    // Unregister vanilla Nether dimension
    DimensionManager.unregisterDimension(-1);
    // Add override
    DimensionType netherBOP = DimensionType.register("Nether", "_nether", -1, WorldProviderBOPHell.class, false);
    DimensionManager.registerDimension(-1, netherBOP);
}
Also used : DimensionType(net.minecraft.world.DimensionType)

Example 17 with DimensionType

use of net.minecraft.world.DimensionType in project NetherEx by LogicTechCorp.

the class NetherExBiomes method init.

public static void init() {
    BiomeDictionary.addTypes(HELL, NETHER, HOT, DRY);
    BiomeDictionary.addTypes(RUTHLESS_SANDS, NETHER, HOT, DRY, SANDY);
    BiomeDictionary.addTypes(FUNGI_FOREST, NETHER, HOT, DRY, MUSHROOM);
    BiomeDictionary.addTypes(TORRID_WASTELAND, NETHER, HOT, DRY, WASTELAND);
    BiomeDictionary.addTypes(ARCTIC_ABYSS, NETHER, WET, COLD);
    DimensionManager.unregisterDimension(-1);
    DimensionType nether = DimensionType.register("Nether", "_nether", -1, WorldProviderNether.class, false);
    DimensionManager.registerDimension(-1, nether);
    LOGGER.info("The Nether has been overridden.");
}
Also used : DimensionType(net.minecraft.world.DimensionType)

Example 18 with DimensionType

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

the class ModDimensions method init.

public static void init() {
    int id = GeneralConfiguration.rftoolsProviderId;
    if (id == -1) {
        for (DimensionType type : DimensionType.values()) {
            if (type.getId() > id) {
                id = type.getId();
            }
        }
        id++;
    }
    Logging.log("Registering rftools dimension type at id " + id);
    rftoolsType = DimensionType.register("rftools_dimension", "_rftools", id, GenericWorldProvider.class, false);
    GameRegistry.registerWorldGenerator(new GenericWorldGenerator(), 1000);
    MapGenStructureIO.registerStructure(MapGenDesertTemple.Start.class, "RFTDesertTemple");
    MapGenStructureIO.registerStructure(MapGenJungleTemple.Start.class, "RFTJungleTemple");
    MapGenStructureIO.registerStructure(MapGenSwampHut.Start.class, "RFTSwampHut");
    MapGenStructureIO.registerStructure(MapGenIgloo.Start.class, "RFTIgloo");
}
Also used : DimensionType(net.minecraft.world.DimensionType) MapGenJungleTemple(mcjty.rftoolsdim.dimensions.world.mapgen.MapGenJungleTemple) MapGenDesertTemple(mcjty.rftoolsdim.dimensions.world.mapgen.MapGenDesertTemple) GenericWorldGenerator(mcjty.rftoolsdim.dimensions.world.GenericWorldGenerator) MapGenSwampHut(mcjty.rftoolsdim.dimensions.world.mapgen.MapGenSwampHut) MapGenIgloo(mcjty.rftoolsdim.dimensions.world.mapgen.MapGenIgloo) GenericWorldProvider(mcjty.rftoolsdim.dimensions.world.GenericWorldProvider)

Example 19 with DimensionType

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

the class WorldManager method loadAllWorlds.

public static void loadAllWorlds(String worldName, long defaultSeed, WorldType defaultWorldType, String generatorOptions) {
    final MinecraftServer server = SpongeImpl.getServer();
    // We cannot call getCurrentSavesDirectory here as that would generate a savehandler and trigger a session lock.
    // We'll go ahead and make the directories for the save name here so that the migrator won't fail
    final Path currentSavesDir = server.anvilFile.toPath().resolve(server.getFolderName());
    try {
        // Symlink needs special handling
        if (Files.isSymbolicLink(currentSavesDir)) {
            final Path actualPathLink = Files.readSymbolicLink(currentSavesDir);
            if (Files.notExists(actualPathLink)) {
                // TODO Need to test symlinking to see if this is even legal...
                Files.createDirectories(actualPathLink);
            } else if (!Files.isDirectory(actualPathLink)) {
                throw new IOException("Saves directory [" + currentSavesDir + "] symlinked to [" + actualPathLink + "] is not a directory!");
            }
        } else {
            Files.createDirectories(currentSavesDir);
        }
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
    WorldManager.registerVanillaDimensionPaths(currentSavesDir);
    WorldMigrator.migrateWorldsTo(currentSavesDir);
    registerExistingSpongeDimensions(currentSavesDir);
    for (Map.Entry<Integer, DimensionType> entry : sortedDimensionMap().entrySet()) {
        final int dimensionId = entry.getKey();
        final DimensionType dimensionType = entry.getValue();
        // Skip all worlds besides dimension 0 if multi-world is disabled
        if (dimensionId != 0 && !server.getAllowNether()) {
            continue;
        }
        // Skip already loaded worlds by plugins
        if (getWorldByDimensionId(dimensionId).isPresent()) {
            continue;
        }
        // Step 1 - Grab the world's data folder
        final Path worldFolder = getWorldFolder(dimensionType, dimensionId);
        if (worldFolder == null) {
            SpongeImpl.getLogger().error("An attempt was made to load a world with dimension id [{}] that has no registered world folder!", dimensionId);
            continue;
        }
        final String worldFolderName = worldFolder.getFileName().toString();
        // Step 2 - See if we are allowed to load it
        if (dimensionId != 0) {
            final SpongeConfig<? extends GeneralConfigBase> activeConfig = SpongeHooks.getActiveConfig(((IMixinDimensionType) (Object) dimensionType).getConfigPath(), worldFolderName);
            if (!activeConfig.getConfig().getWorld().isWorldEnabled()) {
                SpongeImpl.getLogger().warn("World [{}] (DIM{}) is disabled. World will not be loaded...", worldFolder, dimensionId);
                continue;
            }
        }
        // Step 3 - Get our world information from disk
        final ISaveHandler saveHandler;
        if (dimensionId == 0) {
            saveHandler = server.getActiveAnvilConverter().getSaveLoader(server.getFolderName(), true);
        } else {
            saveHandler = new AnvilSaveHandler(WorldManager.getCurrentSavesDirectory().get().toFile(), worldFolderName, true, SpongeImpl.getDataFixer());
        }
        WorldInfo worldInfo = saveHandler.loadWorldInfo();
        WorldSettings worldSettings;
        // If this is integrated server, we need to use the WorldSettings from the client's Single Player menu to construct the worlds
        if (server instanceof IMixinIntegratedServer) {
            worldSettings = ((IMixinIntegratedServer) server).getSettings();
            // If this is overworld and a new save, the WorldInfo has already been made but we want to still fire the construct event.
            if (dimensionId == 0 && ((IMixinIntegratedServer) server).isNewSave()) {
                SpongeImpl.postEvent(SpongeEventFactory.createConstructWorldPropertiesEvent(Sponge.getCauseStackManager().getCurrentCause(), (WorldArchetype) (Object) worldSettings, (WorldProperties) worldInfo));
            }
        } else {
            // WorldSettings will be null here on dedicated server so we need to build one
            worldSettings = new WorldSettings(defaultSeed, server.getGameType(), server.canStructuresSpawn(), server.isHardcore(), defaultWorldType);
        }
        if (worldInfo == null) {
            // Step 4 - At this point, we have either have the WorldInfo or we have none. If we have none, we'll use the settings built above to
            // create the WorldInfo
            worldInfo = createWorldInfoFromSettings(currentSavesDir, (org.spongepowered.api.world.DimensionType) (Object) dimensionType, dimensionId, worldFolderName, worldSettings, generatorOptions);
        } else {
            // create config
            ((IMixinWorldInfo) worldInfo).setDimensionType((org.spongepowered.api.world.DimensionType) (Object) dimensionType);
            ((IMixinWorldInfo) worldInfo).createWorldConfig();
            ((WorldProperties) worldInfo).setGenerateSpawnOnLoad(((IMixinDimensionType) (Object) dimensionType).shouldGenerateSpawnOnLoad());
        }
        // Safety check to ensure we'll get a unique id no matter what
        if (((WorldProperties) worldInfo).getUniqueId() == null) {
            setUuidOnProperties(dimensionId == 0 ? currentSavesDir.getParent() : currentSavesDir, (WorldProperties) worldInfo);
        }
        // Safety check to ensure the world info has the dimension id set
        if (((IMixinWorldInfo) worldInfo).getDimensionId() == null) {
            ((IMixinWorldInfo) worldInfo).setDimensionId(dimensionId);
        }
        // Keep the LevelName in the LevelInfo up to date with the directory name
        if (!worldInfo.getWorldName().equals(worldFolderName)) {
            worldInfo.setWorldName(worldFolderName);
        }
        // Step 5 - Load server resource pack from dimension 0
        if (dimensionId == 0) {
            server.setResourcePackFromWorld(worldFolderName, saveHandler);
        }
        // Step 6 - Cache the WorldProperties we've made so we don't load from disk later.
        registerWorldProperties((WorldProperties) worldInfo);
        if (dimensionId != 0 && !((WorldProperties) worldInfo).loadOnStartup()) {
            SpongeImpl.getLogger().warn("World [{}] (DIM{}) is set to not load on startup. To load it later, enable [load-on-startup] in config " + "or use a plugin", worldFolder, dimensionId);
            continue;
        }
        // Step 7 - Finally, we can create the world and tell it to load
        final WorldServer worldServer = createWorldFromProperties(dimensionId, saveHandler, worldInfo, worldSettings);
        SpongeImpl.getLogger().info("Loading world [{}] ({})", ((org.spongepowered.api.world.World) worldServer).getName(), getDimensionType(dimensionId).get().getName());
    }
    // Set the worlds on the Minecraft server
    reorderWorldsVanillaFirst();
}
Also used : IMixinDimensionType(org.spongepowered.common.interfaces.world.IMixinDimensionType) DimensionType(net.minecraft.world.DimensionType) ISaveHandler(net.minecraft.world.storage.ISaveHandler) IMixinWorldInfo(org.spongepowered.common.interfaces.world.IMixinWorldInfo) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) WorldServer(net.minecraft.world.WorldServer) WorldSettings(net.minecraft.world.WorldSettings) IMixinWorldSettings(org.spongepowered.common.interfaces.world.IMixinWorldSettings) WorldArchetype(org.spongepowered.api.world.WorldArchetype) IMixinIntegratedServer(org.spongepowered.common.interfaces.IMixinIntegratedServer) WorldInfo(net.minecraft.world.storage.WorldInfo) IMixinWorldInfo(org.spongepowered.common.interfaces.world.IMixinWorldInfo) AnvilSaveHandler(net.minecraft.world.chunk.storage.AnvilSaveHandler) Path(java.nio.file.Path) IOException(java.io.IOException) IMixinMinecraftServer(org.spongepowered.common.interfaces.IMixinMinecraftServer) MinecraftServer(net.minecraft.server.MinecraftServer) Map(java.util.Map) BiMap(com.google.common.collect.BiMap) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HashBiMap(com.google.common.collect.HashBiMap) Int2ObjectMap(it.unimi.dsi.fastutil.ints.Int2ObjectMap) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 20 with DimensionType

use of net.minecraft.world.DimensionType in project Cavern2 by kegare.

the class BlockPortalCavern method onEntityCollidedWithBlock.

@Override
public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState state, Entity entity) {
    if (world.isRemote || getDimension() == null || teleporting) {
        return;
    }
    if (entity.isDead || entity.isSneaking() || entity.isRiding() || entity.isBeingRidden() || !entity.isNonBoss() || entity instanceof IProjectile) {
        return;
    }
    if (entity.timeUntilPortal <= 0) {
        ResourceLocation key = getRegistryName();
        IPortalCache cache = PortalCache.get(entity);
        MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
        DimensionType dimOld = world.provider.getDimensionType();
        DimensionType dimNew = isEntityInCave(entity) ? cache.getLastDim(key) : getDimension();
        WorldServer worldNew = server.getWorld(dimNew.getId());
        Teleporter teleporter = getTeleporter(worldNew);
        BlockPos prevPos = entity.getPosition();
        entity.timeUntilPortal = Math.max(entity.getPortalCooldown(), 100);
        if (entity instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) entity;
            if (MinerStats.get(player).getRank() < getMinerRank().getRank()) {
                player.sendStatusMessage(new TextComponentTranslation("cavern.message.portal.rank", new TextComponentTranslation(getMinerRank().getUnlocalizedName())), true);
                return;
            }
        }
        teleporting = true;
        cache.setLastDim(key, dimOld);
        cache.setLastPos(key, dimOld, prevPos);
        PatternHelper pattern = createPatternHelper(world, pos);
        double d0 = pattern.getForwards().getAxis() == EnumFacing.Axis.X ? (double) pattern.getFrontTopLeft().getZ() : (double) pattern.getFrontTopLeft().getX();
        double d1 = pattern.getForwards().getAxis() == EnumFacing.Axis.X ? entity.posZ : entity.posX;
        d1 = Math.abs(MathHelper.pct(d1 - (pattern.getForwards().rotateY().getAxisDirection() == EnumFacing.AxisDirection.NEGATIVE ? 1 : 0), d0, d0 - pattern.getWidth()));
        double d2 = MathHelper.pct(entity.posY - 1.0D, pattern.getFrontTopLeft().getY(), pattern.getFrontTopLeft().getY() - pattern.getHeight());
        cache.setLastPortalVec(new Vec3d(d1, d2, 0.0D));
        cache.setTeleportDirection(pattern.getForwards());
        entity.changeDimension(dimNew.getId(), teleporter);
        teleporting = false;
    } else {
        entity.timeUntilPortal = Math.max(entity.getPortalCooldown(), 100);
    }
}
Also used : DimensionType(net.minecraft.world.DimensionType) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) PatternHelper(net.minecraft.block.state.pattern.BlockPattern.PatternHelper) Teleporter(net.minecraft.world.Teleporter) WorldServer(net.minecraft.world.WorldServer) Vec3d(net.minecraft.util.math.Vec3d) IProjectile(net.minecraft.entity.IProjectile) MinecraftServer(net.minecraft.server.MinecraftServer) IPortalCache(cavern.api.IPortalCache) ResourceLocation(net.minecraft.util.ResourceLocation) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

DimensionType (net.minecraft.world.DimensionType)28 BlockPos (net.minecraft.util.math.BlockPos)8 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 ResourceLocation (net.minecraft.util.ResourceLocation)6 WorldServer (net.minecraft.world.WorldServer)6 IPortalCache (cavern.api.IPortalCache)5 ItemStack (net.minecraft.item.ItemStack)5 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)5 NBTTagList (net.minecraft.nbt.NBTTagList)4 IOException (java.io.IOException)3 Path (java.nio.file.Path)3 MinecraftServer (net.minecraft.server.MinecraftServer)3 File (java.io.File)2 PatternHelper (net.minecraft.block.state.pattern.BlockPattern.PatternHelper)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ActionResult (net.minecraft.util.ActionResult)2 EnumActionResult (net.minecraft.util.EnumActionResult)2 Vec3d (net.minecraft.util.math.Vec3d)2 WorldProvider (net.minecraft.world.WorldProvider)2