Skip to content

Commit

Permalink
👕 Reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
unhappychoice committed Jun 27, 2021
1 parent 11eee82 commit ccb6aab
Show file tree
Hide file tree
Showing 306 changed files with 1,708 additions and 7,448 deletions.
21 changes: 1 addition & 20 deletions src/main/java/com/replaymod/compat/ReplayModCompat.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,18 @@
package com.replaymod.compat;

import com.replaymod.compat.optifine.DisableFastRender;
import com.replaymod.compat.shaders.ShaderBeginRender;
import com.replaymod.core.Module;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

//#if MC<11400
//$$ import com.replaymod.compat.oranges17animations.HideInvisibleEntities;
//#endif

//#if MC<11400
//$$ import com.replaymod.compat.bettersprinting.DisableBetterSprinting;
//#endif

//#if MC>=10800
import com.replaymod.compat.shaders.ShaderBeginRender;
//#endif

public class ReplayModCompat implements Module {
public static Logger LOGGER = LogManager.getLogger();

@Override
public void initClient() {
//#if MC>=10800
new ShaderBeginRender().register();
//#endif
new DisableFastRender().register();
//#if MC<11400
//$$ new HideInvisibleEntities().register();
//#endif
//#if MC<11400
//$$ DisableBetterSprinting.register();
//#endif
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.replaymod.compat.optifine;

import com.replaymod.gui.utils.EventRegistrations;
import com.replaymod.core.versions.MCVer;
import com.replaymod.gui.utils.EventRegistrations;
import com.replaymod.render.events.ReplayRenderCallback;
import net.minecraft.client.Minecraft;

Expand All @@ -11,7 +11,10 @@ public class DisableFastRender extends EventRegistrations {

private boolean wasFastRender = false;

{ on(ReplayRenderCallback.Pre.EVENT, renderer -> onRenderBegin()); }
{
on(ReplayRenderCallback.Pre.EVENT, renderer -> onRenderBegin());
}

private void onRenderBegin() {
if (!MCVer.hasOptifine()) return;

Expand All @@ -23,7 +26,10 @@ private void onRenderBegin() {
}
}

{ on(ReplayRenderCallback.Post.EVENT, renderer -> onRenderEnd()); }
{
on(ReplayRenderCallback.Post.EVENT, renderer -> onRenderEnd());
}

private void onRenderEnd() {
if (!MCVer.hasOptifine()) return;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//#if MC>=10800
package com.replaymod.compat.shaders;

import com.replaymod.core.events.PreRenderCallback;
import com.replaymod.render.hooks.EntityRendererHandler;
import com.replaymod.gui.utils.EventRegistrations;
import com.replaymod.render.hooks.EntityRendererHandler;
import net.minecraft.client.Minecraft;

import java.lang.reflect.InvocationTargetException;
Expand All @@ -16,8 +15,10 @@ public class ShaderBeginRender extends EventRegistrations {
* Invokes Shaders#beginRender when rendering a video,
* as this would usually get called by EntityRenderer#renderWorld,
* which we're not calling during rendering.
*/
{ on(PreRenderCallback.EVENT, this::onRenderTickStart); }
*/ {
on(PreRenderCallback.EVENT, this::onRenderTickStart);
}

private void onRenderTickStart() {
if (ShaderReflection.shaders_beginRender == null) return;
if (ShaderReflection.config_isShaders == null) return;
Expand All @@ -31,14 +32,11 @@ private void onRenderTickStart() {
if (!(boolean) (ShaderReflection.config_isShaders.invoke(null))) return;

ShaderReflection.shaders_beginRender.invoke(null, mc,
//#if MC>=11400
mc.gameRenderer.getActiveRenderInfo(),
//#endif
mc.getRenderPartialTicks(), 0);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}

}
//#endif
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
//#if MC>=10800
package com.replaymod.compat.shaders;

import net.minecraft.client.Minecraft;

//#if MC>=11400
import net.minecraft.client.renderer.ActiveRenderInfo;
//#endif

import java.lang.reflect.Field;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -42,9 +38,7 @@ public class ShaderReflection {
shaders_isShadowPass.setAccessible(true);

shaders_beginRender = shadersClass.getDeclaredMethod("beginRender", Minecraft.class,
//#if MC>=11400
ActiveRenderInfo.class,
//#endif
float.class, long.class);
shaders_beginRender.setAccessible(true);

Expand All @@ -63,4 +57,3 @@ public class ShaderReflection {
}
}
}
//#endif
18 changes: 0 additions & 18 deletions src/main/java/com/replaymod/core/DummyChainLoadEntryPoint.java
Original file line number Diff line number Diff line change
@@ -1,18 +0,0 @@
//#if FABRIC>=1
//$$ package com.replaymod.core;
//$$
//$$ import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint;
//$$
//$$ // Required for ReplayModMMLauncher.
//$$ //
//$$ // Chain-loading mixin configurations only works when the first class that is loaded doesn't have any mixins which
//$$ // target it. The first class would ordinarily be MC's Main but there are valid use cases for targeting it, see
//$$ // e.g. https://github.com/ReplayMod/ReplayMod/issues/327
//$$ // So, instead of relying on the bad assumption that Main doesn't have any mixins, we'll instead register this
//$$ // dummy pre-launch entry point which is practically guaranteed to not have any mixins and gets called before Main.
//$$ public class DummyChainLoadEntryPoint implements PreLaunchEntrypoint {
//$$ @Override
//$$ public void onPreLaunch() {
//$$ }
//$$ }
//#endif
57 changes: 16 additions & 41 deletions src/main/java/com/replaymod/core/KeyBindingRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,23 @@

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import com.replaymod.core.events.PreRenderCallback;
import com.replaymod.mixin.KeyBindingAccessor;
import com.replaymod.gui.utils.EventRegistrations;
import com.replaymod.core.events.KeyBindingEventCallback;
import com.replaymod.core.events.KeyEventCallback;
import com.replaymod.core.events.PreRenderCallback;
import com.replaymod.gui.utils.EventRegistrations;
import com.replaymod.mixin.KeyBindingAccessor;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.crash.CrashReport;
import net.minecraft.crash.CrashReportCategory;
import net.minecraft.crash.ReportedException;

//#if FABRIC>=1
//$$ import com.replaymod.core.versions.LangResourcePack;
//$$ import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding;
//$$ import net.minecraft.client.util.InputUtil;
//$$ import net.minecraft.util.Identifier;
//$$ import static com.replaymod.core.ReplayMod.MOD_ID;
//#else
import net.minecraftforge.fml.client.registry.ClientRegistry;
//#endif

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import java.util.*;
import java.util.function.Consumer;
import java.util.function.Supplier;

public class KeyBindingRegistry extends EventRegistrations {
private static final String CATEGORY = "replaymod.title";
//#if FABRIC>=1
//$$ static { net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry.INSTANCE.addCategory(CATEGORY); }
//#endif

private final Map<String, Binding> bindings = new HashMap<>();
private Set<KeyBinding> onlyInReplay = new HashSet<>();
Expand All @@ -58,18 +39,8 @@ public Binding registerRepeatedKeyBinding(String name, int keyCode, Runnable whe
private Binding registerKeyBinding(String name, int keyCode, boolean onlyInRepay) {
Binding binding = bindings.get(name);
if (binding == null) {
//#if FABRIC>=1
//$$ if (keyCode == 0) {
//$$ keyCode = -1;
//$$ }
//$$ Identifier id = new Identifier(MOD_ID, name.substring(LangResourcePack.LEGACY_KEY_PREFIX.length()));
//$$ FabricKeyBinding fabricKeyBinding = FabricKeyBinding.Builder.create(id, InputUtil.Type.KEYSYM, keyCode, CATEGORY).build();
//$$ net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry.INSTANCE.register(fabricKeyBinding);
//$$ KeyBinding keyBinding = fabricKeyBinding;
//#else
KeyBinding keyBinding = new KeyBinding(name, keyCode, CATEGORY);
ClientRegistry.registerKeyBinding(keyBinding);
//#endif
binding = new Binding(name, keyBinding);
bindings.put(name, binding);
if (onlyInRepay) {
Expand All @@ -93,7 +64,9 @@ public Set<KeyBinding> getOnlyInReplay() {
return Collections.unmodifiableSet(onlyInReplay);
}

{ on(PreRenderCallback.EVENT, this::handleRepeatedKeyBindings); }
{
on(PreRenderCallback.EVENT, this::handleRepeatedKeyBindings);
}

public void handleRepeatedKeyBindings() {
for (Binding binding : bindings.values()) {
Expand All @@ -103,7 +76,10 @@ public void handleRepeatedKeyBindings() {
}
}

{ on(KeyBindingEventCallback.EVENT, this::handleKeyBindings); }
{
on(KeyBindingEventCallback.EVENT, this::handleKeyBindings);
}

private void handleKeyBindings() {
for (Binding binding : bindings.values()) {
while (binding.keyBinding.isPressed()) {
Expand All @@ -127,7 +103,10 @@ private void invokeKeyBindingHandlers(Binding binding, Collection<Runnable> hand
}
}

{ on(KeyEventCallback.EVENT, (keyCode, scanCode, action, modifiers) -> handleRaw(keyCode, action)); }
{
on(KeyEventCallback.EVENT, (keyCode, scanCode, action, modifiers) -> handleRaw(keyCode, action));
}

private boolean handleRaw(int keyCode, int action) {
if (action != KeyEventCallback.ACTION_PRESS) return false;
for (final Supplier<Boolean> handler : rawHandlers.get(keyCode)) {
Expand Down Expand Up @@ -169,11 +148,7 @@ public String getBoundKey() {
}

public boolean isBound() {
//#if MC>=11400
return !keyBinding.isInvalid();
//#else
//$$ return keyBinding.getKeyCode() != 0;
//#endif
}

public void trigger() {
Expand Down
12 changes: 1 addition & 11 deletions src/main/java/com/replaymod/core/MinecraftMethodAccessor.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
package com.replaymod.core;

public interface MinecraftMethodAccessor {
//#if MC>=11400
void replayModProcessKeyBinds();
//#else
//#if MC>=10904
//$$ void replayModRunTickMouse();
//$$ void replayModRunTickKeyboard();
//#else
//$$ void replayModSetEarlyReturnFromRunTick(boolean earlyReturn);
//#endif
//#endif
//#if MC>=11400

void replayModExecuteTaskQueue();
//#endif
}
11 changes: 8 additions & 3 deletions src/main/java/com/replaymod/core/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

public interface Module {
// FMLCommonSetupEvent for 1.13+, FMLInitializationEvent below
default void initCommon() {}
default void initCommon() {
}

// FMLClientSetupEvent for 1.13+, FMLInitializationEvent (if client) below
default void initClient() {}
default void initClient() {
}

// FMLClientSetupEvent for 1.13+, FMLInitializationEvent below
default void registerKeyBindings(KeyBindingRegistry registry) {}
default void registerKeyBindings(KeyBindingRegistry registry) {
}
}
Loading

0 comments on commit ccb6aab

Please sign in to comment.