Adapted new API System with search API call

Implemented raw Pagination support to Replay Center
Fixed awkward time jumps caused by MCTimerHandler
Fixed Java 1.6 incompatibility with List.sort Method in GuiSpectateSelection
Fixed a LOT of compatibility issues with the Shader Mod
This commit is contained in:
Marius Metzger
2015-02-19 00:20:11 +01:00
parent ee05535024
commit d3a9331bf7
17 changed files with 209 additions and 129 deletions

View File

@@ -18,6 +18,7 @@ import com.google.gson.JsonParser;
import eu.crushedpixel.replaymod.api.client.holders.ApiError; import eu.crushedpixel.replaymod.api.client.holders.ApiError;
import eu.crushedpixel.replaymod.api.client.holders.AuthKey; import eu.crushedpixel.replaymod.api.client.holders.AuthKey;
import eu.crushedpixel.replaymod.api.client.holders.FileInfo; import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
import eu.crushedpixel.replaymod.api.client.holders.SearchResult;
import eu.crushedpixel.replaymod.api.client.holders.Success; import eu.crushedpixel.replaymod.api.client.holders.Success;
import eu.crushedpixel.replaymod.api.client.holders.UserFiles; import eu.crushedpixel.replaymod.api.client.holders.UserFiles;
import eu.crushedpixel.replaymod.utils.StreamTools; import eu.crushedpixel.replaymod.utils.StreamTools;
@@ -54,21 +55,19 @@ public class ApiClient {
QueryBuilder builder = new QueryBuilder(ApiMethods.replay_files); QueryBuilder builder = new QueryBuilder(ApiMethods.replay_files);
builder.put("auth", auth); builder.put("auth", auth);
builder.put("ids", buildListString(ids)); builder.put("ids", buildListString(ids));
FileInfo[] info = invokeAndReturn(builder, FileInfo[].class); //TODO: Test if that works FileInfo[] info = invokeAndReturn(builder, FileInfo[].class);
return info; return info;
} }
public FileInfo[] getRecentFiles() throws IOException, ApiException { public FileInfo[] searchFiles(SearchQuery query) throws IOException, ApiException {
QueryBuilder builder = new QueryBuilder(ApiMethods.replay_files); StringBuilder sb = new StringBuilder();
builder.put("recent", true);
FileInfo[] info = invokeAndReturn(builder, FileInfo[].class); //TODO: Test if that works // build base url
return info; sb.append(QueryBuilder.API_BASE_URL);
} sb.append("search");
sb.append(query.buildQuery());
public FileInfo[] getBestFiles() throws IOException, ApiException {
QueryBuilder builder = new QueryBuilder(ApiMethods.replay_files); FileInfo[] info = invokeAndReturn(sb.toString(), SearchResult.class).getResults();
builder.put("best", true);
FileInfo[] info = invokeAndReturn(builder, FileInfo[].class); //TODO: Test if that works
return info; return info;
} }
@@ -116,8 +115,12 @@ public class ApiClient {
invokeAndReturn(builder, Success.class); invokeAndReturn(builder, Success.class);
} }
private <T> T invokeAndReturn(QueryBuilder builder,Class<T> classOfT) throws IOException, ApiException { private <T> T invokeAndReturn(QueryBuilder builder, Class<T> classOfT) throws IOException, ApiException {
JsonElement ele = GsonApiClient.invoke(builder); return invokeAndReturn(builder.toString(), classOfT);
}
private <T> T invokeAndReturn(String url, Class<T> classOfT) throws IOException, ApiException {
JsonElement ele = GsonApiClient.invokeJson(url);
return gson.fromJson(ele, classOfT); return gson.fromJson(ele, classOfT);
} }

View File

