Skip to content

Commit

Permalink
Forge users will see this and just be like "hell yea"
Browse files Browse the repository at this point in the history
  • Loading branch information
enjarai committed Jan 24, 2024
1 parent 1099212 commit 85cf044
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 95 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Added support for Forge & NeoForge 1.20.1.
- Removed dependency on Forgified Fabric API.
12 changes: 1 addition & 11 deletions common/src/main/java/nl/enjarai/doabarrelroll/DoABarrelRoll.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

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.net.HandshakeServer;
import nl.enjarai.doabarrelroll.net.RollSyncServer;
import nl.enjarai.doabarrelroll.net.register.RollSyncServer;
import nl.enjarai.doabarrelroll.net.ServerConfigHolder;
import nl.enjarai.doabarrelroll.net.register.HandshakeServerRegister;
import nl.enjarai.doabarrelroll.net.register.ServerConfigUpdaterRegister;
Expand Down Expand Up @@ -47,14 +45,6 @@ public static void 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());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package nl.enjarai.doabarrelroll;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.util.SmoothUtil;
import nl.enjarai.doabarrelroll.api.RollEntity;
import nl.enjarai.doabarrelroll.api.RollMouse;
import nl.enjarai.doabarrelroll.api.event.ClientEvents;
import nl.enjarai.doabarrelroll.api.event.RollEvents;
import nl.enjarai.doabarrelroll.api.event.RollGroup;
Expand All @@ -14,13 +11,9 @@
import nl.enjarai.doabarrelroll.config.ModConfigServer;
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.joml.Vector2d;

