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,139 @@
package eu.crushedpixel.replaymod.gui;
import io.netty.channel.SimpleChannelInboundHandler;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Calendar;
import java.util.Date;
import eu.crushedpixel.replaymod.reflection.MCPNames;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiButtonLanguage;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.GuiSelectWorld;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.client.resources.I18n;
import net.minecraft.network.Packet;
public class GuiCustomMainMenu extends GuiMainMenu {
private static final int REPLAY_MANAGER_ID = 9001;
@Override
public void initGui() {
Class<? extends GuiMainMenu> clazz = GuiMainMenu.class;
int i1 = this.height / 4 + 48;
this.buttonList.add(new GuiButton(REPLAY_MANAGER_ID, this.width / 2 - 100, i1 + 2*24, I18n.format("Replay Manager", new Object[0])));
try {
Field viewportTexture = clazz.getDeclaredField(MCPNames.field("field_73977_n"));
viewportTexture.setAccessible(true);
viewportTexture.set(this, new DynamicTexture(256, 256));
Field field_110351_G = clazz.getDeclaredField(MCPNames.field("field_110351_G"));
field_110351_G.setAccessible(true);
field_110351_G.set(this, this.mc.getTextureManager().getDynamicTextureLocation("background", (DynamicTexture)viewportTexture.get(this)));
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
Field splashText = clazz.getDeclaredField(MCPNames.field("field_73975_c"));
splashText.setAccessible(true);
if (calendar.get(2) + 1 == 11 && calendar.get(5) == 9)
{
splashText.set(this, "Happy birthday, ez!");
}
else if (calendar.get(2) + 1 == 6 && calendar.get(5) == 1)
{
splashText.set(this, "Happy birthday, Notch!");
}
else if (calendar.get(2) + 1 == 12 && calendar.get(5) == 24)
{
splashText.set(this, "Merry X-Mas!");
}
else if (calendar.get(2) + 1 == 1 && calendar.get(5) == 1)
{
splashText.set(this, "Happy new year!");
}
else if (calendar.get(2) + 1 == 10 && calendar.get(5) == 31)
{
splashText.set(this, "OOoooOOOoooo! Spooky!");
}
boolean flag = true;
int i = this.height / 4 + 48;
if (this.mc.isDemo())
{
Method addDemoButtons = clazz.getDeclaredMethod(MCPNames.method("func_73972_b"), int.class, int.class);
addDemoButtons.setAccessible(true);
addDemoButtons.invoke(this, i, 24);
}
else
{
Method addSingleplayerMultiplayerButtons = clazz.getDeclaredMethod(MCPNames.method("func_73969_a"), int.class, int.class);
addSingleplayerMultiplayerButtons.setAccessible(true);
addSingleplayerMultiplayerButtons.invoke(this, i - 24, 24);
}
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, i + 72 + 12, 98, 20, I18n.format("menu.options", new Object[0])));
this.buttonList.add(new GuiButton(4, this.width / 2 + 2, i + 72 + 12, 98, 20, I18n.format("menu.quit", new Object[0])));
this.buttonList.add(new GuiButtonLanguage(5, this.width / 2 - 124, i + 72 + 12));
Field threadLock = clazz.getDeclaredField(MCPNames.field("field_104025_t"));
threadLock.setAccessible(true);
Object object = threadLock.get(this);
Field field_92023_s = clazz.getDeclaredField(MCPNames.field("field_92023_s"));
field_92023_s.setAccessible(true);
Field openGLWarning1 = clazz.getDeclaredField(MCPNames.field("openGLWarning1"));
openGLWarning1.setAccessible(true);
Field openGLWarning2 = clazz.getDeclaredField(MCPNames.field("openGLWarning2"));
openGLWarning2.setAccessible(true);
Field field_92024_r = clazz.getDeclaredField(MCPNames.field("field_92024_r"));
field_92024_r.setAccessible(true);
Field field_92022_t = clazz.getDeclaredField(MCPNames.field("field_92022_t"));
field_92022_t.setAccessible(true);
Field field_92021_u = clazz.getDeclaredField(MCPNames.field("field_92021_u"));
field_92021_u.setAccessible(true);
Field field_92020_v = clazz.getDeclaredField(MCPNames.field("field_92020_v"));
field_92020_v.setAccessible(true);
Field field_92019_w = clazz.getDeclaredField(MCPNames.field("field_92019_w"));
field_92019_w.setAccessible(true);
synchronized (object)
{
field_92023_s.set(this, this.fontRendererObj.getStringWidth((String)openGLWarning1.get(this)));
field_92024_r.set(this, this.fontRendererObj.getStringWidth((String)openGLWarning2.get(this)));
int j = Math.max((Integer)(field_92023_s.get(this)), (Integer)(field_92024_r.get(this)));
field_92022_t.set(this, (this.width - j) / 2);
field_92021_u.set(this, ((GuiButton)this.buttonList.get(0)).yPosition - 24);
field_92020_v.set(this, (Integer)field_92022_t.get(this) + j);
field_92019_w.set(this, (Integer)field_92021_u.get(this) + 24);
}
} catch(Exception e) {
e.printStackTrace();
}
}
@Override
protected void actionPerformed(GuiButton button) throws IOException {
if(button.id == REPLAY_MANAGER_ID) {
this.mc.displayGuiScreen(new GuiReplayManager());
}
super.actionPerformed(button);
}
}

View File

