diff --git a/build/build.properties b/build/build.properties index 3f5f84a..8aee948 100644 --- a/build/build.properties +++ b/build/build.properties @@ -1,4 +1,4 @@ -mc_version=1.7.2 -forge_version=10.12.0.1054 -ccl_version=1.1.0.77 -mod_version=1.0 +mc_version=1.7.10 +forge_version=10.13.0.1151 +ccl_version=1.1.1.88 +mod_version=1.0.1 diff --git a/build/settings.gradle b/build/settings.gradle index 398e21f..25615e7 100644 --- a/build/settings.gradle +++ b/build/settings.gradle @@ -16,4 +16,4 @@ include 'api' include 'services:webservice' */ -rootProject.name = 'CodeChickenLib' +rootProject.name = 'CodeChickenCore' diff --git a/src/codechicken/core/CCUpdateChecker.java b/src/codechicken/core/CCUpdateChecker.java index c9501b2..2631fbc 100644 --- a/src/codechicken/core/CCUpdateChecker.java +++ b/src/codechicken/core/CCUpdateChecker.java @@ -10,6 +10,8 @@ import java.net.URL; import java.net.UnknownHostException; import java.util.ArrayList; +import codechicken.core.launch.CodeChickenCorePlugin; +import com.google.common.base.Function; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.versioning.ComparableVersion; import cpw.mods.fml.relauncher.FMLInjectionData; @@ -20,27 +22,22 @@ import net.minecraft.util.ChatComponentText; public class CCUpdateChecker { private static final ArrayList updates = new ArrayList(); - + private static class ThreadUpdateCheck extends Thread { private final URL url; - private final String mod; - private final ComparableVersion version; - - public ThreadUpdateCheck(URL url, String mod, ComparableVersion version) - { + private final Function handler; + + public ThreadUpdateCheck(URL url, Function handler) { this.url = url; - this.mod = mod; - this.version = version; - + this.handler = handler; + setName("CodeChicken Update Checker"); } - + @Override - public void run() - { - try - { + public void run() { + try { HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setConnectTimeout(5000); @@ -48,71 +45,65 @@ public class CCUpdateChecker BufferedReader read = new BufferedReader(new InputStreamReader(conn.getInputStream())); String ret = read.readLine(); read.close(); - if(!ret.startsWith("Ret: ")) - { - System.err.println("Failed to check update for "+mod+" returned: "+ret); - return; - } - ComparableVersion newversion = new ComparableVersion(ret.substring(5)); - if(newversion.compareTo(version) > 0) - { - addUpdateMessage("Version "+newversion+" of "+mod+" is available"); - } - } - catch(SocketTimeoutException ste) - {} - catch(UnknownHostException uhe) - {} - catch(IOException iox) - { + handler.apply(ret); + } catch (SocketTimeoutException ignored) {} + catch (UnknownHostException ignored) {} + catch (IOException iox) { iox.printStackTrace(); } } } - - public static void tick() - { + + public static void tick() { Minecraft mc = Minecraft.getMinecraft(); - if(!mc.inGameHasFocus) + if (!mc.inGameHasFocus) return; - - synchronized(updates) - { - for(String s : updates) + + synchronized (updates) { + for (String s : updates) mc.thePlayer.addChatMessage(new ChatComponentText(s)); updates.clear(); } } - - public static void addUpdateMessage(String s) - { - synchronized(updates) - { + + public static void addUpdateMessage(String s) { + synchronized (updates) { updates.add(s); } } - - public static String mcVersion() - { + + public static String mcVersion() { return (String) FMLInjectionData.data()[4]; } - - public static void updateCheck(String mod, String version) - { - try - { - new ThreadUpdateCheck( - new URL("http://www.chickenbones.craftsaddle.org/Files/New_Versions/version.php?"+ - "version="+mcVersion()+"&"+ - "file="+mod), - mod, new ComparableVersion(version)).start(); - } - catch(MalformedURLException e) - {} + + public static void updateCheck(final String mod, final String version) { + updateCheck("http://www.chickenbones.net/Files/notification/version.php?" + + "version=" + mcVersion() + "&" + + "file=" + mod, + new Function() + { + @Override public Void apply(String ret) { + if (!ret.startsWith("Ret: ")) { + CodeChickenCorePlugin.logger.error("Failed to check update for " + mod + " returned: " + ret); + return null; + } + ComparableVersion newversion = new ComparableVersion(ret.substring(5)); + if (newversion.compareTo(new ComparableVersion(version)) > 0) + addUpdateMessage("Version " + newversion + " of " + mod + " is available"); + return null; + } + }); } - public static void updateCheck(String mod) - { + public static void updateCheck(String mod) { updateCheck(mod, Loader.instance().getIndexedModList().get(mod).getVersion()); } + + public static void updateCheck(String url, Function handler) { + try { + new ThreadUpdateCheck(new URL(url), handler).start(); + } catch (MalformedURLException e) { + CodeChickenCorePlugin.logger.error("Malformed URL: "+url, e); + } + } } diff --git a/src/codechicken/core/ClassDiscoverer.java b/src/codechicken/core/ClassDiscoverer.java index 3e03cd8..d36b248 100644 --- a/src/codechicken/core/ClassDiscoverer.java +++ b/src/codechicken/core/ClassDiscoverer.java @@ -69,8 +69,7 @@ public class ClassDiscoverer addClass(classname); } catch (IOException e) { - System.err.println("Unable to load class: " + resource); - e.printStackTrace(); + CodeChickenCorePlugin.logger.error("Unable to load class: " + resource, e); } } @@ -79,8 +78,7 @@ public class ClassDiscoverer Class class1 = Class.forName(classname, true, modClassLoader); classes.add(class1); } catch (Throwable t) { - System.err.println("Unable to load class: " + classname); - t.printStackTrace(); + CodeChickenCorePlugin.logger.error("Unable to load class: " + classname, t); } } @@ -101,8 +99,7 @@ public class ClassDiscoverer try { readFromZipFile(minecraftSource); } catch (Exception e) { - System.err.println("Failed to scan " + minecraftSource.getAbsolutePath() + ", the zip file is invalid"); - e.printStackTrace(); + CodeChickenCorePlugin.logger.error("Failed to scan " + minecraftSource.getAbsolutePath() + ", the zip file is invalid", e); } } } else if (minecraftSource.isDirectory()) { diff --git a/src/codechicken/core/ServerUtils.java b/src/codechicken/core/ServerUtils.java index 5dd759f..dc8de3a 100644 --- a/src/codechicken/core/ServerUtils.java +++ b/src/codechicken/core/ServerUtils.java @@ -18,7 +18,7 @@ public class ServerUtils extends CommonUtils } public static EntityPlayerMP getPlayer(String playername) { - return mc().getConfigurationManager().getPlayerForUsername(playername); + return mc().getConfigurationManager().func_152612_a(playername); } public static List getPlayers() { @@ -44,7 +44,7 @@ public class ServerUtils extends CommonUtils } public static boolean isPlayerOP(String username) { - return mc().getConfigurationManager().isPlayerOpped(username); + return mc().getConfigurationManager().func_152596_g(getPlayer(username).getGameProfile()); } public static boolean isPlayerOwner(String username) { diff --git a/src/codechicken/core/asm/CodeChickenCoreModContainer.java b/src/codechicken/core/asm/CodeChickenCoreModContainer.java index 1050917..334de2b 100644 --- a/src/codechicken/core/asm/CodeChickenCoreModContainer.java +++ b/src/codechicken/core/asm/CodeChickenCoreModContainer.java @@ -3,6 +3,8 @@ package codechicken.core.asm; import java.io.File; import java.util.LinkedList; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import codechicken.core.CCUpdateChecker; import codechicken.core.featurehack.LiquidTextures; @@ -10,6 +12,8 @@ import codechicken.core.internal.CCCEventHandler; import codechicken.core.launch.CodeChickenCorePlugin; import codechicken.lib.config.ConfigFile; +import codechicken.lib.config.ConfigTag; +import com.google.common.base.Function; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; @@ -59,10 +63,38 @@ public class CodeChickenCoreModContainer extends DummyModContainer if (event.getSide().isClient()) { if (config.getTag("checkUpdates").getBooleanValue(true)) CCUpdateChecker.updateCheck(getModId()); + notificationCheck(); FMLCommonHandler.instance().bus().register(new CCCEventHandler()); } } + private void notificationCheck() { + final ConfigTag tag = config.getTag("checkNotifications").setComment("The most recent notification number recieved. -1 to disable"); + final int notify = tag.getIntValue(0); + if(notify < 0) + return; + + CCUpdateChecker.updateCheck( + "http://www.chickenbones.net/Files/notification/general.php", + new Function() + { + @Override + public Void apply(String ret) { + Matcher m = Pattern.compile("Ret \\((\\d+)\\): (.+)").matcher(ret); + if (!m.matches()) { + CodeChickenCorePlugin.logger.error("Failed to check notifications: " + ret); + return null; + } + int index = Integer.parseInt(m.group(1)); + if(index > notify) { + tag.setIntValue(index); + CCUpdateChecker.addUpdateMessage(m.group(2)); + } + return null; + } + }); + } + @Override public VersionRange acceptableMinecraftVersionRange() { return VersionParser.parseRange(CodeChickenCorePlugin.mcVersion); diff --git a/src/codechicken/core/gui/ClickCounter.java b/src/codechicken/core/gui/ClickCounter.java new file mode 100644 index 0000000..918d0d9 --- /dev/null +++ b/src/codechicken/core/gui/ClickCounter.java @@ -0,0 +1,52 @@ +package codechicken.core.gui; + +import java.util.Map; +import java.util.TreeMap; + +public class ClickCounter +{ + public class ClickCount + { + public T clicked; + public long time; + public int count; + + public boolean update(T clicked) { + if(this.clicked != clicked) { + this.clicked = clicked; + count = 0; + time = Long.MIN_VALUE; + return false; + } + return true; + } + } + + public Map buttons = new TreeMap(); + + public ClickCount getCount(int button) { + ClickCount c = buttons.get(button); + if(c == null) + buttons.put(button, c = new ClickCount()); + return c; + } + + public void mouseDown(T clicked, int button) { + ClickCount c = getCount(button); + c.update(clicked); + } + + public int mouseUp(T clicked, int button) { + ClickCount c = getCount(button); + if(!c.update(clicked)) + return 0; + + long time = System.currentTimeMillis(); + if(time-c.time < 500) + c.count++; + else + c.count = 1; + c.time = time; + return c.count; + } +} diff --git a/src/codechicken/core/gui/GuiScrollPane.java b/src/codechicken/core/gui/GuiScrollPane.java new file mode 100644 index 0000000..e51050f --- /dev/null +++ b/src/codechicken/core/gui/GuiScrollPane.java @@ -0,0 +1,215 @@ +package codechicken.core.gui; + +import codechicken.lib.math.MathHelper; +import codechicken.lib.vec.Rectangle4i; + +import java.awt.*; + +public abstract class GuiScrollPane extends GuiWidget +{ + protected int scrollclicky = -1; + protected float scrollpercent; + protected int scrollmousey; + protected float percentscrolled; + + public int marginleft; + public int margintop; + public int marginright; + public int marginbottom; + + public GuiScrollPane(int x, int y, int width, int height) { + super(x, y, width, height); + } + + public void setMargins(int left, int top, int right, int bottom) { + marginleft = left; + margintop = top; + marginright = right; + marginbottom = bottom; + } + + public Rectangle windowBounds() { + return new Rectangle(x+marginleft, y+margintop, width-marginleft-marginright, height-margintop-marginbottom); + } + + public abstract int contentHeight(); + + public Dimension scrollbarDim() { + int h = (int) ((windowBounds().getHeight() / contentHeight()) * height); + return new Dimension(5, h > height ? height : h < height / 15 ? height / 15 : h); + } + + public Rectangle scrollbarBounds() { + Dimension dim = scrollbarDim(); + return new Rectangle( + x + width - dim.width, y + (int) ((height - dim.height) * percentscrolled + 0.4999), + dim.width, dim.height); + } + + public void scrollUp() { + scroll(-5); + } + + public void scrollDown() { + scroll(5); + } + + public void scroll(int i) { + percentscrolled += i * height / (float)(2*contentHeight()); + calculatePercentScrolled(); + } + + public void calculatePercentScrolled() { + int barempty = height - scrollbarDim().height; + if (isScrolling()) { + int scrolldiff = scrollmousey - scrollclicky; + percentscrolled = scrolldiff / (float) barempty + scrollpercent; + } + percentscrolled = (float) MathHelper.clip(percentscrolled, 0, 1); + } + + public boolean isScrolling() { + return scrollclicky >= 0; + } + + public boolean hasScrollbar() { + return contentHeight() > height; + } + + /** + * @return -1 for left, 0 for none, 1 for right + */ + public int scrollbarGuideAlignment() { + return -1; + } + + public void showSlot(int sloty, int slotHeight) { + Rectangle w = windowBounds(); + if (sloty + slotHeight > w.y + w.height) { + int diff = sloty - (w.y + w.height - slotHeight); + percentscrolled += diff / (double) (contentHeight() - w.height); + calculatePercentScrolled(); + } else if (sloty < w.y) { + int diff = w.y - sloty; + percentscrolled -= diff / (double) (contentHeight() - w.height); + calculatePercentScrolled(); + } + } + + @Override + public void mouseClicked(int mx, int my, int button) { + Rectangle sbar = scrollbarBounds(); + Rectangle w = windowBounds(); + int barempty = height - sbar.height; + + if (button == 0 && + sbar.height < height && //the scroll bar can move (not full length) + mx >= sbar.x && mx <= sbar.x + sbar.width && + my >= y && my <= y + height)//in the scroll pane + { + if (my < sbar.y) { + percentscrolled = (my - y) / (float) barempty; + calculatePercentScrolled(); + } else if (my > sbar.y+sbar.height) { + percentscrolled = (my - y - sbar.height + 1) / (float) barempty; + calculatePercentScrolled(); + } else { + scrollclicky = my; + scrollpercent = percentscrolled; + scrollmousey = my; + } + } else if (w.contains(mx, my)) + slotDown(mx - w.x, my - w.y + scrolledPixels(), button); + } + + /** + * Mouse down on slot area + * Coordinates relative to slot content area + */ + public void slotDown(int mx, int my, int button) {} + + /** + * Mouse up on slot area + * Coordinates relative to slot content area + */ + public void slotUp(int mx, int my, int button) {} + + @Override + public void mouseMovedOrUp(int mx, int my, int button) { + Rectangle w = windowBounds(); + if (isScrolling() && button == 0)//we were scrolling and we released mouse + scrollclicky = -1; + else if (w.contains(mx, my)) + slotUp(mx - w.x, my - w.y + scrolledPixels(), button); + } + + @Override + public void mouseDragged(int mousex, int mousey, int button, long time) { + if (isScrolling()) { + int scrolldiff = mousey - scrollclicky; + int sbarh = scrollbarDim().height; + int barupallowed = (int) ((height - sbarh) * scrollpercent + 0.5); + int bardownallowed = (height - sbarh) - barupallowed; + + if (-scrolldiff > barupallowed) + scrollmousey = scrollclicky - barupallowed; + else if (scrolldiff > bardownallowed) + scrollmousey = scrollclicky + bardownallowed; + else + scrollmousey = mousey; + + calculatePercentScrolled(); + } + } + + public int scrolledPixels() { + int scrolled = (int) ((contentHeight() - windowBounds().height) * percentscrolled + 0.5); + if (scrolled < 0) scrolled = 0; + return scrolled; + } + + public Rectangle4i bounds() { + return new Rectangle4i(x, y, width, height); + } + + public boolean contains(int mx, int my) { + return bounds().contains(mx, my); + } + + @Override + public void draw(int mx, int my, float frame) { + Rectangle w = windowBounds(); + drawBackground(frame); + drawContent(mx-w.x, my+scrolledPixels()-w.y, frame); + drawOverlay(frame); + drawScrollbar(frame); + } + + public void drawBackground(float frame) { + drawRect(x, y, x + width, y + height, 0xff000000); + } + + public abstract void drawContent(int mx, int my, float frame); + + public void drawOverlay(float frame) { + //outlines + drawRect(x, y - 1, x + width, y, 0xffa0a0a0);//top + drawRect(x, y + height, x + width, y + height + 1, 0xffa0a0a0);//bottom + drawRect(x - 1, y - 1, x, y + height + 1, 0xffa0a0a0);//left + drawRect(x + width, y - 1, x + width + 1, y + height + 1, 0xffa0a0a0);//right + } + + public void drawScrollbar(float frame) { + Rectangle r = scrollbarBounds(); + + drawRect(r.x, r.y, r.x + r.width, r.y + r.height, 0xFF8B8B8B);//corners + drawRect(r.x, r.y, r.x + r.width - 1, r.y + r.height - 1, 0xFFF0F0F0);//topleft up + drawRect(r.x + 1, r.y + 1, r.x + r.width, r.y + r.height, 0xFF555555);//bottom right down + drawRect(r.x + 1, r.y + 1, r.x + r.width - 1, r.y + r.height - 1, 0xFFC6C6C6);//scrollbar + + int algn = scrollbarGuideAlignment(); + if (algn != 0) + drawRect(algn > 0 ? r.x + r.width : r.x - 1, y, r.x, y + height, 0xFF808080);//lineguide + } + +} diff --git a/src/codechicken/core/gui/GuiScrollSlot.java b/src/codechicken/core/gui/GuiScrollSlot.java index 5fc848b..e1da5dd 100644 --- a/src/codechicken/core/gui/GuiScrollSlot.java +++ b/src/codechicken/core/gui/GuiScrollSlot.java @@ -1,361 +1,157 @@ package codechicken.core.gui; -import net.minecraft.client.gui.GuiButton; - import org.lwjgl.input.Keyboard; -import codechicken.lib.math.MathHelper; +import java.awt.*; -public abstract class GuiScrollSlot extends GuiWidget -{ - protected GuiButton scrollupbutton; - protected GuiButton scrolldownbutton; +public abstract class GuiScrollSlot extends GuiScrollPane +{ protected String actionCommand; - - protected int scrollclicky = -1; - protected float scrollpercent; - protected int scrollmousey; - protected float percentscrolled; - - protected int lastslotclicked = -1; - protected int lastbuttonclicked = -1; - protected long lastslotclicktime; - public boolean focused; - - public int contentx; - public int contenty; - public int contentheight; + protected ClickCounter click = new ClickCounter(); public boolean smoothScroll = true; - - public GuiScrollSlot(int x, int y, int width, int height) - { + + public GuiScrollSlot(int x, int y, int width, int height) { super(x, y, width, height); - setContentSize(x+3, y+2, height-2); + setMargins(3, 2, 3, 2); } - - public GuiScrollSlot setActionCommand(String s) - { + + public GuiScrollSlot setActionCommand(String s) { actionCommand = s; return this; } - - public void setSmoothScroll(boolean b) - { + + public void setSmoothScroll(boolean b) { smoothScroll = b; } - - public void setSize(int x, int y, int width, int height) - { - int cx = contentx-this.x; - int cy = contenty-this.y; - int ch = height-contentheight; - super.setSize(x, y, width, height); - - setContentSize(x+cx, y+cy, height-ch); - } - - public void setContentSize(int x, int y, int h) - { - this.contentx = x; - this.contenty = y; - this.contentheight = h; - } - - public void registerButtons(GuiButton up, GuiButton down, String selectionCommand) - { - scrollupbutton = up; - scrolldownbutton = down; - actionCommand = selectionCommand; - } - public abstract int getSlotHeight(); + public abstract int getSlotHeight(int slot); protected abstract int getNumSlots(); - public abstract void selectNext(); - - public abstract void selectPrev(); + public void selectNext() {} - protected abstract void slotClicked(int slot, int button, int mousex, int mousey, boolean doubleclick); + public void selectPrev() {} - protected abstract boolean isSlotSelected(int slot); + /** + * Coordinates are relative to slot area + */ + protected abstract void slotClicked(int slot, int button, int mx, int my, int count); - protected abstract void drawSlot(int slot, int x, int y, int mousex, int mousey, boolean selected, float frame); + protected abstract void drawSlot(int slot, int x, int y, int mx, int my, float frame); - protected void unfocus() - { + protected void unfocus() { } - - public void setFocused(boolean focus) - { + + public void setFocused(boolean focus) { focused = focus; - if(!focused) + if (!focused) unfocus(); } - - public void scrollUp() - { - scroll(-5); - } - - public void scrollDown() - { - scroll(5); - } - - public void scroll(int i) - { - percentscrolled += i/(float)contentheight * 100; - calculatePercentScrolled(); - } - - public int totalContentHeight() - { - return getNumSlots() * getSlotHeight(); - } - - public int getSlotY(int slot) - { - int scrolledPixels = (int)((totalContentHeight() - contentheight) * percentscrolled + 0.5); - if(!smoothScroll) - scrolledPixels = (int)(scrolledPixels/(double)getSlotHeight()+0.5)*getSlotHeight(); - return contenty-scrolledPixels+slot*getSlotHeight(); + + @Override + public int contentHeight() { + return getSlotY(getNumSlots()); } - public int getClickedSlot(int mousey) - { - if(mousey < contenty || mousey >= contenty+contentheight) + public int getSlotY(int slot) { + int h = 0; + for(int i = 0; i < slot; i++) + h+=getSlotHeight(i); + return h; + } + + public int getSlot(int my) { + if (my < 0) return -1; - - for(int slot = 0; slot < getNumSlots(); slot++) - { - int sloty = getSlotY(slot); - if(mousey >= sloty && mousey < sloty + getSlotHeight()) - return slot; + + int y = 0; + for(int i = 0; i < getNumSlots(); i++) { + int h = getSlotHeight(i); + if(my >= y && my < y+h) + return i; + y+=h; } return -1; } - - public int getScrollBarWidth() - { - return 5; - } - - public int getScrollBarHeight() - { - int sbarh = (int)((contentheight / (float)totalContentHeight()) * height); - if(sbarh > height) - { - return height; - } - else if(sbarh < height / 15) - { - return height / 15; - } - else - { - return sbarh; - } - } - - public void calculatePercentScrolled() - { - int barempty = height - getScrollBarHeight(); - if(scrollclicky >= 0) - { - int scrolldiff = scrollmousey - scrollclicky; - percentscrolled = scrolldiff / (float)barempty + scrollpercent; - } - percentscrolled = (float) MathHelper.clip(percentscrolled, 0, 1); - } - - public void showSlot(int slot) - { - int sloty = getSlotY(slot); - if(sloty+getSlotHeight() > contenty+contentheight) - { - int diff = sloty-(contenty+contentheight-getSlotHeight()); - percentscrolled += diff/(double)(totalContentHeight() - contentheight); - calculatePercentScrolled(); - } - else if(sloty < contenty) - { - int diff = contenty-sloty; - percentscrolled -= diff/(double)(totalContentHeight() - contentheight); - calculatePercentScrolled(); - } + + public int getClickedSlot(int my) { + return getSlot(my-windowBounds().y+scrolledPixels()); } - public void processMouse(int mousex, int mousey) - { - if(scrollclicky >= 0) - { - int scrolldiff = mousey - scrollclicky; - int barupallowed = (int)((height - getScrollBarHeight()) * scrollpercent + 0.5); - int bardownallowed = (height - getScrollBarHeight()) - barupallowed; - - if(-scrolldiff > barupallowed) - scrollmousey = scrollclicky - barupallowed; - else if(scrolldiff > bardownallowed) - scrollmousey = scrollclicky + bardownallowed; - else - scrollmousey = mousey; - - calculatePercentScrolled(); + @Override + public int scrolledPixels() { + int scrolled = super.scrolledPixels(); + if(!smoothScroll) { + int slot = getSlot(scrolled); + int sloty = getSlotY(slot); + int sloth = getSlotHeight(slot); + scrolled = sloty+(int)((scrolled-sloty)/(double)sloth+0.5)*sloth; } + return scrolled; } - - public void actionPerformed(GuiButton guibutton) - { - if(!guibutton.enabled) - { + + /** + * @return -1 for left, 1 for right + */ + public int scrollbarAlignment() { + return 1; + } + + @Override + public int scrollbarGuideAlignment() { + return scrollbarAlignment(); + } + + @Override + public Rectangle scrollbarBounds() { + Rectangle r = super.scrollbarBounds(); + if(scrollbarAlignment() == -1) + r.x = x; + return r; + } + + public void showSlot(int slot) { + showSlot(getSlotY(slot), getSlotHeight(slot)); + } + + @Override + public void slotDown(int mx, int my, int button) { + int slot = getSlot(my); + click.mouseDown(slot >= 0 ? slot : null, button); + } + + @Override + public void slotUp(int mx, int my, int button) { + int slot = getSlot(my); + int c = click.mouseUp(slot >= 0 ? slot : null, button); + if(c > 0 && slot >= 0) + slotClicked(slot, button, mx, my-getSlotY(slot), c); + } + + @Override + public void keyTyped(char c, int keycode) { + if (!focused) return; - } - if(scrollupbutton != null && guibutton.id == scrollupbutton.id) - { - scrollUp(); - } - else if(scrolldownbutton != null && guibutton.id == scrolldownbutton.id) - { - scrollDown(); - } - } - @Override - public void mouseClicked(int mousex, int mousey, int button) - { - boolean needsfocus = (mousex >= x && mousex < x + width && - mousey >= y && mousey <= y + height); - if(needsfocus != focused) - { - setFocused(needsfocus); - } - - int barempty = height - getScrollBarHeight(); - int sbarx = x + width - getScrollBarWidth(); - int sbary = y + (int)(barempty * percentscrolled + 0.5); - - if(button == 0 && - getScrollBarHeight() < height && //the scroll bar can move (not full length) - mousex >= sbarx && mousex <= x + width && - mousey >= y && mousey <= y + height)//in the scroll pane - { - if(mousey < sbary) - { - percentscrolled = (mousey - y) / (float)barempty; - calculatePercentScrolled(); - } - else if(mousey > sbary + getScrollBarHeight()) - { - percentscrolled = (mousey - y - getScrollBarHeight() + 1) / (float)barempty; - calculatePercentScrolled(); - } - else - { - scrollclicky = mousey; - scrollpercent = percentscrolled; - scrollmousey = mousey; - } - } - else if(mousex >= contentx && mousex < sbarx && - mousey >= contenty && mousey <= contenty + contentheight)//in the box - { - int slot = getClickedSlot(mousey); - if(slot >= 0) - slotClicked(slot, button, mousex-contentx, mousey-getSlotY(slot), - slot == lastslotclicked && button == lastbuttonclicked && System.currentTimeMillis() - lastslotclicktime < 500); - - lastslotclicked = slot; - lastbuttonclicked = button; - lastslotclicktime = System.currentTimeMillis(); - } - } - - @Override - public void mouseMovedOrUp(int mousex, int mousey, int button) - { - if(scrollclicky >= 0 && button == 0)//we were scrolling and we released mouse - scrollclicky = -1; - } - - @Override - public void keyTyped(char c, int keycode) - { - if(!focused) - return; - - if(keycode == Keyboard.KEY_UP) + if (keycode == Keyboard.KEY_UP) selectPrev(); - if(keycode == Keyboard.KEY_DOWN) + if (keycode == Keyboard.KEY_DOWN) selectNext(); - if(keycode == Keyboard.KEY_RETURN && actionCommand != null) + if (keycode == Keyboard.KEY_RETURN && actionCommand != null) sendAction(actionCommand); } - - public void drawSlotBox(float frame) - { - drawRect(x, y, x + width, y + height, 0xff000000); - } - - public void drawBackground(float frame) - { - - } - - public void drawOverlay(float frame) - { - //outlines - drawRect(x, y - 1, x + width, y, 0xffa0a0a0);//top - drawRect(x, y + height, x + width, y + height + 1, 0xffa0a0a0);//bottom - drawRect(x - 1, y - 1, x, y + height + 1, 0xffa0a0a0);//left - drawRect(x + width, y - 1, x + width + 1, y + height + 1, 0xffa0a0a0);//right - } - - public void drawScrollBar(float frame) - { - int sbarw = getScrollBarWidth(); - int sbarh = getScrollBarHeight(); - int sbarx = x + width - sbarw; - int sbary = y + (int)((height - sbarh) * percentscrolled + 0.4999); - - drawRect(sbarx, sbary, sbarx+sbarw, sbary+sbarh, 0xFF8B8B8B);//corners - drawRect(sbarx, sbary, sbarx+sbarw-1, sbary+sbarh - 1, 0xFFF0F0F0);//topleft up - drawRect(sbarx + 1, sbary + 1, sbarx+sbarw, sbary+sbarh, 0xFF555555);//bottom right down - drawRect(sbarx + 1, sbary + 1, sbarx+sbarw-1, sbary+sbarh - 1, 0xFFC6C6C6);//scrollbar - - if(drawLineGuide()) - drawRect(sbarx - 1, y, sbarx, y + height, 0xFF808080);//lineguide - } - - public boolean drawLineGuide() - { - return true; - } - - public void drawSlots(int mousex, int mousey, float frame) - { - for(int slot = 0; slot < getNumSlots(); slot++) - { - int sloty = getSlotY(slot); - if(sloty > contenty - getSlotHeight() && sloty < contenty + contentheight) - drawSlot(slot, contentx, sloty, mousex-contentx, mousey-sloty, isSlotSelected(slot), frame); + + @Override + public void drawContent(int mx, int my, float frame) { + int scrolled = scrolledPixels(); + Rectangle w = windowBounds(); + int y = 0; + for (int slot = 0; slot < getNumSlots(); slot++) { + int h = getSlotHeight(slot); + if (y+h > scrolled && y < scrolled+w.height) + drawSlot(slot, w.x, w.y+y-scrolledPixels(), mx, my-y, frame); + y+=h; } } - - @Override - public void mouseDragged(int x, int y, int button, long time) - { - processMouse(x, y); - } - - @Override - public void draw(int mousex, int mousey, float frame) - { - drawBackground(frame); - drawSlotBox(frame); - drawSlots(mousex, mousey, frame); - drawOverlay(frame); - drawScrollBar(frame); - } } diff --git a/src/codechicken/core/inventory/GuiContainerWidget.java b/src/codechicken/core/inventory/GuiContainerWidget.java index e917c58..919ca8a 100644 --- a/src/codechicken/core/inventory/GuiContainerWidget.java +++ b/src/codechicken/core/inventory/GuiContainerWidget.java @@ -33,9 +33,8 @@ public class GuiContainerWidget extends GuiContainer implements IGuiActionListen @Override public void setWorldAndResolution(Minecraft mc, int i, int j) { - boolean init = this.mc == null; super.setWorldAndResolution(mc, i, j); - if(init) + if(widgets.isEmpty()) addWidgets(); } @@ -127,7 +126,6 @@ public class GuiContainerWidget extends GuiContainer implements IGuiActionListen @Override public void onGuiClosed() { super.onGuiClosed(); - mc = null; widgets.clear(); } } diff --git a/src/codechicken/core/launch/CodeChickenCorePlugin.java b/src/codechicken/core/launch/CodeChickenCorePlugin.java index 67ecc1f..0d31aac 100644 --- a/src/codechicken/core/launch/CodeChickenCorePlugin.java +++ b/src/codechicken/core/launch/CodeChickenCorePlugin.java @@ -4,7 +4,6 @@ import java.awt.Desktop; import java.io.File; import java.lang.reflect.Constructor; import java.lang.reflect.Field; -import java.lang.reflect.Method; import java.util.List; import java.util.Map; import java.util.jar.Attributes; @@ -17,9 +16,7 @@ import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; import codechicken.core.asm.*; -import codechicken.lib.asm.ASMInit; import cpw.mods.fml.relauncher.CoreModManager; -import net.minecraft.launchwrapper.Launch; import cpw.mods.fml.common.versioning.DefaultArtifactVersion; import cpw.mods.fml.common.versioning.VersionParser; @@ -33,7 +30,7 @@ import org.apache.logging.log4j.Logger; @TransformerExclusions(value = {"codechicken.core.asm", "codechicken.obfuscator"}) public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook { - public static final String mcVersion = "[1.7.2]"; + public static final String mcVersion = "[1.7.10]"; public static File minecraftDir; public static String currentMcVersion; @@ -59,8 +56,7 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook f_loadPlugins.setAccessible(true); ((List)f_loadPlugins.get(null)).add(2, wrapperConstructor.newInstance("CCCDeobfPlugin", new MCPDeobfuscationTransformer.LoadPlugin(), null, 0, new String[0])); } catch (Exception e) { - System.err.println("Failed to inject MCPDeobfuscation Transformer"); - e.printStackTrace(); + logger.error("Failed to inject MCPDeobfuscation Transformer", e); } } @@ -68,7 +64,7 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook String mcVersion = (String) FMLInjectionData.data()[4]; if (!VersionParser.parseRange(reqVersion).containsVersion(new DefaultArtifactVersion(mcVersion))) { String err = "This version of " + mod + " does not support minecraft version " + mcVersion; - System.err.println(err); + logger.error(err); JEditorPane ep = new JEditorPane("text/html", "" + @@ -85,7 +81,7 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook try { if (event.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) Desktop.getDesktop().browse(event.getURL().toURI()); - } catch (Exception e) {} + } catch (Exception ignored) {} } }); @@ -167,8 +163,7 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook jar.close(); } } catch (Exception e) { - e.printStackTrace(); - System.err.println("CodeChickenCore: Failed to read jar file: " + file.getName()); + logger.error("CodeChickenCore: Failed to read jar file: " + file.getName(), e); } } }