Improved video channel synchronisation
This commit is contained in:
parent
7c47ab1423
commit
0a3a780f21
4 changed files with 59 additions and 5 deletions
|
@ -4,6 +4,9 @@ import li.cil.oc.api.machine.Arguments;
|
|||
import li.cil.oc.api.machine.Callback;
|
||||
import li.cil.oc.api.machine.Context;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.ChunkPosition;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
|
@ -23,11 +26,12 @@ public class TileEntityCamera extends TileEntityAbstractInterfaced implements IV
|
|||
private final static int REGISTRY_UPDATE_INTERVAL_TICKS = 15 * 20;
|
||||
private final static int PACKET_SEND_INTERVAL_TICKS = 60 * 20;
|
||||
|
||||
private int packetSendTicks = 10;
|
||||
private int registryUpdateTicks = 20;
|
||||
private int packetSendTicks = 20;
|
||||
|
||||
public TileEntityCamera() {
|
||||
super();
|
||||
|
||||
peripheralName = "warpdriveCamera";
|
||||
addMethods(new String[] {
|
||||
"videoChannel"
|
||||
|
@ -140,6 +144,19 @@ public class TileEntityCamera extends TileEntityAbstractInterfaced implements IV
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||
writeToNBT(tagCompound);
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager networkManager, S35PacketUpdateTileEntity packet) {
|
||||
NBTTagCompound tagCompound = packet.func_148857_g();
|
||||
readFromNBT(tagCompound);
|
||||
}
|
||||
|
||||
// OpenComputer callback methods
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
|
|
|
@ -4,6 +4,9 @@ import li.cil.oc.api.machine.Arguments;
|
|||
import li.cil.oc.api.machine.Callback;
|
||||
import li.cil.oc.api.machine.Context;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
|
@ -19,7 +22,7 @@ public class TileEntityMonitor extends TileEntityAbstractInterfaced implements I
|
|||
private int videoChannel = -1;
|
||||
|
||||
private final static int PACKET_SEND_INTERVAL_TICKS = 60 * 20;
|
||||
private int packetSendTicks = 20;
|
||||
private int packetSendTicks = 10;
|
||||
|
||||
public TileEntityMonitor() {
|
||||
super();
|
||||
|
@ -103,6 +106,19 @@ public class TileEntityMonitor extends TileEntityAbstractInterfaced implements I
|
|||
tag.setInteger("videoChannel", videoChannel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||
writeToNBT(tagCompound);
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager networkManager, S35PacketUpdateTileEntity packet) {
|
||||
NBTTagCompound tagCompound = packet.func_148857_g();
|
||||
readFromNBT(tagCompound);
|
||||
}
|
||||
|
||||
// OpenComputer callback methods
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
|
|
|
@ -180,8 +180,8 @@ public class TileEntityIC2reactorLaserMonitor extends TileEntityAbstractEnergy {
|
|||
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager networkManager, S35PacketUpdateTileEntity packet) {
|
||||
NBTTagCompound tag = packet.func_148857_g();
|
||||
readFromNBT(tag);
|
||||
NBTTagCompound tagCompound = packet.func_148857_g();
|
||||
readFromNBT(tagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,6 +4,9 @@ import li.cil.oc.api.machine.Arguments;
|
|||
import li.cil.oc.api.machine.Callback;
|
||||
import li.cil.oc.api.machine.Context;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.ChunkPosition;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
|
@ -23,8 +26,8 @@ public class TileEntityLaserCamera extends TileEntityLaser implements IVideoChan
|
|||
private final static int REGISTRY_UPDATE_INTERVAL_TICKS = 15 * 20;
|
||||
private final static int PACKET_SEND_INTERVAL_TICKS = 60 * 20;
|
||||
|
||||
private int packetSendTicks = 10;
|
||||
private int registryUpdateTicks = 20;
|
||||
private int packetSendTicks = 20;
|
||||
|
||||
public TileEntityLaserCamera() {
|
||||
super();
|
||||
|
@ -50,6 +53,9 @@ public class TileEntityLaserCamera extends TileEntityLaser implements IVideoChan
|
|||
registryUpdateTicks--;
|
||||
if (registryUpdateTicks <= 0) {
|
||||
registryUpdateTicks = REGISTRY_UPDATE_INTERVAL_TICKS;
|
||||
if (WarpDriveConfig.LOGGING_VIDEO_CHANNEL) {
|
||||
WarpDrive.logger.info(this + " Updating registry (" + videoChannel + ")");
|
||||
}
|
||||
WarpDrive.instance.cameras.updateInRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord), videoChannel, CameraType.LASER_CAMERA);
|
||||
}
|
||||
}
|
||||
|
@ -115,6 +121,21 @@ public class TileEntityLaserCamera extends TileEntityLaser implements IVideoChan
|
|||
tag.setInteger("videoChannel", videoChannel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||
// (beam frequency is server side only)
|
||||
tagCompound.setInteger("videoChannel", videoChannel);
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager networkManager, S35PacketUpdateTileEntity packet) {
|
||||
NBTTagCompound tagCompound = packet.func_148857_g();
|
||||
// (beam frequency is server side only)
|
||||
setVideoChannel(tagCompound.getInteger("videoChannel"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
WarpDrive.instance.cameras.removeFromRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord));
|
||||
|
|
Loading…
Reference in a new issue