@@ -0,0 +1,63 @@
package eu.crushedpixel.replaymod.gui;
import java.io.IOException;
import java.lang.reflect.Field;
import com.mojang.realmsclient.util.Pair;
import eu.crushedpixel.replaymod.reflection.MCPNames;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiCustomizeSkin;
import net.minecraft.client.gui.GuiOptionButton;
import net.minecraft.client.gui.GuiOptions;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.client.settings.GameSettings;
public class GuiCustomOptions extends GuiOptions {
public static GuiScreen getGuiScreen(GuiOptions go) {
try {
Class<GuiOptions> clazz = GuiOptions.class;
Field guiScreen = clazz.getDeclaredField(MCPNames.field(MCPNames.field("field_146441_g")));
guiScreen.setAccessible(true);
Object obj = guiScreen.get(go);
return (GuiScreen)obj;
} catch(Exception e) {
e.printStackTrace();
return null;
}
}
public static GameSettings getGameSettings(GuiOptions go) {
try {
Class<GuiOptions> clazz = GuiOptions.class;
Field gameSettings = clazz.getDeclaredField(MCPNames.field(MCPNames.field("field_146443_h")));
gameSettings.setAccessible(true);
Object obj = gameSettings.get(go);
return (GameSettings)obj;
} catch(Exception e) {
e.printStackTrace();
return null;
}
}
public GuiCustomOptions(GuiScreen guiScreen, GameSettings gameSettings) {
super(guiScreen, gameSettings);
}
@Override
public void initGui() {
super.initGui();
buttonList.add(new GuiButton(9001, this.width / 2 - 155, this.height / 6 + 48 - 6 - 24, 310, 20, "Replay Mod Settings..."));
}
@Override
public void actionPerformed(GuiButton button) throws IOException {
super.actionPerformed(button);
if (button.enabled && button.id == 9001) { //Replay Mod Settings...
this.mc.displayGuiScreen(new GuiReplaySettings(this));
}
}
}

View File

@@ -0,0 +1,65 @@
package eu.crushedpixel.replaymod.gui;
import java.io.IOException;
import eu.crushedpixel.replaymod.replay.ReplayHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiIngameMenu;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.resources.I18n;
public class GuiExitReplay extends GuiIngameMenu {
@Override
public void initGui()
{
this.buttonList.clear();
byte b0 = -16;
boolean flag = true;
this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 120 + b0, I18n.format("menu.returnToMenu", new Object[0])));
if (!this.mc.isIntegratedServerRunning())
{
((GuiButton)this.buttonList.get(0)).displayString = I18n.format("Exit Replay", new Object[0]);
}
this.buttonList.add(new GuiButton(4, this.width / 2 - 100, this.height / 4 + 24 + b0, I18n.format("menu.returnToGame", new Object[0])));
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 96 + b0, 98, 20, I18n.format("menu.options", new Object[0])));
this.buttonList.add(new GuiButton(12, this.width / 2 + 2, this.height / 4 + 96 + b0, 98, 20, I18n.format("fml.menu.modoptions")));
GuiButton guibutton;
this.buttonList.add(guibutton = new GuiButton(7, this.width / 2 - 100, this.height / 4 + 72 + b0, 200, 20, I18n.format("menu.shareToLan", new Object[0])));
this.buttonList.add(new GuiButton(5, this.width / 2 - 100, this.height / 4 + 48 + b0, 98, 20, I18n.format("gui.achievements", new Object[0])));
this.buttonList.add(new GuiButton(6, this.width / 2 + 2, this.height / 4 + 48 + b0, 98, 20, I18n.format("gui.stats", new Object[0])));
guibutton.enabled = this.mc.isSingleplayer() && !this.mc.getIntegratedServer().getPublic();
}
@Override
protected void actionPerformed(GuiButton button) throws IOException
{
if(button.id == 1) {
button.enabled = false;
Thread t = new Thread(new Runnable() {
@Override
public void run() {
ReplayHandler.endReplay();
ReplayHandler.setSpeed(1f);
ReplayHandler.lastExit = System.currentTimeMillis();
mc.theWorld.sendQuittingDisconnectingPacket();
mc.displayGuiScreen(new GuiMainMenu());
//mc.loadWorld((WorldClient)null);
}
});
t.run();
} else {
super.actionPerformed(button);
}
}
}

View File

@@ -0,0 +1,10 @@
package eu.crushedpixel.replaymod.gui;
import org.lwjgl.input.Keyboard;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
public class GuiMouseInput extends GuiScreen {
}

View File

@@ -0,0 +1,102 @@
package eu.crushedpixel.replaymod.gui;
import java.io.File;
import java.io.IOException;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.resources.I18n;
import org.apache.commons.io.FilenameUtils;
import org.lwjgl.input.Keyboard;
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
public class GuiRenameReplay extends GuiScreen
{
private GuiScreen field_146585_a;
private GuiTextField field_146583_f;
private static final String __OBFID = "CL_00000709";
private File file;
public GuiRenameReplay(GuiScreen parent, File file)
{
this.field_146585_a = parent;
this.file = file;
}
public void updateScreen()
{
this.field_146583_f.updateCursorCounter();
}
public void initGui()
{
Keyboard.enableRepeatEvents(true);
this.buttonList.clear();
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 96 + 12, I18n.format("Rename", new Object[0])));
this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 120 + 12, I18n.format("Cancel", new Object[0])));
String s = FilenameUtils.getBaseName(file.getAbsolutePath());
this.field_146583_f = new GuiTextField(2, this.fontRendererObj, this.width / 2 - 100, 60, 200, 20);
this.field_146583_f.setFocused(true);
this.field_146583_f.setText(s);
}
public void onGuiClosed()
{
Keyboard.enableRepeatEvents(false);
}
protected void actionPerformed(GuiButton button) throws IOException
{
if (button.enabled)
{
if (button.id == 1)
{
this.mc.displayGuiScreen(this.field_146585_a);
}
else if (button.id == 0)
{
File folder = new File("./replay_recordings/");
folder.mkdirs();
File initRenamed = new File(folder, this.field_146583_f.getText().trim()+ConnectionEventHandler.ZIP_FILE_EXTENSION.replaceAll("[^a-zA-Z0-9\\.\\-]", "_"));
File renamed = initRenamed;
int i=1;
while(renamed.isFile()) {
renamed = new File(initRenamed.getAbsolutePath()+"_"+i);
i++;
}
file.renameTo(renamed);
this.mc.displayGuiScreen(this.field_146585_a);
}
}
}
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
this.field_146583_f.textboxKeyTyped(typedChar, keyCode);
((GuiButton)this.buttonList.get(0)).enabled = this.field_146583_f.getText().trim().length() > 0;
if (keyCode == 28 || keyCode == 156)
{
this.actionPerformed((GuiButton)this.buttonList.get(0));
}
}
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
super.mouseClicked(mouseX, mouseY, mouseButton);
this.field_146583_f.mouseClicked(mouseX, mouseY, mouseButton);
}
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
this.drawCenteredString(this.fontRendererObj, I18n.format("Rename World", new Object[0]), this.width / 2, 20, 16777215);
this.drawString(this.fontRendererObj, I18n.format("Replay Name", new Object[0]), this.width / 2 - 100, 47, 10526880);
this.field_146583_f.drawTextBox();
super.drawScreen(mouseX, mouseY, partialTicks);
}
}

