Skip to content

Commit

Permalink
Update kirin and implement instant config reloading
Browse files Browse the repository at this point in the history
- add minScalingMultiplier, logNetworkEvents settings,
- fix various syncing bugs
- fix scaling limits not being abided by in some places
  • Loading branch information
Sollace committed Jul 23, 2024
1 parent 0c2a677 commit 65b159b
Show file tree
Hide file tree
Showing 15 changed files with 237 additions and 113 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ org.gradle.daemon=false

# Dependencies
modmenu_version=11.0.0-beta.1
kirin_version=1.19.0+1.21
kirin_version=1.19.1-beta.1+1.21
hd_skins_version=6.13.0+1.21
minelp_version=4.12.1-beta.1+1.21
fabwork_version=1.3.0+1.21
3 changes: 3 additions & 0 deletions src/main/java/com/minelittlepony/bigpony/BigPonyConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ public class BigPonyConfig extends Config {
public final Setting<EntityScale> scale = value("common", "scale", EntityScale.DEFAULT);

public final Setting<Boolean> useDetectedPonyScaling = value("client", "useDetectedPonyScaling", false);

public final Setting<Boolean> logNetworkEvents = value("server", "logNetworkEvents", false);
public final Setting<Float> maxScalingMultiplier = value("server", "maxScalingMultiplier", 2F);
public final Setting<Float> minScalingMultiplier = value("server", "minScalingMultiplier", 0.04F);
public final Setting<Boolean> allowHitboxChanges = value("server", "allowHitboxChanges", true);
public final Setting<Boolean> allowCameraChanges = value("server", "allowCameraChanges", true);
public final Setting<Boolean> allowFreeformResizing = value("server", "allowFreeformResizing", true);
Expand Down
31 changes: 0 additions & 31 deletions src/main/java/com/minelittlepony/bigpony/InteractionManager.java

This file was deleted.

48 changes: 21 additions & 27 deletions src/main/java/com/minelittlepony/bigpony/Scaling.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.minelittlepony.bigpony;

import com.minelittlepony.bigpony.client.BigPonyClient;
import com.minelittlepony.bigpony.data.BodyScale;
import com.minelittlepony.bigpony.data.CameraScale;
import com.minelittlepony.bigpony.data.EntityScale;
import com.minelittlepony.bigpony.minelittlepony.PresetDetector;
import com.minelittlepony.bigpony.network.InteractionManager;
import com.minelittlepony.bigpony.network.MsgPlayerSize;
import com.minelittlepony.bigpony.network.Network;
import net.minecraft.entity.EntityPose;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityDimensions;

Expand All @@ -35,25 +34,33 @@ public BodyScale getRenderedBodyScale() {
return (dimensions.visual() || !isPony) ? dimensions.body() : BodyScale.DEFAULT;
}

public BodyScale getHitboxScale() {
return Permissions.hitbox(InteractionManager.getInstance().getPermissions()) ? dimensions.body() : BodyScale.DEFAULT;
}

public CameraScale getCameraScale() {
return Permissions.hitbox(InteractionManager.getInstance().getPermissions()) ? dimensions.camera() : CameraScale.DEFAULT;
}

public EntityDimensions getReplacementSize(PlayerEntity entity, EntityPose pose, EntityDimensions existing) {
long permissions = InteractionManager.getInstance().getPermissions();
boolean changeHitbox = Permissions.hitbox(permissions);
boolean changeCamera = Permissions.camera(permissions);
BodyScale hitboxScale = getHitboxScale();
return new EntityDimensions(
changeHitbox ? Math.max(0.04F, multiply(existing.width(), dimensions.body().x())) : existing.width(),
changeHitbox ? Math.max(0.04F, multiply(existing.height(), dimensions.body().y())) : existing.height(),
changeCamera ? Math.max(0.004F, multiply(existing.eyeHeight(), dimensions.camera().height())) : existing.eyeHeight(),
existing.width() * InteractionManager.getInstance().getClamped(hitboxScale.shadowScale()),
existing.height() * InteractionManager.getInstance().getClamped(hitboxScale.y()),
existing.eyeHeight() * InteractionManager.getInstance().getClamped(getCameraScale().height()),
existing.attachments(),
false
);
}

public float getShadowScale() {
return Math.min(getRenderedBodyScale().shadowScale(), InteractionManager.getInstance().getMaxMultiplier());
return InteractionManager.getInstance().getClamped(getRenderedBodyScale().shadowScale());
}

public float getCameraDistanceMultiplier() {
return Permissions.camera(InteractionManager.getInstance().getPermissions()) ? Math.min(dimensions.camera().distance(), InteractionManager.getInstance().getMaxMultiplier()) : 1;
return Permissions.camera(InteractionManager.getInstance().getPermissions())
? InteractionManager.getInstance().getClamped(dimensions.camera().distance())
: 1;
}

public void markDirty() {
Expand All @@ -64,32 +71,19 @@ public void tick(PlayerEntity entity) {
isPony = PresetDetector.getInstance().isPony(entity);

long lastSettingsUpdateTime = InteractionManager.getInstance().getLastSettingsUpdateTime();
if (lastSettingsUpdateTime != this.lastSettingsUpdateTime) {
dirty = true;
this.lastSettingsUpdateTime = lastSettingsUpdateTime;
}

if (dirty) {
if (dirty || lastSettingsUpdateTime != this.lastSettingsUpdateTime) {
dirty = false;
this.lastSettingsUpdateTime = lastSettingsUpdateTime;
entity.calculateDimensions();
if (InteractionManager.getInstance().isNetworkConnected()) {
if (entity instanceof ServerPlayerEntity) {
Network.OTHER_PLAYER_SIZE.sendToSurroundingPlayers(toUpdatePacket(entity), entity);
} else if (entity.getWorld().isClient && BigPonyClient.isClientPlayer(entity)) {
Network.PLAYER_SIZE.sendToServer(toUpdatePacket(entity));
}
}
InteractionManager.getInstance().sendSizeUpdate(entity, this);
}
}

public MsgPlayerSize toUpdatePacket(Entity owner) {
return new MsgPlayerSize(owner.getId(), dimensions, true);
}

private static float multiply(float existing, float multiplier) {
return existing * Math.min(multiplier, InteractionManager.getInstance().getMaxMultiplier());
}

public interface Holder {
Scaling getScaling();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

import org.lwjgl.glfw.GLFW;

import com.minelittlepony.bigpony.Scaling;
import com.minelittlepony.bigpony.BigPony;
import com.minelittlepony.bigpony.client.gui.GuiBigSettings;
import com.minelittlepony.bigpony.network.client.ClientNetworkHandlerImpl;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;

public class BigPonyClient implements ClientModInitializer {
Expand Down Expand Up @@ -42,9 +41,13 @@ public void onInitializeClient() {
}
});
new ClientNetworkHandlerImpl();
}

public float onRenderShadow(float radius, Entity entity, MatrixStack stack) {
return radius * (entity instanceof Scaling.Holder holder ? holder.getScaling().getShadowScale() : 1);
BigPony.getInstance().getConfig().onChangedExternally(config -> {
MinecraftClient.getInstance().execute(() -> {
if (MinecraftClient.getInstance().currentScreen instanceof GuiBigSettings screen) {
screen.init(MinecraftClient.getInstance(), screen.width, ((Screen)screen).height);
}
});
});
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.minelittlepony.bigpony.client.gui;

import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Stream;

import com.minelittlepony.bigpony.BigPony;
import com.minelittlepony.bigpony.InteractionManager;
import com.minelittlepony.bigpony.Permissions;
import com.minelittlepony.bigpony.Scaling;
import com.minelittlepony.bigpony.data.EntityScale;
import com.minelittlepony.bigpony.minelittlepony.PresetDetector;
import com.minelittlepony.bigpony.network.InteractionManager;
import com.minelittlepony.common.client.gui.GameGui;
import com.minelittlepony.common.client.gui.ScrollContainer;
import com.minelittlepony.common.client.gui.element.AbstractSlider;
Expand All @@ -27,46 +28,69 @@ public class GuiBigSettings extends GameGui {
public static final Text OPTION_DISABLED = Text.translatable("minebp.options.disabled").formatted(Formatting.YELLOW);

private EntityScale dimensions;
private EntityScale initialDimensions;

final ScrollContainer content = new ScrollContainer();

private Button revert;
private ResettableSlider global, xSize, ySize, zSize, height, distance;

private CameraPresetButton[] presets;

public GuiBigSettings(Screen parent) {
super(TITLE);
MinecraftClient client = MinecraftClient.getInstance();
if (client.player == null) {
dimensions = BigPony.getInstance().getConfig().scale.get();
} else {
dimensions = ((Scaling.Holder)client.player).getScaling().getDimensions();
}

content.margin.top = 30;
content.margin.bottom = 30;
content.getContentPadding().top = 10;
content.getContentPadding().right = 10;
content.getContentPadding().bottom = 20;
content.getContentPadding().left = 10;
loadDimensions();
}

public boolean hasCameraConsent() {
return client.player == null || Permissions.camera(InteractionManager.getInstance().getPermissions());
}

public boolean hasScalingConsent() {
return (client.player == null || Permissions.freeform(InteractionManager.getInstance().getPermissions())) && dimensions.visual();
return (client.player == null || Permissions.freeform(InteractionManager.getInstance().getPermissions())) && !BigPony.getInstance().getConfig().useDetectedPonyScaling.get();
}

public boolean hasHitboxConsent() {
return client.player == null || Permissions.hitbox(InteractionManager.getInstance().getPermissions());
}


@Override
protected void init() {
loadDimensions();

addButton(new Label(width / 2, 6)).setCentered().getStyle().setText(getTitle().getString());

content.init(this::rebuildContent);

addButton(new Button(width / 2 - 110, super.height - 25, 100, 20))
.onClick(sender -> finish())
.getStyle()
.setText("gui.done");
addButton(revert = new Button(width / 2 + 10, super.height - 25, 100, 20))
.onClick(sender -> {
dimensions = initialDimensions;
updateDimensions();
clearAndInit();
})
.getStyle()
.setText("gui.revert");
tick();
}

private void loadDimensions() {
MinecraftClient client = MinecraftClient.getInstance();
if (client.player == null) {
dimensions = BigPony.getInstance().getConfig().scale.get();
} else {
dimensions = ((Scaling.Holder)client.player).getScaling().getDimensions();
}
initialDimensions = dimensions;
}

private void rebuildContent() {
Expand All @@ -80,8 +104,6 @@ private void rebuildContent() {
boolean allowHitbox = hasHitboxConsent();
boolean allowScaling = hasScalingConsent();

addButton(new Label(width / 2, 6)).setCentered().getStyle().setText(getTitle().getString());

content.addButton(new Label(left, top)).getStyle().setText("minebp.options.body");
content.addButton(new Label(left, top + 100)).getStyle().setText("minebp.options.camera");
content.addButton(new Label(right, top)).getStyle().setText("minebp.options.presets");
Expand Down Expand Up @@ -175,13 +197,6 @@ private void rebuildContent() {
presets = Stream.of(CameraPresets.values())
.map(preset -> new CameraPresetButton(this, preset, right))
.toArray(CameraPresetButton[]::new);

addButton(new Button(width / 2 - 100, super.height - 25, 200, 20))
.onClick(sender -> finish())
.getStyle()
.setText("gui.done");

tick();
}

static Function<AbstractSlider<Float>, Text> format(String key) {
Expand Down Expand Up @@ -210,6 +225,7 @@ public void tick() {

height.setEnabled(allowCamera && allowScaling);
distance.setEnabled(allowCamera && allowScaling);
revert.setEnabled(!Objects.equals(dimensions, initialDimensions));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.network.codec.PacketCodecs;

public record CameraScale(float distance, float height) {
public static final CameraScale DEFAULT = new CameraScale(1);
public static final Codec<CameraScale> CODEC = RecordCodecBuilder.create(i -> i.group(
Codec.FLOAT.fieldOf("distance").forGetter(CameraScale::distance),
Codec.FLOAT.fieldOf("height").forGetter(CameraScale::height)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;

import com.minelittlepony.bigpony.client.BigPonyClient;

import com.minelittlepony.bigpony.Scaling;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.util.math.MatrixStack;
Expand All @@ -31,6 +30,6 @@ abstract class MixinEntityRenderDispatcher {
+ "F"
+ ")V"), index = 6)
private float modifyRadius(MatrixStack matrices, VertexConsumerProvider vertices, Entity entity, float opacity, float tickDelta, WorldView world, float radius) {
return BigPonyClient.getInstance().onRenderShadow(radius, entity, matrices);
return radius * (entity instanceof Scaling.Holder holder ? holder.getScaling().getShadowScale() : 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.minelittlepony.bigpony.Scaling;
import com.minelittlepony.bigpony.data.BodyScale;
import com.minelittlepony.bigpony.network.InteractionManager;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.GameRenderer;
Expand All @@ -24,29 +25,31 @@ abstract class MixinGameRenderer implements SynchronousResourceReloader, AutoClo
private void onBobView(MatrixStack matrices, float f, CallbackInfo info) {
MinecraftClient client = MinecraftClient.getInstance();

if (!(client.getCameraEntity() instanceof PlayerEntity)) {
if (!(client.getCameraEntity() instanceof PlayerEntity player)) {
return;
}

info.cancel();

PlayerEntity player = (PlayerEntity)client.getCameraEntity();
BodyScale scale = ((Scaling.Holder)player).getScaling().getRenderedBodyScale();

float g = player.horizontalSpeed - player.prevHorizontalSpeed;
float h = -(player.horizontalSpeed + g * f);
float i = MathHelper.lerp(f, player.prevStrideDistance, player.strideDistance);

BodyScale scale = ((Scaling.Holder)player).getScaling().getRenderedBodyScale();
float xScale = InteractionManager.getInstance().getClamped(scale.x());
float yScale = InteractionManager.getInstance().getClamped(scale.y());
float zScale = InteractionManager.getInstance().getClamped(scale.z());

matrices.translate(
(MathHelper.sin(h * (float)Math.PI) * i / 2) * scale.x(),
-Math.abs(MathHelper.cos(h * (float)Math.PI) * i) * scale.y(),
(MathHelper.sin(h * MathHelper.PI) * i * 0.5F) * xScale,
-Math.abs(MathHelper.cos(h * MathHelper.PI) * i) * yScale,
0
);
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(
MathHelper.sin(h * (float)Math.PI) * i * 3 * scale.z()
MathHelper.sin(h * MathHelper.PI) * i * 3 * zScale
));
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(
Math.abs(MathHelper.cos(h * (float)Math.PI - 0.2f) * i) * 5 * scale.x()
Math.abs(MathHelper.cos(h * MathHelper.PI - 0.2F) * i) * 5 * xScale
));
}
}
Loading

0 comments on commit 65b159b

Please sign in to comment.