mirror of
https://github.com/darksaid98/Flashback.git
synced 2026-12-01 14:38:50 +00:00
Implement entity audio source switching
This commit is contained in:
1 parent
b8b22db8ee
commit
d9de587543
9 files changed
+163
-46
No files matched your search
@@ -5,6 +5,7 @@ import com.mojang.blaze3d.platform.TextureUtil;
|
||||
import com.mojang.blaze3d.platform.Window;
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import com.moulberry.flashback.editor.ui.windows.ExportQueueWindow;
|
||||
import com.moulberry.flashback.editor.ui.windows.SelectedEntityPopup;
|
||||
import com.moulberry.flashback.state.EditorState;
|
||||
import com.moulberry.flashback.state.EditorStateManager;
|
||||
import com.moulberry.flashback.combo_options.Sizing;
|
||||
@@ -86,7 +87,7 @@ public class ReplayUI {
|
||||
private static String infoOverlayText = null;
|
||||
private static long infoOverlayEndMillis = 0;
|
||||
|
||||
private static int selectedEntity = Integer.MIN_VALUE;
|
||||
private static UUID selectedEntity = null;
|
||||
private static boolean openSelectedEntityPopup = false;
|
||||
|
||||
public static void init() {
|
||||
@@ -303,8 +304,8 @@ public class ReplayUI {
|
||||
return getMouseLookVectorFromForwards(getMouseForwardsVector());
|
||||
}
|
||||
|
||||
public static boolean isEntitySelected(int entityId) {
|
||||
return isActive() && selectedEntity == entityId;
|
||||
public static boolean isEntitySelected(UUID uuid) {
|
||||
return isActive() && uuid.equals(selectedEntity);
|
||||
}
|
||||
|
||||
public static boolean isMovingCamera() {
|
||||
@@ -636,56 +637,26 @@ public class ReplayUI {
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedEntity != Integer.MIN_VALUE) {
|
||||
Entity entity = Minecraft.getInstance().level.getEntity(selectedEntity);
|
||||
if (selectedEntity != null) {
|
||||
Entity entity = Minecraft.getInstance().level.getEntities().get(selectedEntity);
|
||||
if (entity == null) {
|
||||
selectedEntity = Integer.MIN_VALUE;
|
||||
selectedEntity = null;
|
||||
} else if (entity instanceof Player && editorState != null && !editorState.replayVisuals.renderPlayers) {
|
||||
selectedEntity = Integer.MIN_VALUE;
|
||||
selectedEntity = null;
|
||||
} else if (!(entity instanceof Player) && editorState != null && !editorState.replayVisuals.renderEntities) {
|
||||
selectedEntity = Integer.MIN_VALUE;
|
||||
selectedEntity = null;
|
||||
} else {
|
||||
if (openSelectedEntityPopup) {
|
||||
ImGui.openPopup("###EntityPopup");
|
||||
}
|
||||
|
||||
if (ImGuiHelper.beginPopup("###EntityPopup")) {
|
||||
ImGui.text("Entity: " + entity.getUUID());
|
||||
|
||||
ImGui.separator();
|
||||
|
||||
if (ImGui.button("Look At")) {
|
||||
Minecraft.getInstance().cameraEntity.lookAt(EntityAnchorArgument.Anchor.EYES, entity.getEyePosition());
|
||||
}
|
||||
if (ImGui.button("Spectate")) {
|
||||
Minecraft.getInstance().player.connection.sendUnsignedCommand("spectate " + entity.getUUID());
|
||||
ImGui.closeCurrentPopup();
|
||||
}
|
||||
// ImGui.sameLine();
|
||||
// ImGui.button("Track Entity");
|
||||
//
|
||||
// ImGui.checkbox("Hide During Export", false);
|
||||
//
|
||||
// ImGui.checkbox("Force Glowing", false);
|
||||
// ImGui.sameLine();
|
||||
// ImGui.colorButton("Glow Colour", new float[4]);
|
||||
// ImGui.sameLine();
|
||||
// ImGui.text("Glow Colour");
|
||||
//
|
||||
// if (entity instanceof LivingEntity) {
|
||||
// ImGui.checkbox("Show Nametag", true);
|
||||
// ImGui.checkbox("Override Nametag", false);
|
||||
// }
|
||||
// if (entity instanceof Player) {
|
||||
// ImGui.checkbox("Override Skin", false);
|
||||
// }
|
||||
|
||||
|
||||
SelectedEntityPopup.render(entity, editorState);
|
||||
ImGui.endPopup();
|
||||
}
|
||||
|
||||
if (!ImGui.isPopupOpen("###EntityPopup")) {
|
||||
selectedEntity = Integer.MIN_VALUE;
|
||||
selectedEntity = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -761,7 +732,7 @@ public class ReplayUI {
|
||||
if (Minecraft.getInstance().player == Minecraft.getInstance().cameraEntity) {
|
||||
Minecraft.getInstance().player.setDeltaMovement(Vec3.ZERO);
|
||||
}
|
||||
selectedEntity = entityHitResult.getEntity().getId();
|
||||
selectedEntity = entityHitResult.getEntity().getUUID();
|
||||
openSelectedEntityPopup = true;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.moulberry.flashback.editor.ui.windows;
|
||||
|
||||
import com.moulberry.flashback.state.EditorState;
|
||||
import imgui.ImGui;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.commands.arguments.EntityAnchorArgument;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class SelectedEntityPopup {
|
||||
|
||||
public static void render(Entity entity, EditorState editorState) {
|
||||
UUID uuid = entity.getUUID();
|
||||
ImGui.text("Entity: " + uuid);
|
||||
|
||||
ImGui.separator();
|
||||
|
||||
if (ImGui.button("Look At")) {
|
||||
Minecraft.getInstance().cameraEntity.lookAt(EntityAnchorArgument.Anchor.EYES, entity.getEyePosition());
|
||||
}
|
||||
if (ImGui.button("Spectate")) {
|
||||
Minecraft.getInstance().player.connection.sendUnsignedCommand("spectate " + entity.getUUID());
|
||||
ImGui.closeCurrentPopup();
|
||||
}
|
||||
if (uuid.equals(editorState.audioSourceEntity)) {
|
||||
if (ImGui.button("Unset Audio Source")) {
|
||||
editorState.audioSourceEntity = null;
|
||||
editorState.markDirty();
|
||||
}
|
||||
} else if (ImGui.button("Set Audio Source")) {
|
||||
editorState.audioSourceEntity = entity.getUUID();
|
||||
editorState.markDirty();
|
||||
}
|
||||
|
||||
// ImGui.sameLine();
|
||||
// ImGui.button("Track Entity");
|
||||
//
|
||||
// ImGui.checkbox("Hide During Export", false);
|
||||
//
|
||||
// ImGui.checkbox("Force Glowing", false);
|
||||
// ImGui.sameLine();
|
||||
// ImGui.colorButton("Glow Colour", new float[4]);
|
||||
// ImGui.sameLine();
|
||||
// ImGui.text("Glow Colour");
|
||||
//
|
||||
// if (entity instanceof LivingEntity) {
|
||||
// ImGui.checkbox("Show Nametag", true);
|
||||
// ImGui.checkbox("Override Nametag", false);
|
||||
// }
|
||||
// if (entity instanceof Player) {
|
||||
// ImGui.checkbox("Override Skin", false);
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -160,6 +160,13 @@ public class StartExportWindow {
|
||||
audioCodec = newAudioCodec;
|
||||
}
|
||||
}
|
||||
|
||||
EditorState editorState = EditorStateManager.getCurrent();
|
||||
if (editorState != null && editorState.audioSourceEntity != null) {
|
||||
ImGui.text("Audio Source: \nEntity(" + editorState.audioSourceEntity + ")");
|
||||
} else {
|
||||
ImGui.text("Audio Source: Camera");
|
||||
}
|
||||
} else {
|
||||
recordAudio = false;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import it.unimi.dsi.fastutil.doubles.DoubleArrayList;
|
||||
import it.unimi.dsi.fastutil.doubles.DoubleList;
|
||||
import it.unimi.dsi.fastutil.floats.FloatArrayList;
|
||||
import it.unimi.dsi.fastutil.floats.FloatList;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.Screenshot;
|
||||
import net.minecraft.client.gui.Font;
|
||||
@@ -417,12 +418,31 @@ public class ExportJob {
|
||||
private void runClientTick() {
|
||||
this.tryUnfreezeClient();
|
||||
|
||||
while (Minecraft.getInstance().pollTask()) {}
|
||||
Minecraft.getInstance().tick();
|
||||
Minecraft.getInstance().getSoundManager().updateSource(Minecraft.getInstance().gameRenderer.getMainCamera());
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
|
||||
while (minecraft.pollTask()) {}
|
||||
minecraft.tick();
|
||||
this.updateSoundSound(minecraft);
|
||||
|
||||
this.tryUnfreezeClient();
|
||||
}
|
||||
|
||||
private void updateSoundSound(Minecraft minecraft) {
|
||||
EditorState editorState = EditorStateManager.getCurrent();
|
||||
if (editorState != null && editorState.audioSourceEntity != null && minecraft.level != null) {
|
||||
Entity sourceEntity = minecraft.level.getEntities().get(editorState.audioSourceEntity);
|
||||
if (sourceEntity != null) {
|
||||
Camera dummyCamera = new Camera();
|
||||
dummyCamera.eyeHeight = sourceEntity.getEyeHeight();
|
||||
dummyCamera.setup(minecraft.level, sourceEntity, false, false, 1.0f);
|
||||
minecraft.getSoundManager().updateSource(dummyCamera);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
minecraft.getSoundManager().updateSource(Minecraft.getInstance().gameRenderer.getMainCamera());
|
||||
}
|
||||
|
||||
private void tryUnfreezeClient() {
|
||||
ClientLevel level = Minecraft.getInstance().level;
|
||||
if (level != null) {
|
||||
|
||||
@@ -19,6 +19,7 @@ import it.unimi.dsi.fastutil.floats.FloatUnaryOperator;
|
||||
import net.minecraft.CrashReport;
|
||||
import net.minecraft.ReportedException;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.DeltaTracker;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.User;
|
||||
@@ -32,6 +33,7 @@ import net.minecraft.client.multiplayer.chat.report.ReportEnvironment;
|
||||
import net.minecraft.client.particle.ParticleEngine;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.client.server.IntegratedServer;
|
||||
import net.minecraft.client.sounds.SoundManager;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.protocol.login.ServerboundHelloPacket;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
@@ -158,6 +160,23 @@ public abstract class MixinMinecraft implements MinecraftExt {
|
||||
}
|
||||
}
|
||||
|
||||
@WrapOperation(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/sounds/SoundManager;updateSource(Lnet/minecraft/client/Camera;)V"))
|
||||
public void runTick_updateSource(SoundManager instance, Camera camera, Operation<Void> original) {
|
||||
EditorState editorState = EditorStateManager.getCurrent();
|
||||
if (editorState != null && editorState.audioSourceEntity != null && this.level != null) {
|
||||
Entity sourceEntity = this.level.getEntities().get(editorState.audioSourceEntity);
|
||||
if (sourceEntity != null) {
|
||||
Camera dummyCamera = new Camera();
|
||||
dummyCamera.eyeHeight = sourceEntity.getEyeHeight();
|
||||
dummyCamera.setup(this.level, sourceEntity, false, false, 1.0f);
|
||||
instance.updateSource(dummyCamera);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
original.call(instance, camera);
|
||||
}
|
||||
|
||||
@Inject(method = "runTick", at=@At(value = "INVOKE", target = "Lcom/mojang/blaze3d/pipeline/RenderTarget;blitToScreen(II)V", shift = At.Shift.AFTER))
|
||||
public void afterMainBlit(boolean bl, CallbackInfo ci) {
|
||||
if (!RenderSystem.isOnRenderThread()) return;
|
||||
|
||||
+10
-2
@@ -3,6 +3,7 @@ package com.moulberry.flashback.mixin.visuals;
|
||||
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import com.moulberry.flashback.state.EditorState;
|
||||
import com.moulberry.flashback.state.EditorStateManager;
|
||||
import com.moulberry.flashback.editor.ui.ReplayUI;
|
||||
@@ -27,8 +28,15 @@ public abstract class MixinEntityRenderDispatcher {
|
||||
// Add a yellow outline to selected entity
|
||||
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;popPose()V", shift = At.Shift.BEFORE))
|
||||
public void render(Entity entity, double d, double e, double f, float g, float h, PoseStack poseStack, MultiBufferSource multiBufferSource, int i, CallbackInfo ci) {
|
||||
if (ReplayUI.isEntitySelected(entity.getId())) {
|
||||
renderHitbox(poseStack, multiBufferSource.getBuffer(RenderType.lines()), entity, h, 1.0f, 1.0f, 0.0f);
|
||||
if (Flashback.isInReplay()) {
|
||||
if (ReplayUI.isEntitySelected(entity.getUUID())) {
|
||||
renderHitbox(poseStack, multiBufferSource.getBuffer(RenderType.lines()), entity, h, 1.0f, 1.0f, 0.0f);
|
||||
} else if (!Flashback.isExporting()) {
|
||||
EditorState editorState = EditorStateManager.getCurrent();
|
||||
if (editorState != null && entity.getUUID().equals(editorState.audioSourceEntity)) {
|
||||
renderHitbox(poseStack, multiBufferSource.getBuffer(RenderType.lines()), entity, h, 0.0f, 1.0f, 0.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,12 +49,15 @@ import net.minecraft.server.packs.repository.PackRepository;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
import net.minecraft.world.BossEvent;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.flag.FeatureFlagSet;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.WorldDataConfiguration;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.level.storage.LevelStorageSource;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -251,6 +254,36 @@ public class ReplayServer extends IntegratedServer {
|
||||
public void broadcastSystemMessage(Component component, Function<ServerPlayer, Component> function, boolean bl) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcast(@Nullable Player player, double x, double y, double z, double distance, ResourceKey<Level> resourceKey, Packet<?> packet) {
|
||||
UUID audioSourceEntity = null;
|
||||
|
||||
EditorState editorState = ReplayServer.this.getEditorState();
|
||||
if (editorState != null) {
|
||||
audioSourceEntity = editorState.audioSourceEntity;
|
||||
}
|
||||
|
||||
for (ReplayPlayer replayViewer : ReplayServer.this.replayViewers) {
|
||||
if (replayViewer != player && replayViewer.level().dimension() == resourceKey) {
|
||||
Vec3 source = replayViewer.position();
|
||||
|
||||
if (audioSourceEntity != null) {
|
||||
Entity entity = replayViewer.serverLevel().getEntity(audioSourceEntity);
|
||||
if (entity != null) {
|
||||
source = entity.position();
|
||||
}
|
||||
}
|
||||
|
||||
double dx = x - source.x;
|
||||
double dy = y - source.y;
|
||||
double dz = z - source.z;
|
||||
if (dx*dx + dy*dy + dz*dz < distance*distance) {
|
||||
replayViewer.connection.send(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendLevelInfo(ServerPlayer serverPlayer, ServerLevel serverLevel) {
|
||||
super.sendLevelInfo(serverPlayer, serverLevel);
|
||||
|
||||
@@ -30,6 +30,8 @@ public class EditorState {
|
||||
public int exportStartTicks = -1;
|
||||
public int exportEndTicks = -1;
|
||||
|
||||
public UUID audioSourceEntity = null;
|
||||
|
||||
public void setKeyframe(int trackIndex, int tick, Keyframe keyframe) {
|
||||
if (trackIndex >= this.keyframeTracks.size()) {
|
||||
return;
|
||||
|
||||
@@ -120,6 +120,7 @@ accessible field com/mojang/blaze3d/platform/Window height I
|
||||
|
||||
# Visuals
|
||||
accessible field net/minecraft/client/Camera eyeHeight F
|
||||
accessible method net/minecraft/client/multiplayer/ClientLevel getEntities ()Lnet/minecraft/world/level/entity/LevelEntityGetter;
|
||||
|
||||
# Exporting
|
||||
accessible field net/minecraft/client/Minecraft clientTickCount J
|
||||
|
||||
Reference in new issue
Block a user