View File

@@ -0,0 +1,92 @@
package eu.crushedpixel.replaymod.gui;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiListExtended.IGuiListEntry;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import eu.crushedpixel.replaymod.recording.ReplayMetaData;
public class GuiReplayListEntry implements IGuiListEntry {
private Minecraft minecraft = Minecraft.getMinecraft();
private final DateFormat dateFormat = new SimpleDateFormat();
private ReplayMetaData metaData;
private String fileName;
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 boolean selected = false;
private GuiReplayListExtended parent;
public GuiReplayListEntry(GuiReplayListExtended parent, String fileName, ReplayMetaData metaData) {
this.metaData = metaData;
this.fileName = fileName;
this.parent = parent;
}
@Override
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected)
{
minecraft.fontRendererObj.drawString(fileName, x + 3, y + 1, 16777215);
List<String> list = new ArrayList<String>();
list.add(metaData.getServerName()+" ("+dateFormat.format(new Date(metaData.getDate()))+")");
list.add(String.format("%02dm%02ds",
TimeUnit.MILLISECONDS.toMinutes(metaData.getDuration()),
TimeUnit.MILLISECONDS.toSeconds(metaData.getDuration()) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(metaData.getDuration()))
));
for (int l1 = 0; l1 < Math.min(list.size(), 2); ++l1) {
minecraft.fontRendererObj.drawString((String)list.get(l1), x + 3, y + 12 + minecraft.fontRendererObj.FONT_HEIGHT * l1, 8421504);
}
}
@Override
public void setSelected(int p_178011_1_, int p_178011_2_, int p_178011_3_) {}
@Override
public boolean mousePressed(int p_148278_1_, int p_148278_2_,
int p_148278_3_, int p_148278_4_, int p_148278_5_, int p_148278_6_) {
for(int slot = 0; slot<parent.getSize(); slot++) {
if(parent.getListEntry(slot) == this) {
parent.elementClicked(slot, false, p_148278_5_, p_148278_6_);
break;
}
}
return true;
}
@Override
public void mouseReleased(int slotIndex, int x, int y, int mouseEvent,
int relativeX, int relativeY) {}
}

View File

