Refactored tooltip handling

This commit is contained in:
LemADEC 2016-08-13 11:22:39 +02:00
parent a78529a11d
commit 4f7f866571
18 changed files with 91 additions and 82 deletions

View file

@ -5,6 +5,7 @@ import java.util.List;
import java.util.UUID;
import com.mojang.authlib.GameProfile;
import cr0s.warpdrive.block.*;
import cr0s.warpdrive.block.forcefield.*;
import cr0s.warpdrive.block.hull.BlockHullStairs;
import cr0s.warpdrive.item.*;
@ -46,15 +47,6 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import cr0s.warpdrive.block.BlockAirGenerator;
import cr0s.warpdrive.block.BlockChunkLoader;
import cr0s.warpdrive.block.BlockLaser;
import cr0s.warpdrive.block.BlockLaserMedium;
import cr0s.warpdrive.block.TileEntityAbstractChunkLoading;
import cr0s.warpdrive.block.TileEntityAirGenerator;
import cr0s.warpdrive.block.TileEntityChunkLoader;
import cr0s.warpdrive.block.TileEntityLaser;
import cr0s.warpdrive.block.TileEntityLaserMedium;
import cr0s.warpdrive.block.building.BlockShipScanner;
import cr0s.warpdrive.block.building.TileEntityShipScanner;
import cr0s.warpdrive.block.collection.BlockLaserTreeFarm;
@ -248,158 +240,158 @@ public class WarpDrive implements LoadingCallback {
// CORE CONTROLLER
blockShipController = new BlockShipController();
GameRegistry.registerBlock(blockShipController, "blockShipController");
GameRegistry.registerBlock(blockShipController, ItemBlockAbstractBase.class, "blockShipController");
GameRegistry.registerTileEntity(TileEntityShipController.class, MODID + ":blockShipController");
// SHIP CORE
blockShipCore = new BlockShipCore();
GameRegistry.registerBlock(blockShipCore, "blockShipCore");
GameRegistry.registerBlock(blockShipCore, ItemBlockAbstractBase.class, "blockShipCore");
GameRegistry.registerTileEntity(TileEntityShipCore.class, MODID + ":blockShipCore");
// RADAR
blockRadar = new BlockRadar();
GameRegistry.registerBlock(blockRadar, "blockRadar");
GameRegistry.registerBlock(blockRadar, ItemBlockAbstractBase.class, "blockRadar");
GameRegistry.registerTileEntity(TileEntityRadar.class, MODID + ":blockRadar");
// WARP ISOLATION
blockWarpIsolation = new BlockWarpIsolation();
GameRegistry.registerBlock(blockWarpIsolation, "blockWarpIsolation");
GameRegistry.registerBlock(blockWarpIsolation, ItemBlockAbstractBase.class, "blockWarpIsolation");
// AIR GENERATOR
blockAirGenerator = new BlockAirGenerator();
GameRegistry.registerBlock(blockAirGenerator, "blockAirGenerator");
GameRegistry.registerBlock(blockAirGenerator, ItemBlockAbstractBase.class, "blockAirGenerator");
GameRegistry.registerTileEntity(TileEntityAirGenerator.class, MODID + ":blockAirGenerator");
// AIR BLOCK
blockAir = new BlockAir();
GameRegistry.registerBlock(blockAir, "blockAir");
GameRegistry.registerBlock(blockAir, ItemBlockAbstractBase.class, "blockAir");
// GAS BLOCK
blockGas = new BlockGas();
GameRegistry.registerBlock(blockGas, "blockGas");
GameRegistry.registerBlock(blockGas, ItemBlockAbstractBase.class, "blockGas");
// LASER EMITTER
blockLaser = new BlockLaser();
GameRegistry.registerBlock(blockLaser, "blockLaser");
GameRegistry.registerBlock(blockLaser, ItemBlockAbstractBase.class, "blockLaser");
GameRegistry.registerTileEntity(TileEntityLaser.class, MODID + ":blockLaser");
// LASER EMITTER WITH CAMERA
blockLaserCamera = new BlockLaserCamera();
GameRegistry.registerBlock(blockLaserCamera, "blockLaserCamera");
GameRegistry.registerBlock(blockLaserCamera, ItemBlockAbstractBase.class, "blockLaserCamera");
GameRegistry.registerTileEntity(TileEntityLaserCamera.class, MODID + ":blockLaserCamera");
// LASER EMITTER WITH CAMERA
blockWeaponController = new BlockWeaponController();
GameRegistry.registerBlock(blockWeaponController, "blockWeaponController");
GameRegistry.registerBlock(blockWeaponController, ItemBlockAbstractBase.class, "blockWeaponController");
GameRegistry.registerTileEntity(TileEntityWeaponController.class, MODID + ":blockWeaponController");
// CAMERA
blockCamera = new BlockCamera();
GameRegistry.registerBlock(blockCamera, "blockCamera");
GameRegistry.registerBlock(blockCamera, ItemBlockAbstractBase.class, "blockCamera");
GameRegistry.registerTileEntity(TileEntityCamera.class, MODID + ":blockCamera");
// MONITOR
blockMonitor = new BlockMonitor();
GameRegistry.registerBlock(blockMonitor, "blockMonitor");
GameRegistry.registerBlock(blockMonitor, ItemBlockAbstractBase.class, "blockMonitor");
GameRegistry.registerTileEntity(TileEntityMonitor.class, MODID + ":blockMonitor");
// MINING LASER
blockMiningLaser = new BlockMiningLaser();
GameRegistry.registerBlock(blockMiningLaser, "blockMiningLaser");
GameRegistry.registerBlock(blockMiningLaser, ItemBlockAbstractBase.class, "blockMiningLaser");
GameRegistry.registerTileEntity(TileEntityMiningLaser.class, MODID + ":blockMiningLaser");
// LASER TREE FARM
blockLaserTreeFarm = new BlockLaserTreeFarm();
GameRegistry.registerBlock(blockLaserTreeFarm, "blockLaserTreeFarm");
GameRegistry.registerBlock(blockLaserTreeFarm, ItemBlockAbstractBase.class, "blockLaserTreeFarm");
GameRegistry.registerTileEntity(TileEntityLaserTreeFarm.class, MODID + ":blockLaserTreeFarm");
// LASER MEDIUM
blockLaserMedium = new BlockLaserMedium();
GameRegistry.registerBlock(blockLaserMedium, "blockLaserMedium");
GameRegistry.registerBlock(blockLaserMedium, ItemBlockAbstractBase.class, "blockLaserMedium");
GameRegistry.registerTileEntity(TileEntityLaserMedium.class, MODID + ":blockLaserMedium");
// LIFT
blockLift = new BlockLift();
GameRegistry.registerBlock(blockLift, "blockLift");
GameRegistry.registerBlock(blockLift, ItemBlockAbstractBase.class, "blockLift");
GameRegistry.registerTileEntity(TileEntityLift.class, MODID + ":blockLift");
// IRIDIUM BLOCK
blockIridium = new BlockIridium();
GameRegistry.registerBlock(blockIridium, "blockIridium");
GameRegistry.registerBlock(blockIridium, ItemBlockAbstractBase.class, "blockIridium");
// HIGHLY ADVANCED MACHINE BLOCK
blockHighlyAdvancedMachine = new BlockHighlyAdvancedMachine();
GameRegistry.registerBlock(blockHighlyAdvancedMachine, "blockHighlyAdvancedMachine");
GameRegistry.registerBlock(blockHighlyAdvancedMachine, ItemBlockAbstractBase.class, "blockHighlyAdvancedMachine");
// SHIP SCANNER
blockShipScanner = new BlockShipScanner();
GameRegistry.registerBlock(blockShipScanner, "blockShipScanner");
GameRegistry.registerBlock(blockShipScanner, ItemBlockAbstractBase.class, "blockShipScanner");
GameRegistry.registerTileEntity(TileEntityShipScanner.class, MODID + ":blockShipScanner");
// CLOAKING DEVICE CORE
blockCloakingCore = new BlockCloakingCore();
GameRegistry.registerBlock(blockCloakingCore, "blockCloakingCore");
GameRegistry.registerBlock(blockCloakingCore, ItemBlockAbstractBase.class, "blockCloakingCore");
GameRegistry.registerTileEntity(TileEntityCloakingCore.class, MODID + ":blockCloakingCore");
// CLOAKING DEVICE COIL
blockCloakingCoil = new BlockCloakingCoil();
GameRegistry.registerBlock(blockCloakingCoil, "blockCloakingCoil");
GameRegistry.registerBlock(blockCloakingCoil, ItemBlockAbstractBase.class, "blockCloakingCoil");
// TRANSPORTER
blockTransporter = new BlockTransporter();
GameRegistry.registerBlock(blockTransporter, "blockTransporter");
GameRegistry.registerBlock(blockTransporter, ItemBlockAbstractBase.class, "blockTransporter");
GameRegistry.registerTileEntity(TileEntityTransporter.class, MODID + ":blockTransporter");
// IC2 REACTOR LASER MONITOR
if (WarpDriveConfig.isIndustrialCraft2Loaded) {
blockIC2reactorLaserMonitor = new BlockIC2reactorLaserMonitor();
GameRegistry.registerBlock(blockIC2reactorLaserMonitor, "blockIC2reactorLaserMonitor");
GameRegistry.registerBlock(blockIC2reactorLaserMonitor, ItemBlockAbstractBase.class, "blockIC2reactorLaserMonitor");
GameRegistry.registerTileEntity(TileEntityIC2reactorLaserMonitor.class, MODID + ":blockIC2reactorLaserMonitor");
}
// TRANSPORT BEACON
blockTransportBeacon = new BlockTransportBeacon();
GameRegistry.registerBlock(blockTransportBeacon, "blockTransportBeacon");
GameRegistry.registerBlock(blockTransportBeacon, ItemBlockAbstractBase.class, "blockTransportBeacon");
// POWER REACTOR, LASER, STORE
blockEnanReactorCore = new BlockEnanReactorCore();
GameRegistry.registerBlock(blockEnanReactorCore, "blockEnanReactorCore");
GameRegistry.registerBlock(blockEnanReactorCore, ItemBlockAbstractBase.class, "blockEnanReactorCore");
GameRegistry.registerTileEntity(TileEntityEnanReactorCore.class, MODID + ":blockEnanReactorCore");
blockEnanReactorLaser = new BlockEnanReactorLaser();
GameRegistry.registerBlock(blockEnanReactorLaser, "blockEnanReactorLaser");
GameRegistry.registerBlock(blockEnanReactorLaser, ItemBlockAbstractBase.class, "blockEnanReactorLaser");
GameRegistry.registerTileEntity(TileEntityEnanReactorLaser.class, MODID + ":blockEnanReactorLaser");
blockEnergyBank = new BlockEnergyBank();
GameRegistry.registerBlock(blockEnergyBank, "blockEnergyBank");
GameRegistry.registerBlock(blockEnergyBank, ItemBlockAbstractBase.class, "blockEnergyBank");
GameRegistry.registerTileEntity(TileEntityEnergyBank.class, MODID + ":blockEnergyBank");
// CHUNK LOADER
blockChunkLoader = new BlockChunkLoader();
GameRegistry.registerBlock(blockChunkLoader, "blockChunkLoader");
GameRegistry.registerBlock(blockChunkLoader, ItemBlockAbstractBase.class, "blockChunkLoader");
GameRegistry.registerTileEntity(TileEntityChunkLoader.class, MODID + ":blockChunkLoader");
// FORCE FIELD BLOCKS
@ -410,7 +402,7 @@ public class WarpDrive implements LoadingCallback {
int index = tier - 1;
// FORCE FIELD
blockForceFields[index] = new BlockForceField(tier);
GameRegistry.registerBlock(blockForceFields[index], "blockForceField" + tier);
GameRegistry.registerBlock(blockForceFields[index], ItemBlockAbstractBase.class, "blockForceField" + tier);
GameRegistry.registerTileEntity(TileEntityForceField.class, MODID + ":blockForceField" + tier);
// FORCE FIELD PROJECTOR
@ -426,7 +418,7 @@ public class WarpDrive implements LoadingCallback {
/* TODO
// SECURITY STATION
blockSecurityStation = new BlockSecurityStation();
GameRegistry.registerBlock(blockSecurityStation, "blockSecurityStation");
GameRegistry.registerBlock(blockSecurityStation, ItemBlockAbstractBase.class, "blockSecurityStation");
GameRegistry.registerTileEntity(TileEntitySecurityStation.class, MODID + ":blockSecurityStation");
*/
// DECORATIVE

View file

@ -33,11 +33,11 @@ public class ItemBlockAbstractBase extends ItemBlock {
public String getStatus(final NBTTagCompound nbtTagCompound) {
TileEntity tileEntity = field_150939_a.createTileEntity(null, 0);
if (tileEntity instanceof TileEntityAbstractEnergy) {
if (tileEntity instanceof TileEntityAbstractBase) {
if (nbtTagCompound != null) {
tileEntity.readFromNBT(nbtTagCompound);
}
return ((TileEntityAbstractEnergy)tileEntity).getStatus();
return ((TileEntityAbstractBase)tileEntity).getStatus();
} else {
return "";

View file

@ -13,6 +13,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
@ -335,6 +336,11 @@ public abstract class TileEntityAbstractBase extends TileEntity implements IBloc
return nbtTagCompound;
}
// status
public String getStatus() {
return (worldObj != null ? StatCollector.translateToLocalFormatted("warpdrive.guide.prefix", getBlockType().getLocalizedName()) : "");
}
// upgrade system
private final HashMap<Object, Integer> installedUpgrades = new HashMap<>(10);
private final HashMap<Object, Integer> maxUpgrades = new HashMap<>(10);

View file

@ -531,10 +531,14 @@ public class TileEntityLaser extends TileEntityAbstractLaser implements IBeamFre
}
}
@Override
public String getStatus() {
return StatCollector.translateToLocalFormatted("warpdrive.guide.prefix",
getBlockType().getLocalizedName())
+ getBeamFrequencyStatus();
if (worldObj == null || !worldObj.isRemote) {
return super.getStatus()
+ "\n" + getBeamFrequencyStatus();
} else {
return super.getStatus();
}
}
private void playSoundCorrespondsEnergy(int energy) {

View file

@ -720,7 +720,9 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
return super.callMethod(computer, context, method, arguments);
}
@Override
public String getStatus() {
// @TODO merge with base
int energy = getEnergyStored();
String state = "IDLE (not farming)";
if (currentState == STATE_IDLE) {

View file

@ -514,7 +514,9 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
return super.callMethod(computer, context, method, arguments);
}
@Override
public String getStatus() {
// @TODO merge with base
int energy = getEnergyStored();
String state = "IDLE (not mining)";
if (currentState == STATE_IDLE) {

View file

@ -102,9 +102,9 @@ public class TileEntityCamera extends TileEntityAbstractInterfaced implements IV
}
}
@Override
public String getStatus() {
return StatCollector.translateToLocalFormatted("warpdrive.guide.prefix",
getBlockType().getLocalizedName())
return super.getStatus()
+ getVideoChannelStatus();
}

View file

@ -360,6 +360,10 @@ public class TileEntityCloakingCore extends TileEntityAbstractEnergy {
@Override
public String getStatus() {
if (worldObj == null) {
return super.getStatus();
}
String unlocalizedStatus;
if (!isValid) {
unlocalizedStatus = "warpdrive.cloakingCore.invalidAssembly";
@ -370,11 +374,10 @@ public class TileEntityCloakingCore extends TileEntityAbstractEnergy {
} else {
unlocalizedStatus = "warpdrive.cloakingCore.cloaking";
}
return StatCollector.translateToLocalFormatted("warpdrive.guide.prefix",
getBlockType().getLocalizedName())
+ StatCollector.translateToLocalFormatted(unlocalizedStatus,
tier,
volume);
return super.getStatus()
+ "\n" + StatCollector.translateToLocalFormatted(unlocalizedStatus,
tier,
volume);
}
// OpenComputer callback methods

View file

@ -72,7 +72,6 @@ public class TileEntityMonitor extends TileEntityAbstractInterfaced implements I
} else {
CameraRegistryItem camera = WarpDrive.cameras.getCameraByVideoChannel(worldObj, videoChannel);
if (camera == null) {
WarpDrive.cameras.printRegistry(worldObj);
return StatCollector.translateToLocalFormatted("warpdrive.videoChannel.statusLine.invalidOrNotLoaded", videoChannel);
} else if (camera.isTileEntity(this)) {
return StatCollector.translateToLocalFormatted("warpdrive.videoChannel.statusLine.valid", videoChannel);
@ -86,9 +85,9 @@ public class TileEntityMonitor extends TileEntityAbstractInterfaced implements I
}
}
@Override
public String getStatus() {
return StatCollector.translateToLocalFormatted("warpdrive.guide.prefix",
getBlockType().getLocalizedName())
return super.getStatus()
+ getVideoChannelStatus();
}

View file

@ -187,16 +187,18 @@ public class TileEntityIC2reactorLaserMonitor extends TileEntityAbstractEnergy {
@Override
@Optional.Method(modid = "IC2")
public String getStatus() {
if (worldObj == null) {
return super.getStatus();
}
Set<IReactor> reactors = findReactors();
if (reactors != null && !reactors.isEmpty()) {
return StatCollector.translateToLocalFormatted("warpdrive.guide.prefix",
getBlockType().getLocalizedName())
+ StatCollector.translateToLocalFormatted("warpdrive.IC2reactorLaserMonitor.multipleReactors",
reactors.size());
return super.getStatus()
+ StatCollector.translateToLocalFormatted("warpdrive.IC2reactorLaserMonitor.multipleReactors",
reactors.size());
} else {
return StatCollector.translateToLocalFormatted("warpdrive.guide.prefix",
getBlockType().getLocalizedName())
+ StatCollector.translateToLocalFormatted("warpdrive.IC2reactorLaserMonitor.noReactor");
return super.getStatus()
+ StatCollector.translateToLocalFormatted("warpdrive.IC2reactorLaserMonitor.noReactor");
}
}

View file

@ -109,10 +109,9 @@ public class TileEntityAbstractForceField extends TileEntityAbstractEnergy imple
}
}
@Override
public String getStatus() {
String strEnergyStatus = getEnergyStatus();
return (worldObj != null ? StatCollector.translateToLocalFormatted("warpdrive.guide.prefix", getBlockType().getLocalizedName()) : "")
+ (strEnergyStatus.isEmpty() ? "" : "\n" + strEnergyStatus)
return super.getStatus()
+ "\n" + getBeamFrequencyStatus();
}

View file

@ -864,6 +864,7 @@ public class TileEntityForceFieldProjector extends TileEntityAbstractForceField
}
}
@Override
public String getStatus() {
return super.getStatus()
+ "\n" + getShapeStatus()

View file

@ -260,9 +260,9 @@ public class TileEntityShipController extends TileEntityAbstractInterfaced {
getAttachedPlayersList());
}
@Override
public String getStatus() {
return StatCollector.translateToLocalFormatted("warpdrive.guide.prefix",
getBlockType().getLocalizedName())
return super.getStatus()
+ StatCollector.translateToLocalFormatted("warpdrive.ship.attachedPlayers",
getAttachedPlayersList());
}

View file

@ -1016,9 +1016,7 @@ public class TileEntityShipCore extends TileEntityAbstractEnergy {
@Override
public String getStatus() {
return StatCollector.translateToLocalFormatted("warpdrive.guide.prefix",
getBlockType().getLocalizedName())
+ "\n" + getEnergyStatus()
return super.getStatus()
+ ((cooldownTime > 0) ? "\n" + StatCollector.translateToLocalFormatted("warpdrive.ship.statusLine.cooling", cooldownTime / 20) : "")
+ ((isolationBlocksCount > 0) ? "\n" + StatCollector.translateToLocalFormatted("warpdrive.ship.statusLine.isolation", isolationBlocksCount, isolationRate * 100.0) : "");
}

View file

@ -76,9 +76,7 @@ public class TileEntityTransporter extends TileEntityAbstractEnergy implements I
@Override
public String getStatus() {
return StatCollector.translateToLocalFormatted("warpdrive.guide.prefix",
getBlockType().getLocalizedName())
+ "\n" + getEnergyStatus()
return super.getStatus()
+ "\n" + StatCollector.translateToLocalFormatted("warpdrive.transporter.status",
sourceVec.x, sourceVec.y, sourceVec.z,
destVec.x, destVec.y, destVec.z);

View file

@ -104,9 +104,12 @@ public class TileEntityLaserCamera extends TileEntityLaser implements IVideoChan
@Override
public String getStatus() {
return StatCollector.translateToLocalFormatted("warpdrive.guide.prefix",
getBlockType().getLocalizedName())
+ (worldObj.isRemote ? getVideoChannelStatus() : getBeamFrequencyStatus());
if (worldObj == null || worldObj.isRemote) {
return super.getStatus()
+ "\n" + getVideoChannelStatus();
} else {
return super.getStatus();
}
}
@Override

View file

@ -21,12 +21,7 @@ public class TileEntityWeaponController extends TileEntityAbstractInterfaced {
public void updateEntity() {
super.updateEntity();
}
public String getStatus() {
return StatCollector.translateToLocalFormatted("warpdrive.guide.prefix",
getBlockType().getLocalizedName());
}
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);

View file

@ -17,6 +17,9 @@ public class CamerasRegistry {
}
public CameraRegistryItem getCameraByVideoChannel(World world, int videoChannel) {
if (world == null) {
return null;
}
CameraRegistryItem cam;
for (Iterator<CameraRegistryItem> it = registry.iterator(); it.hasNext();) {
cam = it.next();
@ -107,7 +110,6 @@ public class CamerasRegistry {
public void updateInRegistry(World world, ChunkPosition position, int videoChannel, EnumCameraType enumCameraType) {
CameraRegistryItem cam = new CameraRegistryItem(world, position, videoChannel, enumCameraType);
// WarpDrive.debugPrint("updateInRegistry " + cam.position.x + ", " + cam.position.y + ", " + cam.position.z);
removeDeadCams(world);
if (isCamAlive(world, cam)) {
@ -135,6 +137,9 @@ public class CamerasRegistry {
}
public void printRegistry(World world) {
if (world == null) {
return;
}
WarpDrive.logger.info("Cameras registry for dimension " + world.provider.dimensionId + ":");
for (CameraRegistryItem cam : registry) {