From f0e43cdbe7247abb95a821acaded8ef2eb26cd83 Mon Sep 17 00:00:00 2001 From: Sollace Date: Mon, 1 Mar 2021 09:41:14 +0200 Subject: [PATCH] Rotate ponies wings to match when the player flaps their wings --- gradle.properties | 2 +- .../unicopia/client/UnicopiaClient.java | 1 + .../unicopia/client/gui/SettingsScreen.java | 2 +- .../unicopia/client/minelittlepony/Main.java | 22 ++++++++++++++----- .../{ => minelittlepony}/MineLPConnector.java | 2 +- 5 files changed, 21 insertions(+), 8 deletions(-) rename src/main/java/com/minelittlepony/unicopia/client/{ => minelittlepony}/MineLPConnector.java (95%) diff --git a/gradle.properties b/gradle.properties index 3efd7298..915b502a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,5 +18,5 @@ org.gradle.daemon=false # Dependencies modmenu_version=1.14.+ - minelp_version=4.2.1-1.16.5 + minelp_version=4.2.2-1.16.5-1.16-SNAPSHOT kirin_version=1.7.1-1.16.2-SNAPSHOT diff --git a/src/main/java/com/minelittlepony/unicopia/client/UnicopiaClient.java b/src/main/java/com/minelittlepony/unicopia/client/UnicopiaClient.java index 8dc87935..5e78dcab 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/UnicopiaClient.java +++ b/src/main/java/com/minelittlepony/unicopia/client/UnicopiaClient.java @@ -8,6 +8,7 @@ import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.client.gui.SettingsScreen; import com.minelittlepony.unicopia.client.gui.UHud; +import com.minelittlepony.unicopia.client.minelittlepony.MineLPConnector; import com.minelittlepony.unicopia.entity.player.PlayerCamera; import com.minelittlepony.unicopia.entity.player.Pony; import net.fabricmc.api.ClientModInitializer; diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/SettingsScreen.java b/src/main/java/com/minelittlepony/unicopia/client/gui/SettingsScreen.java index abfffb5d..7c8ed4dd 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/SettingsScreen.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/SettingsScreen.java @@ -19,7 +19,7 @@ import com.minelittlepony.unicopia.Config; import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.WorldTribeManager; -import com.minelittlepony.unicopia.client.MineLPConnector; +import com.minelittlepony.unicopia.client.minelittlepony.MineLPConnector; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.MinecraftClient; diff --git a/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/Main.java b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/Main.java index 94ff6eba..c7555e91 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/Main.java +++ b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/Main.java @@ -3,26 +3,38 @@ package com.minelittlepony.unicopia.client.minelittlepony; import com.minelittlepony.client.render.EquineRenderManager; import com.minelittlepony.model.IModel; import com.minelittlepony.model.capabilities.fabric.PonyModelPrepareCallback; +import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.entity.player.Pony; import net.fabricmc.api.ClientModInitializer; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.math.MathHelper; public class Main implements ClientModInitializer { + private boolean hookErroring; + @Override public void onInitializeClient() { PonyModelPrepareCallback.EVENT.register(this::onPonyModelPrepared); } private void onPonyModelPrepared(Entity entity, IModel model, EquineRenderManager.Mode mode) { - if (entity instanceof PlayerEntity) { - Pony pony = Pony.of((PlayerEntity)entity); + if (hookErroring) return; + try { + if (entity instanceof PlayerEntity) { + Pony pony = Pony.of((PlayerEntity)entity); - model.getAttributes().isSwimming |= pony.getMotion().isFlying(); - //model.getAttributes().isSwimmingRotated |= pony.getMotion().isFlying(); - model.getAttributes().isGoingFast |= pony.getMotion().isRainbooming(); + if (pony.getMotion().isFlying()) { + model.getAttributes().wingAngle = MathHelper.clamp(pony.getMotion().getWingAngle() / 3 - (float)Math.PI * 0.7F, -3, 0); + model.getAttributes().isHorizontal = true; + } + model.getAttributes().isGoingFast |= pony.getMotion().isRainbooming(); + } + } catch (Throwable t) { + Unicopia.LOGGER.error("Exception occured in MineLP hook:onPonyModelPrepared", t); + hookErroring = true; } } } diff --git a/src/main/java/com/minelittlepony/unicopia/client/MineLPConnector.java b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/MineLPConnector.java similarity index 95% rename from src/main/java/com/minelittlepony/unicopia/client/MineLPConnector.java rename to src/main/java/com/minelittlepony/unicopia/client/minelittlepony/MineLPConnector.java index c7084833..ee0cd6f6 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/MineLPConnector.java +++ b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/MineLPConnector.java @@ -1,4 +1,4 @@ -package com.minelittlepony.unicopia.client; +package com.minelittlepony.unicopia.client.minelittlepony; import com.minelittlepony.client.MineLittlePony; import com.minelittlepony.unicopia.Race;