Пример #1
0
func main() {
	path := flag.String("path", "", "Path to region directory")
	flag.Parse()

	if *path == "" {
		flag.Usage()
		os.Exit(1)
	}

	region, err := mcmap.OpenRegion(*path, false)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Could not open region: %s\n", err)
		os.Exit(1)
	}

	chunk, err := region.Chunk(200, 200)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error getting chunk 200,200: %s\n", err)
		os.Exit(1)
	}

	chunk.MarkDeleted()
	if err := chunk.MarkUnused(); err != nil {
		fmt.Fprintf(os.Stderr, "Could not mark chunk as unused: %s\n", err)
		os.Exit(1)
	}

	if err := region.Save(); err != nil {
		fmt.Fprintf(os.Stderr, "Could not save region: %s\n", err)
		os.Exit(1)
	}
}
Пример #2
0
func main() {
	path := flag.String("path", "", "Path to region directory")
	flag.Parse()

	if *path == "" {
		flag.Usage()
		os.Exit(1)
	}

	region, err := mcmap.OpenRegion(*path, true)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Could not open region: %s\n", err)
		os.Exit(1)
	}

chunkLoop:
	for chunkPos := range region.AllChunks() {
		cx, cz := chunkPos.X, chunkPos.Z
		chunk, err := region.Chunk(cx, cz)
		switch err {
		case nil:
		case mcmap.NotAvailable:
			continue chunkLoop
		default:
			fmt.Fprintf(os.Stderr, "Error while getting chunk (%d, %d): %s\n", cx, cz, err)
			os.Exit(1)
		}

		modified := false
		chunk.Iter(func(x, y, z int, blk *mcmap.Block) {
			if blk.ID == mcmap.BlkBlockOfIron {
				blk.ID = mcmap.BlkBlockOfDiamond
				modified = true
			}
		})

		if modified {
			fmt.Printf("Modified chunk %d, %d.\n", cx, cz)
			chunk.MarkModified()
		}

		if err := chunk.MarkUnused(); err != nil {
			fmt.Fprintf(os.Stderr, "Error while unloading chunk %d, %d: %s\n", cx, cz, err)
			os.Exit(1)
		}
	}

	if err := region.Save(); err != nil {
		fmt.Fprintf(os.Stderr, "Error while saving: %s\n", err)
		os.Exit(1)
	}
}
Пример #3
0
func readWorld(p string) (*mcmap.Region, int, int, error) {
	f, err := os.Open(p)
	if err != nil {
		return nil, 0, 0, err
	}
	defer f.Close()

	x, z, err := getMapCenter(f)
	if err != nil {
		return nil, 0, 0, err
	}

	dir, _ := path.Split(p)
	region, err := mcmap.OpenRegion(path.Join(dir, "region"), false)
	return region, x, z, err
}
Пример #4
0
func main() {
	path := flag.String("path", "", "Path to region directory")
	flag.Parse()

	if *path == "" {
		flag.Usage()
		os.Exit(1)
	}

	region, err := mcmap.OpenRegion(*path, true)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Could not open region: %s\n", err)
		os.Exit(1)
	}

chunkLoop:
	for chunkPos := range region.AllChunks() {
		cx, cz := chunkPos.X, chunkPos.Z
		chunk, err := region.Chunk(cx, cz)
		switch err {
		case nil:
		case mcmap.NotAvailable:
			continue chunkLoop
		default:
			fmt.Fprintf(os.Stderr, "Error while getting chunk (%d, %d): %s\n", cx, cz, err)
			os.Exit(1)
		}

		chunk.Iter(func(x, y, z int, blk *mcmap.Block) {
			if blk.ID == mcmap.BlkEmeraldOre {
				absx, absz := mcmap.ChunkToBlock(cx, cz, x, z)
				fmt.Printf("%d, %d, %d\n", absx, y, absz)
			}
		})

		chunk.MarkUnused()
	}
}
Пример #5
0
func main() {
	path := flag.String("path", "", "Path to region directory")
	flag.Parse()

	if *path == "" {
		flag.Usage()
		os.Exit(1)
	}

	region, err := mcmap.OpenRegion(*path, false)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Could not open region: %s\n", err)
		os.Exit(1)
	}

	chunk, err := region.NewChunk(200, 200)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Could not create a Chunk at 200,200: %s\n", err)
		os.Exit(1)
	}

	chunk.Iter(func(x, y, z int, blk *mcmap.Block) {
		blk.ID = mcmap.BlkSandstone
	})

	chunk.RecalcHeightMap()
	chunk.MarkModified()
	if err := chunk.MarkUnused(); err != nil {
		fmt.Fprintf(os.Stderr, "Could not MarkUnused(): %s\n", err)
		os.Exit(1)
	}

	if err := region.Save(); err != nil {
		fmt.Fprintf(os.Stderr, "Could not save region: %s\n", err)
		os.Exit(1)
	}
}
Пример #6
0
func main() {
	path := flag.String("path", "", "Path to region directory")
	output := flag.String("output", "map.png", "File to write image to")
	flag.Parse()

	if *path == "" {
		flag.Usage()
		os.Exit(1)
	}

	region, err := mcmap.OpenRegion(*path, true)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Could not open region: %s\n", err)
		os.Exit(1)
	}

	xmin, xmax, zmin, zmax := region.MaxDims()
	w := (xmax - xmin) * mcmap.ChunkSizeXZ
	h := (zmax - zmin) * mcmap.ChunkSizeXZ
	img := image.NewRGBA(image.Rect(0, 0, w, h))

chunkLoop:
	for chunkPos := range region.AllChunks() {
		cx, cz := chunkPos.X, chunkPos.Z
		chunk, err := region.Chunk(cx, cz)
		switch err {
		case nil:
		case mcmap.NotAvailable:
			continue chunkLoop
		default:
			fmt.Fprintf(os.Stderr, "Error while getting chunk (%d, %d): %s\n", cx, cz, err)
			os.Exit(1)
		}

		for x := 0; x < mcmap.ChunkSizeXZ; x++ {
		scanZ:
			for z := 0; z < mcmap.ChunkSizeXZ; z++ {
				ax, az := mcmap.ChunkToBlock(cx, cz, x, z)
				for y := mcmap.ChunkSizeY; y >= 0; y-- {
					blk := chunk.Block(x, y, z)
					c, ok := colors[blk.ID]
					if ok {
						img.Set(ax-(xmin*mcmap.ChunkSizeXZ), az-(zmin*mcmap.ChunkSizeXZ), c)
						continue scanZ
					}
				}
				img.Set(ax-(xmin*mcmap.ChunkSizeXZ), az-(zmin*mcmap.ChunkSizeXZ), rgb(0x000000))
			}
		}

		if err := chunk.MarkUnused(); err != nil {
			fmt.Fprintf(os.Stderr, "Error while unloading chunk %d, %d: %s\n", cx, cz, err)
			os.Exit(1)
		}
	}

	f, err := os.Create(*output)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Could not write image: %s", err)
		os.Exit(1)
	}
	defer f.Close()
	if err := png.Encode(f, img); err != nil {
		fmt.Fprintf(os.Stderr, "Could not write image: %s", err)
		os.Exit(1)
	}
}