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
Changes from 1 commit
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
Next Next commit
First-pass partial implementation of sendMap
Will send blank maps until GlowMapRenderer.render() is implemented.
  • Loading branch information
Pr0methean committed Dec 17, 2017
commit 9fd517aef42a16e2d43873d8cf41d1d3809bd047
10 changes: 9 additions & 1 deletion src/main/java/net/glowstone/entity/GlowPlayer.java
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@
import java.util.concurrent.ThreadLocalRandom;
import java.util.logging.Level;
import java.util.stream.Collectors;
import javafx.scene.effect.Glow;
import javax.annotation.Nullable;
import lombok.Getter;
import lombok.Setter;
@@ -61,6 +62,8 @@
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.map.GlowMapView;
import net.glowstone.net.GlowSession;
import net.glowstone.net.message.play.entity.AnimateEntityMessage;
import net.glowstone.net.message.play.entity.DestroyEntitiesMessage;
@@ -73,6 +76,8 @@
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.MapDataMessage.Section;
import net.glowstone.net.message.play.game.MultiBlockChangeMessage;
import net.glowstone.net.message.play.game.NamedSoundEffectMessage;
import net.glowstone.net.message.play.game.PlayEffectMessage;
@@ -173,6 +178,7 @@
import org.bukkit.inventory.Merchant;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.Recipe;
import org.bukkit.map.MapRenderer;
import org.bukkit.map.MapView;
import org.bukkit.material.MaterialData;
import org.bukkit.plugin.Plugin;
@@ -2404,7 +2410,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
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.
@@ -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;
}

@@ -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());
}
}
8 changes: 4 additions & 4 deletions src/main/java/net/glowstone/map/GlowMapView.java
Original file line number Diff line number Diff line change
@@ -21,9 +21,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();
@@ -76,13 +76,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