Fixed video channel handling

Splitted laser from laser+cam
Added self-upgrader
Fixed client/server mixup regression
Code cleanup
This commit is contained in:
LemADEC 2016-01-15 04:56:07 +01:00
parent 505d30d706
commit d49bb546f9
13 changed files with 288 additions and 162 deletions

View file

@ -90,6 +90,7 @@ import cr0s.warpdrive.block.passive.BlockIridium;
import cr0s.warpdrive.block.passive.BlockTransportBeacon;
import cr0s.warpdrive.block.passive.ItemBlockDecorative;
import cr0s.warpdrive.block.weapon.BlockLaserCamera;
import cr0s.warpdrive.block.weapon.TileEntityLaserCamera;
import cr0s.warpdrive.command.CommandDebug;
import cr0s.warpdrive.command.CommandGenerate;
import cr0s.warpdrive.command.CommandInvisible;
@ -269,6 +270,7 @@ public class WarpDrive implements LoadingCallback {
blockLaserCamera = new BlockLaserCamera();
GameRegistry.registerBlock(blockLaserCamera, "blockLaserCamera");
GameRegistry.registerTileEntity(TileEntityLaserCamera.class, MODID + ":blockLaserCamera");
// CAMERA
blockCamera = new BlockCamera();

View file

@ -21,29 +21,29 @@ import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.StatCollector;
import net.minecraft.util.Vec3;
import net.minecraft.world.ChunkPosition;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Optional;
import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.api.IBeamFrequency;
import cr0s.warpdrive.api.IVideoChannel;
import cr0s.warpdrive.block.weapon.BlockLaserCamera;
import cr0s.warpdrive.block.weapon.TileEntityLaserCamera;
import cr0s.warpdrive.config.Dictionary;
import cr0s.warpdrive.config.WarpDriveConfig;
import cr0s.warpdrive.data.CameraRegistryItem;
import cr0s.warpdrive.data.Vector3;
import cr0s.warpdrive.data.VectorI;
import cr0s.warpdrive.network.PacketHandler;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IComputerAccess;
public class TileEntityLaser extends TileEntityAbstractLaser implements IBeamFrequency, IVideoChannel {
public class TileEntityLaser extends TileEntityAbstractLaser implements IBeamFrequency {
private final int BEAM_FREQUENCY_SCANNING = 1420;
private final int BEAM_FREQUENCY_MAX = 65000;
private int legacyVideoChannel = -1;
private boolean legacyCheck = !(this instanceof TileEntityLaserCamera);
private float yaw, pitch; // laser direction
private int beamFrequency = -1;
private int videoChannel = -1;
protected int beamFrequency = -1;
private float r, g, b; // beam color (corresponds to frequency)
public boolean isEmitting = false;
@ -66,12 +66,6 @@ public class TileEntityLaser extends TileEntityAbstractLaser implements IBeamFre
private int scanResult_blockMetadata = 0;
private float scanResult_blockResistance = -2;
private final static int REGISTRY_UPDATE_INTERVAL_TICKS = 15 * 20;
private final static int PACKET_SEND_INTERVAL_TICKS = 60 * 20;
private int registryUpdateTicks = 20;
private int packetSendTicks = 20;
public TileEntityLaser() {
super();
@ -79,8 +73,7 @@ public class TileEntityLaser extends TileEntityAbstractLaser implements IBeamFre
addMethods(new String[] {
"emitBeam",
"beamFrequency",
"getScanResult",
"videoChannel"
"getScanResult"
});
laserMediumMaxCount = WarpDriveConfig.LASER_CANNON_MAX_MEDIUMS_COUNT;
}
@ -89,21 +82,26 @@ public class TileEntityLaser extends TileEntityAbstractLaser implements IBeamFre
public void updateEntity() {
super.updateEntity();
if (isWithCamera()) {
// Update video channel on clients (recovery mechanism, no need to go too fast)
if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
packetSendTicks--;
if (packetSendTicks <= 0) {
packetSendTicks = PACKET_SEND_INTERVAL_TICKS;
PacketHandler.sendVideoChannelPacket(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, videoChannel);
}
} else {
registryUpdateTicks--;
if (registryUpdateTicks <= 0) {
registryUpdateTicks = REGISTRY_UPDATE_INTERVAL_TICKS;
WarpDrive.instance.cameras.updateInRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord), videoChannel, 1);
// Legacy tile entity
if (legacyCheck) {
if (worldObj.getBlock(xCoord, yCoord, zCoord) instanceof BlockLaserCamera) {
try {
WarpDrive.logger.info("Self-upgrading legacy tile entity " + this);
NBTTagCompound oldnbt = new NBTTagCompound();
writeToNBT(oldnbt);
TileEntityLaserCamera newTileEntity = new TileEntityLaserCamera(); // id has changed, we can't directly call createAndLoadEntity
newTileEntity.readFromNBT(oldnbt);
newTileEntity.setWorldObj(worldObj);
newTileEntity.validate();
invalidate();
worldObj.removeTileEntity(xCoord, yCoord, zCoord);
worldObj.setTileEntity(xCoord, yCoord, zCoord, newTileEntity);
newTileEntity.setVideoChannel(legacyVideoChannel);
} catch (Exception exception) {
exception.printStackTrace();
}
}
legacyCheck = false;
}
// Frequency is not set
@ -398,10 +396,6 @@ public class TileEntityLaser extends TileEntityAbstractLaser implements IBeamFre
return new TreeMap(entityHits);
}
public boolean isWithCamera() {
return (getBlockType().isAssociatedBlock(WarpDrive.blockLaserCamera));
}
@Override
public int getBeamFrequency() {
return beamFrequency;
@ -428,60 +422,10 @@ public class TileEntityLaser extends TileEntityAbstractLaser implements IBeamFre
}
}
@Override
public int getVideoChannel() {
return videoChannel;
}
@Override
public void setVideoChannel(int parVideoChannel) {
if (videoChannel != parVideoChannel) {
if (WarpDriveConfig.LOGGING_VIDEO_CHANNEL) {
WarpDrive.logger.info(this + " Video channel updated from " + videoChannel + " to " + parVideoChannel);
}
videoChannel = parVideoChannel;
// force update through main thread since CC runs on server as 'client'
packetSendTicks = 0;
registryUpdateTicks = 0;
}
}
public String getVideoChannelStatus() {
if (!isWithCamera()) {
return "";
}
if (videoChannel < 0) {
return StatCollector.translateToLocalFormatted("warpdrive.videoChannel.statusLine.invalid",
videoChannel );
} else {
CameraRegistryItem camera = WarpDrive.instance.cameras.getCameraByVideoChannel(worldObj, videoChannel);
if (camera == null) {
WarpDrive.instance.cameras.printRegistry(worldObj);
return StatCollector.translateToLocalFormatted("warpdrive.videoChannel.statusLine.invalid",
videoChannel );
} else if (camera.isTileEntity(this)) {
return StatCollector.translateToLocalFormatted("warpdrive.videoChannel.statusLine.valid",
videoChannel );
} else {
return StatCollector.translateToLocalFormatted("warpdrive.videoChannel.statusLine.validCamera",
videoChannel,
camera.position.chunkPosX,
camera.position.chunkPosY,
camera.position.chunkPosZ );
}
}
}
public String getStatus() {
if (!isWithCamera()) {
return StatCollector.translateToLocalFormatted("warpdrive.guide.prefix",
getBlockType().getLocalizedName())
+ getBeamFrequencyStatus();
} else {
return StatCollector.translateToLocalFormatted("warpdrive.guide.prefix",
getBlockType().getLocalizedName())
+ getBeamFrequencyStatus() + "\n" + getVideoChannelStatus();
}
return StatCollector.translateToLocalFormatted("warpdrive.guide.prefix",
getBlockType().getLocalizedName())
+ getBeamFrequencyStatus();
}
private void playSoundCorrespondsEnergy(int energy) {
@ -539,25 +483,22 @@ public class TileEntityLaser extends TileEntityAbstractLaser implements IBeamFre
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
setBeamFrequency(tag.getInteger("beamFrequency"));
setVideoChannel(tag.getInteger("cameraFrequency") + tag.getInteger("videoChannel"));
legacyVideoChannel = tag.getInteger("cameraFrequency") + tag.getInteger("videoChannel");
}
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
tag.setInteger("beamFrequency", beamFrequency);
tag.setInteger("videoChannel", videoChannel);
}
@Override
public void invalidate() {
WarpDrive.instance.cameras.removeFromRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord));
super.invalidate();
}
@Override
public void onChunkUnload() {
WarpDrive.instance.cameras.removeFromRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord));
super.onChunkUnload();
}
@ -583,18 +524,6 @@ public class TileEntityLaser extends TileEntityAbstractLaser implements IBeamFre
return getScanResult();
}
@Callback
@Optional.Method(modid = "OpenComputers")
public Object[] videoChannel(Context context, Arguments arguments) {
if (isWithCamera()) {
if (arguments.count() == 1) {
setVideoChannel(arguments.checkInteger(0));
}
return new Integer[] { videoChannel };
}
return null;
}
private Object[] emitBeam(Object[] arguments) {
try {
float newYaw, newPitch;
@ -660,15 +589,6 @@ public class TileEntityLaser extends TileEntityAbstractLaser implements IBeamFre
} else if (methodName.equals("getScanResult")) {
return getScanResult();
} else if (methodName.equals("videoChannel")) {
// Only valid for lasers with camera
if (isWithCamera()) {
if (arguments.length == 1) {
setVideoChannel(toInt(arguments[0]));
}
return new Integer[] { videoChannel };
}
return null;
}
return super.callMethod(computer, context, method, arguments);
@ -676,7 +596,7 @@ public class TileEntityLaser extends TileEntityAbstractLaser implements IBeamFre
@Override
public String toString() {
return String.format("%s Beam \'%d\' Camera \'%d\' @ \'%s\' %d, %d, %d", new Object[] { getClass().getSimpleName(),
beamFrequency, videoChannel, worldObj == null ? "~NULL~" : worldObj.getWorldInfo().getWorldName(), xCoord, yCoord, zCoord });
return String.format("%s Beam \'%d\' @ \'%s\' %d, %d, %d", new Object[] { getClass().getSimpleName(),
beamFrequency, worldObj == null ? "~NULL~" : worldObj.getWorldInfo().getWorldName(), xCoord, yCoord, zCoord });
}
}

