Small optimisations to Camera registry, etc.
Updated monitor to only work with an empty hand Removed useless calls to invalidate (Forge already do it) Fixed Camera & LaserCamera not always removed from registry Improved server & network load when updating Camera & LaserCamera registration Updated debug logs to state client/server side
This commit is contained in:
parent
147f4f4ebc
commit
f2921db45c
13 changed files with 54 additions and 95 deletions
|
@ -148,7 +148,7 @@ public class WarpDrive implements LoadingCallback {
|
|||
return;
|
||||
}
|
||||
if (WarpDriveConfig.debugMode) {
|
||||
System.out.println(out);
|
||||
System.out.println((FMLCommonHandler.instance().getEffectiveSide().isClient() ? "Client ":"Server ") + out);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -97,14 +97,4 @@ public class BlockAirGenerator extends BlockContainer
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) {
|
||||
TileEntity te = par1World.getBlockTileEntity(par2, par3, par4);
|
||||
if (te != null) {
|
||||
te.invalidate();
|
||||
}
|
||||
|
||||
super.breakBlock(par1World, par2, par3, par4, par5, par6);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ public class BlockCamera extends BlockContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World var1) {
|
||||
public TileEntity createNewTileEntity(World parWorld) {
|
||||
return new TileEntityCamera();
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ public class BlockCamera extends BlockContainer {
|
|||
* Returns the ID of the items to drop on destruction.
|
||||
*/
|
||||
@Override
|
||||
public int idDropped(int par1, Random par2Random, int par3) {
|
||||
public int idDropped(int par1, Random par2Random, int par3) {
|
||||
return this.blockID;
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ public class BlockCamera extends BlockContainer {
|
|||
|
||||
// Get camera frequency
|
||||
TileEntity te = par1World.getBlockTileEntity(x, y, z);
|
||||
if (te != null && te instanceof TileEntityCamera) {
|
||||
if (te != null && te instanceof TileEntityCamera && (par5EntityPlayer.getHeldItem() == null)) {
|
||||
int frequency = ((TileEntityCamera)te).getFrequency();
|
||||
|
||||
CamRegistryItem cam = WarpDrive.instance.cams.getCamByFrequency(par1World, frequency);
|
||||
|
|
|
@ -64,14 +64,4 @@ public class BlockCloakingCoil extends Block {
|
|||
public int idDropped(int par1, Random par2Random, int par3) {
|
||||
return this.blockID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) {
|
||||
TileEntity te = par1World.getBlockTileEntity(par2, par3, par4);
|
||||
if (te != null) {
|
||||
te.invalidate();
|
||||
}
|
||||
|
||||
super.breakBlock(par1World, par2, par3, par4, par5, par6);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,8 +91,6 @@ public class BlockCloakingDeviceCore extends BlockContainer {
|
|||
if (te != null && te instanceof TileEntityCloakingDeviceCore) {
|
||||
((TileEntityCloakingDeviceCore)te).isEnabled = false;
|
||||
((TileEntityCloakingDeviceCore)te).disableCloakingField();
|
||||
|
||||
te.invalidate();
|
||||
}
|
||||
|
||||
super.breakBlock(par1World, par2, par3, par4, par5, par6);
|
||||
|
|
|
@ -96,12 +96,4 @@ public class BlockLift extends BlockContainer
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) {
|
||||
TileEntity te = par1World.getBlockTileEntity(par2, par3, par4);
|
||||
if (te != null) {
|
||||
te.invalidate();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -75,7 +75,6 @@ public class BlockMonitor extends BlockContainer {
|
|||
|
||||
if (te != null && te instanceof TileEntityMonitor && (par5EntityPlayer.getHeldItem() == null)) {
|
||||
int frequency = ((TileEntityMonitor)te).getFrequency();
|
||||
WarpDrive.instance.cams.removeDeadCams(par1World);
|
||||
CamRegistryItem cam = WarpDrive.instance.cams.getCamByFrequency(par1World, frequency);
|
||||
if (cam == null) {
|
||||
par5EntityPlayer.addChatMessage(getLocalizedName() + " Frequency '" + frequency + "' is invalid or camera is too far!");
|
||||
|
|
|
@ -92,14 +92,4 @@ public class BlockParticleBooster extends BlockContainer {
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) {
|
||||
TileEntity te = par1World.getBlockTileEntity(par2, par3, par4);
|
||||
if (te != null) {
|
||||
te.invalidate();
|
||||
}
|
||||
|
||||
super.breakBlock(par1World, par2, par3, par4, par5, par6);
|
||||
}
|
||||
}
|
|
@ -99,14 +99,4 @@ public class BlockRadar extends BlockContainer
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) {
|
||||
TileEntity te = par1World.getBlockTileEntity(par2, par3, par4);
|
||||
if (te != null) {
|
||||
te.invalidate();
|
||||
}
|
||||
|
||||
super.breakBlock(par1World, par2, par3, par4, par5, par6);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,7 +104,6 @@ public class BlockReactor extends BlockContainer {
|
|||
TileEntity te = par1World.getBlockTileEntity(par2, par3, par4);
|
||||
if (te != null && te instanceof TileEntityReactor) {
|
||||
WarpDrive.instance.warpCores.removeFromRegistry((TileEntityReactor)te);
|
||||
te.invalidate();
|
||||
}
|
||||
|
||||
WarpDrive.instance.warpCores.removeDeadCores();
|
||||
|
|
|
@ -85,12 +85,4 @@ public class BlockShipScanner extends BlockContainer {
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) {
|
||||
TileEntity te = par1World.getBlockTileEntity(par2, par3, par4);
|
||||
if (te != null) {
|
||||
te.invalidate();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,27 +25,27 @@ public class TileEntityCamera extends TileEntity implements IPeripheral {
|
|||
"freq"
|
||||
};
|
||||
|
||||
private final int REGISTRY_UPDATE_INTERVAL_SEC = 10;
|
||||
private int ticks = 0;
|
||||
private final static int REGISTRY_UPDATE_INTERVAL_TICKS = 10 * 20;
|
||||
private final static int PACKET_SEND_INTERVAL_TICKS = 60 * 20;
|
||||
|
||||
private int registryUpdateTicks = 20;
|
||||
private int packetSendTicks = 20;
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
// Update frequency on clients
|
||||
// Update frequency on clients (recovery mechanism, no need to go too fast)
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
|
||||
packetSendTicks--;
|
||||
if (packetSendTicks == 0) {
|
||||
packetSendTicks = 20 * 5;
|
||||
if (packetSendTicks <= 0) {
|
||||
packetSendTicks = PACKET_SEND_INTERVAL_TICKS;
|
||||
sendFreqPacket();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
ticks++;
|
||||
if (ticks > 20 * REGISTRY_UPDATE_INTERVAL_SEC) {
|
||||
ticks = 0;
|
||||
WarpDrive.instance.cams.updateInRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord), frequency, 0);
|
||||
} else {
|
||||
registryUpdateTicks--;
|
||||
if (registryUpdateTicks <= 0) {
|
||||
registryUpdateTicks = REGISTRY_UPDATE_INTERVAL_TICKS;
|
||||
WarpDrive.instance.cams.updateInRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord), frequency, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,8 +57,15 @@ public class TileEntityCamera extends TileEntity implements IPeripheral {
|
|||
if (frequency != parFrequency) {
|
||||
frequency = parFrequency;
|
||||
WarpDrive.debugPrint("" + this + " Frequency set to " + frequency);
|
||||
WarpDrive.instance.cams.updateInRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord), frequency, 0);
|
||||
sendFreqPacket();
|
||||
}
|
||||
WarpDrive.instance.cams.updateInRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord), frequency, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
WarpDrive.instance.cams.removeFromRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord));
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -33,8 +33,8 @@ public class TileEntityLaser extends WarpTE implements IPeripheral {
|
|||
private int dx, dz, dy;
|
||||
public float yaw, pitch; // laser direction
|
||||
|
||||
private int beamFrequency = -1; // beam frequency
|
||||
private int cameraFrequency = -1; // camera frequency
|
||||
private int beamFrequency = -1;
|
||||
private int cameraFrequency = -1;
|
||||
private float r, g, b; // beam color (corresponds to frequency)
|
||||
|
||||
public boolean isEmitting = false;
|
||||
|
@ -54,22 +54,28 @@ public class TileEntityLaser extends WarpTE implements IPeripheral {
|
|||
|
||||
private MovingObjectPosition firstHit = null;
|
||||
|
||||
private int camUpdateTicks = 20;
|
||||
private int registryUpdateTicks = 20 * 10;
|
||||
private final static int REGISTRY_UPDATE_INTERVAL_TICKS = 10 * 20;
|
||||
private final static int PACKET_SEND_INTERVAL_TICKS = 60 * 20;
|
||||
|
||||
private int registryUpdateTicks = 20;
|
||||
private int packetSendTicks = 20;
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
if (isWithCamera()) {
|
||||
registryUpdateTicks--;
|
||||
if (registryUpdateTicks == 0 && FMLCommonHandler.instance().getEffectiveSide().isClient()) {
|
||||
registryUpdateTicks = 20 * 10;
|
||||
WarpDrive.instance.cams.updateInRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord), cameraFrequency, 1);
|
||||
}
|
||||
|
||||
camUpdateTicks--;
|
||||
if (camUpdateTicks == 0) {
|
||||
camUpdateTicks = 20 * 5; // 5 seconds
|
||||
sendFreqPacket(); // send own cam frequency to clients
|
||||
// Update frequency on clients (recovery mechanism, no need to go too fast)
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
|
||||
packetSendTicks--;
|
||||
if (packetSendTicks <= 0) {
|
||||
packetSendTicks = PACKET_SEND_INTERVAL_TICKS;
|
||||
sendFreqPacket();
|
||||
}
|
||||
} else {
|
||||
registryUpdateTicks--;
|
||||
if (registryUpdateTicks <= 0) {
|
||||
registryUpdateTicks = REGISTRY_UPDATE_INTERVAL_TICKS;
|
||||
WarpDrive.instance.cams.updateInRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord), cameraFrequency, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -438,6 +444,12 @@ public class TileEntityLaser extends WarpTE implements IPeripheral {
|
|||
tag.setInteger("cameraFrequency", cameraFrequency);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
WarpDrive.instance.cams.removeFromRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord));
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload() {
|
||||
WarpDrive.instance.cams.removeFromRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord));
|
||||
|
|
Loading…
Reference in a new issue