socially distanced camera

- zoom out the third person view when mounting a train
- added a command to manually zoom out as well :)
- removed op permission requirement from highlight command
This commit is contained in:
zelophed 2022-06-08 02:16:07 +02:00
parent 9b3b0032fc
commit 017c547d0d
9 changed files with 157 additions and 2 deletions

View file

@ -0,0 +1,30 @@
package com.simibubi.create.content.logistics.trains;
import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.utility.animation.LerpedFloat;
public class CameraDistanceModifier {
private static final LerpedFloat multiplier = LerpedFloat.linear().startWithValue(1);
public static float getMultiplier(float partialTicks) {
return multiplier.getValue(partialTicks);
}
public static void tick() {
multiplier.tickChaser();
}
public static void reset() {
multiplier.chase(1, 0.1, LerpedFloat.Chaser.EXP);
}
public static void zoomOut() {
zoomOut(AllConfigs.CLIENT.mountedZoomMultiplier.getF());
}
public static void zoomOut(float targetMultiplier) {
multiplier.chase(targetMultiplier, 0.075, LerpedFloat.Chaser.EXP);
}
}

View file

@ -35,6 +35,8 @@ import com.simibubi.create.content.logistics.block.depot.EjectorTargetHandler;
import com.simibubi.create.content.logistics.block.display.DisplayLinkBlockItem;
import com.simibubi.create.content.logistics.block.mechanicalArm.ArmInteractionPointHandler;
import com.simibubi.create.content.logistics.item.LinkedControllerClientHandler;
import com.simibubi.create.content.logistics.trains.CameraDistanceModifier;
import com.simibubi.create.content.logistics.trains.entity.CarriageContraptionEntity;
import com.simibubi.create.content.logistics.trains.entity.CarriageCouplingRenderer;
import com.simibubi.create.content.logistics.trains.entity.TrainRelocator;
import com.simibubi.create.content.logistics.trains.management.edgePoint.TrackTargetingClient;
@ -89,6 +91,7 @@ import net.minecraftforge.client.event.RenderTooltipEvent;
import net.minecraftforge.event.TickEvent.ClientTickEvent;
import net.minecraftforge.event.TickEvent.Phase;
import net.minecraftforge.event.TickEvent.RenderTickEvent;
import net.minecraftforge.event.entity.EntityMountEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.world.WorldEvent;
@ -165,6 +168,7 @@ public class ClientEvents {
TrainRelocator.clientTick();
DisplayLinkBlockItem.clientTick();
CurvedTrackInteraction.clientTick();
CameraDistanceModifier.tick();
}
@SubscribeEvent
@ -275,6 +279,23 @@ public class ClientEvents {
TurntableHandler.gameRenderTick();
}
@SubscribeEvent
public static void onMount(EntityMountEvent event) {
if (event.getEntityMounting() != Minecraft.getInstance().player)
return;
if (event.isDismounting()) {
CameraDistanceModifier.reset();
return;
}
if (!event.isMounting() || !(event.getEntityBeingMounted() instanceof CarriageContraptionEntity carriage)) {
return;
}
CameraDistanceModifier.zoomOut();
}
protected static boolean isGameActive() {
return !(Minecraft.getInstance().level == null || Minecraft.getInstance().player == null);
}

View file