View file

@ -55,7 +55,7 @@ public class BlockCamera extends BlockContainer {
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) {
if (world.isRemote) {
if (!world.isRemote) {
return false;
}

View file

@ -12,6 +12,7 @@ import cr0s.warpdrive.api.IVideoChannel;
import cr0s.warpdrive.block.TileEntityAbstractInterfaced;
import cr0s.warpdrive.config.WarpDriveConfig;
import cr0s.warpdrive.data.CameraRegistryItem;
import cr0s.warpdrive.data.CameraType;
import cr0s.warpdrive.network.PacketHandler;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IComputerAccess;
@ -51,7 +52,7 @@ public class TileEntityCamera extends TileEntityAbstractInterfaced implements IV
if (WarpDriveConfig.LOGGING_VIDEO_CHANNEL) {
WarpDrive.logger.info(this + " Updating registry (" + videoChannel + ")");
}
WarpDrive.instance.cameras.updateInRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord), videoChannel, 0);
WarpDrive.instance.cameras.updateInRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord), videoChannel, CameraType.SIMPLE_CAMERA);
}
}
}
@ -167,10 +168,10 @@ public class TileEntityCamera extends TileEntityAbstractInterfaced implements IV
@Override
public String toString() {
return String.format("%s \'%d\' @ \'%s\' %d, %d, %d", new Object[] {
return String.format("%s %d @ \'%s\' %d, %d, %d",
getClass().getSimpleName(),
videoChannel,
worldObj == null ? "~NULL~" : worldObj.getWorldInfo().getWorldName(),
xCoord, yCoord, zCoord});
xCoord, yCoord, zCoord);
}
}

