Skip to content

Commit 04f9469

Browse files
ScribbleScribble
authored andcommitted
Update to Alpha 8.1
- Control Bytes (@pancake) - Playback Interpolation (@pancake) - Fixes a softlock - Changing savestate loading behaviour - Bug Fixes
2 parents 9f2b6e3 + c1d747e commit 04f9469

24 files changed

+428
-120
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ apply plugin: 'org.spongepowered.mixin'
1919
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
2020

2121

22-
version = "Alpha8"
22+
version = "Alpha8.1"
2323
group = "de.scribble.lp.tastools" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
2424
archivesBaseName = "TASmod-1.12.2"
2525

src/main/java/de/pfannekuchen/infogui/gui/InfoHud.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
import com.mojang.realmsclient.gui.ChatFormatting;
1515

16+
import de.pfannekuchen.tasmod.controlbytes.ControlByteHandler;
17+
import de.pfannekuchen.tasmod.events.CameraInterpolationEvents;
1618
import de.pfannekuchen.tasmod.utils.PlayerPositionCalculator;
1719
import de.pfannekuchen.tasmod.utils.TrajectoriesCalculator;
1820
import de.scribble.lp.killtherng.KillTheRNG;
@@ -197,7 +199,6 @@ private void saveConfig() {
197199
*/
198200
public void tick() {
199201
if (checkInit()) return;
200-
for (InfoLabel label : lists) label.tick();
201202
}
202203

203204
public boolean checkInit() {
@@ -268,7 +269,7 @@ public boolean checkInit() {
268269
if (configuration.getProperty(title + "_x", "err").equals("err")) setDefaults(title, y);
269270
lists.add(new InfoLabel(title, Integer.parseInt(configuration.getProperty(title + "_x")), Integer.parseInt(configuration.getProperty(title + "_y")), Boolean.parseBoolean(configuration.getProperty(title + "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> {
270271
if (Minecraft.getMinecraft().currentScreen == this) return "Facing";
271-
return String.format("%.2f %.2f", Minecraft.getMinecraft().player.rotationYaw, Minecraft.getMinecraft().player.rotationPitch);
272+
return String.format("%.2f %.2f", CameraInterpolationEvents.rotationYaw, CameraInterpolationEvents.rotationPitch);
272273
}));
273274

274275
title = "cticks";
@@ -386,9 +387,16 @@ public boolean checkInit() {
386387
* Render the Info Hud only
387388
*/
388389
public void drawHud() {
390+
// render custom info box if control byte is set
391+
if (!ControlByteHandler.hideInfoBox && ClientProxy.virtual.getContainer().isPlayingback())
392+
drawRectWithText(ControlByteHandler.text, 10, 10, true);
393+
// skip rendering of control byte is set
394+
if (!ControlByteHandler.shouldRenderHud && ClientProxy.virtual.getContainer().isPlayingback())
395+
return;
389396
int xpos=40;
390397
int ypos=190;
391398
for (InfoLabel label : lists) {
399+
label.tick();
392400
if (label.visible) {
393401
drawRectWithText(label.renderText, label.x, label.y, label.renderRect);
394402
} else if (Minecraft.getMinecraft().currentScreen != null) {
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package de.pfannekuchen.tasmod.controlbytes;
2+
3+
/**
4+
* Handles playback control bytes
5+
* @author Pancake
6+
*/
7+
public class ControlByteHandler {
8+
9+
/**
10+
* Resets all control-byte-controlled settings
11+
*/
12+
public static void reset() {
13+
ControlByteHandler.shouldInterpolate = false;
14+
ControlByteHandler.shouldRenderHud = true;
15+
ControlByteHandler.text = "";
16+
ControlByteHandler.hideInfoBox = true;
17+
}
18+
19+
/**
20+
* Reacts to control bytes
21+
* @param command Control Command
22+
* @param args Arguments
23+
*/
24+
public static void onControlByte(String command, String[] args) {
25+
switch (command.toLowerCase()) {
26+
case "interpolation":
27+
interpolation(args);
28+
break;
29+
case "hud":
30+
hud(args);
31+
break;
32+
case "info":
33+
info(args);
34+
default:
35+
break;
36+
}
37+
}
38+
39+
private static void info(String[] args) {
40+
ControlByteHandler.hideInfoBox = "off".equals(args[0].trim()) || "false".equals(args[0].trim()) || "no".equals(args[0].trim()) || "0".equals(args[0].trim());
41+
// Parse array as text
42+
ControlByteHandler.text = "";
43+
for (String string : args) {
44+
ControlByteHandler.text += " " + string;
45+
}
46+
ControlByteHandler.text = ControlByteHandler.text.trim();
47+
}
48+
49+
public static void interpolation(String[] args) {
50+
ControlByteHandler.shouldInterpolate = "on".equals(args[0].trim()) || "true".equals(args[0].trim()) || "yes".equals(args[0].trim()) || "1".equals(args[0].trim());
51+
}
52+
53+
public static void hud(String[] args) {
54+
ControlByteHandler.shouldRenderHud = "on".equals(args[0].trim()) || "true".equals(args[0].trim()) || "yes".equals(args[0].trim()) || "1".equals(args[0].trim());
55+
}
56+
57+
public static boolean hideInfoBox = true;
58+
public static String text = "";
59+
public static boolean shouldInterpolate = false;
60+
public static boolean shouldRenderHud = true;
61+
62+
}
Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
11
package de.pfannekuchen.tasmod.events;
22

3+
import de.pfannekuchen.tasmod.controlbytes.ControlByteHandler;
4+
import de.scribble.lp.tasmod.ClientProxy;
5+
import de.scribble.lp.tasmod.inputcontainer.TickInputContainer;
6+
import de.scribble.lp.tasmod.mixin.accessors.AccessorRunStuff;
7+
import net.minecraft.client.Minecraft;
8+
import net.minecraft.util.math.MathHelper;
39
import net.minecraftforge.client.event.EntityViewRenderEvent.CameraSetup;
410
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
511

612
public class CameraInterpolationEvents {
713

814
public static float rotationPitch = 0f;
915
public static float rotationYaw = 0f;
10-
1116
@SubscribeEvent
1217
public void inter(CameraSetup ev) {
13-
ev.setPitch(rotationPitch);
14-
ev.setYaw(rotationYaw);
18+
if (ClientProxy.virtual.getContainer().isPlayingback() && ControlByteHandler.shouldInterpolate) {
19+
TickInputContainer input = ClientProxy.virtual.getContainer().get(ClientProxy.virtual.getContainer().index());
20+
if (input == null) return;
21+
float nextPitch = input.getSubticks().getPitch();
22+
float nextYaw = input.getSubticks().getYaw();
23+
ev.setPitch((float) MathHelper.clampedLerp(rotationPitch, nextPitch, ((AccessorRunStuff) Minecraft.getMinecraft()).timer().renderPartialTicks));
24+
ev.setYaw((float) MathHelper.clampedLerp(rotationYaw, nextYaw+180, ((AccessorRunStuff) Minecraft.getMinecraft()).timer().renderPartialTicks));
25+
} else {
26+
ev.setPitch(rotationPitch);
27+
ev.setYaw(rotationYaw);
28+
}
1529
}
1630

1731
}

src/main/java/de/scribble/lp/tasmod/InfoGui.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import com.mojang.realmsclient.gui.ChatFormatting;
66

7+
import de.pfannekuchen.tasmod.controlbytes.ControlByteHandler;
78
import net.minecraft.client.Minecraft;
89
import net.minecraft.client.gui.Gui;
910
import net.minecraft.client.gui.ScaledResolution;
@@ -26,6 +27,9 @@ public void drawStuff(RenderGameOverlayEvent.Post event) {
2627
if (event.isCancelable() || event.getType() != ElementType.HOTBAR) {
2728
return;
2829
}
30+
// skip rendering control byte hide hud is set
31+
if (!ControlByteHandler.shouldRenderHud && ClientProxy.virtual.getContainer().isPlayingback())
32+
return;
2933
ScaledResolution scaled = new ScaledResolution(mc);
3034
int width = scaled.getScaledWidth();
3135
int height = scaled.getScaledHeight();

src/main/java/de/scribble/lp/tasmod/commands/fullplay/CommandFullPlay.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public String getUsage(ICommandSender sender) {
2727
@Override
2828
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
2929
try {
30-
TASmod.savestateHandler.loadState(0, false);
30+
TASmod.savestateHandler.loadState(0, false, false);
3131
} catch (LoadstateException e) {
3232
sender.sendMessage(new TextComponentString(TextFormatting.RED+"Failed to load a savestate: "+e.getMessage()));
3333
return;

src/main/java/de/scribble/lp/tasmod/commands/fullrecord/FullRecordPacket.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package de.scribble.lp.tasmod.commands.fullrecord;
22

3+
import de.scribble.lp.tasmod.ClientProxy;
34
import de.scribble.lp.tasmod.events.OpenGuiEvents;
45
import de.scribble.lp.tasmod.util.TASstate;
56
import io.netty.buffer.ByteBuf;
@@ -43,6 +44,7 @@ public IMessage onMessage(FullRecordPacket message, MessageContext ctx) {
4344
@SideOnly(Side.CLIENT)
4445
private void workaround(Minecraft mc) {
4546
OpenGuiEvents.stateWhenOpened = TASstate.RECORDING;
47+
ClientProxy.virtual.getContainer().clear();
4648
mc.world.sendQuittingDisconnectingPacket();
4749
mc.loadWorld((WorldClient) null);
4850
mc.displayGuiScreen(new net.minecraft.client.gui.GuiMainMenu());

src/main/java/de/scribble/lp/tasmod/events/LoadWorldEvents.java

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
public class LoadWorldEvents {
99

1010
public static boolean waszero = false;
11-
public static int cd = -1;
11+
private static boolean isLoading =false;
12+
13+
/**
14+
* Delay after the loading screen is finished before firing "doneWithLoadingScreen"
15+
*/
16+
private static int loadingScreenDelay = -1;
1217

1318
/**
1419
* Executed when an integrated server is launched
@@ -20,20 +25,19 @@ public static void startLaunchServer() {
2025
if (TickrateChangerClient.ticksPerSecond == 0 || TickrateChangerClient.advanceTick) {
2126
waszero = true;
2227
}
28+
isLoading = true;
2329
}
2430

2531
/**
2632
* Executed when the server is initialising
2733
* Side: Integrated Server
2834
*
29-
* @see de.scribble.lp.tasmod.mixin.events.MixinMinecraftServer#inject_run(org.spongepowered.asm.mixin.injection.callback.CallbackInfo)
35+
* @see de.scribble.lp.tasmod.mixin.events.MixinIntegratedServer#inject_init(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable)
3036
*/
3137
public static void initServer() {
32-
if (!TASmod.getServerInstance().isDedicatedServer()) {
33-
TASmod.logger.info("Integrated server initialised");
34-
TickrateChangerClient.pauseClientGame(true);
35-
TickrateChangerServer.pauseServerGame(true);
36-
}
38+
TASmod.logger.info("Integrated server initialised");
39+
TickrateChangerClient.pauseClientGame(true);
40+
TickrateChangerServer.pauseServerGame(true);
3741
}
3842

3943
/* The following code is for integrated and dedicated server! */
@@ -63,26 +67,33 @@ public static void doneShuttingDown() {
6367
*/
6468
public static void doneLoadingClientWorld() {
6569
TASmod.logger.info("Finished loading the world on the client");
66-
if(TASmod.getServerInstance()!=null) {
67-
cd = 1;
70+
if(TASmod.getServerInstance()!=null) { //Check if a server is running and if it's an integrated server
71+
loadingScreenDelay = 1;
6872
}
6973
}
7074

7175
/**
7276
* Executed a frame after the world is done loading
7377
*/
7478
public static void doneWithLoadingScreen() {
75-
if (cd > -1) {
76-
if (cd == 0) {
79+
if (loadingScreenDelay > -1) {
80+
if (loadingScreenDelay == 0) {
7781
TASmod.logger.info("Finished loading screen on the client");
7882
if (!waszero) {
79-
TickrateChangerClient.pauseGame(false);
83+
if(TASmod.getServerInstance()!=null) { //Check if a server is running and if it's an integrated server
84+
TickrateChangerClient.pauseClientGame(false);
85+
TickrateChangerServer.pauseServerGame(false);
86+
}
8087
} else {
8188
waszero = false;
8289
}
90+
isLoading=false;
8391
}
84-
cd--;
92+
loadingScreenDelay--;
8593
}
8694
}
8795

96+
public static boolean isLoading() {
97+
return isLoading;
98+
}
8899
}

src/main/java/de/scribble/lp/tasmod/inputcontainer/InputContainer.java

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package de.scribble.lp.tasmod.inputcontainer;
22

33
import java.io.File;
4+
import java.util.HashMap;
5+
import java.util.List;
6+
import java.util.Map;
47

58
import org.lwjgl.opengl.Display;
69

710
import com.dselent.bigarraylist.BigArrayList;
811
import com.mojang.realmsclient.gui.ChatFormatting;
12+
import com.mojang.realmsclient.util.Pair;
913

14+
import de.pfannekuchen.tasmod.controlbytes.ControlByteHandler;
1015
import de.scribble.lp.tasmod.ClientProxy;
1116
import de.scribble.lp.tasmod.CommonProxy;
1217
import de.scribble.lp.tasmod.monitoring.DesyncMonitoring;
@@ -69,6 +74,9 @@ public class InputContainer {
6974
*/
7075
private BigArrayList<TickInputContainer> inputs = new BigArrayList<TickInputContainer>(directory + File.separator + "temp");
7176

77+
// All control characters
78+
private Map<Integer, List<Pair<String, String[]>>> controls = new HashMap<Integer, List<Pair<String, String[]>>>();
79+
7280
public DesyncMonitoring dMonitor = new DesyncMonitoring();
7381

7482
// =====================================================================================================
@@ -105,6 +113,7 @@ public String setTASState(TASstate stateIn) {
105113
* @return The message printed in the chat
106114
*/
107115
public String setTASState(TASstate stateIn, boolean verbose) {
116+
ControlByteHandler.reset();
108117
if (state == stateIn) {
109118
switch (stateIn) {
110119
case PLAYBACK:
@@ -360,6 +369,11 @@ private void playbackNextTick() {
360369
this.keyboard = tickcontainer.getKeyboard().clone();
361370
this.mouse = tickcontainer.getMouse().clone();
362371
this.subticks = tickcontainer.getSubticks().clone();
372+
// check for control bytes
373+
List<Pair<String, String[]>> controlbyte = controls.get(index);
374+
if (controlbyte != null)
375+
for (Pair<String, String[]> pair : controlbyte)
376+
ControlByteHandler.onControlByte(pair.first(), pair.second());
363377
}
364378
}
365379
// =====================================================================================================
@@ -381,13 +395,21 @@ public BigArrayList<TickInputContainer> getInputs() {
381395
return inputs;
382396
}
383397

384-
public void setIndex(int index) {
385-
this.index = index;
386-
if (state == TASstate.PLAYBACK) {
387-
TickInputContainer tickcontainer = inputs.get(index);
388-
this.keyboard = tickcontainer.getKeyboard();
389-
this.mouse = tickcontainer.getMouse();
390-
this.subticks = tickcontainer.getSubticks();
398+
public Map<Integer, List<Pair<String, String[]>>> getControlBytes() {
399+
return controls;
400+
}
401+
402+
public void setIndex(int index) throws IndexOutOfBoundsException{
403+
if(index<=size()) {
404+
this.index = index;
405+
if (state == TASstate.PLAYBACK) {
406+
TickInputContainer tickcontainer = inputs.get(index);
407+
this.keyboard = tickcontainer.getKeyboard();
408+
this.mouse = tickcontainer.getMouse();
409+
this.subticks = tickcontainer.getSubticks();
410+
}
411+
}else {
412+
throw new IndexOutOfBoundsException("Index is bigger than the container");
391413
}
392414
}
393415

@@ -403,6 +425,7 @@ public TickInputContainer get(int index) {
403425

404426
public void clear() {
405427
inputs = new BigArrayList<TickInputContainer>(directory + File.separator + "temp");
428+
controls.clear();
406429
index = 0;
407430
dMonitor.getPos().clear();
408431
clearCredits();

src/main/java/de/scribble/lp/tasmod/mixin/MixinMinecraftServer.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,28 +96,28 @@ public void redirectThreadSleep(long msToTick) {
9696
if (TickrateChangerServer.ticksPerSecond == 0) {
9797
currentTime = System.currentTimeMillis();
9898
faketick++;
99-
if (faketick >= 20) {
99+
if (faketick >= 50) {
100100
faketick = 0;
101101
networkSystem.networkTick();
102102
if (((MinecraftServer) (Object) this).isDedicatedServer()) {
103103
runPendingCommands();
104104
}
105+
synchronized (this.futureTaskQueue) {
106+
while (!this.futureTaskQueue.isEmpty()) {
107+
try {
108+
((FutureTask<?>) this.futureTaskQueue.poll()).run();
109+
} catch (Throwable var9) {
110+
var9.printStackTrace();
111+
}
112+
}
113+
}
105114
}
106115
}
107116
if (TickrateChangerServer.interrupt) {
108117
currentTime = System.currentTimeMillis();
109118
msToTick = 1L;
110119
TickrateChangerServer.interrupt = false;
111120
}
112-
synchronized (this.futureTaskQueue) {
113-
while (!this.futureTaskQueue.isEmpty()) {
114-
try {
115-
((FutureTask<?>) this.futureTaskQueue.poll()).run();
116-
} catch (Throwable var9) {
117-
var9.printStackTrace();
118-
}
119-
}
120-
}
121121

122122
try {
123123
Thread.sleep(1L);

0 commit comments

Comments
 (0)