Skip to content

Commit

Permalink
[PlaybackController] Fixed TASfile not being applied to the controller
Browse files Browse the repository at this point in the history
- [PlaybackSerialiser] Added support for null values in Camera Angle
  • Loading branch information
ScribbleTAS committed Jun 30, 2024
1 parent be1dcc1 commit 3f92474
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 20 deletions.
1 change: 0 additions & 1 deletion src/main/java/com/minecrafttas/tasmod/TASmodClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ private void registerNetworkPacketHandlers() {

private void registerEventListeners() {
EventListenerRegistry.register(this);
// EventListenerRegistry.register(virtual); TODO Remove if unnecessary
EventListenerRegistry.register(hud);
EventListenerRegistry.register(shieldDownloader);
EventListenerRegistry.register(loadingScreenHandler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class MixinEntityRenderer implements SubtickDuck {

/**
* Injects into the vanilla camera updating cycle, runs every frame.
* Updates {@link com.minecrafttas.tasmod.virtual.VirtualInput.VirtualCameraAngleInput#nextCameraAngle}
* Updates {@link com.minecrafttas.tasmod.virtual.VirtualInput.VirtualCameraAngleInput#nextCameraAngle VirtualCameraAngleInput#nextCameraAngle}
* @param partialTicks The partial ticks of the timer, unused
* @param nanoTime The nanoTime, unused
* @param ci CBI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import com.minecrafttas.tasmod.util.Scheduler.Task;
import com.minecrafttas.tasmod.virtual.VirtualCameraAngle;
import com.minecrafttas.tasmod.virtual.VirtualInput;
import com.minecrafttas.tasmod.virtual.VirtualInput.VirtualCameraAngleInput;
import com.minecrafttas.tasmod.virtual.VirtualKeyboard;
import com.minecrafttas.tasmod.virtual.VirtualMouse;

Expand Down Expand Up @@ -239,7 +240,12 @@ public String setTASStateClient(TASstate stateIn, boolean verbose) {

private void startRecording() {
LOGGER.debug(LoggerMarkers.Playback, "Starting recording");
if (this.inputs.isEmpty()) {
if(this.inputs.isEmpty()) {
VirtualCameraAngleInput CAMERA_ANGLE = TASmodClient.virtual.CAMERA_ANGLE;
Float pitch = CAMERA_ANGLE.getCurrentPitch();
Float yaw = CAMERA_ANGLE.getCurrentYaw();
this.camera.set(pitch, yaw);

inputs.add(new TickContainer());
}
}
Expand Down Expand Up @@ -462,12 +468,7 @@ public BigArrayList<TickContainer> getInputs() {
}

public void setInputs(BigArrayList<TickContainer> inputs) {
try {
inputs.clearMemory();
} catch (IOException e) {
e.printStackTrace();
}
inputs = new BigArrayList<TickContainer>(directory + File.separator + "temp");
clear();
SerialiserFlavorBase.addAll(this.inputs, inputs);
}

Expand Down Expand Up @@ -503,14 +504,15 @@ public TickContainer get() {
}

public void clear() {
LOGGER.debug(LoggerMarkers.Playback, "Clearing playback controller");
LOGGER.info(LoggerMarkers.Playback, "Clearing playback controller");
EventListenerRegistry.fireEvent(EventPlaybackClient.EventRecordClear.class);
try {
inputs.clearMemory();
} catch (IOException e) {
e.printStackTrace();
}
inputs = new BigArrayList<TickContainer>(directory + File.separator + "temp");
index = 0;
}

/**
Expand Down Expand Up @@ -575,9 +577,7 @@ public TickContainer(VirtualKeyboard keyboard, VirtualMouse mouse, VirtualCamera
}

public TickContainer() {
this.keyboard = new VirtualKeyboard();
this.mouse = new VirtualMouse();
this.cameraAngle = new VirtualCameraAngle();
this(new VirtualKeyboard(), new VirtualMouse(), new VirtualCameraAngle());
}

@Override
Expand Down Expand Up @@ -792,7 +792,7 @@ public void onClientPacket(PacketID id, ByteBuffer buf, String username) throws
flavor = TASmodBufferBuilder.readString(buf);

try {
PlaybackSerialiser2.loadFromFile(new File(directory, name + ".mctas"), flavor);
TASmodClient.controller.setInputs(PlaybackSerialiser2.loadFromFile(new File(directory, name + ".mctas"), flavor));
} catch (PlaybackLoadException e) {
if (mc.world != null)
mc.ingameGUI.getChatGUI().printChatMessage(new TextComponentString(TextFormatting.RED + e.getMessage()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,9 +719,15 @@ protected VirtualCameraAngle deserialiseCameraAngle(List<String> cameraAngleStri
if (matcher.find()) {
String cameraPitchString = matcher.group(1);
String cameraYawString = matcher.group(2);

float cameraPitch = deserialiseRelativeFloat("camera pitch", cameraPitchString, previousPitch);
float cameraYaw = deserialiseRelativeFloat("camera yaw", cameraYawString, previousYaw);

Float cameraPitch = null;
Float cameraYaw = null;

if(!"null".equals(cameraPitchString))
cameraPitch = deserialiseRelativeFloat("camera pitch", cameraPitchString, previousPitch);

if(!"null".equals(cameraYawString))
cameraYaw = deserialiseRelativeFloat("camera yaw", cameraYawString, previousYaw);

out.updateFromState(cameraPitch, cameraYaw);
}
Expand Down Expand Up @@ -789,7 +795,11 @@ protected float parseFloat(String name, String floatstring) {
}
}

protected float deserialiseRelativeFloat(String name, String floatstring, Float previous) {
protected Float deserialiseRelativeFloat(String name, String floatstring, Float previous) {
if(floatstring == null) {
return null;
}

float out = 0;
if (floatstring.startsWith("~")) {
floatstring = floatstring.replace("~", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,14 @@ public void updateFromEvent(float pitchDelta, float yawDelta, boolean updateSubt
this.yaw += yawDelta;
}

public void updateFromState(float pitch, float yaw) {
public void updateFromState(Float pitch, Float yaw) {
if(this.pitch!=null && this.yaw != null) {
createSubtick(true);
}
this.pitch = MathHelper.clamp(pitch, -90F, 90F);
if(pitch != null) {
pitch = MathHelper.clamp(pitch, -90F, 90F);
}
this.pitch = pitch;
this.yaw = yaw;
}

Expand Down

0 comments on commit 3f92474

Please sign in to comment.