Finished ServerPacketHandler, moved to watcher package.
Removed unused PacketConstants class.
This commit is contained in:
parent
88078bd228
commit
1e62c62924
4 changed files with 31 additions and 103 deletions
src/main/java/com/zixiken/dimdoors
|
@ -8,6 +8,7 @@ import java.io.IOException;
|
|||
import com.zixiken.dimdoors.blocks.BaseDimDoor;
|
||||
import com.zixiken.dimdoors.tileentities.TileEntityDimDoor;
|
||||
|
||||
import com.zixiken.dimdoors.watcher.ServerPacketHandler;
|
||||
import net.minecraft.block.BlockDoor;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
package com.zixiken.dimdoors;
|
||||
|
||||
public class PacketConstants
|
||||
{
|
||||
private PacketConstants() { }
|
||||
|
||||
public static final String CHANNEL_NAME = "DimDoorsPackets";
|
||||
|
||||
public static final byte CLIENT_JOIN_PACKET_ID = 1;
|
||||
public static final byte CREATE_DIM_PACKET_ID = 2;
|
||||
public static final byte DELETE_DIM_PACKET_ID = 3;
|
||||
public static final byte CREATE_LINK_PACKET_ID = 4;
|
||||
public static final byte DELETE_LINK_PACKET_ID = 5;
|
||||
public static final byte CLIENT_LOGIN_DIM_REGISTER = 6;
|
||||
public static final byte UPDATE_LINK_PACKET_ID = 7;
|
||||
|
||||
}
|
|
@ -12,81 +12,48 @@ public class Point3D implements Serializable {
|
|||
private int y;
|
||||
private int z;
|
||||
|
||||
public Point3D(int x, int y,int z)
|
||||
{
|
||||
public Point3D(int x, int y,int z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public Point3D(Point4D point)
|
||||
{
|
||||
public Point3D(Point4D point) {
|
||||
this.x = point.getX();
|
||||
this.y = point.getY();
|
||||
this.z = point.getZ();
|
||||
}
|
||||
|
||||
public int getX()
|
||||
{
|
||||
return x;
|
||||
}
|
||||
public int getX() {return x;}
|
||||
|
||||
public int getY()
|
||||
{
|
||||
return y;
|
||||
}
|
||||
public int getY() {return y;}
|
||||
|
||||
public int getZ()
|
||||
{
|
||||
return z;
|
||||
}
|
||||
public int getZ() {return z;}
|
||||
|
||||
public int setX(int x)
|
||||
{
|
||||
return this.x = x;
|
||||
}
|
||||
public int setX(int x) {return this.x = x;}
|
||||
|
||||
public int setY(int y)
|
||||
{
|
||||
return this.y = y;
|
||||
}
|
||||
public int setY(int y) {return this.y = y;}
|
||||
|
||||
public int setZ(int z)
|
||||
{
|
||||
return this.z = z;
|
||||
}
|
||||
public int setZ(int z) {return this.z = z;}
|
||||
|
||||
@Override
|
||||
public Point3D clone()
|
||||
{
|
||||
return new Point3D(x, y, z);
|
||||
}
|
||||
public Point3D clone() {return new Point3D(x, y, z);}
|
||||
|
||||
public int[] toIntArray()
|
||||
{
|
||||
return new int[]{x,y,z};
|
||||
}
|
||||
public int[] toIntArray() {return new int[]{x,y,z};}
|
||||
|
||||
public boolean equals(Point3D other)
|
||||
{
|
||||
if (other == null)
|
||||
return false;
|
||||
public boolean equals(Point3D other) {
|
||||
if (other == null) return false;
|
||||
|
||||
if (this == other)
|
||||
return true;
|
||||
if (this == other) return true;
|
||||
|
||||
return (this.x == other.x && this.y == other.y && this.z == other.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other)
|
||||
{
|
||||
return equals((Point3D) other);
|
||||
}
|
||||
public boolean equals(Object other) {return equals((Point3D) other);}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
//Time for some witchcraft.
|
||||
//The code here is inspired by a discussion on Stack Overflow regarding hash codes for 3D.
|
||||
//Source: http://stackoverflow.com/questions/9858376/hashcode-for-3d-integer-coordinates-with-high-spatial-coherence
|
||||
|
@ -95,14 +62,8 @@ public class Point3D implements Serializable {
|
|||
//For instance, points that are within the same chunk or within a few neighboring chunks. Only the low-order
|
||||
//bits of each component would differ. I'll use 8 bits from Y and the 12 bits from X and Z. ~SenseiKiwi
|
||||
|
||||
int bit;
|
||||
int hash;
|
||||
int index;
|
||||
|
||||
hash = 0;
|
||||
index = 0;
|
||||
for (bit = 0; bit < 8; bit++)
|
||||
{
|
||||
int hash = 0, index = 0, bit;
|
||||
for (bit = 0; bit < 8; bit++) {
|
||||
hash |= ((y >> bit) & 1) << index;
|
||||
index++;
|
||||
hash |= ((x >> bit) & 1) << index;
|
||||
|
@ -110,8 +71,7 @@ public class Point3D implements Serializable {
|
|||
hash |= ((z >> bit) & 1) << index;
|
||||
index++;
|
||||
}
|
||||
for (; bit < 12; bit++)
|
||||
{
|
||||
for (; bit < 12; bit++) {
|
||||
hash |= ((x >> bit) & 1) << index;
|
||||
index++;
|
||||
hash |= ((z >> bit) & 1) << index;
|
||||
|
@ -121,8 +81,5 @@ public class Point3D implements Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "(" + x + ", " + y + ", " + z + ")";
|
||||
}
|
||||
public String toString() {return "(" + x + ", " + y + ", " + z + ")";}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.zixiken.dimdoors;
|
||||
package com.zixiken.dimdoors.watcher;
|
||||
|
||||
import com.zixiken.dimdoors.network.packets.*;
|
||||
import com.zixiken.dimdoors.watcher.ClientLinkData;
|
||||
|
@ -7,53 +7,40 @@ import com.zixiken.dimdoors.watcher.ClientDimData;
|
|||
import com.zixiken.dimdoors.watcher.IUpdateWatcher;
|
||||
import com.zixiken.dimdoors.network.DimDoorsNetwork;
|
||||
|
||||
public class ServerPacketHandler
|
||||
{
|
||||
public ServerPacketHandler()
|
||||
{
|
||||
public class ServerPacketHandler {
|
||||
public ServerPacketHandler() {
|
||||
PocketManager.registerDimWatcher(new DimWatcher());
|
||||
PocketManager.registerLinkWatcher(new LinkWatcher());
|
||||
}
|
||||
|
||||
private static class DimWatcher implements IUpdateWatcher<ClientDimData>
|
||||
{
|
||||
private static class DimWatcher implements IUpdateWatcher<ClientDimData> {
|
||||
@Override
|
||||
public void onCreated(ClientDimData message)
|
||||
{
|
||||
public void onCreated(ClientDimData message) {
|
||||
DimDoorsNetwork.sendToAllPlayers(new CreateDimensionPacket(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeleted(ClientDimData message)
|
||||
{
|
||||
public void onDeleted(ClientDimData message) {
|
||||
DimDoorsNetwork.sendToAllPlayers(new DeleteDimensionPacket(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(ClientDimData message)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
public void update(ClientDimData message) {}
|
||||
}
|
||||
|
||||
private static class LinkWatcher implements IUpdateWatcher<ClientLinkData>
|
||||
{
|
||||
private static class LinkWatcher implements IUpdateWatcher<ClientLinkData> {
|
||||
@Override
|
||||
public void onCreated(ClientLinkData message)
|
||||
{
|
||||
public void onCreated(ClientLinkData message) {
|
||||
DimDoorsNetwork.sendToAllPlayers(new CreateLinkPacket(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeleted(ClientLinkData message)
|
||||
{
|
||||
public void onDeleted(ClientLinkData message) {
|
||||
DimDoorsNetwork.sendToAllPlayers(new DeleteLinkPacket(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(ClientLinkData message)
|
||||
{
|
||||
public void update(ClientLinkData message) {
|
||||
DimDoorsNetwork.sendToAllPlayers(new UpdateLinkPacket(message));
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue