Created
March 20, 2021 21:18
-
-
Save Demonly/3713117ca2dcc60d4ba88748485fd748 to your computer and use it in GitHub Desktop.
Minecraft 1.16 - Allows for dynamic map updating
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.mojang.authlib.GameProfile; | |
import net.minecraft.server.v1_16_R3.*; | |
import org.bukkit.craftbukkit.v1_16_R3.CraftWorld; | |
import org.bukkit.craftbukkit.v1_16_R3.map.CraftMapView; | |
import org.bukkit.map.MapView; | |
import java.lang.reflect.Field; | |
import java.util.UUID; | |
public class MapUpdater extends EntityHuman { | |
public static final UUID ID = UUID.randomUUID(); | |
public static final String NAME = "_____MapUpdater_____"; | |
public MapUpdater(CraftWorld world, BlockPosition position, Float f) { | |
super(world.getHandle(), position, f, new GameProfile(ID, NAME)); | |
} | |
@Override | |
public boolean isCreative() { | |
return false; | |
} | |
@Override | |
public boolean isSpectator() { | |
return false; | |
} | |
public void update(MapView mapView) { | |
if (mapView == null) { | |
throw new IllegalArgumentException("mapView cannot be null"); | |
} | |
if (((CraftWorld) mapView.getWorld()).getHandle() != world) { | |
throw new IllegalArgumentException("world of mapView cannot be different"); | |
} | |
try { | |
Field field = CraftMapView.class.getDeclaredField("worldMap"); | |
field.setAccessible(true); | |
WorldMap worldMap = (WorldMap) field.get(mapView); | |
int size = 128 << worldMap.scale; | |
for (int x = worldMap.centerX - size / 2; x <= worldMap.centerX + size / 2; x += 64) { | |
for (int z = worldMap.centerZ - size / 2; z <= worldMap.centerZ + size / 2; z += 64) { | |
setPositionRaw(x, 0., z); | |
((ItemWorldMap) Items.FILLED_MAP).a(world, this, worldMap); | |
} | |
} | |
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment