Selecting a chunk will replace the list with an ent list.

Clicking the ent list will TP the player.
This commit is contained in:
ProfMobius committed 2013-12-06 16:59:10 +01:00
1 parent 8ac018ecba
commit e2c134295e
9 files changed
+124 -19

No files matched your search

@@ -4,6 +4,7 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import codechicken.lib.math.MathHelper;
import net.minecraft.tileentity.TileEntity;
public final class CoordinatesBlock implements ISerializable {
@@ -21,6 +22,16 @@ public final class CoordinatesBlock implements ISerializable {
//this.isChunk = false;
}
public CoordinatesBlock(int dim, double x, double y, double z){
this.dim = dim;
this.x = MathHelper.floor_double(x);
this.y = MathHelper.floor_double(y);
this.z = MathHelper.floor_double(z);
this.chunkX = MathHelper.floor_double(x) >> 4;
this.chunkZ = MathHelper.floor_double(z) >> 4;
//this.isChunk = false;
}
public CoordinatesBlock(CoordinatesChunk coord){
this.dim = coord.dim;
this.chunkX = coord.chunkX;
@@ -75,6 +75,10 @@ public class EntityStats implements ISerializable, Comparable {
return String.format("[%d] %50s %.3f \u00B5s", this.entId, this.name, this.getGeometricMean());
}
public CoordinatesBlock getCoord(){
return new CoordinatesBlock(this.dim, this.x, this.y, this.z);
}
@Override
public void writeToStream(DataOutputStream stream) throws IOException{
stream.writeInt(this.entId);
@@ -42,6 +42,7 @@ public interface IWidget {
IWidget delWidget(String name);
IWidget getWidgetAtCoordinates(double posX, double posY);
IWidget getWidgetAtLayer(double posX, double posY, int layer);
boolean hasWidget(String name);
boolean isWidgetAtCoordinates(double posx, double posy);
+8 -1
View File
@@ -95,10 +95,17 @@ public abstract class WidgetBase implements IWidget {
@Override
public IWidget delWidget(String name){
IWidget widget = this.getWidget(name);
this.widgets.remove(widget);
//this.widgets.remove(widget);
this.widgets.remove(name);
return widget;
}
@Override
public boolean hasWidget(String name){
if (this.widgets.containsKey(name)) return true;
return false;
}
@Override
public IWidget getWidgetAtLayer(double posX, double posY, int layer){
if (layer == 0) return this;
@@ -126,8 +126,8 @@ public class OpisPacketHandler implements IPacketHandler {
else if (header == Packets.DATA_LIST_CHUNK_ENTITIES){
Packet_DataListChunkEntities castedPacket = new Packet_DataListChunkEntities(packet);
for (EntityStats entity : castedPacket.stats)
System.out.printf("%s\n", entity);
OverlayEntityPerChunk.instance().entStats = castedPacket.stats;
OverlayEntityPerChunk.instance().setupEntTable();
}
}
@@ -18,7 +18,7 @@ public class Packet_DataListChunkEntities {
public Packet_DataListChunkEntities(Packet250CustomPayload packet) {
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
this.stats.clear();
this.stats.clear();
try{
this.header = inputStream.readByte();
@@ -17,6 +17,7 @@ import mapwriter.map.MapView;
import mapwriter.map.mapmode.MapMode;
import mcp.mobius.opis.data.holders.CoordinatesBlock;
import mcp.mobius.opis.data.holders.CoordinatesChunk;
import mcp.mobius.opis.data.holders.EntityStats;
import mcp.mobius.opis.gui.events.MouseEvent;
import mcp.mobius.opis.gui.interfaces.CType;
import mcp.mobius.opis.gui.interfaces.IWidget;
@@ -53,6 +54,7 @@ public class OverlayEntityPerChunk implements IMwDataProvider {
public LayoutCanvas canvas = null;
public HashMap<CoordinatesChunk, Integer> overlayData = new HashMap<CoordinatesChunk, Integer>();
public ArrayList<ReducedData> reducedData = new ArrayList<ReducedData>();
public ArrayList<EntityStats> entStats = new ArrayList<EntityStats>();
CoordinatesChunk selectedChunk = null;
private OverlayEntityPerChunk(){}
@@ -139,7 +141,7 @@ public class OverlayEntityPerChunk implements IMwDataProvider {
@Override
public void onDimensionChanged(int dimension, MapView mapview) {
PacketDispatcher.sendPacketToServer(Packet_ReqData.create("overlay:chunk:entities"));
//PacketDispatcher.sendPacketToServer(Packet_ReqData.create("overlay:chunk:entities"));
}
@Override
@@ -176,6 +178,9 @@ public class OverlayEntityPerChunk implements IMwDataProvider {
@SideOnly(Side.CLIENT)
public void setupChunkTable(){
if (this.canvas.hasWidget("Table"))
this.canvas.delWidget("Table");
LayoutBase layout = (LayoutBase)this.canvas.addWidget("Table", new LayoutBase(null));
//layout.setGeometry(new WidgetGeometry(100.0,0.0,300.0,100.0,CType.RELXY, CType.REL_Y, WAlign.RIGHT, WAlign.TOP));
layout.setGeometry(new WidgetGeometry(100.0,0.0,20.0,100.0,CType.RELXY, CType.RELXY, WAlign.RIGHT, WAlign.TOP));
@@ -201,10 +206,47 @@ public class OverlayEntityPerChunk implements IMwDataProvider {
this.showList = true;
}
@SideOnly(Side.CLIENT)
public void setupEntTable(){
if (this.canvas.hasWidget("Table"))
this.canvas.delWidget("Table");
LayoutBase layout = (LayoutBase)this.canvas.addWidget("Table", new LayoutBase(null));
//layout.setGeometry(new WidgetGeometry(100.0,0.0,300.0,100.0,CType.RELXY, CType.REL_Y, WAlign.RIGHT, WAlign.TOP));
layout.setGeometry(new WidgetGeometry(100.0,0.0,20.0,100.0,CType.RELXY, CType.RELXY, WAlign.RIGHT, WAlign.TOP));
layout.setBackgroundColors(0x90202020, 0x90202020);
TableEntities table = (TableEntities)layout.addWidget("Table_", new TableEntities(null, this));
table.setGeometry(new WidgetGeometry(0.0,0.0,100.0,100.0,CType.RELXY, CType.RELXY, WAlign.LEFT, WAlign.TOP));
table.setColumnsAlign(WAlign.CENTER, WAlign.CENTER)
//.setColumnsTitle("\u00a7a\u00a7oType", "\u00a7a\u00a7oPos", "\u00a7a\u00a7oUpdate Time")
.setColumnsTitle("Name", "Pos")
.setColumnsWidth(75,25)
.setRowColors(0xff808080, 0xff505050)
.setFontSize(1.0f);
int nrows = 0;
for (EntityStats data : this.entStats){
String[] namelst = data.getName().split("\\.");
String name = namelst[namelst.length - 1];
table.addRow(data, name, String.format("[ %d %d %d ]", data.getCoord().x, data.getCoord().y, data.getCoord().z));
nrows++;
if (nrows > 100) break;
}
this.showList = true;
}
@Override
public boolean onMouseInput(MapView mapview, MapMode mapmode) {
if (this.canvas != null && this.canvas.shouldRender() && ((LayoutCanvas)this.canvas).hasWidgetAtCursor()){
((TableChunks)this.canvas.getWidget("Table").getWidget("Table_")).setMap(mapview, mapmode);
if (this.canvas.getWidget("Table").getWidget("Table_") instanceof TableEntities)
((TableEntities)this.canvas.getWidget("Table").getWidget("Table_")).setMap(mapview, mapmode);
else
((TableChunks)this.canvas.getWidget("Table").getWidget("Table_")).setMap(mapview, mapmode);
this.canvas.handleMouseInput();
return true;
}
@@ -1,8 +1,7 @@
package mcp.mobius.opis.overlay.entperchunk;
import cpw.mods.fml.common.network.PacketDispatcher;
import net.minecraft.client.Minecraft;
import net.minecraft.util.MathHelper;
import cpw.mods.fml.common.network.PacketDispatcher;
import mapwriter.map.MapView;
import mapwriter.map.mapmode.MapMode;
import mcp.mobius.opis.data.holders.CoordinatesBlock;
@@ -10,7 +9,7 @@ import mcp.mobius.opis.gui.events.MouseEvent;
import mcp.mobius.opis.gui.interfaces.IWidget;
import mcp.mobius.opis.gui.widgets.tableview.TableRow;
import mcp.mobius.opis.gui.widgets.tableview.ViewTable;
import mcp.mobius.opis.network.client.Packet_ReqTeleport;
import mcp.mobius.opis.network.client.Packet_ReqData;
import mcp.mobius.opis.overlay.entperchunk.OverlayEntityPerChunk.ReducedData;
public class TableChunks extends ViewTable {
@@ -33,17 +32,16 @@ public class TableChunks extends ViewTable {
TableRow row = this.getRow(event.x, event.y);
if (row != null){
CoordinatesBlock coord = ((ReducedData)row.getObject()).chunk.asCoordinatesBlock();
this.overlay.selectedChunk = ((ReducedData)row.getObject()).chunk;
PacketDispatcher.sendPacketToServer(Packet_ReqData.create(this.overlay.selectedChunk, "list:chunk:entities"));
this.overlay.showList = false;
if (this.mapView.getX() != coord.x || this.mapView.getZ() != coord.z || this.mapView.getDimension() != coord.dim){
this.mapView.setDimension(coord.dim);
this.mapView.setViewCentre(coord.x, coord.z);
this.overlay.requestChunkUpdate(this.mapView.getDimension(),
MathHelper.ceiling_double_int(this.mapView.getX()) >> 4,
MathHelper.ceiling_double_int(this.mapView.getZ()) >> 4);
} else {
PacketDispatcher.sendPacketToServer(Packet_ReqTeleport.create(coord));
Minecraft.getMinecraft().setIngameFocus();
}
this.mapView.setDimension(coord.dim);
this.mapView.setViewCentre(coord.x, coord.z);
this.overlay.requestChunkUpdate(this.mapView.getDimension(),
MathHelper.ceiling_double_int(this.mapView.getX()) >> 4,
MathHelper.ceiling_double_int(this.mapView.getZ()) >> 4);
}
}
}
@@ -0,0 +1,42 @@
package mcp.mobius.opis.overlay.entperchunk;
import cpw.mods.fml.common.network.PacketDispatcher;
import net.minecraft.client.Minecraft;
import net.minecraft.util.MathHelper;
import mapwriter.map.MapView;
import mapwriter.map.mapmode.MapMode;
import mcp.mobius.opis.data.holders.CoordinatesBlock;
import mcp.mobius.opis.data.holders.EntityStats;
import mcp.mobius.opis.gui.events.MouseEvent;
import mcp.mobius.opis.gui.interfaces.IWidget;
import mcp.mobius.opis.gui.widgets.tableview.TableRow;
import mcp.mobius.opis.gui.widgets.tableview.ViewTable;
import mcp.mobius.opis.network.client.Packet_ReqData;
import mcp.mobius.opis.network.client.Packet_ReqTeleport;
import mcp.mobius.opis.overlay.entperchunk.OverlayEntityPerChunk.ReducedData;
public class TableEntities extends ViewTable {
MapView mapView;
MapMode mapMode;
OverlayEntityPerChunk overlay;
public TableEntities(IWidget parent, OverlayEntityPerChunk overlay) {
super(parent);
this.overlay = overlay;
}
public void setMap(MapView mapView, MapMode mapMode){
this.mapView = mapView;
this.mapMode = mapMode;
}
@Override
public void onMouseClick(MouseEvent event){
TableRow row = this.getRow(event.x, event.y);
if (row != null){
CoordinatesBlock coord = ((EntityStats)row.getObject()).getCoord();
PacketDispatcher.sendPacketToServer(Packet_ReqTeleport.create(coord));
Minecraft.getMinecraft().setIngameFocus();
}
}
}