View file

@ -8,10 +8,10 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.block.BlockAbstractContainer;
import cr0s.warpdrive.block.TileEntityLaser;
import cr0s.warpdrive.render.ClientCameraHandler;
public class BlockLaserCamera extends BlockAbstractContainer {
@ -38,7 +38,7 @@ public class BlockLaserCamera extends BlockAbstractContainer {
@Override
public TileEntity createNewTileEntity(World parWorld, int i) {
return new TileEntityLaser();
return new TileEntityLaserCamera();
}
/**
@ -68,8 +68,14 @@ public class BlockLaserCamera extends BlockAbstractContainer {
if (entityPlayer.getHeldItem() == null) {
TileEntity tileEntity = world.getTileEntity(x, y, z);
if (tileEntity instanceof TileEntityLaser && !ClientCameraHandler.isOverlayEnabled) {
WarpDrive.addChatMessage(entityPlayer, ((TileEntityLaser) tileEntity).getStatus());
if (!ClientCameraHandler.isOverlayEnabled) {
if (tileEntity instanceof TileEntityLaserCamera) {
WarpDrive.addChatMessage(entityPlayer, ((TileEntityLaserCamera) tileEntity).getStatus());
} else {
WarpDrive.addChatMessage(entityPlayer, StatCollector.translateToLocalFormatted("warpdrive.guide.prefix",
getLocalizedName()) + StatCollector.translateToLocalFormatted("warpdrive.error.badTileEntity"));
WarpDrive.logger.error("Block " + this + " with invalid tile entity " + tileEntity);
}
return true;
}
}

View file

@ -0,0 +1,162 @@
package cr0s.warpdrive.block.weapon;
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.util.StatCollector;
import net.minecraft.world.ChunkPosition;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Optional;
import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.api.IVideoChannel;
import cr0s.warpdrive.block.TileEntityLaser;
import cr0s.warpdrive.config.WarpDriveConfig;
import cr0s.warpdrive.data.CameraRegistryItem;
import cr0s.warpdrive.data.CameraType;
import cr0s.warpdrive.network.PacketHandler;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IComputerAccess;
public class TileEntityLaserCamera extends TileEntityLaser implements IVideoChannel {
private int videoChannel = -1;
private final static int REGISTRY_UPDATE_INTERVAL_TICKS = 15 * 20;
private final static int PACKET_SEND_INTERVAL_TICKS = 60 * 20;
private int registryUpdateTicks = 20;
private int packetSendTicks = 20;
public TileEntityLaserCamera() {
super();
peripheralName = "warpdriveLaserCamera";
addMethods(new String[] {
"videoChannel"
});
}
@Override
public void updateEntity() {
super.updateEntity();
// Update video channel on clients (recovery mechanism, no need to go too fast)
if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
packetSendTicks--;
if (packetSendTicks <= 0) {
packetSendTicks = PACKET_SEND_INTERVAL_TICKS;
PacketHandler.sendVideoChannelPacket(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, videoChannel);
}
} else {
registryUpdateTicks--;
if (registryUpdateTicks <= 0) {
registryUpdateTicks = REGISTRY_UPDATE_INTERVAL_TICKS;
WarpDrive.instance.cameras.updateInRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord), videoChannel, CameraType.LASER_CAMERA);
}
}
}
@Override
public int getVideoChannel() {
return videoChannel;
}
@Override
public void setVideoChannel(int parVideoChannel) {
if (videoChannel != parVideoChannel) {
if (WarpDriveConfig.LOGGING_VIDEO_CHANNEL) {
WarpDrive.logger.info(this + " Video channel updated from " + videoChannel + " to " + parVideoChannel);
}
videoChannel = parVideoChannel;
// force update through main thread since CC runs on server as 'client'
packetSendTicks = 0;
registryUpdateTicks = 0;
}
}
public String getVideoChannelStatus() {
if (videoChannel < 0) {
return StatCollector.translateToLocalFormatted("warpdrive.videoChannel.statusLine.invalid",
videoChannel );
} else {
CameraRegistryItem camera = WarpDrive.instance.cameras.getCameraByVideoChannel(worldObj, videoChannel);
if (camera == null) {
WarpDrive.instance.cameras.printRegistry(worldObj);
return StatCollector.translateToLocalFormatted("warpdrive.videoChannel.statusLine.invalid",
videoChannel );
} else if (camera.isTileEntity(this)) {
return StatCollector.translateToLocalFormatted("warpdrive.videoChannel.statusLine.valid",
videoChannel );
} else {
return StatCollector.translateToLocalFormatted("warpdrive.videoChannel.statusLine.validCamera",
videoChannel,
camera.position.chunkPosX,
camera.position.chunkPosY,
camera.position.chunkPosZ );
}
}
}
@Override
public String getStatus() {
return StatCollector.translateToLocalFormatted("warpdrive.guide.prefix",
getBlockType().getLocalizedName())
+ getBeamFrequencyStatus() + "\n" + getVideoChannelStatus();
}
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
setVideoChannel(tag.getInteger("cameraFrequency") + tag.getInteger("videoChannel"));
}
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
tag.setInteger("videoChannel", videoChannel);
}
@Override
public void invalidate() {
WarpDrive.instance.cameras.removeFromRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord));
super.invalidate();
}
@Override
public void onChunkUnload() {
WarpDrive.instance.cameras.removeFromRegistry(worldObj, new ChunkPosition(xCoord, yCoord, zCoord));
super.onChunkUnload();
}
// OpenComputer callback methods
@Callback
@Optional.Method(modid = "OpenComputers")
public Object[] videoChannel(Context context, Arguments arguments) {
if (arguments.count() == 1) {
setVideoChannel(arguments.checkInteger(0));
}
return new Integer[] { videoChannel };
}
// ComputerCraft IPeripheral methods implementation
@Override
@Optional.Method(modid = "ComputerCraft")
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) {
String methodName = getMethodName(method);
if (methodName.equals("videoChannel")) {
if (arguments.length == 1) {
setVideoChannel(toInt(arguments[0]));
}
return new Integer[] { videoChannel };
}
return super.callMethod(computer, context, method, arguments);
}
@Override
public String toString() {
return String.format("%s Beam \'%d\' Camera \'%d\' @ \'%s\' %d, %d, %d", new Object[] { getClass().getSimpleName(),
beamFrequency, videoChannel, worldObj == null ? "~NULL~" : worldObj.getWorldInfo().getWorldName(), xCoord, yCoord, zCoord });
}
}

View file

@ -359,7 +359,7 @@ public class WarpDriveConfig {
if (WarpDrive.isDev) {// disabled in production, for obvious reasons :)
LOGGING_EFFECTS = config.get("logging", "enable_effects_logs", LOGGING_EFFECTS, "Detailled effects logs to help debug the mod, will spam your console!").getBoolean(false);
LOGGING_CLOAKING = config.get("logging", "enable_cloaking_logs", LOGGING_CLOAKING, "Detailled cloaking logs to help debug the mod, will spam your console!").getBoolean(false);
LOGGING_VIDEO_CHANNEL = config.get("logging", "enable_frequency_logs", LOGGING_VIDEO_CHANNEL, "Detailled video channel logs to help debug the mod, will spam your console!").getBoolean(false);
LOGGING_VIDEO_CHANNEL = config.get("logging", "enable_videoChannel_logs", LOGGING_VIDEO_CHANNEL, "Detailled video channel logs to help debug the mod, will spam your console!").getBoolean(false);
LOGGING_TARGETTING = config.get("logging", "enable_targetting_logs", LOGGING_TARGETTING, "Detailled targetting logs to help debug the mod, will spam your console!").getBoolean(false);
} else {
LOGGING_EFFECTS = false;

View file

@ -6,25 +6,25 @@ import net.minecraft.world.ChunkPosition;
import net.minecraft.world.World;
public class CameraRegistryItem {
public int dimensionId = -666;
public ChunkPosition position = null;
public int videoChannel = -1;
public int type = 0; // 0 - basic camera, 1 - laser camera
public CameraRegistryItem(World parWorldObj, ChunkPosition parPosition, int parFrequency, int parType) {
videoChannel = parFrequency;
position = parPosition;
dimensionId = parWorldObj.provider.dimensionId;
type = parType;
}
public boolean isTileEntity(TileEntity tileEntity) {
return tileEntity != null
&& tileEntity instanceof IVideoChannel
&& dimensionId == tileEntity.getWorldObj().provider.dimensionId
&& position.chunkPosX == tileEntity.xCoord
&& position.chunkPosY == tileEntity.yCoord
&& position.chunkPosZ == tileEntity.zCoord
&& videoChannel == ((IVideoChannel)tileEntity).getVideoChannel();
}
public int dimensionId = -666;
public ChunkPosition position = null;
public int videoChannel = -1;
public CameraType type = null;
public CameraRegistryItem(World parWorldObj, ChunkPosition parPosition, int parFrequency, CameraType parType) {
videoChannel = parFrequency;
position = parPosition;
dimensionId = parWorldObj.provider.dimensionId;
type = parType;
}
public boolean isTileEntity(TileEntity tileEntity) {
return tileEntity != null
&& tileEntity instanceof IVideoChannel
&& dimensionId == tileEntity.getWorldObj().provider.dimensionId
&& position.chunkPosX == tileEntity.xCoord
&& position.chunkPosY == tileEntity.yCoord
&& position.chunkPosZ == tileEntity.zCoord
&& videoChannel == ((IVideoChannel)tileEntity).getVideoChannel();
}
}

View file

@ -0,0 +1,32 @@
package cr0s.warpdrive.data;
import java.util.HashMap;
import cr0s.warpdrive.block.TileEntityLaser;
import cr0s.warpdrive.block.detection.TileEntityCamera;
public enum CameraType {
SIMPLE_CAMERA (TileEntityCamera.class),
LASER_CAMERA (TileEntityLaser.class);
public final Class<?> clazz;
// cached values
public static final int length;
private static final HashMap<Integer, CameraType> ID_MAP = new HashMap<Integer, CameraType>();
static {
length = CameraType.values().length;
for (CameraType cameraType : values()) {
ID_MAP.put(cameraType.ordinal(), cameraType);
}
}
private CameraType(Class<?> clazz) {
this.clazz = clazz;
}
public static CameraType get(final int id) {
return ID_MAP.get(id);
}
}

View file

@ -11,11 +11,11 @@ import cr0s.warpdrive.config.WarpDriveConfig;
public class CamerasRegistry {
private LinkedList<CameraRegistryItem> registry;
public CamerasRegistry() {
registry = new LinkedList<CameraRegistryItem>();
}
public CameraRegistryItem getCameraByVideoChannel(World world, int videoChannel) {
CameraRegistryItem cam = null;
for (Iterator<CameraRegistryItem> it = registry.iterator(); it.hasNext();) {
@ -47,16 +47,16 @@ public class CamerasRegistry {
return cam;
}
}
return null;
}
private static boolean isCamAlive(World world, CameraRegistryItem cam) {
if (world.provider.dimensionId != cam.dimensionId) {
WarpDrive.logger.error("Inconsistent worldObj with camera " + world.provider.dimensionId + " vs " + cam.dimensionId);
return false;
}
if (!world.getChunkFromBlockCoords(cam.position.chunkPosX, cam.position.chunkPosZ).isChunkLoaded) {
if (WarpDriveConfig.LOGGING_VIDEO_CHANNEL) {
WarpDrive.logger.info("Reporting an 'unloaded' camera in dimension " + cam.dimensionId + " at "
@ -72,13 +72,13 @@ public class CamerasRegistry {
}
return false;
}
return true;
}
private void removeDeadCams(World world) {
// LocalProfiler.start("CamRegistry Removing dead cameras");
CameraRegistryItem cam = null;
for (Iterator<CameraRegistryItem> it = registry.iterator(); it.hasNext();) {
cam = it.next();
@ -90,10 +90,10 @@ public class CamerasRegistry {
it.remove();
}
}
// LocalProfiler.stop();
}
public void removeFromRegistry(World world, ChunkPosition position) {
CameraRegistryItem cam = getCamByPosition(world, position);
if (cam != null) {
@ -104,12 +104,12 @@ public class CamerasRegistry {
registry.remove(cam);
}
}
public void updateInRegistry(World world, ChunkPosition position, int videoChannel, int type) {
CameraRegistryItem cam = new CameraRegistryItem(world, position, videoChannel, type);
public void updateInRegistry(World world, ChunkPosition position, int videoChannel, CameraType cameraType) {
CameraRegistryItem cam = new CameraRegistryItem(world, position, videoChannel, cameraType);
// WarpDrive.debugPrint("updateInRegistry " + cam.position.x + ", " + cam.position.y + ", " + cam.position.z);
removeDeadCams(world);
if (isCamAlive(world, cam)) {
CameraRegistryItem existingCam = getCamByPosition(world, cam.position);
if (existingCam == null) {
@ -133,10 +133,10 @@ public class CamerasRegistry {
}
}
}
public void printRegistry(World world) {
WarpDrive.logger.info("Cameras registry for dimension " + world.provider.dimensionId + ":");
for (CameraRegistryItem cam : registry) {
WarpDrive.logger.info("- " + cam.videoChannel + " (" + cam.position.chunkPosX + ", " + cam.position.chunkPosY + ", " + cam.position.chunkPosZ + ")");
}

View file

@ -11,11 +11,12 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.network.FMLNetworkEvent.ClientDisconnectionFromServerEvent;
import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.config.WarpDriveConfig;
import cr0s.warpdrive.data.CameraType;
public class ClientCameraHandler {
public static boolean isOverlayEnabled = false;
public static int overlayType = 0;
public static CameraType overlayType = null;
public static int zoomIndex = 0;
public static String overlayLoggingMessage = "";
public static float originalFOV = 70.0F;
@ -35,7 +36,7 @@ public class ClientCameraHandler {
}
}
public static void setupViewpoint(final int type, EntityPlayer parEntityPlayer, final float initialYaw, final float initialPitch,
public static void setupViewpoint(final CameraType cameraType, EntityPlayer parEntityPlayer, final float initialYaw, final float initialPitch,
final int monitor_x, final int monitor_y, final int monitor_z, final Block blockMonitor,
final int camera_x, final int camera_y, final int camera_z, final Block blockCamera) {
Minecraft mc = Minecraft.getMinecraft();
@ -48,7 +49,7 @@ public class ClientCameraHandler {
// Save initial state
originalFOV = mc.gameSettings.fovSetting;
originalSensitivity = mc.gameSettings.mouseSensitivity;
overlayType = type;
overlayType = cameraType;
entityPlayer = parEntityPlayer;
dimensionId = entityPlayer.worldObj.provider.dimensionId;
check1_x = monitor_x;

View file

@ -10,6 +10,7 @@ import org.lwjgl.opengl.GL11;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cr0s.warpdrive.config.WarpDriveConfig;
import cr0s.warpdrive.data.CameraType;
public class RenderOverlayCamera {
private Minecraft mc;
@ -33,7 +34,7 @@ public class RenderOverlayCamera {
try {
String strHelp;
if (ClientCameraHandler.overlayType == 0) {
if (ClientCameraHandler.overlayType == CameraType.SIMPLE_CAMERA) {
mc.getTextureManager().bindTexture(new ResourceLocation("warpdrive", "textures/blocks/detection/cameraOverlay.png"));
strHelp = "Left click to zoom / Right click to exit";
} else {

View file

@ -195,6 +195,7 @@ tile.warpdrive.hull3.glass.black.name=Black Stained Superior Hull Glass
warpdrive.guide.prefix=%1$s:
warpdrive.error.badTileEntity=§cthis block needs an update by breaking and placing it.
warpdrive.monitor.viewingCamera=Viewing camera at %2$d, %3$d, %4$d on video channel %1$d
warpdrive.ship.attachedPlayers=Attached players: %1$s
warpdrive.ship.playerAttached=You're now attached to ship %1$s.\nAttached players are %2$s