@@ -0,0 +1,203 @@
package eu.crushedpixel.replaymod.gui;
import java.util.ArrayList;
import java.util.List;
import org.lwjgl.input.Mouse;
import eu.crushedpixel.replaymod.recording.ReplayMetaData;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiListExtended;
import net.minecraft.client.gui.ServerListEntryLanScan;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.resources.ResourcePackListEntry;
import net.minecraft.util.MathHelper;
public class GuiReplayListExtended extends GuiListExtended {
private GuiReplayManager parent;
public int selected = -1;
public GuiReplayListExtended(GuiReplayManager parent, Minecraft mcIn, int p_i45010_2_,
int p_i45010_3_, int p_i45010_4_, int p_i45010_5_, int p_i45010_6_) {
super(mcIn, p_i45010_2_, p_i45010_3_, p_i45010_4_, p_i45010_5_, p_i45010_6_);
this.parent = parent;
}
@Override
protected void elementClicked(int slotIndex, boolean isDoubleClick,
int mouseX, int mouseY) {
super.elementClicked(slotIndex, isDoubleClick, mouseX, mouseY);
this.selected = slotIndex;
parent.setButtonsEnabled(true);
if(isDoubleClick) {
parent.loadReplay(slotIndex);
}
}
@Override
protected void drawSelectionBox(int p_148120_1_, int p_148120_2_, int p_148120_3_, int p_148120_4_)
{
int i1 = this.getSize();
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
for (int j1 = 0; j1 < i1; ++j1)
{
int k1 = p_148120_2_ + j1 * this.slotHeight + this.headerPadding;
int l1 = this.slotHeight - 4;
if (k1 > this.bottom || k1 + l1 < this.top)
{
this.func_178040_a(j1, p_148120_1_, k1);
}
if (this.showSelectionBox && selected == j1)
{
int i2 = this.left + (this.width / 2 - this.getListWidth() / 2);
int j2 = this.left + this.width / 2 + this.getListWidth() / 2;
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.disableTexture2D();
worldrenderer.startDrawingQuads();
worldrenderer.setColorOpaque_I(8421504);
worldrenderer.addVertexWithUV((double)i2, (double)(k1 + l1 + 2), 0.0D, 0.0D, 1.0D);
worldrenderer.addVertexWithUV((double)j2, (double)(k1 + l1 + 2), 0.0D, 1.0D, 1.0D);
worldrenderer.addVertexWithUV((double)j2, (double)(k1 - 2), 0.0D, 1.0D, 0.0D);
worldrenderer.addVertexWithUV((double)i2, (double)(k1 - 2), 0.0D, 0.0D, 0.0D);
worldrenderer.setColorOpaque_I(0);
worldrenderer.addVertexWithUV((double)(i2 + 1), (double)(k1 + l1 + 1), 0.0D, 0.0D, 1.0D);
worldrenderer.addVertexWithUV((double)(j2 - 1), (double)(k1 + l1 + 1), 0.0D, 1.0D, 1.0D);
worldrenderer.addVertexWithUV((double)(j2 - 1), (double)(k1 - 1), 0.0D, 1.0D, 0.0D);
worldrenderer.addVertexWithUV((double)(i2 + 1), (double)(k1 - 1), 0.0D, 0.0D, 0.0D);
tessellator.draw();
GlStateManager.enableTexture2D();
}
this.drawSlot(j1, p_148120_1_, k1, l1, p_148120_3_, p_148120_4_);
}
}
private List<GuiReplayListEntry> entries = new ArrayList<GuiReplayListEntry>();
public void clearEntries() {
entries = new ArrayList<GuiReplayListEntry>();
}
public void addEntry(String fileName, ReplayMetaData metaData) {
entries.add(new GuiReplayListEntry(this, fileName, metaData));
}
@Override
public GuiReplayListEntry getListEntry(int index) {
return entries.get(index);
}
@Override
protected int getSize() {
return entries.size();
}
@Override
public void handleMouseInput()
{
if (this.isMouseYWithinSlotBounds(this.mouseY))
{
if (Mouse.isButtonDown(0))
{
if (this.initialClickY == -1.0F)
{
int i2 = this.getScrollBarX();
int i1 = i2 + 6;
boolean flag = true;
if (this.mouseY >= this.top && this.mouseY <= this.bottom && this.mouseX <= i1)
{
int i = this.width / 2 - this.getListWidth() / 2;
int j = this.width / 2 + this.getListWidth() / 2;
int k = this.mouseY - this.top - this.headerPadding + (int)this.amountScrolled - 4;
int l = k / this.slotHeight;
if (this.mouseX >= i && this.mouseX <= j && l >= 0 && k >= 0 && l < this.getSize())
{
boolean flag1 = l == this.selectedElement && Minecraft.getSystemTime() - this.lastClicked < 250L;
this.elementClicked(l, flag1, this.mouseX, this.mouseY);
this.selectedElement = l;
this.lastClicked = Minecraft.getSystemTime();
}
else if (this.mouseX >= i && this.mouseX <= j && k < 0)
{
this.func_148132_a(this.mouseX - i, this.mouseY - this.top + (int)this.amountScrolled - 4);
flag = false;
}
if (this.mouseX >= i2 && this.mouseX <= i1)
{
this.scrollMultiplier = -1.0F;
int j1 = this.func_148135_f();
if (j1 < 1)
{
j1 = 1;
}
int k1 = (int)((float)((this.bottom - this.top) * (this.bottom - this.top)) / (float)this.getContentHeight());
k1 = MathHelper.clamp_int(k1, 32, this.bottom - this.top - 8);
this.scrollMultiplier /= (float)(this.bottom - this.top - k1) / (float)j1;
}
else
{
this.scrollMultiplier = 1.0F;
}
if (flag)
{
this.initialClickY = (float)this.mouseY;
}
else
{
this.initialClickY = -2.0F;
}
}
else
{
this.initialClickY = -2.0F;
}
}
else if (this.initialClickY >= 0.0F)
{
this.amountScrolled -= ((float)this.mouseY - this.initialClickY) * this.scrollMultiplier;
this.initialClickY = (float)this.mouseY;
}
}
else
{
this.initialClickY = -1.0F;
}
int l1 = Mouse.getEventDWheel();
if (l1 != 0)
{
if (l1 > 0)
{
l1 = -1;
}
else if (l1 < 0)
{
l1 = 1;
}
this.amountScrolled += (float)(l1 * this.slotHeight / 2);
}
}
}
}

View File

