mirror of
https://github.com/GTNewHorizons/Opis.git
synced 2026-11-20 20:22:39 +00:00
Add Navigator integration for overlay rendering (#19)
This commit is contained in:
1 parent
8cf18c462e
commit
747bdcba3b
29 files changed
+998
-158
No files matched your search
@@ -1,6 +1,9 @@
|
||||
// Add your dependencies here
|
||||
|
||||
dependencies {
|
||||
devOnlyNonPublishable('com.github.GTNewHorizons:Navigator:1.1.8:dev')
|
||||
compileOnly('info.journeymap:journeymap-api-forge:1.7.10-2.0.0')
|
||||
|
||||
shadowCompile 'io.netty-opis:Netty-opis:4.0.23'
|
||||
shadowCompile 'org.apache.commons:commons-math3:3.2'
|
||||
shadowCompile 'org.jfree:jfreechart:1.0.17'
|
||||
|
||||
+23
-3
@@ -39,14 +39,34 @@ remoteMappings = https\://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/co
|
||||
# `./gradlew runClient --username=AnotherPlayer`, or configuring this command in your IDE.
|
||||
developmentEnvironmentUserName = Developer
|
||||
|
||||
# Enables using modern Java syntax (up to version 17) via Jabel, while still targeting JVM 8.
|
||||
# See https://github.com/bsideup/jabel for details on how this works.
|
||||
enableModernJavaSyntax = true
|
||||
# Enables modern Java syntax support. Valid values:
|
||||
# - false: No modern syntax, Java 8 only
|
||||
# - jabel: Jabel syntax-only support, compiles to J8 bytecode
|
||||
# - jvmDowngrader: Full modern Java via JVM Downgrader (syntax + stdlib APIs)
|
||||
# - modern: Native modern Java bytecode, no downgrading
|
||||
enableModernJavaSyntax = jabel
|
||||
|
||||
# If set, ignores the above setting and compiles with the given toolchain. This may cause unexpected issues,
|
||||
# and should *not* be used in most situations. -1 disables this.
|
||||
# forceToolchainVersion = -1
|
||||
|
||||
# Target JVM version for JVM Downgrader bytecode downgrading.
|
||||
# Only used when enableModernJavaSyntax = jvmDowngrader
|
||||
# downgradeTargetVersion = 8
|
||||
|
||||
# Comma-separated list of Java versions for multi-release jar support (JVM Downgrader only).
|
||||
# Classes will be available in META-INF/versions/N/ for each version N in this list.
|
||||
# Default: "21,25" (J25+ gets native classes, J21-24 gets partial downgrade, J8-20 gets full downgrade).
|
||||
# jvmDowngraderMultiReleaseVersions = 21,25
|
||||
|
||||
# Specifies how JVM Downgrader API stubs are provided. Options:
|
||||
# - shade: Shade minimized stubs into the jar
|
||||
# - gtnhlib: GTNHLib provides stubs at runtime (adds version constraint)
|
||||
# - external: Another dependency provides stubs (no constraint, no warning)
|
||||
# - (empty): Warning reminding you to configure stubs
|
||||
# Note: 'shade' option requires you to verify license compliance, see: https://github.com/unimined/JvmDowngrader/blob/main/LICENSE.md
|
||||
# jvmDowngraderStubsProvider =
|
||||
|
||||
# Enables injecting missing generics into the decompiled source code for a better coding experience.
|
||||
# Turns most publicly visible List, Map, etc. into proper List<E>, Map<K, V> types.
|
||||
enableGenericInjection = true
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
// Add any additional repositories for your dependencies here
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
name = "JourneyMap"
|
||||
url = 'https://maven.blamejared.com'
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -17,7 +17,7 @@ pluginManagement {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '2.0.7'
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '2.0.29'
|
||||
}
|
||||
|
||||
|
||||
@@ -26,9 +26,13 @@ public class DataBlockTileEntity implements ISerializable, Comparable<DataBlockT
|
||||
public DataBlockTileEntity fill(CoordinatesBlock coord) {
|
||||
this.pos = coord;
|
||||
World world = DimensionManager.getWorld(this.pos.dim);
|
||||
Block block = world.getBlock(this.pos.x, this.pos.y, this.pos.z);
|
||||
this.id = Block.getIdFromBlock(block);
|
||||
this.meta = block.getDamageValue(world, this.pos.x, this.pos.y, this.pos.z);
|
||||
|
||||
// The profiler keeps coordinates from dimensions that have since unloaded.
|
||||
if (world != null) {
|
||||
Block block = world.getBlock(this.pos.x, this.pos.y, this.pos.z);
|
||||
this.id = Block.getIdFromBlock(block);
|
||||
this.meta = block.getDamageValue(world, this.pos.x, this.pos.y, this.pos.z);
|
||||
}
|
||||
|
||||
HashMap<CoordinatesBlock, DescriptiveStatistics> data = ((ProfilerTileEntityUpdate) (ProfilerSection.TILEENT_UPDATETIME
|
||||
.getProfiler())).data;
|
||||
|
||||
@@ -60,7 +60,11 @@ public class StatsChunk extends StatAbstract {
|
||||
double value = o.getDataSum() - this.getDataSum();
|
||||
if (value > 0) return 1;
|
||||
if (value < 0) return -1;
|
||||
return 0;
|
||||
|
||||
CoordinatesChunk other = ((StatsChunk) o).chunk;
|
||||
if (chunk.dim != other.dim) return Integer.compare(chunk.dim, other.dim);
|
||||
if (chunk.chunkX != other.chunkX) return Integer.compare(chunk.chunkX, other.chunkX);
|
||||
return Integer.compare(chunk.chunkZ, other.chunkZ);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
@@ -12,38 +13,19 @@ import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.gen.ChunkProviderServer;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
import mcp.mobius.mobiuscore.profiler.ProfilerSection;
|
||||
import mcp.mobius.opis.api.IMessageHandler;
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesBlock;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesChunk;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataBlockTileEntity;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataEntity;
|
||||
import mcp.mobius.opis.data.holders.stats.StatsChunk;
|
||||
import mcp.mobius.opis.data.profilers.ProfilerEntityUpdate;
|
||||
import mcp.mobius.opis.data.profilers.ProfilerTileEntityUpdate;
|
||||
import mcp.mobius.opis.network.PacketBase;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
|
||||
public enum ChunkManager implements IMessageHandler {
|
||||
public enum ChunkManager {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
private ArrayList<CoordinatesChunk> chunksLoad = new ArrayList<CoordinatesChunk>();
|
||||
private HashMap<CoordinatesChunk, StatsChunk> chunkMeanTime = new HashMap<CoordinatesChunk, StatsChunk>();
|
||||
|
||||
public synchronized void addLoadedChunks(ArrayList<ISerializable> data) {
|
||||
// chunksLoad.clear();
|
||||
for (ISerializable chunk : data) {
|
||||
chunksLoad.add((CoordinatesChunk) chunk);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void setChunkMeanTime(ArrayList<ISerializable> data) {
|
||||
chunkMeanTime.clear();
|
||||
for (ISerializable stat : data) chunkMeanTime.put(((StatsChunk) stat).getChunk(), (StatsChunk) stat);
|
||||
}
|
||||
|
||||
public synchronized ArrayList<CoordinatesChunk> getLoadedChunks(int dimension) {
|
||||
HashSet<CoordinatesChunk> chunkStatus = new HashSet<CoordinatesChunk>();
|
||||
WorldServer world = DimensionManager.getWorld(dimension);
|
||||
@@ -62,35 +44,44 @@ public enum ChunkManager implements IMessageHandler {
|
||||
return new ArrayList<>(chunkStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the profiler maps directly: the Data*.fill() holders do per-element world and name lookups this ignores.
|
||||
*/
|
||||
public synchronized ArrayList<StatsChunk> getChunksUpdateTime() {
|
||||
HashMap<CoordinatesChunk, StatsChunk> chunks = new HashMap<CoordinatesChunk, StatsChunk>();
|
||||
|
||||
for (CoordinatesBlock coords : ((ProfilerTileEntityUpdate) ProfilerSection.TILEENT_UPDATETIME
|
||||
.getProfiler()).data.keySet()) {
|
||||
DataBlockTileEntity data = new DataBlockTileEntity().fill(coords);
|
||||
CoordinatesChunk chunk = data.pos.asCoordinatesChunk();
|
||||
for (Map.Entry<CoordinatesBlock, DescriptiveStatistics> entry : ((ProfilerTileEntityUpdate) ProfilerSection.TILEENT_UPDATETIME
|
||||
.getProfiler()).data.entrySet()) {
|
||||
CoordinatesChunk chunk = entry.getKey().asCoordinatesChunk();
|
||||
|
||||
if (!chunks.containsKey(chunk)) chunks.put(chunk, new StatsChunk(chunk));
|
||||
|
||||
chunks.get(chunk).addTileEntity();
|
||||
chunks.get(chunk).addMeasure(data.update.timing);
|
||||
chunks.get(chunk).addMeasure(entry.getValue().getGeometricMean());
|
||||
}
|
||||
|
||||
for (Entity entity : ((ProfilerEntityUpdate) ProfilerSection.ENTITY_UPDATETIME.getProfiler()).data.keySet()) {
|
||||
DataEntity data = new DataEntity().fill(entity);
|
||||
CoordinatesChunk chunk = data.pos.asCoordinatesChunk();
|
||||
for (Map.Entry<Entity, DescriptiveStatistics> entry : ((ProfilerEntityUpdate) ProfilerSection.ENTITY_UPDATETIME
|
||||
.getProfiler()).data.entrySet()) {
|
||||
CoordinatesChunk chunk = new CoordinatesBlock(entry.getKey()).asCoordinatesChunk();
|
||||
|
||||
if (!chunks.containsKey(chunk)) chunks.put(chunk, new StatsChunk(chunk));
|
||||
|
||||
chunks.get(chunk).addEntity();
|
||||
chunks.get(chunk).addMeasure(data.update.timing);
|
||||
chunks.get(chunk).addMeasure(entry.getValue().getGeometricMean());
|
||||
}
|
||||
|
||||
return new ArrayList<>(chunks.values());
|
||||
}
|
||||
|
||||
public ArrayList<StatsChunk> getTopChunks(int quantity) {
|
||||
return getTopChunks(quantity, null);
|
||||
}
|
||||
|
||||
/** @param dimension restricts the ranking to one world, so a busier one cannot crowd it out entirely */
|
||||
public ArrayList<StatsChunk> getTopChunks(int quantity, Integer dimension) {
|
||||
ArrayList<StatsChunk> chunks = this.getChunksUpdateTime();
|
||||
if (dimension != null) chunks.removeIf(stat -> stat.getChunk().dim != dimension);
|
||||
|
||||
ArrayList<StatsChunk> outList = new ArrayList<>(quantity);
|
||||
Collections.sort(chunks);
|
||||
|
||||
@@ -133,26 +124,4 @@ public enum ChunkManager implements IMessageHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(Message msg, PacketBase rawdata) {
|
||||
switch (msg) {
|
||||
case LIST_TIMING_CHUNK: {
|
||||
this.setChunkMeanTime(rawdata.array);
|
||||
break;
|
||||
}
|
||||
case LIST_CHUNK_LOADED: {
|
||||
this.addLoadedChunks(rawdata.array);
|
||||
break;
|
||||
}
|
||||
case LIST_CHUNK_LOADED_CLEAR: {
|
||||
synchronized (this) {
|
||||
chunksLoad.clear();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,15 @@ import com.google.common.collect.HashBasedTable;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import mcp.mobius.opis.data.profilers.Clock.IClock;
|
||||
|
||||
/**
|
||||
* Times Forge event invocations. One instance is shared by the client and server threads, so the tables are only safe
|
||||
* under the instance lock, which readers must also hold while iterating.
|
||||
*/
|
||||
public class ProfilerEvent extends ProfilerAbstract {
|
||||
|
||||
private IClock clock = Clock.getNewClock();
|
||||
/** One per thread; a shared clock would interleave start/stop between sides. */
|
||||
private final ThreadLocal<IClock> clock = ThreadLocal.withInitial(Clock::getNewClock);
|
||||
|
||||
public HashBasedTable<Class<?>, String, DescriptiveStatistics> data = HashBasedTable.create();
|
||||
public HashBasedTable<Class<?>, String, String> dataMod = HashBasedTable.create();
|
||||
|
||||
@@ -17,45 +23,35 @@ public class ProfilerEvent extends ProfilerAbstract {
|
||||
public HashBasedTable<Class<?>, String, String> dataModTick = HashBasedTable.create();
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
public synchronized void reset() {
|
||||
data.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
clock.start();
|
||||
clock.get().start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(Object event, Object pkg, Object handler, Object mod) {
|
||||
clock.stop();
|
||||
clock.get().stop();
|
||||
long delta = clock.get().getDelta();
|
||||
|
||||
String eventName = event.getClass().getSimpleName();
|
||||
if (eventName.contains("TickEvent")) {
|
||||
Class<?> type = event.getClass();
|
||||
String name = pkg + "|" + handler.getClass().getSimpleName();
|
||||
boolean isTick = type.getSimpleName().contains("TickEvent");
|
||||
|
||||
try {
|
||||
String name = (String) pkg + "|" + handler.getClass().getSimpleName();
|
||||
dataTick.get(event.getClass(), name).addValue(clock.getDelta());
|
||||
} catch (Exception e) {
|
||||
String name = (String) pkg + "|" + handler.getClass().getSimpleName();
|
||||
dataTick.put(event.getClass(), name, new DescriptiveStatistics(250));
|
||||
dataModTick.put(event.getClass(), name, ((ModContainer) mod).getName());
|
||||
dataTick.get(event.getClass(), name).addValue(clock.getDelta());
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
try {
|
||||
String name = (String) pkg + "|" + handler.getClass().getSimpleName();
|
||||
data.get(event.getClass(), name).addValue(clock.getDelta());
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
String name = (String) pkg + "|" + handler.getClass().getSimpleName();
|
||||
data.put(event.getClass(), name, new DescriptiveStatistics(250));
|
||||
dataMod.put(event.getClass(), name, ((ModContainer) mod).getName());
|
||||
data.get(event.getClass(), name).addValue(clock.getDelta());
|
||||
} catch (Exception f) {}
|
||||
synchronized (this) {
|
||||
HashBasedTable<Class<?>, String, DescriptiveStatistics> stats = isTick ? dataTick : data;
|
||||
DescriptiveStatistics measures = stats.get(type, name);
|
||||
|
||||
if (measures == null) {
|
||||
measures = new DescriptiveStatistics(250);
|
||||
stats.put(type, name, measures);
|
||||
(isTick ? dataModTick : dataMod)
|
||||
.put(type, name, mod instanceof ModContainer ? ((ModContainer) mod).getName() : "unknown");
|
||||
}
|
||||
measures.addValue(delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
import com.google.common.collect.HashBasedTable;
|
||||
import com.google.common.collect.Table.Cell;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
@@ -165,12 +164,15 @@ public enum OpisClientTickHandler {
|
||||
// ====================================================================================
|
||||
|
||||
ArrayList<DataRenderEvent> timingEvents = new ArrayList<DataRenderEvent>();
|
||||
HashBasedTable<Class<?>, String, DescriptiveStatistics> eventData = ((ProfilerEvent) ProfilerSection.EVENT_INVOKE
|
||||
.getProfiler()).data;
|
||||
HashBasedTable<Class<?>, String, String> eventMod = ((ProfilerEvent) ProfilerSection.EVENT_INVOKE
|
||||
.getProfiler()).dataMod;
|
||||
for (Cell<Class<?>, String, DescriptiveStatistics> cell : eventData.cellSet()) {
|
||||
timingEvents.add(new DataRenderEvent().fill(cell, eventMod.get(cell.getRowKey(), cell.getColumnKey())));
|
||||
ProfilerEvent eventProfiler = (ProfilerEvent) ProfilerSection.EVENT_INVOKE.getProfiler();
|
||||
|
||||
// The event profiler is shared with the server thread; its tables are only safe under its own lock.
|
||||
synchronized (eventProfiler) {
|
||||
for (Cell<Class<?>, String, DescriptiveStatistics> cell : eventProfiler.data.cellSet()) {
|
||||
timingEvents.add(
|
||||
new DataRenderEvent()
|
||||
.fill(cell, eventProfiler.dataMod.get(cell.getRowKey(), cell.getColumnKey())));
|
||||
}
|
||||
}
|
||||
((PanelEventClient) (TabPanelRegistrar.INSTANCE.getTab(SelectedTab.CLIENTEVENTS))).setTable(timingEvents);
|
||||
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package mcp.mobius.opis.events;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
import mcp.mobius.opis.data.holders.basetypes.SerialLong;
|
||||
@@ -30,8 +31,8 @@ public enum PlayerTracker {
|
||||
|
||||
private PlayerTracker() {}
|
||||
|
||||
public HashSet<EntityPlayerMP> playersSwing = new HashSet<EntityPlayerMP>(); // This is the list of players who have
|
||||
// opened the UI
|
||||
public Set<EntityPlayerMP> playersSwing = Collections
|
||||
.newSetFromMap(new ConcurrentHashMap<EntityPlayerMP, Boolean>()); // Players who opened the UI
|
||||
// public HashSet<Player> playersOpis = new HashSet<Player>(); //This is the list of players who have opened the
|
||||
// UI or used the command line
|
||||
public HashMap<String, Boolean> filteredAmount = new HashMap<String, Boolean>(); // Should the entity amount be
|
||||
@@ -40,6 +41,8 @@ public enum PlayerTracker {
|
||||
public HashMap<EntityPlayerMP, SelectedTab> playerTab = new HashMap<EntityPlayerMP, SelectedTab>();
|
||||
private HashSet<String> playerPrivileged = new HashSet<String>();
|
||||
|
||||
private static final int ADMIN_OP_LEVEL = 2;
|
||||
|
||||
public SelectedTab getPlayerSelectedTab(EntityPlayerMP player) {
|
||||
return this.playerTab.get(player);
|
||||
}
|
||||
@@ -53,16 +56,26 @@ public enum PlayerTracker {
|
||||
|
||||
public AccessLevel getPlayerAccessLevel(String name) {
|
||||
|
||||
EntityPlayerMP player = MinecraftServer.getServer().getConfigurationManager().func_152612_a(name);
|
||||
GameProfile profile = player.getGameProfile();
|
||||
MinecraftServer server = MinecraftServer.getServer();
|
||||
if (server == null) return AccessLevel.NONE;
|
||||
|
||||
if (MinecraftServer.getServer().getConfigurationManager().func_152596_g(profile)
|
||||
|| MinecraftServer.getServer().isSinglePlayer())
|
||||
return AccessLevel.ADMIN;
|
||||
// Null while a player is disconnecting or has not finished joining.
|
||||
EntityPlayerMP player = server.getConfigurationManager().func_152612_a(name);
|
||||
if (player == null) return playerPrivileged.contains(name) ? AccessLevel.PRIVILEGED : AccessLevel.NONE;
|
||||
|
||||
// Vanilla check: op level, or the singleplayer owner with cheats on.
|
||||
if (player.canCommandSenderUseCommand(ADMIN_OP_LEVEL, "opis")) return AccessLevel.ADMIN;
|
||||
else if (playerPrivileged.contains(name)) return AccessLevel.PRIVILEGED;
|
||||
else return AccessLevel.NONE;
|
||||
}
|
||||
|
||||
/** These key on players that must not outlive the server they came from. */
|
||||
public void clearSessionState() {
|
||||
this.playersSwing.clear();
|
||||
this.playerDimension.clear();
|
||||
this.playerTab.clear();
|
||||
}
|
||||
|
||||
public void addPrivilegedPlayer(String name, boolean save) {
|
||||
this.playerPrivileged.add(name);
|
||||
if (save) {
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package mcp.mobius.opis.gui.overlay;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import com.gtnewhorizons.navigator.api.model.locations.ILocationProvider;
|
||||
|
||||
import journeymap.api.v2.client.display.PolygonOverlay;
|
||||
import journeymap.api.v2.client.model.MapPolygon;
|
||||
import journeymap.api.v2.client.model.ShapeProperties;
|
||||
import journeymap.api.v2.common.Context;
|
||||
import journeymap.api.v2.common.util.BlockPos;
|
||||
|
||||
/** Chunk-sized native JourneyMap 6 overlay, the only way onto its minimap. Loaded only when JM6 is present. */
|
||||
public final class ChunkPolygonJM6 {
|
||||
|
||||
private static final int CHUNK_SIZE = 16;
|
||||
|
||||
private ChunkPolygonJM6() {}
|
||||
|
||||
public static Collection<PolygonOverlay> create(ILocationProvider location, int fillColor, float fillOpacity) {
|
||||
int x = (int) Math.floor(location.getBlockX());
|
||||
int z = (int) Math.floor(location.getBlockZ());
|
||||
|
||||
ShapeProperties shape = new ShapeProperties().setFillColor(fillColor).setFillOpacity(fillOpacity)
|
||||
.setStrokeColor(0x000000).setStrokeOpacity(1f).setStrokeWidth(1f);
|
||||
|
||||
MapPolygon area = new MapPolygon(
|
||||
new BlockPos(x, 64, z),
|
||||
new BlockPos(x + CHUNK_SIZE, 64, z),
|
||||
new BlockPos(x + CHUNK_SIZE, 64, z + CHUNK_SIZE),
|
||||
new BlockPos(x, 64, z + CHUNK_SIZE));
|
||||
|
||||
PolygonOverlay overlay = new PolygonOverlay("Opis", location.getDimensionId(), shape, area);
|
||||
overlay.setOverlayGroupName(location.getClass().getName())
|
||||
.setActiveUIs(Context.UI.Fullscreen, Context.UI.Minimap);
|
||||
|
||||
return Collections.singletonList(overlay);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package mcp.mobius.opis.gui.overlay;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import com.gtnewhorizons.navigator.api.model.SupportedMods;
|
||||
import com.gtnewhorizons.navigator.api.model.buttons.ButtonManager;
|
||||
|
||||
public class ChunkTimeButtonManager extends ButtonManager {
|
||||
|
||||
public static final ChunkTimeButtonManager INSTANCE = new ChunkTimeButtonManager();
|
||||
|
||||
private ChunkTimeButtonManager() {}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getIcon(SupportedMods mod, String theme) {
|
||||
return new ResourceLocation("opis", "textures/icon/chunk_timing.png");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getButtonText() {
|
||||
return "Opis chunk update time";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
package mcp.mobius.opis.gui.overlay;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import com.gtnewhorizons.navigator.api.model.SupportedMods;
|
||||
import com.gtnewhorizons.navigator.api.model.layers.InteractableLayerManager;
|
||||
import com.gtnewhorizons.navigator.api.model.layers.LayerRenderer;
|
||||
import com.gtnewhorizons.navigator.api.model.layers.UniversalInteractableRenderer;
|
||||
import com.gtnewhorizons.navigator.api.model.steps.LocationInteractableStep;
|
||||
import com.gtnewhorizons.navigator.api.util.ClickPos;
|
||||
import com.gtnewhorizons.navigator.api.util.Util;
|
||||
|
||||
import mcp.mobius.opis.api.IMessageHandler;
|
||||
import mcp.mobius.opis.api.MessageHandlerRegistrar;
|
||||
import mcp.mobius.opis.api.TabPanelRegistrar;
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesChunk;
|
||||
import mcp.mobius.opis.data.holders.basetypes.SerialInt;
|
||||
import mcp.mobius.opis.data.holders.stats.StatsChunk;
|
||||
import mcp.mobius.opis.events.OpisClientTickHandler;
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import mcp.mobius.opis.network.PacketBase;
|
||||
import mcp.mobius.opis.network.PacketManager;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.client.PacketReqData;
|
||||
import mcp.mobius.opis.swing.SelectedTab;
|
||||
import mcp.mobius.opis.swing.SwingUI;
|
||||
import mcp.mobius.opis.swing.panels.timingserver.PanelTimingChunks;
|
||||
import mcp.mobius.opis.swing.widgets.JTableStats;
|
||||
|
||||
/** Navigator layer showing per-chunk server update time as a heatmap. */
|
||||
public class ChunkTimeLayerManager extends InteractableLayerManager implements IMessageHandler {
|
||||
|
||||
public static final ChunkTimeLayerManager INSTANCE = new ChunkTimeLayerManager();
|
||||
|
||||
private List<StatsChunk> chunkStats = Collections.emptyList();
|
||||
private long lastRequest = 0;
|
||||
|
||||
private ChunkTimeLayerManager() {
|
||||
super(ChunkTimeButtonManager.INSTANCE);
|
||||
}
|
||||
|
||||
/** Listens for data without showing a button yet. */
|
||||
public static void init() {
|
||||
MessageHandlerRegistrar.INSTANCE.registerHandler(Message.LIST_TIMING_CHUNK_DIM, INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nullable LayerRenderer addLayerRenderer(InteractableLayerManager manager, SupportedMods mod) {
|
||||
UniversalInteractableRenderer renderer = new UniversalInteractableRenderer(manager)
|
||||
.withClickAction(this::onClick);
|
||||
renderer.withRenderStep(location -> new ChunkTimeRenderStep((ChunkTimeLocation) location));
|
||||
|
||||
if (mod == SupportedMods.JourneyMap && Util.isJourneyMapV6Installed()) {
|
||||
// Native overlays are the only route onto the JM6 minimap.
|
||||
renderer.withJourneyMapV6Overlays(
|
||||
location -> ChunkPolygonJM6.create(
|
||||
location,
|
||||
((ChunkTimeLocation) location).getColor(),
|
||||
modOpis.overlayAlphaTiming / 255f),
|
||||
true);
|
||||
}
|
||||
return renderer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdatePre(int minX, int maxX, int minZ, int maxZ) {
|
||||
// Fullscreen integrations recache enabled layers even when toggled off.
|
||||
if (!isLayerActive()) return;
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - lastRequest < modOpis.overlayRefreshInterval) return;
|
||||
|
||||
lastRequest = now;
|
||||
PacketManager.sendToServer(
|
||||
new PacketReqData(
|
||||
Message.LIST_TIMING_CHUNK_DIM,
|
||||
new SerialInt(Minecraft.getMinecraft().thePlayer.dimension)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<ChunkTimeLocation> generateVisibleLocations(int minBlockX, int minBlockZ, int maxBlockX,
|
||||
int maxBlockZ, int dimension) {
|
||||
List<StatsChunk> stats = chunkStats;
|
||||
|
||||
// Per dimension: the server's top 100 is global, so a hotter dimension would wash this one out.
|
||||
double maxTime = 0;
|
||||
for (StatsChunk stat : stats) {
|
||||
if (stat.getChunk().dim == dimension) maxTime = Math.max(maxTime, stat.getDataSum());
|
||||
}
|
||||
if (maxTime <= 0) return Collections.emptyList();
|
||||
|
||||
List<ChunkTimeLocation> locations = new ArrayList<>();
|
||||
for (StatsChunk stat : stats) {
|
||||
CoordinatesChunk chunk = stat.getChunk();
|
||||
if (chunk.dim != dimension) continue;
|
||||
if (chunk.x + 15 < minBlockX || chunk.x > maxBlockX) continue;
|
||||
if (chunk.z + 15 < minBlockZ || chunk.z > maxBlockZ) continue;
|
||||
|
||||
locations.add(new ChunkTimeLocation(stat, stat.getDataSum() / maxTime));
|
||||
}
|
||||
return locations;
|
||||
}
|
||||
|
||||
private boolean onClick(ClickPos click) {
|
||||
if (!click.isDoubleClick()) return false;
|
||||
|
||||
LocationInteractableStep step = click.getLocationRenderStep();
|
||||
if (step == null || !(step.getLocation() instanceof ChunkTimeLocation)) return false;
|
||||
|
||||
CoordinatesChunk chunk = ((ChunkTimeLocation) step.getLocation()).getStats().getChunk();
|
||||
SwingUI.instance().showTab(SelectedTab.TIMINGCHUNKS);
|
||||
selectChunkRow(chunk);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** The chunk is only in the table if the server reported it this run. */
|
||||
private static void selectChunkRow(CoordinatesChunk chunk) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
PanelTimingChunks panel = (PanelTimingChunks) TabPanelRegistrar.INSTANCE.getTab(SelectedTab.TIMINGCHUNKS);
|
||||
if (panel == null || panel.getTable() == null) return;
|
||||
|
||||
JTableStats table = panel.getTable();
|
||||
List<ISerializable> rows = table.getTableData();
|
||||
if (rows == null) return;
|
||||
|
||||
for (int i = 0; i < rows.size(); i++) {
|
||||
if (!chunk.equals(((StatsChunk) rows.get(i)).getChunk())) continue;
|
||||
|
||||
int view = table.convertRowIndexToView(i);
|
||||
if (view < 0) return;
|
||||
table.setRowSelectionInterval(view, view);
|
||||
table.scrollRectToVisible(table.getCellRect(view, 0, true));
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLayerToggled(boolean toEnable) {
|
||||
super.onLayerToggled(toEnable);
|
||||
// Snapshot is kept so re-enabling redraws immediately.
|
||||
if (toEnable) lastRequest = 0;
|
||||
}
|
||||
|
||||
/** Cached data belongs to one server; keeping it would show its chunks in the next session. */
|
||||
public void clearState() {
|
||||
chunkStats = Collections.emptyList();
|
||||
lastRequest = 0;
|
||||
clearFullCache();
|
||||
}
|
||||
|
||||
/** Exact, because the server always sends this ranked, so equal content arrives in equal order. */
|
||||
private static boolean sameData(List<StatsChunk> a, List<StatsChunk> b) {
|
||||
if (a.size() != b.size()) return false;
|
||||
|
||||
for (int i = 0; i < a.size(); i++) {
|
||||
StatsChunk x = a.get(i), y = b.get(i);
|
||||
if (!x.getChunk().equals(y.getChunk())) return false;
|
||||
if (x.tileEntities != y.tileEntities || x.entities != y.entities) return false;
|
||||
if (Double.compare(x.getDataSum(), y.getDataSum()) != 0) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(Message msg, PacketBase rawdata) {
|
||||
if (msg != Message.LIST_TIMING_CHUNK_DIM) return false;
|
||||
|
||||
List<StatsChunk> stats = new ArrayList<>(rawdata.array.size());
|
||||
for (ISerializable data : rawdata.array) stats.add((StatsChunk) data);
|
||||
|
||||
OpisClientTickHandler.INSTANCE.scheduleOnClientThread(() -> {
|
||||
// Polled every second but only changes per profiler run; rebuilding identical data churns JM6 overlays.
|
||||
if (sameData(chunkStats, stats)) return;
|
||||
chunkStats = stats;
|
||||
clearFullCache();
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package mcp.mobius.opis.gui.overlay;
|
||||
|
||||
import com.gtnewhorizons.navigator.api.model.locations.ILocationProvider;
|
||||
|
||||
import mcp.mobius.opis.data.holders.stats.StatsChunk;
|
||||
|
||||
public class ChunkTimeLocation implements ILocationProvider {
|
||||
|
||||
private final StatsChunk stats;
|
||||
private final double heat;
|
||||
|
||||
/** @param heat update time normalised against the slowest chunk shown, 0..1 */
|
||||
public ChunkTimeLocation(StatsChunk stats, double heat) {
|
||||
this.stats = stats;
|
||||
this.heat = heat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDimensionId() {
|
||||
return stats.getChunk().dim;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBlockX() {
|
||||
return stats.getChunk().x + 0.5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBlockZ() {
|
||||
return stats.getChunk().z + 0.5;
|
||||
}
|
||||
|
||||
public StatsChunk getStats() {
|
||||
return stats;
|
||||
}
|
||||
|
||||
/** Blue for the fastest chunks, red for the slowest. */
|
||||
public int getColor() {
|
||||
int red = (int) Math.ceil(heat * 255.0);
|
||||
return (red << 16) | (255 - red);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package mcp.mobius.opis.gui.overlay;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import com.gtnewhorizons.navigator.api.NavigatorApi;
|
||||
import com.gtnewhorizons.navigator.api.model.steps.UniversalLocationInteractableStep;
|
||||
import com.gtnewhorizons.navigator.api.util.DrawUtils;
|
||||
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesChunk;
|
||||
import mcp.mobius.opis.data.holders.stats.StatsChunk;
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import mcp.mobius.opis.network.PacketManager;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.client.PacketReqData;
|
||||
|
||||
public class ChunkTimeRenderStep extends UniversalLocationInteractableStep<ChunkTimeLocation> {
|
||||
|
||||
public ChunkTimeRenderStep(ChunkTimeLocation location) {
|
||||
super(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(double x, double y, float drawScale, double zoom) {
|
||||
DrawUtils.drawRect(
|
||||
x,
|
||||
y,
|
||||
getAdjustedWidth(),
|
||||
getAdjustedHeight(),
|
||||
location.getColor(),
|
||||
modOpis.overlayAlphaTiming);
|
||||
DrawUtils.drawHollowRect(x, y, getAdjustedWidth(), getAdjustedHeight(), 0x000000, 255);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getTooltip(List<String> list) {
|
||||
StatsChunk stats = location.getStats();
|
||||
CoordinatesChunk chunk = stats.getChunk();
|
||||
|
||||
list.add(String.format("Chunk [%d, %d]", chunk.chunkX, chunk.chunkZ));
|
||||
list.add(
|
||||
modOpis.microseconds ? String.format("%.3f µs", stats.getDataSum() / 1000.0)
|
||||
: String.format("%.5f ms", stats.getDataSum() / 1000.0 / 1000.0));
|
||||
list.add(String.format("%d tile entities, %d entities", stats.tileEntities, stats.entities));
|
||||
list.add(EnumChatFormatting.GRAY + teleportHint());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionKeyPressed() {
|
||||
PacketManager.sendToServer(new PacketReqData(Message.COMMAND_TELEPORT_CHUNK, location.getStats().getChunk()));
|
||||
Minecraft.getMinecraft().setIngameFocus();
|
||||
}
|
||||
|
||||
/** The action key is rebindable, so read the current binding. */
|
||||
static String teleportHint() {
|
||||
return "[" + Keyboard.getKeyName(NavigatorApi.ACTION_KEY.getKeyCode()) + "] Teleport here";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package mcp.mobius.opis.gui.overlay;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import com.gtnewhorizons.navigator.api.model.SupportedMods;
|
||||
import com.gtnewhorizons.navigator.api.model.buttons.ButtonManager;
|
||||
|
||||
public class LoadedChunkButtonManager extends ButtonManager {
|
||||
|
||||
public static final LoadedChunkButtonManager INSTANCE = new LoadedChunkButtonManager();
|
||||
|
||||
private LoadedChunkButtonManager() {}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getIcon(SupportedMods mod, String theme) {
|
||||
return new ResourceLocation("opis", "textures/icon/chunk_loaded.png");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getButtonText() {
|
||||
return "Opis loaded chunks";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
package mcp.mobius.opis.gui.overlay;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import com.gtnewhorizons.navigator.api.model.SupportedMods;
|
||||
import com.gtnewhorizons.navigator.api.model.layers.InteractableLayerManager;
|
||||
import com.gtnewhorizons.navigator.api.model.layers.LayerRenderer;
|
||||
import com.gtnewhorizons.navigator.api.model.layers.UniversalInteractableRenderer;
|
||||
import com.gtnewhorizons.navigator.api.model.steps.LocationInteractableStep;
|
||||
import com.gtnewhorizons.navigator.api.util.ClickPos;
|
||||
import com.gtnewhorizons.navigator.api.util.Util;
|
||||
|
||||
import mcp.mobius.opis.api.IMessageHandler;
|
||||
import mcp.mobius.opis.api.MessageHandlerRegistrar;
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesChunk;
|
||||
import mcp.mobius.opis.data.holders.basetypes.SerialInt;
|
||||
import mcp.mobius.opis.events.OpisClientTickHandler;
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import mcp.mobius.opis.network.PacketBase;
|
||||
import mcp.mobius.opis.network.PacketManager;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.client.PacketReqData;
|
||||
import mcp.mobius.opis.swing.SelectedTab;
|
||||
import mcp.mobius.opis.swing.SwingUI;
|
||||
|
||||
/** Navigator layer showing which chunks the server has loaded, and which are held by a ticket. */
|
||||
public class LoadedChunkLayerManager extends InteractableLayerManager implements IMessageHandler {
|
||||
|
||||
public static final LoadedChunkLayerManager INSTANCE = new LoadedChunkLayerManager();
|
||||
|
||||
/** The server splits a set across several packets and ends it with a clear. */
|
||||
private final List<CoordinatesChunk> pending = new ArrayList<>();
|
||||
private List<CoordinatesChunk> chunks = Collections.emptyList();
|
||||
private long lastRequest = 0;
|
||||
|
||||
private LoadedChunkLayerManager() {
|
||||
super(LoadedChunkButtonManager.INSTANCE);
|
||||
}
|
||||
|
||||
/** Listens for data without showing a button yet. */
|
||||
public static void init() {
|
||||
MessageHandlerRegistrar.INSTANCE.registerHandler(Message.LIST_CHUNK_LOADED, INSTANCE);
|
||||
MessageHandlerRegistrar.INSTANCE.registerHandler(Message.LIST_CHUNK_LOADED_CLEAR, INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nullable LayerRenderer addLayerRenderer(InteractableLayerManager manager, SupportedMods mod) {
|
||||
UniversalInteractableRenderer renderer = new UniversalInteractableRenderer(manager)
|
||||
.withClickAction(this::onClick);
|
||||
renderer.withRenderStep(location -> new LoadedChunkRenderStep((LoadedChunkLocation) location));
|
||||
|
||||
if (mod == SupportedMods.JourneyMap && Util.isJourneyMapV6Installed()) {
|
||||
renderer.withJourneyMapV6Overlays(
|
||||
location -> ChunkPolygonJM6.create(
|
||||
location,
|
||||
((LoadedChunkLocation) location).getColor(),
|
||||
modOpis.overlayAlphaLoaded / 255f),
|
||||
true);
|
||||
}
|
||||
return renderer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdatePre(int minX, int maxX, int minZ, int maxZ) {
|
||||
// Fullscreen integrations recache enabled layers even when toggled off.
|
||||
if (!isLayerActive()) return;
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - lastRequest < modOpis.overlayRefreshInterval) return;
|
||||
|
||||
lastRequest = now;
|
||||
PacketManager.sendToServer(
|
||||
new PacketReqData(
|
||||
Message.LIST_CHUNK_LOADED,
|
||||
new SerialInt(Minecraft.getMinecraft().thePlayer.dimension)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<LoadedChunkLocation> generateVisibleLocations(int minBlockX, int minBlockZ, int maxBlockX,
|
||||
int maxBlockZ, int dimension) {
|
||||
List<LoadedChunkLocation> locations = new ArrayList<>();
|
||||
|
||||
for (CoordinatesChunk chunk : chunks) {
|
||||
if (chunk.dim != dimension) continue;
|
||||
if (chunk.x + 15 < minBlockX || chunk.x > maxBlockX) continue;
|
||||
if (chunk.z + 15 < minBlockZ || chunk.z > maxBlockZ) continue;
|
||||
|
||||
locations.add(new LoadedChunkLocation(chunk));
|
||||
}
|
||||
return locations;
|
||||
}
|
||||
|
||||
/** Only forced chunks have a table to open, so other clicks are left unconsumed. */
|
||||
private boolean onClick(ClickPos click) {
|
||||
if (!click.isDoubleClick()) return false;
|
||||
|
||||
LocationInteractableStep step = click.getLocationRenderStep();
|
||||
if (step == null || !(step.getLocation() instanceof LoadedChunkLocation)) return false;
|
||||
if (!((LoadedChunkLocation) step.getLocation()).isForced()) return false;
|
||||
|
||||
SwingUI.instance().showTab(SelectedTab.FORCELOADS);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLayerToggled(boolean toEnable) {
|
||||
super.onLayerToggled(toEnable);
|
||||
// Snapshot is kept so re-enabling redraws immediately.
|
||||
if (toEnable) lastRequest = 0;
|
||||
}
|
||||
|
||||
/** Exact rather than hashed, and order-independent because the server builds the list from a HashSet. */
|
||||
private static boolean sameChunks(List<CoordinatesChunk> a, List<CoordinatesChunk> b) {
|
||||
if (a.size() != b.size()) return false;
|
||||
|
||||
// CoordinatesChunk.equals ignores metadata, which is the colour, so compare it explicitly.
|
||||
Map<CoordinatesChunk, Byte> previous = new HashMap<>(a.size());
|
||||
for (CoordinatesChunk chunk : a) previous.put(chunk, chunk.metadata);
|
||||
|
||||
for (CoordinatesChunk chunk : b) {
|
||||
Byte metadata = previous.get(chunk);
|
||||
if (metadata == null || metadata != chunk.metadata) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Wipes everything tied to one server, so a later session cannot show its chunks. */
|
||||
public void clearState() {
|
||||
pending.clear();
|
||||
chunks = Collections.emptyList();
|
||||
lastRequest = 0;
|
||||
clearFullCache();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(Message msg, PacketBase rawdata) {
|
||||
if (msg == Message.LIST_CHUNK_LOADED) {
|
||||
for (ISerializable chunk : rawdata.array) pending.add((CoordinatesChunk) chunk);
|
||||
return true;
|
||||
}
|
||||
if (msg != Message.LIST_CHUNK_LOADED_CLEAR) return false;
|
||||
|
||||
// Sent after a batch, so it marks the set complete.
|
||||
List<CoordinatesChunk> updated = new ArrayList<>(pending);
|
||||
pending.clear();
|
||||
OpisClientTickHandler.INSTANCE.scheduleOnClientThread(() -> {
|
||||
// Resent every second even when unchanged; rebuilding identical data churns the JM6 overlays.
|
||||
if (sameChunks(chunks, updated)) return;
|
||||
chunks = updated;
|
||||
clearFullCache();
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package mcp.mobius.opis.gui.overlay;
|
||||
|
||||
import com.gtnewhorizons.navigator.api.model.locations.ILocationProvider;
|
||||
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesChunk;
|
||||
|
||||
public class LoadedChunkLocation implements ILocationProvider {
|
||||
|
||||
private final CoordinatesChunk chunk;
|
||||
|
||||
public LoadedChunkLocation(CoordinatesChunk chunk) {
|
||||
this.chunk = chunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDimensionId() {
|
||||
return chunk.dim;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBlockX() {
|
||||
return chunk.x + 0.5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBlockZ() {
|
||||
return chunk.z + 0.5;
|
||||
}
|
||||
|
||||
public CoordinatesChunk getChunk() {
|
||||
return chunk;
|
||||
}
|
||||
|
||||
/** Held by a ticket rather than normal gameplay loading. */
|
||||
public boolean isForced() {
|
||||
return chunk.metadata != 0;
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return isForced() ? 0x0000FF : 0x00FF00;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package mcp.mobius.opis.gui.overlay;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
import com.gtnewhorizons.navigator.api.model.steps.UniversalLocationInteractableStep;
|
||||
import com.gtnewhorizons.navigator.api.util.DrawUtils;
|
||||
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesChunk;
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import mcp.mobius.opis.network.PacketManager;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.client.PacketReqData;
|
||||
|
||||
public class LoadedChunkRenderStep extends UniversalLocationInteractableStep<LoadedChunkLocation> {
|
||||
|
||||
public LoadedChunkRenderStep(LoadedChunkLocation location) {
|
||||
super(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(double x, double y, float drawScale, double zoom) {
|
||||
DrawUtils.drawRect(
|
||||
x,
|
||||
y,
|
||||
getAdjustedWidth(),
|
||||
getAdjustedHeight(),
|
||||
location.getColor(),
|
||||
modOpis.overlayAlphaLoaded);
|
||||
DrawUtils.drawHollowRect(x, y, getAdjustedWidth(), getAdjustedHeight(), 0x000000, 255);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getTooltip(List<String> list) {
|
||||
CoordinatesChunk chunk = location.getChunk();
|
||||
|
||||
list.add(String.format("Chunk [%d, %d]", chunk.chunkX, chunk.chunkZ));
|
||||
list.add(location.isForced() ? "Force loaded" : "Game loaded");
|
||||
list.add(EnumChatFormatting.GRAY + ChunkTimeRenderStep.teleportHint());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionKeyPressed() {
|
||||
PacketManager.sendToServer(new PacketReqData(Message.COMMAND_TELEPORT_CHUNK, location.getChunk()));
|
||||
Minecraft.getMinecraft().setIngameFocus();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package mcp.mobius.opis.gui.overlay;
|
||||
|
||||
import com.gtnewhorizons.navigator.api.NavigatorApi;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.network.FMLNetworkEvent;
|
||||
import mcp.mobius.opis.events.OpisClientTickHandler;
|
||||
|
||||
/** Entry point for the Navigator layers. Only reachable once Navigator is confirmed present and new enough. */
|
||||
public class OpisLayers {
|
||||
|
||||
private static boolean shown = false;
|
||||
|
||||
/** Listens for data without showing any button yet. */
|
||||
public static void init() {
|
||||
ChunkTimeLayerManager.init();
|
||||
LoadedChunkLayerManager.init();
|
||||
FMLCommonHandler.instance().bus().register(new OpisLayers());
|
||||
}
|
||||
|
||||
/** Cached data belongs to one server; keeping it would show its chunks in the next session. */
|
||||
@SubscribeEvent
|
||||
public void onDisconnect(FMLNetworkEvent.ClientDisconnectionFromServerEvent event) {
|
||||
// Fired on the netty thread; clearState touches Navigator caches the render thread is using.
|
||||
OpisClientTickHandler.INSTANCE.scheduleOnClientThread(() -> {
|
||||
ChunkTimeLayerManager.INSTANCE.clearState();
|
||||
LoadedChunkLayerManager.INSTANCE.clearState();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Deferred until first use of Opis so the buttons do not clutter every map. Must run on the client thread, as
|
||||
* Navigator's layer list is iterated while rendering.
|
||||
*/
|
||||
public static void show() {
|
||||
if (shown) return;
|
||||
shown = true;
|
||||
|
||||
NavigatorApi.registerLayerManager(ChunkTimeLayerManager.INSTANCE);
|
||||
NavigatorApi.registerLayerManager(LoadedChunkLayerManager.INSTANCE);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package mcp.mobius.opis;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
@@ -17,8 +19,11 @@ import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerStartingEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerStoppedEvent;
|
||||
import cpw.mods.fml.common.network.NetworkCheckHandler;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.common.versioning.ComparableVersion;
|
||||
import cpw.mods.fml.relauncher.FMLLaunchHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import mcp.mobius.Tags;
|
||||
import mcp.mobius.mobiuscore.profiler.ProfilerSection;
|
||||
import mcp.mobius.opis.api.MessageHandlerRegistrar;
|
||||
@@ -57,6 +62,7 @@ import mcp.mobius.opis.events.OpisServerTickHandler;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import mcp.mobius.opis.helpers.ModIdentification;
|
||||
import mcp.mobius.opis.network.PacketManager;
|
||||
import mcp.mobius.opis.network.ServerMessageHandler;
|
||||
import mcp.mobius.opis.network.enums.AccessLevel;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.proxy.ProxyServer;
|
||||
@@ -68,6 +74,8 @@ import mcp.mobius.opis.tools.TileLag;
|
||||
@Mod(modid = "Opis", name = "Opis", version = Tags.VERSION, acceptableRemoteVersions = "*")
|
||||
public class modOpis {
|
||||
|
||||
private static final ComparableVersion NAVIGATOR_PROTOCOL_VERSION = new ComparableVersion("1.4.12-mapless");
|
||||
|
||||
@Instance("Opis")
|
||||
public static modOpis instance;
|
||||
|
||||
@@ -83,6 +91,9 @@ public class modOpis {
|
||||
public static boolean rconactive = false;
|
||||
public static String rconpass = "";
|
||||
public static boolean microseconds = true;
|
||||
public static int overlayRefreshInterval = 1000;
|
||||
public static int overlayAlphaTiming = 200;
|
||||
public static int overlayAlphaLoaded = 80;
|
||||
private static int lagGenID = -1;
|
||||
public static volatile CoordinatesBlock selectedBlock = null;
|
||||
public static boolean swingOpen = false;
|
||||
@@ -92,6 +103,8 @@ public class modOpis {
|
||||
public static String commentTables = "Minimum access level to be able to view tables in /opis command. Valid values : NONE, PRIVILEGED, ADMIN";
|
||||
public static String commentOpis = "Minimum access level to be open Opis interface. Valid values : NONE, PRIVILEGED, ADMIN";
|
||||
public static String commentPrivileged = "List of players with PRIVILEGED access level.";
|
||||
public static String commentOverlayRefresh = "How often the map overlays ask the server for fresh data, in milliseconds. Raise it to cut bandwidth; the loaded chunk overlay sends 13 bytes per loaded chunk each time.";
|
||||
public static String commentOverlayAlpha = "Opacity of the map overlay chunk fill. 0 is invisible, 255 is opaque.";
|
||||
|
||||
public modOpis() throws ReflectiveOperationException {
|
||||
final boolean isHeadless = Boolean.getBoolean("java.awt.headless");
|
||||
@@ -104,6 +117,14 @@ public class modOpis {
|
||||
MessageHandlerRegistrar.INSTANCE.suppressUnhandledMsgLogs = FMLLaunchHandler.side().isClient() && isHeadless;
|
||||
}
|
||||
|
||||
/** Opis remains optional remotely, but peers with the Navigator packet additions must speak the same protocol. */
|
||||
@NetworkCheckHandler
|
||||
public boolean checkRemoteVersion(Map<String, String> remoteVersions, Side remoteSide) {
|
||||
String remoteVersion = remoteVersions.get("Opis");
|
||||
return remoteVersion == null || Tags.VERSION.equals(remoteVersion)
|
||||
|| new ComparableVersion(remoteVersion).compareTo(NAVIGATOR_PROTOCOL_VERSION) >= 0;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
|
||||
@@ -113,6 +134,13 @@ public class modOpis {
|
||||
lagGenID = config.get(Configuration.CATEGORY_GENERAL, "laggenerator_id", -1).getInt();
|
||||
profilerMaxTicks = config.get(Configuration.CATEGORY_GENERAL, "profiler.maxpts", 250).getInt();
|
||||
microseconds = config.get(Configuration.CATEGORY_GENERAL, "display.microseconds", true).getBoolean(true);
|
||||
overlayRefreshInterval = config
|
||||
.get(Configuration.CATEGORY_GENERAL, "overlay.refresh_ms", 1000, commentOverlayRefresh, 250, 60000)
|
||||
.getInt();
|
||||
overlayAlphaTiming = config
|
||||
.get(Configuration.CATEGORY_GENERAL, "overlay.alpha.timing", 200, commentOverlayAlpha, 0, 255).getInt();
|
||||
overlayAlphaLoaded = config
|
||||
.get(Configuration.CATEGORY_GENERAL, "overlay.alpha.loaded", 80, commentOverlayAlpha, 0, 255).getInt();
|
||||
rconport = config.get("REMOTE_CONSOLE", "opisrcon.port", 25566).getInt();
|
||||
rconactive = config.get("REMOTE_CONSOLE", "opisrcon.active", false).getBoolean(false);
|
||||
rconpass = config.get("REMOTE_CONSOLE", "opisrcon.password", "").getString();
|
||||
@@ -121,10 +149,11 @@ public class modOpis {
|
||||
AccessLevel minTables = AccessLevel.PRIVILEGED;
|
||||
AccessLevel openOpis = AccessLevel.PRIVILEGED;
|
||||
try {
|
||||
openOpis = AccessLevel.valueOf(config.get("ACCESS_RIGHTS", "opis", "NONE", commentTables).getString());
|
||||
openOpis = AccessLevel.valueOf(config.get("ACCESS_RIGHTS", "opis", "PRIVILEGED", commentOpis).getString());
|
||||
} catch (IllegalArgumentException e) {}
|
||||
try {
|
||||
minTables = AccessLevel.valueOf(config.get("ACCESS_RIGHTS", "tables", "NONE", commentTables).getString());
|
||||
minTables = AccessLevel
|
||||
.valueOf(config.get("ACCESS_RIGHTS", "tables", "PRIVILEGED", commentTables).getString());
|
||||
} catch (IllegalArgumentException e) {}
|
||||
|
||||
Message.setTablesMinimumLevel(minTables);
|
||||
@@ -215,5 +244,8 @@ public class modOpis {
|
||||
@EventHandler
|
||||
public void serverStopped(FMLServerStoppedEvent event) {
|
||||
OpisServerTickHandler.INSTANCE.purgeScheduledCallQueue();
|
||||
OpisServerTickHandler.INSTANCE.cachedAccess.clear();
|
||||
ServerMessageHandler.instance().clearSessionState();
|
||||
PlayerTracker.INSTANCE.clearSessionState();
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,6 @@ import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import com.google.common.collect.HashBasedTable;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Table.Cell;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
@@ -120,24 +119,7 @@ public class PacketManager {
|
||||
ByteArrayDataInput input = ByteStreams.newDataInput(source.array());
|
||||
input.skipBytes(1); // skip the packet identifier byte
|
||||
packet.decode(input);
|
||||
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
|
||||
actionClient(packet);
|
||||
} else {
|
||||
actionServer(ctx, packet);
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private void actionClient(PacketBase packet) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
packet.actionClient(mc.theWorld, mc.thePlayer);
|
||||
}
|
||||
|
||||
private void actionServer(ChannelHandlerContext ctx, PacketBase packet) {
|
||||
EntityPlayerMP player = ((NetHandlerPlayServer) ctx.channel().attr(NetworkRegistry.NET_HANDLER)
|
||||
.get()).playerEntity;
|
||||
packet.actionServer(player.worldObj, player);
|
||||
// Dispatch belongs to HandlerClient/HandlerServer; doing it here too ran every packet twice.
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -292,21 +274,20 @@ public class PacketManager {
|
||||
DataBlockTick totalWorldTick = new DataBlockTick().fill();
|
||||
|
||||
ArrayList<DataEvent> timingEvents = new ArrayList<DataEvent>();
|
||||
HashBasedTable<Class<?>, String, DescriptiveStatistics> eventData = ((ProfilerEvent) ProfilerSection.EVENT_INVOKE
|
||||
.getProfiler()).data;
|
||||
HashBasedTable<Class<?>, String, String> eventMod = ((ProfilerEvent) ProfilerSection.EVENT_INVOKE
|
||||
.getProfiler()).dataMod;
|
||||
for (Cell<Class<?>, String, DescriptiveStatistics> cell : eventData.cellSet()) {
|
||||
timingEvents.add(new DataEvent().fill(cell, eventMod.get(cell.getRowKey(), cell.getColumnKey())));
|
||||
}
|
||||
|
||||
ArrayList<DataEvent> timingTicks = new ArrayList<DataEvent>();
|
||||
HashBasedTable<Class<?>, String, DescriptiveStatistics> eventTickData = ((ProfilerEvent) ProfilerSection.EVENT_INVOKE
|
||||
.getProfiler()).dataTick;
|
||||
HashBasedTable<Class<?>, String, String> eventTickMod = ((ProfilerEvent) ProfilerSection.EVENT_INVOKE
|
||||
.getProfiler()).dataModTick;
|
||||
for (Cell<Class<?>, String, DescriptiveStatistics> cell : eventTickData.cellSet()) {
|
||||
timingTicks.add(new DataEvent().fill(cell, eventTickMod.get(cell.getRowKey(), cell.getColumnKey())));
|
||||
ProfilerEvent eventProfiler = (ProfilerEvent) ProfilerSection.EVENT_INVOKE.getProfiler();
|
||||
|
||||
// The event profiler is shared with the client thread; its tables are only safe under its own lock.
|
||||
synchronized (eventProfiler) {
|
||||
for (Cell<Class<?>, String, DescriptiveStatistics> cell : eventProfiler.data.cellSet()) {
|
||||
timingEvents.add(
|
||||
new DataEvent().fill(cell, eventProfiler.dataMod.get(cell.getRowKey(), cell.getColumnKey())));
|
||||
}
|
||||
for (Cell<Class<?>, String, DescriptiveStatistics> cell : eventProfiler.dataTick.cellSet()) {
|
||||
timingTicks.add(
|
||||
new DataEvent()
|
||||
.fill(cell, eventProfiler.dataModTick.get(cell.getRowKey(), cell.getColumnKey())));
|
||||
}
|
||||
}
|
||||
|
||||
PacketManager.validateAndSend(new NetDataList(Message.LIST_TIMING_HANDLERS, timingTicks), player);
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package mcp.mobius.opis.network;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.monster.EntityMob;
|
||||
@@ -30,6 +34,7 @@ import mcp.mobius.opis.data.managers.EntityManager;
|
||||
import mcp.mobius.opis.data.managers.MetaManager;
|
||||
import mcp.mobius.opis.data.managers.StringCache;
|
||||
import mcp.mobius.opis.data.managers.TileEntityManager;
|
||||
import mcp.mobius.opis.events.OpisServerTickHandler;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
@@ -49,16 +54,76 @@ public class ServerMessageHandler {
|
||||
return _instance;
|
||||
}
|
||||
|
||||
/** Requests that walk chunk or profiler collections and queue work onto the server tick. */
|
||||
private static final EnumSet<Message> THROTTLED = EnumSet.of(
|
||||
Message.LIST_CHUNK_LOADED,
|
||||
Message.LIST_TIMING_CHUNK,
|
||||
Message.LIST_TIMING_CHUNK_DIM,
|
||||
Message.LIST_TIMING_TILEENTS,
|
||||
Message.LIST_TIMING_ENTITIES,
|
||||
Message.LIST_AMOUNT_ENTITIES,
|
||||
Message.LIST_AMOUNT_TILEENTS);
|
||||
|
||||
/** Below the map overlay's 250ms floor, leaving headroom for jitter. */
|
||||
private static final long MIN_REQUEST_INTERVAL_MS = 200;
|
||||
|
||||
/** Weak so entries drop with the player; guarded as each connection has its own thread. */
|
||||
private final Map<EntityPlayerMP, EnumMap<Message, Long>> lastRequest = new WeakHashMap<>();
|
||||
|
||||
/** Latest queued job per player and message: a stalled tick cannot build a backlog of stale scans. */
|
||||
private final Map<EntityPlayerMP, EnumMap<Message, Runnable>> queued = new WeakHashMap<>();
|
||||
|
||||
private void schedule(Message msg, EntityPlayerMP player, Runnable job) {
|
||||
synchronized (this) {
|
||||
EnumMap<Message, Runnable> jobs = queued.computeIfAbsent(player, ignored -> new EnumMap<>(Message.class));
|
||||
if (jobs.put(msg, job) != null) return;
|
||||
}
|
||||
|
||||
OpisServerTickHandler.INSTANCE.scheduleOnServerThread(() -> {
|
||||
Runnable latest;
|
||||
synchronized (this) {
|
||||
EnumMap<Message, Runnable> jobs = queued.get(player);
|
||||
latest = jobs.remove(msg);
|
||||
if (jobs.isEmpty()) queued.remove(player);
|
||||
}
|
||||
latest.run();
|
||||
});
|
||||
}
|
||||
|
||||
public synchronized void clearSessionState() {
|
||||
lastRequest.clear();
|
||||
queued.clear();
|
||||
}
|
||||
|
||||
private synchronized boolean isThrottled(Message msg, EntityPlayerMP player) {
|
||||
if (!THROTTLED.contains(msg)) return false;
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
EnumMap<Message, Long> perMessage = lastRequest
|
||||
.computeIfAbsent(player, ignored -> new EnumMap<>(Message.class));
|
||||
Long last = perMessage.get(msg);
|
||||
|
||||
if (last != null && now - last < MIN_REQUEST_INTERVAL_MS) return true;
|
||||
|
||||
perMessage.put(msg, now);
|
||||
return false;
|
||||
}
|
||||
|
||||
public void handle(Message maintype, ISerializable param1, ISerializable param2, EntityPlayerMP player) {
|
||||
String name = player.getGameProfile().getName();
|
||||
|
||||
// Dropped rather than punished: access can be revoked while a client is still polling.
|
||||
if (isThrottled(maintype, player)) return;
|
||||
|
||||
if (maintype == Message.LIST_CHUNK_LOADED) {
|
||||
PlayerTracker.INSTANCE.playerDimension.put(player, ((SerialInt) param1).value);
|
||||
PacketManager.validateAndSend(new NetDataCommand(Message.LIST_CHUNK_LOADED_CLEAR), player);
|
||||
PacketManager.splitAndSend(
|
||||
Message.LIST_CHUNK_LOADED,
|
||||
ChunkManager.INSTANCE.getLoadedChunks(((SerialInt) param1).value),
|
||||
player);
|
||||
int dim = ((SerialInt) param1).value;
|
||||
schedule(maintype, player, () -> {
|
||||
PlayerTracker.INSTANCE.playerDimension.put(player, dim);
|
||||
PacketManager
|
||||
.splitAndSend(Message.LIST_CHUNK_LOADED, ChunkManager.INSTANCE.getLoadedChunks(dim), player);
|
||||
// Sent last: the client treats it as "batch complete" and only then shows it.
|
||||
PacketManager.validateAndSend(new NetDataCommand(Message.LIST_CHUNK_LOADED_CLEAR), player);
|
||||
});
|
||||
} else if (maintype == Message.LIST_TIMING_TILEENTS) {
|
||||
ArrayList<DataBlockTileEntity> timingTileEnts = TileEntityManager.INSTANCE.getWorses(100);
|
||||
DataTiming totalTime = TileEntityManager.INSTANCE.getTotalUpdateTime();
|
||||
@@ -77,8 +142,17 @@ public class ServerMessageHandler {
|
||||
// OpisPacketHandler_OLD.validateAndSend(NetDataValue_OLD.create(Message.VALUE_TIMING_HANDLERS, totalTime),
|
||||
// player);
|
||||
} else if (maintype == Message.LIST_TIMING_CHUNK) {
|
||||
ArrayList<StatsChunk> timingChunks = ChunkManager.INSTANCE.getTopChunks(100);
|
||||
PacketManager.validateAndSend(new NetDataList(Message.LIST_TIMING_CHUNK, timingChunks), player);
|
||||
schedule(maintype, player, () -> {
|
||||
ArrayList<StatsChunk> timingChunks = ChunkManager.INSTANCE.getTopChunks(100);
|
||||
PacketManager.validateAndSend(new NetDataList(Message.LIST_TIMING_CHUNK, timingChunks), player);
|
||||
});
|
||||
} else if (maintype == Message.LIST_TIMING_CHUNK_DIM) {
|
||||
// Ranked within one dimension, and answered on its own message so the Swing table keeps the global list.
|
||||
int dim = ((SerialInt) param1).value;
|
||||
schedule(maintype, player, () -> {
|
||||
ArrayList<StatsChunk> timingChunks = ChunkManager.INSTANCE.getTopChunks(100, dim);
|
||||
PacketManager.validateAndSend(new NetDataList(Message.LIST_TIMING_CHUNK_DIM, timingChunks), player);
|
||||
});
|
||||
} else if (maintype == Message.VALUE_TIMING_WORLDTICK) {
|
||||
PacketManager.validateAndSend(
|
||||
new NetDataValue(Message.VALUE_TIMING_WORLDTICK, new DataBlockTick().fill()),
|
||||
@@ -100,8 +174,14 @@ public class ServerMessageHandler {
|
||||
PlayerTracker.INSTANCE.filteredAmount.put(name, true);
|
||||
} else if (maintype == Message.COMMAND_FILTERING_FALSE) {
|
||||
PlayerTracker.INSTANCE.filteredAmount.put(name, false);
|
||||
} else if (maintype == Message.COMMAND_OPEN_SWING) {
|
||||
SelectedTab tab = SelectedTab.values()[((SerialInt) param1).value];
|
||||
schedule(maintype, player, () -> {
|
||||
PlayerTracker.INSTANCE.playerTab.put(player, tab);
|
||||
if (PlayerTracker.INSTANCE.playersSwing.add(player)) PacketManager.sendFullUpdate(player);
|
||||
});
|
||||
} else if (maintype == Message.COMMAND_UNREGISTER) {
|
||||
PlayerTracker.INSTANCE.playerDimension.remove(player);
|
||||
schedule(maintype, player, () -> PlayerTracker.INSTANCE.playerDimension.remove(player));
|
||||
} else if (maintype == Message.COMMAND_START) {
|
||||
MetaManager.reset();
|
||||
modOpis.profilerRun = true;
|
||||
@@ -140,7 +220,7 @@ public class ServerMessageHandler {
|
||||
String entname = StringCache.INSTANCE.getString(((SerialInt) param1).value);
|
||||
EntityManager.INSTANCE.killAll(entname);
|
||||
} else if (maintype == Message.COMMAND_UNREGISTER_SWING) {
|
||||
PlayerTracker.INSTANCE.playersSwing.remove(player);
|
||||
schedule(maintype, player, () -> PlayerTracker.INSTANCE.playersSwing.remove(player));
|
||||
} else if (maintype == Message.STATUS_TIME_LAST_RUN) {
|
||||
PacketManager.validateAndSend(
|
||||
new NetDataValue(Message.STATUS_TIME_LAST_RUN, new SerialLong(ProfilerSection.timeStampLastRun)),
|
||||
@@ -161,7 +241,7 @@ public class ServerMessageHandler {
|
||||
PacketManager.validateAndSend(new NetDataValue(Message.STATUS_PING, param1), player);
|
||||
} else if (maintype == Message.SWING_TAB_CHANGED) {
|
||||
SelectedTab tab = SelectedTab.values()[((SerialInt) param1).value];
|
||||
PlayerTracker.INSTANCE.playerTab.put(player, tab);
|
||||
schedule(maintype, player, () -> PlayerTracker.INSTANCE.playerTab.put(player, tab));
|
||||
} else if (maintype == Message.LIST_ORPHAN_TILEENTS) {
|
||||
PacketManager.validateAndSend(new NetDataCommand(Message.LIST_ORPHAN_TILEENTS_CLEAR), player);
|
||||
PacketManager.splitAndSend(Message.LIST_ORPHAN_TILEENTS, TileEntityManager.INSTANCE.getOrphans(), player);
|
||||
|
||||
@@ -85,7 +85,10 @@ public enum Message {
|
||||
PLAYER_STATUS_UPDATE, // Update for the players (name, position, offline/online, etc)
|
||||
CONNECTION_STATUS,
|
||||
|
||||
CHAT_MSG;
|
||||
CHAT_MSG,
|
||||
|
||||
/** Dimension-scoped copy of LIST_TIMING_CHUNK, so overlay polling cannot overwrite the Swing table. */
|
||||
LIST_TIMING_CHUNK_DIM;
|
||||
|
||||
public static final Message[] VALUES = values();
|
||||
|
||||
@@ -138,6 +141,7 @@ public enum Message {
|
||||
Message.LIST_TIMING_ENTITIES.setAccessLevel(level);
|
||||
Message.LIST_TIMING_HANDLERS.setAccessLevel(level);
|
||||
Message.LIST_TIMING_CHUNK.setAccessLevel(level);
|
||||
Message.LIST_TIMING_CHUNK_DIM.setAccessLevel(level);
|
||||
Message.LIST_TIMING_TILEENTS_PER_CLASS.setAccessLevel(level);
|
||||
Message.LIST_TIMING_ENTITIES_PER_CLASS.setAccessLevel(level);
|
||||
Message.LIST_TIMING_HANDLERS.setAccessLevel(level);
|
||||
|
||||
@@ -4,18 +4,21 @@ import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.versioning.VersionParser;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import mcp.mobius.mobiuscore.profiler.ProfilerSection;
|
||||
import mcp.mobius.opis.api.IMessageHandler;
|
||||
import mcp.mobius.opis.api.MessageHandlerRegistrar;
|
||||
import mcp.mobius.opis.api.TabPanelRegistrar;
|
||||
import mcp.mobius.opis.data.client.DataCache;
|
||||
import mcp.mobius.opis.data.managers.ChunkManager;
|
||||
import mcp.mobius.opis.data.managers.MetaManager;
|
||||
import mcp.mobius.opis.data.managers.StringCache;
|
||||
import mcp.mobius.opis.events.OpisClientTickHandler;
|
||||
import mcp.mobius.opis.gui.font.Fonts;
|
||||
import mcp.mobius.opis.gui.font.TrueTypeFont;
|
||||
import mcp.mobius.opis.gui.overlay.OpisLayers;
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import mcp.mobius.opis.network.PacketBase;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
@@ -192,12 +195,30 @@ public class ProxyClient extends ProxyServer implements IMessageHandler {
|
||||
MessageHandlerRegistrar.INSTANCE.registerHandler(Message.CLIENT_START_PROFILING, modOpis.proxy);
|
||||
MessageHandlerRegistrar.INSTANCE.registerHandler(Message.CLIENT_SHOW_RENDER_TICK, modOpis.proxy);
|
||||
|
||||
MessageHandlerRegistrar.INSTANCE.registerHandler(Message.LIST_TIMING_CHUNK, ChunkManager.INSTANCE);
|
||||
MessageHandlerRegistrar.INSTANCE.registerHandler(Message.LIST_CHUNK_LOADED, ChunkManager.INSTANCE);
|
||||
MessageHandlerRegistrar.INSTANCE.registerHandler(Message.LIST_CHUNK_LOADED_CLEAR, ChunkManager.INSTANCE);
|
||||
|
||||
MessageHandlerRegistrar.INSTANCE.registerHandler(Message.STATUS_STRINGUPD, StringCache.INSTANCE);
|
||||
MessageHandlerRegistrar.INSTANCE.registerHandler(Message.STATUS_STRINGUPD_FULL, StringCache.INSTANCE);
|
||||
|
||||
MessageHandlerRegistrar.INSTANCE.registerHandler(Message.CLIENT_SHOW_SWING, modOpis.proxy);
|
||||
|
||||
// Keeps every Navigator class behind this branch so Opis still loads without it.
|
||||
if (isNavigatorSupported()) {
|
||||
OpisLayers.init();
|
||||
}
|
||||
}
|
||||
|
||||
/** The layers use APIs added in Navigator 1.1.7, and nothing pins the version for an optional dependency. */
|
||||
private static boolean isNavigatorSupported() {
|
||||
ModContainer navigator = Loader.instance().getIndexedModList().get("navigator");
|
||||
if (navigator == null) return false;
|
||||
|
||||
if (VersionParser.parseRange("[1.1.7,)").containsVersion(navigator.getProcessedVersion())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
modOpis.log.warn(
|
||||
"Navigator {} is too old for the Opis map overlays, which need 1.1.7 or newer. Overlays disabled.",
|
||||
navigator.getVersion());
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -216,6 +237,13 @@ public class ProxyClient extends ProxyServer implements IMessageHandler {
|
||||
});
|
||||
break;
|
||||
}
|
||||
case CLIENT_SHOW_SWING: {
|
||||
// First /opis is what puts the layer buttons on the map.
|
||||
if (isNavigatorSupported()) {
|
||||
OpisClientTickHandler.INSTANCE.scheduleOnClientThread(OpisLayers::show);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CLIENT_SHOW_RENDER_TICK: {
|
||||
modOpis.log.log(Level.INFO, "=== RENDER TICK ===");
|
||||
// ArrayList<DataHandler> stats = TickHandlerManager.getCumulatedStatsServer();
|
||||
|
||||
@@ -2,6 +2,7 @@ package mcp.mobius.opis.swing;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowListener;
|
||||
import java.util.HashSet;
|
||||
@@ -22,6 +23,7 @@ import net.minecraft.client.gui.GuiChat;
|
||||
|
||||
import mcp.mobius.opis.api.IMessageHandler;
|
||||
import mcp.mobius.opis.api.ITabPanel;
|
||||
import mcp.mobius.opis.api.TabPanelRegistrar;
|
||||
import mcp.mobius.opis.data.holders.basetypes.SerialInt;
|
||||
import mcp.mobius.opis.events.OpisClientTickHandler;
|
||||
import mcp.mobius.opis.modOpis;
|
||||
@@ -111,6 +113,27 @@ public class SwingUI extends JFrame implements WindowListener, ChangeListener, I
|
||||
return tabbedPane;
|
||||
}
|
||||
|
||||
/** Tabs under a section live in a nested pane, so every enclosing pane has to be switched too. */
|
||||
public void showTab(SelectedTab tab) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
Component child = TabPanelRegistrar.INSTANCE.getTabAsPanel(tab);
|
||||
|
||||
for (Container parent = child == null ? null : child.getParent(); parent
|
||||
!= null; parent = parent.getParent()) {
|
||||
if (parent instanceof JTabbedPane) {
|
||||
((JTabbedPane) parent).setSelectedComponent(child);
|
||||
}
|
||||
child = parent;
|
||||
}
|
||||
|
||||
modOpis.swingOpen = true;
|
||||
setVisible(true);
|
||||
toFront();
|
||||
// Closing the window unregistered us, so pushed table data would otherwise stay frozen.
|
||||
PacketManager.sendToServer(new PacketReqData(Message.COMMAND_OPEN_SWING, new SerialInt(tab.ordinal())));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(Message msg, PacketBase rawdata) {
|
||||
switch (msg) {
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 663 B |
Binary file not shown.
|
After Width: | Height: | Size: 798 B |
Reference in new issue
Block a user