Deprecate most static fields in ReplayMod class
Fix replay restarting
This commit is contained in:
@@ -33,7 +33,7 @@ import net.minecraft.client.resources.IResourcePack;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.crash.CrashReportCategory;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
@@ -85,32 +85,55 @@ public class ReplayMod {
|
||||
public static final int TEXTURE_SIZE = 128;
|
||||
|
||||
private static final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
@Deprecated
|
||||
public static GuiEventHandler guiEventHandler;
|
||||
@Deprecated
|
||||
public static ReplaySettings replaySettings;
|
||||
@Deprecated
|
||||
public static Configuration config;
|
||||
@Deprecated
|
||||
public static boolean firstMainMenu = true;
|
||||
@Deprecated
|
||||
public static ChatMessageHandler chatMessageHandler = new ChatMessageHandler();
|
||||
@Deprecated
|
||||
public static KeyInputHandler keyInputHandler = new KeyInputHandler();
|
||||
@Deprecated
|
||||
public static MouseInputHandler mouseInputHandler = new MouseInputHandler();
|
||||
@Deprecated
|
||||
public static ReplaySender replaySender;
|
||||
@Deprecated
|
||||
public static int TP_DISTANCE_LIMIT = 128;
|
||||
@Deprecated
|
||||
public static ReplayFileAppender replayFileAppender;
|
||||
@Deprecated
|
||||
public static UploadedFileHandler uploadedFileHandler;
|
||||
@Deprecated
|
||||
public static DownloadedFileHandler downloadedFileHandler;
|
||||
@Deprecated
|
||||
public static FavoritedFileHandler favoritedFileHandler;
|
||||
@Deprecated
|
||||
public static RatedFileHandler ratedFileHandler;
|
||||
@Deprecated
|
||||
public static SpectatorRenderer spectatorRenderer;
|
||||
@Deprecated
|
||||
public static TooltipRenderer tooltipRenderer;
|
||||
@Deprecated
|
||||
public static PathPreviewRenderer pathPreviewRenderer;
|
||||
@Deprecated
|
||||
public static CustomObjectRenderer customObjectRenderer;
|
||||
@Deprecated
|
||||
public static SoundHandler soundHandler = new SoundHandler();
|
||||
@Deprecated
|
||||
public static CrosshairRenderHandler crosshairRenderHandler;
|
||||
@Deprecated
|
||||
public static ApiClient apiClient;
|
||||
|
||||
private final KeyBindingRegistry keyBindingRegistry = new KeyBindingRegistry();
|
||||
private final SettingsRegistry settingsRegistry = new SettingsRegistry();
|
||||
|
||||
@Getter
|
||||
@Deprecated
|
||||
private static boolean latestModVersion = true;
|
||||
|
||||
// The instance of your mod that Forge uses.
|
||||
@@ -448,4 +471,26 @@ public class ReplayMod {
|
||||
public Minecraft getMinecraft() {
|
||||
return mc;
|
||||
}
|
||||
|
||||
public void printInfoToChat(String message, Object... args) {
|
||||
printToChat(false, message, args);
|
||||
}
|
||||
|
||||
public void printWarningToChat(String message, Object... args) {
|
||||
printToChat(true, message, args);
|
||||
}
|
||||
|
||||
private void printToChat(boolean warning, String message, Object... args) {
|
||||
if (ReplayMod.replaySettings.isShowNotifications()) {
|
||||
// Some nostalgia: "§8[§6Replay Mod§8]§r Your message goes here"
|
||||
ChatStyle coloredDarkGray = new ChatStyle().setColor(EnumChatFormatting.DARK_GRAY);
|
||||
ChatStyle coloredGold = new ChatStyle().setColor(EnumChatFormatting.GOLD);
|
||||
IChatComponent text = new ChatComponentText("[").setChatStyle(coloredDarkGray)
|
||||
.appendSibling(new ChatComponentTranslation("replaymod.title").setChatStyle(coloredGold))
|
||||
.appendSibling(new ChatComponentText("] "))
|
||||
.appendSibling(new ChatComponentTranslation(message, args).setChatStyle(new ChatStyle()
|
||||
.setColor(warning ? EnumChatFormatting.RED : EnumChatFormatting.DARK_GREEN)));
|
||||
mc.thePlayer.addChatMessage(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.replaymod.recording;
|
||||
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.recording.handler.ConnectionEventHandler;
|
||||
import com.replaymod.recording.packet.PacketListener;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
@@ -34,6 +34,7 @@ public class ReplayModRecording {
|
||||
PacketListener packetListener = connectionEventHandler.getPacketListener();
|
||||
if (packetListener != null) {
|
||||
packetListener.addMarker();
|
||||
core.printInfoToChat("replaymod.chat.addedmarker");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.replaymod.recording.gui;
|
||||
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.core.SettingsRegistry;
|
||||
import com.replaymod.recording.Setting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
@@ -18,9 +19,11 @@ import static com.replaymod.core.ReplayMod.TEXTURE_SIZE;
|
||||
*/
|
||||
public class GuiRecordingOverlay {
|
||||
private final Minecraft mc;
|
||||
private final SettingsRegistry settingsRegistry;
|
||||
|
||||
public GuiRecordingOverlay(Minecraft mc) {
|
||||
public GuiRecordingOverlay(Minecraft mc, SettingsRegistry settingsRegistry) {
|
||||
this.mc = mc;
|
||||
this.settingsRegistry = settingsRegistry;
|
||||
}
|
||||
|
||||
public void register() {
|
||||
@@ -38,7 +41,7 @@ public class GuiRecordingOverlay {
|
||||
@SubscribeEvent
|
||||
public void renderRecordingIndicator(RenderGameOverlayEvent.Post event) {
|
||||
if (event.type != RenderGameOverlayEvent.ElementType.ALL) return;
|
||||
if(ReplayMod.replaySettings.showRecordingIndicator()) {
|
||||
if (settingsRegistry.get(Setting.INDICATOR)) {
|
||||
FontRenderer fontRenderer = mc.fontRendererObj;
|
||||
fontRenderer.drawString(I18n.format("replaymod.gui.recording").toUpperCase(), 30, 18 - (fontRenderer.FONT_HEIGHT / 2), 0xffffffff);
|
||||
mc.renderEngine.bindTexture(TEXTURE);
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package com.replaymod.recording.handler;
|
||||
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.recording.Setting;
|
||||
import com.replaymod.recording.gui.GuiRecordingOverlay;
|
||||
import com.replaymod.recording.packet.PacketListener;
|
||||
import de.johni0702.replaystudio.replay.ReplayFile;
|
||||
import de.johni0702.replaystudio.replay.ZipReplayFile;
|
||||
import de.johni0702.replaystudio.studio.ReplayStudio;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.chat.ChatMessageHandler.ChatMessageType;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -47,8 +46,6 @@ public class ConnectionEventHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public void onConnectedToServerEvent(ClientConnectedToServerEvent event) {
|
||||
ReplayMod.chatMessageHandler.initialize();
|
||||
|
||||
try {
|
||||
if(event.isLocal) {
|
||||
if (MinecraftServer.getServer().getEntityWorld().getWorldType() == WorldType.DEBUG_WORLD) {
|
||||
@@ -88,12 +85,12 @@ public class ConnectionEventHandler {
|
||||
recordingEventHandler = new RecordingEventHandler(packetListener);
|
||||
recordingEventHandler.register();
|
||||
|
||||
guiOverlay = new GuiRecordingOverlay(mc);
|
||||
guiOverlay = new GuiRecordingOverlay(mc, core.getSettingsRegistry());
|
||||
guiOverlay.register();
|
||||
|
||||
ReplayMod.chatMessageHandler.addLocalizedChatMessage("replaymod.chat.recordingstarted", ChatMessageType.INFORMATION);
|
||||
core.printInfoToChat("replaymod.chat.recordingstarted");
|
||||
} catch(Exception e) {
|
||||
ReplayMod.chatMessageHandler.addLocalizedChatMessage("replaymod.chat.recordingfailed", ChatMessageType.WARNING);
|
||||
core.printWarningToChat("replaymod.chat.recordingfailed");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -106,8 +103,6 @@ public class ConnectionEventHandler {
|
||||
recordingEventHandler.unregister();
|
||||
recordingEventHandler = null;
|
||||
packetListener = null;
|
||||
|
||||
ReplayMod.chatMessageHandler.stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,10 @@ package com.replaymod.recording.packet;
|
||||
|
||||
import com.google.common.hash.Hashing;
|
||||
import com.google.common.io.Files;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import de.johni0702.replaystudio.data.Marker;
|
||||
import de.johni0702.replaystudio.replay.ReplayFile;
|
||||
import de.johni0702.replaystudio.replay.ReplayMetaData;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.chat.ChatMessageHandler;
|
||||
import eu.crushedpixel.replaymod.holders.AdvancedPosition;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
@@ -90,8 +89,6 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
|
||||
marker.setPitch((float) pos.getPitch());
|
||||
marker.setRoll((float) pos.getRoll());
|
||||
markers.add(marker);
|
||||
|
||||
ReplayMod.chatMessageHandler.addLocalizedChatMessage("replaymod.chat.addedmarker", ChatMessageHandler.ChatMessageType.INFORMATION);
|
||||
}
|
||||
|
||||
public class DataWriter {
|
||||
@@ -142,15 +139,13 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
|
||||
|
||||
public synchronized void requestFinish() {
|
||||
if (saveService.isShutdown()) return;
|
||||
// TODO: Add some GUI showing saving status
|
||||
try {
|
||||
Runtime.getRuntime().removeShutdownHook(shutdownHook);
|
||||
saveService.shutdown();
|
||||
saveService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
|
||||
stream.close();
|
||||
|
||||
// TODO: Get rid of replay file appender
|
||||
ReplayMod.replayFileAppender.startNewReplayFileWriting();
|
||||
|
||||
String mcversion = ReplayMod.getMinecraftVersion();
|
||||
|
||||
String[] pl = players.toArray(new String[players.size()]);
|
||||
@@ -173,7 +168,7 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
ReplayMod.replayFileAppender.replayFileWritingFinished();
|
||||
// TODO: Always close GUI
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.replaymod.replay;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.replay.events.ReplayCloseEvent;
|
||||
import com.replaymod.replay.events.ReplayOpenEvent;
|
||||
import com.replaymod.replay.gui.overlay.GuiReplayOverlay;
|
||||
@@ -83,9 +82,6 @@ public class ReplayHandler {
|
||||
|
||||
markers = replayFile.getMarkers().or(Collections.<Marker>emptySet());
|
||||
|
||||
// TODO: get rid of chat message handler
|
||||
ReplayMod.chatMessageHandler.initialize();
|
||||
|
||||
replaySender = new ReplaySender(this, replayFile, asyncMode);
|
||||
|
||||
setup();
|
||||
@@ -312,9 +308,9 @@ public class ReplayHandler {
|
||||
Display.update();
|
||||
|
||||
// Send the packets
|
||||
ReplayMod.replaySender.sendPacketsTill(targetTime);
|
||||
ReplayMod.replaySender.setAsyncMode(true);
|
||||
ReplayMod.replaySender.setReplaySpeed(0);
|
||||
replaySender.sendPacketsTill(targetTime);
|
||||
replaySender.setAsyncMode(true);
|
||||
replaySender.setReplaySpeed(0);
|
||||
|
||||
mc.getNetHandler().getNetworkManager().processReceivedPackets();
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -8,7 +8,6 @@ import com.replaymod.replay.handler.GuiHandler;
|
||||
import de.johni0702.replaystudio.replay.ReplayFile;
|
||||
import de.johni0702.replaystudio.replay.ZipReplayFile;
|
||||
import de.johni0702.replaystudio.studio.ReplayStudio;
|
||||
import eu.crushedpixel.replaymod.chat.ChatMessageHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
@@ -61,8 +60,7 @@ public class ReplayModReplay {
|
||||
public void onSuccess(NoGuiScreenshot result) {
|
||||
try {
|
||||
replayHandler.getReplayFile().writeThumb(result.getImage());
|
||||
ReplayMod.chatMessageHandler.addLocalizedChatMessage("replaymod.chat.savedthumb",
|
||||
ChatMessageHandler.ChatMessageType.INFORMATION);
|
||||
core.printInfoToChat("replaymod.chat.savedthumb");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.google.common.base.Preconditions;
|
||||
import com.google.common.io.Files;
|
||||
import com.google.common.util.concurrent.ListenableFutureTask;
|
||||
import de.johni0702.replaystudio.replay.ReplayFile;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.holders.PacketData;
|
||||
import eu.crushedpixel.replaymod.replay.Restrictions;
|
||||
import eu.crushedpixel.replaymod.settings.ReplaySettings;
|
||||
@@ -67,6 +66,8 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
|
||||
S39PacketPlayerAbilities.class,
|
||||
S45PacketTitle.class);
|
||||
|
||||
private static int TP_DISTANCE_LIMIT = 128;
|
||||
|
||||
/**
|
||||
* The replay handler responsible for the current replay.
|
||||
*/
|
||||
@@ -404,8 +405,8 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
|
||||
}
|
||||
|
||||
if(cent != null) {
|
||||
if(!allowMovement && !((Math.abs(cent.posX - ppl.func_148932_c()) > ReplayMod.TP_DISTANCE_LIMIT) ||
|
||||
(Math.abs(cent.posZ - ppl.func_148933_e()) > ReplayMod.TP_DISTANCE_LIMIT))) {
|
||||
if(!allowMovement && !((Math.abs(cent.posX - ppl.func_148932_c()) > TP_DISTANCE_LIMIT) ||
|
||||
(Math.abs(cent.posZ - ppl.func_148933_e()) > TP_DISTANCE_LIMIT))) {
|
||||
return null;
|
||||
} else {
|
||||
allowMovement = false;
|
||||
|
||||
Reference in New Issue
Block a user