@@ -0,0 +1,286 @@
package eu.crushedpixel.replaymod.gui;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.SocketAddress;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiYesNo;
import net.minecraft.client.gui.GuiYesNoCallback;
import net.minecraft.client.network.NetHandlerLoginClient;
import net.minecraft.client.resources.I18n;
import net.minecraft.network.EnumConnectionState;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.handshake.client.C00Handshake;
import net.minecraft.network.login.client.C00PacketLoginStart;
import net.minecraft.util.Util;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.commons.io.FilenameUtils;
import org.lwjgl.Sys;
import org.lwjgl.input.Keyboard;
import com.google.gson.Gson;
import com.mojang.realmsclient.util.Pair;
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
import eu.crushedpixel.replaymod.recording.ReplayMetaData;
import eu.crushedpixel.replaymod.replay.ReplayHandler;
import eu.crushedpixel.replaymod.replay.ReplaySender;
public class GuiReplayManager extends GuiScreen implements GuiYesNoCallback {
private GuiScreen parentScreen;
private GuiButton btnEditServer;
private GuiButton btnSelectServer;
private GuiButton btnDeleteServer;
private String hoveringText;
private boolean initialized;
private GuiReplayListExtended replayGuiList;
private List<Pair<File, ReplayMetaData>> replayFileList = new ArrayList<Pair<File, ReplayMetaData>>();
private GuiButton loadButton, folderButton, renameButton, deleteButton, cancelButton, settingsButton;
private static Gson gson = new Gson();
private boolean replaying = false;
private static final int LOAD_BUTTON_ID = 9001;
private static final int FOLDER_BUTTON_ID = 9002;
private static final int RENAME_BUTTON_ID = 9003;
private static final int DELETE_BUTTON_ID = 9004;
private static final int SETTINGS_BUTTON_ID = 9005;
private static final int CANCEL_BUTTON_ID = 9006;
private boolean delete_file = false;
private void reloadFiles() {
replayGuiList.clearEntries();
replayFileList = new ArrayList<Pair<File, ReplayMetaData>>();
File folder = new File("./replay_recordings/");
folder.mkdirs();
for(File file : folder.listFiles()) {
if(("."+FilenameUtils.getExtension(file.getAbsolutePath())).equals(ConnectionEventHandler.ZIP_FILE_EXTENSION)) {
try {
ZipFile archive = new ZipFile(file);
ZipArchiveEntry recfile = archive.getEntry("recording"+ConnectionEventHandler.TEMP_FILE_EXTENSION);
ZipArchiveEntry metadata = archive.getEntry("metaData"+ConnectionEventHandler.JSON_FILE_EXTENSION);
InputStream is = archive.getInputStream(metadata);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String json = br.readLine();
ReplayMetaData metaData = gson.fromJson(json, ReplayMetaData.class);
replayFileList.add(Pair.of(file, metaData));
archive.close();
} catch(Exception e) {
e.printStackTrace();
}
}
}
Collections.sort(replayFileList, new FileAgeComparator());
for(Pair<File, ReplayMetaData> p : replayFileList) {
replayGuiList.addEntry(FilenameUtils.getBaseName(p.first().getName()), p.second());
}
}
public class FileAgeComparator implements Comparator<Pair<File, ReplayMetaData>> {
@Override
public int compare(Pair<File, ReplayMetaData> o1, Pair<File, ReplayMetaData> o2) {
return (int) (o2.second().getDate() - o1.second().getDate());
}
}
public void initGui()
{
replayGuiList = new GuiReplayListExtended(this, this.mc, this.width, this.height, 32, this.height - 64, 36);
Keyboard.enableRepeatEvents(true);
this.buttonList.clear();
if (!this.initialized) {
this.initialized = true;
}
else {
this.replayGuiList.setDimensions(this.width, this.height, 32, this.height - 64);
}
reloadFiles();
this.createButtons();
}
private void createButtons() {
this.buttonList.add(loadButton = new GuiButton(LOAD_BUTTON_ID, this.width / 2 - 154, this.height - 52, 150, 20, I18n.format("Load Replay", new Object[0])));
this.buttonList.add(folderButton = new GuiButton(FOLDER_BUTTON_ID, this.width / 2 + 4, this.height - 52, 150, 20, I18n.format("Open Replay Folder...", new Object[0])));
this.buttonList.add(renameButton = new GuiButton(RENAME_BUTTON_ID, this.width / 2 - 154, this.height - 28, 72, 20, I18n.format("Rename", new Object[0])));
this.buttonList.add(deleteButton = new GuiButton(DELETE_BUTTON_ID, this.width / 2 - 76, this.height - 28, 72, 20, I18n.format("Delete", new Object[0])));
this.buttonList.add(settingsButton = new GuiButton(SETTINGS_BUTTON_ID, this.width / 2 + 4, this.height - 28, 72, 20, I18n.format("Settings", new Object[0])));
this.buttonList.add(cancelButton = new GuiButton(CANCEL_BUTTON_ID, this.width / 2 + 4 + 78, this.height - 28, 72, 20, I18n.format("Cancel", new Object[0])));
setButtonsEnabled(false);
}
public void handleMouseInput() throws IOException
{
super.handleMouseInput();
this.replayGuiList.handleMouseInput();
}
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
super.mouseClicked(mouseX, mouseY, mouseButton);
this.replayGuiList.mouseClicked(mouseX, mouseY, mouseButton);
}
protected void mouseReleased(int mouseX, int mouseY, int state)
{
super.mouseReleased(mouseX, mouseY, state);
this.replayGuiList.mouseReleased(mouseX, mouseY, state);
}
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.hoveringText = null;
this.drawDefaultBackground();
this.replayGuiList.drawScreen(mouseX, mouseY, partialTicks);
this.drawCenteredString(this.fontRendererObj, I18n.format("Replay Manager", new Object[0]), this.width / 2, 20, 16777215);
super.drawScreen(mouseX, mouseY, partialTicks);
}
@Override
protected void actionPerformed(GuiButton button) throws IOException
{
if (button.enabled) {
if(button.id == LOAD_BUTTON_ID) {
loadReplay(replayGuiList.selected);
}
else if (button.id == CANCEL_BUTTON_ID)
{
mc.displayGuiScreen(parentScreen);
}
else if (button.id == DELETE_BUTTON_ID)
{
String s = replayGuiList.getListEntry(replayGuiList.selected).getFileName();
if (s != null)
{
delete_file = true;
GuiYesNo guiyesno = getYesNoGui(this, s, 1);
this.mc.displayGuiScreen(guiyesno);
}
}
else if(button.id == SETTINGS_BUTTON_ID) {
this.mc.displayGuiScreen(new GuiReplaySettings(this));
}
else if(button.id == RENAME_BUTTON_ID)
{
File file = replayFileList.get(replayGuiList.selected).first();
this.mc.displayGuiScreen(new GuiRenameReplay(this, file));
}
else if(button.id == FOLDER_BUTTON_ID)
{
File file1 = new File("./replay_recordings/");
file1.mkdirs();
String s = file1.getAbsolutePath();
if (Util.getOSType() == Util.EnumOS.OSX)
{
try
{
Runtime.getRuntime().exec(new String[] {"/usr/bin/open", s});
return;
}
catch (IOException ioexception1) {}
}
else if (Util.getOSType() == Util.EnumOS.WINDOWS)
{
String s1 = String.format("cmd.exe /C start \"Open file\" \"%s\"", new Object[] {s});
try
{
Runtime.getRuntime().exec(s1);
return;
}
catch (IOException ioexception) {}
}
boolean flag = false;
try
{
Class oclass = Class.forName("java.awt.Desktop");
Object object = oclass.getMethod("getDesktop", new Class[0]).invoke((Object)null, new Object[0]);
oclass.getMethod("browse", new Class[] {URI.class}).invoke(object, new Object[] {file1.toURI()});
}
catch (Throwable throwable)
{
flag = true;
}
if (flag)
{
Sys.openURL("file://" + s);
}
}
}
}
public void confirmClicked(boolean result, int id) {
if (this.delete_file)
{
this.delete_file = false;
if (result)
{
replayFileList.get(replayGuiList.selected).first().delete();
replayFileList.remove(replayGuiList.selected);
}
this.mc.displayGuiScreen(this);
}
}
public static GuiYesNo getYesNoGui(GuiYesNoCallback p_152129_0_, String file, int p_152129_2_)
{
String s1 = I18n.format("Are you sure you want to delete this replay?", new Object[0]);
String s2 = "\'" + file + "\' " + I18n.format("will be lost forever! (A long time!)", new Object[0]);
String s3 = I18n.format("Delete", new Object[0]);
String s4 = I18n.format("Cancel", new Object[0]);
GuiYesNo guiyesno = new GuiYesNo(p_152129_0_, s1, s2, s3, s4, p_152129_2_);
return guiyesno;
}
public void setButtonsEnabled(boolean b) {
loadButton.enabled = b;
renameButton.enabled = b;
deleteButton.enabled = b;
}
public void loadReplay(int id)
{
mc.displayGuiScreen((GuiScreen)null);
try {
ReplayHandler.startReplay(replayFileList.get(id).first());
} catch(Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,133 @@
package eu.crushedpixel.replaymod.gui;
import java.awt.Color;
import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiOptionButton;
import net.minecraft.client.gui.GuiOptionSlider;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.fml.client.FMLClientHandler;
import eu.crushedpixel.replaymod.ReplayMod;
import eu.crushedpixel.replaymod.settings.ReplaySettings;
public class GuiReplaySettings extends GuiScreen {
private GuiScreen parentGuiScreen;
protected String screenTitle = "Replay Mod Settings";
private static final int MAXSIZE_SLIDER_ID = 9003;
private static final int RECORDSERVER_ID = 9004;
private static final int RECORDSP_ID = 9005;
private static final int SEND_CHAT = 9006;
private static final int FORCE_LINEAR = 9007;
private GuiButton recordServerButton, recordSPButton, sendChatButton, linearButton;
public GuiReplaySettings(GuiScreen parentGuiScreen)
{
this.parentGuiScreen = parentGuiScreen;
}
public void initGui() {
this.screenTitle = I18n.format("Replay Mod Settings", new Object[0]);
this.buttonList.clear();
this.buttonList.add(new GuiButton(200, this.width / 2 - 100, this.height - 27, I18n.format("gui.done", new Object[0])));
Map<String, Object> aoptions = ReplayMod.replaySettings.getOptions();
int k = 0;
int i = 0;
for (Entry<String, Object> e : aoptions.entrySet()) {
if(e.getKey().equals("Maximum File Size")) {
float minValue = -1;
float maxValue = 10000;
float valueSteps = 1;
int val = (Integer)e.getValue();
this.buttonList.add(new GuiSizeLimitOptionSlider(MAXSIZE_SLIDER_ID, this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), 0, 39, 1, val, e.getKey()));
} else if(e.getKey().equals("Enable Notifications")) {
sendChatButton = new GuiButton(SEND_CHAT, this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), 150, 20, "Enable Notifications: "+onOff((Boolean)e.getValue()));
this.buttonList.add(sendChatButton);
} else if(e.getKey().equals("Record Server")) {
recordServerButton = new GuiButton(RECORDSERVER_ID, this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), 150, 20, "Record Server: "+onOff((Boolean)e.getValue()));
this.buttonList.add(recordServerButton);
} else if(e.getKey().equals("Record Singleplayer")) {
recordSPButton = new GuiButton(RECORDSP_ID, this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), 150, 20, "Record Singleplayer: "+onOff((Boolean)e.getValue()));
this.buttonList.add(recordSPButton);
} else if(e.getKey().equals("Force Linear Movement")) {
linearButton = new GuiButton(FORCE_LINEAR, this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), 150, 20, "Camera Path: "+linearOnOff((Boolean)e.getValue()));
this.buttonList.add(linearButton);
}
++i;
++k;
}
if (i % 2 == 1)
{
++i;
}
}
private String onOff(boolean on) {
return on ? "ON" : "OFF";
}
private String linearOnOff(boolean on) {
return on ? "Linear" : "Cubic";
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
this.drawCenteredString(this.fontRendererObj, "Replay Mod Settings", this.width / 2, 20, 16777215);
if (FMLClientHandler.instance().getClient().thePlayer != null) {
this.drawCenteredString(this.fontRendererObj, "WARNING: These settings are going to be", this.width / 2, 180, Color.RED.getRGB());
this.drawCenteredString(this.fontRendererObj, "applied the next time you join a world.", this.width / 2, 190, Color.RED.getRGB());
}
super.drawScreen(mouseX, mouseY, partialTicks);
}
protected void actionPerformed(GuiButton button) throws IOException
{
if (button.enabled)
{
switch(button.id) {
case 200:
this.mc.displayGuiScreen(this.parentGuiScreen);
break;
case RECORDSERVER_ID:
boolean enabled = ReplayMod.replaySettings.isEnableRecordingServer();
enabled = !enabled;
recordServerButton.displayString = "Record Server: "+onOff(enabled);
ReplayMod.replaySettings.setEnableRecordingServer(enabled);
break;
case RECORDSP_ID:
enabled = ReplayMod.replaySettings.isEnableRecordingSingleplayer();
enabled = !enabled;
recordSPButton.displayString = "Record Singleplayer: "+onOff(enabled);
ReplayMod.replaySettings.setEnableRecordingSingleplayer(enabled);
break;
case SEND_CHAT:
enabled = ReplayMod.replaySettings.isShowNotifications();
enabled = !enabled;
sendChatButton.displayString = "Enable Notifications: "+onOff(enabled);
ReplayMod.replaySettings.setShowNotifications(enabled);
break;
case FORCE_LINEAR:
enabled = ReplayMod.replaySettings.isLinearMovement();
enabled = !enabled;
linearButton.displayString = "Camera Path: "+linearOnOff(enabled);
ReplayMod.replaySettings.setLinearMovement(enabled);
break;
}
}
}
}

