MapCopier

From MinecraftOnline
Jump to navigation Jump to search
Mapmarker labicon.png MapCopier
About
ID Map
Self Triggered No
Clickable No
Input Yes
Output Yes
Rail No
Sign post icon.png Sign Format
First line ```Map number```
Second line [Map]
Craftbook Page

Replaces a held empty map with the map specified by the MapCopier. Must be placed on a bookshelf.

Details

  • First Line
    • The number of the map to be copied
  • Second Line
    • [Map]

Notes

The Map Art of MCO page has an incomplete gallery of map art built by players and their ID numbers.

This Bash script can also be used to scrape all available maps from the map cache endpoint: Click here to toggle Bash code block visibility

#!/usr/bin/env bash

# Directory to save maps in
OUTPUT=maps

# Option to remove empty maps
REMOVE_EMPTY_MAPS=true
EMPTY_MAP_MD5SUM=2de1fb8bd51769a254c49839675e4f02

# C-style format string for a map URL
MAP_URL_TEMPLATE=https://minecraftonline.com/resources/images/mapscache/map_%d_1.png

# After this many consecutive HTTP errors, the script will exit
N_ERRORS_BEFORE_EXIT=5

mkdir -pv "$OUTPUT"

n_consecutive_errors=0

i=$(find "$OUTPUT" -type f |
	sort -V |
	tail -n 1 |
	grep -Po "(?<=map_)[0-9]+")

[ -z $i ] &&
	i=1 ||
	i=$[$i+1] &&
		echo "Resuming at map $i"

trap "rm -f map-*.temp" exit

while true
do
	url=$(printf $MAP_URL_TEMPLATE $i)
	output_file="$OUTPUT/$(basename $url)"
	[ -f "$output_file" ] && continue
	temp_file=$(mktemp -u map-XXX.temp)
	echo -ne "\r\033[1KDownloading map ${i}..."
	if wget -qO $temp_file $url
	then
		mv $temp_file $output_file
		[ $n_consecutive_errors -gt 0 ] &&
			echo "success; reset HTTP error count to 0"
		n_consecutive_errors=0
	else
		n_consecutive_errors=$[$n_consecutive_errors+1]
		n_tries_remaining=$[$N_ERRORS_BEFORE_EXIT-$n_consecutive_errors]
		[ $n_consecutive_errors -eq $N_ERRORS_BEFORE_EXIT ] && break
		echo "HTTP error; $n_tries_remaining more tries until exit"
		
	fi
	i=$[$i+1]
done

echo -e "\nNo more maps to download"

if [ "$REMOVE_EMPTY_MAPS" = true ]
then
	echo -n "Removing empty maps..."
	n_removed=$(
		find "$OUTPUT" -type f |
			xargs md5sum |
			grep $EMPTY_MAP_MD5SUM |
			awk '{print $2}' |
			xargs rm -v 2> /dev/null |
			wc -l
	)
	echo "removed $n_removed files"
fi

See Also