mirror of
https://github.com/GTNewHorizons/Opis.git
synced 2026-11-22 05:02:17 +00:00
Directory structure for ForgeGradle
This commit is contained in:
1 parent
3d8319dc6b
commit
04764c83c9
214 files changed
+104
-6
No files matched your search
@@ -0,0 +1,8 @@
|
||||
package mcp.mobius.opis.api;
|
||||
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataRaw;
|
||||
|
||||
public interface IMessageHandler {
|
||||
public boolean handleMessage(Message msg, NetDataRaw rawdata);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package mcp.mobius.opis.api;
|
||||
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.swing.SelectedTab;
|
||||
|
||||
public interface ITabPanel {
|
||||
SelectedTab getSelectedTab();
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package mcp.mobius.opis.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataRaw;
|
||||
|
||||
public enum MessageHandlerRegistrar {
|
||||
INSTANCE;
|
||||
|
||||
private HashMap<Message, HashSet<IMessageHandler>> msgHandlers = new HashMap<Message, HashSet<IMessageHandler>>();
|
||||
|
||||
public void registerHandler(Message msg, IMessageHandler handler){
|
||||
if (!msgHandlers.containsKey(msg))
|
||||
msgHandlers.put(msg, new HashSet<IMessageHandler>());
|
||||
|
||||
msgHandlers.get(msg).add(handler);
|
||||
}
|
||||
|
||||
public void routeMessage(Message msg, NetDataRaw rawdata){
|
||||
|
||||
if (msgHandlers.containsKey(msg)){
|
||||
for (IMessageHandler handler : msgHandlers.get(msg)){
|
||||
if (!handler.handleMessage(msg, rawdata)){
|
||||
modOpis.log.warning(String.format("Unhandled msg %s in handler %s", msg, handler));
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
modOpis.log.warning(String.format("Unhandled msg : %s", msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package mcp.mobius.opis.api;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import mcp.mobius.opis.data.holders.basetypes.SerialInt;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.client.Packet_ReqData;
|
||||
import mcp.mobius.opis.swing.SelectedTab;
|
||||
import mcp.mobius.opis.swing.SwingUI;
|
||||
|
||||
public enum TabPanelRegistrar implements ChangeListener{
|
||||
INSTANCE;
|
||||
|
||||
//private ArrayList<ITabPanel> panels = new ArrayList<ITabPanel>();
|
||||
//private HashMap<String, ITabPanel> lookup = new HashMap<String, ITabPanel>();
|
||||
private HashMap<String, JTabbedPane> sections = new HashMap<String, JTabbedPane>();
|
||||
private HashMap<SelectedTab, ITabPanel> lookup = new HashMap<SelectedTab, ITabPanel>();
|
||||
|
||||
public JTabbedPane registerSection(String name){
|
||||
JTabbedPane pane = new JTabbedPane();
|
||||
pane.addChangeListener(this);
|
||||
this.sections.put(name, pane);
|
||||
SwingUI.instance().getTabbedPane().addTab(name, pane);
|
||||
return pane;
|
||||
}
|
||||
|
||||
public ITabPanel registerTab(ITabPanel panel, String name){
|
||||
this.lookup.put(panel.getSelectedTab(), panel);
|
||||
SwingUI.instance().getTabbedPane().addTab(name, (JPanel)panel);
|
||||
return panel;
|
||||
}
|
||||
|
||||
public ITabPanel registerTab(ITabPanel panel, String name, String section){
|
||||
this.lookup.put(panel.getSelectedTab(), panel);
|
||||
this.sections.get(section).addTab(name, (JPanel)panel);
|
||||
return panel;
|
||||
}
|
||||
|
||||
public ITabPanel getTab(SelectedTab refname){
|
||||
return lookup.get(refname);
|
||||
}
|
||||
|
||||
public JPanel getTabAsPanel(SelectedTab refname){
|
||||
return (JPanel)lookup.get(refname);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
Component source = ((JTabbedPane)e.getSource()).getSelectedComponent();
|
||||
|
||||
if (source instanceof ITabPanel){
|
||||
ITabPanel panel = (ITabPanel)source;
|
||||
PacketDispatcher.sendPacketToServer(Packet_ReqData.create(Message.SWING_TAB_CHANGED, new SerialInt(panel.getSelectedTab().ordinal())));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
public ArrayList<ITabPanel> getTabs(){
|
||||
return this.panels;
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package mcp.mobius.opis.commands;
|
||||
|
||||
public interface IOpisCommand {
|
||||
String getDescription();
|
||||
String getCommandNameOpis();
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package mcp.mobius.opis.commands.client;
|
||||
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataCommand;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
public class CommandClientShowRenderTick extends CommandBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "opis_ctick";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender icommandsender) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender icommandsender, String[] astring) {
|
||||
if (icommandsender instanceof Player)
|
||||
OpisPacketHandler.validateAndSend(NetDataCommand.create(Message.CLIENT_SHOW_RENDER_TICK), (Player)icommandsender);
|
||||
//((EntityPlayerMP)icommandsender).playerNetServerHandler.sendPacketToPlayer(NetDataCommand.create(Message.CLIENT_SHOW_RENDER_TICK));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender sender)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package mcp.mobius.opis.commands.client;
|
||||
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataCommand;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
public class CommandClientStart extends CommandBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "opis_cstart";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender icommandsender) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender icommandsender, String[] astring) {
|
||||
if (icommandsender instanceof Player)
|
||||
OpisPacketHandler.validateAndSend(NetDataCommand.create(Message.CLIENT_START_PROFILING), (Player)icommandsender);
|
||||
//((EntityPlayerMP)icommandsender).playerNetServerHandler.sendPacketToPlayer(NetDataCommand.create(Message.CLIENT_START_PROFILING));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender sender)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package mcp.mobius.opis.commands.client;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import mcp.mobius.opis.network.ServerMessageHandler;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataCommand;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
|
||||
public class CommandOpis extends CommandBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "opis";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender icommandsender) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender icommandsender, String[] astring) {
|
||||
if (!(icommandsender instanceof Player)){
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText("You are not a normal client and can't open the Swing interface."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Message.COMMAND_OPEN_SWING.canPlayerUseCommand((Player)icommandsender)){
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText("Your access level prevents you from doing that."));
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerTracker.instance().playersSwing.add((Player)icommandsender);
|
||||
//((EntityPlayerMP)icommandsender).playerNetServerHandler.sendPacketToPlayer(NetDataCommand.create(Message.CLIENT_SHOW_SWING));
|
||||
if (icommandsender instanceof Player)
|
||||
OpisPacketHandler.validateAndSend(NetDataCommand.create(Message.CLIENT_SHOW_SWING), (Player)icommandsender);
|
||||
OpisPacketHandler.sendFullUpdate((Player)icommandsender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender sender){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package mcp.mobius.opis.commands.server;
|
||||
|
||||
import mcp.mobius.opis.commands.IOpisCommand;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.MemoryConnection;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
|
||||
public class CommandAddPrivileged extends CommandBase implements IOpisCommand{
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "opis_addpriv";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender icommandsender) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender icommandsender, String[] astring) {
|
||||
PlayerTracker.instance().addPrivilegedPlayer(astring[0]);
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("Player %s added to Opis user list", astring[0])));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender sender)
|
||||
{
|
||||
if (sender instanceof DedicatedServer) return true;
|
||||
if ((sender instanceof EntityPlayerMP) && ((EntityPlayerMP)sender).playerNetServerHandler.netManager instanceof MemoryConnection) return true;
|
||||
if (!(sender instanceof DedicatedServer) && !(sender instanceof EntityPlayerMP)) return true;
|
||||
return PlayerTracker.instance().isAdmin(((EntityPlayerMP)sender).username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Add a user to the privileged list of users.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandNameOpis() {
|
||||
return "opis_addpriv";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package mcp.mobius.opis.commands.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import mcp.mobius.opis.commands.IOpisCommand;
|
||||
import mcp.mobius.opis.data.holders.basetypes.AmountHolder;
|
||||
import mcp.mobius.opis.data.managers.EntityManager;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataList;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.MemoryConnection;
|
||||
import net.minecraft.network.rcon.RConConsoleSource;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
|
||||
public class CommandAmountEntities extends CommandBase implements IOpisCommand{
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "opis_nent";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandNameOpis() {
|
||||
return this.getCommandName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender icommandsender) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender icommandsender, String[] astring) {
|
||||
if (icommandsender instanceof Player){
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText("DEPRECATED ! Please run /opis instead."));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ArrayList<AmountHolder> ents;
|
||||
|
||||
if (astring.length == 1 && astring[0].equals("all"))
|
||||
ents = EntityManager.INSTANCE.getCumulativeEntities(false);
|
||||
else
|
||||
ents = EntityManager.INSTANCE.getCumulativeEntities(true);
|
||||
|
||||
for (AmountHolder s : ents)
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("%s : %s", s.key, s.value)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender sender)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Opens a summary of the number of entities on the server, by type.";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package mcp.mobius.opis.commands.server;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.google.common.collect.ImmutableSetMultimap;
|
||||
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import mcp.mobius.opis.commands.IOpisCommand;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import net.minecraftforge.common.ForgeChunkManager.Ticket;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
public class CommandChunkDump extends CommandBase implements IOpisCommand{
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "chunkdump";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandNameOpis() {
|
||||
return this.getCommandName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender icommandsender) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender icommandsender, String[] astring) {
|
||||
modOpis.log.log(Level.INFO, "== CHUNK DUMP ==");
|
||||
|
||||
HashMap<ChunkCoordIntPair, Boolean> chunkStatus = new HashMap<ChunkCoordIntPair, Boolean>();
|
||||
|
||||
Integer[] worldIDs = DimensionManager.getIDs();
|
||||
for (Integer worldID : worldIDs){
|
||||
Set<ChunkCoordIntPair> persistantChunks = DimensionManager.getWorld(worldID).getPersistentChunks().keySet();
|
||||
Set<ChunkCoordIntPair> chunks = (Set<ChunkCoordIntPair>)DimensionManager.getWorld(worldID).activeChunkSet;
|
||||
|
||||
for (ChunkCoordIntPair chunk : chunks){
|
||||
modOpis.log.log(Level.INFO, String.format("Dim : %s, %s, Forced : %s", worldID, chunk, persistantChunks.contains(chunk)));
|
||||
chunkStatus.put(chunk, persistantChunks.contains(chunk));
|
||||
}
|
||||
}
|
||||
|
||||
//((EntityPlayerMP)icommandsender).playerNetServerHandler.sendPacketToPlayer(Packet_LoadedChunks.create(chunkStatus));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender par1ICommandSender)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Unused";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package mcp.mobius.opis.commands.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import mcp.mobius.opis.commands.IOpisCommand;
|
||||
import mcp.mobius.opis.data.holders.stats.StatsChunk;
|
||||
import mcp.mobius.opis.data.managers.ChunkManager;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataList;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.MemoryConnection;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
|
||||
public class CommandChunkList extends CommandBase implements IOpisCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "opis_chunk";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandNameOpis() {
|
||||
return this.getCommandName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender icommandsender) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender icommandsender, String[] astring) {
|
||||
if (icommandsender instanceof Player){
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText("DEPRECATED ! Please run /opis instead."));
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<StatsChunk> chunks = new ArrayList<StatsChunk>();
|
||||
|
||||
if (astring.length == 0)
|
||||
chunks = ChunkManager.INSTANCE.getTopChunks(20);
|
||||
else
|
||||
try{
|
||||
chunks = ChunkManager.INSTANCE.getTopChunks(Integer.valueOf(astring.length));
|
||||
}catch (Exception e){return;}
|
||||
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText("[DIM X Z] Time NTEs"));
|
||||
for (StatsChunk stat : chunks){
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(stat.toString()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender sender)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Shows the 20 slowest chunks, in respect to tile entities.";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package mcp.mobius.opis.commands.server;
|
||||
|
||||
import mcp.mobius.opis.events.OpisServerEventHandler;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.MemoryConnection;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
|
||||
public class CommandEntityCreate extends CommandBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "opis_enttrace";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender icommandsender) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender icommandsender, String[] astring) {
|
||||
|
||||
if (astring.length == 1 && astring[0].equals("full")){
|
||||
OpisServerEventHandler.printEntityFull = true;
|
||||
OpisServerEventHandler.printEntityTrace = true;
|
||||
} else {
|
||||
OpisServerEventHandler.printEntityTrace = !OpisServerEventHandler.printEntityTrace;
|
||||
OpisServerEventHandler.printEntityFull = false;
|
||||
}
|
||||
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("Entity trace is %s", OpisServerEventHandler.printEntityTrace)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender sender)
|
||||
{
|
||||
if (sender instanceof DedicatedServer) return true;
|
||||
if ((sender instanceof EntityPlayerMP) && ((EntityPlayerMP)sender).playerNetServerHandler.netManager instanceof MemoryConnection) return true;
|
||||
if (!(sender instanceof DedicatedServer) && !(sender instanceof EntityPlayerMP)) return true;
|
||||
return PlayerTracker.instance().isPrivileged(((EntityPlayerMP)sender).username);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package mcp.mobius.opis.commands.server;
|
||||
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import mcp.mobius.opis.commands.IOpisCommand;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.MemoryConnection;
|
||||
import net.minecraft.network.packet.Packet3Chat;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
|
||||
public class CommandFrequency extends CommandBase implements IOpisCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "opis_delay";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandNameOpis() {
|
||||
return this.getCommandName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender icommandsender) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender icommandsender, String[] astring) {
|
||||
if (astring.length < 1) return;
|
||||
try{
|
||||
modOpis.profilerDelay = Integer.valueOf(astring[0]);
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("\u00A7oOpis delay set to %s ticks.", astring[0])));
|
||||
|
||||
} catch (Exception e){}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender sender)
|
||||
{
|
||||
if (sender instanceof DedicatedServer) return true;
|
||||
if ((sender instanceof EntityPlayerMP) && ((EntityPlayerMP)sender).playerNetServerHandler.netManager instanceof MemoryConnection) return true;
|
||||
if (!(sender instanceof DedicatedServer) && !(sender instanceof EntityPlayerMP)) return true;
|
||||
return PlayerTracker.instance().isPrivileged(((EntityPlayerMP)sender).username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Sets the delay in ticks between 2 data points.";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package mcp.mobius.opis.commands.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import mcp.mobius.opis.commands.IOpisCommand;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataHandler;
|
||||
import mcp.mobius.opis.data.managers.TickHandlerManager;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataList;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.MemoryConnection;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
|
||||
public class CommandHandler extends CommandBase implements IOpisCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "opis_handler";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandNameOpis() {
|
||||
return this.getCommandName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender icommandsender) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender icommandsender, String[] astring) {
|
||||
if (icommandsender instanceof Player){
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText("DEPRECATED ! Please run /opis instead."));
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<DataHandler> stats = TickHandlerManager.getCumulatedStatsServer();
|
||||
|
||||
for (DataHandler s : stats)
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("%s : %.2f", s.name, s.update.toString())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender sender)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Opens timing data for server side tick handlers.";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package mcp.mobius.opis.commands.server;
|
||||
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import mcp.mobius.opis.commands.IOpisCommand;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.MemoryConnection;
|
||||
import net.minecraft.network.packet.Packet3Chat;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
|
||||
public class CommandHelp extends CommandBase implements IOpisCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "opis_help";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandNameOpis() {
|
||||
return this.getCommandName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender icommandsender) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender icommandsender, String[] astring) {
|
||||
IOpisCommand[] commands = {
|
||||
new CommandStart(),
|
||||
new CommandStop(),
|
||||
new CommandReset(),
|
||||
new CommandFrequency(),
|
||||
new CommandTicks(),
|
||||
|
||||
new CommandChunkList(),
|
||||
new CommandTimingTileEntities(),
|
||||
|
||||
new CommandTimingEntities(),
|
||||
new CommandAmountEntities(),
|
||||
|
||||
new CommandKill(),
|
||||
new CommandKillAll(),
|
||||
|
||||
new CommandHandler(),
|
||||
|
||||
new CommandAddPrivileged(),
|
||||
new CommandRmPrivileged()
|
||||
};
|
||||
|
||||
for (IOpisCommand cmd : commands)
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("/%s : %s", cmd.getCommandNameOpis(), cmd.getDescription())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender sender)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "This message.";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package mcp.mobius.opis.commands.server;
|
||||
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import mcp.mobius.opis.commands.IOpisCommand;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.MemoryConnection;
|
||||
import net.minecraft.network.packet.Packet3Chat;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
||||
public class CommandKill extends CommandBase implements IOpisCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "opis_kill";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandNameOpis() {
|
||||
return this.getCommandName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender icommandsender) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender icommandsender, String[] astring) {
|
||||
if (astring.length != 2) return;
|
||||
int dim = Integer.valueOf(astring[0]);
|
||||
int eid = Integer.valueOf(astring[1]);
|
||||
|
||||
World world = DimensionManager.getWorld(dim);
|
||||
if (world == null){
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("\u00A7oCannot find dim %d in world %d", dim)));
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = world.getEntityByID(eid);
|
||||
if (entity == null) {
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("\u00A7oCannot find entity %d in dim %d", eid, dim)));
|
||||
return;
|
||||
}
|
||||
|
||||
entity.setDead();
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("\u00A7oKilled entity %d in dim %d", eid, dim)));
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender sender)
|
||||
{
|
||||
if (sender instanceof DedicatedServer) return true;
|
||||
if ((sender instanceof EntityPlayerMP) && ((EntityPlayerMP)sender).playerNetServerHandler.netManager instanceof MemoryConnection) return true;
|
||||
if (!(sender instanceof DedicatedServer) && !(sender instanceof EntityPlayerMP)) return true;
|
||||
return PlayerTracker.instance().isPrivileged(((EntityPlayerMP)sender).username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Kills the given entity id in the given dimension.";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package mcp.mobius.opis.commands.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import mcp.mobius.opis.commands.IOpisCommand;
|
||||
import mcp.mobius.opis.data.managers.EntityManager;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.MemoryConnection;
|
||||
import net.minecraft.network.packet.Packet3Chat;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
||||
public class CommandKillAll extends CommandBase implements IOpisCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "opis_killall";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandNameOpis() {
|
||||
return this.getCommandName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender icommandsender) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender icommandsender, String[] astring) {
|
||||
if (astring.length < 1) return;
|
||||
|
||||
String searchname = StringUtils.join(astring, " ").toLowerCase();
|
||||
|
||||
int nkilled = EntityManager.INSTANCE.killAll(searchname);
|
||||
|
||||
if (nkilled == -1){
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("\u00A7oSeriously ? I can't, seriously, I can't. I should remove you from the OP list !")));
|
||||
return;
|
||||
}
|
||||
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("\u00A7oKilled %d entities of type %s", nkilled, searchname)));
|
||||
|
||||
/*
|
||||
World world = DimensionManager.getWorld(dim);
|
||||
if (world == null){
|
||||
PacketDispatcher.sendPacketToPlayer(
|
||||
new Packet3Chat(ChatMessageComponent.createFromText(String.format("\u00A7oCannot find dim %d in world %d", dim))),
|
||||
(Player)icommandsender);
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = world.getEntityByID(eid);
|
||||
if (entity == null) {
|
||||
PacketDispatcher.sendPacketToPlayer(
|
||||
new Packet3Chat(ChatMessageComponent.createFromText(String.format("\u00A7oCannot find entity %d in dim %d", eid, dim))),
|
||||
(Player)icommandsender);
|
||||
return;
|
||||
}
|
||||
|
||||
entity.setDead();
|
||||
PacketDispatcher.sendPacketToPlayer(
|
||||
new Packet3Chat(ChatMessageComponent.createFromText(String.format("\u00A7oKilled entity %d in dim %d", eid, dim))),
|
||||
(Player)icommandsender);
|
||||
return;
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender sender)
|
||||
{
|
||||
if (sender instanceof DedicatedServer) return true;
|
||||
if ((sender instanceof EntityPlayerMP) && ((EntityPlayerMP)sender).playerNetServerHandler.netManager instanceof MemoryConnection) return true;
|
||||
if (!(sender instanceof DedicatedServer) && !(sender instanceof EntityPlayerMP)) return true;
|
||||
return PlayerTracker.instance().isPrivileged(((EntityPlayerMP)sender).username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Kills all entities of the given name.";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package mcp.mobius.opis.commands.server;
|
||||
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import mcp.mobius.opis.commands.IOpisCommand;
|
||||
import mcp.mobius.opis.data.managers.EntityManager;
|
||||
import mcp.mobius.opis.data.managers.MetaManager;
|
||||
import mcp.mobius.opis.data.managers.TickHandlerManager;
|
||||
import mcp.mobius.opis.data.managers.TileEntityManager;
|
||||
import mcp.mobius.opis.events.OpisServerTickHandler;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataCommand;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.MemoryConnection;
|
||||
import net.minecraft.network.packet.Packet3Chat;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
|
||||
public class CommandReset extends CommandBase implements IOpisCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "opis_reset";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandNameOpis() {
|
||||
return this.getCommandName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender icommandsender) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender icommandsender, String[] astring) {
|
||||
MetaManager.reset();
|
||||
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("\u00A7oInternal data reseted.")));
|
||||
|
||||
//PacketDispatcher.sendPacketToAllPlayers(NetDataCommand.create(Message.CLIENT_CLEAR_SELECTION));
|
||||
if (icommandsender instanceof Player)
|
||||
OpisPacketHandler.validateAndSend(NetDataCommand.create(Message.CLIENT_CLEAR_SELECTION), (Player)icommandsender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender sender)
|
||||
{
|
||||
if (sender instanceof DedicatedServer) return true;
|
||||
if ((sender instanceof EntityPlayerMP) && ((EntityPlayerMP)sender).playerNetServerHandler.netManager instanceof MemoryConnection) return true;
|
||||
if (!(sender instanceof DedicatedServer) && !(sender instanceof EntityPlayerMP)) return true;
|
||||
return PlayerTracker.instance().isPrivileged(((EntityPlayerMP)sender).username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Cleans up all profiling data and remove client block overlay.";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package mcp.mobius.opis.commands.server;
|
||||
|
||||
import mcp.mobius.opis.commands.IOpisCommand;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.MemoryConnection;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
|
||||
public class CommandRmPrivileged extends CommandBase implements IOpisCommand{
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "opis_rmpriv";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender icommandsender) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender icommandsender, String[] astring) {
|
||||
if (PlayerTracker.instance().isPrivileged(astring[0])){
|
||||
PlayerTracker.instance().rmPrivilegedPlayer(astring[0]);
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("Player %s removed from Opis user list.", astring[0])));
|
||||
} else {
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("Player %s not found in list.", astring[0])));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender sender)
|
||||
{
|
||||
if (sender instanceof DedicatedServer) return true;
|
||||
if ((sender instanceof EntityPlayerMP) && ((EntityPlayerMP)sender).playerNetServerHandler.netManager instanceof MemoryConnection) return true;
|
||||
if (!(sender instanceof DedicatedServer) && !(sender instanceof EntityPlayerMP)) return true;
|
||||
return PlayerTracker.instance().isAdmin(((EntityPlayerMP)sender).username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Remove a user from the privileged list of users.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandNameOpis() {
|
||||
return "opis_rmpriv";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package mcp.mobius.opis.commands.server;
|
||||
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import mcp.mobius.opis.commands.IOpisCommand;
|
||||
import mcp.mobius.opis.data.holders.basetypes.SerialInt;
|
||||
import mcp.mobius.opis.data.managers.EntityManager;
|
||||
import mcp.mobius.opis.data.managers.MetaManager;
|
||||
import mcp.mobius.opis.data.managers.TickHandlerManager;
|
||||
import mcp.mobius.opis.data.managers.TileEntityManager;
|
||||
import mcp.mobius.opis.events.OpisServerTickHandler;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataValue;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.MemoryConnection;
|
||||
import net.minecraft.network.packet.Packet3Chat;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
import mcp.mobius.mobiuscore.profiler.ProfilerSection;
|
||||
|
||||
public class CommandStart extends CommandBase implements IOpisCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "opis_start";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandNameOpis() {
|
||||
return this.getCommandName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender icommandsender) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender icommandsender, String[] astring) {
|
||||
if (icommandsender instanceof Player){
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText("DEPRECATED ! Please run /opis instead."));
|
||||
return;
|
||||
}
|
||||
|
||||
MetaManager.reset();
|
||||
modOpis.profilerRun = true;
|
||||
ProfilerSection.activateAll(Side.SERVER);
|
||||
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.STATUS_START, new SerialInt(modOpis.profilerMaxTicks)));
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("\u00A7oOpis started with a tick delay %s.", modOpis.profilerDelay)));
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender sender)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Starts a run.";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package mcp.mobius.opis.commands.server;
|
||||
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import mcp.mobius.opis.commands.IOpisCommand;
|
||||
import mcp.mobius.opis.events.OpisServerTickHandler;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.MemoryConnection;
|
||||
import net.minecraft.network.packet.Packet3Chat;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
import mcp.mobius.mobiuscore.profiler.ProfilerSection;
|
||||
|
||||
public class CommandStop extends CommandBase implements IOpisCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "opis_stop";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandNameOpis() {
|
||||
return this.getCommandName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender icommandsender) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender icommandsender, String[] astring) {
|
||||
modOpis.profilerRun = false;
|
||||
ProfilerSection.desactivateAll(Side.SERVER);
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("\u00A7oOpis stopped.")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender sender)
|
||||
{
|
||||
if (sender instanceof DedicatedServer) return true;
|
||||
if ((sender instanceof EntityPlayerMP) && ((EntityPlayerMP)sender).playerNetServerHandler.netManager instanceof MemoryConnection) return true;
|
||||
if (!(sender instanceof DedicatedServer) && !(sender instanceof EntityPlayerMP)) return true;
|
||||
return PlayerTracker.instance().isPrivileged(((EntityPlayerMP)sender).username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Ends a run before completion.";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package mcp.mobius.opis.commands.server;
|
||||
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import mcp.mobius.opis.commands.IOpisCommand;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.MemoryConnection;
|
||||
import net.minecraft.network.packet.Packet3Chat;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
|
||||
public class CommandTicks extends CommandBase implements IOpisCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "opis_ticks";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandNameOpis() {
|
||||
return this.getCommandName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender icommandsender) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender icommandsender, String[] astring) {
|
||||
if (astring.length < 1) return;
|
||||
try{
|
||||
modOpis.profilerMaxTicks = Integer.valueOf(astring[0]);
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("\u00A7oOpis ticks set to %s ticks.", astring[0])));
|
||||
|
||||
} catch (Exception e){}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender sender)
|
||||
{
|
||||
if (sender instanceof DedicatedServer) return true;
|
||||
if ((sender instanceof EntityPlayerMP) && ((EntityPlayerMP)sender).playerNetServerHandler.netManager instanceof MemoryConnection) return true;
|
||||
if (!(sender instanceof DedicatedServer) && !(sender instanceof EntityPlayerMP)) return true;
|
||||
return PlayerTracker.instance().isPrivileged(((EntityPlayerMP)sender).username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Sets the amount of data points to gather.";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package mcp.mobius.opis.commands.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import mcp.mobius.opis.commands.IOpisCommand;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesChunk;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataEntity;
|
||||
import mcp.mobius.opis.data.managers.EntityManager;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataList;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.MemoryConnection;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
|
||||
public class CommandTimingEntities extends CommandBase implements IOpisCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "opis_ent";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandNameOpis() {
|
||||
return this.getCommandName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender icommandsender) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender icommandsender, String[] astring) {
|
||||
if (icommandsender instanceof Player){
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText("DEPRECATED ! Please run /opis instead."));
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<DataEntity> ents = new ArrayList<DataEntity>();
|
||||
if (astring.length == 0){
|
||||
ents = EntityManager.INSTANCE.getWorses(20);
|
||||
}
|
||||
else{
|
||||
try{
|
||||
ents = EntityManager.INSTANCE.getWorses(Integer.valueOf(astring[0]));
|
||||
} catch (Exception e) {return;}
|
||||
}
|
||||
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText("[DIM X Z] Time NTEs"));
|
||||
for (DataEntity stat : ents){
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(stat.toString()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender sender)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Returns the 20 longest entities to update.";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package mcp.mobius.opis.commands.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import mcp.mobius.opis.commands.IOpisCommand;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataBlockTileEntity;
|
||||
import mcp.mobius.opis.data.managers.TileEntityManager;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataList;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.MemoryConnection;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
|
||||
public class CommandTimingTileEntities extends CommandBase implements IOpisCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "opis_te";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandNameOpis() {
|
||||
return this.getCommandName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender icommandsender) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender icommandsender, String[] astring) {
|
||||
if (icommandsender instanceof Player){
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText("DEPRECATED ! Please run /opis instead."));
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<DataBlockTileEntity> tes = new ArrayList<DataBlockTileEntity>();
|
||||
if (astring.length == 0){
|
||||
tes = TileEntityManager.INSTANCE.getWorses(20);
|
||||
}
|
||||
else{
|
||||
try{
|
||||
tes = TileEntityManager.INSTANCE.getWorses(Integer.valueOf(astring[0]));
|
||||
} catch (Exception e) {return;}
|
||||
}
|
||||
|
||||
for (DataBlockTileEntity stat : tes){
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(stat.toString()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender sender)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Returns the 20 longest TEs to update.";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package mcp.mobius.opis.data.client;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
import org.jfree.chart.ChartFactory;
|
||||
import org.jfree.chart.JFreeChart;
|
||||
import org.jfree.chart.axis.NumberAxis;
|
||||
import org.jfree.chart.plot.PlotOrientation;
|
||||
import org.jfree.chart.plot.ValueMarker;
|
||||
import org.jfree.chart.plot.XYPlot;
|
||||
import org.jfree.data.category.DefaultCategoryDataset;
|
||||
import org.jfree.data.xy.DefaultTableXYDataset;
|
||||
import org.jfree.data.xy.DefaultXYDataset;
|
||||
import org.jfree.data.xy.XYBarDataset;
|
||||
import org.jfree.data.xy.XYDataset;
|
||||
import org.jfree.data.xy.XYSeries;
|
||||
import org.jfree.data.xy.XYSeriesCollection;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import mcp.mobius.opis.api.IMessageHandler;
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import mcp.mobius.opis.data.holders.basetypes.AmountHolder;
|
||||
import mcp.mobius.opis.data.holders.basetypes.SerialInt;
|
||||
import mcp.mobius.opis.data.holders.basetypes.SerialLong;
|
||||
import mcp.mobius.opis.data.holders.stats.StatAbstract;
|
||||
import mcp.mobius.opis.data.holders.stats.StatsChunk;
|
||||
import mcp.mobius.opis.helpers.ModIdentification;
|
||||
import mcp.mobius.opis.network.enums.AccessLevel;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataRaw;
|
||||
import mcp.mobius.opis.swing.SwingUI;
|
||||
import mcp.mobius.opis.swing.widgets.JButtonAccess;
|
||||
|
||||
public class DataCache implements IMessageHandler{
|
||||
|
||||
private static DataCache _instance = new DataCache();
|
||||
public static DataCache instance() { return _instance; };
|
||||
|
||||
private long clockScrew = 0;
|
||||
private AccessLevel clientAccess = AccessLevel.NONE;
|
||||
|
||||
public AccessLevel getAccessLevel(){
|
||||
return this.clientAccess;
|
||||
}
|
||||
|
||||
public long getClockScrew(){
|
||||
return this.clockScrew;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(Message msg, NetDataRaw rawdata) {
|
||||
switch(msg){
|
||||
case STATUS_ACCESS_LEVEL:{
|
||||
this.clientAccess = AccessLevel.values()[((SerialInt)rawdata.value).value];
|
||||
break;
|
||||
}
|
||||
|
||||
case STATUS_CURRENT_TIME:{
|
||||
this.clockScrew = System.currentTimeMillis() - ((SerialLong)rawdata.value).value;
|
||||
System.out.printf("Adjusting clock screw. Server differential is %d ms.\n", clockScrew);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return false;
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package mcp.mobius.opis.data.holders;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import mcp.mobius.opis.data.holders.basetypes.AmountHolder;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesBlock;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesChunk;
|
||||
import mcp.mobius.opis.data.holders.basetypes.SerialDouble;
|
||||
import mcp.mobius.opis.data.holders.basetypes.SerialFloat;
|
||||
import mcp.mobius.opis.data.holders.basetypes.SerialInt;
|
||||
import mcp.mobius.opis.data.holders.basetypes.SerialLong;
|
||||
import mcp.mobius.opis.data.holders.basetypes.SerialNumeral;
|
||||
import mcp.mobius.opis.data.holders.basetypes.SerialString;
|
||||
import mcp.mobius.opis.data.holders.basetypes.TargetEntity;
|
||||
import mcp.mobius.opis.data.holders.basetypes.TicketData;
|
||||
import mcp.mobius.opis.data.holders.newtypes.CachedString;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataAmountRate;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataBlockTileEntityPerClass;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataByteRate;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataByteSize;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataBlockRender;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataBlockTick;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataChunk;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataDimension;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataEntity;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataEntityPerClass;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataEntityRender;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataEvent;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataHandler;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataNetworkTick;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataPacket;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataPacket250;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataStringUpdate;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataBlockTileEntity;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataThread;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataTileEntity;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataTileEntityRender;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataTiming;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataTimingMillisecond;
|
||||
import mcp.mobius.opis.data.holders.stats.StatAbstract;
|
||||
import mcp.mobius.opis.data.holders.stats.StatsChunk;
|
||||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
|
||||
public enum DataType {
|
||||
AMOUNTHOLDER (AmountHolder.class),
|
||||
COORDINATESBLOCK(CoordinatesBlock.class),
|
||||
COORDINATESCHUNK(CoordinatesChunk.class),
|
||||
SERIALDOUBLE (SerialDouble.class),
|
||||
SERIALFLOAT (SerialFloat.class),
|
||||
SERIALINT (SerialInt.class),
|
||||
SERIALLONG (SerialLong.class),
|
||||
SERIALSTRING (SerialString.class),
|
||||
TARGETENTITY (TargetEntity.class),
|
||||
TICKETDATA (TicketData.class),
|
||||
|
||||
CACHEDSTRING (CachedString.class),
|
||||
DATAAMOUNTRATE (DataAmountRate.class),
|
||||
DATABITRATE (DataByteRate.class),
|
||||
DATABITSIZE (DataByteSize.class),
|
||||
DATABLOCKRENDER (DataBlockRender.class),
|
||||
DATABLOCKTICK (DataBlockTick.class),
|
||||
DATABLOCKTILEENTITY (DataBlockTileEntity.class),
|
||||
DATABLOCKTILEENTITYPERCLASS (DataBlockTileEntityPerClass.class),
|
||||
DATACHUNK (DataChunk.class),
|
||||
DATADIMENSION (DataDimension.class),
|
||||
DATAENTITY (DataEntity.class),
|
||||
DATAENTITYPERCLASS (DataEntityPerClass.class),
|
||||
DATAENTITYRENDER (DataEntityRender.class),
|
||||
DATAEVENT (DataEvent.class),
|
||||
DATAHANDLER (DataHandler.class),
|
||||
DATANETWORKTICK (DataNetworkTick.class),
|
||||
DATAPACKET (DataPacket.class),
|
||||
DATAPACKET250 (DataPacket250.class),
|
||||
DATASTRINGUPD (DataStringUpdate.class),
|
||||
DATATHREAD (DataThread.class),
|
||||
DATATILEENTITY (DataTileEntity.class),
|
||||
DATATILEENTITYRENDER (DataTileEntityRender.class),
|
||||
DATATIMING (DataTiming.class),
|
||||
DATATIMINGMILLISECOND (DataTimingMillisecond.class),
|
||||
STATABSTRACT (StatAbstract.class),
|
||||
STATSCHUNK (StatsChunk.class);
|
||||
|
||||
private Class clazz;
|
||||
private static HashBiMap<DataType, Class> bimap = HashBiMap.create(50);
|
||||
|
||||
static
|
||||
{
|
||||
for (DataType type : DataType.values())
|
||||
bimap.put(type, type.clazz);
|
||||
}
|
||||
|
||||
private DataType(Class clazz){
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public static DataType getForClass(Class clazz){
|
||||
DataType type = bimap.inverse().get(clazz);
|
||||
if (type == null){
|
||||
modOpis.log.warning(String.format("Class %s was not registered with the DataType enum", clazz));
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
public static Class getForOrdinal(int ordinal){
|
||||
Class retVal;
|
||||
try{
|
||||
DataType type = DataType.values()[ordinal];
|
||||
retVal = bimap.get(type);
|
||||
if (retVal == null){
|
||||
modOpis.log.warning(String.format("DataType doesn't have a class registered for %s", type));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
retVal = null;
|
||||
modOpis.log.warning(String.format("Index out of bound for ordinal %d in DataType", ordinal));
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package mcp.mobius.opis.data.holders;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public interface ISerializable {
|
||||
void writeToStream(DataOutputStream stream) throws IOException;
|
||||
//Object readFromStream(DataInputStream stream) throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package mcp.mobius.opis.data.holders.basetypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
|
||||
public class AmountHolder implements ISerializable {
|
||||
|
||||
public String key = null;
|
||||
public Integer value = 0;
|
||||
|
||||
public AmountHolder(String key, Integer value){
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
Packet.writeString(this.key, stream);
|
||||
stream.writeInt(this.value);
|
||||
}
|
||||
|
||||
public static AmountHolder readFromStream(DataInputStream istream) throws IOException {
|
||||
String key = Packet.readString(istream, 255);
|
||||
Integer value = istream.readInt();
|
||||
|
||||
return new AmountHolder(key, value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package mcp.mobius.opis.data.holders.basetypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
||||
public final class CoordinatesBlock implements ISerializable {
|
||||
public final int dim, x, y, z;
|
||||
public final int chunkX, chunkZ;
|
||||
//public boolean isChunk;
|
||||
|
||||
public final static CoordinatesBlock INVALID = new CoordinatesBlock(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
|
||||
public CoordinatesBlock(Entity entity){
|
||||
this.dim = entity.worldObj.provider.dimensionId;
|
||||
this.x = MathHelper.floor_double(entity.posX);
|
||||
this.y = MathHelper.floor_double(entity.posY);
|
||||
this.z = MathHelper.floor_double(entity.posZ);
|
||||
this.chunkX = x >> 4;
|
||||
this.chunkZ = z >> 4;
|
||||
//this.isChunk = false;
|
||||
}
|
||||
|
||||
public CoordinatesBlock(int dim, int x, int y, int z){
|
||||
this.dim = dim;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.chunkX = x >> 4;
|
||||
this.chunkZ = z >> 4;
|
||||
//this.isChunk = false;
|
||||
}
|
||||
|
||||
public CoordinatesBlock(int dim, double x, double y, double z){
|
||||
this.dim = dim;
|
||||
this.x = MathHelper.floor_double(x);
|
||||
this.y = MathHelper.floor_double(y);
|
||||
this.z = MathHelper.floor_double(z);
|
||||
this.chunkX = MathHelper.floor_double(x) >> 4;
|
||||
this.chunkZ = MathHelper.floor_double(z) >> 4;
|
||||
//this.isChunk = false;
|
||||
}
|
||||
|
||||
public CoordinatesBlock(CoordinatesChunk coord){
|
||||
this.dim = coord.dim;
|
||||
this.chunkX = coord.chunkX;
|
||||
this.chunkZ = coord.chunkZ;
|
||||
|
||||
this.x = coord.x;
|
||||
this.y = coord.y;
|
||||
this.z = coord.z;
|
||||
}
|
||||
|
||||
/*
|
||||
public CoordinatesBlock(int dim, int chunkX, int chunkZ){
|
||||
this.dim = dim;
|
||||
this.chunkX = chunkX;
|
||||
this.chunkZ = chunkZ;
|
||||
this.x = chunkX << 4;
|
||||
this.y = 0;
|
||||
this.z = chunkZ << 4;
|
||||
this.isChunk = true;
|
||||
}
|
||||
*/
|
||||
|
||||
public CoordinatesBlock(TileEntity te){
|
||||
this.dim = te.getWorldObj().provider.dimensionId;
|
||||
this.x = te.xCoord;
|
||||
this.y = te.yCoord;
|
||||
this.z = te.zCoord;
|
||||
this.chunkX = x >> 4;
|
||||
this.chunkZ = z >> 4;
|
||||
//this.isChunk = false;
|
||||
}
|
||||
|
||||
public CoordinatesChunk asCoordinatesChunk(){
|
||||
return new CoordinatesChunk(this);
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
//if (this.isChunk)
|
||||
// return String.format("[%6d %6d %6d]", this.dim, this.chunkX, this.chunkZ);
|
||||
//else
|
||||
return String.format("[%6d %6d %6d %6d]", this.dim, this.x, this.y, this.z);
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
CoordinatesBlock c = (CoordinatesBlock)o;
|
||||
//if (this.isChunk)
|
||||
// return (this.dim == c.dim) && (this.chunkX == c.chunkX) && (this.chunkZ == c.chunkZ);
|
||||
//else
|
||||
return (this.dim == c.dim) && (this.x == c.x) && (this.y == c.y) && (this.z == c.z);
|
||||
};
|
||||
|
||||
public boolean isInvalid(){
|
||||
return this.equals(CoordinatesBlock.INVALID);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
//if (this.isChunk)
|
||||
// return String.format("%s %s %s", this.dim, this.chunkX, this.chunkZ).hashCode();
|
||||
//else
|
||||
// return String.format("%s %s %s %s", this.dim, this.x, this.y, this.z).hashCode();
|
||||
return this.dim + 31 * this.x + 877 * this.y + 3187 * this.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
stream.writeInt(this.dim);
|
||||
stream.writeInt(this.x);
|
||||
stream.writeInt(this.y);
|
||||
stream.writeInt(this.z);
|
||||
}
|
||||
|
||||
public static CoordinatesBlock readFromStream(DataInputStream stream) throws IOException {
|
||||
return new CoordinatesBlock(stream.readInt(), stream.readInt(), stream.readInt(), stream.readInt());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package mcp.mobius.opis.data.holders.basetypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
|
||||
public final class CoordinatesChunk implements ISerializable {
|
||||
public final int dim, x, y, z;
|
||||
public final int chunkX, chunkZ;
|
||||
public final byte metadata;
|
||||
//public boolean isChunk;
|
||||
|
||||
public final static CoordinatesChunk INVALID = new CoordinatesChunk(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
|
||||
public CoordinatesChunk(CoordinatesBlock coord){
|
||||
this.dim = coord.dim;
|
||||
this.chunkX = coord.chunkX;
|
||||
this.chunkZ = coord.chunkZ;
|
||||
|
||||
this.x = chunkX << 4;
|
||||
this.y = 0;
|
||||
this.z = chunkZ << 4;
|
||||
|
||||
this.metadata = 0;
|
||||
}
|
||||
|
||||
public CoordinatesChunk(int dim, int chunkX, int chunkZ){
|
||||
this.dim = dim;
|
||||
this.chunkX = chunkX;
|
||||
this.chunkZ = chunkZ;
|
||||
|
||||
this.x = chunkX << 4;
|
||||
this.y = 0;
|
||||
this.z = chunkZ << 4;
|
||||
|
||||
this.metadata = 0;
|
||||
}
|
||||
|
||||
public CoordinatesChunk(int dim, int chunkX, int chunkZ, byte metadata){
|
||||
this.dim = dim;
|
||||
this.chunkX = chunkX;
|
||||
this.chunkZ = chunkZ;
|
||||
|
||||
this.x = chunkX << 4;
|
||||
this.y = 0;
|
||||
this.z = chunkZ << 4;
|
||||
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
public CoordinatesChunk(int dim, ChunkCoordIntPair coord){
|
||||
this.dim = dim;
|
||||
this.chunkX = coord.chunkXPos;
|
||||
this.chunkZ = coord.chunkZPos;
|
||||
|
||||
this.x = chunkX << 4;
|
||||
this.y = 0;
|
||||
this.z = chunkZ << 4;
|
||||
|
||||
this.metadata = 0;
|
||||
}
|
||||
|
||||
public CoordinatesChunk(int dim, ChunkCoordIntPair coord, byte metadata){
|
||||
this.dim = dim;
|
||||
this.chunkX = coord.chunkXPos;
|
||||
this.chunkZ = coord.chunkZPos;
|
||||
|
||||
this.x = chunkX << 4;
|
||||
this.y = 0;
|
||||
this.z = chunkZ << 4;
|
||||
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
public CoordinatesChunk(TileEntity te){
|
||||
this.dim = te.getWorldObj().provider.dimensionId;
|
||||
this.chunkX = te.xCoord >> 4;
|
||||
this.chunkZ = te.zCoord >> 4;
|
||||
|
||||
this.x = this.chunkX << 4;
|
||||
this.y = 0;
|
||||
this.z = this.chunkZ << 4;
|
||||
|
||||
this.metadata = 0;
|
||||
}
|
||||
|
||||
public boolean isInvalid(){
|
||||
return this.equals(CoordinatesChunk.INVALID);
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return String.format("[%6d %6d %6d]", this.dim, this.chunkX, this.chunkZ);
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
CoordinatesChunk c = (CoordinatesChunk)o;
|
||||
return (this.dim == c.dim) && (this.chunkX == c.chunkX) && (this.chunkZ == c.chunkZ);
|
||||
}
|
||||
|
||||
//00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
|
||||
//11111111 11111111 11111111 11122222 22222222 22222222 22222200 00000000
|
||||
|
||||
public int hashCode() {
|
||||
//return String.format("%s %s %s", this.dim, this.chunkX, this.chunkZ).hashCode();
|
||||
return this.dim + 31 * this.chunkX + 877 * this.chunkZ;
|
||||
}
|
||||
|
||||
public ChunkCoordIntPair toChunkCoordIntPair(){
|
||||
return new ChunkCoordIntPair(this.chunkX, this.chunkZ);
|
||||
}
|
||||
|
||||
public CoordinatesBlock asCoordinatesBlock(){
|
||||
return new CoordinatesBlock(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
stream.writeInt(this.dim);
|
||||
stream.writeInt(this.chunkX);
|
||||
stream.writeInt(this.chunkZ);
|
||||
stream.writeByte(this.metadata);
|
||||
}
|
||||
|
||||
public static CoordinatesChunk readFromStream(DataInputStream stream) throws IOException {
|
||||
return new CoordinatesChunk(stream.readInt(), stream.readInt(), stream.readInt(), stream.readByte());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package mcp.mobius.opis.data.holders.basetypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
|
||||
public class SerialDouble implements ISerializable {
|
||||
|
||||
public double value = 0;
|
||||
|
||||
public SerialDouble(double value){
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
stream.writeDouble(this.value);
|
||||
}
|
||||
|
||||
public static SerialDouble readFromStream(DataInputStream stream) throws IOException {
|
||||
return new SerialDouble(stream.readDouble());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package mcp.mobius.opis.data.holders.basetypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
|
||||
public class SerialFloat implements ISerializable {
|
||||
|
||||
public float value = 0;
|
||||
|
||||
public SerialFloat(float value){
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
stream.writeFloat(this.value);
|
||||
}
|
||||
|
||||
public static SerialFloat readFromStream(DataInputStream stream) throws IOException {
|
||||
return new SerialFloat(stream.readFloat());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package mcp.mobius.opis.data.holders.basetypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
|
||||
public class SerialInt implements ISerializable {
|
||||
|
||||
public int value = 0;
|
||||
|
||||
public SerialInt(int value){
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
stream.writeInt(this.value);
|
||||
}
|
||||
|
||||
public static SerialInt readFromStream(DataInputStream stream) throws IOException {
|
||||
return new SerialInt(stream.readInt());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package mcp.mobius.opis.data.holders.basetypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
|
||||
public class SerialLong implements ISerializable {
|
||||
|
||||
public long value = 0;
|
||||
|
||||
public SerialLong(long value){
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
stream.writeLong(this.value);
|
||||
}
|
||||
|
||||
public static SerialLong readFromStream(DataInputStream stream) throws IOException {
|
||||
return new SerialLong(stream.readLong());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package mcp.mobius.opis.data.holders.basetypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class SerialNumeral<U> {
|
||||
private enum Type{
|
||||
INTEGER,
|
||||
LONG,
|
||||
FLOAT,
|
||||
DOUBLE,
|
||||
STRING;
|
||||
}
|
||||
|
||||
public static final SerialNumeral<Integer> INTEGER = new SerialNumeral<Integer>(Type.INTEGER);
|
||||
public static final SerialNumeral<Float> FLOAT = new SerialNumeral<Float>(Type.FLOAT);
|
||||
public static final SerialNumeral<Long> LONG = new SerialNumeral<Long>(Type.LONG);
|
||||
public static final SerialNumeral<Double> DOUBLE = new SerialNumeral<Double>(Type.DOUBLE);
|
||||
|
||||
U value;
|
||||
Type type;
|
||||
|
||||
public SerialNumeral(Type type){
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void setValue(U value){
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public U getValue(){
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void writeToSteam(DataOutputStream stream) throws IOException {
|
||||
stream.writeByte(this.type.ordinal());
|
||||
|
||||
switch(type){
|
||||
case DOUBLE:
|
||||
stream.writeDouble((Double)this.value);
|
||||
break;
|
||||
case FLOAT:
|
||||
stream.writeFloat((Float)this.value);
|
||||
break;
|
||||
case INTEGER:
|
||||
stream.writeInt((Integer)this.value);
|
||||
break;
|
||||
case LONG:
|
||||
stream.writeLong((Long)this.value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static SerialNumeral readFromStream(DataInputStream stream) throws IOException {
|
||||
Type datatype = Type.values()[stream.readByte()];
|
||||
switch(datatype){
|
||||
case DOUBLE:{
|
||||
SerialNumeral<Double> retVal = new SerialNumeral<Double>(Type.DOUBLE);
|
||||
retVal.setValue(stream.readDouble());
|
||||
return retVal;
|
||||
}
|
||||
case FLOAT:{
|
||||
SerialNumeral<Float> retVal = new SerialNumeral<Float>(Type.FLOAT);
|
||||
retVal.setValue(stream.readFloat());
|
||||
return retVal;
|
||||
}
|
||||
case INTEGER:{
|
||||
SerialNumeral<Integer> retVal = new SerialNumeral<Integer>(Type.INTEGER);
|
||||
retVal.setValue(stream.readInt());
|
||||
return retVal;
|
||||
}
|
||||
case LONG:{
|
||||
SerialNumeral<Long> retVal = new SerialNumeral<Long>(Type.LONG);
|
||||
retVal.setValue(stream.readLong());
|
||||
return retVal;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package mcp.mobius.opis.data.holders.basetypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
|
||||
public class SerialString implements ISerializable {
|
||||
|
||||
public String value = "";
|
||||
|
||||
public SerialString(String value){
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
Packet.writeString(this.value, stream);
|
||||
}
|
||||
|
||||
public static SerialString readFromStream(DataInputStream stream) throws IOException {
|
||||
return new SerialString(Packet.readString(stream, 255));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package mcp.mobius.opis.data.holders.basetypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
|
||||
public class TargetEntity implements ISerializable {
|
||||
|
||||
public int entityID = 0;
|
||||
public int dim = 0;
|
||||
|
||||
public TargetEntity(int id, int dim){
|
||||
this.entityID = id;
|
||||
this.dim = dim;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
stream.writeInt(this.entityID);
|
||||
stream.writeInt(this.dim);
|
||||
}
|
||||
|
||||
public static TargetEntity readFromStream(DataInputStream stream) throws IOException {
|
||||
return new TargetEntity(stream.readInt(), stream.readInt());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package mcp.mobius.opis.data.holders.basetypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
import net.minecraftforge.common.ForgeChunkManager.Ticket;
|
||||
|
||||
public final class TicketData implements ISerializable{
|
||||
public final CoordinatesChunk coord;
|
||||
public final int nchunks;
|
||||
public final String modID;
|
||||
public final Ticket ticket;
|
||||
|
||||
public TicketData(Ticket ticket){
|
||||
ImmutableSet requestedChunks = ticket.getChunkList();
|
||||
int maxChunkX = -999999, minChunkX = 9999999, maxChunkZ = -999999, minChunkZ = 9999999;
|
||||
|
||||
for (Object obj : requestedChunks){
|
||||
ChunkCoordIntPair chunk = (ChunkCoordIntPair)obj;
|
||||
maxChunkX = Math.max(maxChunkX, chunk.chunkXPos);
|
||||
minChunkX = Math.min(minChunkX, chunk.chunkXPos);
|
||||
maxChunkZ = Math.max(maxChunkZ, chunk.chunkZPos);
|
||||
minChunkZ = Math.min(minChunkZ, chunk.chunkZPos);
|
||||
}
|
||||
|
||||
this.coord = new CoordinatesChunk(ticket.world.provider.dimensionId, (minChunkX + maxChunkX)/2, (minChunkZ + maxChunkZ)/2);
|
||||
this.nchunks = requestedChunks.size();
|
||||
this.modID = ticket.getModId();
|
||||
this.ticket = ticket;
|
||||
}
|
||||
|
||||
public TicketData(CoordinatesChunk coord, int nchunks, String modid){
|
||||
this.coord = coord;
|
||||
this.nchunks = nchunks;
|
||||
this.modID = modid;
|
||||
this.ticket = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
this.coord.writeToStream(stream);
|
||||
stream.writeInt(this.nchunks);
|
||||
Packet.writeString(this.modID, stream);
|
||||
|
||||
}
|
||||
|
||||
public static TicketData readFromStream(DataInputStream stream) throws IOException {
|
||||
return new TicketData(CoordinatesChunk.readFromStream(stream), stream.readInt(), Packet.readString(stream, 255));
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
TicketData c = (TicketData)o;
|
||||
|
||||
if (this.ticket != null && c.ticket != null)
|
||||
return this.ticket.equals(c.ticket);
|
||||
|
||||
return (this.coord.dim == c.coord.dim) &&
|
||||
(this.coord.chunkX == c.coord.chunkX) &&
|
||||
(this.coord.chunkZ == c.coord.chunkZ) &&
|
||||
(this.nchunks == c.nchunks);
|
||||
};
|
||||
|
||||
public int hashCode() {
|
||||
if (this.ticket != null)
|
||||
return this.ticket.hashCode();
|
||||
return String.format("%s %s %s %s", this.coord.dim, this.coord.chunkX, this.coord.chunkZ, this.nchunks).hashCode();
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return String.format("Ticket %s [%d %d %d] %d", this.modID, this.coord.dim, this.coord.chunkX, this.coord.chunkZ, this.nchunks);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.server.ServerListenThread;
|
||||
import net.minecraft.server.ThreadMinecraftServer;
|
||||
import net.minecraft.network.TcpReaderThread;
|
||||
import net.minecraft.network.TcpWriterThread;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.server.FMLServerHandler;
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import mcp.mobius.opis.data.managers.StringCache;
|
||||
import mcp.mobius.opis.helpers.Helpers;
|
||||
|
||||
|
||||
public class CachedString implements Comparable, ISerializable{
|
||||
|
||||
String str;
|
||||
int index;
|
||||
|
||||
public CachedString(int index) {
|
||||
this.index = index;
|
||||
this.str = StringCache.INSTANCE.getString(index);
|
||||
}
|
||||
|
||||
public CachedString(String str){
|
||||
|
||||
//if(FMLCommonHandler.instance().getSide() == Side.SERVER){
|
||||
if(Helpers.getEffectiveSide() == Side.SERVER){
|
||||
this.index = StringCache.INSTANCE.getIndex(str);
|
||||
this.str = str;
|
||||
} else {
|
||||
this.index = -1;
|
||||
this.str = str;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
return ((CachedString)o).str.compareTo(this.str); // Reverse order ! Put higher values FIRST
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
//return String.format("[%d] %s",this.index, this.str);
|
||||
return str;
|
||||
}
|
||||
|
||||
public void writeToStream(DataOutputStream stream) throws IOException{
|
||||
stream.writeInt(this.index);
|
||||
}
|
||||
|
||||
public static CachedString readFromStream(DataInputStream stream) throws IOException {
|
||||
return new CachedString(stream.readInt());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
|
||||
public class DataAmountRate implements Comparable, ISerializable {
|
||||
public Long size; // Size is stored in byte
|
||||
public int interval;
|
||||
|
||||
//public DataByteRate(int interval){ this.size = 0L; this.interval = interval;}
|
||||
public DataAmountRate(long size, int interval){ this.size = size; this.interval = interval;}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
return ((DataAmountRate)o).size.compareTo(this.size); // Reverse order ! Put higher values FIRST
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
this.size = 0L;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return String.format("%.2f packet/s", (double)this.size / (double)this.interval);
|
||||
}
|
||||
|
||||
public void writeToStream(DataOutputStream stream) throws IOException{
|
||||
stream.writeLong(this.size);
|
||||
stream.writeInt(this.interval);
|
||||
}
|
||||
|
||||
public static DataAmountRate readFromStream(DataInputStream stream) throws IOException {
|
||||
return new DataAmountRate(stream.readLong(), stream.readInt());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.world.World;
|
||||
import mcp.mobius.mobiuscore.profiler.ProfilerSection;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesBlock;
|
||||
import mcp.mobius.opis.data.profilers.ProfilerRenderBlock;
|
||||
|
||||
public class DataBlockRender extends DataBlockTileEntity {
|
||||
|
||||
public DataBlockRender fill(CoordinatesBlock coord){
|
||||
this.pos = coord;
|
||||
World world = Minecraft.getMinecraft().theWorld; //DimensionManager.getWorld(this.pos.dim);
|
||||
|
||||
this.id = (short) world.getBlockId(this.pos.x, this.pos.y, this.pos.z);
|
||||
this.meta = (short) world.getBlockMetadata(this.pos.x, this.pos.y, this.pos.z);
|
||||
|
||||
HashMap<CoordinatesBlock, DescriptiveStatistics> data = ((ProfilerRenderBlock)(ProfilerSection.RENDER_BLOCK.getProfiler())).data;
|
||||
this.update = new DataTiming(data.containsKey(coord) ? data.get(coord).getGeometricMean() : 0.0D);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
import mcp.mobius.mobiuscore.profiler.ProfilerSection;
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import mcp.mobius.opis.data.profilers.ProfilerDimBlockTick;
|
||||
|
||||
public class DataBlockTick implements ISerializable{
|
||||
public HashMap<Integer, DataTiming> perdim = new HashMap<Integer, DataTiming>();
|
||||
public DataTiming total;
|
||||
|
||||
public DataBlockTick fill(){
|
||||
this.total = new DataTiming();
|
||||
HashMap<Integer, DescriptiveStatistics> data = ((ProfilerDimBlockTick)ProfilerSection.DIMENSION_BLOCKTICK.getProfiler()).data;
|
||||
|
||||
for (Integer dim : data.keySet()){
|
||||
this.perdim.put(dim, new DataTiming(data.get(dim).getGeometricMean()));
|
||||
this.total.timing += data.get(dim).getGeometricMean();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
stream.writeShort(this.perdim.size());
|
||||
for (Integer key : this.perdim.keySet()){
|
||||
stream.writeInt(key);
|
||||
this.perdim.get(key).writeToStream(stream);
|
||||
}
|
||||
this.total.writeToStream(stream);
|
||||
}
|
||||
|
||||
public static DataBlockTick readFromStream(DataInputStream stream) throws IOException {
|
||||
DataBlockTick retVal = new DataBlockTick();
|
||||
int nkeys = stream.readShort();
|
||||
for (int i = 0; i < nkeys; i++)
|
||||
retVal.perdim.put(stream.readInt(), DataTiming.readFromStream(stream));
|
||||
retVal.total = DataTiming.readFromStream(stream);
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import mcp.mobius.mobiuscore.profiler.ProfilerSection;
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesBlock;
|
||||
import mcp.mobius.opis.data.profilers.ProfilerTileEntityUpdate;
|
||||
|
||||
public class DataBlockTileEntity implements ISerializable, Comparable {
|
||||
|
||||
public short id;
|
||||
public short meta;
|
||||
public CoordinatesBlock pos;
|
||||
public DataTiming update;
|
||||
|
||||
public DataBlockTileEntity fill(CoordinatesBlock coord){
|
||||
this.pos = coord;
|
||||
World world = DimensionManager.getWorld(this.pos.dim);
|
||||
|
||||
this.id = (short) world.getBlockId(this.pos.x, this.pos.y, this.pos.z);
|
||||
this.meta = (short) world.getBlockMetadata(this.pos.x, this.pos.y, this.pos.z);
|
||||
|
||||
HashMap<CoordinatesBlock, DescriptiveStatistics> data = ((ProfilerTileEntityUpdate)(ProfilerSection.TILEENT_UPDATETIME.getProfiler())).data;
|
||||
this.update = new DataTiming(data.containsKey(this.pos) ? data.get(this.pos).getGeometricMean() : 0.0D);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
stream.writeShort(this.id);
|
||||
stream.writeShort(this.meta);
|
||||
this.pos.writeToStream(stream);
|
||||
this.update.writeToStream(stream);
|
||||
}
|
||||
|
||||
public static DataBlockTileEntity readFromStream(DataInputStream stream) throws IOException {
|
||||
DataBlockTileEntity retVal = new DataBlockTileEntity();
|
||||
retVal.id = stream.readShort();
|
||||
retVal.meta = stream.readShort();
|
||||
retVal.pos = CoordinatesBlock.readFromStream(stream);
|
||||
retVal.update = DataTiming.readFromStream(stream);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
return this.update.compareTo(((DataBlockTileEntity)o).update);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
|
||||
public class DataBlockTileEntityPerClass implements ISerializable, Comparable {
|
||||
|
||||
public int id;
|
||||
public int meta;
|
||||
public int amount;
|
||||
public DataTiming update;
|
||||
|
||||
public DataBlockTileEntityPerClass(){}
|
||||
|
||||
public DataBlockTileEntityPerClass(int id, int meta){
|
||||
this.id = id;
|
||||
this.meta = meta;
|
||||
this.amount = 0;
|
||||
this.update = new DataTiming();
|
||||
}
|
||||
|
||||
public DataBlockTileEntityPerClass add(){
|
||||
this.amount += 1;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DataBlockTileEntityPerClass add(Double timing){
|
||||
this.amount += 1;
|
||||
this.update.timing += timing;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public DataBlockTileEntityPerClass add(int amount, Double timing){
|
||||
this.amount += amount;
|
||||
this.update.timing += timing;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
stream.writeInt(this.id);
|
||||
stream.writeInt(this.meta);
|
||||
stream.writeInt(this.amount);
|
||||
this.update.writeToStream(stream);
|
||||
}
|
||||
|
||||
public static DataBlockTileEntityPerClass readFromStream(DataInputStream stream) throws IOException {
|
||||
DataBlockTileEntityPerClass retVal = new DataBlockTileEntityPerClass();
|
||||
retVal.id = stream.readInt();
|
||||
retVal.meta = stream.readInt();
|
||||
retVal.amount = stream.readInt();
|
||||
retVal.update = DataTiming.readFromStream(stream);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
return this.update.compareTo(((DataBlockTileEntityPerClass)o).update);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
|
||||
public class DataByteRate implements Comparable, ISerializable {
|
||||
public Long size; // Size is stored in byte
|
||||
public int interval;
|
||||
|
||||
//public DataByteRate(int interval){ this.size = 0L; this.interval = interval;}
|
||||
public DataByteRate(long size, int interval){ this.size = size; this.interval = interval;}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
return ((DataByteRate)o).size.compareTo(this.size); // Reverse order ! Put higher values FIRST
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
this.size = 0L;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
|
||||
if (size >= 1024 && size < (1024*1024)){
|
||||
return String.format("%.3f KiB/s", this.size / 1024.0 / this.interval);
|
||||
}
|
||||
|
||||
if (size >= (1024*1024)){
|
||||
return String.format("%.3f MiB/s", this.size / 1024.0 / 1024.0 / this.interval);
|
||||
}
|
||||
|
||||
return String.format("%4d B/s", this.size / this.interval);
|
||||
}
|
||||
|
||||
public void writeToStream(DataOutputStream stream) throws IOException{
|
||||
stream.writeLong(this.size);
|
||||
stream.writeInt(this.interval);
|
||||
}
|
||||
|
||||
public static DataByteRate readFromStream(DataInputStream stream) throws IOException {
|
||||
return new DataByteRate(stream.readLong(), stream.readInt());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
|
||||
public class DataByteSize implements Comparable, ISerializable {
|
||||
public Long size; // Size is stored in byte
|
||||
|
||||
public DataByteSize(){ this.size = 0L; }
|
||||
public DataByteSize(long size){ this.size = size; }
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
return ((DataByteSize)o).size.compareTo(this.size); // Reverse order ! Put higher values FIRST
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
|
||||
if (size >= 1024 && size < (1024*1024)){
|
||||
return String.format("%.3f KiB", this.size / 1024.0);
|
||||
}
|
||||
|
||||
if (size >= (1024*1024)){
|
||||
return String.format("%.3f MiB", this.size / 1024.0 / 1024.0);
|
||||
}
|
||||
|
||||
return String.format("%4d B", this.size);
|
||||
}
|
||||
|
||||
public void writeToStream(DataOutputStream stream) throws IOException{
|
||||
stream.writeLong(this.size);
|
||||
}
|
||||
|
||||
public static DataByteSize readFromStream(DataInputStream stream) throws IOException {
|
||||
return new DataByteSize(stream.readLong());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesChunk;
|
||||
import mcp.mobius.opis.data.managers.EntityManager;
|
||||
import mcp.mobius.opis.data.managers.TileEntityManager;
|
||||
|
||||
public class DataChunk implements ISerializable, Comparable {
|
||||
int nentities;
|
||||
int ntileents;
|
||||
DataTiming update;
|
||||
CoordinatesChunk chunk;
|
||||
|
||||
public DataChunk fill(CoordinatesChunk chunk){
|
||||
this.chunk = chunk;
|
||||
ArrayList<DataBlockTileEntity> tileEnts = TileEntityManager.INSTANCE.getTileEntitiesInChunk(this.chunk);
|
||||
ArrayList<DataEntity> entities = EntityManager.INSTANCE.getEntitiesInChunk(this.chunk);
|
||||
|
||||
this.nentities = entities.size();
|
||||
this.ntileents = tileEnts.size();
|
||||
double totalUpdate = 0.0D;
|
||||
for (DataBlockTileEntity tileent : tileEnts)
|
||||
totalUpdate += tileent.update.timing;
|
||||
|
||||
for (DataEntity ent : entities)
|
||||
totalUpdate += ent.update.timing;
|
||||
|
||||
this.update = new DataTiming(totalUpdate);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
stream.writeInt(this.nentities);
|
||||
stream.writeInt(this.ntileents);
|
||||
this.update.writeToStream(stream);
|
||||
this.chunk.writeToStream(stream);
|
||||
}
|
||||
|
||||
public static DataChunk readFromStream(DataInputStream stream) throws IOException {
|
||||
DataChunk retVal = new DataChunk();
|
||||
retVal.nentities = stream.readInt();
|
||||
retVal.ntileents = stream.readInt();
|
||||
retVal.update = DataTiming.readFromStream(stream);
|
||||
retVal.chunk = CoordinatesChunk.readFromStream(stream);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
return this.update.compareTo(((DataEntity)o).update);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
import mcp.mobius.mobiuscore.profiler.ProfilerSection;
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import mcp.mobius.opis.data.profilers.ProfilerDimTick;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.monster.EntityMob;
|
||||
import net.minecraft.entity.passive.EntityAnimal;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
||||
|
||||
/* Data holder for infos about dimensions */
|
||||
|
||||
public class DataDimension implements ISerializable {
|
||||
|
||||
public int dim;
|
||||
public CachedString name;
|
||||
public int players;
|
||||
public int forced;
|
||||
public int loaded;
|
||||
public int entities;
|
||||
public int mobs;
|
||||
public int neutral;
|
||||
public int itemstacks;
|
||||
public DataTiming update;
|
||||
|
||||
public DataDimension fill(int dim){
|
||||
WorldServer world = DimensionManager.getWorld(dim);
|
||||
|
||||
this.dim = dim;
|
||||
this.name = new CachedString(world.provider.getDimensionName());
|
||||
this.players = world.playerEntities.size();
|
||||
this.forced = world.getPersistentChunks().size();
|
||||
this.loaded = world.getChunkProvider().getLoadedChunkCount();
|
||||
|
||||
HashMap<Integer, DescriptiveStatistics> data = ((ProfilerDimTick)(ProfilerSection.DIMENSION_TICK.getProfiler())).data;
|
||||
this.update = new DataTiming(data.containsKey(dim) ? data.get(dim).getGeometricMean() : 0.0D);
|
||||
|
||||
this.mobs = 0;
|
||||
this.neutral = 0;
|
||||
this.entities = world.loadedEntityList.size();
|
||||
|
||||
for (Entity entity : (ArrayList<Entity>)world.loadedEntityList){
|
||||
if (entity instanceof EntityMob)
|
||||
this.mobs += 1;
|
||||
if (entity instanceof EntityAnimal)
|
||||
this.neutral += 1;
|
||||
if (entity instanceof EntityItem)
|
||||
this.itemstacks += 1;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
stream.writeInt(dim);
|
||||
stream.writeInt(players);
|
||||
stream.writeInt(forced);
|
||||
stream.writeInt(loaded);
|
||||
stream.writeInt(entities);
|
||||
stream.writeInt(mobs);
|
||||
stream.writeInt(neutral);
|
||||
stream.writeInt(itemstacks);
|
||||
//stream.writeDouble(update);
|
||||
this.update.writeToStream(stream);
|
||||
this.name.writeToStream(stream);
|
||||
}
|
||||
|
||||
public static DataDimension readFromStream(DataInputStream stream) throws IOException {
|
||||
DataDimension retVal = new DataDimension();
|
||||
retVal.dim = stream.readInt();
|
||||
retVal.players = stream.readInt();
|
||||
retVal.forced = stream.readInt();
|
||||
retVal.loaded = stream.readInt();
|
||||
retVal.entities= stream.readInt();
|
||||
retVal.mobs = stream.readInt();
|
||||
retVal.neutral = stream.readInt();
|
||||
retVal.itemstacks = stream.readInt();
|
||||
//retVal.update = stream.readDouble();
|
||||
retVal.update = DataTiming.readFromStream(stream);
|
||||
retVal.name = CachedString.readFromStream(stream);
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import mcp.mobius.mobiuscore.profiler.ProfilerSection;
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesBlock;
|
||||
import mcp.mobius.opis.data.managers.EntityManager;
|
||||
import mcp.mobius.opis.data.profilers.ProfilerEntityUpdate;
|
||||
|
||||
public class DataEntity implements ISerializable, Comparable {
|
||||
|
||||
public int eid;
|
||||
public long npoints;
|
||||
public CachedString name;
|
||||
public CoordinatesBlock pos;
|
||||
public DataTiming update;
|
||||
|
||||
public DataEntity fill(Entity entity){
|
||||
|
||||
this.eid = entity.entityId;
|
||||
this.name = new CachedString(EntityManager.INSTANCE.getEntityName(entity, false));
|
||||
this.pos = new CoordinatesBlock(entity);
|
||||
|
||||
WeakHashMap<Entity, DescriptiveStatistics> data = ((ProfilerEntityUpdate)(ProfilerSection.ENTITY_UPDATETIME.getProfiler())).data;
|
||||
this.update = new DataTiming(data.containsKey(entity) ? data.get(entity).getGeometricMean() : 0.0D);
|
||||
this.npoints = data.containsKey(entity) ? data.get(entity).getN() : 0;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
stream.writeInt(this.eid);
|
||||
this.name.writeToStream(stream);
|
||||
this.pos.writeToStream(stream);
|
||||
this.update.writeToStream(stream);
|
||||
stream.writeLong(this.npoints);
|
||||
}
|
||||
|
||||
public static DataEntity readFromStream(DataInputStream stream) throws IOException {
|
||||
DataEntity retVal = new DataEntity();
|
||||
retVal.eid = stream.readInt();
|
||||
retVal.name = CachedString.readFromStream(stream);
|
||||
retVal.pos = CoordinatesBlock.readFromStream(stream);
|
||||
retVal.update = DataTiming.readFromStream(stream);
|
||||
retVal.npoints= stream.readLong();
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
return this.update.compareTo(((DataEntity)o).update);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
|
||||
public class DataEntityPerClass implements Comparable, ISerializable{
|
||||
|
||||
public int nents;
|
||||
public CachedString name;
|
||||
public DataTiming update;
|
||||
|
||||
public DataEntityPerClass(){}
|
||||
|
||||
public DataEntityPerClass(String name){
|
||||
this.name = new CachedString(name);
|
||||
this.nents = 0;
|
||||
this.update = new DataTiming();
|
||||
}
|
||||
|
||||
public DataEntityPerClass add(Double timing){
|
||||
this.nents += 1;
|
||||
this.update.timing += timing;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
stream.writeInt(this.nents);
|
||||
this.name.writeToStream(stream);
|
||||
this.update.writeToStream(stream);
|
||||
}
|
||||
|
||||
public static DataEntityPerClass readFromStream(DataInputStream stream) throws IOException {
|
||||
DataEntityPerClass retVal = new DataEntityPerClass();
|
||||
retVal.nents = stream.readInt();
|
||||
retVal.name = CachedString.readFromStream(stream);
|
||||
retVal.update = DataTiming.readFromStream(stream);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
return this.update.compareTo(((DataEntityPerClass)o).update);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
import mcp.mobius.mobiuscore.profiler.ProfilerSection;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesBlock;
|
||||
import mcp.mobius.opis.data.managers.EntityManager;
|
||||
import mcp.mobius.opis.data.profilers.ProfilerRenderEntity;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
public class DataEntityRender extends DataEntity {
|
||||
|
||||
public DataEntityRender fill(Entity entity){
|
||||
|
||||
this.eid = entity.entityId;
|
||||
this.name = new CachedString(EntityManager.INSTANCE.getEntityName(entity, false));
|
||||
this.pos = new CoordinatesBlock(entity);
|
||||
|
||||
WeakHashMap<Entity, DescriptiveStatistics> data = ((ProfilerRenderEntity)(ProfilerSection.RENDER_ENTITY.getProfiler())).data;
|
||||
this.update = new DataTiming(data.containsKey(entity) ? data.get(entity).getGeometricMean() : 0.0D);
|
||||
this.npoints = data.containsKey(entity) ? data.get(entity).getN() : 0;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
|
||||
public class DataError implements ISerializable {
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
}
|
||||
|
||||
public static DataError readFromStream(DataInputStream stream) throws IOException {
|
||||
return new DataError();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
import com.google.common.collect.Table.Cell;
|
||||
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
|
||||
public class DataEvent implements ISerializable, Comparable {
|
||||
public CachedString event;
|
||||
public CachedString handler;
|
||||
public CachedString package_;
|
||||
public long nCalls;
|
||||
public DataTiming update;
|
||||
|
||||
public DataEvent fill(Cell<Class, String, DescriptiveStatistics> cell){
|
||||
/*
|
||||
String handlerName = cell.getColumnKey().getSimpleName();
|
||||
try {
|
||||
String[] splitHandler = handlerName.split("_");
|
||||
handlerName = splitHandler[2] + "." + splitHandler[3];
|
||||
} catch (Exception e){}
|
||||
*/
|
||||
String[] nameRaw = cell.getColumnKey().split("\\|");
|
||||
|
||||
String handlerName = nameRaw[1];
|
||||
try {
|
||||
String[] splitHandler = handlerName.split("_");
|
||||
handlerName = splitHandler[2] + "." + splitHandler[3];
|
||||
} catch (Exception e){}
|
||||
|
||||
this.package_= new CachedString(nameRaw[0]);
|
||||
this.handler = new CachedString(handlerName);
|
||||
this.event = new CachedString(cell.getRowKey().getName().replace("net.minecraftforge.event.", ""));
|
||||
this.nCalls = cell.getValue().getN();
|
||||
|
||||
this.update = new DataTiming(cell.getValue().getGeometricMean());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
this.event.writeToStream(stream);
|
||||
this.package_.writeToStream(stream);
|
||||
this.handler.writeToStream(stream);
|
||||
this.update.writeToStream(stream);
|
||||
stream.writeLong(this.nCalls);
|
||||
}
|
||||
|
||||
public static DataEvent readFromStream(DataInputStream stream) throws IOException {
|
||||
DataEvent retVal = new DataEvent();
|
||||
retVal.event = CachedString.readFromStream(stream);
|
||||
retVal.package_= CachedString.readFromStream(stream);
|
||||
retVal.handler = CachedString.readFromStream(stream);
|
||||
retVal.update = DataTiming.readFromStream(stream);
|
||||
retVal.nCalls = stream.readLong();
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
return this.update.compareTo(((DataHandler)o).update);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import mcp.mobius.mobiuscore.profiler.ProfilerSection;
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import mcp.mobius.opis.data.managers.TickHandlerManager;
|
||||
import mcp.mobius.opis.data.profilers.ProfilerHandler;
|
||||
import cpw.mods.fml.common.IScheduledTickHandler;
|
||||
|
||||
public class DataHandler implements ISerializable, Comparable {
|
||||
public CachedString name;
|
||||
public DataTiming update;
|
||||
|
||||
public DataHandler fillServer(IScheduledTickHandler ticker){
|
||||
double timingPre = ((ProfilerHandler)(ProfilerSection.HANDLER_TICKSTART.getProfiler())).dataServer.get(ticker).getGeometricMean();
|
||||
double timingPost = ((ProfilerHandler)(ProfilerSection.HANDLER_TICKSTOP.getProfiler())).dataServer.get(ticker).getGeometricMean();
|
||||
|
||||
this.update = new DataTiming(timingPre + timingPost);
|
||||
this.name = new CachedString(TickHandlerManager.getHandlerName(ticker));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public DataHandler fillRender(IScheduledTickHandler ticker){
|
||||
double timingPre = ((ProfilerHandler)(ProfilerSection.HANDLER_TICKSTART.getProfiler())).dataRender.get(ticker).getGeometricMean();
|
||||
double timingPost = ((ProfilerHandler)(ProfilerSection.HANDLER_TICKSTOP.getProfiler())).dataRender.get(ticker).getGeometricMean();
|
||||
|
||||
this.update = new DataTiming(timingPre + timingPost);
|
||||
this.name = new CachedString(TickHandlerManager.getHandlerName(ticker));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
this.name.writeToStream(stream);
|
||||
this.update.writeToStream(stream);
|
||||
}
|
||||
|
||||
public static DataHandler readFromStream(DataInputStream stream) throws IOException {
|
||||
DataHandler retVal = new DataHandler();
|
||||
retVal.name = CachedString.readFromStream(stream);
|
||||
retVal.update = DataTiming.readFromStream(stream);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
return this.update.compareTo(((DataHandler)o).update);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
import mcp.mobius.mobiuscore.profiler.ProfilerSection;
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import mcp.mobius.opis.data.profilers.ProfilerNetworkTick;
|
||||
|
||||
public class DataNetworkTick implements ISerializable, Comparable {
|
||||
public DataTiming update;
|
||||
|
||||
public DataNetworkTick fill(){
|
||||
|
||||
DescriptiveStatistics data = ((ProfilerNetworkTick)(ProfilerSection.NETWORK_TICK.getProfiler())).data;
|
||||
this.update = new DataTiming(data.getN() != 0 ? data.getGeometricMean() : 0.0D);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
this.update.writeToStream(stream);
|
||||
}
|
||||
|
||||
public static DataNetworkTick readFromStream(DataInputStream stream) throws IOException {
|
||||
DataNetworkTick retVal = new DataNetworkTick();
|
||||
retVal.update = DataTiming.readFromStream(stream);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
return this.update.compareTo(((DataNetworkTick)o).update);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
|
||||
public class DataPacket implements ISerializable{
|
||||
public int id;
|
||||
public DataByteSize size;
|
||||
public DataByteRate rate;
|
||||
public DataAmountRate amount;
|
||||
public String type;
|
||||
|
||||
public DataPacket(){
|
||||
}
|
||||
|
||||
public DataPacket(int id){
|
||||
this.id = id;
|
||||
this.size = new DataByteSize(0);
|
||||
this.rate = new DataByteRate(0, 5);
|
||||
this.amount = new DataAmountRate(0, 5);
|
||||
try {
|
||||
this.type = ((Class)(Packet.packetIdToClassMap.lookup(this.id))).getSimpleName();
|
||||
} catch (Exception e) {
|
||||
this.type = "<UNUSED>";
|
||||
}
|
||||
}
|
||||
|
||||
public DataPacket fill(Packet packet){
|
||||
this.size.size += packet.getPacketSize() + 1;
|
||||
this.rate.size += packet.getPacketSize() + 1;
|
||||
this.amount.size += 1;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void startInterval(){
|
||||
this.rate.reset();
|
||||
this.amount.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
stream.writeInt(this.id);
|
||||
this.size.writeToStream(stream);
|
||||
this.rate.writeToStream(stream);
|
||||
this.amount.writeToStream(stream);
|
||||
}
|
||||
|
||||
public static DataPacket readFromStream(DataInputStream stream) throws IOException {
|
||||
DataPacket retVal = new DataPacket();
|
||||
retVal.id = stream.readInt();
|
||||
retVal.size = DataByteSize.readFromStream(stream);
|
||||
retVal.rate = DataByteRate.readFromStream(stream);
|
||||
retVal.amount = DataAmountRate.readFromStream(stream);
|
||||
try {
|
||||
retVal.type = ((Class)(Packet.packetIdToClassMap.lookup(retVal.id))).getSimpleName();
|
||||
} catch (Exception e) {
|
||||
retVal.type = "<UNUSED>";
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
|
||||
public class DataPacket250 implements ISerializable{
|
||||
public CachedString channel;
|
||||
public DataByteSize size;
|
||||
public DataByteRate rate;
|
||||
public DataAmountRate amount;
|
||||
|
||||
public DataPacket250(){ }
|
||||
|
||||
public DataPacket250(String channel){
|
||||
this.channel = new CachedString(channel);
|
||||
this.size = new DataByteSize(0);
|
||||
this.rate = new DataByteRate(0, 5);
|
||||
this.amount = new DataAmountRate(0, 5);
|
||||
}
|
||||
|
||||
public DataPacket250 fill(Packet packet){
|
||||
this.size.size += packet.getPacketSize() + 1;
|
||||
this.rate.size += packet.getPacketSize() + 1;
|
||||
this.amount.size += 1;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void startInterval(){
|
||||
this.rate.reset();
|
||||
this.amount.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
this.channel.writeToStream(stream);
|
||||
this.size.writeToStream(stream);
|
||||
this.rate.writeToStream(stream);
|
||||
this.amount.writeToStream(stream);
|
||||
}
|
||||
|
||||
public static DataPacket250 readFromStream(DataInputStream stream) throws IOException {
|
||||
DataPacket250 retVal = new DataPacket250();
|
||||
retVal.channel = CachedString.readFromStream(stream);
|
||||
retVal.size = DataByteSize.readFromStream(stream);
|
||||
retVal.rate = DataByteRate.readFromStream(stream);
|
||||
retVal.amount = DataAmountRate.readFromStream(stream);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
|
||||
public class DataStringUpdate implements ISerializable {
|
||||
|
||||
public String str;
|
||||
public int index;
|
||||
|
||||
public DataStringUpdate(){}
|
||||
|
||||
public DataStringUpdate(String str, int index){
|
||||
this.str = str;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
Packet.writeString(this.str, stream);
|
||||
stream.writeInt(this.index);
|
||||
|
||||
}
|
||||
|
||||
public static DataStringUpdate readFromStream(DataInputStream stream) throws IOException {
|
||||
return new DataStringUpdate(Packet.readString(stream, 255), stream.readInt());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
|
||||
public class DataThread implements ISerializable{
|
||||
|
||||
public CachedString name;
|
||||
public CachedString clzz;
|
||||
|
||||
public DataThread fill(Thread thread){
|
||||
this.name = new CachedString(thread.getName());
|
||||
this.clzz = new CachedString(thread.getClass().getSimpleName());
|
||||
return this;
|
||||
}
|
||||
|
||||
public void writeToStream(DataOutputStream stream) throws IOException{
|
||||
this.name.writeToStream(stream);
|
||||
this.clzz.writeToStream(stream);
|
||||
|
||||
}
|
||||
|
||||
public static DataThread readFromStream(DataInputStream stream) throws IOException {
|
||||
DataThread retVal = new DataThread();
|
||||
retVal.name = CachedString.readFromStream(stream);
|
||||
retVal.clzz = CachedString.readFromStream(stream);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesBlock;
|
||||
|
||||
public class DataTileEntity implements ISerializable {
|
||||
|
||||
public CachedString clazz;
|
||||
public CoordinatesBlock pos;
|
||||
public int hashCode;
|
||||
public boolean isValid;
|
||||
public CachedString cause;
|
||||
|
||||
public DataTileEntity fill(TileEntity tileEntity, String cause){
|
||||
this.pos = new CoordinatesBlock(tileEntity.worldObj.provider.dimensionId, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
|
||||
this.clazz = new CachedString(tileEntity.getClass().getCanonicalName());
|
||||
this.hashCode = System.identityHashCode(tileEntity);
|
||||
this.isValid = !tileEntity.isInvalid();
|
||||
this.cause = new CachedString(cause);
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
public DataTileEntity fill(CoordinatesBlock coord, String clazz, int hashCode, boolean isInvalid){
|
||||
this.pos = coord;
|
||||
this.clazz = new CachedString(clazz);
|
||||
this.hashCode = hashCode;
|
||||
this.isValid = !isInvalid;
|
||||
return this;
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
this.clazz.writeToStream(stream);
|
||||
this.pos.writeToStream(stream);
|
||||
this.cause.writeToStream(stream);
|
||||
stream.writeInt(this.hashCode);
|
||||
stream.writeBoolean(this.isValid);
|
||||
|
||||
}
|
||||
|
||||
public static DataTileEntity readFromStream(DataInputStream stream) throws IOException {
|
||||
DataTileEntity retVal = new DataTileEntity();
|
||||
retVal.clazz = CachedString.readFromStream(stream);
|
||||
retVal.pos = CoordinatesBlock.readFromStream(stream);
|
||||
retVal.cause = CachedString.readFromStream(stream);
|
||||
retVal.hashCode = stream.readInt();
|
||||
retVal.isValid = stream.readBoolean();
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
import mcp.mobius.mobiuscore.profiler.ProfilerSection;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesBlock;
|
||||
import mcp.mobius.opis.data.profilers.ProfilerRenderTileEntity;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
||||
public class DataTileEntityRender extends DataBlockTileEntity {
|
||||
|
||||
public DataTileEntityRender fill(TileEntity ent){
|
||||
this.pos = new CoordinatesBlock(ent.worldObj.provider.dimensionId, ent.xCoord, ent.yCoord, ent.zCoord);
|
||||
World world = Minecraft.getMinecraft().theWorld; //DimensionManager.getWorld(this.pos.dim);
|
||||
|
||||
this.id = (short) world.getBlockId(this.pos.x, this.pos.y, this.pos.z);
|
||||
this.meta = (short) world.getBlockMetadata(this.pos.x, this.pos.y, this.pos.z);
|
||||
|
||||
WeakHashMap<TileEntity, DescriptiveStatistics> data = ((ProfilerRenderTileEntity)(ProfilerSection.RENDER_TILEENTITY.getProfiler())).data;
|
||||
this.update = new DataTiming(data.containsKey(ent) ? data.get(ent).getGeometricMean() : 0.0D);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
|
||||
public class DataTiming implements Comparable, ISerializable{
|
||||
public Double timing;
|
||||
|
||||
public DataTiming(){ this.timing = 0.0D; }
|
||||
public DataTiming(double timing){ this.timing = timing; }
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
return ((DataTiming)o).timing.compareTo(this.timing); // Reverse order ! Put higher values FIRST
|
||||
}
|
||||
|
||||
public DataTimingMillisecond asMillisecond(){
|
||||
return new DataTimingMillisecond(this.timing);
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return String.format("%.3f µs", this.timing / 1000.0);
|
||||
}
|
||||
|
||||
public void writeToStream(DataOutputStream stream) throws IOException{
|
||||
stream.writeDouble(this.timing);
|
||||
}
|
||||
|
||||
public static DataTiming readFromStream(DataInputStream stream) throws IOException {
|
||||
return new DataTiming(stream.readDouble());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class DataTimingMillisecond extends DataTiming {
|
||||
|
||||
public DataTimingMillisecond(){ this.timing = 0.0D; }
|
||||
public DataTimingMillisecond(double timing){ this.timing = timing; }
|
||||
|
||||
public String toString(){
|
||||
return String.format("%.3f ms", this.timing / 1000.0 / 1000.0);
|
||||
}
|
||||
|
||||
public void writeToStream(DataOutputStream stream) throws IOException{
|
||||
stream.writeDouble(this.timing);
|
||||
}
|
||||
|
||||
public static DataTimingMillisecond readFromStream(DataInputStream stream) throws IOException {
|
||||
return new DataTimingMillisecond(stream.readDouble());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package mcp.mobius.opis.data.holders.stats;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesBlock;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesChunk;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
public abstract class StatAbstract implements Comparable, ISerializable{
|
||||
protected DescriptiveStatistics dstat = new DescriptiveStatistics();
|
||||
public Long dataPoints = 0L;
|
||||
protected Double geomMean = null;
|
||||
protected Double dataSum = null;
|
||||
protected CoordinatesBlock coord = CoordinatesBlock.INVALID;
|
||||
protected CoordinatesChunk chunk = CoordinatesChunk.INVALID;
|
||||
protected String name;
|
||||
|
||||
/*
|
||||
public StatAbstract(){
|
||||
dstat = new DescriptiveStatistics();
|
||||
}
|
||||
|
||||
public StatAbstract(int points){
|
||||
dstat = new DescriptiveStatistics(points);
|
||||
}
|
||||
*/
|
||||
|
||||
public void addMeasure(long timing){
|
||||
//this.dstat.addValue((double)timing/1000.0);
|
||||
this.dstat.addValue((double)timing/1000.);
|
||||
dataPoints += 1;
|
||||
}
|
||||
|
||||
public void addMeasure(double timing){
|
||||
this.dstat.addValue(timing);
|
||||
dataPoints += 1;
|
||||
}
|
||||
|
||||
public double getGeometricMean(){
|
||||
if (geomMean != null)
|
||||
return geomMean;
|
||||
else
|
||||
return dstat.getGeometricMean();
|
||||
}
|
||||
|
||||
public void setGeometricMean(double value){
|
||||
this.geomMean = value;
|
||||
}
|
||||
|
||||
public double getDataSum(){
|
||||
if (dataSum != null)
|
||||
return dataSum;
|
||||
else
|
||||
return dstat.getSum();
|
||||
}
|
||||
|
||||
public void setDataSum(double value){
|
||||
this.dataSum = value;
|
||||
}
|
||||
|
||||
public long getDataPoints(){
|
||||
return this.dataPoints;
|
||||
}
|
||||
|
||||
public void setDataPoints(long ndata){
|
||||
this.dataPoints = ndata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
double value = ((StatAbstract)o).getGeometricMean() - this.getGeometricMean();
|
||||
if (value > 0)
|
||||
return 1;
|
||||
if (value < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getName(){ return this.name; };
|
||||
|
||||
public CoordinatesBlock getCoordinates() {return this.coord;}
|
||||
public CoordinatesChunk getChunk() {return this.chunk;}
|
||||
public CoordinatesBlock getTeleportTarget(){return this.coord;}
|
||||
|
||||
|
||||
public abstract void writeToStream(DataOutputStream stream) throws IOException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package mcp.mobius.opis.data.holders.stats;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesChunk;
|
||||
|
||||
public class StatsChunk extends StatAbstract{
|
||||
public int tileEntities = 0;
|
||||
public int entities = 0;
|
||||
|
||||
public StatsChunk(){}
|
||||
|
||||
public StatsChunk(CoordinatesChunk chunk){
|
||||
this.chunk = chunk;
|
||||
this.coord = chunk.asCoordinatesBlock();
|
||||
}
|
||||
|
||||
public StatsChunk(CoordinatesChunk chunk, int tileEntities, int entities){
|
||||
this.chunk = chunk;
|
||||
this.coord = chunk.asCoordinatesBlock();
|
||||
this.tileEntities = tileEntities;
|
||||
this.entities = entities;
|
||||
}
|
||||
|
||||
public StatsChunk(CoordinatesChunk chunk, int tileEntities, int entities, double time){
|
||||
this.chunk = chunk;
|
||||
this.coord = chunk.asCoordinatesBlock();
|
||||
this.tileEntities = tileEntities;
|
||||
this.entities = entities;
|
||||
this.setDataSum(time);
|
||||
}
|
||||
|
||||
public void addTileEntity(){
|
||||
this.tileEntities += 1;
|
||||
}
|
||||
|
||||
public void addEntity(){
|
||||
this.entities += 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException{
|
||||
this.chunk.writeToStream(stream);
|
||||
stream.writeInt(this.tileEntities);
|
||||
stream.writeInt(this.entities);
|
||||
stream.writeDouble(this.getDataSum());
|
||||
}
|
||||
|
||||
public static StatsChunk readFromStream(DataInputStream stream) throws IOException {
|
||||
CoordinatesChunk chunk = CoordinatesChunk.readFromStream(stream);
|
||||
StatsChunk chunkStats = new StatsChunk(chunk, stream.readInt(), stream.readInt());
|
||||
chunkStats.setDataSum(stream.readDouble());
|
||||
return chunkStats;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
double value = ((StatAbstract)o).getDataSum() - this.getDataSum();
|
||||
if (value > 0)
|
||||
return 1;
|
||||
if (value < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return String.format("%.3f µs", this.getDataSum()/1000.0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
package mcp.mobius.opis.data.managers;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
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.basetypes.TicketData;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataEntity;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataBlockTileEntity;
|
||||
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.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataRaw;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.gen.ChunkProviderServer;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import net.minecraftforge.common.ForgeChunkManager.Ticket;
|
||||
|
||||
public enum ChunkManager implements IMessageHandler{
|
||||
INSTANCE;
|
||||
|
||||
private ArrayList<CoordinatesChunk> chunksLoad = new ArrayList<CoordinatesChunk>();
|
||||
private HashMap<CoordinatesChunk, StatsChunk> chunkMeanTime = new HashMap<CoordinatesChunk, StatsChunk>();
|
||||
public ArrayList<TicketData> tickets = new ArrayList<TicketData>();
|
||||
|
||||
public void addLoadedChunks(ArrayList<ISerializable> data){
|
||||
//chunksLoad.clear();
|
||||
for (ISerializable chunk : data){
|
||||
chunksLoad.add((CoordinatesChunk)chunk);
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<CoordinatesChunk> getLoadedChunks(){
|
||||
return chunksLoad;
|
||||
}
|
||||
|
||||
public void setChunkMeanTime(ArrayList<ISerializable> data){
|
||||
chunkMeanTime.clear();
|
||||
for (ISerializable stat : data)
|
||||
chunkMeanTime.put(((StatsChunk)stat).getChunk(), (StatsChunk)stat);
|
||||
}
|
||||
|
||||
public HashMap<CoordinatesChunk, StatsChunk> getChunkMeanTime(){
|
||||
return chunkMeanTime;
|
||||
}
|
||||
|
||||
public ArrayList<CoordinatesChunk> getLoadedChunks(int dimension){
|
||||
HashSet<CoordinatesChunk> chunkStatus = new HashSet<CoordinatesChunk>();
|
||||
WorldServer world = DimensionManager.getWorld(dimension);
|
||||
if (world != null)
|
||||
{
|
||||
for (ChunkCoordIntPair coord : world.getPersistentChunks().keySet()){
|
||||
chunkStatus.add(new CoordinatesChunk(dimension, coord, (byte)1));
|
||||
}
|
||||
|
||||
for (Object o : ((ChunkProviderServer)world.getChunkProvider()).loadedChunks){
|
||||
Chunk chunk = (Chunk)o;
|
||||
|
||||
chunkStatus.add(new CoordinatesChunk(dimension, chunk.getChunkCoordIntPair(), (byte)0));
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayList<CoordinatesChunk>(chunkStatus);
|
||||
}
|
||||
|
||||
public HashSet<TicketData> getTickets(){
|
||||
HashSet<TicketData> tickets = new HashSet<TicketData>();
|
||||
for (int dim : DimensionManager.getIDs())
|
||||
for (Ticket ticket : DimensionManager.getWorld(dim).getPersistentChunks().values())
|
||||
tickets.add(new TicketData(ticket));
|
||||
|
||||
return tickets;
|
||||
}
|
||||
|
||||
public 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();
|
||||
|
||||
if (!chunks.containsKey(chunk))
|
||||
chunks.put(chunk, new StatsChunk(chunk));
|
||||
|
||||
chunks.get(chunk).addTileEntity();
|
||||
chunks.get(chunk).addMeasure(data.update.timing);
|
||||
|
||||
}
|
||||
|
||||
for (Entity entity : ((ProfilerEntityUpdate)ProfilerSection.ENTITY_UPDATETIME.getProfiler()).data.keySet()){
|
||||
DataEntity data = new DataEntity().fill(entity);
|
||||
CoordinatesChunk chunk = data.pos.asCoordinatesChunk();
|
||||
|
||||
if (!chunks.containsKey(chunk))
|
||||
chunks.put(chunk, new StatsChunk(chunk));
|
||||
|
||||
chunks.get(chunk).addEntity();
|
||||
chunks.get(chunk).addMeasure(data.update.timing);
|
||||
}
|
||||
|
||||
ArrayList<StatsChunk> chunksUpdate = new ArrayList<StatsChunk>(chunks.values());
|
||||
return chunksUpdate;
|
||||
}
|
||||
|
||||
public ArrayList<StatsChunk> getTopChunks(int quantity){
|
||||
ArrayList<StatsChunk> chunks = this.getChunksUpdateTime();
|
||||
ArrayList<StatsChunk> outList = new ArrayList<StatsChunk>();
|
||||
Collections.sort(chunks);
|
||||
|
||||
for (int i = 0; i < Math.min(quantity, chunks.size()); i++)
|
||||
outList.add(chunks.get(i));
|
||||
|
||||
return outList;
|
||||
}
|
||||
|
||||
public int getLoadedChunkAmount(){
|
||||
int loadedChunks = 0;
|
||||
for (WorldServer world : DimensionManager.getWorlds()){
|
||||
int loadedChunksForDim = world.getChunkProvider().getLoadedChunkCount();
|
||||
loadedChunks += loadedChunksForDim;
|
||||
//System.out.printf("[ %2d ] %d chunks\n", world.provider.dimensionId, loadedChunksForDim);
|
||||
}
|
||||
//System.out.printf("Total : %d chunks\n", loadedChunks);
|
||||
return loadedChunks;
|
||||
}
|
||||
|
||||
public int getForcedChunkAmount(){
|
||||
int forcedChunks = 0;
|
||||
for (WorldServer world : DimensionManager.getWorlds()){
|
||||
forcedChunks += world.getPersistentChunks().size();
|
||||
}
|
||||
return forcedChunks;
|
||||
}
|
||||
|
||||
public void purgeChunks(int dim){
|
||||
WorldServer world = DimensionManager.getWorld(dim);
|
||||
if (world == null) return;
|
||||
|
||||
int loadedChunksDelta = 100;
|
||||
|
||||
((ChunkProviderServer)world.getChunkProvider()).unloadAllChunks();
|
||||
|
||||
while(loadedChunksDelta >= 100){
|
||||
int loadedBefore = world.getChunkProvider().getLoadedChunkCount();
|
||||
world.getChunkProvider().unloadQueuedChunks();
|
||||
loadedChunksDelta = loadedBefore - world.getChunkProvider().getLoadedChunkCount();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(Message msg, NetDataRaw 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:{
|
||||
chunksLoad.clear();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,345 @@
|
||||
package mcp.mobius.opis.data.managers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.monster.EntityMob;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.network.packet.Packet3Chat;
|
||||
import net.minecraft.network.packet.Packet41EntityEffect;
|
||||
import net.minecraft.network.packet.Packet9Respawn;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.Teleporter;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldProvider;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import mcp.mobius.mobiuscore.profiler.ProfilerSection;
|
||||
import mcp.mobius.opis.data.holders.basetypes.AmountHolder;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesBlock;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesChunk;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataEntity;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataEntityPerClass;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataTiming;
|
||||
import mcp.mobius.opis.data.profilers.ProfilerEntityUpdate;
|
||||
import mcp.mobius.opis.helpers.Teleport;
|
||||
|
||||
public enum EntityManager {
|
||||
INSTANCE;
|
||||
|
||||
public ArrayList<DataEntity> getWorses(int amount){
|
||||
ArrayList<DataEntity> sorted = new ArrayList<DataEntity>();
|
||||
ArrayList<DataEntity> topEntities = new ArrayList<DataEntity>();
|
||||
|
||||
for (Entity entity : ((ProfilerEntityUpdate)ProfilerSection.ENTITY_UPDATETIME.getProfiler()).data.keySet())
|
||||
sorted.add(new DataEntity().fill(entity));
|
||||
|
||||
Collections.sort(sorted);
|
||||
|
||||
int i = 0;
|
||||
while (topEntities.size() < Math.min(amount, sorted.size()) && (i < sorted.size()) ){
|
||||
DataEntity testats = sorted.get(i);
|
||||
|
||||
if (testats.npoints < 40){ i++; continue; }
|
||||
if (DimensionManager.getWorld(testats.pos.dim) == null) { i++; continue; }
|
||||
|
||||
topEntities.add(testats);
|
||||
i++;
|
||||
}
|
||||
return topEntities;
|
||||
}
|
||||
|
||||
/* Returns all the entities in all dimensions (without timing data) */
|
||||
public ArrayList<DataEntity> getAllEntities(){
|
||||
ArrayList<DataEntity> entities = new ArrayList<DataEntity>();
|
||||
for (int i : DimensionManager.getIDs()){
|
||||
entities.addAll(this.getEntitiesInDim(i));
|
||||
}
|
||||
return entities;
|
||||
}
|
||||
|
||||
/* Returns all the entities in the given dimension (without timing data) */
|
||||
public ArrayList<DataEntity> getEntitiesInDim(int dim){
|
||||
ArrayList<DataEntity> entities = new ArrayList<DataEntity>();
|
||||
|
||||
World world = DimensionManager.getWorld(dim);
|
||||
if (world == null) return entities;
|
||||
|
||||
ArrayList copyList = new ArrayList(world.loadedEntityList);
|
||||
|
||||
for (int i = 0; i < copyList.size(); i++){
|
||||
Entity ent = (Entity)copyList.get(i);
|
||||
entities.add(new DataEntity().fill(ent));
|
||||
}
|
||||
|
||||
return entities;
|
||||
}
|
||||
|
||||
/* Returns a hashmap of all entities per chunk (not timing) */
|
||||
public HashMap<CoordinatesChunk, ArrayList<DataEntity>> getAllEntitiesPerChunk(){
|
||||
HashMap<CoordinatesChunk, ArrayList<DataEntity>> entities = new HashMap<CoordinatesChunk, ArrayList<DataEntity>>();
|
||||
for (int i : DimensionManager.getIDs()){
|
||||
entities.putAll(this.getEntitiesPerChunkInDim(i));
|
||||
}
|
||||
return entities;
|
||||
}
|
||||
|
||||
/* Returns a hashmap of entities in the given dimension (not timing) */
|
||||
public HashMap<CoordinatesChunk, ArrayList<DataEntity>> getEntitiesPerChunkInDim(int dim){
|
||||
HashMap<CoordinatesChunk, ArrayList<DataEntity>> entities = new HashMap<CoordinatesChunk, ArrayList<DataEntity>>();
|
||||
World world = DimensionManager.getWorld(dim);
|
||||
if (world == null) return entities;
|
||||
|
||||
ArrayList copyList = new ArrayList(world.loadedEntityList);
|
||||
|
||||
for (int i = 0; i < copyList.size(); i++){
|
||||
Entity ent = (Entity)copyList.get(i);
|
||||
CoordinatesChunk chunk = new CoordinatesBlock(ent.dimension, (int)ent.posX, (int)ent.posY, (int)ent.posZ).asCoordinatesChunk();
|
||||
|
||||
if (!entities.containsKey(chunk))
|
||||
entities.put(chunk, new ArrayList<DataEntity>());
|
||||
|
||||
//entities.get(chunk).add(new EntityStats(ent.entityId, ent.getClass().getName(), ent.dimension, ent.posX, ent.posY, ent.posZ));
|
||||
entities.get(chunk).add(new DataEntity().fill(ent));
|
||||
}
|
||||
|
||||
return entities;
|
||||
}
|
||||
|
||||
/* Returns an array of all entities in a given chunk */
|
||||
public ArrayList<DataEntity> getEntitiesInChunk(CoordinatesChunk coord){
|
||||
ArrayList<DataEntity> entities = new ArrayList<DataEntity>();
|
||||
|
||||
World world = DimensionManager.getWorld(coord.dim);
|
||||
if (world == null) return entities;
|
||||
|
||||
ArrayList copyList = new ArrayList(world.loadedEntityList);
|
||||
|
||||
for (int i = 0; i < copyList.size(); i++){
|
||||
Entity ent = (Entity)copyList.get(i);
|
||||
CoordinatesChunk chunk = new CoordinatesBlock(ent.dimension, (int)ent.posX, (int)ent.posY, (int)ent.posZ).asCoordinatesChunk();
|
||||
if (chunk.equals(coord))
|
||||
//entities.add(new EntityStats(ent.entityId, ent.getClass().getName(), ent.dimension, ent.posX, ent.posY, ent.posZ));
|
||||
entities.add(new DataEntity().fill(ent));
|
||||
}
|
||||
|
||||
return entities;
|
||||
}
|
||||
|
||||
/* Returns a hashmap with the entity name and amount of it on the server */
|
||||
public ArrayList<AmountHolder> getCumulativeEntities(boolean filtered){
|
||||
ArrayList<AmountHolder> cumData = new ArrayList<AmountHolder>();
|
||||
HashMap<String, Integer> entities = new HashMap<String, Integer>();
|
||||
|
||||
for (int dim : DimensionManager.getIDs()){
|
||||
World world = DimensionManager.getWorld(dim);
|
||||
if (world == null) continue;
|
||||
|
||||
ArrayList copyList = new ArrayList(world.loadedEntityList);
|
||||
|
||||
for (int i = 0; i < copyList.size(); i++){
|
||||
Entity ent = (Entity)copyList.get(i);
|
||||
//String name = ent.getClass().getName();
|
||||
String name = getEntityName(ent, filtered);
|
||||
|
||||
if (!entities.containsKey(name))
|
||||
entities.put(name, 0);
|
||||
|
||||
entities.put(name, entities.get(name) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
for (String key : entities.keySet())
|
||||
cumData.add(new AmountHolder(key, entities.get(key)));
|
||||
|
||||
return cumData;
|
||||
}
|
||||
|
||||
public boolean teleportPlayer(CoordinatesBlock coord, EntityPlayerMP player){
|
||||
//System.out.printf("%s %s\n", coord, getTeleportTarget(coord));
|
||||
CoordinatesBlock target = Teleport.instance().getTeleportTarget(coord);
|
||||
if (target == null) return false;
|
||||
|
||||
target = Teleport.instance().fixNetherTP(target);
|
||||
|
||||
if (target == null) return false;
|
||||
|
||||
if (Teleport.instance().movePlayerToDimension(player, coord.dim))
|
||||
player.setPositionAndUpdate(target.x + 0.5, target.y, target.z + 0.5);
|
||||
else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean teleportEntity(Entity src, Entity trg, Player msgtrg){
|
||||
if ((src == null) && (msgtrg != null)) {
|
||||
PacketDispatcher.sendPacketToPlayer(new Packet3Chat(ChatMessageComponent.createFromText(String.format("\u00A7oCannot find source entity %s", src))), (Player)msgtrg);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((trg == null) && (msgtrg != null)) {
|
||||
PacketDispatcher.sendPacketToPlayer(new Packet3Chat(ChatMessageComponent.createFromText(String.format("\u00A7oCannot find target entity %s", trg))), (Player)msgtrg);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (src instanceof EntityPlayerMP){
|
||||
if (Teleport.instance().movePlayerToDimension((EntityPlayerMP)src, trg.worldObj.provider.dimensionId))
|
||||
src.setLocationAndAngles(trg.posX, trg.posY, trg.posZ, src.rotationYaw, src.rotationPitch);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
if (Teleport.instance().moveEntityToDimension(src, trg.worldObj.provider.dimensionId))
|
||||
src.setLocationAndAngles(trg.posX, trg.posY, trg.posZ, src.rotationYaw, src.rotationPitch);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public Entity getEntity(int eid, int dim){
|
||||
World world = DimensionManager.getWorld(dim);
|
||||
if (world == null) return null;
|
||||
|
||||
Entity entity = world.getEntityByID(eid);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public String getEntityName(Entity ent){
|
||||
return getEntityName(ent, false);
|
||||
}
|
||||
|
||||
public String getEntityName(Entity ent, boolean filtered){
|
||||
if (ent instanceof EntityItem && filtered){
|
||||
return "Dropped Item";
|
||||
} else if (ent instanceof EntityItem && !filtered){
|
||||
try {
|
||||
return "[Stack] " + ((EntityItem)ent).getEntityItem().getDisplayName();
|
||||
} catch (Exception e) {
|
||||
return "<Unknown dropped item>";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (ent instanceof EntityPlayerMP && filtered)
|
||||
return "Player";
|
||||
else if (ent instanceof EntityPlayerMP && !filtered)
|
||||
return "[ Player ] " + ((EntityPlayerMP)ent).getDisplayName();
|
||||
|
||||
String name = ent.getTranslatedEntityName();
|
||||
|
||||
if (name.contains(".")){
|
||||
String[] namelst = ent.getClass().getName().split("\\.");
|
||||
return namelst[namelst.length - 1];
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
public DataTiming getTotalUpdateTime(){
|
||||
double updateTime = 0D;
|
||||
for (Entity entity : ((ProfilerEntityUpdate)ProfilerSection.ENTITY_UPDATETIME.getProfiler()).data.keySet()){
|
||||
updateTime += ((ProfilerEntityUpdate)ProfilerSection.ENTITY_UPDATETIME.getProfiler()).data.get(entity).getGeometricMean();
|
||||
}
|
||||
return new DataTiming(updateTime);
|
||||
}
|
||||
|
||||
public int killAll(String entName){
|
||||
int nkilled = 0;
|
||||
|
||||
if (entName.contains("Player")){
|
||||
return -1; //Error msg for when trying to kill a player
|
||||
}
|
||||
|
||||
|
||||
for (int dim : DimensionManager.getIDs()){
|
||||
World world = DimensionManager.getWorld(dim);
|
||||
if (world == null) continue;
|
||||
|
||||
ArrayList copyList = new ArrayList(world.loadedEntityList);
|
||||
|
||||
for (Object o : copyList){
|
||||
Entity ent = (Entity)o;
|
||||
String nameFiltered = this.getEntityName(ent, true).toLowerCase();
|
||||
String nameUnfiltered = this.getEntityName(ent, false).toLowerCase();
|
||||
|
||||
if (nameFiltered.equals(entName.toLowerCase()) || nameUnfiltered.equals(entName.toLowerCase())){
|
||||
ent.setDead();
|
||||
nkilled += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.printf("Killed %d %s\n", nkilled, entName);
|
||||
|
||||
return nkilled;
|
||||
}
|
||||
|
||||
public ArrayList<DataEntity> getAllPlayers(){
|
||||
List players = MinecraftServer.getServerConfigurationManager(MinecraftServer.getServer()).playerEntityList;
|
||||
ArrayList<DataEntity> outList = new ArrayList<DataEntity>();
|
||||
|
||||
for (Object p : players)
|
||||
outList.add(new DataEntity().fill((EntityPlayer) p));
|
||||
|
||||
return outList;
|
||||
}
|
||||
|
||||
public int getAmountEntities(){
|
||||
int amountEntities = 0;
|
||||
for (WorldServer world : DimensionManager.getWorlds()){
|
||||
amountEntities += world.loadedEntityList.size();
|
||||
}
|
||||
return amountEntities;
|
||||
}
|
||||
|
||||
public int killAllPerClass(int dim, Class clazz){
|
||||
WorldServer world = DimensionManager.getWorld(dim);
|
||||
if (world == null) return -1;
|
||||
|
||||
int killedEnts = 0;
|
||||
|
||||
ArrayList copyList = new ArrayList(world.loadedEntityList);
|
||||
|
||||
for (Entity entity : (ArrayList<Entity>)copyList){
|
||||
if (clazz.isInstance(entity)){
|
||||
entity.setDead();
|
||||
killedEnts += 1;
|
||||
}
|
||||
}
|
||||
return killedEnts;
|
||||
}
|
||||
|
||||
public ArrayList<DataEntityPerClass> getTotalPerClass(){
|
||||
HashMap<String, DataEntityPerClass> data = new HashMap<String, DataEntityPerClass>();
|
||||
|
||||
for (Entity entity : ((ProfilerEntityUpdate)ProfilerSection.ENTITY_UPDATETIME.getProfiler()).data.keySet()){
|
||||
String name = this.getEntityName(entity, true);
|
||||
if (!data.containsKey(name))
|
||||
data.put(name, new DataEntityPerClass(name));
|
||||
|
||||
data.get(name).add(((ProfilerEntityUpdate)ProfilerSection.ENTITY_UPDATETIME.getProfiler()).data.get(entity).getGeometricMean());
|
||||
}
|
||||
return new ArrayList<DataEntityPerClass>(data.values());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package mcp.mobius.opis.data.managers;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import mcp.mobius.mobiuscore.profiler.ProfilerSection;
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import mcp.mobius.opis.events.OpisServerTickHandler;
|
||||
|
||||
public class MetaManager {
|
||||
|
||||
public static void reset(){
|
||||
modOpis.profilerRun = false;
|
||||
modOpis.selectedBlock = null;
|
||||
OpisServerTickHandler.INSTANCE.profilerRunningTicks = 0;
|
||||
|
||||
ProfilerSection.resetAll(Side.SERVER);
|
||||
ProfilerSection.desactivateAll(Side.SERVER);
|
||||
//ProfilerSection.resetAll(Side.CLIENT);
|
||||
//ProfilerSection.desactivateAll(Side.CLIENT);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package mcp.mobius.opis.data.managers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import mcp.mobius.opis.api.IMessageHandler;
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataStringUpdate;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataList;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataRaw;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataValue;
|
||||
|
||||
public enum StringCache implements IMessageHandler {
|
||||
INSTANCE;
|
||||
|
||||
private int currentIndex = -1;
|
||||
private HashBiMap<Integer, String> cache = HashBiMap.create();
|
||||
private ArrayList<DataStringUpdate> toSend = new ArrayList<DataStringUpdate>();
|
||||
|
||||
public String getString(int index){
|
||||
String retVal = this.cache.get(index);
|
||||
if (retVal == null){
|
||||
//modOpis.log.info(String.format("++++ Couldn't find string for index %d", index));
|
||||
return "<ERROR>";
|
||||
}else
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public int getIndex(String str){
|
||||
|
||||
if (cache.inverse().containsKey(str)){
|
||||
//if (cache.inverse().get(str) == -1){
|
||||
// throw new RuntimeException(String.format("Found a misaligned key ! %s", str));
|
||||
//}
|
||||
|
||||
return cache.inverse().get(str);
|
||||
}
|
||||
else{
|
||||
currentIndex += 1;
|
||||
cache.put(currentIndex, str);
|
||||
|
||||
//System.out.printf("++++ Adding string %s with index %d to cache\n", str, currentIndex);
|
||||
|
||||
DataStringUpdate upd = new DataStringUpdate(str, currentIndex);
|
||||
this.toSend.add(upd);
|
||||
|
||||
PacketDispatcher.sendPacketToAllPlayers(NetDataValue.create(Message.STATUS_STRINGUPD, upd).packet);
|
||||
return currentIndex;
|
||||
}
|
||||
}
|
||||
|
||||
public void syncCache(Player player){
|
||||
|
||||
int i = 0;
|
||||
|
||||
ArrayList<DataStringUpdate> toSendCopy = new ArrayList(toSend);
|
||||
|
||||
while (i < toSendCopy.size()){
|
||||
PacketDispatcher.sendPacketToPlayer(NetDataList.create(Message.STATUS_STRINGUPD_FULL, toSendCopy.subList(i, Math.min(i + 50, toSendCopy.size()))).packet, player);
|
||||
i += 50;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(Message msg, NetDataRaw rawdata) {
|
||||
switch(msg){
|
||||
case STATUS_STRINGUPD:{
|
||||
DataStringUpdate data = (DataStringUpdate)rawdata.value;
|
||||
//modOpis.log.info(String.format("++++ Received String Cache update : [%d] %s", data.index, data.str));
|
||||
try{
|
||||
this.cache.put(data.index, data.str);
|
||||
} catch (IllegalArgumentException e){
|
||||
this.cache.remove(data.index);
|
||||
this.cache.inverse().remove(data.str);
|
||||
this.cache.put(data.index, data.str);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case STATUS_STRINGUPD_FULL:{
|
||||
modOpis.log.info(String.format("Received full String Cache update containing %d entries", rawdata.array.size()));
|
||||
|
||||
for (ISerializable idata : rawdata.array){
|
||||
DataStringUpdate data = (DataStringUpdate)idata;
|
||||
//modOpis.log.info(String.format("++++ Received String Cache update : [%d] %s", data.index, data.str));
|
||||
try{
|
||||
this.cache.put(data.index, data.str);
|
||||
} catch (IllegalArgumentException e){
|
||||
this.cache.remove(data.index);
|
||||
this.cache.inverse().remove(data.str);
|
||||
this.cache.put(data.index, data.str);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package mcp.mobius.opis.data.managers;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import cpw.mods.fml.common.IScheduledTickHandler;
|
||||
import cpw.mods.fml.common.SingleIntervalHandler;
|
||||
import mcp.mobius.mobiuscore.profiler.ProfilerSection;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataHandler;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataTiming;
|
||||
import mcp.mobius.opis.data.profilers.ProfilerHandler;
|
||||
|
||||
public class TickHandlerManager {
|
||||
|
||||
public static Class SingleIntervalHandlerReflect;
|
||||
public static Field wrapped;
|
||||
|
||||
static {
|
||||
try{
|
||||
SingleIntervalHandlerReflect = Class.forName("cpw.mods.fml.common.SingleIntervalHandler");
|
||||
wrapped = SingleIntervalHandlerReflect.getDeclaredField("wrapped");
|
||||
wrapped.setAccessible(true);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
throw new RuntimeException(e);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<DataHandler> getCumulatedStatsServer(){
|
||||
ArrayList<DataHandler> retVal = new ArrayList<DataHandler>();
|
||||
for (IScheduledTickHandler ticker : ((ProfilerHandler)(ProfilerSection.HANDLER_TICKSTART.getProfiler())).dataServer.keySet())
|
||||
retVal.add(new DataHandler().fillServer(ticker));
|
||||
|
||||
Collections.sort(retVal);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public static ArrayList<DataHandler> getCumulatedStatsRender(){
|
||||
ArrayList<DataHandler> retVal = new ArrayList<DataHandler>();
|
||||
for (IScheduledTickHandler ticker : ((ProfilerHandler)(ProfilerSection.HANDLER_TICKSTART.getProfiler())).dataRender.keySet())
|
||||
retVal.add(new DataHandler().fillRender(ticker));
|
||||
|
||||
Collections.sort(retVal);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public static String getHandlerName(IScheduledTickHandler handler){
|
||||
String name = handler.getLabel();
|
||||
if (name == null || name.equals("")){
|
||||
if (handler instanceof SingleIntervalHandler){
|
||||
try{
|
||||
Object ticker = wrapped.get(handler);
|
||||
name = ticker.getClass().getName();
|
||||
} catch (Exception e) {
|
||||
name = "<Unnamed SingleIntervalHandler>";
|
||||
}
|
||||
} else {
|
||||
name = handler.getClass().getName();
|
||||
}
|
||||
}
|
||||
/*
|
||||
}else{
|
||||
name = handler.getClass().getName();
|
||||
}
|
||||
*/
|
||||
/*
|
||||
if (name == null || name.equals("")){
|
||||
name = "<Unnamed SingleIntervalHandler>";
|
||||
}
|
||||
*/
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
public static DataTiming getTotalUpdateTime(){
|
||||
double updateTime = 0D;
|
||||
for (IScheduledTickHandler ticker : ((ProfilerHandler)(ProfilerSection.HANDLER_TICKSTART.getProfiler())).dataServer.keySet())
|
||||
updateTime += new DataHandler().fillServer(ticker).update.timing;
|
||||
|
||||
return new DataTiming(updateTime);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
package mcp.mobius.opis.data.managers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import com.google.common.collect.HashBasedTable;
|
||||
|
||||
import mcp.mobius.mobiuscore.profiler.ProfilerSection;
|
||||
import mcp.mobius.opis.modOpis;
|
||||
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.DataBlockTileEntityPerClass;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataTileEntity;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataTiming;
|
||||
import mcp.mobius.opis.data.holders.stats.StatsChunk;
|
||||
import mcp.mobius.opis.data.profilers.ProfilerTileEntityUpdate;
|
||||
import mcp.mobius.opis.helpers.ModIdentification;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
||||
public enum TileEntityManager {
|
||||
INSTANCE;
|
||||
|
||||
public HashMap<CoordinatesChunk, StatsChunk> getTimes(int dim){
|
||||
HashMap<CoordinatesChunk, StatsChunk> chunks = new HashMap<CoordinatesChunk, StatsChunk>();
|
||||
|
||||
for (CoordinatesBlock coord : ((ProfilerTileEntityUpdate)ProfilerSection.TILEENT_UPDATETIME.getProfiler()).data.keySet()){
|
||||
if (coord.dim == dim){
|
||||
|
||||
CoordinatesChunk coordC = new CoordinatesChunk(coord);
|
||||
if (!(chunks.containsKey(coordC)))
|
||||
chunks.put(coordC, new StatsChunk());
|
||||
|
||||
chunks.get(coordC).addEntity();
|
||||
chunks.get(coordC).addMeasure(((ProfilerTileEntityUpdate)ProfilerSection.TILEENT_UPDATETIME.getProfiler()).data.get(coord).getGeometricMean());
|
||||
}
|
||||
}
|
||||
return chunks;
|
||||
}
|
||||
|
||||
private void cleanUpStats(){
|
||||
|
||||
/*
|
||||
HashSet<CoordinatesBlock> dirty = new HashSet<CoordinatesBlock>();
|
||||
|
||||
for (CoordinatesBlock tecoord : TileEntityManager.stats.keySet()){
|
||||
World world = DimensionManager.getWorld(tecoord.dim);
|
||||
int blockID = world.getBlockId(tecoord.x, tecoord.y, tecoord.z);
|
||||
short blockMeta = (short)world.getBlockMetadata(tecoord.x, tecoord.y, tecoord.z);
|
||||
|
||||
if ((blockID != TileEntityManager.stats.get(tecoord).getID()) || (blockMeta != TileEntityManager.stats.get(tecoord).getMeta())){
|
||||
dirty.add(tecoord);
|
||||
}
|
||||
}
|
||||
|
||||
for (CoordinatesBlock tecoord : dirty){
|
||||
stats.remove(tecoord);
|
||||
references.remove(tecoord);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<DataBlockTileEntity> getTileEntitiesInChunk(CoordinatesChunk coord){
|
||||
cleanUpStats();
|
||||
|
||||
ArrayList<DataBlockTileEntity> returnList = new ArrayList<DataBlockTileEntity>();
|
||||
|
||||
for (CoordinatesBlock tecoord : ((ProfilerTileEntityUpdate)ProfilerSection.TILEENT_UPDATETIME.getProfiler()).data.keySet()){
|
||||
if (coord.equals(tecoord.asCoordinatesChunk())){
|
||||
DataBlockTileEntity testats = new DataBlockTileEntity().fill(tecoord);
|
||||
|
||||
returnList.add(testats);
|
||||
}
|
||||
}
|
||||
|
||||
return returnList;
|
||||
}
|
||||
|
||||
public ArrayList<DataBlockTileEntity> getWorses(int amount){
|
||||
ArrayList<DataBlockTileEntity> sorted = new ArrayList<DataBlockTileEntity>();
|
||||
ArrayList<DataBlockTileEntity> topEntities = new ArrayList<DataBlockTileEntity>();
|
||||
|
||||
for (CoordinatesBlock coord : ((ProfilerTileEntityUpdate)ProfilerSection.TILEENT_UPDATETIME.getProfiler()).data.keySet())
|
||||
sorted.add(new DataBlockTileEntity().fill(coord));
|
||||
|
||||
Collections.sort(sorted);
|
||||
|
||||
for (int i = 0; i < Math.min(amount, sorted.size()); i++)
|
||||
topEntities.add(sorted.get(i));
|
||||
|
||||
|
||||
return topEntities;
|
||||
}
|
||||
|
||||
public DataTiming getTotalUpdateTime(){
|
||||
double updateTime = 0D;
|
||||
for (CoordinatesBlock coords : ((ProfilerTileEntityUpdate)ProfilerSection.TILEENT_UPDATETIME.getProfiler()).data.keySet()){
|
||||
updateTime += ((ProfilerTileEntityUpdate)ProfilerSection.TILEENT_UPDATETIME.getProfiler()).data.get(coords).getGeometricMean();
|
||||
}
|
||||
return new DataTiming(updateTime);
|
||||
}
|
||||
|
||||
public int getAmountTileEntities(){
|
||||
int amountTileEntities = 0;
|
||||
for (WorldServer world : DimensionManager.getWorlds()){
|
||||
amountTileEntities += world.loadedTileEntityList.size();
|
||||
}
|
||||
return amountTileEntities;
|
||||
}
|
||||
|
||||
public ArrayList<DataTileEntity> getOrphans(){
|
||||
ArrayList<DataTileEntity> orphans = new ArrayList<DataTileEntity>();
|
||||
HashMap<CoordinatesBlock, DataTileEntity> coordHashset = new HashMap<CoordinatesBlock, DataTileEntity>();
|
||||
HashSet<Integer> registeredEntities = new HashSet<Integer>();
|
||||
|
||||
for (WorldServer world : DimensionManager.getWorlds()){
|
||||
for (Object o : world.loadedTileEntityList){
|
||||
TileEntity tileEntity = (TileEntity)o;
|
||||
CoordinatesBlock coord = new CoordinatesBlock(world.provider.dimensionId, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
|
||||
int hash = System.identityHashCode(tileEntity);
|
||||
|
||||
if (registeredEntities.contains(hash)) continue; //This entitie has already been seen;
|
||||
|
||||
int id = world.getBlockId(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
|
||||
if (id == 0 || Block.blocksList[id] == null
|
||||
|| !Block.blocksList[id].hasTileEntity()
|
||||
|| world.getBlockTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord) == null
|
||||
|| world.getBlockTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord).getClass() != tileEntity.getClass()){
|
||||
|
||||
orphans.add(new DataTileEntity().fill(tileEntity, "Orphan"));
|
||||
registeredEntities.add(hash);
|
||||
}
|
||||
|
||||
if (coordHashset.containsKey(coord)){
|
||||
if (!registeredEntities.contains(hash))
|
||||
orphans.add(new DataTileEntity().fill(tileEntity, "Duplicate"));
|
||||
|
||||
if (!registeredEntities.contains(coordHashset.get(coord).hashCode))
|
||||
orphans.add(coordHashset.get(coord));
|
||||
}
|
||||
|
||||
if (!coordHashset.containsKey(coord)){
|
||||
coordHashset.put(coord, new DataTileEntity().fill(tileEntity, "Duplicate"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
modOpis.log.warning(String.format("Found %d potential orphans !", orphans.size()));
|
||||
|
||||
return orphans;
|
||||
}
|
||||
|
||||
public ArrayList<DataBlockTileEntityPerClass> getCumulativeAmountTileEntities(){
|
||||
HashBasedTable<Integer, Integer, DataBlockTileEntityPerClass> data = HashBasedTable.create();
|
||||
|
||||
for (WorldServer world : DimensionManager.getWorlds()){
|
||||
for (Object o : world.loadedTileEntityList){
|
||||
TileEntity tileEntity = (TileEntity)o;
|
||||
int id = world.getBlockId(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
|
||||
int meta = world.getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
|
||||
|
||||
if (!data.contains(id, meta))
|
||||
data.put(id, meta, new DataBlockTileEntityPerClass(id, meta));
|
||||
|
||||
data.get(id, meta).add();
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayList<DataBlockTileEntityPerClass>(data.values());
|
||||
}
|
||||
|
||||
public ArrayList<DataBlockTileEntityPerClass> getCumulativeTimingTileEntities(){
|
||||
HashBasedTable<Integer, Integer, DataBlockTileEntityPerClass> data = HashBasedTable.create();
|
||||
|
||||
for (CoordinatesBlock coord : ((ProfilerTileEntityUpdate)ProfilerSection.TILEENT_UPDATETIME.getProfiler()).data.keySet()){
|
||||
World world = DimensionManager.getWorld(coord.dim);
|
||||
int id = world.getBlockId(coord.x, coord.y, coord.z);
|
||||
int meta = world.getBlockMetadata(coord.x, coord.y, coord.z);
|
||||
|
||||
if (!data.contains(id, meta))
|
||||
data.put(id, meta, new DataBlockTileEntityPerClass(id, meta));
|
||||
|
||||
data.get(id, meta).add(((ProfilerTileEntityUpdate)ProfilerSection.TILEENT_UPDATETIME.getProfiler()).data.get(coord).getGeometricMean());
|
||||
|
||||
}
|
||||
|
||||
return new ArrayList<DataBlockTileEntityPerClass>(data.values());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package mcp.mobius.opis.data.profilers;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.ThreadInfo;
|
||||
import java.lang.management.ThreadMXBean;
|
||||
|
||||
import javax.management.ObjectName;
|
||||
|
||||
public class Clock {
|
||||
|
||||
public interface IClock{
|
||||
void start();
|
||||
void stop();
|
||||
long getDelta();
|
||||
}
|
||||
|
||||
public static ThreadMXBean threadMX = ManagementFactory.getThreadMXBean();
|
||||
//public static boolean canThreadCPU = threadMX.isCurrentThreadCpuTimeSupported();
|
||||
public static boolean canThreadCPU = false;
|
||||
|
||||
public class ClockMX implements IClock{
|
||||
public long startTime = 0;
|
||||
public long timeDelta = 0;
|
||||
public void start(){this.startTime = threadMX.getCurrentThreadCpuTime();}
|
||||
public void stop() {this.timeDelta = threadMX.getCurrentThreadCpuTime() - this.startTime;}
|
||||
public long getDelta() {return this.timeDelta;}
|
||||
}
|
||||
|
||||
public class ClockNano implements IClock{
|
||||
public long startTime = 0;
|
||||
public long timeDelta = 0;
|
||||
public void start(){this.startTime = System.nanoTime();}
|
||||
public void stop() {this.timeDelta = System.nanoTime() - this.startTime;}
|
||||
public long getDelta() {return this.timeDelta;}
|
||||
}
|
||||
|
||||
public static IClock getNewClock(){
|
||||
if (Clock.canThreadCPU)
|
||||
return new Clock().new ClockMX();
|
||||
else
|
||||
return new Clock().new ClockNano();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package mcp.mobius.opis.data.profilers;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
public class DeadManSwitch implements Runnable{
|
||||
|
||||
public static DeadManSwitch instance;
|
||||
private Thread serverThread = null;
|
||||
private MinecraftServer server = null;
|
||||
private AtomicLong timer = new AtomicLong();
|
||||
private AtomicLong timerPrev = new AtomicLong();
|
||||
private Long lastTested = 0L;
|
||||
private long nderps = 0L;
|
||||
private BlockingQueue<Long> queue = new ArrayBlockingQueue<Long>(2);
|
||||
|
||||
public DeadManSwitch(MinecraftServer server, Thread serverThread){
|
||||
this.server = server;
|
||||
this.serverThread = serverThread;
|
||||
DeadManSwitch.instance = this;
|
||||
|
||||
}
|
||||
|
||||
public void setTimer(long time){
|
||||
this.timerPrev.set(this.timer.get());
|
||||
this.timer.set(time);
|
||||
}
|
||||
|
||||
public long getTimerDelta(){
|
||||
return this.timer.get() - this.timerPrev.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
System.out.printf("Starting Dead Man Switch\n");
|
||||
|
||||
//while (server.isServerRunning()){
|
||||
while (true){
|
||||
|
||||
try{
|
||||
if (this.lastTested != this.timer.get()){
|
||||
|
||||
//if (this.getTimerDelta() / 1000. / 1000. > 1000.){
|
||||
if (this.getTimerDelta() / 1000. / 1000. > 300.){
|
||||
System.out.printf("==== Main thread is staled ! %.3f ms [ %d ]====\n", this.getTimerDelta() / 1000. / 1000., this.nderps);
|
||||
|
||||
this.nderps += 1;
|
||||
|
||||
if (this.nderps > 10){
|
||||
/*
|
||||
this.nderps = 0;
|
||||
this.serverThread.interrupt();
|
||||
System.out.printf("Restarting\n");
|
||||
Thread.sleep(1000);
|
||||
MinecraftServer.main(MinecraftServer.arguments);
|
||||
System.out.printf("Restarted\n");
|
||||
return;
|
||||
*/
|
||||
for (Thread thread : Thread.getAllStackTraces().keySet()){
|
||||
if (thread != Thread.currentThread()){
|
||||
try{
|
||||
thread.interrupt();
|
||||
} catch (Exception e){
|
||||
System.out.printf("%s\n",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.lastTested = this.timer.get();
|
||||
}
|
||||
catch (Exception e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
LockSupport.parkNanos(1L * 1000L * 1000L);
|
||||
}
|
||||
}
|
||||
|
||||
public static DeadManSwitch startDeadManSwitch(MinecraftServer server){
|
||||
DeadManSwitch deadManSwitch = new DeadManSwitch(server, Thread.currentThread());
|
||||
Thread deadManSwitchThrd = new Thread(deadManSwitch);
|
||||
deadManSwitchThrd.setName("Dead Man Switch");
|
||||
deadManSwitchThrd.setPriority(Thread.MAX_PRIORITY);
|
||||
//deadManSwitchThrd.setDaemon(false);
|
||||
deadManSwitchThrd.start();
|
||||
return deadManSwitch;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package mcp.mobius.opis.data.profilers;
|
||||
|
||||
import mcp.mobius.mobiuscore.profiler.IProfilerBase;
|
||||
|
||||
public abstract class ProfilerAbstract implements IProfilerBase {
|
||||
|
||||
@Override
|
||||
public abstract void reset();
|
||||
|
||||
@Override
|
||||
public void start() {}
|
||||
|
||||
@Override
|
||||
public void stop() {}
|
||||
|
||||
@Override
|
||||
public void start(Object key) {}
|
||||
|
||||
@Override
|
||||
public void stop(Object key) {}
|
||||
|
||||
@Override
|
||||
public void start(Object key1, Object key2) {}
|
||||
|
||||
@Override
|
||||
public void stop(Object key1, Object key2) {}
|
||||
|
||||
@Override
|
||||
public void start(Object key1, Object key2, Object key3) {}
|
||||
|
||||
@Override
|
||||
public void stop(Object key1, Object key2, Object key3) {}
|
||||
|
||||
@Override
|
||||
public void start(Object key1, Object key2, Object key3, Object key4) {}
|
||||
|
||||
@Override
|
||||
public void stop(Object key1, Object key2, Object key3, Object key4) {}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package mcp.mobius.opis.data.profilers;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
import mcp.mobius.mobiuscore.profiler.IProfilerBase;
|
||||
import mcp.mobius.opis.data.profilers.Clock.IClock;
|
||||
|
||||
public class ProfilerDimBlockTick extends ProfilerAbstract implements IProfilerBase {
|
||||
|
||||
private IClock clock = Clock.getNewClock();
|
||||
public HashMap<Integer, DescriptiveStatistics> data = new HashMap<Integer, DescriptiveStatistics>();
|
||||
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
this.data.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Object key) {
|
||||
Integer dim = (Integer)key;
|
||||
if (DimensionManager.getWorld(dim).isRemote) return;
|
||||
|
||||
if (!data.containsKey(dim))
|
||||
data.put(dim, new DescriptiveStatistics());
|
||||
clock.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(Object key) {
|
||||
Integer dim = (Integer)key;
|
||||
if (DimensionManager.getWorld(dim).isRemote) return;
|
||||
|
||||
clock.stop();
|
||||
data.get(dim).addValue((double)clock.getDelta());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package mcp.mobius.opis.data.profilers;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import mcp.mobius.mobiuscore.profiler.IProfilerBase;
|
||||
import mcp.mobius.opis.data.profilers.Clock.IClock;
|
||||
|
||||
public class ProfilerDimTick extends ProfilerAbstract implements IProfilerBase {
|
||||
|
||||
private IClock clock = Clock.getNewClock();
|
||||
public HashMap<Integer, DescriptiveStatistics> data = new HashMap<Integer, DescriptiveStatistics>();
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
this.data.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Object key) {
|
||||
World world = (World)key;
|
||||
if (world.isRemote) return;
|
||||
|
||||
if (!data.containsKey(world.provider.dimensionId))
|
||||
data.put(world.provider.dimensionId, new DescriptiveStatistics(20));
|
||||
clock.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(Object key) {
|
||||
World world = (World)key;
|
||||
if (world.isRemote) return;
|
||||
|
||||
clock.stop();
|
||||
data.get(world.provider.dimensionId).addValue((double)clock.getDelta());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package mcp.mobius.opis.data.profilers;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
import mcp.mobius.mobiuscore.profiler.IProfilerBase;
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import mcp.mobius.opis.data.profilers.Clock.IClock;
|
||||
|
||||
public class ProfilerEntityUpdate extends ProfilerAbstract implements IProfilerBase {
|
||||
|
||||
private IClock clock = Clock.getNewClock();
|
||||
public WeakHashMap<Entity, DescriptiveStatistics> data = new WeakHashMap<Entity, DescriptiveStatistics>();
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
this.data = new WeakHashMap<Entity, DescriptiveStatistics>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Object key) {
|
||||
Entity entity = (Entity)key;
|
||||
if (entity.worldObj.isRemote) return;
|
||||
|
||||
if (!data.containsKey(entity))
|
||||
data.put(entity, new DescriptiveStatistics());
|
||||
clock.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(Object key) {
|
||||
Entity entity = (Entity)key;
|
||||
if (entity.worldObj.isRemote) return;
|
||||
|
||||
clock.stop();
|
||||
try{
|
||||
data.get(entity).addValue((double)clock.getDelta());
|
||||
} catch (Exception e){
|
||||
modOpis.log.warning(String.format("Error while profiling entity %s\n", key));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package mcp.mobius.opis.data.profilers;
|
||||
|
||||
import mcp.mobius.opis.data.profilers.Clock.IClock;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
import com.google.common.collect.HashBasedTable;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
|
||||
public class ProfilerEvent extends ProfilerAbstract {
|
||||
|
||||
private IClock clock = Clock.getNewClock();
|
||||
public HashBasedTable<Class, String, DescriptiveStatistics> data = HashBasedTable.create();
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
data.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
clock.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(Object key1, Object key2, Object key3) {
|
||||
clock.stop();
|
||||
|
||||
try{
|
||||
String name = (String)key2 + "|" + key3.getClass().getSimpleName();
|
||||
data.get(key1.getClass(), name).addValue((double)clock.getDelta());
|
||||
} catch (Exception e) {
|
||||
String name = (String)key2 + "|" + key3.getClass().getSimpleName();
|
||||
data.put(key1.getClass(), name, new DescriptiveStatistics(250));
|
||||
data.get(key1.getClass(), name).addValue((double)clock.getDelta());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package mcp.mobius.opis.data.profilers;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import mcp.mobius.opis.data.profilers.Clock.IClock;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
import cpw.mods.fml.common.IScheduledTickHandler;
|
||||
import cpw.mods.fml.common.TickType;
|
||||
|
||||
public class ProfilerHandler extends ProfilerAbstract {
|
||||
|
||||
private IClock clockServer = Clock.getNewClock();
|
||||
private IClock clockRender = Clock.getNewClock();
|
||||
public WeakHashMap<IScheduledTickHandler, DescriptiveStatistics> dataServer = new WeakHashMap<IScheduledTickHandler, DescriptiveStatistics>();
|
||||
public WeakHashMap<IScheduledTickHandler, DescriptiveStatistics> dataRender = new WeakHashMap<IScheduledTickHandler, DescriptiveStatistics>();
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Object key1, Object key2) {
|
||||
IScheduledTickHandler ticker = (IScheduledTickHandler) key1;
|
||||
EnumSet<TickType> ticksToRun = (EnumSet<TickType>) key2;
|
||||
|
||||
if (ticksToRun.contains(TickType.SERVER) && ticksToRun.size() == 1){
|
||||
if (!dataServer.containsKey(ticker))
|
||||
dataServer.put(ticker, new DescriptiveStatistics());
|
||||
|
||||
clockServer.start();
|
||||
}
|
||||
|
||||
else if (ticksToRun.contains(TickType.RENDER) && ticksToRun.size() == 1){
|
||||
if (!dataRender.containsKey(ticker))
|
||||
dataRender.put(ticker, new DescriptiveStatistics());
|
||||
|
||||
clockRender.start();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(Object key1, Object key2) {
|
||||
IScheduledTickHandler ticker = (IScheduledTickHandler) key1;
|
||||
EnumSet<TickType> ticksToRun = (EnumSet<TickType>) key2;
|
||||
if (ticksToRun.contains(TickType.SERVER) && ticksToRun.size() == 1){
|
||||
clockServer.stop();
|
||||
dataServer.get(ticker).addValue((double)clockServer.getDelta());
|
||||
}
|
||||
|
||||
else if (ticksToRun.contains(TickType.RENDER) && ticksToRun.size() == 1){
|
||||
clockRender.stop();
|
||||
dataRender.get(ticker).addValue((double)clockRender.getDelta());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package mcp.mobius.opis.data.profilers;
|
||||
|
||||
import mcp.mobius.opis.data.profilers.Clock.IClock;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
public class ProfilerNetworkTick extends ProfilerAbstract {
|
||||
|
||||
private IClock clock = Clock.getNewClock();
|
||||
public DescriptiveStatistics data = new DescriptiveStatistics();
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
data.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(){
|
||||
clock.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(){
|
||||
clock.stop();
|
||||
data.addValue((double)clock.getDelta());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package mcp.mobius.opis.data.profilers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataPacket;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataPacket250;
|
||||
import mcp.mobius.opis.helpers.Helpers;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
|
||||
public class ProfilerPacket extends ProfilerAbstract {
|
||||
|
||||
public long dataAmount = 0;
|
||||
public ArrayList<DataPacket> data = new ArrayList<DataPacket>();
|
||||
public HashMap<String, DataPacket250> data250 = new HashMap<String, DataPacket250>();
|
||||
|
||||
public ArrayList<DataPacket> jabbaSpec = new ArrayList<DataPacket>();
|
||||
|
||||
public ProfilerPacket(){
|
||||
for (int i = 0; i < 256; i++)
|
||||
data.add(new DataPacket(i));
|
||||
|
||||
}
|
||||
|
||||
public void startInterval(){
|
||||
for (DataPacket packet : data)
|
||||
packet.startInterval();
|
||||
|
||||
for (DataPacket250 packet : data250.values())
|
||||
packet.startInterval();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
dataAmount = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Object key) {
|
||||
if (key != null && Helpers.getEffectiveSide() == Side.SERVER){
|
||||
//System.out.printf("%s | %s\n", Thread.currentThread().getClass(), Thread.currentThread().getName());
|
||||
|
||||
Packet packet = (Packet)key;
|
||||
dataAmount += packet.getPacketSize() + 1;
|
||||
data.get(packet.getPacketId()).fill(packet);
|
||||
|
||||
if (packet.getPacketId() == 250){
|
||||
String channel = ((Packet250CustomPayload)packet).channel;
|
||||
|
||||
try{
|
||||
data250.get(channel).fill(packet);
|
||||
} catch (Exception e){
|
||||
data250.put(channel, new DataPacket250(channel));
|
||||
data250.get(channel).fill(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package mcp.mobius.opis.data.profilers;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesBlock;
|
||||
import mcp.mobius.opis.data.profilers.Clock.IClock;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
public class ProfilerRenderBlock extends ProfilerAbstract {
|
||||
|
||||
private IClock clock = Clock.getNewClock();
|
||||
public HashMap<CoordinatesBlock, DescriptiveStatistics> data = new HashMap<CoordinatesBlock, DescriptiveStatistics>();
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Object key1, Object key2, Object key3, Object key4) {
|
||||
CoordinatesBlock coord = new CoordinatesBlock(Minecraft.getMinecraft().theWorld.provider.dimensionId, (Integer)key2, (Integer)key3, (Integer)key4);
|
||||
|
||||
if (!data.containsKey(coord))
|
||||
data.put(coord, new DescriptiveStatistics());
|
||||
clock.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(Object key1, Object key2, Object key3, Object key4) {
|
||||
CoordinatesBlock coord = new CoordinatesBlock(Minecraft.getMinecraft().theWorld.provider.dimensionId, (Integer)key2, (Integer)key3, (Integer)key4);
|
||||
|
||||
clock.stop();
|
||||
data.get(coord).addValue((double)clock.getDelta());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package mcp.mobius.opis.data.profilers;
|
||||
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import mcp.mobius.opis.data.profilers.Clock.IClock;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
public class ProfilerRenderEntity extends ProfilerAbstract {
|
||||
|
||||
public WeakHashMap<Entity, DescriptiveStatistics> data = new WeakHashMap<Entity, DescriptiveStatistics>();
|
||||
private IClock clock = Clock.getNewClock();
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
data.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Object key){
|
||||
Entity entity = (Entity)key;
|
||||
if (!data.containsKey(entity))
|
||||
data.put(entity, new DescriptiveStatistics());
|
||||
|
||||
clock.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(Object key){
|
||||
clock.stop();
|
||||
try{
|
||||
data.get((Entity)key).addValue((double)clock.getDelta());
|
||||
} catch (Exception e) {
|
||||
modOpis.log.warning(String.format("Error while profiling entity %s\n", key));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package mcp.mobius.opis.data.profilers;
|
||||
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import mcp.mobius.opis.data.profilers.Clock.IClock;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class ProfilerRenderTileEntity extends ProfilerAbstract {
|
||||
|
||||
public WeakHashMap<TileEntity, DescriptiveStatistics> data = new WeakHashMap<TileEntity, DescriptiveStatistics>();
|
||||
private IClock clock = Clock.getNewClock();
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
data.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Object key){
|
||||
TileEntity tileEnt = (TileEntity)key;
|
||||
if (!data.containsKey(tileEnt))
|
||||
data.put(tileEnt, new DescriptiveStatistics());
|
||||
|
||||
clock.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(Object key){
|
||||
clock.stop();
|
||||
try{
|
||||
data.get((TileEntity)key).addValue((double)clock.getDelta());
|
||||
} catch (Exception e) {
|
||||
modOpis.log.warning(String.format("Error while profiling entity %s\n", key));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package mcp.mobius.opis.data.profilers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import mcp.mobius.opis.data.profilers.Clock.IClock;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
public class ProfilerTick extends ProfilerAbstract {
|
||||
|
||||
private IClock clock = Clock.getNewClock();
|
||||
public DescriptiveStatistics data = new DescriptiveStatistics(20);
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
//this.data.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
//DeadManSwitch.instance.setTimer(System.nanoTime());
|
||||
this.clock.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
this.clock.stop();
|
||||
this.data.addValue((double)clock.getDelta());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package mcp.mobius.opis.data.profilers;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesBlock;
|
||||
import mcp.mobius.opis.data.profilers.Clock.IClock;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class ProfilerTileEntityUpdate extends ProfilerAbstract {
|
||||
|
||||
private IClock clock = Clock.getNewClock();
|
||||
public HashMap<CoordinatesBlock, DescriptiveStatistics> data = new HashMap<CoordinatesBlock, DescriptiveStatistics>();
|
||||
public HashMap<CoordinatesBlock, Class> refs = new HashMap<CoordinatesBlock, Class>();
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
this.data.clear();
|
||||
this.refs.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Object key) {
|
||||
TileEntity tileent = (TileEntity)key;
|
||||
if (tileent.getWorldObj().isRemote) return;
|
||||
|
||||
CoordinatesBlock coord = new CoordinatesBlock(tileent);
|
||||
|
||||
if (!data.containsKey(coord) || (refs.get(coord) != tileent.getClass())){
|
||||
data.put(coord, new DescriptiveStatistics());
|
||||
refs.put(coord, tileent.getClass());
|
||||
}
|
||||
clock.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(Object key) {
|
||||
TileEntity tileent = (TileEntity)key;
|
||||
if (tileent.getWorldObj().isRemote) return;
|
||||
|
||||
clock.stop();
|
||||
CoordinatesBlock coord = new CoordinatesBlock(tileent);
|
||||
|
||||
data.get(coord).addValue((double)clock.getDelta());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package mcp.mobius.opis.events;
|
||||
|
||||
public class EventTimer {
|
||||
private long interval;
|
||||
private long lastTick = System.nanoTime();
|
||||
|
||||
public EventTimer(long interval){
|
||||
this.interval = interval * 1000L * 1000L; //Interval is passed in millisecond but stored in nanosecond.
|
||||
}
|
||||
|
||||
public boolean isDone(){
|
||||
long time = System.nanoTime();
|
||||
long delta = (time - this.lastTick) - this.interval;
|
||||
boolean done = delta >= 0;
|
||||
if (!done) return false;
|
||||
|
||||
this.lastTick = time - delta;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package mcp.mobius.opis.events;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||
import net.minecraftforge.event.ForgeSubscribe;
|
||||
|
||||
public class OpisClientEventHandler {
|
||||
|
||||
@ForgeSubscribe
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void onRenderWorldLast(RenderWorldLastEvent event) {
|
||||
if (modOpis.selectedBlock == null) return;
|
||||
if (Minecraft.getMinecraft().theWorld.provider.dimensionId != modOpis.selectedBlock.dim) return;
|
||||
if (Minecraft.getMinecraft().theWorld.isAirBlock(modOpis.selectedBlock.x, modOpis.selectedBlock.y, modOpis.selectedBlock.z)) return;
|
||||
|
||||
double partialTicks = event.partialTicks;
|
||||
|
||||
EntityLivingBase player = Minecraft.getMinecraft().renderViewEntity;
|
||||
double px = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
|
||||
double py = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
|
||||
double pz = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
|
||||
|
||||
int bx = modOpis.selectedBlock.x;
|
||||
int by = modOpis.selectedBlock.y;
|
||||
int bz = modOpis.selectedBlock.z;
|
||||
|
||||
double offset = 0.02;
|
||||
double delta = 1 + 2 * offset;
|
||||
|
||||
double x = bx - px - offset;
|
||||
double y = by - py - offset;
|
||||
double z = bz - pz - offset;
|
||||
|
||||
GL11.glPushAttrib(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glDepthMask(false);
|
||||
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
tessellator.startDrawingQuads();
|
||||
|
||||
tessellator.setColorRGBA(255, 0, 0, 150);
|
||||
|
||||
tessellator.addVertex(x, y, z);
|
||||
tessellator.addVertex(x + delta, y, z);
|
||||
tessellator.addVertex(x + delta, y, z + delta);
|
||||
tessellator.addVertex(x, y, z + delta);
|
||||
|
||||
tessellator.addVertex(x, y + delta, z);
|
||||
tessellator.addVertex(x, y + delta, z + delta);
|
||||
tessellator.addVertex(x + delta, y + delta, z + delta);
|
||||
tessellator.addVertex(x + delta, y + delta, z);
|
||||
|
||||
tessellator.addVertex(x, y, z);
|
||||
tessellator.addVertex(x, y + delta, z);
|
||||
tessellator.addVertex(x + delta, y + delta, z);
|
||||
tessellator.addVertex(x + delta, y, z);
|
||||
|
||||
tessellator.addVertex(x, y, z + delta);
|
||||
tessellator.addVertex(x + delta, y, z + delta);
|
||||
tessellator.addVertex(x + delta, y + delta, z + delta);
|
||||
tessellator.addVertex(x, y + delta, z + delta);
|
||||
|
||||
tessellator.addVertex(x, y, z);
|
||||
tessellator.addVertex(x, y, z + delta);
|
||||
tessellator.addVertex(x, y + delta, z + delta);
|
||||
tessellator.addVertex(x, y + delta, z);
|
||||
|
||||
tessellator.addVertex(x + delta, y, z);
|
||||
tessellator.addVertex(x + delta, y + delta, z);
|
||||
tessellator.addVertex(x + delta, y + delta, z + delta);
|
||||
tessellator.addVertex(x + delta, y, z + delta);
|
||||
|
||||
tessellator.draw();
|
||||
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
|
||||
GL11.glPopAttrib();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
package mcp.mobius.opis.events;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
import com.google.common.collect.HashBasedTable;
|
||||
import com.google.common.collect.Table.Cell;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import mcp.mobius.mobiuscore.profiler.ProfilerSection;
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import mcp.mobius.opis.api.TabPanelRegistrar;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesBlock;
|
||||
import mcp.mobius.opis.data.holders.basetypes.SerialLong;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataBlockRender;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataEntityRender;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataEvent;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataHandler;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataTileEntityRender;
|
||||
import mcp.mobius.opis.data.managers.TickHandlerManager;
|
||||
import mcp.mobius.opis.data.profilers.ProfilerEvent;
|
||||
import mcp.mobius.opis.data.profilers.ProfilerRenderBlock;
|
||||
import mcp.mobius.opis.data.profilers.ProfilerRenderEntity;
|
||||
import mcp.mobius.opis.data.profilers.ProfilerRenderTileEntity;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.client.Packet_ReqData;
|
||||
import mcp.mobius.opis.swing.SelectedTab;
|
||||
import mcp.mobius.opis.swing.panels.timingclient.PanelRenderEntities;
|
||||
import mcp.mobius.opis.swing.panels.timingclient.PanelRenderHandlers;
|
||||
import mcp.mobius.opis.swing.panels.timingclient.PanelRenderTileEnts;
|
||||
import mcp.mobius.opis.swing.panels.timingclient.PanelEventClient;
|
||||
import cpw.mods.fml.common.ITickHandler;
|
||||
import cpw.mods.fml.common.TickType;
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
public enum OpisClientTickHandler implements ITickHandler {
|
||||
INSTANCE;
|
||||
|
||||
public long profilerUpdateTickCounter = 0;
|
||||
public long profilerRunningTicks = 0;
|
||||
public EventTimer timer500 = new EventTimer(500);
|
||||
public EventTimer timer1000 = new EventTimer(1000);
|
||||
public EventTimer timer2000 = new EventTimer(2000);
|
||||
public EventTimer timer5000 = new EventTimer(5000);
|
||||
public EventTimer timer10000 = new EventTimer(10000);
|
||||
|
||||
@Override
|
||||
public void tickStart(EnumSet<TickType> type, Object... tickData) {}
|
||||
|
||||
@Override
|
||||
public void tickEnd(EnumSet<TickType> type, Object... tickData) {
|
||||
if(type.contains(TickType.CLIENT)){
|
||||
|
||||
// One second timer
|
||||
if (timer1000.isDone()){
|
||||
if(modOpis.swingOpen)
|
||||
PacketDispatcher.sendPacketToServer(Packet_ReqData.create(Message.STATUS_PING, new SerialLong(System.nanoTime())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (modOpis.profilerRunClient){
|
||||
((PanelRenderTileEnts)(TabPanelRegistrar.INSTANCE.getTab(SelectedTab.RENDERTILEENTS))).getBtnRunRender().setText("Running...");
|
||||
((PanelRenderEntities)(TabPanelRegistrar.INSTANCE.getTab(SelectedTab.RENDERENTITIES))).getBtnRunRender().setText("Running...");
|
||||
((PanelRenderHandlers)(TabPanelRegistrar.INSTANCE.getTab(SelectedTab.RENDERHANDLERS))).getBtnRunRender().setText("Running...");
|
||||
((PanelEventClient)(TabPanelRegistrar.INSTANCE.getTab(SelectedTab.CLIENTEVENTS))).getBtnRunRender().setText("Running...");
|
||||
}
|
||||
else{
|
||||
((PanelRenderTileEnts)(TabPanelRegistrar.INSTANCE.getTab(SelectedTab.RENDERTILEENTS))).getBtnRunRender().setText("Run Render");
|
||||
((PanelRenderEntities)(TabPanelRegistrar.INSTANCE.getTab(SelectedTab.RENDERENTITIES))).getBtnRunRender().setText("Run Render");
|
||||
((PanelRenderHandlers)(TabPanelRegistrar.INSTANCE.getTab(SelectedTab.RENDERHANDLERS))).getBtnRunRender().setText("Run Render");
|
||||
((PanelEventClient)(TabPanelRegistrar.INSTANCE.getTab(SelectedTab.CLIENTEVENTS))).getBtnRunRender().setText("Run Render");
|
||||
}
|
||||
|
||||
profilerUpdateTickCounter++;
|
||||
|
||||
if (profilerRunningTicks < modOpis.profilerMaxTicks && modOpis.profilerRunClient){
|
||||
profilerRunningTicks++;
|
||||
}else if (profilerRunningTicks >= modOpis.profilerMaxTicks && modOpis.profilerRunClient){
|
||||
profilerRunningTicks = 0;
|
||||
modOpis.profilerRunClient = false;
|
||||
ProfilerSection.desactivateAll(Side.CLIENT);
|
||||
|
||||
System.out.printf("Profiling done\n");
|
||||
|
||||
this.updateTabs();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<TickType> ticks() {
|
||||
return EnumSet.of(TickType.CLIENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "opis.client.tickhandler";
|
||||
}
|
||||
|
||||
private void updateTabs(){
|
||||
//====================================================================================
|
||||
|
||||
ArrayList<DataTileEntityRender> tileEntData = new ArrayList<DataTileEntityRender>();
|
||||
double tileEntTotal = 0.0D;
|
||||
for (TileEntity te : ((ProfilerRenderTileEntity)ProfilerSection.RENDER_TILEENTITY.getProfiler()).data.keySet()){
|
||||
try{
|
||||
DataTileEntityRender dataTe = new DataTileEntityRender().fill(te);
|
||||
tileEntData.add(dataTe);
|
||||
tileEntTotal += dataTe.update.timing;
|
||||
} catch (Exception e) {
|
||||
modOpis.log.warning(String.format("Error while adding entity %s to the list", te));
|
||||
}
|
||||
}
|
||||
|
||||
System.out.printf("Rendered %d TileEntities\n", tileEntData.size());
|
||||
|
||||
Collections.sort(tileEntData);
|
||||
((PanelRenderTileEnts)(TabPanelRegistrar.INSTANCE.getTab(SelectedTab.RENDERTILEENTS))).setTable(tileEntData);
|
||||
((PanelRenderTileEnts)(TabPanelRegistrar.INSTANCE.getTab(SelectedTab.RENDERTILEENTS))).getLblTotal().setText(String.format("Total : %.3f µs", tileEntTotal / 1000.0));
|
||||
|
||||
//====================================================================================
|
||||
|
||||
ArrayList<DataEntityRender> entData = new ArrayList<DataEntityRender>();
|
||||
double entTotal = 0.0D;
|
||||
for (Entity ent : ((ProfilerRenderEntity)ProfilerSection.RENDER_ENTITY.getProfiler()).data.keySet()){
|
||||
try{
|
||||
DataEntityRender dataEnt = new DataEntityRender().fill(ent);
|
||||
entData.add(dataEnt);
|
||||
entTotal += dataEnt.update.timing;
|
||||
} catch (Exception e) {
|
||||
modOpis.log.warning(String.format("Error while adding entity %s to the list", ent));
|
||||
}
|
||||
}
|
||||
|
||||
System.out.printf("Rendered %d Entities\n", entData.size());
|
||||
|
||||
Collections.sort(entData);
|
||||
((PanelRenderEntities)(TabPanelRegistrar.INSTANCE.getTab(SelectedTab.RENDERENTITIES))).setTable(entData);
|
||||
((PanelRenderEntities)(TabPanelRegistrar.INSTANCE.getTab(SelectedTab.RENDERENTITIES))).getLblTotal().setText(String.format("Total : %.3f µs", entTotal / 1000.0));
|
||||
|
||||
//====================================================================================
|
||||
|
||||
((PanelRenderHandlers)(TabPanelRegistrar.INSTANCE.getTab(SelectedTab.RENDERHANDLERS))).setTable(TickHandlerManager.getCumulatedStatsRender());
|
||||
|
||||
//====================================================================================
|
||||
|
||||
ArrayList<DataEvent> timingEvents = new ArrayList<DataEvent>();
|
||||
HashBasedTable<Class, String, DescriptiveStatistics> eventData = ((ProfilerEvent)ProfilerSection.EVENT_INVOKE.getProfiler()).data;
|
||||
for (Cell<Class, String, DescriptiveStatistics> cell : eventData.cellSet()){
|
||||
timingEvents.add(new DataEvent().fill(cell));
|
||||
}
|
||||
((PanelEventClient)(TabPanelRegistrar.INSTANCE.getTab(SelectedTab.CLIENTEVENTS))).setTable(timingEvents);
|
||||
|
||||
//====================================================================================
|
||||
|
||||
ArrayList<DataBlockRender> blockData = new ArrayList<DataBlockRender>();
|
||||
for (CoordinatesBlock coord : ((ProfilerRenderBlock)ProfilerSection.RENDER_BLOCK.getProfiler()).data.keySet()){
|
||||
try{
|
||||
DataBlockRender dataBlock = new DataBlockRender().fill(coord);
|
||||
blockData.add(dataBlock);
|
||||
} catch (Exception e) {
|
||||
modOpis.log.warning(String.format("Error while adding block %s to the list", coord));
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(blockData);
|
||||
for (DataBlockRender data : blockData){
|
||||
ItemStack stack = new ItemStack(data.id, 0, data.meta);
|
||||
String name = stack.getDisplayName();
|
||||
|
||||
System.out.printf("%s %s : %s\n", data.pos, name, data.update);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package mcp.mobius.opis.events;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraftforge.event.ForgeSubscribe;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
|
||||
public class OpisServerEventHandler {
|
||||
|
||||
public static boolean printEntityTrace = false;
|
||||
public static boolean printEntityFull = false;
|
||||
|
||||
@ForgeSubscribe
|
||||
@SideOnly(Side.SERVER)
|
||||
public void onEntityConstructed(EntityEvent.EntityConstructing event) {
|
||||
if (printEntityTrace){
|
||||
|
||||
if (event.entity instanceof EntityItem){
|
||||
System.out.printf("Entity %s of type %s [ %s ] created\n", event.entity.entityId, event.entity.getClass().getName(), ((EntityItem)(event.entity)).getEntityItem().getDisplayName());
|
||||
|
||||
|
||||
} else {
|
||||
System.out.printf("Entity %s of type %s created\n", event.entity.entityId, event.entity.getClass().getName());
|
||||
}
|
||||
|
||||
|
||||
if (printEntityFull){
|
||||
try{
|
||||
throw new RuntimeException();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
package mcp.mobius.opis.events;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
||||
|
||||
import com.google.common.collect.HashBasedTable;
|
||||
import com.google.common.collect.Table;
|
||||
import com.google.common.collect.Table.Cell;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.packet.Packet3Chat;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import mcp.mobius.opis.data.holders.basetypes.AmountHolder;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesChunk;
|
||||
import mcp.mobius.opis.data.holders.basetypes.SerialDouble;
|
||||
import mcp.mobius.opis.data.holders.basetypes.SerialInt;
|
||||
import mcp.mobius.opis.data.holders.basetypes.SerialLong;
|
||||
import mcp.mobius.opis.data.holders.newtypes.CachedString;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataDimension;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataPacket;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataPacket250;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataThread;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataTiming;
|
||||
import mcp.mobius.opis.data.holders.stats.StatsChunk;
|
||||
import mcp.mobius.opis.data.managers.ChunkManager;
|
||||
import mcp.mobius.opis.data.managers.EntityManager;
|
||||
import mcp.mobius.opis.data.managers.TickHandlerManager;
|
||||
import mcp.mobius.opis.data.managers.TileEntityManager;
|
||||
import mcp.mobius.opis.data.profilers.ProfilerEvent;
|
||||
import mcp.mobius.opis.data.profilers.ProfilerPacket;
|
||||
import mcp.mobius.opis.data.profilers.ProfilerTick;
|
||||
import mcp.mobius.opis.gui.overlay.OverlayStatus;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler;
|
||||
import mcp.mobius.opis.network.enums.AccessLevel;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataCommand;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataList;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataValue;
|
||||
import cpw.mods.fml.common.ITickHandler;
|
||||
import cpw.mods.fml.common.TickType;
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import mcp.mobius.mobiuscore.profiler.ProfilerSection;
|
||||
|
||||
public enum OpisServerTickHandler implements ITickHandler {
|
||||
INSTANCE;
|
||||
|
||||
public long profilerUpdateTickCounter = 0;
|
||||
public int profilerRunningTicks;
|
||||
public EventTimer timer500 = new EventTimer(500);
|
||||
public EventTimer timer1000 = new EventTimer(1000);
|
||||
public EventTimer timer2000 = new EventTimer(2000);
|
||||
public EventTimer timer5000 = new EventTimer(5000);
|
||||
public EventTimer timer10000 = new EventTimer(10000);
|
||||
|
||||
public HashMap<Player, AccessLevel> cachedAccess = new HashMap<Player, AccessLevel>();
|
||||
|
||||
@Override
|
||||
public void tickStart(EnumSet<TickType> type, Object... tickData) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tickEnd(EnumSet<TickType> type, Object... tickData) {
|
||||
if(type.contains(TickType.SERVER)){
|
||||
|
||||
/*
|
||||
if (System.nanoTime() - timer500 > 500000000){
|
||||
timer500 = System.nanoTime();
|
||||
|
||||
for (Player player : PlayerTracker.instance().playersSwing){
|
||||
PacketDispatcher.sendPacketToPlayer(Packet_DataValue.create(DataReq.VALUE_TIMING_TICK, TickProfiler.instance().stats), player);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// One second timer
|
||||
if (timer1000.isDone()){
|
||||
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_AMOUNT_UPLOAD, new SerialLong(((ProfilerPacket)ProfilerSection.PACKET_OUTBOUND.getProfiler()).dataAmount)));
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_AMOUNT_DOWNLOAD, new SerialLong(((ProfilerPacket)ProfilerSection.PACKET_INBOUND.getProfiler()).dataAmount)));
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_CHUNK_FORCED, new SerialInt(ChunkManager.INSTANCE.getForcedChunkAmount())));
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_CHUNK_LOADED, new SerialInt(ChunkManager.INSTANCE.getLoadedChunkAmount())));
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_TIMING_TICK, new DataTiming(((ProfilerTick)ProfilerSection.TICK.getProfiler()).data.getGeometricMean())));
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_AMOUNT_TILEENTS, new SerialInt(TileEntityManager.INSTANCE.getAmountTileEntities())));
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_AMOUNT_ENTITIES, new SerialInt(EntityManager.INSTANCE.getAmountEntities())));
|
||||
|
||||
for (Player player : PlayerTracker.instance().playersSwing){
|
||||
if (!cachedAccess.containsKey(player) || cachedAccess.get(player) != PlayerTracker.instance().getPlayerAccessLevel(player)){
|
||||
OpisPacketHandler.validateAndSend(NetDataValue.create(Message.STATUS_ACCESS_LEVEL, new SerialInt(PlayerTracker.instance().getPlayerAccessLevel(player).ordinal())), player);
|
||||
cachedAccess.put(player, PlayerTracker.instance().getPlayerAccessLevel(player));
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<DataThread> threads = new ArrayList<DataThread>();
|
||||
for (Thread t : Thread.getAllStackTraces().keySet()){
|
||||
threads.add(new DataThread().fill(t));
|
||||
}
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataList.create(Message.LIST_THREADS, threads));
|
||||
|
||||
// Dimension data update.
|
||||
ArrayList<DataDimension> dimData = new ArrayList<DataDimension>();
|
||||
for (int dim : DimensionManager.getIDs()){
|
||||
dimData.add(new DataDimension().fill(dim));
|
||||
}
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataList.create(Message.LIST_DIMENSION_DATA, dimData));
|
||||
|
||||
// Profiler update (if running)
|
||||
if (modOpis.profilerRun){
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.STATUS_RUNNING, new SerialInt(modOpis.profilerMaxTicks)));
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.STATUS_RUN_UPDATE, new SerialInt(profilerRunningTicks)));
|
||||
}
|
||||
|
||||
((ProfilerPacket)ProfilerSection.PACKET_INBOUND.getProfiler()).dataAmount = 0L;
|
||||
((ProfilerPacket)ProfilerSection.PACKET_OUTBOUND.getProfiler()).dataAmount = 0L;
|
||||
}
|
||||
|
||||
// Two second timer
|
||||
if (timer2000.isDone()){
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataList.create(Message.LIST_PLAYERS, EntityManager.INSTANCE.getAllPlayers()));
|
||||
}
|
||||
|
||||
// Five second timer
|
||||
if (timer5000.isDone()){
|
||||
updatePlayers();
|
||||
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataList.create(Message.LIST_PACKETS_OUTBOUND, ((ProfilerPacket)ProfilerSection.PACKET_OUTBOUND.getProfiler()).data));
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataList.create(Message.LIST_PACKETS_INBOUND, ((ProfilerPacket)ProfilerSection.PACKET_INBOUND.getProfiler()).data));
|
||||
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataList.create(Message.LIST_PACKETS_OUTBOUND_250, new ArrayList<DataPacket250>( ((ProfilerPacket)ProfilerSection.PACKET_OUTBOUND.getProfiler()).data250.values())));
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataList.create(Message.LIST_PACKETS_INBOUND_250, new ArrayList<DataPacket250>( ((ProfilerPacket)ProfilerSection.PACKET_INBOUND.getProfiler()).data250.values())));
|
||||
|
||||
((ProfilerPacket)ProfilerSection.PACKET_OUTBOUND.getProfiler()).startInterval();
|
||||
((ProfilerPacket)ProfilerSection.PACKET_INBOUND.getProfiler()).startInterval();
|
||||
|
||||
/*
|
||||
for (DataPacket data : ((ProfilerPacket)ProfilerSection.PACKET_OUTBOUND.getProfiler()).jabbaSpec){
|
||||
System.out.printf("[ %d ] %d %d\n", data.id, data.amount, data.size);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
profilerUpdateTickCounter++;
|
||||
|
||||
if (profilerRunningTicks < modOpis.profilerMaxTicks && modOpis.profilerRun){
|
||||
profilerRunningTicks++;
|
||||
}else if (profilerRunningTicks >= modOpis.profilerMaxTicks && modOpis.profilerRun){
|
||||
profilerRunningTicks = 0;
|
||||
modOpis.profilerRun = false;
|
||||
ProfilerSection.desactivateAll(Side.SERVER);
|
||||
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.STATUS_STOP, new SerialInt(modOpis.profilerMaxTicks)));
|
||||
|
||||
for (Player player : PlayerTracker.instance().playersSwing){
|
||||
OpisPacketHandler.sendFullUpdate(player);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<TickType> ticks() {
|
||||
return EnumSet.of(TickType.SERVER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "opis.server.tickhandler";
|
||||
}
|
||||
|
||||
private void updatePlayers(){
|
||||
for (Player player : PlayerTracker.instance().playerOverlayStatus.keySet()){
|
||||
|
||||
if (PlayerTracker.instance().playerOverlayStatus.get(player) == OverlayStatus.CHUNKSTATUS){
|
||||
OpisPacketHandler.validateAndSend(NetDataCommand.create(Message.LIST_CHUNK_LOADED_CLEAR), player);
|
||||
OpisPacketHandler.splitAndSend(Message.LIST_CHUNK_LOADED, ChunkManager.INSTANCE.getLoadedChunks(PlayerTracker.instance().playerDimension.get(player)), player);
|
||||
}
|
||||
|
||||
if (PlayerTracker.instance().playerOverlayStatus.get(player) == OverlayStatus.MEANTIME){
|
||||
ArrayList<StatsChunk> timingChunks = ChunkManager.INSTANCE.getTopChunks(100);
|
||||
//OpisPacketHandler.validateAndSend(Packet_DataList.create(DataReq.LIST_TIMING_CHUNK, timingChunks), player);
|
||||
OpisPacketHandler.validateAndSend(NetDataList.create(Message.LIST_TIMING_CHUNK, timingChunks), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package mcp.mobius.opis.events;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import mcp.mobius.opis.gui.overlay.OverlayStatus;
|
||||
import mcp.mobius.opis.network.enums.AccessLevel;
|
||||
import mcp.mobius.opis.swing.SelectedTab;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraftforge.common.Configuration;
|
||||
import cpw.mods.fml.common.IPlayerTracker;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
public class PlayerTracker implements IPlayerTracker{
|
||||
private static PlayerTracker _instance = new PlayerTracker();
|
||||
public static PlayerTracker instance() {return _instance;}
|
||||
private PlayerTracker(){}
|
||||
|
||||
public HashSet<Player> playersSwing = new HashSet<Player>(); //This is the list of players who have 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 filtered or not
|
||||
public HashMap<Player, OverlayStatus> playerOverlayStatus = new HashMap<Player, OverlayStatus>();
|
||||
public HashMap<Player, Integer> playerDimension = new HashMap<Player, Integer>();
|
||||
public HashMap<Player, SelectedTab> playerTab = new HashMap<Player, SelectedTab>();
|
||||
private HashSet<String> playerPrivileged = new HashSet<String>();
|
||||
|
||||
public SelectedTab getPlayerSelectedTab(Player player){
|
||||
return this.playerTab.get(player);
|
||||
}
|
||||
|
||||
public AccessLevel getPlayerAccessLevel(Player player){
|
||||
return this.getPlayerAccessLevel(((EntityPlayerMP)player).username);
|
||||
}
|
||||
|
||||
public AccessLevel getPlayerAccessLevel(String name){
|
||||
if (MinecraftServer.getServer().getConfigurationManager().isPlayerOpped(name) || MinecraftServer.getServer().isSinglePlayer())
|
||||
return AccessLevel.ADMIN;
|
||||
else if (playerPrivileged.contains(name))
|
||||
return AccessLevel.PRIVILEGED;
|
||||
else
|
||||
return AccessLevel.NONE;
|
||||
}
|
||||
|
||||
public void addPrivilegedPlayer(String name, boolean save){
|
||||
this.playerPrivileged.add(name);
|
||||
if (save){
|
||||
modOpis.instance.config.get("ACCESS_RIGHTS", "privileged", new String[]{}, modOpis.commentPrivileged).set(playerPrivileged.toArray(new String[]{}));
|
||||
modOpis.instance.config.save();
|
||||
}
|
||||
}
|
||||
|
||||
public void addPrivilegedPlayer(String name){
|
||||
this.addPrivilegedPlayer(name, true);
|
||||
}
|
||||
|
||||
public void rmPrivilegedPlayer(String name){
|
||||
this.playerPrivileged.remove(name);
|
||||
modOpis.instance.config.get("ACCESS_RIGHTS", "privileged", new String[]{}, modOpis.commentPrivileged).set(playerPrivileged.toArray(new String[]{}));
|
||||
modOpis.instance.config.save();
|
||||
}
|
||||
|
||||
public void reloeadPriviligedPlayers(){
|
||||
String[] users = modOpis.instance.config.get("ACCESS_RIGHTS", "privileged", new String[]{}, modOpis.commentPrivileged).getStringList();
|
||||
for (String s : users)
|
||||
PlayerTracker.instance().addPrivilegedPlayer(s,false);
|
||||
}
|
||||
|
||||
public boolean isAdmin(Player player){
|
||||
return this.getPlayerAccessLevel(player).ordinal() >= AccessLevel.ADMIN.ordinal();
|
||||
}
|
||||
|
||||
public boolean isAdmin(String name){
|
||||
return this.getPlayerAccessLevel(name).ordinal() >= AccessLevel.ADMIN.ordinal();
|
||||
}
|
||||
|
||||
public boolean isPrivileged(Player player){
|
||||
return this.getPlayerAccessLevel(player).ordinal() >= AccessLevel.PRIVILEGED.ordinal();
|
||||
}
|
||||
|
||||
public boolean isPrivileged(String name){
|
||||
return this.getPlayerAccessLevel(name).ordinal() >= AccessLevel.PRIVILEGED.ordinal();
|
||||
}
|
||||
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
|
||||
|
||||
@Override
|
||||
public void onPlayerLogin(EntityPlayer player) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerLogout(EntityPlayer player) {
|
||||
this.playerOverlayStatus.remove(player);
|
||||
this.playerDimension.remove(player);
|
||||
//this.playersOpis.remove(player);
|
||||
this.playersSwing.remove(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerChangedDimension(EntityPlayer player) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerRespawn(EntityPlayer player) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package mcp.mobius.opis.gui.events;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import mcp.mobius.opis.gui.interfaces.IWidget;
|
||||
|
||||
public class MouseEvent {
|
||||
|
||||
public enum EventType {NONE, MOVE, CLICK, RELEASED, DRAG, WHEEL, ENTER, LEAVE};
|
||||
|
||||
public long timestamp;
|
||||
public Minecraft mc;
|
||||
public IWidget srcwidget;
|
||||
public IWidget trgwidget;
|
||||
public double x,y;
|
||||
public int z;
|
||||
public static int buttonCount = Mouse.getButtonCount();
|
||||
public boolean[] buttonState = new boolean[buttonCount];
|
||||
public EventType type;
|
||||
public int button = -1;
|
||||
|
||||
|
||||
public MouseEvent(IWidget widget){
|
||||
this.srcwidget = widget;
|
||||
this.timestamp = System.nanoTime();
|
||||
|
||||
this.mc = Minecraft.getMinecraft();
|
||||
|
||||
this.x = (double)Mouse.getEventX() * (double)this.srcwidget.getSize().getX() / (double)this.mc.displayWidth;
|
||||
this.y = (double)this.srcwidget.getSize().getY() - (double)Mouse.getEventY() * (double)this.srcwidget.getSize().getY() / (double)this.mc.displayHeight - 1.0;
|
||||
|
||||
//this.x = Mouse.getEventX();
|
||||
//this.y = Mouse.getEventY();
|
||||
|
||||
//System.out.printf("%s %s\n", this.x, this.y);
|
||||
|
||||
//this.z = Mouse.getEventDWheel();
|
||||
this.z = Mouse.getDWheel();
|
||||
|
||||
for (int i = 0; i < buttonCount; i++)
|
||||
buttonState[i] = Mouse.isButtonDown(i);
|
||||
|
||||
this.trgwidget = this.srcwidget.getWidgetAtCoordinates(this.x, this.y);
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
String retstring = String.format("MOUSE %s : [%s] [ %.2f %.2f %d ] [", this.type, this.timestamp, this.x, this.y, this.z);
|
||||
if (this.buttonCount < 5)
|
||||
for (int i = 0; i < this.buttonCount; i++)
|
||||
retstring += String.format(" %s ", this.buttonState[i]);
|
||||
else
|
||||
for (int i = 0; i < 5; i++)
|
||||
retstring += String.format(" %s ", this.buttonState[i]);
|
||||
retstring += "]";
|
||||
|
||||
if (this.button != -1)
|
||||
retstring += String.format(" Button %s", this.button);
|
||||
|
||||
return retstring;
|
||||
}
|
||||
|
||||
// Returns the event type based on the previous mouse event.
|
||||
public EventType getEventType(MouseEvent me){
|
||||
|
||||
this.type = EventType.NONE;
|
||||
|
||||
if (this.trgwidget != me.trgwidget){
|
||||
this.type = EventType.ENTER;
|
||||
return this.type;
|
||||
}
|
||||
|
||||
if (this.z != 0){
|
||||
this.type = EventType.WHEEL;
|
||||
return this.type;
|
||||
}
|
||||
|
||||
for (int i = 0; i < this.buttonCount; i++){
|
||||
if (this.buttonState[i] != me.buttonState[i]){
|
||||
if (this.buttonState[i] == true)
|
||||
this.type = EventType.CLICK;
|
||||
else
|
||||
this.type = EventType.RELEASED;
|
||||
this.button = i;
|
||||
return this.type;
|
||||
}
|
||||
}
|
||||
|
||||
//MOVE & DRAG EVENTS (we moved the mouse and button 0 was clicked or not)
|
||||
if ((this.x != me.x) || (this.y != me.y)){
|
||||
if (this.buttonState[0] == true)
|
||||
this.type = EventType.DRAG;
|
||||
else
|
||||
this.type = EventType.MOVE;
|
||||
return this.type;
|
||||
}
|
||||
|
||||
return this.type;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package mcp.mobius.opis.gui.font;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.util.vector.Matrix4f;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
|
||||
|
||||
public class FontHelper {
|
||||
|
||||
public static void drawString(String s, int x, int y, TrueTypeFont font, float scaleX, float scaleY, float... rgba){
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
ScaledResolution sr = new ScaledResolution(mc.gameSettings, mc.displayWidth, mc.displayHeight);
|
||||
if(mc.gameSettings.hideGUI){
|
||||
return;
|
||||
}
|
||||
int amt = 1;
|
||||
if(sr.getScaleFactor() == 1){
|
||||
amt = 2;
|
||||
}
|
||||
|
||||
FloatBuffer matrixData = BufferUtils.createFloatBuffer(16);
|
||||
GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, matrixData);
|
||||
Matrix4f matrix = new Matrix4f();
|
||||
matrix.load(matrixData);
|
||||
|
||||
FontHelper.set2DMode();
|
||||
y = mc.displayHeight-(y*sr.getScaleFactor())-(((font.getLineHeight()/amt)));
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
|
||||
font.drawString(x*sr.getScaleFactor(), y - matrix.m31*sr.getScaleFactor(), s, scaleX/amt, scaleY/amt, rgba);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
FontHelper.set3DMode();
|
||||
}
|
||||
|
||||
private static void set2DMode() {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
GL11.glMatrixMode(GL11.GL_PROJECTION);
|
||||
GL11.glPushMatrix();
|
||||
GL11.glLoadIdentity();
|
||||
GL11.glOrtho(0, mc.displayWidth, 0, mc.displayHeight, -1, 1);
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
GL11.glPushMatrix();
|
||||
GL11.glLoadIdentity();
|
||||
}
|
||||
|
||||
private static void set3DMode() {
|
||||
GL11.glMatrixMode(GL11.GL_PROJECTION);
|
||||
GL11.glPopMatrix();
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
GL11.glPopMatrix();
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
mc.entityRenderer.setupOverlayRendering();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package mcp.mobius.opis.gui.font;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.FontFormatException;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.io.IOException;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class Fonts{
|
||||
|
||||
|
||||
/**
|
||||
* USAGE GUIDE, HUE!
|
||||
*
|
||||
* create a TrueTypeFont object variable
|
||||
* using either a resource location to a .ttf or
|
||||
* name of a system font, choose base size and
|
||||
* whether or not you want anti aliasing like so:
|
||||
*
|
||||
* testFont = createFont(new ResourceLocation("modid", "testfont.ttf"), 24f, false);
|
||||
*
|
||||
*
|
||||
* Once the font has been created, to render to screen, simply use the static call:
|
||||
*
|
||||
* FontHelper.drawString(String name, int x, int y, TrueTypeFont font, float scaleX, float scaleY, float... rgba)
|
||||
*
|
||||
* (^ help me think of a better class name for that class please o7)
|
||||
* --
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* FontHelper.drawString(windowTitle, posX, posY, Fonts.fontHelvetica, 1f, 1f);
|
||||
*
|
||||
* --
|
||||
*
|
||||
* gl&hf
|
||||
* - oku
|
||||
*
|
||||
* */
|
||||
|
||||
public static TrueTypeFont fontHelvetica = null, fontMinecraft = null, fontCoolvetica = null,
|
||||
fontArial = null, fontArialSmall = null, fontVenice = null;
|
||||
|
||||
public static void initFonts(){
|
||||
fontVenice = createFont(new ResourceLocation("okuguiapi", "venice.ttf"), 25, false);
|
||||
fontMinecraft = createFont(new ResourceLocation("okuguiapi", "Minecraftia.ttf"), 16, true);
|
||||
fontCoolvetica = createFont(new ResourceLocation("okuguiapi", "coolvetica.ttf"), 26, true);
|
||||
fontHelvetica = loadSystemFont("Helvetica", 18, false);
|
||||
fontArial = loadSystemFont("Arial", 24, false);
|
||||
fontArialSmall = loadSystemFont("Arial", 16, false);
|
||||
}
|
||||
|
||||
public static TrueTypeFont loadSystemFont(String name, float defSize, boolean antialias){
|
||||
return loadSystemFont(name, defSize, antialias, Font.TRUETYPE_FONT);
|
||||
|
||||
}
|
||||
|
||||
public static TrueTypeFont loadSystemFont(String name, float defSize, boolean antialias, int type){
|
||||
Font font;
|
||||
TrueTypeFont out = null;
|
||||
try {
|
||||
font = new Font(name, type, (int)defSize);
|
||||
font = font.deriveFont(defSize);
|
||||
out = new TrueTypeFont(font, antialias);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public static TrueTypeFont createFont(ResourceLocation res, float defSize, boolean antialias){
|
||||
return createFont(res, defSize, antialias, Font.TRUETYPE_FONT);
|
||||
}
|
||||
|
||||
public static TrueTypeFont createFont(ResourceLocation res, float defSize, boolean antialias, int type){
|
||||
Font font;
|
||||
TrueTypeFont out = null;
|
||||
try {
|
||||
font = Font.createFont(type, Minecraft.getMinecraft().getResourceManager().getResource(res).getInputStream());
|
||||
font = font.deriveFont(defSize);
|
||||
out = new TrueTypeFont(font, antialias);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,507 @@
|
||||
package mcp.mobius.opis.gui.font;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBuffer;
|
||||
import java.awt.image.DataBufferByte;
|
||||
import java.awt.image.DataBufferInt;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
import org.lwjgl.util.glu.GLU;
|
||||
|
||||
|
||||
/**
|
||||
* A TrueType font implementation originally for Slick, modified to use
|
||||
* Minecraft's Tessellator and add native floating point colour support
|
||||
*/
|
||||
|
||||
public class TrueTypeFont {
|
||||
public final static int
|
||||
ALIGN_LEFT = 0,
|
||||
ALIGN_RIGHT = 1,
|
||||
ALIGN_CENTER = 2;
|
||||
/** Array that holds necessary information about the font characters */
|
||||
private IntObject[] charArray = new IntObject[256];
|
||||
|
||||
/** Map of user defined font characters (Character <-> IntObject) */
|
||||
private Map customChars = new HashMap();
|
||||
|
||||
/** Boolean flag on whether AntiAliasing is enabled or not */
|
||||
private boolean antiAlias;
|
||||
|
||||
/** Font's size */
|
||||
private int fontSize = 0;
|
||||
|
||||
/** Font's height */
|
||||
private int fontHeight = 0;
|
||||
|
||||
/** Texture used to cache the font 0-255 characters */
|
||||
private int fontTextureID;
|
||||
|
||||
/** Default font texture width */
|
||||
private int textureWidth = 1024;
|
||||
|
||||
/** Default font texture height */
|
||||
private int textureHeight = 1024;
|
||||
|
||||
/** A reference to Java's AWT Font that we create our font texture from */
|
||||
private Font font;
|
||||
|
||||
/** The font metrics for our Java AWT font */
|
||||
private FontMetrics fontMetrics;
|
||||
|
||||
|
||||
private int correctL = 9, correctR = 8;
|
||||
|
||||
private class IntObject {
|
||||
/** Character's width */
|
||||
public int width;
|
||||
|
||||
/** Character's height */
|
||||
public int height;
|
||||
|
||||
/** Character's stored x position */
|
||||
public int storedX;
|
||||
|
||||
/** Character's stored y position */
|
||||
public int storedY;
|
||||
}
|
||||
|
||||
|
||||
public TrueTypeFont(Font font, boolean antiAlias, char[] additionalChars) {
|
||||
this.font = font;
|
||||
this.fontSize = font.getSize()+3;
|
||||
this.antiAlias = antiAlias;
|
||||
|
||||
createSet( additionalChars );
|
||||
System.out.println("TrueTypeFont loaded: "+font+" - AntiAlias = "+antiAlias);
|
||||
fontHeight -= 1;
|
||||
if (fontHeight <= 0) fontHeight = 1;
|
||||
}
|
||||
|
||||
public TrueTypeFont(Font font, boolean antiAlias) {
|
||||
this( font, antiAlias, null );
|
||||
}
|
||||
public void setCorrection(boolean on) {
|
||||
if (on) {
|
||||
correctL = 2;
|
||||
correctR = 1;
|
||||
} else {
|
||||
correctL = 0;
|
||||
correctR = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private BufferedImage getFontImage(char ch) {
|
||||
// Create a temporary image to extract the character's size
|
||||
BufferedImage tempfontImage = new BufferedImage(1, 1,
|
||||
BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g = (Graphics2D) tempfontImage.getGraphics();
|
||||
if (antiAlias == true) {
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
}
|
||||
g.setFont(font);
|
||||
fontMetrics = g.getFontMetrics();
|
||||
int charwidth = fontMetrics.charWidth(ch)+8;
|
||||
|
||||
if (charwidth <= 0) {
|
||||
charwidth = 7;
|
||||
}
|
||||
int charheight = fontMetrics.getHeight()+3;
|
||||
if (charheight <= 0) {
|
||||
charheight = fontSize;
|
||||
}
|
||||
|
||||
// Create another image holding the character we are creating
|
||||
BufferedImage fontImage;
|
||||
fontImage = new BufferedImage(charwidth, charheight,
|
||||
BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D gt = (Graphics2D) fontImage.getGraphics();
|
||||
if (antiAlias == true) {
|
||||
gt.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
}
|
||||
gt.setFont(font);
|
||||
|
||||
gt.setColor(Color.WHITE);
|
||||
int charx = 3;
|
||||
int chary = 1;
|
||||
gt.drawString(String.valueOf(ch), (charx), (chary)
|
||||
+ fontMetrics.getAscent());
|
||||
|
||||
return fontImage;
|
||||
|
||||
}
|
||||
|
||||
private void createSet( char[] customCharsArray ) {
|
||||
// If there are custom chars then I expand the font texture twice
|
||||
if (customCharsArray != null && customCharsArray.length > 0) {
|
||||
textureWidth *= 2;
|
||||
}
|
||||
|
||||
// In any case this should be done in other way. Texture with size 512x512
|
||||
// can maintain only 256 characters with resolution of 32x32. The texture
|
||||
// size should be calculated dynamicaly by looking at character sizes.
|
||||
|
||||
try {
|
||||
|
||||
BufferedImage imgTemp = new BufferedImage(textureWidth, textureHeight, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g = (Graphics2D) imgTemp.getGraphics();
|
||||
|
||||
g.setColor(new Color(0,0,0,1));
|
||||
g.fillRect(0,0,textureWidth,textureHeight);
|
||||
|
||||
int rowHeight = 0;
|
||||
int positionX = 0;
|
||||
int positionY = 0;
|
||||
|
||||
int customCharsLength = ( customCharsArray != null ) ? customCharsArray.length : 0;
|
||||
|
||||
for (int i = 0; i < 256 + customCharsLength; i++) {
|
||||
|
||||
// get 0-255 characters and then custom characters
|
||||
char ch = ( i < 256 ) ? (char) i : customCharsArray[i-256];
|
||||
|
||||
BufferedImage fontImage = getFontImage(ch);
|
||||
|
||||
IntObject newIntObject = new IntObject();
|
||||
|
||||
newIntObject.width = fontImage.getWidth();
|
||||
newIntObject.height = fontImage.getHeight();
|
||||
|
||||
if (positionX + newIntObject.width >= textureWidth) {
|
||||
positionX = 0;
|
||||
positionY += rowHeight;
|
||||
rowHeight = 0;
|
||||
}
|
||||
|
||||
newIntObject.storedX = positionX;
|
||||
newIntObject.storedY = positionY;
|
||||
|
||||
if (newIntObject.height > fontHeight) {
|
||||
fontHeight = newIntObject.height;
|
||||
}
|
||||
|
||||
if (newIntObject.height > rowHeight) {
|
||||
rowHeight = newIntObject.height;
|
||||
}
|
||||
|
||||
// Draw it here
|
||||
g.drawImage(fontImage, positionX, positionY, null);
|
||||
|
||||
positionX += newIntObject.width;
|
||||
|
||||
if( i < 256 ) { // standard characters
|
||||
charArray[i] = newIntObject;
|
||||
} else { // custom characters
|
||||
customChars.put( new Character( ch ), newIntObject );
|
||||
}
|
||||
|
||||
fontImage = null;
|
||||
}
|
||||
|
||||
fontTextureID = loadImage(imgTemp);
|
||||
|
||||
|
||||
|
||||
//.getTexture(font.toString(), imgTemp);
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("Failed to create font.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void drawQuad(float drawX, float drawY, float drawX2, float drawY2,
|
||||
float srcX, float srcY, float srcX2, float srcY2) {
|
||||
float DrawWidth = drawX2 - drawX;
|
||||
float DrawHeight = drawY2 - drawY;
|
||||
float TextureSrcX= srcX / textureWidth;
|
||||
float TextureSrcY = srcY / textureHeight;
|
||||
float SrcWidth = srcX2 - srcX;
|
||||
float SrcHeight = srcY2 - srcY;
|
||||
float RenderWidth = (SrcWidth / textureWidth);
|
||||
float RenderHeight = (SrcHeight / textureHeight);
|
||||
Tessellator t = Tessellator.instance;
|
||||
|
||||
//t.setColorRGBA_F(0f, 0f, 0f, 1f);
|
||||
|
||||
t.addVertexWithUV(drawX, drawY, 0, TextureSrcX, TextureSrcY);
|
||||
//GL11.glTexCoord2f(TextureSrcX, TextureSrcY);
|
||||
//GL11.glVertex2f(drawX, drawY);
|
||||
|
||||
t.addVertexWithUV(drawX, drawY + DrawHeight, 0, TextureSrcX, TextureSrcY + RenderHeight);
|
||||
//GL11.glTexCoord2f(TextureSrcX, TextureSrcY + RenderHeight);
|
||||
//GL11.glVertex2f(drawX, drawY + DrawHeight);
|
||||
|
||||
t.addVertexWithUV(drawX + DrawWidth, drawY + DrawHeight, 0, TextureSrcX + RenderWidth, TextureSrcY + RenderHeight);
|
||||
//GL11.glTexCoord2f(TextureSrcX + RenderWidth, TextureSrcY + RenderHeight);
|
||||
//GL11.glVertex2f(drawX + DrawWidth, drawY + DrawHeight);
|
||||
|
||||
t.addVertexWithUV(drawX + DrawWidth, drawY, 0, TextureSrcX + RenderWidth, TextureSrcY);
|
||||
//GL11.glTexCoord2f(TextureSrcX + RenderWidth, TextureSrcY);
|
||||
//GL11.glVertex2f(drawX + DrawWidth, drawY);
|
||||
}
|
||||
|
||||
public int getWidth(String whatchars) {
|
||||
int totalwidth = 0;
|
||||
IntObject intObject = null;
|
||||
int currentChar = 0;
|
||||
int lastWidth = -10;
|
||||
for (int i = 0; i < whatchars.length(); i++) {
|
||||
currentChar = whatchars.charAt(i);
|
||||
if (currentChar < 256) {
|
||||
intObject = charArray[currentChar];
|
||||
} else {
|
||||
intObject = (IntObject)customChars.get( new Character( (char) currentChar ) );
|
||||
}
|
||||
|
||||
if( intObject != null ){
|
||||
totalwidth += intObject.width/4;
|
||||
lastWidth = intObject.width;
|
||||
}
|
||||
}
|
||||
//System.out.println("Size: "+totalwidth);
|
||||
return (totalwidth);
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return fontHeight;
|
||||
}
|
||||
|
||||
|
||||
public int getHeight(String HeightString) {
|
||||
return fontHeight;
|
||||
}
|
||||
|
||||
public int getLineHeight() {
|
||||
return fontHeight;
|
||||
}
|
||||
|
||||
public void drawString(float x, float y, String whatchars, float scaleX, float scaleY, float... rgba) {
|
||||
if (whatchars == null)
|
||||
whatchars = "";
|
||||
drawString(x,y,whatchars, 0, whatchars.length()-1, scaleX, scaleY, ALIGN_LEFT, rgba);
|
||||
}
|
||||
public void drawString(float x, float y, String whatchars, float scaleX, float scaleY, int format, float... rgba) {
|
||||
if (whatchars == null)
|
||||
whatchars = "";
|
||||
drawString(x,y,whatchars, 0, whatchars.length()-1, scaleX, scaleY, format, rgba);
|
||||
}
|
||||
|
||||
|
||||
public void drawString(float x, float y, String whatchars, int startIndex, int endIndex, float scaleX, float scaleY, int format, float... rgba) {
|
||||
|
||||
//GameSettings gameSettings = new GameSettings();
|
||||
|
||||
//gameSettings.setOptionValue(EnumOptions.GUI_SCALE, par2);
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glScalef (scaleX, scaleY, 1.0f);
|
||||
|
||||
IntObject intObject = null;
|
||||
int charCurrent;
|
||||
|
||||
|
||||
float totalwidth = 0;
|
||||
int i = startIndex, d, c;
|
||||
float startY = 0;
|
||||
|
||||
|
||||
|
||||
switch (format) {
|
||||
case ALIGN_RIGHT: {
|
||||
d = -1;
|
||||
c = correctR;
|
||||
|
||||
while (i < endIndex) {
|
||||
if (whatchars.charAt(i) == '\n') startY -= fontHeight;
|
||||
i++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ALIGN_CENTER: {
|
||||
for (int l = startIndex; l <= endIndex; l++) {
|
||||
charCurrent = whatchars.charAt(l);
|
||||
if (charCurrent == '\n') break;
|
||||
if (charCurrent < 256) {
|
||||
intObject = charArray[charCurrent];
|
||||
} else {
|
||||
intObject = (IntObject)customChars.get( new Character( (char) charCurrent ) );
|
||||
}
|
||||
totalwidth += intObject.width-correctL;
|
||||
}
|
||||
totalwidth /= -2;
|
||||
}
|
||||
case ALIGN_LEFT:
|
||||
default: {
|
||||
d = 1;
|
||||
c = correctL;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, fontTextureID);
|
||||
Tessellator t = Tessellator.instance;
|
||||
t.startDrawingQuads();
|
||||
// GL11.glBegin(GL11.GL_QUADS);
|
||||
if(rgba.length == 4)
|
||||
t.setColorRGBA_F(rgba[0], rgba[1], rgba[2], rgba[3]);
|
||||
while (i >= startIndex && i <= endIndex) {
|
||||
|
||||
charCurrent = whatchars.charAt(i);
|
||||
if (charCurrent < 256) {
|
||||
intObject = charArray[charCurrent];
|
||||
} else {
|
||||
intObject = (IntObject)customChars.get( new Character( (char) charCurrent ) );
|
||||
}
|
||||
|
||||
if( intObject != null ) {
|
||||
if (d < 0) totalwidth += (intObject.width-c) * d;
|
||||
if (charCurrent == '\n') {
|
||||
startY -= fontHeight * d;
|
||||
totalwidth = 0;
|
||||
if (format == ALIGN_CENTER) {
|
||||
for (int l = i+1; l <= endIndex; l++) {
|
||||
charCurrent = whatchars.charAt(l);
|
||||
if (charCurrent == '\n') break;
|
||||
if (charCurrent < 256) {
|
||||
intObject = charArray[charCurrent];
|
||||
} else {
|
||||
intObject = (IntObject)customChars.get( new Character( (char) charCurrent ) );
|
||||
}
|
||||
totalwidth += intObject.width-correctL;
|
||||
}
|
||||
totalwidth /= -2;
|
||||
}
|
||||
//if center get next lines total width/2;
|
||||
}
|
||||
else {
|
||||
drawQuad((totalwidth + intObject.width) + x/scaleX,
|
||||
startY + y/scaleY,
|
||||
totalwidth + x/scaleX,
|
||||
(startY + intObject.height) + y/scaleY,
|
||||
intObject.storedX + intObject.width,
|
||||
intObject.storedY + intObject.height,
|
||||
intObject.storedX,
|
||||
intObject.storedY);
|
||||
if (d > 0) totalwidth += (intObject.width-c) * d ;
|
||||
}
|
||||
i += d;
|
||||
|
||||
}
|
||||
}
|
||||
t.draw();
|
||||
// GL11.glEnd();
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
public static int loadImage(BufferedImage bufferedImage) {
|
||||
try {
|
||||
short width = (short)bufferedImage.getWidth();
|
||||
short height = (short)bufferedImage.getHeight();
|
||||
//textureLoader.bpp = bufferedImage.getColorModel().hasAlpha() ? (byte)32 : (byte)24;
|
||||
int bpp = (byte)bufferedImage.getColorModel().getPixelSize();
|
||||
ByteBuffer byteBuffer;
|
||||
DataBuffer db = bufferedImage.getData().getDataBuffer();
|
||||
if (db instanceof DataBufferInt) {
|
||||
int intI[] = ((DataBufferInt)(bufferedImage.getData().getDataBuffer())).getData();
|
||||
byte newI[] = new byte[intI.length * 4];
|
||||
for (int i = 0; i < intI.length; i++) {
|
||||
byte b[] = intToByteArray(intI[i]);
|
||||
int newIndex = i*4;
|
||||
|
||||
newI[newIndex] = b[1];
|
||||
newI[newIndex+1] = b[2];
|
||||
newI[newIndex+2] = b[3];
|
||||
newI[newIndex+3] = b[0];
|
||||
}
|
||||
|
||||
byteBuffer = ByteBuffer.allocateDirect(
|
||||
width*height*(bpp/8))
|
||||
.order(ByteOrder.nativeOrder())
|
||||
.put(newI);
|
||||
} else {
|
||||
byteBuffer = ByteBuffer.allocateDirect(
|
||||
width*height*(bpp/8))
|
||||
.order(ByteOrder.nativeOrder())
|
||||
.put(((DataBufferByte)(bufferedImage.getData().getDataBuffer())).getData());
|
||||
}
|
||||
byteBuffer.flip();
|
||||
|
||||
|
||||
int internalFormat = GL11.GL_RGBA8,
|
||||
format = GL11.GL_RGBA;
|
||||
IntBuffer textureId = BufferUtils.createIntBuffer(1);;
|
||||
GL11.glGenTextures(textureId);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId.get(0));
|
||||
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
|
||||
|
||||
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
|
||||
//GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
|
||||
//GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_NEAREST);
|
||||
|
||||
//GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
|
||||
//GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR);
|
||||
//GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_NEAREST);
|
||||
|
||||
GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);
|
||||
|
||||
GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D, internalFormat, width, height, format, GL11.GL_UNSIGNED_BYTE, byteBuffer);
|
||||
return textureId.get(0);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
public static boolean isSupported(String fontname) {
|
||||
Font font[] = getFonts();
|
||||
for (int i = font.length-1; i >= 0; i--) {
|
||||
if (font[i].getName().equalsIgnoreCase(fontname))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static Font[] getFonts() {
|
||||
return GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
|
||||
}
|
||||
public static byte[] intToByteArray(int value) {
|
||||
return new byte[] {
|
||||
(byte)(value >>> 24),
|
||||
(byte)(value >>> 16),
|
||||
(byte)(value >>> 8),
|
||||
(byte)value};
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
IntBuffer scratch = BufferUtils.createIntBuffer(1);
|
||||
scratch.put(0, fontTextureID);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
|
||||
GL11.glDeleteTextures(scratch);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package mcp.mobius.opis.gui.helpers;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class ReverseIterator<T> implements Iterable<T> {
|
||||
|
||||
private ListIterator<T> listIterator;
|
||||
|
||||
public ReverseIterator(Collection<T> wrappedList) {
|
||||
List list = Lists.newArrayList(wrappedList);
|
||||
this.listIterator = list.listIterator(wrappedList.size());
|
||||
}
|
||||
|
||||
public Iterator<T> iterator() {
|
||||
return new Iterator<T>() {
|
||||
|
||||
public boolean hasNext() {
|
||||
return listIterator.hasPrevious();
|
||||
}
|
||||
|
||||
public T next() {
|
||||
return listIterator.previous();
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
listIterator.remove();
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package mcp.mobius.opis.gui.helpers;
|
||||
|
||||
public class UIException extends RuntimeException {
|
||||
public UIException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package mcp.mobius.opis.gui.helpers;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
|
||||
public class UIHelper {
|
||||
|
||||
public static void drawTexture(int posX, int posY, int sizeX, int sizeY)
|
||||
{
|
||||
UIHelper.drawTexture(posX, posY, sizeX, sizeY, 0, 0, 256, 256);
|
||||
}
|
||||
|
||||
public static void drawTexture(int posX, int posY, int sizeX, int sizeY, int texU, int texV, int texSizeU, int texSizeV)
|
||||
{
|
||||
float zLevel = 0.0F;
|
||||
float f = 0.00390625F;
|
||||
|
||||
Tessellator tess = Tessellator.instance;
|
||||
tess.startDrawingQuads();
|
||||
tess.addVertexWithUV((double)(posX + 0), (double)(posY + sizeY), (double)zLevel, texU*f, (texV + texSizeV)*f);
|
||||
tess.addVertexWithUV((double)(posX + sizeX), (double)(posY + sizeY), (double)zLevel, (texU + texSizeU)*f, (texV + texSizeV)*f);
|
||||
tess.addVertexWithUV((double)(posX + sizeX), (double)(posY + 0), (double)zLevel, (texU + texSizeU)*f, texV*f);
|
||||
tess.addVertexWithUV((double)(posX + 0), (double)(posY + 0), (double)zLevel, texU*f, texV*f);
|
||||
tess.draw();
|
||||
}
|
||||
|
||||
public static void drawGradientRect(int minx, int miny, int maxx, int maxy, int zlevel, int color1, int color2)
|
||||
{
|
||||
float alpha1 = (float)(color1 >> 24 & 255) / 255.0F;
|
||||
float red1 = (float)(color1 >> 16 & 255) / 255.0F;
|
||||
float green1 = (float)(color1 >> 8 & 255) / 255.0F;
|
||||
float blue1 = (float)(color1 & 255) / 255.0F;
|
||||
float alpha2 = (float)(color2 >> 24 & 255) / 255.0F;
|
||||
float red2 = (float)(color2 >> 16 & 255) / 255.0F;
|
||||
float green2 = (float)(color2 >> 8 & 255) / 255.0F;
|
||||
float blue2 = (float)(color2 & 255) / 255.0F;
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glShadeModel(GL11.GL_SMOOTH);
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setColorRGBA_F(red1, green1, blue1, alpha1);
|
||||
tessellator.addVertex((double)maxx, (double)miny, (double)zlevel);
|
||||
tessellator.addVertex((double)minx, (double)miny, (double)zlevel);
|
||||
tessellator.setColorRGBA_F(red2, green2, blue2, alpha2);
|
||||
tessellator.addVertex((double)minx, (double)maxy, (double)zlevel);
|
||||
tessellator.addVertex((double)maxx, (double)maxy, (double)zlevel);
|
||||
tessellator.draw();
|
||||
GL11.glShadeModel(GL11.GL_FLAT);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
public void drawLine(int x, int y, int x2, int y2, int width, float... rgba) {
|
||||
|
||||
Tessellator tess = Tessellator.instance;
|
||||
GL11.glPushMatrix();
|
||||
//GL11.glLineWidth(3);
|
||||
GL11.glLineWidth(width);
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
tess.startDrawing(3);
|
||||
|
||||
if(rgba.length == 4)
|
||||
tess.setColorRGBA_F(rgba[0], rgba[1], rgba[2], rgba[3]);
|
||||
//tess.setColorRGBA_F(1,1,1,1);
|
||||
|
||||
tess.addVertex(x, y, 0);
|
||||
tess.addVertex(x2, y2, 0);
|
||||
|
||||
|
||||
tess.draw();
|
||||
GL11.glDisable(32826 /*GL_RESCALE_NORMAL_EXT*/);
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loaded 100 of 214 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user