Пример #1
0
func newCache(blocks []data.Blocks) *chunkCache {
	mem := minecraft.NewMemPath()
	l, _ := minecraft.NewLevel(mem)

	bedrock := minecraft.Block{ID: 7}

	l.SetBlock(0, 0, 0, minecraft.Block{})
	l.Save()
	l.Close()
	clearChunk, _ := mem.GetChunk(0, 0)

	for j := int32(0); j < 255; j++ {
		l.SetBlock(-1, j, -1, bedrock)
		l.SetBlock(-1, j, 16, bedrock)
		l.SetBlock(16, j, -1, bedrock)
		l.SetBlock(16, j, 16, bedrock)
		for i := int32(0); i < 16; i++ {
			l.SetBlock(i, j, -1, bedrock)
			l.SetBlock(i, j, 16, bedrock)
			l.SetBlock(-1, j, i, bedrock)
			l.SetBlock(16, j, i, bedrock)
		}
	}
	l.Save()
	l.Close()
	mem.SetChunk(clearChunk)
	return &chunkCache{
		mem:    mem,
		level:  l,
		clear:  clearChunk,
		cache:  make(map[uint16]nbt.Tag),
		blocks: blocks,
	}
}
Пример #2
0
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
}
Пример #3
0
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
}