Search in sources :

Example 1 with MapItemSavedData

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;
}
Also used : MapItemSavedData(net.minecraft.world.level.saveddata.maps.MapItemSavedData) CraftServer(org.bukkit.craftbukkit.v1_17_R1.CraftServer)

Example 2 with MapItemSavedData

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;
}
Also used : MapItemSavedData(net.minecraft.world.level.saveddata.maps.MapItemSavedData) CraftServer(org.bukkit.craftbukkit.v1_18_R1.CraftServer)

Example 3 with MapItemSavedData

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);
    }
}
Also used : MapItemSavedData(net.minecraft.world.level.saveddata.maps.MapItemSavedData)

Example 4 with MapItemSavedData

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);
}
Also used : MapIdTrackerBridge(org.spongepowered.common.bridge.map.MapIdTrackerBridge) ServerLevel(net.minecraft.server.level.ServerLevel) MapItemSavedData(net.minecraft.world.level.saveddata.maps.MapItemSavedData) CreateMapEvent(org.spongepowered.api.event.action.CreateMapEvent) MapInfo(org.spongepowered.api.map.MapInfo) SpongeMapStorage(org.spongepowered.common.map.SpongeMapStorage)

Example 5 with MapItemSavedData

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);
    }
}
Also used : MapItemSavedData(net.minecraft.world.level.saveddata.maps.MapItemSavedData)

Aggregations

MapItemSavedData (net.minecraft.world.level.saveddata.maps.MapItemSavedData)6 BlockRenderDispatcher (net.minecraft.client.renderer.block.BlockRenderDispatcher)1 ModelManager (net.minecraft.client.resources.model.ModelManager)1 ModelResourceLocation (net.minecraft.client.resources.model.ModelResourceLocation)1 Direction (net.minecraft.core.Direction)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 ItemStack (net.minecraft.world.item.ItemStack)1 MapItem (net.minecraft.world.item.MapItem)1 Vec3 (net.minecraft.world.phys.Vec3)1 CraftServer (org.bukkit.craftbukkit.v1_17_R1.CraftServer)1 CraftServer (org.bukkit.craftbukkit.v1_18_R1.CraftServer)1 CreateMapEvent (org.spongepowered.api.event.action.CreateMapEvent)1 MapInfo (org.spongepowered.api.map.MapInfo)1 MapIdTrackerBridge (org.spongepowered.common.bridge.map.MapIdTrackerBridge)1 SpongeMapStorage (org.spongepowered.common.map.SpongeMapStorage)1