Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First-pass partial implementation of sendMap #605

Merged
merged 4 commits into from
Dec 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main/java/net/glowstone/entity/GlowPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import net.glowstone.inventory.InventoryMonitor;
import net.glowstone.inventory.crafting.PlayerRecipeMonitor;
import net.glowstone.io.PlayerDataService.PlayerReader;
import net.glowstone.map.GlowMapCanvas;
import net.glowstone.net.GlowSession;
import net.glowstone.net.message.play.entity.AnimateEntityMessage;
import net.glowstone.net.message.play.entity.DestroyEntitiesMessage;
Expand All @@ -73,6 +74,7 @@
import net.glowstone.net.message.play.game.ExperienceMessage;
import net.glowstone.net.message.play.game.HealthMessage;
import net.glowstone.net.message.play.game.JoinGameMessage;
import net.glowstone.net.message.play.game.MapDataMessage;
import net.glowstone.net.message.play.game.MultiBlockChangeMessage;
import net.glowstone.net.message.play.game.NamedSoundEffectMessage;
import net.glowstone.net.message.play.game.PlayEffectMessage;
Expand Down Expand Up @@ -2404,7 +2406,9 @@ public void sendBlockEntityChange(Location location, GlowBlockEntity type, Compo

@Override
public void sendMap(MapView map) {
throw new UnsupportedOperationException("Not supported yet.");
GlowMapCanvas mapCanvas = GlowMapCanvas.createAndRender(map, this);
session.send(new MapDataMessage(map.getId(), map.getScale().ordinal(), Collections.emptyList(),
mapCanvas.toSection()));
}

@Override
Expand Down
22 changes: 19 additions & 3 deletions src/main/java/net/glowstone/map/GlowMapCanvas.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package net.glowstone.map;

import java.awt.Image;
import net.glowstone.net.message.play.game.MapDataMessage.Section;
import org.bukkit.entity.Player;
import org.bukkit.map.MapCanvas;
import org.bukkit.map.MapCursorCollection;
import org.bukkit.map.MapFont;
import org.bukkit.map.MapRenderer;
import org.bukkit.map.MapView;

/**
* Represents a canvas for drawing to a map. Each canvas is associated with a specific {@link org.bukkit.map.MapRenderer} and represents that renderer's layer on the map.
Expand All @@ -12,16 +16,25 @@ public final class GlowMapCanvas implements MapCanvas {

public static final int MAP_SIZE = 128;
private final byte[] buffer = new byte[MAP_SIZE * MAP_SIZE];
private final GlowMapView mapView;
private final MapView mapView;
private MapCursorCollection cursors = new MapCursorCollection();
private byte[] base;

protected GlowMapCanvas(GlowMapView mapView) {
public static GlowMapCanvas createAndRender(MapView mapView, Player player) {
GlowMapCanvas out = new GlowMapCanvas(mapView);
for (MapRenderer renderer : mapView.getRenderers()) {
renderer.initialize(mapView);
renderer.render(mapView, out, player);
}
return out;
}

protected GlowMapCanvas(MapView mapView) {
this.mapView = mapView;
}

@Override
public GlowMapView getMapView() {
public MapView getMapView() {
return mapView;
}

Expand Down Expand Up @@ -80,4 +93,7 @@ public void drawText(int x, int y, MapFont font, String text) {
throw new UnsupportedOperationException("Not supported yet.");
}

public Section toSection() {
return new Section(MAP_SIZE, MAP_SIZE, mapView.getCenterX(), mapView.getCenterZ(), buffer.clone());
}
}
9 changes: 4 additions & 5 deletions src/main/java/net/glowstone/map/GlowMapView.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.glowstone.GlowWorld;
import net.glowstone.entity.GlowPlayer;
import org.bukkit.World;
import org.bukkit.map.MapRenderer;
Expand All @@ -21,9 +20,9 @@ public final class GlowMapView implements MapView {
private final short id;
private Scale scale;
private int x, z;
private GlowWorld world;
private World world;

protected GlowMapView(GlowWorld world, short id) {
protected GlowMapView(World world, short id) {
this.world = world;
this.id = id;
x = world.getSpawnLocation().getBlockX();
Expand Down Expand Up @@ -76,13 +75,13 @@ public void setCenterZ(int z) {
}

@Override
public GlowWorld getWorld() {
public World getWorld() {
return world;
}

@Override
public void setWorld(World world) {
this.world = (GlowWorld) world;
this.world = world;
}

@Override
Expand Down