View File

@@ -0,0 +1,189 @@
package eu.crushedpixel.replaymod.gui;
import eu.crushedpixel.replaymod.ReplayMod;
import eu.crushedpixel.replaymod.replay.ReplayHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.util.MathHelper;
import net.minecraftforge.fml.client.FMLClientHandler;
public class GuiReplaySpeedSlider extends GuiButton {
private float sliderValue;
private float valueStep, valueMin, valueMax;
private String displayKey;
private boolean dragging = false;
public GuiReplaySpeedSlider(int buttonId, int p_i45017_2_, int p_i45017_3_, String displayKey)
{
super(buttonId, p_i45017_2_, p_i45017_3_, 150, 20, "");
sliderValue = (9f/38f);
this.width = 100;
this.valueMin = 1;
this.valueMax = 38;
this.valueStep = 1;
this.displayString = displayKey+": 1x";
this.displayKey = displayKey;
Minecraft.getMinecraft().getTextureManager().bindTexture(buttonTextures);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.xPosition + (int)(sliderValue * (float)(this.width - 8)), this.yPosition, 0, 66, 4, 20);
this.drawTexturedModalRect(this.xPosition + (int)(sliderValue * (float)(this.width - 8)) + 4, this.yPosition, 196, 66, 4, 20);
}
@Override
protected int getHoverState(boolean mouseOver) {
return 0;
}
@Override
public void drawButton(Minecraft mc, int mouseX, int mouseY)
{
if (this.visible)
{
try {
FontRenderer fontrenderer = mc.fontRendererObj;
mc.getTextureManager().bindTexture(buttonTextures);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
int k = this.getHoverState(this.hovered);
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
GlStateManager.blendFunc(770, 771);
this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + k * 20, this.width / 2, this.height);
this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition, 200 - this.width / 2, 46 + k * 20, this.width / 2, this.height);
this.mouseDragged(mc, mouseX, mouseY);
int l = 14737632;
if (packedFGColour != 0)
{
l = packedFGColour;
}
else if (!this.enabled)
{
l = 10526880;
}
else if (this.hovered && FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class))
{
l = 16777120;
}
this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, l);
} catch(Exception e) {}
}
}
private String translate(float f) {
return f+"x";
}
public static float convertScaleRet(float value) {
if(value <= 1) {
return Math.round(value*10);
}
float steps = value-1;
return Math.round(steps/0.25f);
}
public static float convertScale(float value) {
if(value == 10) {
return 1;
}
if(value <= 9) {
return value/10f;
}
return 1+(0.25f*(value-10));
}
public double getSliderValue() {
return convertScale(normalizedToReal(sliderValue));
}
@Override
protected void mouseDragged(Minecraft mc, int mouseX, int mouseY) {
if (this.visible) {
try {
if(this.dragging) {
sliderValue = (float)(mouseX - (this.xPosition + 4)) / (float)(this.width - 8);
sliderValue = MathHelper.clamp_float(sliderValue, 0.0F, 1.0F);
float f = denormalizeValue(sliderValue);
sliderValue = normalizeValue(f);
if(ReplayHandler.getSpeed() != 0) {
ReplayHandler.setSpeed(convertScale(normalizedToReal(sliderValue)));
}
this.displayString = displayKey+": "+translate(convertScale(normalizedToReal(sliderValue)));
}
mc.getTextureManager().bindTexture(buttonTextures);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.xPosition + (int)(sliderValue * (float)(this.width - 8)), this.yPosition, 0, 66, 4, 20);
this.drawTexturedModalRect(this.xPosition + (int)(sliderValue * (float)(this.width - 8)) + 4, this.yPosition, 196, 66, 4, 20);
} catch(Exception e) {}
}
}
public float normalizeValue(float p_148266_1_)
{
return MathHelper.clamp_float((this.snapToStepClamp(p_148266_1_) - this.valueMin) / (this.valueMax - this.valueMin), 0.0F, 1.0F);
}
public float realToNormalized(float value) {
float min = 0 - valueMin;
float max = valueMax + min;
return value/(max) - min;
}
public float denormalizeValue(float p_148262_1_)
{
return this.snapToStepClamp(this.valueMin + (this.valueMax - this.valueMin) * MathHelper.clamp_float(p_148262_1_, 0.0F, 1.0F));
}
public float snapToStepClamp(float p_148268_1_)
{
p_148268_1_ = this.snapToStep(p_148268_1_);
return MathHelper.clamp_float(p_148268_1_, this.valueMin, this.valueMax);
}
protected float snapToStep(float p_148264_1_)
{
if (this.valueStep > 0.0F)
{
p_148264_1_ = this.valueStep * (float)Math.round(p_148264_1_ / this.valueStep);
}
return p_148264_1_;
}
public float normalizedToReal(float value) {
float min = 0 - valueMin;
float max = valueMax + min;
return Math.round(value*(max) - min);
}
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY)
{
if (super.mousePressed(mc, mouseX, mouseY))
{
this.dragging = true;
return true;
}
else
{
return false;
}
}
public void mouseReleased(int mouseX, int mouseY)
{
this.dragging = false;
}
}

