First Commit

This commit is contained in:
Marius Metzger
2015-01-03 23:25:21 +01:00
commit cbd96d57f4
64 changed files with 23728 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
package eu.crushedpixel.replaymod.events;
import eu.crushedpixel.replaymod.gui.GuiCustomMainMenu;
import eu.crushedpixel.replaymod.gui.GuiCustomOptions;
import eu.crushedpixel.replaymod.gui.GuiExitReplay;
import eu.crushedpixel.replaymod.replay.ReplayHandler;
import net.minecraft.client.gui.GuiChat;
import net.minecraft.client.gui.GuiDisconnected;
import net.minecraft.client.gui.GuiIngameMenu;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.GuiOptions;
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class GuiEventHandler {
@SubscribeEvent
public void onGui(GuiOpenEvent event) {
if(event.gui instanceof GuiMainMenu) {
event.gui = new GuiCustomMainMenu();
} else if(event.gui instanceof GuiOptions) {
GuiOptions go = (GuiOptions)event.gui;
GuiCustomOptions gco = new GuiCustomOptions(GuiCustomOptions.getGuiScreen(go), GuiCustomOptions.getGameSettings(go));
event.gui = gco;
}
else if(event.gui instanceof GuiChat || event.gui instanceof GuiInventory) {
if(ReplayHandler.replayActive()) {
event.setCanceled(true);
}
}
else if(event.gui instanceof GuiIngameMenu) {
if(ReplayHandler.replayActive()) {
event.gui = new GuiExitReplay();
}
}
else if(event.gui instanceof GuiDisconnected) {
if(!ReplayHandler.replayActive() && System.currentTimeMillis() - ReplayHandler.lastExit < 5000) {
event.setCanceled(true);
}
}
}
}

View File

