Skip to content

Commit 709c511

Browse files
authored
Refactor PlaybackController (#200)
- Added new VirtualInput hooks to PlaybackController - Added PlaybackMetdata for an easier way to add metadata to the TASFile - Recreated existing metadata as PlaybackMetadataExtensions - [VirtualInput] Fixed issues with Interpolation not working properly - Fixed #185
2 parents a061286 + 12e039b commit 709c511

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1734
-649
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Setup Gradle
2020
uses: gradle/[email protected]
2121
with:
22-
gradle-version: 8.4
22+
gradle-version: 8.6
2323
- name: Build TASmod with Gradle
2424
run: gradle build
2525
- name: Upload Test Report

.github/workflows/buildandupload.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Setup Gradle
2121
uses: gradle/[email protected]
2222
with:
23-
gradle-version: 8.4
23+
gradle-version: 8.6
2424
- name: Build TASmod with Gradle
2525
run: gradle build
2626
- name: Upload artifact

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ org.gradle.jvmargs=-Xmx3G
33

44
# Fabric properties
55
minecraft_version=1.12.2
6-
loader_version=0.15.6
7-
loom_version=1.5-SNAPSHOT
6+
loader_version=0.15.9
7+
loom_version=1.6-SNAPSHOT
88

99
# Mod properties
1010
mod_name=Tool-Assisted Speedrun Mod

src/main/java/com/minecrafttas/mctcommon/events/EventListenerRegistry.java

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ public static void register(EventBase eventListener) {
107107
}
108108
}
109109

