use of net.minecraft.world.level.saveddata.maps.MapItemSavedData in project Denizen-For-Bukkit by DenizenScript.
the class ItemHelperImpl method renderEntireMap.
@Override
public boolean renderEntireMap(int mapId, int xMin, int zMin, int xMax, int zMax) {
MapItemSavedData worldmap = ((CraftServer) Bukkit.getServer()).getServer().getLevel(net.minecraft.world.level.Level.OVERWORLD).getMapData("map_" + mapId);
if (worldmap == null) {
return false;
}
renderFullMap(worldmap, xMin, zMin, xMax, zMax);
return true;
}
use of net.minecraft.world.level.saveddata.maps.MapItemSavedData in project Denizen-For-Bukkit by DenizenScript.
the class ItemHelperImpl method renderEntireMap.
@Override
public boolean renderEntireMap(int mapId, int xMin, int zMin, int xMax, int zMax) {
MapItemSavedData worldmap = ((CraftServer) Bukkit.getServer()).getServer().getLevel(net.minecraft.world.level.Level.OVERWORLD).getMapData("map_" + mapId);
if (worldmap == null) {
return false;
}
renderFullMap(worldmap, xMin, zMin, xMax, zMax);
return true;
}
use of net.minecraft.world.level.saveddata.maps.MapItemSavedData in project Denizen-For-Bukkit by DenizenScript.
the class PacketHelperImpl method setMapData.
@Override
public void setMapData(MapCanvas canvas, byte[] bytes, int x, int y, MapImage image) {
if (x > 127 || y > 127) {
return;
}
int width = Math.min(image.width, 128 - x), height = Math.min(image.height, 128 - y);
if (x + width <= 0 || y + height <= 0) {
return;
}
try {
boolean anyChanged = false;
byte[] buffer = (byte[]) CANVAS_GET_BUFFER.invoke(canvas);
for (int x2 = x < 0 ? -x : 0; x2 < width; ++x2) {
for (int y2 = y < 0 ? -y : 0; y2 < height; ++y2) {
byte p = bytes[y2 * image.width + x2];
if (p != MapPalette.TRANSPARENT) {
int index = (y2 + y) * 128 + (x2 + x);
if (buffer[index] != p) {
buffer[index] = p;
anyChanged = true;
}
}
}
}
if (anyChanged) {
// Flag the whole image as dirty
MapItemSavedData map = (MapItemSavedData) MAPVIEW_WORLDMAP.get(canvas.getMapView());
map.setColorsDirty(Math.max(x, 0), Math.max(y, 0));
map.setColorsDirty(width + x - 1, height + y - 1);
}
} catch (Throwable ex) {
Debug.echoError(ex);
}
}
use of net.minecraft.world.level.saveddata.maps.MapItemSavedData in project SpongeCommon by SpongePowered.
the class SpongeCommonEventFactory method fireCreateMapEvent.
public static Optional<MapInfo> fireCreateMapEvent(final Cause cause, final Set<Value<?>> values) {
final ServerLevel defaultWorld = (ServerLevel) Sponge.server().worldManager().defaultWorld();
final MapIdTrackerBridge mapIdTrackerBridge = (MapIdTrackerBridge) defaultWorld.getDataStorage().computeIfAbsent(MapIndex::new, Constants.Map.MAP_INDEX_DATA_NAME);
final int id = mapIdTrackerBridge.bridge$getHighestMapId().orElse(-1) + 1;
final String s = Constants.Map.MAP_PREFIX + id;
final MapItemSavedData mapData = new MapItemSavedData(s);
// Set default to prevent NPEs
mapData.dimension = Level.OVERWORLD;
final MapInfo mapInfo = (MapInfo) mapData;
for (final Value<?> value : values) {
mapInfo.offer(value);
}
final CreateMapEvent event = SpongeEventFactory.createCreateMapEvent(cause, mapInfo);
SpongeCommon.post(event);
if (event.isCancelled()) {
return Optional.empty();
}
// Advance map id.
final int mcId = defaultWorld.getFreeMapId();
if (id != mcId) {
// TODO: REMOVE OR replace for Integer.MAX_VALUE
SpongeCommon.logger().warn("Map size corruption, vanilla only allows " + Integer.MAX_VALUE + "! " + "Expected next number was not equal to the true next number.");
SpongeCommon.logger().warn("Expected: " + id + ". Got: " + mcId);
SpongeCommon.logger().warn("Automatically cancelling map creation");
mapIdTrackerBridge.bridge$setHighestMapId(id - 1);
return Optional.empty();
}
defaultWorld.setMapData(mapData);
((SpongeMapStorage) Sponge.server().mapStorage()).addMapInfo(mapInfo);
return Optional.of(mapInfo);
}
use of net.minecraft.world.level.saveddata.maps.MapItemSavedData in project Denizen-For-Bukkit by DenizenScript.
the class PacketHelperImpl method setMapData.
@Override
public void setMapData(MapCanvas canvas, byte[] bytes, int x, int y, MapImage image) {
if (x > 127 || y > 127) {
return;
}
int width = Math.min(image.width, 128 - x), height = Math.min(image.height, 128 - y);
if (x + width <= 0 || y + height <= 0) {
return;
}
try {
boolean anyChanged = false;
byte[] buffer = (byte[]) CANVAS_GET_BUFFER.invoke(canvas);
for (int x2 = x < 0 ? -x : 0; x2 < width; ++x2) {
for (int y2 = y < 0 ? -y : 0; y2 < height; ++y2) {
byte p = bytes[y2 * image.width + x2];
if (p != MapPalette.TRANSPARENT) {
int index = (y2 + y) * 128 + (x2 + x);
if (buffer[index] != p) {
buffer[index] = p;
anyChanged = true;
}
}
}
}
if (anyChanged) {
// Flag the whole image as dirty
MapItemSavedData map = (MapItemSavedData) MAPVIEW_WORLDMAP.get(canvas.getMapView());
map.setColorsDirty(Math.max(x, 0), Math.max(y, 0));
map.setColorsDirty(width + x - 1, height + y - 1);
}
} catch (Throwable ex) {
Debug.echoError(ex);
}
}
Aggregations