Get core, recording and replay modules compiling on 1.13.2
This commit is contained in:
10
src/main/java/com/replaymod/core/Module.java
Normal file
10
src/main/java/com/replaymod/core/Module.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.replaymod.core;
|
||||
|
||||
public interface Module {
|
||||
// FMLCommonSetupEvent for 1.13+, FMLInitializationEvent below
|
||||
default void initCommon() {}
|
||||
// FMLClientSetupEvent for 1.13+, FMLInitializationEvent (if client) below
|
||||
default void initClient() {}
|
||||
// FMLClientSetupEvent for 1.13+, FMLInitializationEvent below
|
||||
default void registerKeyBindings(KeyBindingRegistry registry) {}
|
||||
}
|
||||
@@ -14,7 +14,6 @@ import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import org.apache.commons.io.Charsets;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
@@ -22,10 +21,15 @@ import org.apache.commons.io.FileUtils;
|
||||
import com.replaymod.core.versions.LangResourcePack;
|
||||
import net.minecraft.resources.FolderPack;
|
||||
import net.minecraft.resources.IResourcePack;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLModLoadingContext;
|
||||
import net.minecraftforge.fml.DeferredWorkQueue;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.versions.mcp.MCPVersion;
|
||||
//#else
|
||||
//$$ import net.minecraft.client.resources.FolderResourcePack;
|
||||
//$$ import net.minecraft.client.resources.IResourcePack;
|
||||
//$$ import net.minecraftforge.common.config.Configuration;
|
||||
//#endif
|
||||
|
||||
//#if MC>=10904
|
||||
@@ -51,12 +55,12 @@ import net.minecraftforge.fml.ModList;
|
||||
//$$ import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
//$$ import net.minecraftforge.fml.common.Mod.Instance;
|
||||
//$$ import net.minecraftforge.fml.common.ModContainer;
|
||||
//$$ import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
//$$ import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||
//$$ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
//$$ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
//#endif
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
//#else
|
||||
//$$ import cpw.mods.fml.common.Loader;
|
||||
@@ -99,7 +103,7 @@ import static com.replaymod.core.versions.MCVer.*;
|
||||
//#endif
|
||||
//$$ guiFactory = "com.replaymod.core.gui.GuiFactory")
|
||||
//#endif
|
||||
public class ReplayMod {
|
||||
public class ReplayMod implements Module {
|
||||
|
||||
public static ModContainer getContainer() {
|
||||
//#if MC>=11300
|
||||
@@ -111,7 +115,7 @@ public class ReplayMod {
|
||||
|
||||
@Getter(lazy = true)
|
||||
//#if MC>=11300
|
||||
private static final String minecraftVersion = "1.13"; // FIXME
|
||||
private static final String minecraftVersion = MCPVersion.getMCVersion();
|
||||
//#else
|
||||
//$$ private static final String minecraftVersion = Loader.MC_VERSION;
|
||||
//#endif
|
||||
@@ -123,11 +127,16 @@ public class ReplayMod {
|
||||
|
||||
private static final Minecraft mc = MCVer.getMinecraft();
|
||||
|
||||
@Deprecated
|
||||
public static Configuration config;
|
||||
//#if MC<11300
|
||||
//$$ @Deprecated
|
||||
//$$ public static Configuration config;
|
||||
//#endif
|
||||
|
||||
private final KeyBindingRegistry keyBindingRegistry = new KeyBindingRegistry();
|
||||
private final SettingsRegistry settingsRegistry = new SettingsRegistry();
|
||||
{
|
||||
settingsRegistry.register(Setting.class);
|
||||
}
|
||||
|
||||
// The instance of your mod that Forge uses.
|
||||
//#if MC>=11300
|
||||
@@ -138,9 +147,31 @@ public class ReplayMod {
|
||||
public static ReplayMod instance;
|
||||
|
||||
private final List<Module> modules = new ArrayList<>();
|
||||
{
|
||||
|
||||
public ReplayMod() {
|
||||
I18n.setI18n(net.minecraft.client.resources.I18n::format);
|
||||
|
||||
// Initialize the static OpenGL info field from the minecraft main thread
|
||||
// Unfortunately lwjgl uses static methods so we have to make use of magic init calls as well
|
||||
DeferredWorkQueue.runLater(OpenGLUtils::init);
|
||||
|
||||
//#if MC>=11300
|
||||
DeferredWorkQueue.runLater(() -> MCVer.getMinecraft().resourcePackRepository.addPackFinder(new LangResourcePack.Finder()));
|
||||
//#endif
|
||||
|
||||
// Register all RM modules
|
||||
modules.add(this);
|
||||
modules.add(new ReplayModRecording(this));
|
||||
modules.add(new ReplayModReplay(this));
|
||||
|
||||
//#if MC>=11300
|
||||
settingsRegistry.register();
|
||||
//#else
|
||||
//$$ config = new Configuration(event.getSuggestedConfigurationFile());
|
||||
//$$ config.load();
|
||||
//$$ settingsRegistry.setConfiguration(config);
|
||||
//$$ settingsRegistry.save(); // Save default values to disk
|
||||
//#endif
|
||||
}
|
||||
|
||||
public KeyBindingRegistry getKeyBindingRegistry() {
|
||||
@@ -158,32 +189,6 @@ public class ReplayMod {
|
||||
return folder;
|
||||
}
|
||||
|
||||
//#if MC>=11300
|
||||
{ FMLModLoadingContext.get().getModEventBus().addListener(this::preInit); }
|
||||
//#else
|
||||
//$$ @EventHandler
|
||||
//#endif
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
// Initialize the static OpenGL info field from the minecraft main thread
|
||||
// Unfortunately lwjgl uses static methods so we have to make use of magic init calls as well
|
||||
OpenGLUtils.init();
|
||||
|
||||
I18n.setI18n(net.minecraft.client.resources.I18n::format);
|
||||
//#if MC>=11300
|
||||
MCVer.getMinecraft().resourcePackRepository.addPackFinder(new LangResourcePack.Finder());
|
||||
//#endif
|
||||
|
||||
//#if MC>=11300
|
||||
config = new Configuration(new File(mcDataDir(mc), "configs/replaymod.cfg")); // FIXME where'd the suggestion go?
|
||||
//#else
|
||||
//$$ config = new Configuration(event.getSuggestedConfigurationFile());
|
||||
//#endif
|
||||
// FIXME forge config api is currently broken config.load();
|
||||
settingsRegistry.setConfiguration(config);
|
||||
|
||||
modules.forEach(m -> m.preInit(event));
|
||||
}
|
||||
|
||||
//#ifdef DEV_ENV
|
||||
static { // Note: even preInit is too late and we'd have to issue another resource reload
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -231,39 +236,41 @@ public class ReplayMod {
|
||||
//#endif
|
||||
|
||||
//#if MC>=11300
|
||||
{ FMLModLoadingContext.get().getModEventBus().addListener(this::init); }
|
||||
{
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener((FMLCommonSetupEvent event) -> modules.forEach(Module::initCommon));
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener((FMLClientSetupEvent event) -> modules.forEach(Module::initClient));
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener((FMLClientSetupEvent event) -> modules.forEach(m -> m.registerKeyBindings(keyBindingRegistry)));
|
||||
}
|
||||
//#else
|
||||
//$$ @EventHandler
|
||||
//$$ public void init(FMLInitializationEvent event) {
|
||||
//$$ modules.forEach(Module::initCommon);
|
||||
//$$ modules.forEach(Module::initClient);
|
||||
//$$ modules.forEach(m -> m.registerKeyBindings(keyBindingRegistry));
|
||||
//$$ }
|
||||
//#endif
|
||||
public void init(FMLInitializationEvent event) {
|
||||
getSettingsRegistry().register(Setting.class);
|
||||
|
||||
@Override
|
||||
public void registerKeyBindings(KeyBindingRegistry registry) {
|
||||
registry.registerKeyBinding("replaymod.input.settings", 0, () -> {
|
||||
new GuiReplaySettings(null, settingsRegistry).display();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initClient() {
|
||||
new MainMenuHandler().register();
|
||||
|
||||
//#if MC<=10710
|
||||
//$$ FML_BUS.register(this); // For runLater(Runnable)
|
||||
//#endif
|
||||
|
||||
FML_BUS.register(keyBindingRegistry);
|
||||
|
||||
getKeyBindingRegistry().registerKeyBinding("replaymod.input.settings", 0, () -> {
|
||||
new GuiReplaySettings(null, settingsRegistry).display();
|
||||
});
|
||||
|
||||
modules.forEach(m -> m.init(event));
|
||||
}
|
||||
|
||||
//#if MC>=11300
|
||||
{ FMLModLoadingContext.get().getModEventBus().addListener(this::postInit); }
|
||||
//#else
|
||||
//$$ @EventHandler
|
||||
//#endif
|
||||
public void postInit(FMLPostInitializationEvent event) {
|
||||
settingsRegistry.save(); // Save default values to disk
|
||||
|
||||
// 1.7.10 crashes when render distance > 16
|
||||
//#if MC>=10800
|
||||
//if(!FMLClientHandler.instance().hasOptifine()) FIXME 1.13 update
|
||||
GameSettings.Options.RENDER_DISTANCE.setValueMax(64f);
|
||||
GameSettings.Options.RENDER_DISTANCE.setValueMax(64f);
|
||||
//#endif
|
||||
|
||||
testIfMoeshAndExitMinecraft();
|
||||
@@ -300,8 +307,6 @@ public class ReplayMod {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
modules.forEach(m -> m.postInit(event));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -433,10 +438,4 @@ public class ReplayMod {
|
||||
mc.ingameGUI.getChatGUI().printChatMessage(new TextComponentTranslation(message, args));
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract class Module {
|
||||
public void preInit(FMLPreInitializationEvent event) {}
|
||||
public void init(FMLInitializationEvent event) {}
|
||||
public void postInit(FMLPostInitializationEvent event) {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,67 @@
|
||||
package com.replaymod.core;
|
||||
|
||||
import com.replaymod.core.events.SettingsChangedEvent;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
//#if MC>=11300
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
import net.minecraftforge.fml.ModLoadingContext;
|
||||
import net.minecraftforge.fml.config.ModConfig;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
//#else
|
||||
//$$ import net.minecraftforge.common.config.Configuration;
|
||||
//#endif
|
||||
|
||||
import static com.replaymod.core.versions.MCVer.*;
|
||||
|
||||
public class SettingsRegistry {
|
||||
private static final Object NULL_OBJECT = new Object();
|
||||
private Map<SettingKey<?>, Object> settings = new ConcurrentHashMap<>();
|
||||
private Configuration configuration;
|
||||
//#if MC>=11300
|
||||
private ForgeConfigSpec spec;
|
||||
private ModConfig config;
|
||||
//#else
|
||||
//$$ private Configuration configuration;
|
||||
//#endif
|
||||
|
||||
public void setConfiguration(Configuration configuration) {
|
||||
this.configuration = configuration;
|
||||
//#if MC>=11300
|
||||
public void register() {
|
||||
if (spec == null) {
|
||||
ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
|
||||
for (SettingKey<?> key : settings.keySet()) {
|
||||
builder
|
||||
.translation(key.getDisplayString())
|
||||
.define(key.getCategory() + "." + key.getKey(), key.getDefault());
|
||||
}
|
||||
spec = builder.build();
|
||||
}
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::load);
|
||||
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, spec);
|
||||
}
|
||||
|
||||
List<SettingKey<?>> keys = new ArrayList<>(settings.keySet());
|
||||
settings.clear();
|
||||
for (SettingKey key : keys) {
|
||||
register(key);
|
||||
private void load(ModConfig.Loading event) {
|
||||
config = event.getConfig();
|
||||
for (Map.Entry<SettingKey<?>, Object> entry : settings.entrySet()) {
|
||||
SettingKey<?> key = entry.getKey();
|
||||
Object value = config.getConfigData().get(key.getCategory() + "." + key.getKey());
|
||||
entry.setValue(value == null ? key.getDefault() : value);
|
||||
}
|
||||
}
|
||||
//#else
|
||||
//$$ public void setConfiguration(Configuration configuration) {
|
||||
//$$ this.configuration = configuration;
|
||||
//$$
|
||||
//$$ List<SettingKey<?>> keys = new ArrayList<>(settings.keySet());
|
||||
//$$ settings.clear();
|
||||
//$$ for (SettingKey key : keys) {
|
||||
//$$ register(key);
|
||||
//$$ }
|
||||
//$$ }
|
||||
//#endif
|
||||
|
||||
public void register(Class<?> settingsClass) {
|
||||
for (Field field : settingsClass.getDeclaredFields()) {
|
||||
@@ -40,23 +77,30 @@ public class SettingsRegistry {
|
||||
}
|
||||
|
||||
public void register(SettingKey<?> key) {
|
||||
Object value;
|
||||
if (configuration != null) {
|
||||
if (key.getDefault() instanceof Boolean) {
|
||||
value = configuration.get(key.getCategory(), key.getKey(), (Boolean) key.getDefault()).getBoolean();
|
||||
} else if (key.getDefault() instanceof Integer) {
|
||||
value = configuration.get(key.getCategory(), key.getKey(), (Integer) key.getDefault()).getInt();
|
||||
} else if (key.getDefault() instanceof Double) {
|
||||
value = configuration.get(key.getCategory(), key.getKey(), (Double) key.getDefault()).getDouble();
|
||||
} else if (key.getDefault() instanceof String) {
|
||||
value = configuration.get(key.getCategory(), key.getKey(), (String) key.getDefault()).getString();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Default type " + key.getDefault().getClass() + " not supported.");
|
||||
}
|
||||
} else {
|
||||
value = NULL_OBJECT;
|
||||
//#if MC>=11300
|
||||
if (spec != null) {
|
||||
throw new IllegalStateException("Cannot register more settings are spec has been built.");
|
||||
}
|
||||
settings.put(key, value);
|
||||
settings.put(key, NULL_OBJECT);
|
||||
//#else
|
||||
//$$ Object value;
|
||||
//$$ if (configuration != null) {
|
||||
//$$ if (key.getDefault() instanceof Boolean) {
|
||||
//$$ value = configuration.get(key.getCategory(), key.getKey(), (Boolean) key.getDefault()).getBoolean();
|
||||
//$$ } else if (key.getDefault() instanceof Integer) {
|
||||
//$$ value = configuration.get(key.getCategory(), key.getKey(), (Integer) key.getDefault()).getInt();
|
||||
//$$ } else if (key.getDefault() instanceof Double) {
|
||||
//$$ value = configuration.get(key.getCategory(), key.getKey(), (Double) key.getDefault()).getDouble();
|
||||
//$$ } else if (key.getDefault() instanceof String) {
|
||||
//$$ value = configuration.get(key.getCategory(), key.getKey(), (String) key.getDefault()).getString();
|
||||
//$$ } else {
|
||||
//$$ throw new IllegalArgumentException("Default type " + key.getDefault().getClass() + " not supported.");
|
||||
//$$ }
|
||||
//$$ } else {
|
||||
//$$ value = NULL_OBJECT;
|
||||
//$$ }
|
||||
//$$ settings.put(key, value);
|
||||
//#endif
|
||||
}
|
||||
|
||||
public Set<SettingKey<?>> getSettings() {
|
||||
@@ -72,23 +116,35 @@ public class SettingsRegistry {
|
||||
}
|
||||
|
||||
public <T> void set(SettingKey<T> key, T value) {
|
||||
if (key.getDefault() instanceof Boolean) {
|
||||
configuration.get(key.getCategory(), key.getKey(), (Boolean) key.getDefault()).set((Boolean) value);
|
||||
} else if (key.getDefault() instanceof Integer) {
|
||||
configuration.get(key.getCategory(), key.getKey(), (Integer) key.getDefault()).set((Integer) value);
|
||||
} else if (key.getDefault() instanceof Double) {
|
||||
configuration.get(key.getCategory(), key.getKey(), (Double) key.getDefault()).set((Double) value);
|
||||
} else if (key.getDefault() instanceof String) {
|
||||
configuration.get(key.getCategory(), key.getKey(), (String) key.getDefault()).set((String) value);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Default type " + key.getDefault().getClass() + " not supported.");
|
||||
//#if MC>=11300
|
||||
if (config != null) {
|
||||
config.getConfigData().set(key.getCategory() + "." + key.getKey(), value);
|
||||
}
|
||||
//#else
|
||||
//$$ if (key.getDefault() instanceof Boolean) {
|
||||
//$$ configuration.get(key.getCategory(), key.getKey(), (Boolean) key.getDefault()).set((Boolean) value);
|
||||
//$$ } else if (key.getDefault() instanceof Integer) {
|
||||
//$$ configuration.get(key.getCategory(), key.getKey(), (Integer) key.getDefault()).set((Integer) value);
|
||||
//$$ } else if (key.getDefault() instanceof Double) {
|
||||
//$$ configuration.get(key.getCategory(), key.getKey(), (Double) key.getDefault()).set((Double) value);
|
||||
//$$ } else if (key.getDefault() instanceof String) {
|
||||
//$$ configuration.get(key.getCategory(), key.getKey(), (String) key.getDefault()).set((String) value);
|
||||
//$$ } else {
|
||||
//$$ throw new IllegalArgumentException("Default type " + key.getDefault().getClass() + " not supported.");
|
||||
//$$ }
|
||||
//#endif
|
||||
settings.put(key, value);
|
||||
FML_BUS.post(new SettingsChangedEvent(this, key));
|
||||
}
|
||||
|
||||
public void save() {
|
||||
// FIXME forge config api is currently broken configuration.save();
|
||||
//#if MC>=11300
|
||||
if (config != null) {
|
||||
config.save();
|
||||
}
|
||||
//#else
|
||||
//$$ configuration.save();
|
||||
//#endif
|
||||
}
|
||||
|
||||
public interface SettingKey<T> {
|
||||
@@ -127,7 +183,7 @@ public class SettingsRegistry {
|
||||
|
||||
@Override
|
||||
public String getDisplayString() {
|
||||
return displayString == null ? null : I18n.format(displayString);
|
||||
return displayString;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -41,7 +41,7 @@ public class GuiReplaySettings extends AbstractGuiScreen<GuiReplaySettings> {
|
||||
@SuppressWarnings("unchecked")
|
||||
final SettingsRegistry.SettingKey<Boolean> booleanKey = (SettingsRegistry.SettingKey<Boolean>) key;
|
||||
final GuiToggleButton button = new GuiToggleButton<>().setSize(150, 20)
|
||||
.setLabel(key.getDisplayString()).setSelected(settingsRegistry.get(booleanKey) ? 0 : 1)
|
||||
.setI18nLabel(key.getDisplayString()).setSelected(settingsRegistry.get(booleanKey) ? 0 : 1)
|
||||
.setValues(I18n.format("options.on"), I18n.format("options.off"));
|
||||
element = button.onClick(new Runnable() {
|
||||
@Override
|
||||
@@ -60,7 +60,7 @@ public class GuiReplaySettings extends AbstractGuiScreen<GuiReplaySettings> {
|
||||
for (int j = 0; j < entries.length; j++) {
|
||||
Object value = values.get(j);
|
||||
entries[j] = new MultipleChoiceDropdownEntry(value,
|
||||
multipleChoiceKey.getDisplayString() + ": " + I18n.format(value.toString()));
|
||||
I18n.format(multipleChoiceKey.getDisplayString()) + ": " + I18n.format(value.toString()));
|
||||
if (currentValue.equals(value)) {
|
||||
selected = j;
|
||||
}
|
||||
|
||||
@@ -73,12 +73,25 @@ import static com.replaymod.core.versions.MCVer.getMinecraft;
|
||||
|
||||
public class Utils {
|
||||
|
||||
private static InputStream getResourceAsStream(String path) {
|
||||
// FIXME this seems broken in 1.13, hence the workaround. probably want to open an issue with modlauncher (or forge?)
|
||||
//#ifdef DEV_ENV
|
||||
try {
|
||||
return new java.io.FileInputStream(new File("../src/main/resources" + path));
|
||||
} catch (java.io.FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
//#else
|
||||
//$$ return Utils.class.getResourceAsStream(path);
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static final BufferedImage DEFAULT_THUMBNAIL;
|
||||
|
||||
static {
|
||||
BufferedImage thumbnail;
|
||||
try {
|
||||
thumbnail = ImageIO.read(Utils.class.getClassLoader().getResourceAsStream("default_thumb.jpg"));
|
||||
thumbnail = ImageIO.read(getResourceAsStream("/default_thumb.jpg"));
|
||||
} catch (Exception e) {
|
||||
thumbnail = new BufferedImage(1, 1, BufferedImage.TYPE_3BYTE_BGR);
|
||||
e.printStackTrace();
|
||||
@@ -103,7 +116,7 @@ public class Utils {
|
||||
|
||||
static {
|
||||
// Largely from https://community.letsencrypt.org/t/134/37
|
||||
try (InputStream in = Utils.class.getResourceAsStream("/dst_root_ca_x3.pem")){
|
||||
try (InputStream in = getResourceAsStream("/dst_root_ca_x3.pem")){
|
||||
Certificate certificate = CertificateFactory.getInstance("X.509").generateCertificate(in);
|
||||
|
||||
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
|
||||
@@ -47,7 +47,7 @@ public class LangResourcePack extends AbstractResourcePack {
|
||||
}
|
||||
|
||||
private ModFileResourcePack getParent() {
|
||||
return (ModFileResourcePack) ResourcePackLoader.getResourcePackFor(ReplayMod.MOD_ID);
|
||||
return ResourcePackLoader.getResourcePackFor(ReplayMod.MOD_ID).orElseThrow(() -> new RuntimeException("Failed to get ReplayMod resource pack!"));
|
||||
}
|
||||
|
||||
private String langName(String path) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.replaymod.recording;
|
||||
|
||||
import com.replaymod.core.KeyBindingRegistry;
|
||||
import com.replaymod.core.Module;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.core.utils.Restrictions;
|
||||
import com.replaymod.recording.handler.ConnectionEventHandler;
|
||||
@@ -20,22 +22,18 @@ import com.replaymod.core.versions.MCVer.Keyboard;
|
||||
//#endif
|
||||
|
||||
//#if MC>=10800
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
//#if MC>=11300
|
||||
import net.minecraftforge.fml.network.NetworkRegistry;
|
||||
//#else
|
||||
//$$ import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
//#endif
|
||||
//#else
|
||||
//$$ import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
//$$ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
//$$ import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
//#endif
|
||||
|
||||
import static com.replaymod.core.versions.MCVer.*;
|
||||
|
||||
public class ReplayModRecording extends ReplayMod.Module {
|
||||
public class ReplayModRecording implements Module {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final AttributeKey<Void> ATTR_CHECKED = AttributeKey.newInstance("ReplayModRecording_checked");
|
||||
@@ -49,13 +47,13 @@ public class ReplayModRecording extends ReplayMod.Module {
|
||||
|
||||
public ReplayModRecording(ReplayMod mod) {
|
||||
core = mod;
|
||||
|
||||
core.getSettingsRegistry().register(Setting.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
core.getSettingsRegistry().register(Setting.class);
|
||||
|
||||
core.getKeyBindingRegistry().registerKeyBinding("replaymod.input.marker", Keyboard.KEY_M, new Runnable() {
|
||||
public void registerKeyBindings(KeyBindingRegistry registry) {
|
||||
registry.registerKeyBinding("replaymod.input.marker", Keyboard.KEY_M, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PacketListener packetListener = connectionEventHandler.getPacketListener();
|
||||
@@ -68,7 +66,7 @@ public class ReplayModRecording extends ReplayMod.Module {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FMLInitializationEvent event) {
|
||||
public void initClient() {
|
||||
FML_BUS.register(connectionEventHandler = new ConnectionEventHandler(LOGGER, core));
|
||||
|
||||
new GuiHandler(core).register();
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.apache.logging.log4j.Logger;
|
||||
|
||||
//#if MC>=10800
|
||||
//#if MC>=11300
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
//#else
|
||||
//$$ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
@@ -62,7 +63,7 @@ public class ConnectionEventHandler {
|
||||
if (local) {
|
||||
//#if MC>=10800
|
||||
//#if MC>=11300
|
||||
if (mc.getIntegratedServer().getWorld(0).getWorldType() == WorldType_DEBUG_ALL_BLOCK_STATES) {
|
||||
if (mc.getIntegratedServer().getWorld(DimensionType.OVERWORLD).getWorldType() == WorldType_DEBUG_ALL_BLOCK_STATES) {
|
||||
//#else
|
||||
//$$ if (mc.getIntegratedServer().getEntityWorld().getWorldType() == WorldType_DEBUG_ALL_BLOCK_STATES) {
|
||||
//#endif
|
||||
|
||||
@@ -370,8 +370,17 @@ public class RecordingEventHandler {
|
||||
try {
|
||||
//#if MC>=11100
|
||||
//#if MC>=11200
|
||||
packetListener.save(new SPacketCollectItem(event.pickedUp.getEntityId(), event.player.getEntityId(),
|
||||
event.pickedUp.getItem().getMaxStackSize()));
|
||||
//#if MC>=11300
|
||||
ItemStack stack = event.getStack();
|
||||
packetListener.save(new SPacketCollectItem(
|
||||
event.getOriginalEntity().getEntityId(),
|
||||
event.getPlayer().getEntityId(),
|
||||
event.getStack().getCount()
|
||||
));
|
||||
//#else
|
||||
//$$ packetListener.save(new SPacketCollectItem(event.pickedUp.getEntityId(), event.player.getEntityId(),
|
||||
//$$ event.pickedUp.getItem().getMaxStackSize()));
|
||||
//#endif
|
||||
//#else
|
||||
//$$ packetListener.save(new SPacketCollectItem(event.pickedUp.getEntityId(), event.player.getEntityId(),
|
||||
//$$ event.pickedUp.getEntityItem().getMaxStackSize()));
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
package com.replaymod.recording.mixin;
|
||||
|
||||
import com.replaymod.recording.handler.RecordingEventHandler;
|
||||
import net.minecraft.client.renderer.RenderGlobal;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
//#if MC>=11300
|
||||
//#else
|
||||
//$$ import net.minecraft.client.renderer.RenderGlobal;
|
||||
//#endif
|
||||
|
||||
//#if MC>=10904
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
//#else
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
//#if MC>=11300
|
||||
import net.minecraft.world.dimension.Dimension;
|
||||
import net.minecraft.world.storage.WorldSavedDataStorage;
|
||||
//#else
|
||||
//$$ import net.minecraft.world.WorldProvider;
|
||||
//#endif
|
||||
@@ -31,14 +32,22 @@ public abstract class MixinWorldClient extends World implements RecordingEventHa
|
||||
@Shadow
|
||||
private Minecraft mc;
|
||||
|
||||
protected MixinWorldClient(ISaveHandler saveHandlerIn, WorldInfo info,
|
||||
protected MixinWorldClient(ISaveHandler saveHandlerIn,
|
||||
//#if MC>=11300
|
||||
WorldSavedDataStorage mapStorage,
|
||||
//#endif
|
||||
WorldInfo info,
|
||||
//#if MC>=11300
|
||||
Dimension providerIn,
|
||||
//#else
|
||||
//$$ WorldProvider providerIn,
|
||||
//#endif
|
||||
Profiler profilerIn, boolean client) {
|
||||
super(saveHandlerIn, info, providerIn, profilerIn, client);
|
||||
super(saveHandlerIn,
|
||||
//#if MC>=11300
|
||||
mapStorage,
|
||||
//#endif
|
||||
info, providerIn, profilerIn, client);
|
||||
}
|
||||
|
||||
private RecordingEventHandler replayModRecording_getRecordingEventHandler() {
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.apache.commons.io.IOUtils;
|
||||
|
||||
//#if MC>=11300
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
//#endif
|
||||
|
||||
//#if MC>=11200
|
||||
@@ -377,10 +378,14 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
|
||||
int chunkX = entity.chunkCoordX;
|
||||
int chunkY = entity.chunkCoordZ;
|
||||
|
||||
//#if MC>=11300
|
||||
if (entity.addedToChunk && world.getChunkProvider().provideChunk(chunkX, chunkY, false, false) != null) {
|
||||
//#else
|
||||
//#if MC>=10904
|
||||
if (entity.addedToChunk && world.getChunkProvider().getLoadedChunk(chunkX, chunkY) != null) {
|
||||
//$$ if (entity.addedToChunk && world.getChunkProvider().getLoadedChunk(chunkX, chunkY) != null) {
|
||||
//#else
|
||||
//$$ if (entity.addedToChunk && world.getChunkProvider().chunkExists(chunkX, chunkY)) {
|
||||
//#endif
|
||||
//#endif
|
||||
//#if MC>=11300
|
||||
world.getChunk(chunkX, chunkY).removeEntity(entity);
|
||||
@@ -566,7 +571,11 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
|
||||
actualID = entId;
|
||||
entId = -1789435; // Camera entity id should be negative which is an invalid id and can't be used by servers
|
||||
//#if MC>=10800
|
||||
int dimension = packet.getDimension();
|
||||
//#if MC>=11300
|
||||
DimensionType dimension = packet.func_212642_e();
|
||||
//#else
|
||||
//$$ int dimension = packet.getDimension();
|
||||
//#endif
|
||||
EnumDifficulty difficulty = packet.getDifficulty();
|
||||
//#if MC>=11300
|
||||
int maxPlayers = 0;// FIXME needs AT packet.maxPlayers;
|
||||
@@ -596,7 +605,12 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
|
||||
//#if MC>=10904
|
||||
if(p instanceof SPacketRespawn) {
|
||||
SPacketRespawn respawn = (SPacketRespawn) p;
|
||||
p = new SPacketRespawn(respawn.getDimensionID(),
|
||||
p = new SPacketRespawn(
|
||||
//#if MC>=11300
|
||||
respawn.func_212643_b(),
|
||||
//#else
|
||||
//$$ respawn.getDimensionID(),
|
||||
//#endif
|
||||
respawn.getDifficulty(), respawn.getWorldType(), GameType.SPECTATOR);
|
||||
//#else
|
||||
//$$ if(p instanceof S07PacketRespawn) {
|
||||
@@ -1083,7 +1097,11 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
|
||||
World world = world(mc);
|
||||
IChunkProvider chunkProvider = world.getChunkProvider();
|
||||
// Get the chunk that will be unloaded
|
||||
Chunk chunk = chunkProvider.provideChunk(x, z);
|
||||
//#if MC>=11300
|
||||
Chunk chunk = chunkProvider.provideChunk(x, z, false, false);
|
||||
//#else
|
||||
//$$ Chunk chunk = chunkProvider.provideChunk(x, z);
|
||||
//#endif
|
||||
if (!chunk.isEmpty()) {
|
||||
List<Entity> entitiesInChunk = new ArrayList<>();
|
||||
// Gather all entities in that chunk
|
||||
@@ -1109,12 +1127,16 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
|
||||
if (entity.chunkCoordX != chunkX || entity.chunkCoordZ != chunkZ) {
|
||||
// Entity has left the chunk
|
||||
chunk.removeEntityAtIndex(entity, entity.chunkCoordY);
|
||||
//#if MC>=11300
|
||||
Chunk newChunk = chunkProvider.provideChunk(chunkX, chunkZ, false, false);
|
||||
//#else
|
||||
//#if MC>=10904
|
||||
Chunk newChunk = chunkProvider.getLoadedChunk(chunkX, chunkZ);
|
||||
//$$ Chunk newChunk = chunkProvider.getLoadedChunk(chunkX, chunkZ);
|
||||
//#else
|
||||
//$$ Chunk newChunk = chunkProvider.chunkExists(chunkX, chunkZ)
|
||||
//$$ ? chunkProvider.provideChunk(chunkX, chunkZ) : null;
|
||||
//#endif
|
||||
//#endif
|
||||
if (newChunk != null) {
|
||||
newChunk.addEntity(entity);
|
||||
} else {
|
||||
|
||||
@@ -54,11 +54,15 @@ public class NoGuiScreenshot {
|
||||
mc.getFramebuffer().bindFramebuffer(true);
|
||||
GlStateManager.enableTexture2D();
|
||||
|
||||
//#if MC>=11300
|
||||
mc.entityRenderer.renderWorld(mc.timer.renderPartialTicks, System.nanoTime());
|
||||
//#else
|
||||
//#if MC>=10809
|
||||
mc.entityRenderer.updateCameraAndRender(mc.timer.renderPartialTicks, System.nanoTime());
|
||||
//$$ mc.entityRenderer.updateCameraAndRender(mc.timer.renderPartialTicks, System.nanoTime());
|
||||
//#else
|
||||
//$$ mc.entityRenderer.updateCameraAndRender(mc.timer.renderPartialTicks);
|
||||
//#endif
|
||||
//#endif
|
||||
|
||||
mc.getFramebuffer().unbindFramebuffer();
|
||||
GlStateManager.popMatrix();
|
||||
@@ -79,7 +83,12 @@ public class NoGuiScreenshot {
|
||||
// disk for better maintainability
|
||||
File tmpFolder = Files.createTempDir();
|
||||
try {
|
||||
ScreenShotHelper.saveScreenshot(tmpFolder, "tmp", frameWidth, frameHeight, mc.getFramebuffer());
|
||||
//#if MC>=11300
|
||||
ScreenShotHelper.saveScreenshot(tmpFolder, "tmp", frameWidth, frameHeight, mc.getFramebuffer(), (msg) ->
|
||||
mc.addScheduledTask(() -> mc.ingameGUI.getChatGUI().printChatMessage(msg)));
|
||||
//#else
|
||||
//$$ ScreenShotHelper.saveScreenshot(tmpFolder, "tmp", frameWidth, frameHeight, mc.getFramebuffer());
|
||||
//#endif
|
||||
File screenshotFile = new File(tmpFolder, "screenshots/tmp");
|
||||
BufferedImage image = ImageIO.read(screenshotFile);
|
||||
int imageWidth = image.getWidth();
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.google.common.base.Function;
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.replaymod.core.KeyBindingRegistry;
|
||||
import com.replaymod.core.Module;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.core.utils.ModCompat;
|
||||
import com.replaymod.core.versions.MCVer;
|
||||
@@ -29,23 +31,12 @@ import com.replaymod.core.versions.MCVer.Keyboard;
|
||||
//$$ import org.lwjgl.input.Keyboard;
|
||||
//#endif
|
||||
|
||||
//#if MC>=10800
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
//#else
|
||||
//$$ import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
//$$ import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
//$$ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
//#endif
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ReplayModReplay extends ReplayMod.Module {
|
||||
public class ReplayModReplay implements Module {
|
||||
|
||||
{ instance = this; }
|
||||
public static ReplayModReplay instance;
|
||||
@@ -64,13 +55,13 @@ public class ReplayModReplay extends ReplayMod.Module {
|
||||
|
||||
public ReplayModReplay(ReplayMod core) {
|
||||
this.core = core;
|
||||
|
||||
core.getSettingsRegistry().register(Setting.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
core.getSettingsRegistry().register(Setting.class);
|
||||
|
||||
core.getKeyBindingRegistry().registerKeyBinding("replaymod.input.marker", MCVer.Keyboard.KEY_M, new Runnable() {
|
||||
public void registerKeyBindings(KeyBindingRegistry registry) {
|
||||
registry.registerKeyBinding("replaymod.input.marker", MCVer.Keyboard.KEY_M, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (replayHandler != null ) {
|
||||
@@ -91,7 +82,7 @@ public class ReplayModReplay extends ReplayMod.Module {
|
||||
}
|
||||
});
|
||||
|
||||
core.getKeyBindingRegistry().registerRaw(Keyboard.KEY_DELETE, () -> {
|
||||
registry.registerRaw(Keyboard.KEY_DELETE, () -> {
|
||||
if (replayHandler != null) {
|
||||
GuiMarkerTimeline timeline = replayHandler.getOverlay().timeline;
|
||||
if (timeline.getSelectedMarker() != null) {
|
||||
@@ -102,7 +93,7 @@ public class ReplayModReplay extends ReplayMod.Module {
|
||||
}
|
||||
});
|
||||
|
||||
core.getKeyBindingRegistry().registerKeyBinding("replaymod.input.thumbnail", Keyboard.KEY_N, new Runnable() {
|
||||
registry.registerKeyBinding("replaymod.input.thumbnail", Keyboard.KEY_N, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (replayHandler != null) {
|
||||
@@ -130,7 +121,7 @@ public class ReplayModReplay extends ReplayMod.Module {
|
||||
}
|
||||
});
|
||||
|
||||
core.getKeyBindingRegistry().registerKeyBinding("replaymod.input.playpause", Keyboard.KEY_P, new Runnable() {
|
||||
registry.registerKeyBinding("replaymod.input.playpause", Keyboard.KEY_P, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (replayHandler != null) {
|
||||
@@ -139,7 +130,7 @@ public class ReplayModReplay extends ReplayMod.Module {
|
||||
}
|
||||
});
|
||||
|
||||
core.getKeyBindingRegistry().registerKeyBinding("replaymod.input.quickmode", Keyboard.KEY_Q, () -> {
|
||||
registry.registerKeyBinding("replaymod.input.quickmode", Keyboard.KEY_Q, () -> {
|
||||
if (replayHandler != null) {
|
||||
replayHandler.getReplaySender().setSyncModeAndWait();
|
||||
core.runLater(() ->
|
||||
@@ -161,7 +152,10 @@ public class ReplayModReplay extends ReplayMod.Module {
|
||||
core.getKeyBindingRegistry().registerKeyBinding("replaymod.input.resettilt", Keyboard.KEY_K, () -> {
|
||||
Optional.ofNullable(replayHandler).map(ReplayHandler::getCameraEntity).ifPresent(c -> c.roll = 0);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initClient() {
|
||||
cameraControllerRegistry.register("replaymod.camera.classic", new Function<CameraEntity, CameraController>() {
|
||||
@Nullable
|
||||
@Override
|
||||
@@ -176,21 +170,13 @@ public class ReplayModReplay extends ReplayMod.Module {
|
||||
return new VanillaCameraController(core.getMinecraft(), cameraEntity);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FMLInitializationEvent event) {
|
||||
Minecraft mc = core.getMinecraft();
|
||||
// FIXME mc.timer = new InputReplayTimer(mc.timer, this);
|
||||
|
||||
new GuiHandler(this).register();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInit(FMLPostInitializationEvent event) {
|
||||
Setting.CAMERA.setChoices(new ArrayList<>(cameraControllerRegistry.getControllers()));
|
||||
}
|
||||
|
||||
public void startReplay(File file) throws IOException {
|
||||
startReplay(new ZipReplayFile(new ReplayStudio(), file));
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ package com.replaymod.replay.camera;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.replaymod.replay.Setting;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -14,6 +16,7 @@ public class CameraControllerRegistry {
|
||||
public void register(String name, Function<CameraEntity, CameraController> constructor) {
|
||||
Preconditions.checkState(!constructors.containsKey(name), "Controller " + name + " is already registered.");
|
||||
constructors.put(name, constructor);
|
||||
Setting.CAMERA.setChoices(new ArrayList<>(getControllers()));
|
||||
}
|
||||
|
||||
public Set<String> getControllers() {
|
||||
|
||||
Reference in New Issue
Block a user