コード例 #1
0
ファイル: generator.go プロジェクト: MJKWoolnough/minewebgen
func (g *generator) Generate(name, mapPath string, o *ora.ORA, c chan paint, m chan string, memoryLimit uint64) error {
	sTerrain, err := toPaletted(o, "terrain", g.Terrain.Palette)
	if err != nil {
		return err
	}
	if sTerrain == nil {
		return layerError{"terrain"}
	}

	sHeight, err := toGray(o, "height")
	if err != nil {
		return err
	}
	if sHeight == nil {
		return layerError{"height"}
	}

	sBiomes, err := toPaletted(o, "biomes", g.Biomes.Palette)
	if err != nil {
		return err
	}
	sWater, err := toGray(o, "water")
	if err != nil {
		return err
	}
	sPlants, err := toPaletted(o, "plants", g.Plants.Palette)
	if err != nil {
		return err
	}

	p, err := minecraft.NewFilePath(mapPath)
	if err != nil {
		return err
	}

	l, err := minecraft.NewLevel(p)
	if err != nil {
		return err
	}
	level := &level{Level: l, MemoryLimit: memoryLimit}

	level.LevelName(name)

	m <- "Building Terrain"
	if err = g.buildTerrain(p, level, sTerrain, sBiomes, sPlants, sHeight, sWater, c); err != nil {
		return err
	}

	level.LevelName(name)
	level.Generator(minecraft.FlatGenerator)
	level.GeneratorOptions("0")
	level.GameMode(minecraft.Creative)

	for k, v := range g.generator.Options {
		v = strings.ToLower(v)
		switch strings.ToLower(k) {
		case "generate-structures":
			level.MapFeatures(v != "false")
		case "hardcore":
			level.Hardcore(v != "false")
		case "gamemode":
			gm, _ := strconv.Atoi(v)
			if gm >= 0 && gm <= 3 {
				level.GameMode(int32(gm))
			}
		case "difficulty":
			d, _ := strconv.Atoi(v)
			if d >= 0 && d <= 3 {
				level.Difficulty(int8(d))
			}
		case "daylight-cycle":
			level.DayLightCycle(v != "false")
		case "fire-tick":
			level.FireTick(v != "false")
		case "keep-inventory":
			level.KeepInventory(v != "false")
		}
	}

	level.AllowCommands(true)
	level.MobSpawning(false)
	level.MobGriefing(false)
	level.Spawn(10, 250, 10)

	m <- "Exporting"
	level.Save()
	level.Close()
	return nil
}
コード例 #2
0
ファイル: rpc.go プロジェクト: MJKWoolnough/minewebgen
func (r RPC) createMap(data data.DefaultMap, generatorSettings string) error {
	if data.Seed == 0 {
		data.Seed = rand.Int63()
	}
	m := r.c.NewMap()
	if m == nil {
		return errors.New("failed to create map")
	}
	m.Lock()
	defer m.Unlock()
	p, err := minecraft.NewFilePath(m.Path)
	if err != nil {
		r.c.RemoveMap(m.ID)
		return err
	}
	l, err := minecraft.NewLevel(p)
	if err != nil {
		r.c.RemoveMap(m.ID)
		return err
	}
	l.GameMode(data.GameMode)
	l.LevelName(data.Name)
	m.Name = data.Name
	switch data.Mode {
	case 0:
		l.Generator(minecraft.DefaultGenerator)
	case 1:
		l.Generator(minecraft.FlatGenerator)
	case 2:
		l.Generator(minecraft.LargeBiomeGenerator)
	case 3:
		l.Generator(minecraft.AmplifiedGenerator)
	case 4:
		l.Generator(minecraft.CustomGenerator)
	}
	l.Seed(data.Seed)
	l.AllowCommands(data.Cheats)
	l.MapFeatures(data.Structures)
	if generatorSettings != "" {
		l.GeneratorOptions(generatorSettings)
	}
	l.Save()
	f, err := os.Create(path.Join(m.Path, "properties.map"))
	if err != nil {
		r.c.RemoveMap(m.ID)
		return err
	}
	defer f.Close()
	ms := DefaultMapSettings()
	ms["gamemode"] = strconv.Itoa(int(data.GameMode))
	if !data.Structures {
		ms["generate-structures"] = "false"
	}
	if data.GameMode == 3 {
		ms["hardcore"] = "true"
	}
	if generatorSettings != "" {
		ms["generator-settings"] = generatorSettings
	}
	ms["level-seed"] = strconv.FormatInt(data.Seed, 10)
	ms["motd"] = data.Name
	switch data.Mode {
	case 0:
		ms["level-type"] = minecraft.DefaultGenerator
	case 1:
		ms["level-type"] = minecraft.FlatGenerator
	case 2:
		ms["level-type"] = minecraft.LargeBiomeGenerator
	case 3:
		ms["level-type"] = minecraft.AmplifiedGenerator
	case 4:
		ms["level-type"] = minecraft.CustomGenerator
	case 5:
		ms["level-type"] = minecraft.DebugGenerator
	}
	if err := ms.WriteTo(f); err != nil {
		return err
	}
	go r.c.Save()
	return nil
}