Skip to content

Commit 39cf454

Browse files
committed
[PlayUntil] Moved to new event
1 parent 8294701 commit 39cf454

File tree

5 files changed

+47
-53
lines changed

5 files changed

+47
-53
lines changed

src/main/java/com/minecrafttas/tasmod/events/EventPlaybackClient.java

+18-3
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ public interface EventRecordTick extends EventBase {
6565
public interface EventPlaybackTick extends EventBase {
6666

6767
/**
68-
* Fired when a tick is being recorded
68+
* Fired when a tick is played back
6969
*
70-
* @param index The index of the tick that is being recorded
71-
* @param container The {@link InputContainer} that is being recorded
70+
* @param index The index of the tick that is played back
71+
* @param container The {@link InputContainer} that is played back
7272
*/
7373
public void onPlaybackTick(long index, InputContainer container);
7474
}
@@ -98,4 +98,19 @@ public interface EventInputDelete extends EventBase {
9898
*/
9999
public void onInputDelete(long index);
100100
}
101+
102+
/**
103+
* Fired when a tick is being played back before reading the inputs
104+
*/
105+
@FunctionalInterface
106+
public interface EventPlaybackTickPre extends EventBase {
107+
108+
/**
109+
* Fired when a tick is being played back before reading the inputs
110+
*
111+
* @param index The index of the tick that is played back
112+
* @param container The {@link InputContainer} that is played back
113+
*/
114+
public void onPlaybackTickPre(long index);
115+
}
101116
}

src/main/java/com/minecrafttas/tasmod/handlers/PlayUntilHandler.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import com.minecrafttas.tasmod.events.EventPlaybackClient;
1515
import com.minecrafttas.tasmod.networking.TASmodBufferBuilder;
1616
import com.minecrafttas.tasmod.playback.PlaybackControllerClient;
17-
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.InputContainer;
1817
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate;
1918
import com.minecrafttas.tasmod.registries.TASmodPackets;
2019