public class DoABarrelRollClient {
public static final HandshakeClient<LimitedModConfigServer, ModConfigServer> HANDSHAKE_CLIENT = new HandshakeClient<>(
Expand Down Expand Up @@ -67,43 +60,7 @@ public static void init() {
StarFoxUtil.register();
}

public static void clientTick(MinecraftClient client) {
InputContextImpl.getContexts().forEach(InputContextImpl::tick);

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

ModKeybindings.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) {
if (!isFallFlying()) return;

var matrices = context.getMatrices();
var entity = MinecraftClient.getInstance().getCameraEntity();
var rollEntity = ((RollEntity) entity);
if (entity != null) {
if (ModConfig.INSTANCE.getShowHorizon()) {
HorizonLineWidget.render(matrices, scaledWidth, scaledHeight,
rollEntity.doABarrelRoll$getRoll(tickDelta), entity.getPitch(tickDelta));
}

if (ModConfig.INSTANCE.getMomentumBasedMouse() && ModConfig.INSTANCE.getShowMomentumWidget()) {
var rollMouse = (RollMouse) MinecraftClient.getInstance().mouse;

MomentumCrosshairWidget.render(matrices, scaledWidth, scaledHeight, new Vector2d(rollMouse.doABarrelRoll$getMouseTurnVec()));
}
}
}

private static void clearValues() {
public static void clearValues() {
PITCH_SMOOTHER.clear();
YAW_SMOOTHER.clear();
ROLL_SMOOTHER.clear();
Expand Down
14 changes: 14 additions & 0 deletions common/src/main/java/nl/enjarai/doabarrelroll/EventCallbacks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package nl.enjarai.doabarrelroll;

import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayNetworkHandler;

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

public static void playerDisconnected(ServerPlayNetworkHandler handler) {
DoABarrelRoll.HANDSHAKE_SERVER.playerDisconnected(handler);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package nl.enjarai.doabarrelroll;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import nl.enjarai.doabarrelroll.api.RollEntity;
import nl.enjarai.doabarrelroll.api.RollMouse;
import nl.enjarai.doabarrelroll.config.ModConfig;
import nl.enjarai.doabarrelroll.impl.key.InputContextImpl;
import nl.enjarai.doabarrelroll.render.HorizonLineWidget;
import nl.enjarai.doabarrelroll.render.MomentumCrosshairWidget;
import nl.enjarai.doabarrelroll.util.StarFoxUtil;
import org.joml.Vector2d;

public class EventCallbacksClient {
public static void clientTick(MinecraftClient client) {
InputContextImpl.getContexts().forEach(InputContextImpl::tick);

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

ModKeybindings.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) {
if (!DoABarrelRollClient.isFallFlying()) return;

var matrices = context.getMatrices();
var entity = MinecraftClient.getInstance().getCameraEntity();
var rollEntity = ((RollEntity) entity);
if (entity != null) {
if (ModConfig.INSTANCE.getShowHorizon()) {
HorizonLineWidget.render(matrices, scaledWidth, scaledHeight,
rollEntity.doABarrelRoll$getRoll(tickDelta), entity.getPitch(tickDelta));
}

if (ModConfig.INSTANCE.getMomentumBasedMouse() && ModConfig.INSTANCE.getShowMomentumWidget()) {
var rollMouse = (RollMouse) MinecraftClient.getInstance().mouse;

MomentumCrosshairWidget.render(matrices, scaledWidth, scaledHeight, new Vector2d(rollMouse.doABarrelRoll$getMouseTurnVec()));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.llamalad7.mixinextras.sugar.ref.LocalFloatRef;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.hud.InGameHud;
import nl.enjarai.doabarrelroll.DoABarrelRollClient;
import nl.enjarai.doabarrelroll.EventCallbacksClient;
import nl.enjarai.doabarrelroll.util.StarFoxUtil;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -31,7 +31,7 @@ public abstract class InGameHudMixin {
)
private void doABarrelRoll$renderCrosshairHead(DrawContext context, CallbackInfo ci, @Share("tickDelta") LocalFloatRef tickDeltaRef) {
context.getMatrices().push();
DoABarrelRollClient.onRenderCrosshair(context, tickDeltaRef.get(), scaledWidth, scaledHeight);
EventCallbacksClient.onRenderCrosshair(context, tickDeltaRef.get(), scaledWidth, scaledHeight);
}

@Inject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import nl.enjarai.doabarrelroll.config.Sensitivity;
import nl.enjarai.doabarrelroll.flight.RotationModifiers;
import nl.enjarai.doabarrelroll.math.MagicNumbers;
import nl.enjarai.doabarrelroll.net.RollSyncClient;
import nl.enjarai.doabarrelroll.net.register.RollSyncClient;
import org.joml.Vector3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import net.minecraft.entity.Entity;
import net.minecraft.server.network.EntityTrackerEntry;
import nl.enjarai.doabarrelroll.api.RollEntity;
import nl.enjarai.doabarrelroll.net.RollSyncServer;
import nl.enjarai.doabarrelroll.net.register.RollSyncServer;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import nl.enjarai.doabarrelroll.DoABarrelRoll;
import nl.enjarai.doabarrelroll.DoABarrelRollClient;
import nl.enjarai.doabarrelroll.net.RollSyncClient;
import nl.enjarai.doabarrelroll.platform.Services;

public class HandshakeClientRegister {
Expand All @@ -12,7 +11,7 @@ public static void init() {
responseSender.accept(returnBuf);

if (DoABarrelRollClient.HANDSHAKE_CLIENT.hasConnected()) {
RollSyncClient.startListening();
RollSyncClient.init();
ServerConfigUpdateClientRegister.startListening();
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nl.enjarai.doabarrelroll.net;
package nl.enjarai.doabarrelroll.net.register;

import net.minecraft.client.MinecraftClient;
import net.minecraft.util.math.MathHelper;
Expand All @@ -8,20 +8,7 @@
import nl.enjarai.doabarrelroll.platform.Services;

public class RollSyncClient {
public static void sendUpdate(RollEntity entity) {
if (DoABarrelRollClient.HANDSHAKE_CLIENT.hasConnected()) {
boolean rolling = entity.doABarrelRoll$isRolling();
float roll = entity.doABarrelRoll$getRoll();

var buf = DoABarrelRoll.createBuf();
buf.writeBoolean(rolling);
buf.writeFloat(roll);

Services.CLIENT_NET.sendPacket(DoABarrelRoll.ROLL_CHANNEL, buf);
}
}

public static void startListening() {
public static void init() {
Services.CLIENT_NET.registerListener(DoABarrelRoll.ROLL_CHANNEL, (buf, responseSender) -> {
var client = MinecraftClient.getInstance();
if (client.world == null) {
Expand All @@ -42,4 +29,17 @@ public static void startListening() {
rollEntity.doABarrelRoll$setRoll(MathHelper.wrapDegrees(roll));
});
}

public static void sendUpdate(RollEntity entity) {
if (DoABarrelRollClient.HANDSHAKE_CLIENT.hasConnected()) {
boolean rolling = entity.doABarrelRoll$isRolling();
float roll = entity.doABarrelRoll$getRoll();

var buf = DoABarrelRoll.createBuf();
buf.writeBoolean(rolling);
buf.writeFloat(roll);

Services.CLIENT_NET.sendPacket(DoABarrelRoll.ROLL_CHANNEL, buf);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package nl.enjarai.doabarrelroll.net;
package nl.enjarai.doabarrelroll.net.register;

import net.minecraft.entity.Entity;
import net.minecraft.util.math.MathHelper;
import nl.enjarai.doabarrelroll.DoABarrelRoll;
import nl.enjarai.doabarrelroll.api.RollEntity;
import nl.enjarai.doabarrelroll.net.HandshakeServer;
import nl.enjarai.doabarrelroll.platform.Services;

public class RollSyncServer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public void onInitialize() {
DoABarrelRoll.init();

ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> {
DoABarrelRoll.playerDisconnected(handler);
EventCallbacks.playerDisconnected(handler);
});
ServerTickEvents.END_SERVER_TICK.register(DoABarrelRoll::serverTick);
ServerTickEvents.END_SERVER_TICK.register(EventCallbacks::serverTick);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import nl.enjarai.doabarrelroll.DoABarrelRollClient;

public class DoABarrelRollFabricClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
DoABarrelRollClient.init();

ClientTickEvents.END_CLIENT_TICK.register(DoABarrelRollClient::clientTick);
ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> DoABarrelRollClient.clientDisconnect());
ClientTickEvents.END_CLIENT_TICK.register(EventCallbacksClient::clientTick);
ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> EventCallbacksClient.clientDisconnect());

// Register keybindings on fabric
ModKeybindings.ALL.forEach(KeyBindingHelper::registerKeyBinding);
Expand Down
8 changes: 0 additions & 8 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ loom {

sourceSets.main.resources.srcDir 'src/generated/resources'

repositories {
maven {
name = "Sinytra"
url = "https://maven.su5ed.dev/releases"
}
mavenLocal()
}

dependencies {
minecraft "com.mojang:minecraft:${minecraft_version}"
forge "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ public static void gatherPermissions(PermissionGatherEvent.Nodes event) {
@SubscribeEvent
public static void playerLoggedOut(PlayerEvent.PlayerLoggedOutEvent event) {
if (event.getEntity() instanceof ServerPlayerEntity serverPlayer) {
DoABarrelRoll.playerDisconnected(serverPlayer.networkHandler);
EventCallbacks.playerDisconnected(serverPlayer.networkHandler);
}
}

@SubscribeEvent
public static void serverTick(TickEvent.ServerTickEvent event) {
if (event.phase == TickEvent.Phase.END) {
DoABarrelRoll.serverTick(event.getServer());
EventCallbacks.serverTick(event.getServer());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ public class WhyIsTherePublicTransportationInThisModLoaderClient {
@SubscribeEvent
public static void clientTick(TickEvent.ClientTickEvent event) {
if (event.phase == TickEvent.Phase.END) {
DoABarrelRollClient.clientTick(MinecraftClient.getInstance());
EventCallbacksClient.clientTick(MinecraftClient.getInstance());
}
}

@SubscribeEvent
public static void loggedOut(ClientPlayerNetworkEvent.LoggingOut event) {
DoABarrelRollClient.clientDisconnect();
EventCallbacksClient.clientDisconnect();
}
}

0 comments on commit 85cf044

Please sign in to comment.