@@ -48,7 +48,7 @@ public class FileUploader {
uploading = true; uploading = true;
String postData = "?auth="+auth+"&category="+category.getId(); String postData = "?auth="+auth+"&category="+category.getId();
if(tags.size() > 0) { if(tags.size() > 0) {
postData += "&tags="; postData += "&tags=";
for(String tag : tags) { for(String tag : tags) {
@@ -58,7 +58,7 @@ public class FileUploader {
} }
} }
} }
postData +="&name="+URLEncoder.encode(filename, "UTF-8"); postData +="&name="+URLEncoder.encode(filename, "UTF-8");
System.out.println(postData); System.out.println(postData);
@@ -118,23 +118,28 @@ public class FileUploader {
is = con.getErrorStream(); is = con.getErrorStream();
} }
BufferedReader r = new BufferedReader(new InputStreamReader(is));
String info = null; String info = null;
if(responseCode != 200) {
ApiError error = new ApiError(-1, "An unknown error occured"); if(is != null) {
String json = ""; BufferedReader r = new BufferedReader(new InputStreamReader(is));
while(r.ready()) { info = null;
json += r.readLine(); if(responseCode != 200) {
ApiError error = new ApiError(-1, "An unknown error occured");
String json = "";
while(r.ready()) {
json += r.readLine();
}
error = gson.fromJson(json, ApiError.class);
info = error.getDesc();
System.out.println(info);
} }
System.out.println(json);
error = gson.fromJson(json, ApiError.class);
info = error.getDesc();
System.out.println(info);
} }
con.disconnect(); con.disconnect();
if(info == null) info = "An unknown error occured";
parent.onFinishUploading(success, info); parent.onFinishUploading(success, info);
uploading = false; uploading = false;

View File

