Skip to content

Commit

Permalink
Man. That sure is a port
Browse files Browse the repository at this point in the history
  • Loading branch information
enjarai committed Jan 23, 2024
1 parent 8bd509f commit 1099212
Show file tree
Hide file tree
Showing 49 changed files with 519 additions and 244 deletions.
1 change: 0 additions & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ dependencies {
minecraft "com.mojang:minecraft:${minecraft_version}"
mappings "net.fabricmc:yarn:${yarn_version}:v2"

modCompileOnly "net.fabricmc.fabric-api:fabric-api:${fabric_version}"
modCompileOnly "net.fabricmc:fabric-loader:${fabric_loader_version}"

modImplementation("dev.isxander.yacl:yet-another-config-lib-common:${project.yacl_version}") {
Expand Down
31 changes: 27 additions & 4 deletions common/src/main/java/nl/enjarai/doabarrelroll/DoABarrelRoll.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package nl.enjarai.doabarrelroll;

import net.fabricmc.loader.api.FabricLoader;
import io.netty.buffer.Unpooled;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.util.Identifier;
import nl.enjarai.doabarrelroll.api.event.ServerEvents;
import nl.enjarai.doabarrelroll.config.ModConfigServer;
import nl.enjarai.doabarrelroll.fabric.net.HandshakeServerFabric;
import nl.enjarai.doabarrelroll.net.HandshakeServer;
import nl.enjarai.doabarrelroll.net.RollSyncServer;
import nl.enjarai.doabarrelroll.net.ServerConfigHolder;
import nl.enjarai.doabarrelroll.net.register.HandshakeServerRegister;
import nl.enjarai.doabarrelroll.net.register.ServerConfigUpdaterRegister;
import nl.enjarai.doabarrelroll.platform.Services;
import org.slf4j.Logger;

import java.nio.file.Path;

public class DoABarrelRoll {
public static final String MODID = "do_a_barrel_roll";
public static final Logger LOGGER = Services.PLATFORM.getLogger();
Expand All @@ -25,14 +32,30 @@ public static Identifier id(String path) {
}

public static void init() {
var configFile = FabricLoader.getInstance().getConfigDir().resolve(DoABarrelRoll.MODID + "-server.json");
var configFile = Path.of("config").resolve(DoABarrelRoll.MODID + "-server.json");

Services.PLATFORM.registerNetworkChannels(HANDSHAKE_CHANNEL, SERVER_CONFIG_UPDATE_CHANNEL, ROLL_CHANNEL);

CONFIG_HOLDER = new ServerConfigHolder<>(configFile,
ModConfigServer.CODEC, ModConfigServer.DEFAULT, ServerEvents::updateServerConfig);
HANDSHAKE_SERVER = new HandshakeServer(CONFIG_HOLDER, player -> !ModConfigServer.canModify(player));

// Register server-side listeners for config syncing, this is done on
// both client and server to ensure everything works in LAN worlds as well.
HandshakeServerFabric.init();
RollSyncServer.init();
HandshakeServerRegister.init();
ServerConfigUpdaterRegister.init();
}

public static void serverTick(MinecraftServer server) {
HANDSHAKE_SERVER.tick(server);
}

public static void playerDisconnected(ServerPlayNetworkHandler handler) {
HANDSHAKE_SERVER.playerDisconnected(handler);
}

public static PacketByteBuf createBuf() {
return new PacketByteBuf(Unpooled.buffer());
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package nl.enjarai.doabarrelroll;

import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.network.ServerInfo;
import net.minecraft.client.util.SmoothUtil;
import nl.enjarai.doabarrelroll.api.RollEntity;
import nl.enjarai.doabarrelroll.api.RollMouse;
Expand All @@ -16,18 +12,16 @@
import nl.enjarai.doabarrelroll.config.LimitedModConfigServer;
import nl.enjarai.doabarrelroll.config.ModConfig;
import nl.enjarai.doabarrelroll.config.ModConfigServer;
import nl.enjarai.doabarrelroll.fabric.net.HandshakeClientFabric;
import nl.enjarai.doabarrelroll.net.register.HandshakeClientRegister;
import nl.enjarai.doabarrelroll.flight.RotationModifiers;
import nl.enjarai.doabarrelroll.impl.key.InputContextImpl;
import nl.enjarai.doabarrelroll.net.HandshakeClient;
import nl.enjarai.doabarrelroll.render.HorizonLineWidget;
import nl.enjarai.doabarrelroll.render.MomentumCrosshairWidget;
import nl.enjarai.doabarrelroll.util.MixinHooks;
import nl.enjarai.doabarrelroll.util.StarFoxUtil;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector2d;

import java.lang.reflect.Method;

public class DoABarrelRollClient {
public static final HandshakeClient<LimitedModConfigServer, ModConfigServer> HANDSHAKE_CLIENT = new HandshakeClient<>(
ModConfigServer.CODEC,
Expand Down Expand Up @@ -64,28 +58,29 @@ public static void init() {
.useModifier(RotationModifiers::banking, ModConfig.INSTANCE::getEnableBanking),
1000, FALL_FLYING_GROUP);

ClientTickEvents.END_CLIENT_TICK.register((client) -> {
if (!isFallFlying()) {
clearValues();
}
});

ClientEvents.SERVER_CONFIG_UPDATE.register(ModConfig.INSTANCE::notifyPlayerOfServerConfig);

ModConfig.touch();
HandshakeClientFabric.init();

// Register keybindings on fabric
ModKeybindings.FABRIC.forEach(KeyBindingHelper::registerKeyBinding);
HandshakeClientRegister.init();

// Init barrel rollery.
StarFoxUtil.register();
}

ClientTickEvents.END_CLIENT_TICK.register(client -> {
ModKeybindings.clientTick(client);
public static void clientTick(MinecraftClient client) {
InputContextImpl.getContexts().forEach(InputContextImpl::tick);

if (!isFallFlying()) {
clearValues();
}

ModKeybindings.clientTick(client);

StarFoxUtil.clientTick(client);
}

StarFoxUtil.clientTick(client);
});
public static void clientDisconnect() {
DoABarrelRollClient.HANDSHAKE_CLIENT.reset();
}

public static void onRenderCrosshair(DrawContext context, float tickDelta, int scaledWidth, int scaledHeight) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class ModKeybindings {
"category.do_a_barrel_roll.do_a_barrel_roll.movement"
);

public static final List<KeyBinding> FABRIC = List.of(
public static final List<KeyBinding> ALL = List.of(
TOGGLE_ENABLED,
TOGGLE_THRUST,
OPEN_CONFIG,
Expand Down
20 changes: 4 additions & 16 deletions common/src/main/java/nl/enjarai/doabarrelroll/compat/Compat.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
package nl.enjarai.doabarrelroll.compat;

import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.Version;
import net.fabricmc.loader.api.VersionParsingException;
import nl.enjarai.doabarrelroll.platform.Services;

public class Compat {
public static final Version YACL_MIN_VERSION;

static {
try {
YACL_MIN_VERSION = Version.parse("3.1.0");
} catch (VersionParsingException e) {
throw new RuntimeException(e);
}
}
public static final String YACL_MIN_VERSION = "3.1.0";

public static boolean isYACLLoaded() {
return FabricLoader.getInstance().isModLoaded("yet_another_config_lib_v3");
return Services.PLATFORM.checkModLoaded("yet_another_config_lib_v3");
}

public static boolean isYACLUpToDate() {
return FabricLoader.getInstance().getModContainer("yet_another_config_lib_v3")
.filter(modContainer -> modContainer.getMetadata().getVersion().compareTo(YACL_MIN_VERSION) >= 0)
.isPresent();
return Services.PLATFORM.isModVersionAtLeast("yet_another_config_lib_v3", YACL_MIN_VERSION);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package nl.enjarai.doabarrelroll.compat;

import net.fabricmc.loader.api.FabricLoader;
import nl.enjarai.doabarrelroll.platform.Services;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
Expand All @@ -27,7 +27,7 @@ default String getRefMapperConfig() {
@Override
default boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return getRequiredMods().stream()
.allMatch((modId) -> FabricLoader.getInstance().isModLoaded(modId));
.allMatch(Services.PLATFORM::checkModLoaded);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package nl.enjarai.doabarrelroll.compat.yacl;

import dev.isxander.yacl3.api.*;
import dev.isxander.yacl3.api.controller.*;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
import net.fabricmc.loader.api.FabricLoader;
import dev.isxander.yacl3.api.controller.DoubleSliderControllerBuilder;
import dev.isxander.yacl3.api.controller.EnumControllerBuilder;
import dev.isxander.yacl3.api.controller.IntegerSliderControllerBuilder;
import dev.isxander.yacl3.api.controller.TickBoxControllerBuilder;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ConfirmScreen;
import net.minecraft.client.gui.screen.Screen;
Expand All @@ -21,6 +21,7 @@
import nl.enjarai.doabarrelroll.config.*;
import nl.enjarai.doabarrelroll.math.ExpressionParser;
import nl.enjarai.doabarrelroll.net.ServerConfigUpdateClient;
import nl.enjarai.doabarrelroll.platform.Services;

import java.net.URI;
import java.util.ArrayList;
Expand All @@ -47,7 +48,7 @@ public static Screen generateConfigScreen(Screen parent) {
.option(allowDisabled.add(getBooleanOption("general", "mod_enabled", false, false)
.description(OptionDescription.createBuilder()
.text(Text.translatable("config.do_a_barrel_roll.general.mod_enabled.description",
KeyBindingHelper.getBoundKeyOf(ModKeybindings.TOGGLE_ENABLED).getLocalizedText()))
ModKeybindings.TOGGLE_ENABLED.getBoundKeyLocalizedText()))
.build())
.binding(true, () -> ModConfig.INSTANCE.getModEnabled(), value -> ModConfig.INSTANCE.setModEnabled(value))))
.group(OptionGroup.createBuilder()
Expand Down Expand Up @@ -155,7 +156,7 @@ public static Screen generateConfigScreen(Screen parent) {
.build())
.group(OptionGroup.createBuilder()
.name(getText("controller"))
.collapsed(!(FabricLoader.getInstance().isModLoaded("controlify") || FabricLoader.getInstance().isModLoaded("midnightcontrols")))
.collapsed(!(Services.PLATFORM.checkModLoaded("controlify") || Services.PLATFORM.checkModLoaded("midnightcontrols")))
.description(OptionDescription.createBuilder()
.text(getText("controller.description"))
.build())
Expand Down Expand Up @@ -301,7 +302,7 @@ public static Screen generateConfigScreen(Screen parent) {
// Add a listener for this screen to update elements when the server config changes.
ClientEvents.ServerConfigUpdateEvent listener = configListener::accept;
ClientEvents.SERVER_CONFIG_UPDATE.register(listener);
ScreenEvents.remove(screen).register(screen1 -> ClientEvents.SERVER_CONFIG_UPDATE.unregister(listener));
Services.PLATFORM.notMyProblem(screen, () -> ClientEvents.SERVER_CONFIG_UPDATE.unregister(listener));
})
.build()
.generateScreen(parent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import nl.enjarai.doabarrelroll.DoABarrelRollClient;
Expand All @@ -24,8 +23,7 @@ public class ModConfig {
.setPrettyPrinting()
.create();
public static final ModConfig DEFAULT = new ModConfig();
public static final Path CONFIG_FILE = FabricLoader.getInstance()
.getConfigDir().resolve("do_a_barrel_roll-client.json");
public static final Path CONFIG_FILE = Path.of("config").resolve("do_a_barrel_roll-client.json");
public static ModConfig INSTANCE = loadConfigFile(CONFIG_FILE.toFile());

public static void touch() {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 1099212

Please sign in to comment.