@@ -23,20 +22,19 @@
2322
*
2423
* @author Scribble
2524
*/
26-
public class PlayUntilHandler implements ClientPacketHandler, ServerPacketHandler, EventPlaybackClient.EventPlaybackTick {
25+
public class PlayUntilHandler implements ClientPacketHandler, ServerPacketHandler, EventPlaybackClient.EventPlaybackTickPre {
2726

2827
/**
2928
* If not null, play until a certain point
3029
*/
3130
private Integer playUntil = null;
3231

3332
@Override
34-
public void onPlaybackTick(long index, InputContainer container) {
33+
public void onPlaybackTickPre(long index) {
3534
/* Playuntil logic */
3635
if (playUntil != null && playUntil == index) {
3736
TASmodClient.tickratechanger.pauseGame(true);
3837
PlaybackControllerClient controller = TASmodClient.controller;
39-
controller.setDontClearOnStop(true);
4038
controller.setTASState(TASstate.NONE);
4139
controller.setIndex(controller.index() - 1);
4240
for (long i = controller.size() - 1; i >= index; i--) {

src/main/java/com/minecrafttas/tasmod/playback/PlaybackControllerClient.java

+5-24
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.minecrafttas.tasmod.events.EventPlaybackClient.EventControllerStateChange;
4343
import com.minecrafttas.tasmod.events.EventPlaybackClient.EventPlaybackJoinedWorld;
4444
import com.minecrafttas.tasmod.events.EventPlaybackClient.EventPlaybackTick;
45+
import com.minecrafttas.tasmod.events.EventPlaybackClient.EventPlaybackTickPre;
4546
import com.minecrafttas.tasmod.events.EventPlaybackClient.EventRecordTick;
4647
import com.minecrafttas.tasmod.events.EventVirtualInput;
4748
import com.minecrafttas.tasmod.networking.TASmodBufferBuilder;
@@ -141,12 +142,6 @@ public class PlaybackControllerClient implements
141142
*/
142143
private BigArrayList<InputContainer> inputs;
143144

144-
/**
145-
* If true, doesn't clear the virtual inputs<br>
146-
* when stopping a recording or playback
147-
*/
148-
private boolean dontZwonkel = false;
149-
150145
// private long startSeed = TASmod.ktrngHandler.getGlobalSeedClient(); // TODO Replace with Metadata extension
151146

152147
// =====================================================================================================
@@ -293,12 +288,7 @@ private void startRecording() {
293288

294289
private void stopRecording() {
295290
LOGGER.debug(LoggerMarkers.Playback, "Stopping a recording");
296-
297-
if (dontZwonkel)
298-
dontZwonkel = false;
299-
else {
300-
TASmodClient.virtual.clear();
301-
}
291+
TASmodClient.virtual.clear();
302292
}
303293

304294
private void startPlayback() {
@@ -311,11 +301,7 @@ private void startPlayback() {
311301
private void stopPlayback() {
312302
LOGGER.debug(LoggerMarkers.Playback, "Stopping a playback");
313303
Minecraft.getMinecraft().gameSettings.chatLinks = true;
314-
if (dontZwonkel)
315-
dontZwonkel = false;
316-
else {
317-
TASmodClient.virtual.clear();
318-
}
304+
TASmodClient.virtual.clear();
319305
}
320306

321307
/**
@@ -507,6 +493,8 @@ private void playbackNextTick() {
507493

508494
index++; // Increase the index and load the next inputs
509495

496+
EventListenerRegistry.fireEvent(EventPlaybackTickPre.class, index);
497+
510498
/* Stop condition */
511499
if (index == inputs.size() || inputs.isEmpty()) {
512500
index--;
@@ -631,13 +619,6 @@ public void unpressContainer() {
631619
mouse.clear();
632620
}
633621

634-
/**
635-
* @param dontClear {@link #dontZwonkel}
636-
*/
637-
public void setDontClearOnStop(boolean dontClear) {
638-
this.dontZwonkel = dontClear;
639-
}
640-
641622
// ==============================================================
642623

643624
/**

src/main/java/com/minecrafttas/tasmod/virtual/VirtualCameraAngle.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public String toString() {
216216
}
217217

218218
public String toString2() {
219-
return String.format("%s;%s", pitch, yaw);
219+
return String.format("%s;%s", yaw, pitch);
220220
}
221221

222222
/**

src/test/java/tasmod/virtual/VirtualCameraAngleTest.java

+21-21
Original file line numberDiff line numberDiff line change
@@ -118,26 +118,26 @@ void testGetStates() {
118118
test.updateFromEvent(1f, 1f);
119119
test.updateFromEvent(1f, 1f);
120120
test.updateFromEvent(1f, 1f);
121-
121+
122122
List<VirtualCameraAngle> actual = new ArrayList<>();
123-
123+
124124
// Test get states on a subtick, should result in an empty array
125125
VirtualCameraAngle test2 = new VirtualCameraAngle(0f, 0f);
126-
126+
127127
test2.getStates(actual);
128-
128+
129129
assertTrue(actual.isEmpty());
130-
130+
131131
actual.clear();
132-
132+
133133
test.getStates(actual);
134-
134+
135135
List<VirtualCameraAngle> expected = new ArrayList<>();
136-
136+
137137
expected.add(new VirtualCameraAngle(1f, 1f));
138138
expected.add(new VirtualCameraAngle(2f, 2f));
139139
expected.add(new VirtualCameraAngle(3f, 3f));
140-
140+
141141
assertIterableEquals(expected, actual);
142142
}
143143

@@ -149,26 +149,26 @@ void testCopyFrom() {
149149
VirtualCameraAngle expected = new VirtualCameraAngle(0f, 0f, true);
150150
expected.updateFromEvent(1f, 2f);
151151
expected.updateFromEvent(3f, 4f);
152-
152+
153153
VirtualCameraAngle actual = new VirtualCameraAngle(0f, 0f, true);
154-
154+
155155
actual.moveFrom(expected);
156-
156+
157157
// Test pitch and yaw
158158
assertEquals(expected.getPitch(), actual.getPitch());
159159
assertEquals(expected.getYaw(), actual.getYaw());
160-
160+
161161
// Test subticks
162162
List<VirtualCameraAngle> expected2 = new ArrayList<>();
163163
expected2.add(new VirtualCameraAngle(1f, 2f));
164164
expected2.add(new VirtualCameraAngle(4f, 6f));
165-
165+
166166
assertIterableEquals(expected2, actual.getAll());
167167
// Test expected subticks being cleared
168-
168+
169169
assertTrue(expected.getSubticks().isEmpty());
170170
}
171-
171+
172172
/**
173173
* Test clearing the camera angle
174174
*/
@@ -179,9 +179,9 @@ void testClear() {
179179
actual.updateFromEvent(1f, 1f);
180180
actual.updateFromEvent(1f, 1f);
181181
actual.updateFromEvent(1f, 1f);
182-
182+
183183
actual.clear();
184-
184+
185185
assertNull(actual.getPitch());
186186
assertNull(actual.getYaw());
187187
assertTrue(actual.getSubticks().isEmpty());
@@ -197,7 +197,7 @@ void testToString() {
197197

198198
VirtualCameraAngle actual = new VirtualCameraAngle(x, y);
199199

200-
assertEquals("1.0;2.0", actual.toString());
200+
assertEquals("2.0;1.0", actual.toString());
201201
}
202202

203203
/**
@@ -210,7 +210,7 @@ void testToStringSubticks() {
210210
actual.updateFromEvent(3f, 4f);
211211
actual.updateFromEvent(5f, 6f);
212212

213-
assertEquals("1.0;2.0\n4.0;6.0\n9.0;12.0", actual.toString());
213+
assertEquals("2.0;1.0\n6.0;4.0\n12.0;9.0", actual.toString());
214214
}
215215

216216
/**
@@ -228,7 +228,7 @@ void testShallowClone() {
228228
assertEquals(1f, actual.getPitch());
229229
assertEquals(2f, actual.getYaw());
230230
}
231-
231+
232232
// DeepCloning
233233

234234
/**

0 commit comments

Comments
 (0)