Update to MC 1.14 / Fabric

This commit is contained in:
Jonas Herzig
2019-05-04 14:37:00 +02:00
parent 17fe5b345f
commit 3d009e45c7
151 changed files with 3963 additions and 1455 deletions

View File

@@ -1,6 +1,7 @@
package com.replaymod.replay.gui.overlay;
import com.replaymod.core.ReplayMod;
import com.replaymod.core.versions.MCVer.Keyboard;
import com.replaymod.replay.ReplayHandler;
import com.replaymod.replay.ReplaySender;
import de.johni0702.minecraft.gui.GuiRenderer;
@@ -14,20 +15,22 @@ import de.johni0702.minecraft.gui.element.GuiTooltip;
import de.johni0702.minecraft.gui.element.advanced.IGuiTimeline;
import de.johni0702.minecraft.gui.layout.CustomLayout;
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
import de.johni0702.minecraft.gui.utils.EventRegistrations;
import de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension;
import de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint;
import de.johni0702.minecraft.gui.utils.lwjgl.WritablePoint;
import net.minecraft.client.GameSettings;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
//#if MC<11300
//$$ import org.lwjgl.input.Keyboard;
//#if MC>=11300
import com.replaymod.core.events.KeyBindingEventCallback;
import com.replaymod.core.events.KeyEventCallback;
//#else
//$$ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
//$$ import net.minecraftforge.fml.common.gameevent.InputEvent;
//#endif
import static com.replaymod.core.ReplayMod.TEXTURE_SIZE;
import static com.replaymod.core.versions.MCVer.*;
public class GuiReplayOverlay extends AbstractGuiOverlay<GuiReplayOverlay> {
@@ -57,6 +60,8 @@ public class GuiReplayOverlay extends AbstractGuiOverlay<GuiReplayOverlay> {
public final GuiPanel statusIndicatorPanel = new GuiPanel(this).setSize(100, 20)
.setLayout(new HorizontalLayout(HorizontalLayout.Alignment.RIGHT).setSpacing(5));
private final EventHandler eventHandler = new EventHandler();
public GuiReplayOverlay(final ReplayHandler replayHandler) {
timeline = new GuiMarkerTimeline(replayHandler){
@Override
@@ -141,32 +146,14 @@ public class GuiReplayOverlay extends AbstractGuiOverlay<GuiReplayOverlay> {
public void setVisible(boolean visible) {
if (isVisible() != visible) {
if (visible) {
FML_BUS.register(this);
eventHandler.register();
} else {
FML_BUS.unregister(this);
eventHandler.unregister();
}
}
super.setVisible(visible);
}
@SubscribeEvent
public void onKeyInput(InputEvent.KeyInputEvent event) {
GameSettings gameSettings = getMinecraft().gameSettings;
while (gameSettings.keyBindChat.isPressed() || gameSettings.keyBindCommand.isPressed()) {
if (!isMouseVisible()) {
setMouseVisible(true);
}
}
/* FIXME
if (Keyboard.getEventKeyState()) {
// Handle the F1 key binding while the overlay is opened as a gui screen
if (isMouseVisible() && Keyboard.getEventKey() == Keyboard.KEY_F1) {
gameSettings.hideGUI = !gameSettings.hideGUI;
}
}
*/
}
@Override
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
// Do not render overlay when user pressed F1 and we are not currently in some popup
@@ -182,4 +169,38 @@ public class GuiReplayOverlay extends AbstractGuiOverlay<GuiReplayOverlay> {
protected GuiReplayOverlay getThis() {
return this;
}
private class EventHandler extends EventRegistrations {
//#if MC>=11300
{ on(KeyBindingEventCallback.EVENT, this::onKeyBindingEvent); }
private void onKeyBindingEvent() {
//#else
//$$ @SubscribeEvent
//$$ public void onKeyBindingEvent(InputEvent.KeyInputEvent event) {
//#endif
GameSettings gameSettings = getMinecraft().gameSettings;
while (gameSettings.keyBindChat.isPressed() || gameSettings.keyBindCommand.isPressed()) {
if (!isMouseVisible()) {
setMouseVisible(true);
}
}
}
//#if MC>=11300
{ on(KeyEventCallback.EVENT, (int key, int scanCode, int action, int modifiers) -> onKeyInput(key, action)); }
private void onKeyInput(int key, int action) {
if (action != 0) return;
//#else
//$$ @SubscribeEvent
//$$ public void onKeyInput(InputEvent.KeyInputEvent event) {
//$$ if (!Keyboard.getEventKeyState()) return;
//$$ int key = Keyboard.getEventKey();
//#endif
GameSettings gameSettings = getMinecraft().gameSettings;
// Handle the F1 key binding while the overlay is opened as a gui screen
if (isMouseVisible() && key == Keyboard.KEY_F1) {
gameSettings.hideGUI = !gameSettings.hideGUI;
}
}
}
}

View File

@@ -5,7 +5,7 @@ import com.google.common.base.Supplier;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.SettableFuture;
import com.mojang.realmsclient.gui.ChatFormatting;
import net.minecraft.util.text.TextFormatting;
import com.replaymod.core.ReplayMod;
import com.replaymod.core.SettingsRegistry;
import com.replaymod.core.gui.GuiReplaySettings;
@@ -37,7 +37,6 @@ import de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension;
import de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint;
import lombok.Getter;
import net.minecraft.client.gui.GuiErrorScreen;
import net.minecraft.client.resources.I18n;
import net.minecraft.crash.CrashReport;
import net.minecraft.crash.ReportedException;
import org.apache.commons.io.FileUtils;
@@ -57,6 +56,12 @@ import java.util.List;
import static com.replaymod.replay.ReplayModReplay.LOGGER;
//#if MC>=11400
//$$ import net.minecraft.text.TranslatableTextComponent;
//#else
import net.minecraft.client.resources.I18n;
//#endif
public class GuiReplayViewer extends GuiScreen {
private final ReplayModReplay mod;
@@ -137,8 +142,14 @@ public class GuiReplayViewer extends GuiScreen {
// We failed (might also be their OS)
e.printStackTrace();
getMinecraft().displayGuiScreen(new GuiErrorScreen(
//#if MC>=11400
//$$ () -> {},
//$$ new TranslatableTextComponent("replaymod.gui.viewer.delete.failed1"),
//$$ new TranslatableTextComponent("replaymod.gui.viewer.delete.failed2")
//#else
I18n.format("replaymod.gui.viewer.delete.failed1"),
I18n.format("replaymod.gui.viewer.delete.failed2")
//#endif
));
return;
}
@@ -159,7 +170,7 @@ public class GuiReplayViewer extends GuiScreen {
String name = list.getSelected().name.getText();
GuiYesNoPopup popup = GuiYesNoPopup.open(GuiReplayViewer.this,
new GuiLabel().setI18nText("replaymod.gui.viewer.delete.linea").setColor(Colors.BLACK),
new GuiLabel().setI18nText("replaymod.gui.viewer.delete.lineb", name + ChatFormatting.RESET).setColor(Colors.BLACK)
new GuiLabel().setI18nText("replaymod.gui.viewer.delete.lineb", name + TextFormatting.RESET).setColor(Colors.BLACK)
).setYesI18nLabel("replaymod.gui.delete").setNoI18nLabel("replaymod.gui.cancel");
Futures.addCallback(popup.getFuture(), new FutureCallback<Boolean>() {
@Override
@@ -393,7 +404,7 @@ public class GuiReplayViewer extends GuiScreen {
public GuiReplayEntry(File file, ReplayMetaData metaData, BufferedImage thumbImage) {
this.file = file;
name.setText(ChatFormatting.UNDERLINE + Utils.fileNameToReplayName(file.getName()));
name.setText(TextFormatting.UNDERLINE + Utils.fileNameToReplayName(file.getName()));
if (StringUtils.isEmpty(metaData.getServerName())
|| !ReplayMod.instance.getSettingsRegistry().get(Setting.SHOW_SERVER_IPS)) {
server.setI18nText("replaymod.gui.iphidden").setColor(Colors.DARK_RED);