@@ -7,7 +7,7 @@ import java.util.Map;
public class QueryBuilder { public class QueryBuilder {
private static final String API_BASE_URL = "http://ReplayMod.com/api/"; public static final String API_BASE_URL = "http://ReplayMod.com/api/";
public String apiMethod; public String apiMethod;
public Map<String,String> paramMap; public Map<String,String> paramMap;

View File

@@ -13,6 +13,21 @@ public class FileInfo {
private int downloads; private int downloads;
private String name; private String name;
private boolean thumbnail; private boolean thumbnail;
public FileInfo(int id, ReplayMetaData metadata, String owner,
Rating ratings, int size, int category, int downloads, String name,
boolean thumbnail) {
this.id = id;
this.metadata = metadata;
this.owner = owner;
this.ratings = ratings;
this.size = size;
this.category = category;
this.downloads = downloads;
this.name = name;
this.thumbnail = thumbnail;
}
public int getId() { public int getId() {
return id; return id;
@@ -38,6 +53,9 @@ public class FileInfo {
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String name) {
this.name = name;
}
public boolean hasThumbnail() { public boolean hasThumbnail() {
return thumbnail; return thumbnail;
} }

View File

@@ -34,7 +34,8 @@ public class CameraEntity extends EntityPlayer {
//frac = time since last tick //frac = time since last tick
public void updateMovement() { public void updateMovement() {
Minecraft mc = Minecraft.getMinecraft(); Minecraft mc = Minecraft.getMinecraft();
if(ReplayHandler.getCameraEntity() != null && mc.thePlayer != null) { if(ReplayHandler.getCameraEntity() != null && mc.thePlayer != null
&& mc.getRenderViewEntity() != null) {
//Aligns the particle rotation //Aligns the particle rotation
mc.thePlayer.rotationPitch = mc.getRenderViewEntity().rotationPitch; mc.thePlayer.rotationPitch = mc.getRenderViewEntity().rotationPitch;
mc.thePlayer.rotationYaw = mc.getRenderViewEntity().rotationYaw; mc.thePlayer.rotationYaw = mc.getRenderViewEntity().rotationYaw;

View File

@@ -13,6 +13,7 @@ import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.GuiOptions; import net.minecraft.client.gui.GuiOptions;
import net.minecraft.client.gui.GuiVideoSettings; import net.minecraft.client.gui.GuiVideoSettings;
import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.resources.I18n; import net.minecraft.client.resources.I18n;
import net.minecraft.client.settings.GameSettings.Options; import net.minecraft.client.settings.GameSettings.Options;
import net.minecraftforge.client.event.GuiOpenEvent; import net.minecraftforge.client.event.GuiOpenEvent;
@@ -56,9 +57,9 @@ public class GuiEventHandler {
event.gui = null; event.gui = null;
return; return;
} }
if(!(event.gui instanceof GuiReplayManager || event.gui instanceof GuiUploadFile)) ResourceHelper.freeAllResources(); if(!(event.gui instanceof GuiReplayManager || event.gui instanceof GuiUploadFile)) ResourceHelper.freeAllResources();
if(event.gui instanceof GuiMainMenu) { if(event.gui instanceof GuiMainMenu) {
if(ReplayMod.firstMainMenu) { if(ReplayMod.firstMainMenu) {
ReplayMod.firstMainMenu = false; ReplayMod.firstMainMenu = false;
@@ -162,20 +163,20 @@ public class GuiEventHandler {
if(ReplayHandler.replayActive() && event.gui instanceof GuiIngameMenu && event.button.id == 1) { if(ReplayHandler.replayActive() && event.gui instanceof GuiIngameMenu && event.button.id == 1) {
event.button.enabled = false; event.button.enabled = false;
Thread t = new Thread(new Runnable() {
@Override mc.gameSettings.setOptionFloatValue(Options.GAMMA, ReplayHandler.getInitialGamma());
public void run() {
ReplayHandler.endReplay();
mc.gameSettings.setOptionFloatValue(Options.GAMMA, ReplayHandler.getInitialGamma()); ReplayHandler.lastExit = System.currentTimeMillis();
ReplayHandler.lastExit = System.currentTimeMillis(); /* This is already being executed by the default Exit action handling (vanilla code)
mc.theWorld.sendQuittingDisconnectingPacket(); mc.theWorld.sendQuittingDisconnectingPacket();
mc.loadWorld((WorldClient)null);
mc.displayGuiScreen(new GuiMainMenu());
*/
ReplayHandler.endReplay();
ReplayGuiRegistry.show(); ReplayGuiRegistry.show();
}
});
t.start();
} }
} }

View File

@@ -90,7 +90,7 @@ public class GuiReplayOverlay extends Gui {
private static boolean requestScreenshot = false; private static boolean requestScreenshot = false;
private Field drawBlockOutline; //private Field drawBlockOutline;
public static void requestScreenshot() { public static void requestScreenshot() {
requestScreenshot = true; requestScreenshot = true;
@@ -98,13 +98,13 @@ public class GuiReplayOverlay extends Gui {
public GuiReplayOverlay() { public GuiReplayOverlay() {
try { try {
drawBlockOutline = EntityRenderer.class.getDeclaredField(MCPNames.field("field_175073_D")); // drawBlockOutline = EntityRenderer.class.getDeclaredField(MCPNames.field("field_175073_D"));
drawBlockOutline.setAccessible(true); // drawBlockOutline.setAccessible(true);
drawBlockOutline.set(Minecraft.getMinecraft().entityRenderer, false); // drawBlockOutline.set(Minecraft.getMinecraft().entityRenderer, false);
} catch(Exception e) {} } catch(Exception e) {}
} }
@SubscribeEvent //@SubscribeEvent TODO
public void renderHand(RenderHandEvent event) { public void renderHand(RenderHandEvent event) {
if(ReplayHandler.replayActive()) { if(ReplayHandler.replayActive()) {
event.setCanceled(true); event.setCanceled(true);
@@ -135,7 +135,8 @@ public class GuiReplayOverlay extends Gui {
if(mc != null && mc.thePlayer != null) if(mc != null && mc.thePlayer != null)
MinecraftTicker.runMouseKeyboardTick(mc); MinecraftTicker.runMouseKeyboardTick(mc);
} }
if(mc.getRenderViewEntity() == mc.thePlayer || !mc.getRenderViewEntity().isEntityAlive()) { if(mc.getRenderViewEntity() == mc.thePlayer || !mc.getRenderViewEntity().isEntityAlive()
&& ReplayHandler.getCameraEntity() != null) {
ReplayHandler.spectateCamera(); ReplayHandler.spectateCamera();
ReplayHandler.getCameraEntity().movePath(new Position(lastX, lastY, lastZ, lastPitch, lastYaw)); ReplayHandler.getCameraEntity().movePath(new Position(lastX, lastY, lastZ, lastPitch, lastYaw));
} else if(!ReplayHandler.isCamera()) { } else if(!ReplayHandler.isCamera()) {
@@ -169,6 +170,7 @@ public class GuiReplayOverlay extends Gui {
@SubscribeEvent @SubscribeEvent
public void onRenderGui(RenderGameOverlayEvent.Post event) throws IllegalArgumentException, IllegalAccessException { public void onRenderGui(RenderGameOverlayEvent.Post event) throws IllegalArgumentException, IllegalAccessException {
if(!ReplayHandler.replayActive() || FMLClientHandler.instance().isGUIOpen(GuiSpectateSelection.class) || VideoWriter.isRecording()) { if(!ReplayHandler.replayActive() || FMLClientHandler.instance().isGUIOpen(GuiSpectateSelection.class) || VideoWriter.isRecording()) {
return; return;
} }
@@ -185,7 +187,7 @@ public class GuiReplayOverlay extends Gui {
} }
GL11.glEnable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_BLEND);
drawBlockOutline.set(Minecraft.getMinecraft().entityRenderer, false); // drawBlockOutline.set(Minecraft.getMinecraft().entityRenderer, false);
if(!ReplayHandler.replayActive()) { if(!ReplayHandler.replayActive()) {
return; return;
@@ -750,7 +752,7 @@ public class GuiReplayOverlay extends Gui {
} }
private void addPlaceKeyframe() { private void addPlaceKeyframe() {
CameraEntity cam = ReplayHandler.getCameraEntity(); Entity cam = mc.getRenderViewEntity();
if(cam == null) return; if(cam == null) return;
ReplayHandler.addKeyframe(new PositionKeyframe(ReplayHandler.getRealTimelineCursor(), new Position(cam.posX, cam.posY, cam.posZ, cam.rotationPitch, cam.rotationYaw))); ReplayHandler.addKeyframe(new PositionKeyframe(ReplayHandler.getRealTimelineCursor(), new Position(cam.posX, cam.posY, cam.posZ, cam.rotationPitch, cam.rotationYaw)));
} }

View File

@@ -2,7 +2,6 @@ package eu.crushedpixel.replaymod.gui;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
@@ -15,47 +14,31 @@ import javax.imageio.ImageIO;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiListExtended.IGuiListEntry; import net.minecraft.client.gui.GuiListExtended.IGuiListEntry;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.texture.DynamicTexture; import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
import eu.crushedpixel.replaymod.gui.replaymanager.ResourceHelper; import eu.crushedpixel.replaymod.gui.replaymanager.ResourceHelper;
import eu.crushedpixel.replaymod.recording.ReplayMetaData;
public class GuiReplayListEntry implements IGuiListEntry { public class GuiReplayListEntry implements IGuiListEntry {
private Minecraft minecraft = Minecraft.getMinecraft(); private Minecraft minecraft = Minecraft.getMinecraft();
private final DateFormat dateFormat = new SimpleDateFormat(); private final DateFormat dateFormat = new SimpleDateFormat();
private ReplayMetaData metaData; private FileInfo fileInfo;
private String fileName;
private ResourceLocation textureResource; private ResourceLocation textureResource;
private DynamicTexture dynTex = null; private DynamicTexture dynTex = null;
private File imageFile; private File imageFile;
private BufferedImage image = null; private BufferedImage image = null;
public ReplayMetaData getMetaData() {
return metaData;
}
public void setMetaData(ReplayMetaData metaData) {
this.metaData = metaData;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
private GuiReplayListExtended parent; private GuiReplayListExtended parent;
public FileInfo getFileInfo() {
return fileInfo;
}
public GuiReplayListEntry(GuiReplayListExtended parent, String fileName, ReplayMetaData metaData, File imageFile) { public GuiReplayListEntry(GuiReplayListExtended parent, FileInfo fileInfo, File imageFile) {
this.metaData = metaData; this.fileInfo = fileInfo;
this.fileName = fileName;
this.parent = parent; this.parent = parent;
dynTex = null; dynTex = null;
this.imageFile = imageFile; this.imageFile = imageFile;
@@ -66,7 +49,10 @@ public class GuiReplayListEntry implements IGuiListEntry {
@Override @Override
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected) { public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected) {
try { try {
minecraft.fontRendererObj.drawString(fileName, x + 3, y + 1, 16777215); if(fileInfo.getName() == null || fileInfo.getName().length() < 1) {
fileInfo.setName("No Name");
}
minecraft.fontRendererObj.drawString(fileInfo.getName(), x + 3, y + 1, 16777215);
if(y < -slotHeight || y > parent.height) { if(y < -slotHeight || y > parent.height) {
if(registered) { if(registered) {
@@ -79,7 +65,7 @@ public class GuiReplayListEntry implements IGuiListEntry {
return; return;
} else { } else {
if(!registered) { if(!registered) {
textureResource = new ResourceLocation("thumbs/"+fileName); textureResource = new ResourceLocation("thumbs/"+fileInfo.getName()+fileInfo.getId());
if(imageFile == null) { if(imageFile == null) {
image = ResourceHelper.getDefaultThumbnail(); image = ResourceHelper.getDefaultThumbnail();
} else { } else {
@@ -97,12 +83,12 @@ public class GuiReplayListEntry implements IGuiListEntry {
} }
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<String>();
list.add(metaData.getServerName()+" ("+dateFormat.format(new Date(metaData.getDate()))+")"); list.add(fileInfo.getMetadata().getServerName()+" ("+dateFormat.format(new Date(fileInfo.getMetadata().getDate()))+")");
list.add(String.format("%02dm%02ds", list.add(String.format("%02dm%02ds",
TimeUnit.MILLISECONDS.toMinutes(metaData.getDuration()), TimeUnit.MILLISECONDS.toMinutes(fileInfo.getMetadata().getDuration()),
TimeUnit.MILLISECONDS.toSeconds(metaData.getDuration()) - TimeUnit.MILLISECONDS.toSeconds(fileInfo.getMetadata().getDuration()) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(metaData.getDuration())) TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(fileInfo.getMetadata().getDuration()))
)); ));
for (int l1 = 0; l1 < Math.min(list.size(), 2); ++l1) { for (int l1 = 0; l1 < Math.min(list.size(), 2); ++l1) {

View File

@@ -13,7 +13,7 @@ import net.minecraft.util.MathHelper;
import org.lwjgl.input.Mouse; import org.lwjgl.input.Mouse;
import eu.crushedpixel.replaymod.recording.ReplayMetaData; import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
public abstract class GuiReplayListExtended extends GuiListExtended { public abstract class GuiReplayListExtended extends GuiListExtended {
@@ -81,8 +81,8 @@ public abstract class GuiReplayListExtended extends GuiListExtended {
entries = new ArrayList<GuiReplayListEntry>(); entries = new ArrayList<GuiReplayListEntry>();
} }
public void addEntry(String fileName, ReplayMetaData metaData, File image) { public void addEntry(FileInfo fileInfo, File image) {
entries.add(new GuiReplayListEntry(this, fileName, metaData, image)); entries.add(new GuiReplayListEntry(this, fileInfo, image));
} }
@Override @Override

View File

@@ -3,6 +3,7 @@ package eu.crushedpixel.replaymod.gui;
import java.awt.Color; import java.awt.Color;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
@@ -14,7 +15,6 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EnumPlayerModelParts; import net.minecraft.entity.player.EnumPlayerModelParts;
import net.minecraft.potion.Potion; import net.minecraft.potion.Potion;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.versioning.ComparableVersion;
import com.mojang.realmsclient.util.Pair; import com.mojang.realmsclient.util.Pair;
@@ -53,7 +53,7 @@ public class GuiSpectateSelection extends GuiScreen {
public GuiSpectateSelection(List<EntityPlayer> players) { public GuiSpectateSelection(List<EntityPlayer> players) {
this.prevSpeed = ReplayHandler.getSpeed(); this.prevSpeed = ReplayHandler.getSpeed();
players.sort(new PlayerComparator()); Collections.sort(players, new PlayerComparator());
this.players = new ArrayList<Pair<EntityPlayer, ResourceLocation>>(); this.players = new ArrayList<Pair<EntityPlayer, ResourceLocation>>();

View File

@@ -17,6 +17,8 @@ import org.lwjgl.input.Keyboard;
import eu.crushedpixel.replaymod.ReplayMod; import eu.crushedpixel.replaymod.ReplayMod;
import eu.crushedpixel.replaymod.api.client.ApiException; import eu.crushedpixel.replaymod.api.client.ApiException;
import eu.crushedpixel.replaymod.api.client.SearchPagination;
import eu.crushedpixel.replaymod.api.client.SearchQuery;
import eu.crushedpixel.replaymod.api.client.holders.FileInfo; import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
import eu.crushedpixel.replaymod.gui.GuiConstants; import eu.crushedpixel.replaymod.gui.GuiConstants;
import eu.crushedpixel.replaymod.gui.GuiReplayListExtended; import eu.crushedpixel.replaymod.gui.GuiReplayListExtended;
@@ -35,12 +37,25 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
private Tab currentTab = Tab.RECENT_FILES; private Tab currentTab = Tab.RECENT_FILES;
private static final SearchQuery recentFileSearchQuery = new SearchQuery(false, null, null, null, null, null,
null, null, null, null);
private static final SearchQuery bestFileSearchQuery = new SearchQuery(true, null, null, null, null, null,
null, null, null, null);
private final SearchPagination recentFilePagination = new SearchPagination(recentFileSearchQuery);
private final SearchPagination bestFilePagination = new SearchPagination(bestFileSearchQuery);
private SearchPagination myFilePagination;
@Override @Override
public void initGui() { public void initGui() {
Keyboard.enableRepeatEvents(true); Keyboard.enableRepeatEvents(true);
if(!AuthenticationHandler.isAuthenticated()) {
mc.displayGuiScreen(new GuiLoginPrompt(new GuiMainMenu(), this)); if(AuthenticationHandler.isAuthenticated()) {
return; SearchQuery query = new SearchQuery();
query.auth = AuthenticationHandler.getKey();
query.order = false;
myFilePagination = new SearchPagination(query);
} }
//Top Button Bar //Top Button Bar
@@ -53,6 +68,7 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
buttonBar.add(bestButton); buttonBar.add(bestButton);
GuiButton ownReplayButton = new GuiButton(GuiConstants.CENTER_MY_REPLAYS_BUTTON, 20, 30, "My Replays"); GuiButton ownReplayButton = new GuiButton(GuiConstants.CENTER_MY_REPLAYS_BUTTON, 20, 30, "My Replays");
ownReplayButton.enabled = AuthenticationHandler.isAuthenticated();
buttonBar.add(ownReplayButton); buttonBar.add(ownReplayButton);
GuiButton searchButton = new GuiButton(GuiConstants.CENTER_SEARCH_BUTTON, 20, 30, "Search"); GuiButton searchButton = new GuiButton(GuiConstants.CENTER_SEARCH_BUTTON, 20, 30, "Search");
@@ -115,9 +131,9 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
} else if(button.id == GuiConstants.CENTER_RECENT_BUTTON) { } else if(button.id == GuiConstants.CENTER_RECENT_BUTTON) {
showOnlineRecent(); showOnlineRecent();
} else if(button.id == GuiConstants.CENTER_BEST_BUTTON) { } else if(button.id == GuiConstants.CENTER_BEST_BUTTON) {
showOnlineBest();
} else if(button.id == GuiConstants.CENTER_MY_REPLAYS_BUTTON) { } else if(button.id == GuiConstants.CENTER_MY_REPLAYS_BUTTON) {
showOnlineOwnFiles();
} else if(button.id == GuiConstants.CENTER_SEARCH_BUTTON) { } else if(button.id == GuiConstants.CENTER_SEARCH_BUTTON) {
} }
@@ -188,40 +204,67 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
Keyboard.enableRepeatEvents(false); Keyboard.enableRepeatEvents(false);
} }
private void updateCurrentList(ReplayFileList list, SearchPagination pagination) {
currentList = list;
if(currentList == null) {
currentList = new ReplayFileList(mc, width, height, 50, height-40, 36);
} else {
currentList.clearEntries();
currentList.width = width;
currentList.height = height;
currentList.top = 50;
currentList.bottom = height-40;
}
if(pagination.getLoadedPages() < 0) {
pagination.fetchPage();
}
for(FileInfo i : pagination.getFiles()) {
try {
File tmp = null;
if(i.hasThumbnail()) {
tmp = File.createTempFile("thumb_online_"+i.getId(), "jpg");
ReplayMod.apiClient.downloadThumbnail(i.getId(), tmp);
}
currentList.addEntry(i, tmp);
} catch(Exception e) {
e.printStackTrace();
}
}
}
public void showOnlineRecent() { public void showOnlineRecent() {
Thread t = new Thread(new Runnable() { Thread t = new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
try { updateCurrentList(recentFileList, recentFilePagination);
if(recentFileList == null) { currentTab = Tab.RECENT_FILES;
recentFileList = new ReplayFileList(mc, width, height, 50, height-40, 36);
} else {
recentFileList.clearEntries();
recentFileList.width = width;
recentFileList.height = height;
recentFileList.top = 50;
recentFileList.bottom = height-40;
}
currentTab = Tab.RECENT_FILES;
currentList = recentFileList;
FileInfo[] files = ReplayMod.apiClient.getRecentFiles();
for(FileInfo i : files) {
File tmp = null;
if(i.hasThumbnail()) {
tmp = File.createTempFile("thumb_online_"+i.getId(), "jpg");
ReplayMod.apiClient.downloadThumbnail(i.getId(), tmp);
}
recentFileList.addEntry(i.getName(), i.getMetadata(), tmp);
}
} catch (IOException e) {
e.printStackTrace();
} catch (ApiException e) { //TODO: Error message
e.printStackTrace();
}
} }
}); });
t.start(); t.start();
}
public void showOnlineBest() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
updateCurrentList(bestFileList, bestFilePagination);
currentTab = Tab.BEST_FILES;
}
});
t.start();
}
public void showOnlineOwnFiles() {
if(!AuthenticationHandler.isAuthenticated() || myFilePagination == null) return;
Thread t = new Thread(new Runnable() {
@Override
public void run() {
updateCurrentList(myFileList, myFilePagination);
currentTab = Tab.MY_FILES;
}
});
t.start();
} }
} }

View File

@@ -37,6 +37,7 @@ import org.lwjgl.input.Keyboard;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.mojang.realmsclient.util.Pair; import com.mojang.realmsclient.util.Pair;
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
import eu.crushedpixel.replaymod.gui.GuiReplayListExtended; import eu.crushedpixel.replaymod.gui.GuiReplayListExtended;
import eu.crushedpixel.replaymod.gui.GuiReplaySettings; import eu.crushedpixel.replaymod.gui.GuiReplaySettings;
import eu.crushedpixel.replaymod.gui.online.GuiUploadFile; import eu.crushedpixel.replaymod.gui.online.GuiUploadFile;
@@ -122,7 +123,9 @@ public class GuiReplayManager extends GuiScreen implements GuiYesNoCallback {
Collections.sort(replayFileList, new FileAgeComparator()); Collections.sort(replayFileList, new FileAgeComparator());
for(Pair<Pair<File, ReplayMetaData>, File> p : replayFileList) { for(Pair<Pair<File, ReplayMetaData>, File> p : replayFileList) {
replayGuiList.addEntry(FilenameUtils.getBaseName(p.first().first().getName()), p.first().second(), p.second()); FileInfo fileInfo = new FileInfo(-1, p.first().second(), null, null,
-1, -1, -1, FilenameUtils.getBaseName(p.first().first().getName()), true);
replayGuiList.addEntry(fileInfo, p.second());
} }
} }
@@ -204,7 +207,7 @@ public class GuiReplayManager extends GuiScreen implements GuiYesNoCallback {
mc.displayGuiScreen(parentScreen); mc.displayGuiScreen(parentScreen);
} }
else if(button.id == DELETE_BUTTON_ID) { else if(button.id == DELETE_BUTTON_ID) {
String s = replayGuiList.getListEntry(replayGuiList.selected).getFileName(); String s = replayGuiList.getListEntry(replayGuiList.selected).getFileInfo().getName();
if (s != null) { if (s != null) {
delete_file = true; delete_file = true;

View File

@@ -4,24 +4,27 @@ import java.lang.reflect.Field;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.EntityRenderer; import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.network.play.server.S0CPacketSpawnPlayer;
import net.minecraftforge.client.GuiIngameForge; import net.minecraftforge.client.GuiIngameForge;
import eu.crushedpixel.replaymod.reflection.MCPNames; import eu.crushedpixel.replaymod.reflection.MCPNames;
public class ReplayGuiRegistry { public class ReplayGuiRegistry {
private static Field renderHand; //private static Field renderHand;
private static Minecraft mc = Minecraft.getMinecraft(); private static Minecraft mc = Minecraft.getMinecraft();
public static boolean hidden = false; public static boolean hidden = false;
/*
static { static {
try { try {
renderHand = EntityRenderer.class.getDeclaredField(MCPNames.field("field_175074_C")); //renderHand = EntityRenderer.class.getDeclaredField(MCPNames.field("field_175074_C"));
renderHand.setAccessible(true); //renderHand.setAccessible(true);
} catch(Exception e) { } catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
*/
public static void hide() { public static void hide() {
if(hidden) return; if(hidden) return;
@@ -39,11 +42,13 @@ public class ReplayGuiRegistry {
GuiIngameForge.renderJumpBar = false; GuiIngameForge.renderJumpBar = false;
GuiIngameForge.renderObjective = false; GuiIngameForge.renderObjective = false;
/*
try { try {
renderHand.set(mc.entityRenderer, false); renderHand.set(mc.entityRenderer, false);
} catch(Exception e) { } catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
*/
hidden = true; hidden = true;
} }
@@ -65,11 +70,13 @@ public class ReplayGuiRegistry {
GuiIngameForge.renderJumpBar = true; GuiIngameForge.renderJumpBar = true;
GuiIngameForge.renderObjective = true; GuiIngameForge.renderObjective = true;
/*
try { try {
renderHand.set(mc.entityRenderer, true); renderHand.set(mc.entityRenderer, true);
} catch(Exception e) { } catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
*/
hidden = false; hidden = false;
} }

View File

@@ -39,7 +39,6 @@ public class MCTimerHandler {
try { try {
if(!(getTimer() instanceof ReplayTimer)) { if(!(getTimer() instanceof ReplayTimer)) {
timerBefore = getTimer(); timerBefore = getTimer();
System.out.println("here");
mcTimer.set(mc, rpt); mcTimer.set(mc, rpt);
} }
} catch(Exception e) { } catch(Exception e) {
@@ -152,12 +151,12 @@ public class MCTimerHandler {
} }
return 1; return 1;
} }
public static void updateTimer(double d) { public static void updateTimer(double d) {
try{ try {
Timer t = getTimer(); Timer t = getTimer();
double d2 = d; double d2 = d;
d2 = MathHelper.clamp_double(d2, 0.0D, 1.0D); //d2 = MathHelper.clamp_double(d2, 0.0D, 1.0D);
t.elapsedPartialTicks = (float)((double)t.elapsedPartialTicks + d2 * (double)t.timerSpeed * 20); t.elapsedPartialTicks = (float)((double)t.elapsedPartialTicks + d2 * (double)t.timerSpeed * 20);
t.elapsedTicks = (int)t.elapsedPartialTicks; t.elapsedTicks = (int)t.elapsedPartialTicks;
t.elapsedPartialTicks -= (float)t.elapsedTicks; t.elapsedPartialTicks -= (float)t.elapsedTicks;

View File

@@ -361,6 +361,9 @@ public class ReplayHandler {
ReplayMod.overlay.resetUI(); ReplayMod.overlay.resetUI();
} catch(Exception e) {} } catch(Exception e) {}
//Load lighting and trigger update
ReplayMod.replaySettings.setLightingEnabled(ReplayMod.replaySettings.isLightingEnabled());
replayActive = true; replayActive = true;
} }
@@ -397,9 +400,11 @@ public class ReplayHandler {
resetKeyframes(); resetKeyframes();
if(channel != null) { /*
if(channel != null && channel.isOpen()) {
channel.close(); channel.close();
} }
*/
replayActive = false; replayActive = false;
} }

View File

@@ -330,7 +330,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
dis = new DataInputStream(archive.getInputStream(replayEntry)); dis = new DataInputStream(archive.getInputStream(replayEntry));
setReplaySpeed(0); setReplaySpeed(0);
} catch(IOException e) { } catch(IOException e) {
e.printStackTrace(); //e.printStackTrace();
} }
} }
} }
@@ -442,6 +442,8 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
difficulty, maxPlayers, worldType, false); difficulty, maxPlayers, worldType, false);
} }
/*
* Proof of concept for some nasty player manipulation ;)
String crPxl = "2cb08a5951f34e98bd0985d9747e80df"; String crPxl = "2cb08a5951f34e98bd0985d9747e80df";
String johni = "cd3d4be14ffc2f9db432db09e0cd254b"; String johni = "cd3d4be14ffc2f9db432db09e0cd254b";
@@ -469,6 +471,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
p = sp; p = sp;
} }
*/
if(p instanceof S07PacketRespawn) { if(p instanceof S07PacketRespawn) {
allowMovement = true; allowMovement = true;

View File

@@ -5,7 +5,10 @@ import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiOptions;
import net.minecraft.client.gui.GuiVideoSettings;
import net.minecraft.client.settings.GameSettings.Options; import net.minecraft.client.settings.GameSettings.Options;
import net.minecraft.entity.player.EnumPlayerModelParts;
import net.minecraft.util.Timer; import net.minecraft.util.Timer;
import net.minecraftforge.common.config.Property; import net.minecraftforge.common.config.Property;
import eu.crushedpixel.replaymod.ReplayMod; import eu.crushedpixel.replaymod.ReplayMod;
@@ -90,6 +93,7 @@ public class ReplaySettings {
public boolean isLightingEnabled() { public boolean isLightingEnabled() {
return lightingEnabled; return lightingEnabled;
} }
public void setLightingEnabled(boolean enabled) { public void setLightingEnabled(boolean enabled) {
this.lightingEnabled = enabled; this.lightingEnabled = enabled;
if(enabled) { if(enabled) {