mirror of
https://github.com/GTNewHorizons/Opis.git
synced 2026-11-17 11:05:05 +00:00
Map is automatically updated when jumping to a given spot.
Chunks are send one by one. Packet_Chunks too big are discarded.
This commit is contained in:
1 parent
bc24c0e760
commit
c19b4fa4e6
6 files changed
+87
-18
No files matched your search
@@ -5,6 +5,7 @@ import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
|
||||
public final class CoordinatesChunk implements ISerializable {
|
||||
public final int dim, x, y, z;
|
||||
@@ -54,6 +55,10 @@ public final class CoordinatesChunk implements ISerializable {
|
||||
return String.format("%s %s %s", this.dim, this.chunkX, this.chunkZ).hashCode();
|
||||
}
|
||||
|
||||
public ChunkCoordIntPair toChunkCoordIntPair(){
|
||||
return new ChunkCoordIntPair(this.chunkX, this.chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
stream.writeInt(this.dim);
|
||||
|
||||
@@ -25,7 +25,7 @@ import cpw.mods.fml.common.registry.TickRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
@Mod(modid="Opis", name="Opis", version="0.0.1")
|
||||
@NetworkMod(channels={"Opis"},clientSideRequired=true, serverSideRequired=true, connectionHandler=OpisConnectionHandler.class, packetHandler=OpisPacketHandler.class)
|
||||
@NetworkMod(channels={"Opis", "Opis_Chunk"},clientSideRequired=true, serverSideRequired=true, connectionHandler=OpisConnectionHandler.class, packetHandler=OpisPacketHandler.class)
|
||||
|
||||
public class modOpis {
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public class OpisPacketHandler implements IPacketHandler {
|
||||
else if (header == Packets.CHUNKS){
|
||||
Packet_Chunks castedPacket = new Packet_Chunks(packet);
|
||||
Mw.instance.chunkManager.forceChunks(castedPacket.chunks);
|
||||
}
|
||||
}
|
||||
|
||||
// SERVER RECEIVED PACKETS
|
||||
else if (header == Packets.UNREGISTER_USER){
|
||||
@@ -101,6 +101,7 @@ public class OpisPacketHandler implements IPacketHandler {
|
||||
|
||||
if (!list.isEmpty())
|
||||
PacketDispatcher.sendPacketToPlayer( Packet_Chunks.create(castedPacket.dim, !world.provider.hasNoSky, list), player);
|
||||
//PacketDispatcher.sendPacketToPlayer( new Packet56MapChunks(list), player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,14 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.Level;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import mapwriter.region.MwChunk;
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.network.packet.Packet56MapChunks;
|
||||
@@ -55,19 +59,21 @@ public class Packet_Chunks {
|
||||
Packet56MapChunks chunkPacket = new Packet56MapChunks(chunks);
|
||||
|
||||
try{
|
||||
|
||||
outputStream.writeByte(Packets.CHUNKS);
|
||||
outputStream.writeInt(dim);
|
||||
outputStream.writeBoolean(hasNoSky);
|
||||
chunkPacket.writePacketData(outputStream);
|
||||
|
||||
chunkPacket.writePacketData(outputStream);
|
||||
}catch(IOException e){}
|
||||
|
||||
packet.channel = "Opis";
|
||||
packet.data = bos.toByteArray();
|
||||
packet.length = bos.size();
|
||||
|
||||
//System.out.printf("Size : %s\n", packet.length);
|
||||
if (packet.length > 32767){
|
||||
//throw new IllegalArgumentException(String.format("Payload may not be larger than 32k : %s", packet.length));
|
||||
modOpis.log.log(Level.WARNING, String.format("Payload may not be larger than 32k : %s", packet.length));
|
||||
return null;
|
||||
}
|
||||
|
||||
return packet;
|
||||
}
|
||||
@@ -156,8 +162,8 @@ public class Packet_Chunks {
|
||||
for (ExtendedBlockStorage storage : storageArrays) {
|
||||
if (storage != null) {
|
||||
int y = (storage.getYLocation() >> 4) & 0xf;
|
||||
lsbArray[y] = storage.getBlockLSBArray();
|
||||
msbArray[y] = (storage.getBlockMSBArray() != null) ? storage.getBlockMSBArray().data : null;
|
||||
lsbArray[y] = storage.getBlockLSBArray();
|
||||
msbArray[y] = (storage.getBlockMSBArray() != null) ? storage.getBlockMSBArray().data : null;
|
||||
metaArray[y] = (storage.getMetadataArray() != null) ? storage.getMetadataArray().data : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,15 @@ package mcp.mobius.opis.overlay;
|
||||
import java.awt.Point;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
import mapwriter.Mw;
|
||||
import mapwriter.api.IMwChunkOverlay;
|
||||
import mapwriter.api.IMwDataProvider;
|
||||
import mapwriter.map.MapView;
|
||||
@@ -35,9 +39,11 @@ public class OverlayLoadedChunks implements IMwDataProvider {
|
||||
public class TicketTable extends ViewTable{
|
||||
MapView mapView;
|
||||
MapMode mapMode;
|
||||
OverlayLoadedChunks overlay;
|
||||
|
||||
public TicketTable(IWidget parent) {
|
||||
public TicketTable(IWidget parent, OverlayLoadedChunks overlay) {
|
||||
super(parent);
|
||||
this.overlay = overlay;
|
||||
}
|
||||
|
||||
public void setMap(MapView mapView, MapMode mapMode){
|
||||
@@ -54,6 +60,9 @@ public class OverlayLoadedChunks implements IMwDataProvider {
|
||||
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(new CoordinatesBlock(coord)));
|
||||
}
|
||||
@@ -135,22 +144,44 @@ public class OverlayLoadedChunks implements IMwDataProvider {
|
||||
public void onMiddleClick(int dim, int bX, int bZ, MapView mapview) {
|
||||
int chunkX = bX >> 4;
|
||||
int chunkZ = bZ >> 4;
|
||||
|
||||
this.requestChunkUpdate(dim, chunkX, chunkZ);
|
||||
}
|
||||
|
||||
private void requestChunkUpdate(int dim, int chunkX, int chunkZ){
|
||||
ArrayList<CoordinatesChunk> chunks = new ArrayList<CoordinatesChunk>();
|
||||
//HashSet<ChunkCoordIntPair> chunkCoords = new HashSet<ChunkCoordIntPair>();
|
||||
|
||||
for (int x = -5; x <= 5; x++){
|
||||
for (int z = -5; z <= 5; z++){
|
||||
chunks.add(new CoordinatesChunk(dim, chunkX + x, chunkZ + z));
|
||||
if (chunks.size() >= 4){
|
||||
PacketDispatcher.sendPacketToServer(Packet_ReqChunks.create(dim, chunks));
|
||||
if (chunks.size() >= 1){
|
||||
Packet250CustomPayload packet = Packet_ReqChunks.create(dim, chunks);
|
||||
if (packet != null)
|
||||
PacketDispatcher.sendPacketToServer(packet);
|
||||
chunks.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
for (int x = -5; x <= 5; x++){
|
||||
for (int z = -5; z <= 5; z++){
|
||||
CoordinatesChunk coord = new CoordinatesChunk(dim, chunkX + x, chunkZ + z);
|
||||
chunks.add(coord);
|
||||
chunkCoords.add(coord.toChunkCoordIntPair());
|
||||
}
|
||||
}
|
||||
|
||||
if (chunks.size() > 0){
|
||||
Mw.instance.chunkManager.addForcedChunks(chunkCoords);
|
||||
PacketDispatcher.sendPacketToServer(Packet_ReqChunks.create(dim, chunks));
|
||||
}
|
||||
*/
|
||||
|
||||
if (chunks.size() > 0)
|
||||
PacketDispatcher.sendPacketToServer(Packet_ReqChunks.create(dim, chunks));
|
||||
PacketDispatcher.sendPacketToServer(Packet_ReqChunks.create(dim, chunks));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDimensionChanged(int dimension, MapView mapview) {
|
||||
PacketDispatcher.sendPacketToServer(Packet_ReqChunksInDim.create(dimension));
|
||||
@@ -202,7 +233,7 @@ public class OverlayLoadedChunks implements IMwDataProvider {
|
||||
layout.setGeometry(new WidgetGeometry(100.0,0.0,300.0,100.0,CType.RELXY, CType.REL_Y, WAlign.RIGHT, WAlign.TOP));
|
||||
layout.setBackgroundColors(0x90000000, 0x90000000);
|
||||
|
||||
TicketTable table = (TicketTable)layout.addWidget("Table_", new TicketTable(null));
|
||||
TicketTable table = (TicketTable)layout.addWidget("Table_", new TicketTable(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, WAlign.CENTER)
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.ArrayList;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
@@ -37,9 +38,11 @@ public class OverlayMeanTime implements IMwDataProvider {
|
||||
public class EntitiesTable extends ViewTable{
|
||||
MapView mapView;
|
||||
MapMode mapMode;
|
||||
OverlayMeanTime overlay;
|
||||
|
||||
public EntitiesTable(IWidget parent) {
|
||||
public EntitiesTable(IWidget parent, OverlayMeanTime overlay) {
|
||||
super(parent);
|
||||
this.overlay = overlay;
|
||||
}
|
||||
|
||||
public void setMap(MapView mapView, MapMode mapMode){
|
||||
@@ -53,8 +56,12 @@ public class OverlayMeanTime implements IMwDataProvider {
|
||||
if (row != null){
|
||||
CoordinatesBlock coord = ((TileEntityStats)row.getObject()).getCoordinates();
|
||||
|
||||
if (this.mapView.getX() != coord.x || this.mapView.getZ() != coord.z)
|
||||
if (this.mapView.getX() != coord.x || this.mapView.getZ() != coord.z){
|
||||
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));
|
||||
}
|
||||
@@ -236,7 +243,7 @@ public class OverlayMeanTime implements IMwDataProvider {
|
||||
layout.setGeometry(new WidgetGeometry(100.0,0.0,300.0,100.0,CType.RELXY, CType.REL_Y, WAlign.RIGHT, WAlign.TOP));
|
||||
layout.setBackgroundColors(0x90000000, 0x90000000);
|
||||
|
||||
EntitiesTable table = (EntitiesTable)layout.addWidget("Table_", new EntitiesTable(null));
|
||||
EntitiesTable table = (EntitiesTable)layout.addWidget("Table_", new EntitiesTable(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, WAlign.CENTER)
|
||||
@@ -263,4 +270,23 @@ public class OverlayMeanTime implements IMwDataProvider {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void requestChunkUpdate(int dim, int chunkX, int chunkZ){
|
||||
ArrayList<CoordinatesChunk> chunks = new ArrayList<CoordinatesChunk>();
|
||||
|
||||
for (int x = -5; x <= 5; x++){
|
||||
for (int z = -5; z <= 5; z++){
|
||||
chunks.add(new CoordinatesChunk(dim, chunkX + x, chunkZ + z));
|
||||
if (chunks.size() >= 1){
|
||||
Packet250CustomPayload packet = Packet_ReqChunks.create(dim, chunks);
|
||||
if (packet != null)
|
||||
PacketDispatcher.sendPacketToServer(packet);
|
||||
chunks.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (chunks.size() > 0)
|
||||
PacketDispatcher.sendPacketToServer(Packet_ReqChunks.create(dim, chunks));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user