View File

@@ -0,0 +1,185 @@
package eu.crushedpixel.replaymod.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.util.MathHelper;
import eu.crushedpixel.replaymod.ReplayMod;
public class GuiSizeLimitOptionSlider extends GuiButton {
public GuiSizeLimitOptionSlider(int buttonId, int p_i45017_2_, int p_i45017_3_, float valueMin, float valueMax, float valueStep, int sliderValue, String displayKey)
{
super(buttonId, p_i45017_2_, p_i45017_3_, 150, 20, "");
this.valueMin = valueMin;
this.valueMax = valueMax;
this.valueStep = valueStep;
this.sliderValue = sliderValue;
this.displayString = displayKey+": "+translate(sliderValue);
this.displayKey = displayKey;
float val = realToNormalized(convertScaleRet(sliderValue));
this.sliderValue = val;
}
private float sliderValue;
public boolean dragging;
private GameSettings.Options options;
private float valueStep, valueMin, valueMax;
private String displayKey;
protected int getHoverState(boolean mouseOver) {
return 0;
}
@Override
protected void mouseDragged(Minecraft mc, int mouseX, int mouseY) {
if (this.visible) {
if (this.dragging) {
sliderValue = (float)(mouseX - (this.xPosition + 4)) / (float)(this.width - 8);
sliderValue = MathHelper.clamp_float(sliderValue, 0.0F, 1.0F);
float f = denormalizeValue(sliderValue);
sliderValue = normalizeValue(f);
this.displayString = displayKey+": "+translate(convertScale(normalizedToReal(sliderValue)));
ReplayMod.replaySettings.setMaximumFileSize(convertScale(normalizedToReal(sliderValue)));
}
mc.getTextureManager().bindTexture(buttonTextures);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.xPosition + (int)(sliderValue * (float)(this.width - 8)), this.yPosition, 0, 66, 4, 20);
this.drawTexturedModalRect(this.xPosition + (int)(sliderValue * (float)(this.width - 8)) + 4, this.yPosition, 196, 66, 4, 20);
}
}
public static String translate(int value) {
if(value == 0) {
return "Unlimited";
} else {
return convertToStringRepresentation(value);
}
}
public static int convertScale(float value) {
if(value == 0) {
return 0;
} else {
if(value > 20) {
value = 1024+((value-20)*1024);
} else {
value = value*50;
}
if(value == 1000) {
value = 1024;
}
return Math.round(value);
}
}
public static int convertScaleRet(float value) {
if(value == 0) {
return 0;
} else {
if(value >= 1024) {
value = 20+((value-1024)/1024);
} else {
value = value/50;
}
if(value == 1024) {
value = 1000;
}
return Math.round(value);
}
}
public static String convertToStringRepresentation(final long value){
long M = 1;
long G = 1024;
long T = G * 1024;
final long[] dividers = new long[] { T, G, M};
final String[] units = new String[] { "TB", "GB", "MB"};
if(value < 1)
throw new IllegalArgumentException("Invalid file size: " + value);
String result = null;
for(int i = 0; i < dividers.length; i++){
final long divider = dividers[i];
if(value >= divider){
result = format(value, divider, units[i]);
break;
}
}
return result;
}
private static String format(final long value,
final long divider,
final String unit){
final double result =
divider > 1 ? (double) value / (double) divider : (double) value;
return String.format("%.0f %s", Double.valueOf(result), unit);
}
public float normalizedToReal(float value) {
float min = 0 - valueMin;
float max = valueMax + min;
return Math.round(value*(max) - min);
}
public float realToNormalized(float value) {
float min = 0 - valueMin;
float max = valueMax + min;
return value/(max) - min;
}
public float normalizeValue(float p_148266_1_)
{
return MathHelper.clamp_float((this.snapToStepClamp(p_148266_1_) - this.valueMin) / (this.valueMax - this.valueMin), 0.0F, 1.0F);
}
public float denormalizeValue(float p_148262_1_)
{
return this.snapToStepClamp(this.valueMin + (this.valueMax - this.valueMin) * MathHelper.clamp_float(p_148262_1_, 0.0F, 1.0F));
}
public float snapToStepClamp(float p_148268_1_)
{
p_148268_1_ = this.snapToStep(p_148268_1_);
return MathHelper.clamp_float(p_148268_1_, this.valueMin, this.valueMax);
}
protected float snapToStep(float p_148264_1_)
{
if (this.valueStep > 0.0F)
{
p_148264_1_ = this.valueStep * (float)Math.round(p_148264_1_ / this.valueStep);
}
return p_148264_1_;
}
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY)
{
if (super.mousePressed(mc, mouseX, mouseY))
{
this.dragging = true;
return true;
}
else
{
return false;
}
}
public void mouseReleased(int mouseX, int mouseY)
{
this.dragging = false;
}
}