@ -55,6 +55,7 @@ public class AllCommands {
return Commands.literal("util")
.then(ReplaceInCommandBlocksCommand.register())
.then(ClearBufferCacheCommand.register())
.then(CameraDistanceCommand.register())
.then(FlySpeedCommand.register())
//.then(KillTPSCommand.register())
.build();

View file

@ -0,0 +1,41 @@
package com.simibubi.create.foundation.command;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.arguments.FloatArgumentType;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.simibubi.create.foundation.networking.AllPackets;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.network.PacketDistributor;
public class CameraDistanceCommand {
public static ArgumentBuilder<CommandSourceStack, ?> register() {
return Commands.literal("camera")
.then(Commands.literal("reset")
.executes(ctx -> {
ServerPlayer player = ctx.getSource().getPlayerOrException();
AllPackets.channel.send(
PacketDistributor.PLAYER.with(() -> player),
new SConfigureConfigPacket(SConfigureConfigPacket.Actions.zoomMultiplier.name(), "1")
);
return Command.SINGLE_SUCCESS;
})
).then(Commands.argument("multiplier", FloatArgumentType.floatArg(0))
.executes(ctx -> {
float multiplier = FloatArgumentType.getFloat(ctx, "multiplier");
ServerPlayer player = ctx.getSource().getPlayerOrException();
AllPackets.channel.send(
PacketDistributor.PLAYER.with(() -> player),
new SConfigureConfigPacket(SConfigureConfigPacket.Actions.zoomMultiplier.name(), String.valueOf(multiplier))
);
return Command.SINGLE_SUCCESS;
})
);
}
}

View file

@ -28,7 +28,6 @@ public class HighlightCommand {
public static ArgumentBuilder<CommandSourceStack, ?> register() {
return Commands.literal("highlight")
.requires(cs -> cs.hasPermission(2))
.then(Commands.argument("pos", BlockPosArgument.blockPos())
.then(Commands.argument("players", EntityArgument.players())
.executes(ctx -> {

View file

@ -7,6 +7,7 @@ import org.apache.logging.log4j.LogManager;
import com.simibubi.create.Create;
import com.simibubi.create.content.contraptions.goggles.GoggleConfigScreen;
import com.simibubi.create.content.logistics.trains.CameraDistanceModifier;
import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.config.ui.BaseConfigScreen;
import com.simibubi.create.foundation.config.ui.ConfigHelper;
@ -113,7 +114,8 @@ public class SConfigureConfigPacket extends SimplePacketBase {
fixLighting(() -> Actions::experimentalLighting),
overlayReset(() -> Actions::overlayReset),
openPonder(() -> Actions::openPonder),
fabulousWarning(() -> Actions::fabulousWarning)
fabulousWarning(() -> Actions::fabulousWarning),
zoomMultiplier(() -> Actions::zoomMultiplier)
;
@ -212,6 +214,19 @@ public class SConfigureConfigPacket extends SimplePacketBase {
Minecraft.getInstance().player.getUUID());
}
@OnlyIn(Dist.CLIENT)
private static void zoomMultiplier(String value) {
try {
float v = Float.parseFloat(value);
if (v <= 0)
return;
CameraDistanceModifier.zoomOut(v);
} catch (NumberFormatException ignored) {
Create.LOGGER.debug("Received non-float value {} in zoom packet, ignoring", value);
}
}
private static MutableComponent boolToText(boolean b) {
return b ? new TextComponent("enabled").withStyle(ChatFormatting.DARK_GREEN)
: new TextComponent("disabled").withStyle(ChatFormatting.RED);

View file

@ -73,6 +73,10 @@ public class CClient extends ConfigBase {
public final ConfigFloat ambientVolumeCap = f(.1f, 0, 1, "ambientVolumeCap",
Comments.ambientVolumeCap);
//train group
public final ConfigGroup trains = group(1, "trains");
public final ConfigFloat mountedZoomMultiplier = f(3, 0, "mountedZoomMultiplier", Comments.mountedZoomMultiplier);
@Override
public String getName() {
return "client";
@ -138,6 +142,9 @@ public class CClient extends ConfigBase {
static String sound = "Sound settings";
static String enableAmbientSounds = "Make cogs rumble and machines clatter.";
static String ambientVolumeCap = "Maximum volume modifier of Ambient noise";
static String trains = "Railway related settings";
static String mountedZoomMultiplier = "How far away the Camera should zoom when seated on a train";
}
}

View file

@ -0,0 +1,40 @@
package com.simibubi.create.foundation.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.simibubi.create.content.logistics.trains.CameraDistanceModifier;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
import net.minecraft.client.Camera;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.BlockGetter;
@Mixin(Camera.class)
public abstract class CameraMixin {
@Shadow
private double getMaxZoom(double pStartingDistance) {
throw new AssertionError();
}
@Shadow
protected void move(double pDistanceOffset, double pVerticalOffset, double pHorizontalOffset) {
throw new AssertionError();
}
@Inject(
method = "Lnet/minecraft/client/Camera;setup(Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/world/entity/Entity;ZZF)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;move(DDD)V", ordinal = 0),
cancellable = true
)
public void modifySetup(BlockGetter pLevel, Entity pEntity, boolean pDetached, boolean pThirdPersonReverse, float pPartialTick, CallbackInfo ci) {
move(-this.getMaxZoom(4.0D * CameraDistanceModifier.getMultiplier(AnimationTickHolder.getPartialTicks())), 0, 0);
ci.cancel();
}
}

View file

@ -14,6 +14,7 @@
"accessor.ServerLevelAccessor"
],
"client": [
"CameraMixin",
"DestroyProgressMixin",
"EntityContraptionInteractionMixin",
"FixNormalScalingMixin",