110+
/**
111+
* Registers multiple objects to be an event listener. The objects must
112+
* implement an event extending {@link EventBase}
113+
*
114+
* @param eventListeners The event listeners to register
115+
*/
116+
public static void register(EventBase... eventListeners) {
117+
for (EventBase eventListener : eventListeners) {
118+
register(eventListener);
119+
}
120+
}
121+
110122
/**
111123
* Unregisters an object from being an event listener.
112124
*
@@ -130,6 +142,17 @@ public static void unregister(EventBase eventListener) {
130142
}
131143
}
132144

145+
/**
146+
* Unregisters multiple objects from being an event listener.
147+
*
148+
* @param eventListener The event listeners to unregister
149+
*/
150+
public static void unregister(EventBase... eventListeners) {
151+
for (EventBase eventListener : eventListeners) {
152+
unregister(eventListener);
153+
}
154+
}
155+
133156
/**
134157
* Fires an event without parameters
135158
*
@@ -151,6 +174,7 @@ public static Object fireEvent(Class<? extends EventListenerRegistry.EventBase>
151174
public static Object fireEvent(Class<? extends EventListenerRegistry.EventBase> eventClass, Object... eventParams) {
152175
ArrayList<EventBase> listenerList = EVENTLISTENER_REGISTRY.get(eventClass);
153176
if (listenerList == null) {
177+
// throw new EventException("The event has not been registered yet", eventClass);
154178
return null;
155179
}
156180

@@ -250,12 +274,7 @@ private static boolean checkTypes(Method method, Object... parameters) {
250274
for (int i = 0; i < methodParameterTypes.length; i++) {
251275
Class<?> paramName = methodParameterTypes[i];
252276
Class<?> eventName = eventParameterTypes[i];
253-
254-
if (paramName == null || eventName == null) {
255-
continue;
256-
}
257-
258-
if (!paramName.equals(eventName) && !paramName.isAssignableFrom(eventName)) {
277+
if (!paramName.equals(eventName) && (paramName != null && eventName != null && !paramName.isAssignableFrom(eventName))) {
259278
return false;
260279
}
261280
}
@@ -265,7 +284,11 @@ private static boolean checkTypes(Method method, Object... parameters) {
265284
private static Class<?>[] getParameterTypes(Object... parameters) {
266285
Class<?>[] out = new Class[parameters.length];
267286
for (int i = 0; i < parameters.length; i++) {
268-
out[i] = parameters[i] == null ? null : parameters[i].getClass();
287+
if (parameters[i] == null) {
288+
out[i] = null;
289+
continue;
290+
}
291+
out[i] = parameters[i].getClass();
269292
}
270293
return out;
271294
}

src/main/java/com/minecrafttas/mctcommon/server/PacketHandlerRegistry.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ public class PacketHandlerRegistry {
1818
private static final List<PacketHandlerBase> REGISTRY = new ArrayList<>();
1919

2020
public static void register(PacketHandlerBase handler) {
21-
if(handler==null) {
21+
if (handler == null) {
2222
throw new NullPointerException("Tried to register a handler with value null");
2323
}
24-
25-
if(containsClass(handler)) {
24+
25+
if (containsClass(handler)) {
2626
MCTCommon.LOGGER.warn("Trying to register packet handler {}, but another instance of this class is already registered!", handler.getClass().getName());
2727
return;
2828
}
29-
29+
3030
if (!REGISTRY.contains(handler)) {
3131
REGISTRY.add(handler);
3232
} else {
@@ -35,13 +35,13 @@ public static void register(PacketHandlerBase handler) {
3535
}
3636

3737
public static void unregister(PacketHandlerBase handler) {
38-
if(handler==null) {
38+
if (handler == null) {
3939
throw new NullPointerException("Tried to unregister a handler with value null");
4040
}
4141
if (REGISTRY.contains(handler)) {
4242
REGISTRY.remove(handler);
4343
} else {
44-
MCTCommon.LOGGER.warn("Trying to unregister packet handler {}, but is was not registered!", handler.getClass().getName());
44+
MCTCommon.LOGGER.warn("Trying to unregister packet handler {}, but it was not registered!", handler.getClass().getName());
4545
}
4646
}
4747

@@ -65,14 +65,14 @@ public static void handle(Side side, PacketID packet, ByteBuffer buf, String use
6565
}
6666
}
6767
}
68-
if(!isImplemented) {
68+
if (!isImplemented) {
6969
throw new PacketNotImplementedException(packet, side);
7070
}
7171
}
72-
72+
7373
private static boolean containsClass(PacketHandlerBase handler) {
74-
for(PacketHandlerBase packethandler : REGISTRY) {
75-
if(packethandler.getClass().equals(handler.getClass())) {
74+
for (PacketHandlerBase packethandler : REGISTRY) {
75+
if (packethandler.getClass().equals(handler.getClass())) {
7676
return true;
7777
}
7878
}

src/main/java/com/minecrafttas/tasmod/TASmod.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.minecrafttas.tasmod.ktrng.KillTheRNGHandler;
2828
import com.minecrafttas.tasmod.networking.TASmodPackets;
2929
import com.minecrafttas.tasmod.playback.PlaybackControllerServer;
30+
import com.minecrafttas.tasmod.playback.metadata.integrated.StartpositionMetadataExtension;
3031
import com.minecrafttas.tasmod.savestates.SavestateHandlerServer;
3132
import com.minecrafttas.tasmod.savestates.files.SavestateTrackerFile;
3233
import com.minecrafttas.tasmod.tickratechanger.TickrateChangerServer;
@@ -68,6 +69,8 @@ public class TASmod implements ModInitializer, EventServerInit, EventServerStop{
6869

6970
public static final boolean isDevEnvironment = FabricLoaderImpl.INSTANCE.isDevelopmentEnvironment();
7071

72+
public static final StartpositionMetadataExtension startPositionMetadataExtension = new StartpositionMetadataExtension();
73+
7174
@Override
7275
public void onInitialize() {
7376

@@ -96,6 +99,7 @@ public void onInitialize() {
9699
PacketHandlerRegistry.register(tickratechanger);
97100
PacketHandlerRegistry.register(ktrngHandler);
98101
PacketHandlerRegistry.register(playbackControllerServer);
102+
PacketHandlerRegistry.register(startPositionMetadataExtension);
99103
}
100104

101105
@Override

src/main/java/com/minecrafttas/tasmod/TASmodClient.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
import com.minecrafttas.tasmod.networking.TASmodPackets;
2929
import com.minecrafttas.tasmod.playback.PlaybackControllerClient;
3030
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate;
31-
import com.minecrafttas.tasmod.playback.PlaybackSerialiser;
31+
import com.minecrafttas.tasmod.playback.metadata.PlaybackMetadataRegistry;
32+
import com.minecrafttas.tasmod.playback.metadata.integrated.CreditsMetadataExtension;
33+
import com.minecrafttas.tasmod.playback.metadata.integrated.StartpositionMetadataExtension;
34+
import com.minecrafttas.tasmod.playback.tasfile.PlaybackSerialiser;
3235
import com.minecrafttas.tasmod.savestates.SavestateHandlerClient;
3336
import com.minecrafttas.tasmod.tickratechanger.TickrateChangerClient;
3437
import com.minecrafttas.tasmod.ticksync.TickSyncClient;
@@ -85,6 +88,10 @@ public class TASmodClient implements ClientModInitializer, EventClientInit, Even
8588
public static SavestateHandlerClient savestateHandlerClient = new SavestateHandlerClient();
8689

8790
public static Client client;
91+
92+
public static CreditsMetadataExtension creditsMetadataExtension = new CreditsMetadataExtension();
93+
94+
public static StartpositionMetadataExtension startpositionMetadataExtension = new StartpositionMetadataExtension();
8895
/**
8996
* The container where all inputs get stored during recording or stored and
9097
* ready to be played back
@@ -153,6 +160,12 @@ public void onInitializeClient() {
153160
}
154161
return gui;
155162
}));
163+
EventListenerRegistry.register(controller);
164+
PlaybackMetadataRegistry.register(creditsMetadataExtension);
165+
EventListenerRegistry.register(creditsMetadataExtension);
166+
167+
PlaybackMetadataRegistry.register(startpositionMetadataExtension);
168+
EventListenerRegistry.register(startpositionMetadataExtension);
156169

157170
// Register packet handlers
158171
LOGGER.info(LoggerMarkers.Networking, "Registering network handlers on client");
@@ -195,14 +208,15 @@ public void onClientInit(Minecraft mc) {
195208
})));
196209
blockedKeybindings.add(keybindManager.registerKeybind(new Keybind("Open InfoGui Editor", "TASmod", Keyboard.KEY_F6, () -> Minecraft.getMinecraft().displayGuiScreen(TASmodClient.hud))));
197210
blockedKeybindings.add(keybindManager.registerKeybind(new Keybind("Various Testing", "TASmod", Keyboard.KEY_F12, () -> {
198-
TASmodClient.client.disconnect();
211+
controller.setTASState(TASstate.RECORDING);
199212
}, VirtualKeybindings::isKeyDown)));
200213
blockedKeybindings.add(keybindManager.registerKeybind(new Keybind("Various Testing2", "TASmod", Keyboard.KEY_F7, () -> {
201-
try {
202-
TASmodClient.client = new Client("localhost", TASmod.networkingport-1, TASmodPackets.values(), mc.getSession().getProfile().getName(), true);
203-
} catch (Exception e) {
204-
e.printStackTrace();
205-
}
214+
// try {
215+
// TASmodClient.client = new Client("localhost", TASmod.networkingport-1, TASmodPackets.values(), mc.getSession().getProfile().getName(), true);
216+
// } catch (Exception e) {
217+
// e.printStackTrace();
218+
// }
219+
controller.setTASState(TASstate.PLAYBACK);
206220
}, VirtualKeybindings::isKeyDown)));
207221
blockedKeybindings.forEach(VirtualKeybindings::registerBlockedKeyBinding);
208222

src/main/java/com/minecrafttas/tasmod/commands/CommandLoadTAS.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public String getUsage(ICommandSender sender) {
3333

3434
@Override
3535
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
36+
sender.sendMessage(new TextComponentString(TextFormatting.RED + "This feature does not work at the moment!"));
3637
if (sender instanceof EntityPlayer) {
3738
if (sender.canUseCommand(2, "load")) {
3839
if (args.length < 1) {

src/main/java/com/minecrafttas/tasmod/commands/CommandPlay.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public List<String> getAliases() {
3838

3939
@Override
4040
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
41-
sender.sendMessage(new TextComponentString(TextFormatting.RED + "This feature doesn't work at the moment!"));
4241
if (!(sender instanceof EntityPlayer)) {
4342
return;
4443
}

src/main/java/com/minecrafttas/tasmod/commands/CommandRecord.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public List<String> getAliases() {
3838

3939
@Override
4040
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
41-
sender.sendMessage(new TextComponentString(TextFormatting.RED + "This feature doesn't work at the moment!"));
4241
if (!(sender instanceof EntityPlayer)) {
4342
return;
4443
}

0 commit comments

Comments
 (0)