Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/com/minecrafttas/tasmod/TASmod.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.minecrafttas.tasmod.commands.CommandSavestate;
import com.minecrafttas.tasmod.commands.CommandTickrate;
import com.minecrafttas.tasmod.commands.TabCompletionUtils;
import com.minecrafttas.tasmod.handlers.PlayUntilHandler;
import com.minecrafttas.tasmod.playback.PlaybackControllerServer;
import com.minecrafttas.tasmod.playback.metadata.builtin.StartpositionMetadataExtension;
import com.minecrafttas.tasmod.registries.TASmodPackets;
Expand Down Expand Up @@ -78,6 +79,8 @@ public class TASmod implements ModInitializer, EventServerInit, EventServerStop

public static final CommandFileCommand commandFileCommand = new CommandFileCommand();

public static final PlayUntilHandler playUntil = new PlayUntilHandler();

@Override
public void onInitialize() {

Expand Down Expand Up @@ -117,6 +120,8 @@ public void onInitialize() {
SavestateMotionStorage motionStorage = new SavestateMotionStorage();
PacketHandlerRegistry.register(motionStorage);
EventListenerRegistry.register(motionStorage);
PacketHandlerRegistry.register(playUntil);
EventListenerRegistry.register(playUntil);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.text.TextComponentString;

public class CommandPlayUntil extends CommandBase{
public class CommandPlayUntil extends CommandBase {

@Override
public String getName() {
Expand All @@ -24,7 +24,7 @@ public String getUsage(ICommandSender sender) {

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if(args.length==1) {
if (args.length == 1) {
int i = 0;
try {
i = Integer.parseInt(args[0]);
Expand All @@ -36,10 +36,8 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args
} catch (Exception e) {
e.printStackTrace();
}
}
else {
} else {
sender.sendMessage(new TextComponentString("Stops the next playback one tick before the specified tick and lets you record from there:\n\n/playuntil 10, runs the playback until tick 9 and will record from there. Useful when you can't savestate"));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.minecrafttas.mctcommon.events.EventListenerRegistry.EventBase;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.InputContainer;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate;

public interface EventPlaybackClient {

Expand Down Expand Up @@ -65,10 +65,10 @@ public interface EventRecordTick extends EventBase {
public interface EventPlaybackTick extends EventBase {

/**
* Fired when a tick is being recorded
* Fired when a tick is played back
*
* @param index The index of the tick that is being recorded
* @param container The {@link InputContainer} that is being recorded
* @param index The index of the tick that is played back
* @param container The {@link InputContainer} that is played back
*/
public void onPlaybackTick(long index, InputContainer container);
}
Expand All @@ -84,4 +84,33 @@ public interface EventRecordClear extends EventBase {
*/
public void onRecordingClear();
}

/**
* Fired when an input is deleted
*/
@FunctionalInterface
public interface EventInputDelete extends EventBase {

/**
* Fired when an input is deleted
*
* @param The index of the input
*/
public void onInputDelete(long index);
}

/**
* Fired when a tick is being played back before reading the inputs
*/
@FunctionalInterface
public interface EventPlaybackTickPre extends EventBase {

/**
* Fired when a tick is being played back before reading the inputs
*
* @param index The index of the tick that is played back
* @param container The {@link InputContainer} that is played back
*/
public void onPlaybackTickPre(long index);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.minecrafttas.tasmod.handlers;

import java.nio.ByteBuffer;

import com.minecrafttas.mctcommon.networking.ByteBufferBuilder;
import com.minecrafttas.mctcommon.networking.Client.Side;
import com.minecrafttas.mctcommon.networking.exception.PacketNotImplementedException;
import com.minecrafttas.mctcommon.networking.exception.WrongSideException;
import com.minecrafttas.mctcommon.networking.interfaces.ClientPacketHandler;
import com.minecrafttas.mctcommon.networking.interfaces.PacketID;
import com.minecrafttas.mctcommon.networking.interfaces.ServerPacketHandler;
import com.minecrafttas.tasmod.TASmod;
import com.minecrafttas.tasmod.TASmodClient;
import com.minecrafttas.tasmod.events.EventPlaybackClient;
import com.minecrafttas.tasmod.networking.TASmodBufferBuilder;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate;
import com.minecrafttas.tasmod.registries.TASmodPackets;

/**
* Feature for starting a recording after playing back a certain number of ticks
*
* @author Scribble
*/
public class PlayUntilHandler implements ClientPacketHandler, ServerPacketHandler, EventPlaybackClient.EventPlaybackTickPre {

/**
* If not null, play until a certain point
*/
private Integer playUntil = null;

@Override
public void onPlaybackTickPre(long index) {
/* Playuntil logic */
if (playUntil != null && playUntil == index) {
TASmodClient.tickratechanger.pauseGame(true);
PlaybackControllerClient controller = TASmodClient.controller;
controller.setTASState(TASstate.NONE);
controller.setIndex(controller.index() - 1);
for (long i = controller.size() - 1; i >= index; i--) {
controller.remove(i);
}
controller.setTASState(TASstate.RECORDING);
playUntil = null;
}
}

public boolean isActive() {
return playUntil != null;
}

public void setPlayUntil(int until) {
this.playUntil = until;
}

@Override
public PacketID[] getAcceptedPacketIDs() {
return new TASmodPackets[] { TASmodPackets.PLAYBACK_PLAYUNTIL };
}

@Override
public void onClientPacket(PacketID id, ByteBuffer buf, String username) throws PacketNotImplementedException, WrongSideException, Exception {
TASmodPackets packet = (TASmodPackets) id;

switch (packet) {
case PLAYBACK_PLAYUNTIL:
int until = ByteBufferBuilder.readInt(buf);
setPlayUntil(until);
break;
default:
throw new PacketNotImplementedException(packet, this.getClass(), Side.SERVER);
}
}

@Override
public void onServerPacket(PacketID id, ByteBuffer buf, String username) throws PacketNotImplementedException, WrongSideException, Exception {
TASmodPackets packet = (TASmodPackets) id;

switch (packet) {
case PLAYBACK_PLAYUNTIL:
TASmod.server.sendToAll(new TASmodBufferBuilder(buf));
break;
default:
throw new PacketNotImplementedException(packet, this.getClass(), Side.SERVER);
}
}
}
Loading