diff --git a/src/main/java/com/minelittlepony/client/mixin/MixinCamera.java b/src/main/java/com/minelittlepony/client/mixin/MixinCamera.java new file mode 100644 index 00000000..b53ab913 --- /dev/null +++ b/src/main/java/com/minelittlepony/client/mixin/MixinCamera.java @@ -0,0 +1,36 @@ +package com.minelittlepony.client.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import com.minelittlepony.MineLittlePony; +import com.minelittlepony.pony.IPony; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.Camera; + +@Mixin(Camera.class) +public abstract class MixinCamera { + + // cameraDistance; + // float field_18721; + // prevCameraDistance; + // float field_18722; + + @Inject(method = "method_19318(D)D", + at = @At("RETURN"), + cancellable = true) + private void redirectCameraDistance(double initial, CallbackInfoReturnable info) { + double value = info.getReturnValueD(); + + IPony pony = MineLittlePony.getInstance().getManager().getPony(MinecraftClient.getInstance().player); + + if (!pony.getRace(false).isHuman()) { + value *= pony.getMetadata().getSize().getEyeDistanceFactor(); + } + + info.setReturnValue(value); + } +} diff --git a/src/main/java/com/minelittlepony/client/mixin/MixinPlayerEntity.java b/src/main/java/com/minelittlepony/client/mixin/MixinPlayerEntity.java new file mode 100644 index 00000000..688d70a8 --- /dev/null +++ b/src/main/java/com/minelittlepony/client/mixin/MixinPlayerEntity.java @@ -0,0 +1,35 @@ +package com.minelittlepony.client.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import com.minelittlepony.MineLittlePony; +import com.minelittlepony.pony.IPony; + +import net.minecraft.entity.EntityPose; +import net.minecraft.entity.EntitySize; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; + +@Mixin(PlayerEntity.class) +public abstract class MixinPlayerEntity extends LivingEntity { + + private MixinPlayerEntity() {super(null, null);} + + @Inject(method = "getActiveEyeHeight(Lnet/minecraft/entity/EntityPose;Lnet/minecraft/entity/EntitySize;)F", + at = @At("RETURN"), + cancellable = true) + protected void redirectGetActiveEyeHeight(EntityPose pose, EntitySize size, CallbackInfoReturnable info) { + float value = info.getReturnValueF(); + + IPony pony = MineLittlePony.getInstance().getManager().getPony((PlayerEntity)(Object)this); + + if (!pony.getRace(false).isHuman()) { + value *= pony.getMetadata().getSize().getEyeHeightFactor(); + } + + info.setReturnValue(value); + } +} diff --git a/src/main/java/com/minelittlepony/client/pony/Pony.java b/src/main/java/com/minelittlepony/client/pony/Pony.java index 357bf702..47d9a189 100644 --- a/src/main/java/com/minelittlepony/client/pony/Pony.java +++ b/src/main/java/com/minelittlepony/client/pony/Pony.java @@ -35,7 +35,6 @@ import net.minecraft.util.math.Vec3d; import java.io.FileNotFoundException; import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; -import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; @@ -91,7 +90,12 @@ public class Pony extends Touchable implements IPony { } @Nullable - public static NativeImage getBufferedImage(@Nonnull Identifier resource) { + public static NativeImage getBufferedImage(@Nullable Identifier resource) { + + if (resource == null) { + return null; + } + try { Resource skin = MinecraftClient.getInstance().getResourceManager().getResource(resource); NativeImage skinImage = NativeImage.fromInputStream(skin.getInputStream()); diff --git a/src/main/java/com/minelittlepony/client/pony/PonyManager.java b/src/main/java/com/minelittlepony/client/pony/PonyManager.java index c97aa1bf..3e945ced 100644 --- a/src/main/java/com/minelittlepony/client/pony/PonyManager.java +++ b/src/main/java/com/minelittlepony/client/pony/PonyManager.java @@ -65,6 +65,10 @@ public class PonyManager implements IPonyManager, ResourceReloadListener, ISkinC @Override public IPony getPony(PlayerEntity player) { + if (player == null || player.getGameProfile() == null) { + return getDefaultPony(player.getUuid()); + } + Identifier skin = getSkin(player); UUID uuid = player.getGameProfile().getId(); diff --git a/src/main/java/com/minelittlepony/client/settings/ClientPonyConfig.java b/src/main/java/com/minelittlepony/client/settings/ClientPonyConfig.java index 0f9d659a..5d9b9615 100644 --- a/src/main/java/com/minelittlepony/client/settings/ClientPonyConfig.java +++ b/src/main/java/com/minelittlepony/client/settings/ClientPonyConfig.java @@ -1,5 +1,8 @@ package com.minelittlepony.client.settings; +import net.minecraft.client.MinecraftClient; +import net.minecraft.entity.player.PlayerEntity; + import com.minelittlepony.client.render.entities.MobRenderers; import com.minelittlepony.hdskins.HDSkins; import com.minelittlepony.settings.PonyConfig; @@ -20,4 +23,13 @@ public class ClientPonyConfig extends PonyConfig { super.setPonyLevel(ponylevel); } + + @Override + public void save() { + super.save(); + PlayerEntity player = MinecraftClient.getInstance().player; + if (player != null) { + player.refreshSize(); + } + } } diff --git a/src/main/java/com/minelittlepony/pony/meta/Size.java b/src/main/java/com/minelittlepony/pony/meta/Size.java index 66fb732e..fdf34eae 100644 --- a/src/main/java/com/minelittlepony/pony/meta/Size.java +++ b/src/main/java/com/minelittlepony/pony/meta/Size.java @@ -5,22 +5,24 @@ import com.minelittlepony.pony.ITriggerPixelMapped; import com.minelittlepony.settings.PonySettings; public enum Size implements ITriggerPixelMapped { - TALL (0x764b53, 0.45f, 1.1F), - BULKY (0x5432ce, 0.5f, 1), - LANKY (0xce5432, 0.45F, 0.85F), - NORMAL (0x000000, 0.4f, 0.8F), - YEARLING(0xffbe53, 0.4F, 0.6F), - FOAL (0x53beff, 0.25f, 0.6F); + TALL (0x764b53, 0.45f, 1.1F, 1.15F), + BULKY (0x5432ce, 0.5f, 1, 1.05F), + LANKY (0xce5432, 0.45F, 0.85F, 0.9F), + NORMAL (0x000000, 0.4f, 0.8F, 0.8F), + YEARLING(0xffbe53, 0.4F, 0.6F, 0.65F), + FOAL (0x53beff, 0.25f, 0.6F, 0.5F); private int triggerValue; private float shadowSize; private float scale; + private float camera; - Size(int pixel, float shadowSz, float scaleF) { + Size(int pixel, float shadowSz, float scaleF, float cameraF) { triggerValue = pixel; shadowSize = shadowSz; scale = scaleF; + camera = cameraF; } public float getShadowSize() { @@ -31,6 +33,20 @@ public enum Size implements ITriggerPixelMapped { return scale * MineLittlePony.getInstance().getConfig().getGlobalScaleFactor(); } + public float getEyeHeightFactor() { + if (!PonySettings.FILLYCAM.get()) { + return 1; + } + return camera * MineLittlePony.getInstance().getConfig().getGlobalScaleFactor(); + } + + public float getEyeDistanceFactor() { + if (!PonySettings.FILLYCAM.get()) { + return 1; + } + return camera * MineLittlePony.getInstance().getConfig().getGlobalScaleFactor(); + } + @Override public int getTriggerPixel() { return triggerValue; diff --git a/src/main/java/com/minelittlepony/settings/PonySettings.java b/src/main/java/com/minelittlepony/settings/PonySettings.java index 38f1eb45..a41fedd0 100644 --- a/src/main/java/com/minelittlepony/settings/PonySettings.java +++ b/src/main/java/com/minelittlepony/settings/PonySettings.java @@ -10,6 +10,7 @@ public enum PonySettings implements Setting { SIZES, SNUZZLES, HD, + FILLYCAM, SHOWSCALE, FPSMAGIC, PONYSKULLS, diff --git a/src/main/resources/assets/minelittlepony/lang/en_us.json b/src/main/resources/assets/minelittlepony/lang/en_us.json index 67c4d88d..0c7bbad6 100644 --- a/src/main/resources/assets/minelittlepony/lang/en_us.json +++ b/src/main/resources/assets/minelittlepony/lang/en_us.json @@ -9,6 +9,7 @@ "minelp.options.hd": "Enable MineLP skin server", "minelp.options.sizes": "Allow all different sizes of pony", "minelp.options.snuzzles": "Display snuzzles on ponies", + "minelp.options.fillycam": "Enable Filly Cam", "minelp.options.showscale": "Use show-accurate scaling", "minelp.options.fpsmagic": "Ponies use magic in first-person", "minelp.options.ponyskulls": "Render mob heads as ponies", diff --git a/src/main/resources/minelp.mixin.json b/src/main/resources/minelp.mixin.json index 9b9526b7..f95aee13 100644 --- a/src/main/resources/minelp.mixin.json +++ b/src/main/resources/minelp.mixin.json @@ -6,10 +6,12 @@ "compatibilityLevel": "JAVA_8", "client": [ "IResizeable", + "MixinCamera", "MixinDefaultPlayerSkin", "MixinFirstPersonRenderer", "MixinGlStateManager", "MixinItemRenderer", + "MixinPlayerEntity", "MixinThreadDownloadImageData" ] }