Skip to content

Commit

Permalink
Fix pony size detecting messing with fillycam
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed May 16, 2024
1 parent ca26c0d commit ae839fc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/minelittlepony/bigpony/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ static void bootstrap() {
BigPony.LOGGER.info("Resetting registered flag");
});
ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> {
if (client.player instanceof Scaled) {
((Scaled)client.player).getScaling().setInitial(client.player);
if (client.player instanceof Scaled scaled) {
scaled.getScaling().setInitial(client.player);
}
});
ClientPlayNetworking.registerGlobalReceiver(CONSENT_ID, (client, ignore1, buffer, ignore2) -> {
Expand Down
40 changes: 17 additions & 23 deletions src/main/java/com/minelittlepony/bigpony/minelittlepony/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.minelittlepony.bigpony.minelittlepony;

import com.minelittlepony.api.pony.IPony;
import com.minelittlepony.api.pony.IPonyData;
import com.minelittlepony.api.pony.meta.Size;
import com.minelittlepony.api.pony.network.fabric.PonyDataCallback;
import com.minelittlepony.bigpony.*;
Expand All @@ -11,14 +12,11 @@
import java.util.concurrent.CompletableFuture;

import com.minelittlepony.api.config.PonyConfig;
import com.minelittlepony.api.model.IModel;
import com.minelittlepony.api.model.ModelAttributes;
import com.minelittlepony.api.model.fabric.PonyModelPrepareCallback;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Identifier;

Expand All @@ -28,22 +26,20 @@ public class Main extends PresetDetector implements ClientModInitializer {
public void onInitializeClient() {
INSTANCE = this;

PonyModelPrepareCallback.EVENT.register(this::onPonyModelPrepared);
PonyModelPrepareCallback.EVENT.register((entity, model, mode) -> {
if (entity instanceof Scaled && !((Scaled)entity).getScaling().isVisual() && isPony((PlayerEntity)entity)) {
model.getAttributes().visualHeight = entity.getHeight() / model.getSize().getScaleFactor();
}
});
PonyDataCallback.EVENT.register((sender, data, noSkin, env) -> {
if (!BigPony.getInstance().getScaling().isVisual()
&& env == EnvType.CLIENT
&& BigPonyClient.isClientPlayer(sender)) {
detectPreset(sender.getGameProfile(), ((Scaled)sender).getScaling());
applyPreset(IPony.getManager().getPony(sender).metadata(), ((Scaled)sender).getScaling());
}
});
}

private void onPonyModelPrepared(Entity entity, IModel model, ModelAttributes.Mode mode) {
if (entity instanceof Scaled && !((Scaled)entity).getScaling().isVisual() && isPony((PlayerEntity)entity)) {
model.getAttributes().visualHeight = entity.getHeight() / model.getSize().getScaleFactor();
}
}

@Override
public boolean isFillyCam() {
return PonyConfig.getInstance().fillycam.get();
Expand All @@ -57,19 +53,17 @@ public boolean isPony(PlayerEntity player) {
@Override
public CompletableFuture<Identifier> detectPreset(GameProfile profile, Scaling into) {
return SkinDetecter.getInstance().loadSkin(profile).thenApplyAsync(skin -> {
// Turn on filly cam so we can get the camera parameters
PonyConfig.getInstance().fillycam.set(true);

IPony pony = IPony.getManager().getPony(skin);
Size size = pony.metadata().getSize();

into.setScale(new Triple(size.getScaleFactor()));
into.setCamera(new Cam(size.getEyeDistanceFactor(), size.getEyeHeightFactor()));

// We turn off filly cam because it's not needed and might cause issues with buckets if left enabled
PonyConfig.getInstance().fillycam.set(false);
PonyConfig.getInstance().save();
applyPreset(IPony.getManager().getPony(skin).metadata(), into);
return skin;
}, MinecraftClient.getInstance());
}

private void applyPreset(IPonyData data, Scaling into) {
Size size = data.getSize();
boolean fillyCam = PonyConfig.getInstance().fillycam.get();
PonyConfig.getInstance().fillycam.set(true);
into.setScale(new Triple(size.getScaleFactor()));
into.setCamera(new Cam(size.getEyeDistanceFactor(), size.getEyeHeightFactor()));
PonyConfig.getInstance().fillycam.set(fillyCam);
}
}

0 comments on commit ae839fc

Please sign in to comment.