@@ -0,0 +1,810 @@
package eu.crushedpixel.replaymod.events;
import java.awt.Color;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.TimeUnit;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.MouseEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import eu.crushedpixel.replaymod.entities.CameraEntity;
import eu.crushedpixel.replaymod.entities.CameraEntity.MoveDirection;
import eu.crushedpixel.replaymod.gui.GuiMouseInput;
import eu.crushedpixel.replaymod.gui.GuiReplaySpeedSlider;
import eu.crushedpixel.replaymod.holders.Keyframe;
import eu.crushedpixel.replaymod.holders.Position;
import eu.crushedpixel.replaymod.holders.PositionKeyframe;
import eu.crushedpixel.replaymod.holders.TimeKeyframe;
import eu.crushedpixel.replaymod.reflection.MCPNames;
import eu.crushedpixel.replaymod.replay.ReplayHandler;
import eu.crushedpixel.replaymod.replay.ReplayProcess;
public class GuiReplayOverlay extends Gui {
private Minecraft mc = Minecraft.getMinecraft();
private int sliderX = 35;
private int sliderY = 10;
private int timelineX = sliderX+100+5;
private int realTimelineX = 10 + 3*25;
private int realTimelineY = 33+10;
private int realTimePosition = 0;
private int ppButtonX = 10;
private int ppButtonY = 10;
private int r_ppButtonX = 10;
private int r_ppButtonY = realTimelineY+1;
private int place_ButtonX = 35;
private int place_ButtonY = realTimelineY+1;
private int time_ButtonX = 60;
private int time_ButtonY = realTimelineY+1;
private long lastSystemTime = System.currentTimeMillis();
private ResourceLocation guiLocation = new ResourceLocation("replaymod", "replay_gui.png");
private ResourceLocation keyframeLocation = new ResourceLocation("replaymod", "extended_gui.png");
private ResourceLocation timelineLocation = new ResourceLocation("replaymod", "timeline_icons.png");
private GuiReplaySpeedSlider speedSlider;
private boolean mouseDown = false;
private Field drawBlockOutline;
public GuiReplayOverlay() {
try {
drawBlockOutline = EntityRenderer.class.getDeclaredField(MCPNames.field("field_175073_D"));
drawBlockOutline.setAccessible(true);
drawBlockOutline.set(Minecraft.getMinecraft().entityRenderer, false);
} catch(Exception e) {}
}
@SubscribeEvent
public void tick(TickEvent event) {
if(!ReplayHandler.replayActive()) return;
if(ReplayHandler.getCameraEntity() != null)
ReplayHandler.getCameraEntity().updateMovement();
onMouseMove(new MouseEvent());
onKeyInput(new KeyInputEvent());
if(ReplayHandler.isReplaying()) ReplayProcess.tickReplay();
}
@SubscribeEvent
public void onRenderWorld(RenderWorldLastEvent event)
throws IllegalAccessException, IllegalArgumentException,
InvocationTargetException, IOException {
if(!ReplayHandler.replayActive()) return;
ReplayHandler.setCameraEntity(ReplayHandler.getCameraEntity());
if(ReplayHandler.replayActive() && ReplayHandler.isPaused()) {
if(mc != null && mc.thePlayer != null)
MinecraftTicker.runMouseKeyboardTick(mc);
}
}
public void resetUI() throws Exception {
if(FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class)) {
mc.displayGuiScreen((GuiScreen)null);
}
realTimePosition = 0;
speedSlider = new GuiReplaySpeedSlider(1, sliderX, sliderY, "Speed");
}
@SubscribeEvent
public void onRenderGui(RenderGameOverlayEvent.Post event) throws IllegalArgumentException, IllegalAccessException {
if(!ReplayHandler.replayActive()) return;
GL11.glEnable(GL11.GL_BLEND);
drawBlockOutline.set(Minecraft.getMinecraft().entityRenderer, false);
if(!ReplayHandler.replayActive()) {
return;
}
ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
final int width = sr.getScaledWidth();
final int height = sr.getScaledHeight();
final int mouseX = (Mouse.getX() * width / mc.displayWidth);
final int mouseY = (height - Mouse.getY() * height / mc.displayHeight);
//Draw Timeline
drawTimeline(timelineX, width - 14, 9);
drawRealTimeline(realTimelineX, width - 14 - 11, realTimelineY, mouseX, mouseY);
//Play/Pause button
int x = 0;
int y = 0;
boolean play = !ReplayHandler.isPaused();
boolean hover = false;
if(FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class)) {
if(mouseX >= ppButtonX && mouseX <= ppButtonX+20
&& mouseY >= ppButtonY && mouseY <= ppButtonY+20) {
hover = true;
}
}
if(play) {
y = 20;
}
if(hover) {
x = 20;
}
mc.renderEngine.bindTexture(guiLocation);
GlStateManager.resetColor();
this.drawModalRectWithCustomSizedTexture(ppButtonX, ppButtonY, x, y, 20, 20, 64, 64);
//GlStateManager.resetColor();
if(Mouse.isButtonDown(0) && FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class)) { //clicking the Button
speedSlider.mousePressed(mc, mouseX, mouseY);
if(!mouseDown) {
mouseDown = true;
if(hover) {
boolean paused = !ReplayHandler.isPaused();
if(paused) {
ReplayHandler.setSpeed(0);
} else {
ReplayHandler.setSpeed(speedSlider.getSliderValue());
}
}
if(mouseX >= timelineX+4 && mouseX <= width - 18 && mouseY >= 11 && mouseY <= 29) {
double tot = (width - 18)-(timelineX+4);
double perc = (mouseX-(timelineX+4))/tot;
double time = perc*(double)ReplayHandler.getReplayLength();
if(time < ReplayHandler.getReplayTime()) {
mc.displayGuiScreen((GuiScreen)null);
}
ReplayHandler.setReplayPos((int)time, false);
}
}
} else {
speedSlider.mouseReleased(mouseX, mouseY);
mouseDown = false;
}
//Place Keyframe Button
hover = false;
x = 0;
y = 0;
if(FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class)) {
if(mouseX >= place_ButtonX && mouseX <= place_ButtonX+20
&& mouseY >= place_ButtonY && mouseY <= place_ButtonY+20) {
hover = true;
}
}
if(hover) {
x = 20;
}
if(ReplayHandler.getSelected() != null && ReplayHandler.getSelected() instanceof PositionKeyframe) {
y += 20;
}
mc.renderEngine.bindTexture(keyframeLocation);
if(hover && Mouse.isButtonDown(0) && isClick()) {
if(ReplayHandler.getSelected() == null || !(ReplayHandler.getSelected() instanceof PositionKeyframe)) {
addPlaceKeyframe();
} else {
ReplayHandler.removeKeyframe(ReplayHandler.getSelected());
}
}
GlStateManager.resetColor();
this.drawModalRectWithCustomSizedTexture(place_ButtonX, place_ButtonY, x, y, 20, 20, 64, 64);
//Time Keyframe Button
hover = false;
x = 0;
y = 40;
boolean timeSelected = false;
if(ReplayHandler.getSelected() != null && ReplayHandler.getSelected() instanceof TimeKeyframe) {
timeSelected = true;
x = 40;
y = 0;
}
if(FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class)) {
if(mouseX >= time_ButtonX && mouseX <= time_ButtonX+20
&& mouseY >= time_ButtonY && mouseY <= time_ButtonY+20) {
hover = true;
}
}
if(hover) {
if(timeSelected) {
y = 20;
} else {
x = 20;
}
}
mc.renderEngine.bindTexture(keyframeLocation);
if(hover && Mouse.isButtonDown(0) && isClick()) {
if(ReplayHandler.getSelected() == null || !(ReplayHandler.getSelected() instanceof TimeKeyframe)) {
addTimeKeyframe();
} else {
ReplayHandler.removeKeyframe(ReplayHandler.getSelected());
}
}
GlStateManager.resetColor();
this.drawModalRectWithCustomSizedTexture(time_ButtonX, time_ButtonY, x, y, 20, 20, 64, 64);
if(mouseX >= (timelineX+4) && mouseX <= width - 18 && mouseY >= 11 && mouseY <= 29) {
double tot = (width - 18)-(timelineX+4);
double perc = (mouseX-(timelineX+4))/tot;
long time = Math.round(perc*(double)ReplayHandler.getReplayLength());
String timestamp = (String.format("%02d:%02ds",
TimeUnit.MILLISECONDS.toMinutes(time),
TimeUnit.MILLISECONDS.toSeconds(time) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time))
));
this.drawCenteredString(mc.fontRendererObj, timestamp, mouseX, mouseY+5, Color.WHITE.getRGB());
}
if(mc.inGameHasFocus) {
Mouse.setCursorPosition(width/2, height/2);
}
speedSlider.drawButton(mc, mouseX, mouseY);
GlStateManager.resetColor();
Entity player = ReplayHandler.getCameraEntity();
if(player != null) {
player.setVelocity(0, 0, 0);
}
if(!Mouse.isButtonDown(0)) isClick();
}
private int tl_begin_x=0;
private int tl_begin_width = 4;
private int tl_end_x=60;
private int tl_end_width = 4;
private int tl_middle_x=4;
private int tl_y=40;
private void drawTimeline(int minX, int maxX, int y) {
int zero = minX+tl_begin_width;
int full = maxX-tl_end_width;
GlStateManager.resetColor();
mc.renderEngine.bindTexture(guiLocation);
this.drawModalRectWithCustomSizedTexture(minX, y, tl_begin_x, tl_y, tl_begin_width, 22, 64, 64);
for(int i=minX+tl_begin_width; i<maxX-tl_end_width; i += tl_end_x-tl_begin_width) {
this.drawModalRectWithCustomSizedTexture(i, y, tl_begin_x+tl_begin_width
, tl_y, Math.min(tl_end_x-tl_begin_width, maxX-tl_end_width-i)
, 22, 64, 64);
}
this.drawModalRectWithCustomSizedTexture(maxX-tl_end_width, y, tl_end_x, tl_y, tl_end_width, 22, 64, 64);
//Cursor
double width = full-zero;
double perc = (double)ReplayHandler.getReplayTime()/(double)ReplayHandler.getReplayLength();
int cursorX = (int)Math.round(zero+(perc*width));
this.drawModalRectWithCustomSizedTexture(cursorX-3, y+3, 44, 0, 8, 16, 64, 64);
}
int sl_begin_x = 0;
int sl_end_x = 63;
int sl_y = 40;
int plus_x = 0;
int plus_y = 0;
int minus_x = 0;
int minus_y = 9;
int slider_begin_x = 1;
int slider_begin_width = 1;
int slider_end_x = 62;
int slider_end_width = 1;
int slider_y = 50;
int slider_height = 7;
private float zoom_scale = 0.1f; //can see 1/10th of the timeline
private float pos_left = 0f; //left border of timeline is at 0%
private float cursor_pos = 0f; //cursor is at 0%
private long timelineLength = 10*60*1000; //10 min of timeline
private float zoom_steps = 0.05f;
private boolean wasSliding = false;
private void drawRealTimeline(int minX, int maxX, int y, int mouseX, int mouseY) {
int zero = minX+tl_begin_width;
int full = maxX-tl_end_width;
//the real timeline
GlStateManager.resetColor();
mc.renderEngine.bindTexture(guiLocation);
this.drawModalRectWithCustomSizedTexture(minX, y, tl_begin_x, tl_y, tl_begin_width, 22, 64, 64);
for(int i=minX+tl_begin_width; i<maxX-tl_end_width; i += tl_end_x-tl_begin_width) {
this.drawModalRectWithCustomSizedTexture(i, y, tl_begin_x+tl_begin_width
, tl_y, Math.min(tl_end_x-tl_begin_width, maxX-tl_end_width-i)
, 22, 64, 64);
}
this.drawModalRectWithCustomSizedTexture(maxX-tl_end_width, y, tl_end_x, tl_y, tl_end_width, 22, 64, 64);
//Time Slider
int yo = y+22+1;
GlStateManager.resetColor();
mc.renderEngine.bindTexture(timelineLocation);
this.drawModalRectWithCustomSizedTexture(minX, yo, sl_begin_x, sl_y, 2, 9, 64, 64);
for(int i=minX+2; i<maxX-1; i+= sl_end_x-2) {
this.drawModalRectWithCustomSizedTexture(i, yo, 2, sl_y,
Math.min(sl_end_x-2, maxX-1-i), 9, 64, 64);
}
this.drawModalRectWithCustomSizedTexture(maxX-1, yo, sl_end_x, sl_y, 1, 9, 64, 64);
//Timeline Pos Slider
int sl_y = yo+1;
int minPos = minX+1;
int maxPos = maxX-2;
int tlWidth = maxPos - minPos;
int slider_min = minPos+Math.round(pos_left*tlWidth);
int slider_width = Math.round(zoom_scale*tlWidth);
int sl_max = slider_min+slider_width;
this.drawModalRectWithCustomSizedTexture(slider_min, sl_y, slider_begin_x, slider_y, slider_begin_width, slider_height, 64, 64);
for(int i=slider_min+slider_begin_width; i<sl_max-slider_end_width; i+=slider_end_x-slider_begin_width-slider_begin_x) {
this.drawModalRectWithCustomSizedTexture(i, sl_y, slider_begin_x+slider_begin_width, slider_y,
Math.min(slider_end_x-slider_end_width-slider_begin_x, sl_max-slider_end_width-i), slider_height, 64, 64);
}
this.drawModalRectWithCustomSizedTexture(sl_max-slider_end_width, sl_y, slider_end_x, slider_y,
slider_end_width, slider_height, 64, 64);
//Slider dragging
if(Mouse.isButtonDown(0) && (mouseX >= slider_min && mouseX <= sl_max && mouseY >= sl_y && mouseY <= sl_y+slider_height || wasSliding)) {
wasSliding = true;
float dx = ((float)Mouse.getDX() * (float)new ScaledResolution(mc, mc.displayWidth, mc.displayHeight).getScaledWidth() / mc.displayWidth);
this.pos_left = Math.min(1f-this.zoom_scale, Math.max(0f, this.pos_left+(dx/(float)tlWidth)));
}
if(!Mouse.isButtonDown(0)) {
wasSliding = false;
}
//Timeline Buttons
//+- Buttons
boolean hover = false;
int px = plus_x;
if(FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class)) {
if(mouseX >= maxX+2 && mouseX <= maxX+2+9
&& mouseY >= y+1 && mouseY <= y+1+9) {
hover = true;
}
}
if(hover) {
px+=9;
}
this.drawModalRectWithCustomSizedTexture(maxX+2, y+1, px, plus_y, 9, 9, 64, 64);
if(hover && Mouse.isButtonDown(0)) {
zoomIn();
}
hover = false;
int mx = minus_x;
if(FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class)) {
if(mouseX >= maxX+2 && mouseX <= maxX+2+9
&& mouseY >= y+9+3 && mouseY <= y+9+3+9) {
hover = true;
}
}
if(hover) {
mx+=9;
}
this.drawModalRectWithCustomSizedTexture(maxX+2, y+9+3, mx, minus_y, 9, 9, 64, 64);
if(hover && Mouse.isButtonDown(0)) {
zoomOut();
}
//show Time String
if(mouseX >= zero && mouseX <= full && mouseY >= y && mouseY <= y+22) {
long tot = Math.round((double)timelineLength*zoom_scale);
double perc = (mouseX-(realTimelineX+4))/(double)(full-zero);
long time = Math.round(this.pos_left*(double)timelineLength)+Math.round(perc*(double)tot);
String timestamp = (String.format("%02d:%02ds",
TimeUnit.MILLISECONDS.toMinutes(time),
TimeUnit.MILLISECONDS.toSeconds(time) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time))
));
this.drawCenteredString(mc.fontRendererObj, timestamp, mouseX, mouseY+5, Color.WHITE.getRGB());
}
//draw Markers on timeline
MarkerType mt = MarkerType.getMarkerType(zoom_scale, timelineLength);
//every x seconds, draw small marker
long left_real = Math.round(pos_left*(double)timelineLength);
long right_real = left_real+(Math.round(zoom_scale*timelineLength));
long tot = Math.round((double)timelineLength*zoom_scale);
for(int s=0; s<=timelineLength; s+= mt.getSmallDistance()) {
if(s > right_real) break;
if(s >= left_real) {
//calculate absolute position on screen
long relative = (s) - (left_real);
double perc = ((double)relative/(double)tot);
long real_width = full-zero;
long rel_x = Math.round(perc*(double)real_width);
long real_x = zero+rel_x;
this.drawVerticalLine((int)real_x, y+19-3, y+19, Color.WHITE.getRGB());
}
}
//every x seconds, draw big marker
for(int s=0; s<=timelineLength; s+= mt.getDistance()) {
if(s > right_real) break;
if(s >= left_real) {
//calculate absolute position on screen
long relative = s - (left_real);
double perc = ((double)relative/(double)tot);
long real_width = full-zero;
long rel_x = Math.round(perc*(double)real_width);
long real_x = zero+rel_x;
this.drawVerticalLine((int)real_x, y+19-7, y+19, Color.LIGHT_GRAY.getRGB());
//write text
int time = s;
String timestamp = (String.format("%02d:%02d",
TimeUnit.MILLISECONDS.toMinutes(time),
TimeUnit.MILLISECONDS.toSeconds(time) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time))
));
this.drawCenteredString(mc.fontRendererObj, timestamp, (int)real_x, y-8, Color.WHITE.getRGB());
}
}
//handle Mouse clicks on realTimeLine
if(Mouse.isButtonDown(0) && !wasSliding && mouseX >= minX+tl_begin_width && mouseX <= maxX-tl_end_width &&
mouseY >= y && mouseY <= y+22) {
//calculate real time and set cursor accordingly
int width = (maxX-tl_end_width) - (minX+tl_begin_width);
int rel_x = mouseX-(minX+tl_begin_width);
float rel_pos = (float)rel_x/(float)width;
float abs_width = (zoom_scale*(float)timelineLength);
int real_pos = Math.round(left_real+((rel_pos)*abs_width));
realTimePosition = real_pos;
//Keyframe click handling here
if(isClick()) {
//tolerance is 2 pixels multiplied with the timespan of one pixel
int tolerance = 2*Math.round(abs_width/(float)width);
if(mouseY >= y+9) {
TimeKeyframe close = ReplayHandler.getClosestTimeKeyframeForRealTime(realTimePosition, tolerance);
ReplayHandler.selectKeyframe(close); //can be null, deselects keyframe
} else {
PositionKeyframe close = ReplayHandler.getClosestPlaceKeyframeForRealTime(realTimePosition, tolerance);
ReplayHandler.selectKeyframe(close); //can be null, deselects keyframe
}
}
}
//Draw Realtime Cursor
if(realTimePosition >= left_real && realTimePosition <= right_real) {
long rel_pos = realTimePosition-left_real;
long rel_width = right_real-left_real;
double perc = (double)rel_pos/(double)rel_width;
int real_width = (maxX-tl_end_width) - (minX+tl_begin_width);
double rel_x = (float)real_width*perc;
int real_x = (int)Math.round((minX+tl_begin_width)+rel_x);
mc.renderEngine.bindTexture(this.guiLocation);
GL11.glEnable(GL11.GL_BLEND);
this.drawModalRectWithCustomSizedTexture(real_x-3, y+3, 44, 0, 8, 16, 64, 64);
//this.drawModalRectWithCustomSizedTexture(real_x, sl_y, u, v, width, height, textureWidth, textureHeight)
}
//Draw Keyframe logos
mc.renderEngine.bindTexture(timelineLocation);
for(Keyframe kf : ReplayHandler.getKeyframes()) {
if(kf.getRealTimestamp() > right_real) break;
if(kf.getRealTimestamp() >= left_real) {
int dx = 18;
int dy = 0;
int ry = y+3;
if(kf instanceof TimeKeyframe) {
dy = 5;
ry += 5;
}
if(ReplayHandler.isSelected(kf)) {
dx += 5;
}
long relative = kf.getRealTimestamp() - (left_real);
double perc = ((double)relative/(double)tot);
long real_width = full-zero;
long rel_x = Math.round(perc*(double)real_width);
long real_x = zero+rel_x - 2;
this.drawModalRectWithCustomSizedTexture((int)real_x, ry, dx, dy, 5, 5, 64, 64);
}
}
//Draw Play/Pause Button
//Play/Pause button
int dx = 0;
int dy = 0;
boolean play = ReplayHandler.isReplaying();
hover = false;
if(FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class)) {
if(mouseX >= r_ppButtonX && mouseX <= r_ppButtonX+20
&& mouseY >= r_ppButtonY && mouseY <= r_ppButtonY+20) {
hover = true;
}
}
if(play) {
dy = 20;
}
if(hover) {
dx = 20;
}
mc.renderEngine.bindTexture(guiLocation);
GlStateManager.resetColor();
this.drawModalRectWithCustomSizedTexture(r_ppButtonX, r_ppButtonY, dx, dy, 20, 20, 64, 64);
//Handling the click on the Replay starter
if(hover && Mouse.isButtonDown(0) && isClick()) {
if(ReplayHandler.isReplaying()) {
ReplayHandler.interruptReplay();
} else {
ReplayHandler.startPath();
}
}
}
private void addPlaceKeyframe() {
CameraEntity cam = ReplayHandler.getCameraEntity();
if(cam == null) return;
ReplayHandler.addKeyframe(new PositionKeyframe(realTimePosition, new Position(cam.posX, cam.posY, cam.posZ, cam.rotationPitch, cam.rotationYaw)));
}
private void addTimeKeyframe() {
ReplayHandler.addKeyframe(new TimeKeyframe(realTimePosition, ReplayHandler.getReplayTime()));
}
private enum MarkerType {
ONE_S(1*1000, 100),
FIVE_S(5*1000, 1*1000),
QUARTER_M(15*1000, 3*1000),
HALF_M(30*1000, 5*1000),
ONE_M(60*1000, 10*1000),
FIVE_M(5*60*1000, 50*1000);
int minimum;
int small_min;
int maximum = 10;
int getDistance() {
return minimum;
}
int getSmallDistance() {
return small_min;
}
MarkerType(int minimum, int small_min) {
this.minimum = minimum;
this.small_min = small_min;
}
public static MarkerType getMarkerType(float scale, long totalLength) {
long visible = Math.round((double)totalLength*scale);
long seconds = visible;
for(MarkerType mt : values()) {
if(seconds/mt.getDistance() <= 10) {
return mt;
}
}
return FIVE_M;
}
}
private void zoomIn() {
if(!isClick()) return;
this.zoom_scale = Math.max(0.025f, zoom_scale-zoom_steps);
}
private void zoomOut() {
if(!isClick()) return;
this.zoom_scale = Math.min(1f, zoom_scale+zoom_steps);
this.pos_left = Math.min(pos_left, 1f-zoom_scale);
}
private boolean mouseDwn = false;
private boolean isClick() {
if(Mouse.isButtonDown(0)) {
boolean bef = new Boolean(mouseDwn);
mouseDwn = true;
return !bef;
} else {
mouseDwn = false;
return false;
}
}
@SubscribeEvent
public void onMouseMove(MouseEvent event) {
if(!ReplayHandler.replayActive()) return;
boolean flag = Display.isActive();
flag = true;
mc.mcProfiler.startSection("mouse");
if (flag && Minecraft.isRunningOnMac && mc.inGameHasFocus && !Mouse.isInsideWindow())
{
Mouse.setGrabbed(false);
Mouse.setCursorPosition(Display.getWidth() / 2, Display.getHeight() / 2);
Mouse.setGrabbed(true);
}
if (mc.inGameHasFocus && flag)
{
mc.mouseHelper.mouseXYChange();
float f1 = mc.gameSettings.mouseSensitivity * 0.6F + 0.2F;
float f2 = f1 * f1 * f1 * 8.0F;
float f3 = (float)mc.mouseHelper.deltaX * f2;
float f4 = (float)mc.mouseHelper.deltaY * f2;
byte b0 = 1;
if (mc.gameSettings.invertMouse)
{
b0 = -1;
}
ReplayHandler.getCameraEntity().setAngles(f3, f4 * (float)b0);
}
}
@SubscribeEvent
public void onKeyInput(KeyInputEvent event) {
if(!ReplayHandler.replayActive()) return;
if(FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class)) {
return;
}
KeyBinding[] keyBindings = Minecraft.getMinecraft().gameSettings.keyBindings;
for(KeyBinding kb : keyBindings) {
if(!kb.isKeyDown()) {
continue;
}
try {
if(kb.getKeyDescription().equals("key.forward")) {
ReplayHandler.getCameraEntity().setMovement(MoveDirection.FORWARD);
continue;
}
if(kb.getKeyDescription().equals("key.back")) {
ReplayHandler.getCameraEntity().setMovement(MoveDirection.BACKWARD);
continue;
}
if(kb.getKeyDescription().equals("key.jump")) {
ReplayHandler.getCameraEntity().setMovement(MoveDirection.UP);
continue;
}
if(kb.getKeyDescription().equals("key.sneak")) {
ReplayHandler.getCameraEntity().setMovement(MoveDirection.DOWN);
continue;
}
if(kb.getKeyDescription().equals("key.left")) {
ReplayHandler.getCameraEntity().setMovement(MoveDirection.LEFT);
continue;
}
if(kb.getKeyDescription().equals("key.right")) {
ReplayHandler.getCameraEntity().setMovement(MoveDirection.RIGHT);
continue;
}
if(kb.getKeyDescription().equals("key.chat")) {
mc.displayGuiScreen(new GuiMouseInput());
continue;
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
}

View File

@@ -0,0 +1,442 @@
package eu.crushedpixel.replaymod.events;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiChat;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.crash.CrashReport;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.play.client.C16PacketClientStatus;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ReportedException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import eu.crushedpixel.replaymod.entities.CameraEntity;
import eu.crushedpixel.replaymod.reflection.MCPNames;
import eu.crushedpixel.replaymod.replay.ReplayHandler;
public class MinecraftTicker {
private static Field debugCrashKeyPressTime, rightClickDelayTimer, systemTime, leftClickCounter;
private static Method getSystemTime, updateDebugProfilerName,
clickMouse, middleClickMouse, rightClickMouse, sendClickBlockToController;
private static Minecraft mc = Minecraft.getMinecraft();
private static float camPitch, camYaw, smoothCamPartialTicks,
smoothCamFilterX, smoothCamFilterY;
static {
try {
debugCrashKeyPressTime = Minecraft.class.getDeclaredField(MCPNames.field("field_83002_am"));
debugCrashKeyPressTime.setAccessible(true);
rightClickDelayTimer = Minecraft.class.getDeclaredField(MCPNames.field("field_71467_ac"));
rightClickDelayTimer.setAccessible(true);
systemTime = Minecraft.class.getDeclaredField(MCPNames.field("field_71423_H"));
systemTime.setAccessible(true);
leftClickCounter = Minecraft.class.getDeclaredField(MCPNames.field("field_71429_W"));
leftClickCounter.setAccessible(true);
getSystemTime = Minecraft.class.getDeclaredMethod(MCPNames.method("func_71386_F"));
getSystemTime.setAccessible(true);
updateDebugProfilerName = Minecraft.class.getDeclaredMethod(MCPNames.method("func_71383_b"), int.class);
updateDebugProfilerName.setAccessible(true);
clickMouse = Minecraft.class.getDeclaredMethod(MCPNames.method("func_147116_af"));
clickMouse.setAccessible(true);
rightClickMouse = Minecraft.class.getDeclaredMethod(MCPNames.method("func_147121_ag"));
rightClickMouse.setAccessible(true);
middleClickMouse = Minecraft.class.getDeclaredMethod(MCPNames.method("func_147112_ai"));
middleClickMouse.setAccessible(true);
sendClickBlockToController = Minecraft.class.getDeclaredMethod(MCPNames.method("func_147115_a"), boolean.class);
sendClickBlockToController.setAccessible(true);
} catch(Exception e) {
e.printStackTrace();
}
}
public static void runMouseKeyboardTick(Minecraft mc) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IOException {
try {
mc.mcProfiler.endStartSection("mouse");
int i;
while(Mouse.next()) {
i = Mouse.getEventButton();
KeyBinding.setKeyBindState(i - 100, Mouse.getEventButtonState());
if (Mouse.getEventButtonState())
{
if (mc.thePlayer.isSpectator() && i == 2)
{
mc.ingameGUI.func_175187_g().func_175261_b();
}
else
{
KeyBinding.onTick(i - 100);
}
}
long k = (Long)getSystemTime.invoke(mc) - (Long)systemTime.get(mc);
if (k <= 200L)
{
int j = Mouse.getEventDWheel();
if (j != 0)
{
if (mc.thePlayer.isSpectator())
{
j = j < 0 ? -1 : 1;
if (mc.ingameGUI.func_175187_g().func_175262_a())
{
mc.ingameGUI.func_175187_g().func_175259_b(-j);
}
else
{
float f = MathHelper.clamp_float(mc.thePlayer.capabilities.getFlySpeed() + (float)j * 0.005F, 0.0F, 0.2F);
mc.thePlayer.capabilities.setFlySpeed(f);
}
}
else
{
mc.thePlayer.inventory.changeCurrentItem(j);
}
}
if (mc.currentScreen == null)
{
if (!mc.inGameHasFocus && Mouse.getEventButtonState())
{
mc.setIngameFocus();
}
}
else
{
mc.currentScreen.handleMouseInput();
}
}
net.minecraftforge.fml.common.FMLCommonHandler.instance().fireMouseInput();
}
if ((Integer)leftClickCounter.get(mc) > 0)
{
leftClickCounter.set(mc, (Integer)leftClickCounter.get(mc) - 1);
}
mc.mcProfiler.endStartSection("keyboard");
while (Keyboard.next())
{
i = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() + 256 : Keyboard.getEventKey();
KeyBinding.setKeyBindState(i, Keyboard.getEventKeyState());
if (Keyboard.getEventKeyState())
{
KeyBinding.onTick(i);
}
if ((Long)debugCrashKeyPressTime.get(mc) > 0L)
{
if ((Long)getSystemTime.invoke(mc) - (Long)debugCrashKeyPressTime.get(mc) >= 6000L)
{
throw new ReportedException(new CrashReport("Manually triggered debug crash", new Throwable()));
}
if (!Keyboard.isKeyDown(46) || !Keyboard.isKeyDown(61))
{
debugCrashKeyPressTime.set(mc, -1);
}
}
else if (Keyboard.isKeyDown(46) && Keyboard.isKeyDown(61))
{
debugCrashKeyPressTime.set(mc, getSystemTime.invoke(mc));
}
mc.dispatchKeypresses();
if (Keyboard.getEventKeyState())
{
if (i == 62 && mc.entityRenderer != null)
{
mc.entityRenderer.switchUseShader();
}
if (mc.currentScreen != null)
{
mc.currentScreen.handleKeyboardInput();
}
else
{
if (i == 1)
{
mc.displayInGameMenu();
}
if (i == 32 && Keyboard.isKeyDown(61) && mc.ingameGUI != null)
{
mc.ingameGUI.getChatGUI().clearChatMessages();
}
if (i == 31 && Keyboard.isKeyDown(61))
{
mc.refreshResources();
}
if (i == 17 && Keyboard.isKeyDown(61))
{
;
}
if (i == 18 && Keyboard.isKeyDown(61))
{
;
}
if (i == 47 && Keyboard.isKeyDown(61))
{
;
}
if (i == 38 && Keyboard.isKeyDown(61))
{
;
}
if (i == 22 && Keyboard.isKeyDown(61))
{
;
}
if (i == 20 && Keyboard.isKeyDown(61))
{
mc.refreshResources();
}
if (i == 33 && Keyboard.isKeyDown(61))
{
boolean flag1 = Keyboard.isKeyDown(42) | Keyboard.isKeyDown(54);
mc.gameSettings.setOptionValue(GameSettings.Options.RENDER_DISTANCE, flag1 ? -1 : 1);
}
if (i == 30 && Keyboard.isKeyDown(61))
{
mc.renderGlobal.loadRenderers();
}
if (i == 35 && Keyboard.isKeyDown(61))
{
mc.gameSettings.advancedItemTooltips = !mc.gameSettings.advancedItemTooltips;
mc.gameSettings.saveOptions();
}
if (i == 48 && Keyboard.isKeyDown(61))
{
mc.getRenderManager().setDebugBoundingBox(!mc.getRenderManager().isDebugBoundingBox());
}
if (i == 25 && Keyboard.isKeyDown(61))
{
mc.gameSettings.pauseOnLostFocus = !mc.gameSettings.pauseOnLostFocus;
mc.gameSettings.saveOptions();
}
if (i == 59)
{
mc.gameSettings.hideGUI = !mc.gameSettings.hideGUI;
}
if (i == 61)
{
mc.gameSettings.showDebugInfo = !mc.gameSettings.showDebugInfo;
mc.gameSettings.showDebugProfilerChart = GuiScreen.isShiftKeyDown();
}
if (mc.gameSettings.keyBindTogglePerspective.isPressed())
{
++mc.gameSettings.thirdPersonView;
if (mc.gameSettings.thirdPersonView > 2)
{
mc.gameSettings.thirdPersonView = 0;
}
if (mc.gameSettings.thirdPersonView == 0)
{
mc.entityRenderer.loadEntityShader(mc.getRenderViewEntity());
}
else if (mc.gameSettings.thirdPersonView == 1)
{
mc.entityRenderer.loadEntityShader((Entity)null);
}
}
if (mc.gameSettings.keyBindSmoothCamera.isPressed())
{
mc.gameSettings.smoothCamera = !mc.gameSettings.smoothCamera;
}
}
if (mc.gameSettings.showDebugInfo && mc.gameSettings.showDebugProfilerChart)
{
if (i == 11)
{
updateDebugProfilerName.invoke(mc, 0);
}
for (int l = 0; l < 9; ++l)
{
if (i == 2 + l)
{
updateDebugProfilerName.invoke(mc, l+1);
}
}
}
}
net.minecraftforge.fml.common.FMLCommonHandler.instance().fireKeyInput();
}
for (i = 0; i < 9; ++i)
{
if (mc.gameSettings.keyBindsHotbar[i].isPressed())
{
if (mc.thePlayer.isSpectator())
{
mc.ingameGUI.func_175187_g().func_175260_a(i);
}
else
{
mc.thePlayer.inventory.currentItem = i;
}
}
}
boolean flag = mc.gameSettings.chatVisibility != EntityPlayer.EnumChatVisibility.HIDDEN;
while (mc.gameSettings.keyBindInventory.isPressed())
{
if (mc.playerController.isRidingHorse())
{
mc.thePlayer.sendHorseInventory();
}
else
{
mc.getNetHandler().addToSendQueue(new C16PacketClientStatus(C16PacketClientStatus.EnumState.OPEN_INVENTORY_ACHIEVEMENT));
mc.displayGuiScreen(new GuiInventory(mc.thePlayer));
}
}
while (mc.gameSettings.keyBindDrop.isPressed())
{
if (!mc.thePlayer.isSpectator())
{
mc.thePlayer.dropOneItem(GuiScreen.isCtrlKeyDown());
}
}
while (mc.gameSettings.keyBindChat.isPressed() && flag)
{
mc.displayGuiScreen(new GuiChat());
}
if (mc.currentScreen == null && mc.gameSettings.keyBindCommand.isPressed() && flag)
{
mc.displayGuiScreen(new GuiChat("/"));
}
if (mc.thePlayer != null && mc.thePlayer.isUsingItem())
{
if (!mc.gameSettings.keyBindUseItem.isKeyDown())
{
mc.playerController.onStoppedUsingItem(mc.thePlayer);
}
label435:
while (true)
{
if (!mc.gameSettings.keyBindAttack.isPressed())
{
while (mc.gameSettings.keyBindUseItem.isPressed())
{
;
}
while (true)
{
if (mc.gameSettings.keyBindPickBlock.isPressed())
{
continue;
}
break label435;
}
}
}
}
else
{
while (mc.gameSettings.keyBindAttack.isPressed())
{
if(mc != null)
try {
clickMouse.invoke(mc);
} catch(Exception e) {}
}
while (mc.gameSettings.keyBindUseItem.isPressed())
{
if(mc != null)
try {
rightClickMouse.invoke(mc);
} catch(Exception e) {}
}
while (mc.gameSettings.keyBindPickBlock.isPressed())
{
if(mc != null)
try {
middleClickMouse.invoke(mc);
} catch(Exception e) {}
}
}
if (mc.gameSettings.keyBindUseItem.isKeyDown() && (Integer)rightClickDelayTimer.get(mc) == 0 && !mc.thePlayer.isUsingItem())
{
if(mc != null)
try {
rightClickMouse.invoke(mc);
} catch(Exception e) {}
}
if(mc != null)
try {
sendClickBlockToController.invoke(mc, mc.currentScreen == null && mc.gameSettings.keyBindAttack.isKeyDown() && mc.inGameHasFocus);
} catch(Exception e) {}
if(mc != null)
systemTime.set(mc, getSystemTime.invoke(mc));
} catch(Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,87 @@
package eu.crushedpixel.replaymod.events;
import java.io.IOException;
import java.util.UUID;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.network.Packet;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.server.S0CPacketSpawnPlayer;
import net.minecraft.network.play.server.S14PacketEntity.S17PacketEntityLookMove;
import net.minecraft.network.play.server.S18PacketEntityTeleport;
import net.minecraft.util.MathHelper;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent;
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
public class RecordingHandler {
private Minecraft mc = Minecraft.getMinecraft();
private int entityID = Integer.MAX_VALUE;
@SubscribeEvent
public void onPlayerJoin(EntityJoinWorldEvent e) throws IOException {
if(e.entity != mc.thePlayer) return;
if(!ConnectionEventHandler.isRecording()) return;
//Packet packet = new S0CPacketSpawnPlayer((EntityPlayer)e.entity);
Packet packet = new S0CPacketSpawnPlayer();
ByteBuf bb = Unpooled.buffer();
PacketBuffer pb = new PacketBuffer(bb);
pb.writeVarIntToBuffer(entityID);
//pb.writeUuid((e.entity).getUniqueID());
pb.writeUuid(UUID.randomUUID());
pb.writeInt(MathHelper.floor_double(e.entity.posX * 32.0D));
pb.writeInt(MathHelper.floor_double(e.entity.posY * 32.0D));
pb.writeInt(MathHelper.floor_double(e.entity.posZ * 32.0D));
pb.writeByte((byte)((int)(((EntityPlayer)e.entity).rotationYaw * 256.0F / 360.0F)));
pb.writeByte((byte)((int)(((EntityPlayer)e.entity).rotationPitch * 256.0F / 360.0F)));
ItemStack itemstack = ((EntityPlayer)e.entity).inventory.getCurrentItem();
pb.writeInt(itemstack == null ? 0 : Item.getIdFromItem(itemstack.getItem()));
((EntityPlayer)e.entity).getDataWatcher().writeTo(pb);
packet.readPacketData(pb);
ConnectionEventHandler.insertPacket(packet);
}
@SubscribeEvent
public void onPlayerTick(PlayerTickEvent e) {
if(e.player != mc.thePlayer) return;
if(!ConnectionEventHandler.isRecording()) return;
double dx = e.player.prevPosX - e.player.posX;
double dy = e.player.prevPosY - e.player.posY;
double dz = e.player.prevPosZ - e.player.posZ;
Packet packet;
if(Math.abs(dx) > 4.0 || Math.abs(dy) > 4.0 || Math.abs(dz) > 4.0) {
packet = new S18PacketEntityTeleport(e.player);
} else {
byte oldYaw = (byte)((int)(e.player.prevRotationYaw * 256.0F / 360.0F));
byte newYaw = (byte)((int)(e.player.rotationYaw * 256.0F / 360.0F));
byte oldPitch = (byte)((int)(e.player.prevRotationPitch * 256.0F / 360.0F));
byte newPitch = (byte)((int)(e.player.rotationPitch * 256.0F / 360.0F));
byte dPitch = (byte)(newPitch-oldPitch);
byte dYaw = (byte)(newYaw-oldYaw);
packet = new S17PacketEntityLookMove(entityID,
(byte)Math.round(dx*32), (byte)Math.round(dy*32), (byte)Math.round(dz*32),
dYaw, dPitch, e.player.onGround);
}
ConnectionEventHandler.insertPacket(packet);
}
}

View File

@@ -0,0 +1,41 @@
package eu.crushedpixel.replaymod.events;
import java.lang.reflect.Field;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.world.WorldSettings.GameType;
import net.minecraftforge.client.event.FOVUpdateEvent;
import net.minecraftforge.client.event.RenderWorldEvent;
import net.minecraftforge.event.entity.player.AchievementEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerFlyableFallEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.ServerTickEvent;
import eu.crushedpixel.replaymod.reflection.MCPNames;
import eu.crushedpixel.replaymod.replay.ReplayHandler;
public class ReplayTickHandler {
private Minecraft mc = Minecraft.getMinecraft();
@SubscribeEvent
public void onPlayer(PlayerEvent event) {
if(ReplayHandler.replayActive() && event.isCancelable()) {
event.setCanceled(true);
}
}
@SubscribeEvent
public void onFovChange(FOVUpdateEvent event) {
if(ReplayHandler.replayActive()) {
event.newfov = 1f;
}
}
}