Skip to content

Commit

Permalink
compat
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamesuta committed Nov 3, 2018
1 parent 798ae7f commit dcb062b
Show file tree
Hide file tree
Showing 63 changed files with 1,982 additions and 1,572 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package net.teamfruit.serverobserver;

import java.io.File;
import java.util.Map;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.apache.logging.log4j.Logger;

import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
Expand All @@ -13,11 +16,14 @@
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.network.NetworkCheckHandler;
import net.minecraftforge.fml.relauncher.Side;
import net.teamfruit.serverobserver.CompatProxy.CompatFMLInitializationEvent;
import net.teamfruit.serverobserver.CompatProxy.CompatFMLPostInitializationEvent;
import net.teamfruit.serverobserver.CompatProxy.CompatFMLPreInitializationEvent;

@Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION, guiFactory = Reference.GUI_FACTORY)
public class ServerObserver {
@SidedProxy(serverSide = Reference.PROXY_SERVER, clientSide = Reference.PROXY_CLIENT)
private static @Nullable IProxy proxy;
private static @Nullable CommonProxy proxy;

@NetworkCheckHandler
public boolean checkModList(final @Nonnull Map<String, String> versions, final @Nonnull Side side) {
Expand All @@ -27,18 +33,51 @@ public boolean checkModList(final @Nonnull Map<String, String> versions, final @
@EventHandler
public void preInit(final @Nonnull FMLPreInitializationEvent event) {
if (proxy!=null)
proxy.preInit(event);
proxy.preInit(new CompatFMLPreInitializationEventImpl(event));
}

@EventHandler
public void init(final @Nonnull FMLInitializationEvent event) {
if (proxy!=null)
proxy.init(event);
proxy.init(new CompatFMLInitializationEventImpl(event));
}

@EventHandler
public void postInit(final @Nonnull FMLPostInitializationEvent event) {
if (proxy!=null)
proxy.postInit(event);
proxy.postInit(new CompatFMLPostInitializationEventImpl(event));
}

private static class CompatFMLPreInitializationEventImpl implements CompatFMLPreInitializationEvent {
private final @Nonnull FMLPreInitializationEvent event;

public CompatFMLPreInitializationEventImpl(final FMLPreInitializationEvent event) {
this.event = event;
}

@Override
public Logger getModLog() {
return this.event.getModLog();
}

@Override
public File getSuggestedConfigurationFile() {
return this.event.getSuggestedConfigurationFile();
}

@Override
public File getModConfigurationDirectory() {
return this.event.getModConfigurationDirectory();
}
}

private static class CompatFMLInitializationEventImpl implements CompatFMLInitializationEvent {
public CompatFMLInitializationEventImpl(final FMLInitializationEvent event) {
}
}

private static class CompatFMLPostInitializationEventImpl implements CompatFMLPostInitializationEvent {
public CompatFMLPostInitializationEventImpl(final FMLPostInitializationEvent event) {
}
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package net.teamfruit.serverobserver;

import java.util.List;
import java.util.Set;

import javax.annotation.Nullable;

import com.google.common.collect.Lists;

import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.common.config.ConfigCategory;
import net.minecraftforge.common.config.ConfigElement;
import net.minecraftforge.common.config.Property;
import net.minecraftforge.fml.client.IModGuiFactory;
import net.minecraftforge.fml.client.config.GuiConfig;
import net.minecraftforge.fml.client.config.IConfigElement;

public class CompatConfigs {
public static class CompatGuiConfig extends GuiConfig {
public CompatGuiConfig(final GuiScreen parentScreen, final List<CompatConfigElement> configElements, final String modID, final boolean allRequireWorldRestart, final boolean allRequireMcRestart, final String title) {
super(parentScreen, CompatConfigElement.getConfigElements(configElements), modID, allRequireWorldRestart, allRequireMcRestart, GuiConfig.getAbridgedConfigPath(title));
}
}

public static class CompatConfigElement {
public final IConfigElement element;

public CompatConfigElement(final IConfigElement element) {
this.element = element;
}

public static List<IConfigElement> getConfigElements(final List<CompatConfigElement> elements) {
return Lists.transform(elements, t -> t==null ? null : t.element);
}

public static CompatConfigElement fromCategory(final ConfigCategory category) {
return new CompatConfigElement(new ConfigElement(category));
}

public static CompatConfigElement fromProperty(final Property prop) {
return new CompatConfigElement(new ConfigElement(prop));
}
}

public static abstract class CompatModGuiFactory implements IModGuiFactory {
@Override
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() {
return null;
}

@SuppressWarnings("deprecation")
@Override
public RuntimeOptionGuiHandler getHandlerFor(final RuntimeOptionCategoryElement element) {
return null;
}

@Override
public @Nullable Class<? extends GuiScreen> mainConfigGuiClass() {
return mainConfigGuiClassCompat();
}

public abstract @Nullable Class<? extends GuiScreen> mainConfigGuiClassCompat();

public abstract GuiScreen createConfigGuiCompat(GuiScreen parentScreen);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package net.teamfruit.serverobserver;

import java.io.File;

import javax.annotation.Nonnull;

import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent;
import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent;
import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;

public abstract class CompatHandler {
public abstract void preInit(final File root);

public void init() {
// FMLCommonHandler.instance().bus().register(this);
MinecraftForge.EVENT_BUS.register(this);
}

public static class CompatEvent<T extends Event> {
protected final T event;

public CompatEvent(final T event) {
this.event = event;
}

public void setCanceled(final boolean cancel) {
this.event.setCanceled(cancel);
}
}

public static class CompatOnConfigChangedEvent extends CompatEvent<ConfigChangedEvent.OnConfigChangedEvent> {
public CompatOnConfigChangedEvent(final ConfigChangedEvent.OnConfigChangedEvent event) {
super(event);
}

public String getModID() {
return this.event.getModID();
}
}

public static class CompatClientTickEvent extends CompatEvent<ClientTickEvent> {
public CompatClientTickEvent(final ClientTickEvent event) {
super(event);
}
}

@SubscribeEvent
public void onConfigChanged(final @Nonnull ConfigChangedEvent.OnConfigChangedEvent eventArgs) {
onConfigChangedCompat(new CompatOnConfigChangedEvent(eventArgs));
}

public abstract void onConfigChangedCompat(final @Nonnull CompatOnConfigChangedEvent eventArgs);

@SubscribeEvent
public void open(final InitGuiEvent.Post e) {
openCompat(e);
}

public abstract void openCompat(final InitGuiEvent.Post e);

@SubscribeEvent
public void draw(final DrawScreenEvent.Post e) {
drawCompat(e);
}

public abstract void drawCompat(final DrawScreenEvent.Post e);

@SubscribeEvent
public void action(final ActionPerformedEvent.Pre e) {
actionCompat(e);
}

public abstract void actionCompat(final ActionPerformedEvent.Pre e);

@SubscribeEvent
public void action(final ActionPerformedEvent.Post e) {
actionCompat(e);
}

public abstract void actionCompat(final ActionPerformedEvent.Post e);

@SubscribeEvent
public void tickclient(final @Nonnull ClientTickEvent e) {
tickclientCompat(new CompatClientTickEvent(e));
}

public abstract void tickclientCompat(final @Nonnull CompatClientTickEvent e);
}
Loading

0 comments on commit dcb062b

Please sign in to comment.