From 092c731aca435021080c617a69f203a98de73311 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Tue, 26 Mar 2013 17:19:45 +0000 Subject: [PATCH 01/51] WorldEditCUI for Minecraft 1.5.1 on LiteLoader + Based on previous "WorldEditCUI" code (prior to rename) + Removed ModLoader support + Added LiteLoader support + No SPC support in this version + Removed "proxy render entity" stuff and replaced with LiteLoader's native render callback + Cleaned up tonnes of legacy obfuscation code, replaced with MCP mappings + Fixed a metric arseload of warnings --- .classpath | 13 + .project | 35 + build/build_wecui.xml | 162 +++ src/main/java/deobf/EntityUpdateThread.java | 32 - src/main/java/deobf/StartMC.java | 28 - src/main/java/deobf/mod_WorldEditCUI.java | 128 -- src/main/java/deobf/spc_WorldEditCUI.java | 37 - src/main/java/wecui/CUIDebug.java | 3 +- src/main/java/wecui/LiteModWorldEditCUI.java | 121 ++ src/main/java/wecui/Updater.java | 21 +- src/main/java/wecui/WorldEditCUI.java | 25 +- .../java/wecui/config/CUIConfiguration.java | 26 +- .../java/wecui/config/ConfigurationNode.java | 11 +- .../wecui/config/EmptyNullRepresenter.java | 3 +- src/main/java/wecui/event/CUIEvent.java | 4 +- .../java/wecui/event/ChatCommandEvent.java | 3 +- .../java/wecui/event/OutgoingChatEvent.java | 3 +- .../event/command/VersionCommandEvent.java | 7 +- .../java/wecui/event/cui/CUIBaseEvent.java | 4 +- .../java/wecui/event/cui/CUIPoint2DEvent.java | 2 +- .../java/wecui/event/cui/CUIPointEvent.java | 5 - .../wecui/event/listeners/CUIListener.java | 5 +- .../event/listeners/WorldRenderListener.java | 29 +- src/main/java/wecui/fevents/Event.java | 3 +- src/main/java/wecui/fevents/HandlerList.java | 6 +- .../wecui/obfuscation/DataPacketList.java | 59 +- .../wecui/obfuscation/FieldObfuscation.java | 27 +- .../java/wecui/obfuscation/Obfuscation.java | 140 -- .../wecui/obfuscation/RenderObfuscation.java | 54 - src/main/java/wecui/render/RenderEntity.java | 111 -- src/main/java/wecui/render/RenderHooks.java | 56 - .../java/wecui/render/shapes/Render2DBox.java | 15 +- .../wecui/render/shapes/Render2DGrid.java | 13 +- .../java/wecui/render/shapes/Render3DBox.java | 50 +- .../wecui/render/shapes/Render3DGrid.java | 59 +- .../render/shapes/RenderCylinderBox.java | 12 +- .../render/shapes/RenderCylinderCircles.java | 12 +- .../render/shapes/RenderCylinderGrid.java | 30 +- .../wecui/render/shapes/RenderEllipsoid.java | 44 +- .../java/wecui/util/ConsoleLogFormatter.java | 3 +- src/main/java/wecui/util/Vector2.java | 1113 ++++++++-------- src/main/java/wecui/util/Vector2m.java | 256 ++-- src/main/java/wecui/util/Vector3.java | 1155 +++++++++-------- src/main/java/wecui/util/Vector3m.java | 327 ++--- .../java/wecui/vendor/org/joor/Reflect.java | 9 +- 45 files changed, 2030 insertions(+), 2231 deletions(-) create mode 100644 .classpath create mode 100644 .project create mode 100644 build/build_wecui.xml delete mode 100644 src/main/java/deobf/EntityUpdateThread.java delete mode 100644 src/main/java/deobf/StartMC.java delete mode 100644 src/main/java/deobf/mod_WorldEditCUI.java delete mode 100644 src/main/java/deobf/spc_WorldEditCUI.java create mode 100644 src/main/java/wecui/LiteModWorldEditCUI.java delete mode 100644 src/main/java/wecui/obfuscation/Obfuscation.java delete mode 100644 src/main/java/wecui/obfuscation/RenderObfuscation.java delete mode 100644 src/main/java/wecui/render/RenderEntity.java delete mode 100644 src/main/java/wecui/render/RenderHooks.java diff --git a/.classpath b/.classpath new file mode 100644 index 00000000..7e98e623 --- /dev/null +++ b/.classpath @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 00000000..decc1cc2 --- /dev/null +++ b/.project @@ -0,0 +1,35 @@ + + + WorldEditCUI + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + + + java + 2 + PROJECT_LOC/src/main/java + + + res + 2 + PROJECT_LOC/src/main/resources + + + + + MCP_LOC + $%7BPARENT-2-PROJECT_LOC%7D + + + diff --git a/build/build_wecui.xml b/build/build_wecui.xml new file mode 100644 index 00000000..5a8b33c1 --- /dev/null +++ b/build/build_wecui.xml @@ -0,0 +1,162 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/deobf/EntityUpdateThread.java b/src/main/java/deobf/EntityUpdateThread.java deleted file mode 100644 index 1e3e96a4..00000000 --- a/src/main/java/deobf/EntityUpdateThread.java +++ /dev/null @@ -1,32 +0,0 @@ -package deobf; - -import java.util.logging.Level; -import java.util.logging.Logger; -import wecui.obfuscation.Obfuscation; - -public class EntityUpdateThread extends Thread { - - private mod_WorldEditCUI mod; - - public EntityUpdateThread(mod_WorldEditCUI mod) { - this.mod = mod; - } - - @Override - public void run() { - while(true) { - try { - Thread.sleep(30000); - } catch (InterruptedException ex) { - Logger.getLogger(EntityUpdateThread.class.getName()).log(Level.SEVERE, null, ex); - } - - if( mod.lastEntity != null ) { - Obfuscation.setEntityPositionToPlayer(mod.controller.getMinecraft(), mod.lastEntity); - } - } - } - - - -} diff --git a/src/main/java/deobf/StartMC.java b/src/main/java/deobf/StartMC.java deleted file mode 100644 index 348d569c..00000000 --- a/src/main/java/deobf/StartMC.java +++ /dev/null @@ -1,28 +0,0 @@ -package deobf; - -import java.io.File; -import java.lang.reflect.Field; -import net.minecraft.client.Minecraft; - -/** - * Starts the Minecraft main class by setting the minecraft directory - * - * @author yetanotherx - * - * @obfuscated 1.4.5 - */ -public class StartMC { - - public static void main(String[] args) { - try { - // This overrides it to a local copy, to preserve my production copy - Field f = Minecraft.class.getDeclaredField("an"); - f.setAccessible(true); - f.set(null, new File(".")); - - Minecraft.main(args); - } catch (Exception e) { - e.printStackTrace(); - } - } -} diff --git a/src/main/java/deobf/mod_WorldEditCUI.java b/src/main/java/deobf/mod_WorldEditCUI.java deleted file mode 100644 index 4cfaca36..00000000 --- a/src/main/java/deobf/mod_WorldEditCUI.java +++ /dev/null @@ -1,128 +0,0 @@ -package deobf; - -import java.nio.charset.Charset; -import wecui.WorldEditCUI; -import wecui.render.RenderEntity; -import wecui.render.RenderHooks; -import java.util.Map; - -import net.minecraft.client.Minecraft; -import wecui.Updater; -import wecui.event.ChannelEvent; -import wecui.obfuscation.DataPacketList; -import wecui.obfuscation.Obfuscation; -import wecui.render.region.CuboidRegion; - -/** - * Main ModLoader class. Initializes the mod, enabling CUI communication - * between server and client, in addition to enabling rendering. - * - * TODO: Move Configuration.yml to WEConfig.yml - * - * @author lahwran - * @author yetanotherx - */ -public class mod_WorldEditCUI extends BaseMod { - - protected WorldEditCUI controller; - protected WorldClient lastWorld; - protected EntityPlayerSP lastPlayer; - protected Entity lastEntity; - protected boolean gameStarted = false; - public final static Charset UTF_8_CHARSET = Charset.forName("UTF-8"); - protected int entityUpdateTickCount = 0; - - public mod_WorldEditCUI() { - this.controller = new WorldEditCUI(ModLoader.getMinecraftInstance()); - this.controller.initialize(); - - ModLoader.registerEntityID(RenderEntity.class, "CUI", ModLoader.getUniqueEntityId()); - - ModLoader.setInGameHook(this, true, true); - ModLoader.registerPacketChannel(this, "WECUI"); - } - - @Override - public void load() { - } - - /** - * Checks if the world or player has changed from the last time we checked. - * If it's changed, spawn a new render entity and update accordingly. - * - * It also checks if initialization tasks have been done, such as checking - * for updates, resetting the region, and registering reflection for the - * outgoing command handler. - * - * @param partialticks - * @param mc - * @return - */ - @Override - public boolean onTickInGame(float partialticks, Minecraft mc) { - - if (Obfuscation.getWorld(mc) != lastWorld || Obfuscation.getPlayer(mc) != lastPlayer) { - lastEntity = controller.getObfuscation().spawnEntity(); - lastWorld = Obfuscation.getWorld(mc); - lastPlayer = Obfuscation.getPlayer(mc); - - if (!gameStarted) { - gameStarted = true; - - new Updater(controller).start(); - this.controller.setSelection(new CuboidRegion(controller)); - //new EntityUpdateThread(this).start(); - - DataPacketList.register(controller); - } - } else { - if( this.entityUpdateTickCount > 1000 ) { - this.entityUpdateTickCount = 0; - if( lastEntity != null ) { - Obfuscation.setEntityPositionToPlayer(mc, lastEntity); - } - } else { - ++this.entityUpdateTickCount; - } - } - return true; - } - - /** - * Called when the client receives a CUI packet from the server. - * @param handler - * @param packet - */ - @Override - public void clientCustomPayload(NetClientHandler handler, Packet250CustomPayload packet) { - ChannelEvent channelevent = new ChannelEvent(controller, new String(Obfuscation.getBytesFromPacket(packet), UTF_8_CHARSET)); - controller.getEventManager().callEvent(channelevent); - } - - /** - * Called when the client connects to a server. Sends the protocol version - * in a channel message to the server. - * @param handler - */ - @Override - public void clientConnect(NetClientHandler handler) { - byte[] buffer = ("v|" + WorldEditCUI.protocolVersion).getBytes(UTF_8_CHARSET); - ModLoader.clientSendPacket(Obfuscation.newPayloadPacket("WECUI", buffer.length, buffer)); - } - - /** - * Tells the renderer that all RenderEntity's should be rendered with the - * RenderHooks class. - * @param map - */ - @Override - @SuppressWarnings("unchecked") - public void addRenderer(Map map) { - map.put(RenderEntity.class, new RenderHooks(controller)); - } - - @Override - public String getVersion() { - return WorldEditCUI.getVersion(); - } -} diff --git a/src/main/java/deobf/spc_WorldEditCUI.java b/src/main/java/deobf/spc_WorldEditCUI.java deleted file mode 100644 index 0e74bf86..00000000 --- a/src/main/java/deobf/spc_WorldEditCUI.java +++ /dev/null @@ -1,37 +0,0 @@ -package deobf; - -import wecui.WorldEditCUI; -import wecui.event.CUIEvent; - -/** - * Main SinglePlayerCommands class - * - * @author lahwran - * @author yetanotherx - * - */ -public class spc_WorldEditCUI extends SPCPlugin { - - protected WorldEditCUI controller; - - public spc_WorldEditCUI(WorldEditCUI controller) { - this.controller = controller; - } - - @Override - public String getVersion() { - return WorldEditCUI.getVersion(); - } - - @Override - public String getName() { - return "WorldEditCUI"; - } - - @Override - public void handleCUIEvent(String type, String params[]) { - if (controller != null) { - controller.getEventManager().callEvent(new CUIEvent(controller, type, params)); - } - } -} \ No newline at end of file diff --git a/src/main/java/wecui/CUIDebug.java b/src/main/java/wecui/CUIDebug.java index cf852cf7..320dc8b6 100644 --- a/src/main/java/wecui/CUIDebug.java +++ b/src/main/java/wecui/CUIDebug.java @@ -7,7 +7,6 @@ import java.util.logging.Level; import java.util.logging.Logger; import wecui.exception.InitializationException; -import wecui.obfuscation.Obfuscation; import wecui.util.ConsoleLogFormatter; /** @@ -38,7 +37,7 @@ public void initialize() throws InitializationException { logger.addHandler(handler); try { - this.debugFile = new File(Obfuscation.getWorldEditCUIDir(), "WorldEditCUI-debug.txt"); + this.debugFile = new File(WorldEditCUI.getWorldEditCUIDir(), "WorldEditCUI-debug.txt"); this.debugMode = controller.getConfiguration().isDebugMode(); if (this.debugMode) { diff --git a/src/main/java/wecui/LiteModWorldEditCUI.java b/src/main/java/wecui/LiteModWorldEditCUI.java new file mode 100644 index 00000000..ba7a6b4d --- /dev/null +++ b/src/main/java/wecui/LiteModWorldEditCUI.java @@ -0,0 +1,121 @@ +package wecui; + +import java.nio.charset.Charset; +import java.util.Arrays; +import java.util.List; + +import net.minecraft.client.Minecraft; +import net.minecraft.src.EntityPlayerSP; +import net.minecraft.src.NetHandler; +import net.minecraft.src.OpenGlHelper; +import net.minecraft.src.Packet1Login; +import net.minecraft.src.RenderHelper; +import net.minecraft.src.WorldClient; +import wecui.Updater; +import wecui.WorldEditCUI; +import wecui.event.ChannelEvent; +import wecui.event.WorldRenderEvent; +import wecui.obfuscation.DataPacketList; +import wecui.render.region.CuboidRegion; + +import com.mumfrey.liteloader.InitCompleteListener; +import com.mumfrey.liteloader.PluginChannelListener; +import com.mumfrey.liteloader.PostRenderListener; +import com.mumfrey.liteloader.core.LiteLoader; + +public class LiteModWorldEditCUI implements InitCompleteListener, PluginChannelListener, PostRenderListener +{ + protected WorldEditCUI controller; + protected WorldClient lastWorld; + protected EntityPlayerSP lastPlayer; + protected boolean gameStarted = false; + public final static Charset UTF_8_CHARSET = Charset.forName("UTF-8"); + protected int entityUpdateTickCount = 0; + protected WorldRenderEvent event; + + @Override + public void init() + { + } + + /* (non-Javadoc) + * @see com.mumfrey.liteloader.InitCompleteListener#onInitCompleted(net.minecraft.client.Minecraft, com.mumfrey.liteloader.core.LiteLoader) + */ + @Override + public void onInitCompleted(Minecraft minecraft, LiteLoader loader) + { + this.controller = new WorldEditCUI(Minecraft.getMinecraft()); + this.controller.initialize(); + this.event = new WorldRenderEvent(controller); + } + + @Override + public void onLogin(NetHandler netHandler, Packet1Login loginPacket) + { + byte[] buffer = ("v|" + WorldEditCUI.protocolVersion).getBytes(UTF_8_CHARSET); + LiteLoader.getInstance().sendPluginChannelMessage("WECUI", buffer); + } + + @Override + public List getChannels() + { + return Arrays.asList(new String[] { "WECUI" }); + } + + @Override + public void onCustomPayload(String channel, int length, byte[] data) + { + ChannelEvent channelevent = new ChannelEvent(controller, new String(data, UTF_8_CHARSET)); + controller.getEventManager().callEvent(channelevent); + } + + @Override + public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clock) + { + if (inGame && clock && controller != null) + { + if (mc.theWorld != lastWorld || mc.thePlayer != lastPlayer) { + lastWorld = mc.theWorld; + lastPlayer = mc.thePlayer; + + if (!gameStarted) { + gameStarted = true; + + new Updater(controller).start(); + this.controller.setSelection(new CuboidRegion(controller)); + + DataPacketList.register(controller); + } + } + } + } + + @Override + public String getName() + { + return "WorldEditCUI by yetanotherx"; + } + + @Override + public String getVersion() + { + return "1.5.1_02_lite"; + } + + @Override + public void onPostRenderEntities(float partialTicks) + { + RenderHelper.disableStandardItemLighting(); + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); + event.setPartialTick(partialTicks); + controller.getEventManager().callEvent(event); + RenderHelper.enableStandardItemLighting(); + } + + @Override + public void onPostRender(float partialTicks) + { + // TODO Auto-generated method stub + + } +} diff --git a/src/main/java/wecui/Updater.java b/src/main/java/wecui/Updater.java index 915883a7..e1c9565a 100644 --- a/src/main/java/wecui/Updater.java +++ b/src/main/java/wecui/Updater.java @@ -7,6 +7,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; + +import net.minecraft.src.EntityClientPlayerMP; + import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.reader.UnicodeReader; import wecui.config.ConfigurationNode; @@ -58,8 +61,8 @@ public void run() { if (currentVersion != null && !currentVersion.equals(WorldEditCUI.VERSION) && !(currentVersion + "beta").equals(WorldEditCUI.VERSION)) { if (supportedVersions != null && !supportedVersions.contains(WorldEditCUI.VERSION)) { - controller.getObfuscation().showChatMessage(ChatColor.RED + "Your WorldEditCUI version is out of date! "); - controller.getObfuscation().showChatMessage(ChatColor.RED + "The latest version is " + currentVersion + ". http://bit.ly/wecui"); + this.showChatMessage(ChatColor.RED + "Your WorldEditCUI version is out of date! "); + this.showChatMessage(ChatColor.RED + "The latest version is " + currentVersion + ". http://bit.ly/wecui"); } } @@ -75,4 +78,18 @@ public void run() { } } } + + /** + * Displays a chat message on the screen, if the player is currently playing + * + * @param chat + */ + public void showChatMessage(String chat) + { + EntityClientPlayerMP thePlayer = this.controller.getMinecraft().thePlayer; + if (thePlayer != null) + { + thePlayer.addChatMessage(chat); + } + } } diff --git a/src/main/java/wecui/WorldEditCUI.java b/src/main/java/wecui/WorldEditCUI.java index b46f973a..86832e8c 100644 --- a/src/main/java/wecui/WorldEditCUI.java +++ b/src/main/java/wecui/WorldEditCUI.java @@ -1,8 +1,9 @@ package wecui; +import java.io.File; + import net.minecraft.client.Minecraft; import wecui.config.CUIConfiguration; -//import wecui.plugin.LocalPlugin; import wecui.event.CUIEvent; import wecui.event.ChannelEvent; import wecui.event.ChatCommandEvent; @@ -14,7 +15,6 @@ import wecui.exception.InitializationException; import wecui.fevents.EventManager; import wecui.fevents.Order; -import wecui.obfuscation.Obfuscation; import wecui.render.region.BaseRegion; import wecui.render.region.CuboidRegion; @@ -30,12 +30,11 @@ */ public class WorldEditCUI { - public static final String VERSION = "1.4.5"; - public static final String MCVERSION = "1.4.5"; + public static final String VERSION = "1.5.1"; + public static final String MCVERSION = "1.5.1"; public static final int protocolVersion = 2; protected Minecraft minecraft; protected EventManager eventManager; - protected Obfuscation obfuscation; protected BaseRegion selection; protected CUIDebug debugger; protected CUIConfiguration configuration; @@ -47,7 +46,6 @@ public WorldEditCUI(Minecraft minecraft) { public void initialize() { this.eventManager = new EventManager(this); - this.obfuscation = new Obfuscation(this); this.selection = new CuboidRegion(this); this.configuration = new CUIConfiguration(this); this.debugger = new CUIDebug(this); @@ -55,7 +53,6 @@ public void initialize() { try { this.eventManager.initialize(); - this.obfuscation.initialize(); this.selection.initialize(); this.configuration.initialize(); this.debugger.initialize(); @@ -118,14 +115,6 @@ public void setMinecraft(Minecraft minecraft) { this.minecraft = minecraft; } - public Obfuscation getObfuscation() { - return obfuscation; - } - - public void setObfuscation(Obfuscation obfuscation) { - this.obfuscation = obfuscation; - } - public BaseRegion getSelection() { return selection; } @@ -137,4 +126,10 @@ public void setSelection(BaseRegion selection) { public static String getVersion() { return VERSION + " for Minecraft version " + MCVERSION; } + + public static File getWorldEditCUIDir() + { + File modsFolder = new File(Minecraft.getMinecraftDir(), "mods"); + return new File(modsFolder, "WorldEditCUI"); + } } diff --git a/src/main/java/wecui/config/CUIConfiguration.java b/src/main/java/wecui/config/CUIConfiguration.java index ac5278a1..64d61f56 100644 --- a/src/main/java/wecui/config/CUIConfiguration.java +++ b/src/main/java/wecui/config/CUIConfiguration.java @@ -1,13 +1,12 @@ package wecui.config; -import deobf.mod_WorldEditCUI; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; + import wecui.InitializationFactory; import wecui.WorldEditCUI; -import wecui.obfuscation.Obfuscation; import wecui.render.LineColor; /** @@ -47,11 +46,11 @@ public CUIConfiguration(WorldEditCUI controller) { @Override public void initialize() { - File file = new File(Obfuscation.getWorldEditCUIDir(), "Configuration.yml"); + File file = new File(WorldEditCUI.getWorldEditCUIDir(), "Configuration.yml"); file.getParentFile().mkdirs(); if (!file.exists()) { - InputStream input = mod_WorldEditCUI.class.getResourceAsStream("/Configuration.yml"); + InputStream input = CUIConfiguration.class.getResourceAsStream("/Configuration.yml"); if (input != null) { FileOutputStream output = null; @@ -67,9 +66,7 @@ public void initialize() { e.printStackTrace(); } finally { try { - if (input != null) { - input.close(); - } + input.close(); } catch (IOException e) { } @@ -134,19 +131,8 @@ protected String parseColor(String color, String def) { return def; } - String r = color.substring(1, 3); - String g = color.substring(3, 5); - String b = color.substring(5, 7); - - try { - int rI = Integer.parseInt(r, 16); - int gI = Integer.parseInt(g, 16); - int bI = Integer.parseInt(b, 16); - - return color; - } catch (NumberFormatException e) { - return def; - } + // Replaced some bloody stupid code with regex + return (color.matches("(?i)^[0-9a-f]{6}$")) ? color : def; } public boolean isDebugMode() { diff --git a/src/main/java/wecui/config/ConfigurationNode.java b/src/main/java/wecui/config/ConfigurationNode.java index 27b410d9..9fc7b7cf 100644 --- a/src/main/java/wecui/config/ConfigurationNode.java +++ b/src/main/java/wecui/config/ConfigurationNode.java @@ -152,9 +152,8 @@ public int getInt(String path, int def) { if (o == null) { //setProperty(path, def); return def; - } else { - return o; - } + } + return o; } /** @@ -173,9 +172,8 @@ public double getDouble(String path, double def) { if (o == null) { //setProperty(path, def); return def; - } else { - return o; } + return o; } /** @@ -193,9 +191,8 @@ public boolean getBoolean(String path, boolean def) { if (o == null) { //setProperty(path, def); return def; - } else { - return o; } + return o; } /** diff --git a/src/main/java/wecui/config/EmptyNullRepresenter.java b/src/main/java/wecui/config/EmptyNullRepresenter.java index 0928b147..d42934e5 100644 --- a/src/main/java/wecui/config/EmptyNullRepresenter.java +++ b/src/main/java/wecui/config/EmptyNullRepresenter.java @@ -19,7 +19,8 @@ public EmptyNullRepresenter() { protected class EmptyRepresentNull implements Represent { - public Node representData(Object data) { + @Override + public Node representData(Object data) { return representScalar(Tag.NULL, ""); // Changed "null" to "" so as to avoid writing nulls } } diff --git a/src/main/java/wecui/event/CUIEvent.java b/src/main/java/wecui/event/CUIEvent.java index 09e43663..9435c390 100644 --- a/src/main/java/wecui/event/CUIEvent.java +++ b/src/main/java/wecui/event/CUIEvent.java @@ -32,7 +32,6 @@ public CUIEvent(WorldEditCUI controller, String type, String[] params) { this.params = params; this.controller.getDebugger().debug("CUI Event (" + type + ") - Params: " + Utilities.join(params, ", ")); - } @Override @@ -72,7 +71,8 @@ public boolean isHandled() { return handled; } - public boolean isCancelled() { + @Override + public boolean isCancelled() { return isHandled(); } diff --git a/src/main/java/wecui/event/ChatCommandEvent.java b/src/main/java/wecui/event/ChatCommandEvent.java index 69fecf79..35d965d5 100644 --- a/src/main/java/wecui/event/ChatCommandEvent.java +++ b/src/main/java/wecui/event/ChatCommandEvent.java @@ -93,7 +93,8 @@ public boolean isCancelled() { return cancelled; } - public void setCancelled(boolean cancelled) { + @Override + public void setCancelled(boolean cancelled) { this.cancelled = cancelled; } } \ No newline at end of file diff --git a/src/main/java/wecui/event/OutgoingChatEvent.java b/src/main/java/wecui/event/OutgoingChatEvent.java index 633f4d61..0f03a187 100644 --- a/src/main/java/wecui/event/OutgoingChatEvent.java +++ b/src/main/java/wecui/event/OutgoingChatEvent.java @@ -37,7 +37,8 @@ public String getMessage() { return message; } - public void setCancelled(boolean cancelled) { + @Override + public void setCancelled(boolean cancelled) { this.cancelled = cancelled; } } diff --git a/src/main/java/wecui/event/command/VersionCommandEvent.java b/src/main/java/wecui/event/command/VersionCommandEvent.java index b8deee01..ee05dd40 100644 --- a/src/main/java/wecui/event/command/VersionCommandEvent.java +++ b/src/main/java/wecui/event/command/VersionCommandEvent.java @@ -1,5 +1,6 @@ package wecui.event.command; +import net.minecraft.src.EntityClientPlayerMP; import wecui.WorldEditCUI; import wecui.util.ChatColor; @@ -22,6 +23,10 @@ public String getCommand() { @Override public void run() { - this.controller.getObfuscation().showChatMessage(ChatColor.LIGHT_PURPLE + "WorldEditCUI version " + WorldEditCUI.getVersion()); + EntityClientPlayerMP thePlayer = this.controller.getMinecraft().thePlayer; + if (thePlayer != null) + { + thePlayer.addChatMessage(ChatColor.LIGHT_PURPLE + "WorldEditCUI version " + WorldEditCUI.getVersion()); + } } } diff --git a/src/main/java/wecui/event/cui/CUIBaseEvent.java b/src/main/java/wecui/event/cui/CUIBaseEvent.java index 9a483c37..2eede934 100644 --- a/src/main/java/wecui/event/cui/CUIBaseEvent.java +++ b/src/main/java/wecui/event/cui/CUIBaseEvent.java @@ -70,9 +70,9 @@ public final String doRun() { } throw new RuntimeException(message); - } else { - return this.run(); } + + return this.run(); } diff --git a/src/main/java/wecui/event/cui/CUIPoint2DEvent.java b/src/main/java/wecui/event/cui/CUIPoint2DEvent.java index 20b8b734..27b0a399 100644 --- a/src/main/java/wecui/event/cui/CUIPoint2DEvent.java +++ b/src/main/java/wecui/event/cui/CUIPoint2DEvent.java @@ -25,7 +25,7 @@ public String run() { int id = this.getInt(0); int x = this.getInt(1); int z = this.getInt(2); - int regionSize = this.getInt(3); + @SuppressWarnings("unused") int regionSize = this.getInt(3); controller.getSelection().setPolygonPoint(id, x, z); controller.getDebugger().debug("Setting point2d #" + id); diff --git a/src/main/java/wecui/event/cui/CUIPointEvent.java b/src/main/java/wecui/event/cui/CUIPointEvent.java index 712473f6..6399b383 100644 --- a/src/main/java/wecui/event/cui/CUIPointEvent.java +++ b/src/main/java/wecui/event/cui/CUIPointEvent.java @@ -1,11 +1,6 @@ package wecui.event.cui; -import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.WorldVector; -import com.sk89q.worldedit.regions.RegionSelector; import wecui.WorldEditCUI; -import wecui.plugin.CUIWorld; /** * Called when point event is received diff --git a/src/main/java/wecui/event/listeners/CUIListener.java b/src/main/java/wecui/event/listeners/CUIListener.java index f8103e93..7e91d173 100644 --- a/src/main/java/wecui/event/listeners/CUIListener.java +++ b/src/main/java/wecui/event/listeners/CUIListener.java @@ -23,13 +23,16 @@ public CUIListener(WorldEditCUI controller) { this.controller = controller; } - public void onEvent(CUIEvent event) { + @Override + public void onEvent(CUIEvent event) { //Get a CUIEventType enum value from the first section of the CUI message CUIEventType eventType = CUIEventType.getTypeFromKey(event.getType()); if (eventType == null || eventType.getEventClass() == null) { event.markInvalid("Unknown CUIEvent identifier."); } + + if (eventType == null) return; try { CUIBaseEvent newEvent = Reflect.on(eventType.getEventClass()).create(this.controller, event.getParams()).get(); diff --git a/src/main/java/wecui/event/listeners/WorldRenderListener.java b/src/main/java/wecui/event/listeners/WorldRenderListener.java index f2ef8d89..75c50a34 100644 --- a/src/main/java/wecui/event/listeners/WorldRenderListener.java +++ b/src/main/java/wecui/event/listeners/WorldRenderListener.java @@ -1,8 +1,9 @@ package wecui.event.listeners; import wecui.fevents.Listener; -import wecui.obfuscation.Obfuscation; import wecui.WorldEditCUI; +import net.minecraft.src.EntityClientPlayerMP; + import org.lwjgl.opengl.GL11; import wecui.event.WorldRenderEvent; @@ -35,11 +36,9 @@ public void onEvent(WorldRenderEvent event) { GL11.glPushMatrix(); try { - Obfuscation obf = controller.getObfuscation(); - - GL11.glTranslated(-obf.getPlayerXGuess(event.getPartialTick()), - -obf.getPlayerYGuess(event.getPartialTick()), - -obf.getPlayerZGuess(event.getPartialTick())); + GL11.glTranslated(-this.getPlayerXGuess(event.getPartialTick()), + -this.getPlayerYGuess(event.getPartialTick()), + -this.getPlayerZGuess(event.getPartialTick())); GL11.glColor3f(1.0f, 1.0f, 1.0f); if (controller.getSelection() != null) { controller.getSelection().render(); @@ -55,4 +54,22 @@ public void onEvent(WorldRenderEvent event) { GL11.glDisable(GL11.GL_BLEND); //GL11.glEnable(GL11.GL_ALPHA_TEST); } + + private double getPlayerXGuess(float renderTick) + { + EntityClientPlayerMP thePlayer = controller.getMinecraft().thePlayer; + return thePlayer.prevPosX + ((thePlayer.posX - thePlayer.prevPosX) * renderTick); + } + + private double getPlayerYGuess(float renderTick) + { + EntityClientPlayerMP thePlayer = controller.getMinecraft().thePlayer; + return thePlayer.prevPosY + ((thePlayer.posY - thePlayer.prevPosY) * renderTick); + } + + private double getPlayerZGuess(float renderTick) + { + EntityClientPlayerMP thePlayer = controller.getMinecraft().thePlayer; + return thePlayer.prevPosZ + ((thePlayer.posZ - thePlayer.prevPosZ) * renderTick); + } } diff --git a/src/main/java/wecui/fevents/Event.java b/src/main/java/wecui/fevents/Event.java index 05a2b9be..6d9fec73 100644 --- a/src/main/java/wecui/fevents/Event.java +++ b/src/main/java/wecui/fevents/Event.java @@ -44,7 +44,8 @@ public abstract class Event> { */ protected abstract String getEventName(); - public String toString() { + @Override + public String toString() { return getEventName() + " (" + this.getClass().getName() + ")"; } diff --git a/src/main/java/wecui/fevents/HandlerList.java b/src/main/java/wecui/fevents/HandlerList.java index f19db186..c40cd455 100644 --- a/src/main/java/wecui/fevents/HandlerList.java +++ b/src/main/java/wecui/fevents/HandlerList.java @@ -42,7 +42,7 @@ public class HandlerList> { /** * List of all handlerlists which have been created, for use in bakeall() */ - private static ArrayList alllists = new ArrayList(); + private static ArrayList>> alllists = new ArrayList>>(); /** * Bake all handler lists. Best used just after all normal event @@ -50,7 +50,7 @@ public class HandlerList> { * you're using fevents in a plugin system. */ public static void bakeall() { - for (HandlerList h : alllists) { + for (HandlerList> h : alllists) { h.bake(); } } @@ -109,7 +109,7 @@ void bake() { if (baked) { return; // don't re-bake when still valid } - ArrayList handlerslist = new ArrayList(); + ArrayList>[]> handlerslist = new ArrayList>[]>(); ArrayList handleridslist = new ArrayList(); for (Entry>> entry : handlerslots.entrySet()) { Order orderslot = entry.getKey(); diff --git a/src/main/java/wecui/obfuscation/DataPacketList.java b/src/main/java/wecui/obfuscation/DataPacketList.java index d90d22a3..dadd4801 100644 --- a/src/main/java/wecui/obfuscation/DataPacketList.java +++ b/src/main/java/wecui/obfuscation/DataPacketList.java @@ -1,13 +1,15 @@ package wecui.obfuscation; -import deobf.EntityClientPlayerMP; -import deobf.NetClientHandler; -import deobf.NetworkManager; -import deobf.Packet; -import deobf.Packet3Chat; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; + +import net.minecraft.src.EntityClientPlayerMP; +import net.minecraft.src.INetworkManager; +import net.minecraft.src.NetClientHandler; +import net.minecraft.src.TcpConnection; +import net.minecraft.src.Packet; +import net.minecraft.src.Packet3Chat; import wecui.WorldEditCUI; import wecui.event.ChatCommandEvent; import wecui.event.OutgoingChatEvent; @@ -40,11 +42,12 @@ public DataPacketList(WorldEditCUI controller, Class typeClass) { * @param packet * @return */ - public boolean add(T packet) { + @Override + public boolean add(T packet) { if (packet instanceof Packet3Chat) { boolean cancelled = false; - String s = Obfuscation.getChatFromPacket((Packet3Chat) packet); + String s = ((Packet3Chat)packet).message; // Obfuscation.getChatFromPacket((Packet3Chat) packet); OutgoingChatEvent chatevent = new OutgoingChatEvent(controller, s); controller.getEventManager().callEvent(chatevent); @@ -77,38 +80,26 @@ public static void register(WorldEditCUI controller) { registered = true; DataPacketList list = new DataPacketList(controller, Packet.class); - Obfuscation obf = controller.getObfuscation(); - - //Checks if it's a multiplayer world - if (!obf.isMultiplayerWorld()) { - return; - } - EntityClientPlayerMP player = (EntityClientPlayerMP) obf.getPlayer(); + EntityClientPlayerMP player = controller.getMinecraft().thePlayer; try { - NetClientHandler nch = obf.getNetClientHandler(player); - - Field nmField = NetClientHandler.class.getDeclaredField(FieldObfuscation.NETWORKMANAGER.getVariable()); - nmField.setAccessible(true); - Object nmMebbe = nmField.get(nch); - NetworkManager nm = null; - if (nmMebbe instanceof NetworkManager) { - nm = (NetworkManager) nmField.get(nch); - } else { - return; + NetClientHandler nch = player.sendQueue; + INetworkManager nm = nch.getNetManager(); + + if (nm instanceof TcpConnection) + { + Field listField = TcpConnection.class.getDeclaredField(FieldObfuscation.dataPackets.getVariable()); + listField.setAccessible(true); + @SuppressWarnings("unchecked") + List oldPacketList = (List)listField.get(nm); + for (Object item : oldPacketList) { + list.add((Packet) item); + } + + listField.set(nm, list); } - Field listField = NetworkManager.class.getDeclaredField(FieldObfuscation.PACKETLIST.getVariable()); - listField.setAccessible(true); - List oldPacketList = (List) listField.get(nm); - for (Object item : oldPacketList) { - list.add((Packet) item); - } - - listField.set(nm, list); - nmField.set(nch, nm); - } catch (Exception e) { throw new RuntimeException("Error inserting outgoing chat handler - Certain parts of WorldEditCUI will not work!", e); } diff --git a/src/main/java/wecui/obfuscation/FieldObfuscation.java b/src/main/java/wecui/obfuscation/FieldObfuscation.java index 900c22d4..29fc5265 100644 --- a/src/main/java/wecui/obfuscation/FieldObfuscation.java +++ b/src/main/java/wecui/obfuscation/FieldObfuscation.java @@ -1,43 +1,42 @@ package wecui.obfuscation; +import com.mumfrey.liteloader.util.ModUtilities; + /** * Method name obfuscation, used whenever we use reflection. * This lets us keep reflected obfuscated methods in a central * class to ease updating. * * @author yetanotherx + * @author Mumfrey * - * @obfuscated 1.4.5 + * @obfuscated 1.5.1 */ public enum FieldObfuscation { - /** - * NetworkManager instance in NetClientHandler.class - */ - NETWORKMANAGER("g"), /** * Packet stream list in NetworkManager.class */ - PACKETLIST("p"), + dataPackets("q", "field_74487_p"), /** * ID->Class hashmap for packets in Packet.class */ - IDSTOCLASSES("l"), - /** - * Class->ID hashmap for packets in Packet.class - */ - CLASSESTOIDS("a"); + packetIdToClassMap("l", "field_73294_l"); + protected String variable; + + protected String seargeVariable; - private FieldObfuscation(String variable) { + private FieldObfuscation(String variable, String seargeVariable) { this.variable = variable; + this.seargeVariable = seargeVariable; } public String getVariable() { - return variable; + return ModUtilities.getObfuscatedFieldName(this.toString(), variable, seargeVariable); } public static String getVariable(FieldObfuscation type) { - return type.getVariable(); + return ModUtilities.getObfuscatedFieldName(type.toString(), type.variable, type.seargeVariable); } } diff --git a/src/main/java/wecui/obfuscation/Obfuscation.java b/src/main/java/wecui/obfuscation/Obfuscation.java deleted file mode 100644 index cb6083b3..00000000 --- a/src/main/java/wecui/obfuscation/Obfuscation.java +++ /dev/null @@ -1,140 +0,0 @@ -package wecui.obfuscation; - -import deobf.Entity; -import deobf.EntityClientPlayerMP; -import deobf.EntityPlayerSP; -import deobf.NetClientHandler; -import deobf.Packet250CustomPayload; -import deobf.Packet3Chat; -import deobf.WorldClient; -import java.io.File; -import net.minecraft.client.Minecraft; -import wecui.InitializationFactory; -import wecui.WorldEditCUI; -import wecui.render.RenderEntity; - -/** - * Main obfuscation class - * Combines all obfuscated classes and methods into a single class - * Eases updates, cleans up the rest of the codebase. - * - * @author lahwran - * @author yetanotherx - * - * @obfuscated 1.4.5 - */ -public class Obfuscation implements InitializationFactory { - - protected WorldEditCUI controller; - protected Minecraft minecraft; - - public Obfuscation(WorldEditCUI controller) { - this.controller = controller; - } - - @Override - public void initialize() { - this.minecraft = this.controller.getMinecraft(); - } - - public boolean isMultiplayerWorld() { - return true; // TODO - Temprarily until I can figure out the new server thing - //return minecraft.l(); - } - - /** - * Displays a chat message on the screen, if the player is currently playing - * @param chat - */ - public void showChatMessage(String chat) { - if (getPlayer() != null) { - getPlayer().b(chat); - } - } - - public EntityPlayerSP getPlayer() { - return getPlayer(minecraft); - } - - public WorldClient getWorld() { - return getWorld(minecraft); - } - - public Entity spawnEntity() { - Minecraft mc = this.controller.getMinecraft(); - - Entity entity = new RenderEntity(this.controller, getWorld(mc)); - setEntityPositionToPlayer(mc, entity); - getWorld(mc).d(entity); - setEntityPositionToPlayer(mc, entity); - controller.getDebugger().debug("RenderEntity spawned"); - return entity; - } - - public static double getPlayerX(EntityPlayerSP player) { - return player.t; - } - - public static double getPlayerY(EntityPlayerSP player) { - return player.u; - } - - public static double getPlayerZ(EntityPlayerSP player) { - return player.v; - } - - public double getPlayerXGuess(float renderTick) { - EntityPlayerSP plyr = getPlayer(); - return plyr.q + ((plyr.t - plyr.q) * renderTick); - } - - public double getPlayerYGuess(float renderTick) { - EntityPlayerSP plyr = getPlayer(); - return plyr.r + ((plyr.u - plyr.r) * renderTick); - } - - public double getPlayerZGuess(float renderTick) { - EntityPlayerSP plyr = getPlayer(); - return plyr.s + ((plyr.v - plyr.s) * renderTick); - } - - public static EntityPlayerSP getPlayer(Minecraft mc) { - return mc.g; - } - - public static WorldClient getWorld(Minecraft mc) { - return mc.e; - } - - public static void setEntityPositionToPlayer(Minecraft mc, Entity entity) { - entity.b(getPlayerX(mc.g), getPlayerY(mc.g), getPlayerZ(mc.g)); - } - - public NetClientHandler getNetClientHandler(EntityClientPlayerMP player) { - return player.a; - } - - public static String getChatFromPacket(Packet3Chat packet) { - return packet.b; - } - - public static byte[] getBytesFromPacket(Packet250CustomPayload packet) { - return packet.c; - } - - public static Packet250CustomPayload newPayloadPacket(String name, int len, byte[] data) { - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.a = name; - packet.b = len; - packet.c = data; - return packet; - } - - public static File getMinecraftDir() { - return Minecraft.b(); - } - - public static File getWorldEditCUIDir() { - return new File(getMinecraftDir(), "mods" + File.separator + "WorldEditCUI"); - } -} diff --git a/src/main/java/wecui/obfuscation/RenderObfuscation.java b/src/main/java/wecui/obfuscation/RenderObfuscation.java deleted file mode 100644 index 9885cbc3..00000000 --- a/src/main/java/wecui/obfuscation/RenderObfuscation.java +++ /dev/null @@ -1,54 +0,0 @@ -package wecui.obfuscation; - -import deobf.RenderHelper; -import deobf.Tessellator; - -/** - * Singleton obfuscation class for dealing - * with tesselator rendering. - * - * @author yetanotherx - * @author lahwran - * - * @obfuscated 1.4.5 - */ -public class RenderObfuscation { - - protected Tessellator tess; - - protected RenderObfuscation() { - tess = Tessellator.a; - } - - public void startDrawing(int type) { - tess.b(type); - } - - public void addVertex(double x, double y, double z) { - tess.a(x, y, z); - } - - public void finishDrawing() { - tess.a(); - } - - /** - * TODO: Find if this is even necessary - */ - public static void disableLighting() { - RenderHelper.a(); - } - - public static void enableLighting() { - RenderHelper.b(); - } - - public static RenderObfuscation getInstance() { - return RenderObfuscationHolder.INSTANCE; - } - - protected static class RenderObfuscationHolder { - - protected static final RenderObfuscation INSTANCE = new RenderObfuscation(); - } -} diff --git a/src/main/java/wecui/render/RenderEntity.java b/src/main/java/wecui/render/RenderEntity.java deleted file mode 100644 index 57738867..00000000 --- a/src/main/java/wecui/render/RenderEntity.java +++ /dev/null @@ -1,111 +0,0 @@ -package wecui.render; - -import deobf.Entity; -import deobf.NBTTagCompound; -import deobf.WorldClient; -import deobf.Vec3; -import wecui.WorldEditCUI; - -/** - * Custom entity renderer, attached in the ModLoader class - * - * @author lahwran - * @author yetanotherx - * - * @obfuscated 1.4.5 - */ -public class RenderEntity extends Entity { - - protected WorldEditCUI controller; - - public RenderEntity(WorldEditCUI controller, WorldClient world) { - super(world); - - this.controller = controller; - this.al = true; // Entity.ignoreFrustumCheck - this.Y = true; // Entity.noClip - this.b(0, 0); // Entity.setSize() - controller.getDebugger().debug("Entity spawned"); - } - - /** - * Entity.readEntityFromNBT - * @param arg0 - */ - @Override - protected void a(NBTTagCompound arg0) { - } - - /** - * Entity.writeEntityToNBT - * @param arg0 - */ - @Override - protected void b(NBTTagCompound arg0) { - } - - /** - * Entity.entityInit - */ - @Override - protected void a() { - } - - /** - * Entity.onUpdate - */ - @Override - public void j_() { - //Obfuscation.setEntityPositionToPlayer(controller.getMinecraft(), this); - } - - /** - * Entity.setDead - */ - @Override - public void x() { - } - - /** - * Entity.whatEver() - * Returns the name of the entity. - * @return - */ - @Override - public String an() { - return "CUI"; - } - - /** - * Entity.isInRangeToRenderVec3D - * Always returns true, we want to render the entity no matter where we are. - * @param vector - * @return - */ - @Override - public boolean a(Vec3 vector) { - return true; - } - - /** - * Entity.getBrightnessForRender - * Always return the maximum value, we want to always see it. - * @param f - * @return - */ - @Override - public int b(float f) { - return 0xf000f0; - } - - /** - * Entity.getBrightness - * Always return the maximum value, we want to always see it. - * @param f - * @return - */ - @Override - public float c(float f) { - return 1f; - } -} diff --git a/src/main/java/wecui/render/RenderHooks.java b/src/main/java/wecui/render/RenderHooks.java deleted file mode 100644 index 875eb14f..00000000 --- a/src/main/java/wecui/render/RenderHooks.java +++ /dev/null @@ -1,56 +0,0 @@ -package wecui.render; - -import deobf.Entity; -import deobf.Render; -import wecui.event.WorldRenderEvent; -import wecui.WorldEditCUI; -import wecui.obfuscation.RenderObfuscation; - -/** - * Custom entity renderer, attached in the ModLoader class - * - * @author lahwran - * @author yetanotherx - * - * @obfuscated 1.4.5 - */ -public class RenderHooks extends Render { - - protected WorldEditCUI controller; - protected WorldRenderEvent event; - - public RenderHooks(WorldEditCUI controller) { - this.controller = controller; - this.event = new WorldRenderEvent(controller); - } - - /** - * Actually renders the entity. - * @param entity - * @param x - * @param y - * @param z - * @param yaw - * @param renderTick - */ - public void renderCUI(Entity entity, double x, double y, double z, float yaw, float renderTick) { - RenderObfuscation.disableLighting(); - event.setPartialTick(renderTick); - controller.getEventManager().callEvent(event); - RenderObfuscation.enableLighting(); - } - - /** - * Render.doRender - * @param entity - * @param x - * @param y - * @param z - * @param yaw - * @param renderTick - */ - @Override - public void a(Entity entity, double x, double y, double z, float yaw, float renderTick) { - renderCUI(entity, x, y, z, yaw, renderTick); - } -} diff --git a/src/main/java/wecui/render/shapes/Render2DBox.java b/src/main/java/wecui/render/shapes/Render2DBox.java index a0168a6e..ffc76e56 100644 --- a/src/main/java/wecui/render/shapes/Render2DBox.java +++ b/src/main/java/wecui/render/shapes/Render2DBox.java @@ -1,8 +1,11 @@ package wecui.render.shapes; import java.util.List; + +import net.minecraft.src.Tessellator; + import org.lwjgl.opengl.GL11; -import wecui.obfuscation.RenderObfuscation; + import wecui.render.LineColor; import wecui.render.LineInfo; import wecui.render.points.PointRectangle; @@ -15,7 +18,6 @@ */ public class Render2DBox { - protected RenderObfuscation obf = RenderObfuscation.getInstance(); protected LineColor color; protected List points; protected int min; @@ -29,20 +31,21 @@ public Render2DBox(LineColor color, List points, int min, int ma } public void render() { + Tessellator tess = Tessellator.instance; double off = 0.03; for (LineInfo tempColor : color.getColors()) { tempColor.prepareRender(); - obf.startDrawing(GL11.GL_LINES); + tess.startDrawing(GL11.GL_LINES); tempColor.prepareColor(); for (PointRectangle point : points) { if (point != null) { - obf.addVertex(point.getPoint().getX() + 0.5, min + off, point.getPoint().getY() + 0.5); - obf.addVertex(point.getPoint().getX() + 0.5, max + 1 + off, point.getPoint().getY() + 0.5); + tess.addVertex(point.getPoint().getX() + 0.5, min + off, point.getPoint().getY() + 0.5); + tess.addVertex(point.getPoint().getX() + 0.5, max + 1 + off, point.getPoint().getY() + 0.5); } } - obf.finishDrawing(); + tess.draw(); } } } diff --git a/src/main/java/wecui/render/shapes/Render2DGrid.java b/src/main/java/wecui/render/shapes/Render2DGrid.java index 489dc029..97934012 100644 --- a/src/main/java/wecui/render/shapes/Render2DGrid.java +++ b/src/main/java/wecui/render/shapes/Render2DGrid.java @@ -1,8 +1,11 @@ package wecui.render.shapes; import java.util.List; + +import net.minecraft.src.Tessellator; + import org.lwjgl.opengl.GL11; -import wecui.obfuscation.RenderObfuscation; + import wecui.render.LineColor; import wecui.render.LineInfo; import wecui.render.points.PointRectangle; @@ -15,7 +18,6 @@ */ public class Render2DGrid { - protected RenderObfuscation obf = RenderObfuscation.getInstance(); protected LineColor color; protected List points; protected int min; @@ -36,17 +38,18 @@ public void render() { } protected void drawPoly(double height) { + Tessellator tess = Tessellator.instance; for (LineInfo tempColor : color.getColors()) { tempColor.prepareRender(); - obf.startDrawing(GL11.GL_LINE_LOOP); + tess.startDrawing(GL11.GL_LINE_LOOP); tempColor.prepareColor(); for (PointRectangle point : points) { if (point != null) { - obf.addVertex(point.getPoint().getX() + 0.5, height, point.getPoint().getY() + 0.5); + tess.addVertex(point.getPoint().getX() + 0.5, height, point.getPoint().getY() + 0.5); } } - obf.finishDrawing(); + tess.draw(); } } } diff --git a/src/main/java/wecui/render/shapes/Render3DBox.java b/src/main/java/wecui/render/shapes/Render3DBox.java index e2d37eb0..f09468aa 100644 --- a/src/main/java/wecui/render/shapes/Render3DBox.java +++ b/src/main/java/wecui/render/shapes/Render3DBox.java @@ -1,7 +1,9 @@ package wecui.render.shapes; +import net.minecraft.src.Tessellator; + import org.lwjgl.opengl.GL11; -import wecui.obfuscation.RenderObfuscation; + import wecui.render.LineColor; import wecui.render.LineInfo; import wecui.util.Vector3; @@ -14,7 +16,6 @@ */ public class Render3DBox { - protected RenderObfuscation obf = RenderObfuscation.getInstance(); protected LineColor color; protected Vector3 first; protected Vector3 second; @@ -26,6 +27,7 @@ public Render3DBox(LineColor color, Vector3 first, Vector3 second) { } public void render() { + Tessellator tess = Tessellator.instance; double x1 = first.getX(); double y1 = first.getY(); double z1 = first.getZ(); @@ -37,40 +39,40 @@ public void render() { tempColor.prepareRender(); // Draw bottom face - obf.startDrawing(GL11.GL_LINE_LOOP); + tess.startDrawing(GL11.GL_LINE_LOOP); tempColor.prepareColor(); - obf.addVertex(x1, y1, z1); - obf.addVertex(x2, y1, z1); - obf.addVertex(x2, y1, z2); - obf.addVertex(x1, y1, z2); - obf.finishDrawing(); + tess.addVertex(x1, y1, z1); + tess.addVertex(x2, y1, z1); + tess.addVertex(x2, y1, z2); + tess.addVertex(x1, y1, z2); + tess.draw(); // Draw top face - obf.startDrawing(GL11.GL_LINE_LOOP); + tess.startDrawing(GL11.GL_LINE_LOOP); tempColor.prepareColor(); - obf.addVertex(x1, y2, z1); - obf.addVertex(x2, y2, z1); - obf.addVertex(x2, y2, z2); - obf.addVertex(x1, y2, z2); - obf.finishDrawing(); + tess.addVertex(x1, y2, z1); + tess.addVertex(x2, y2, z1); + tess.addVertex(x2, y2, z2); + tess.addVertex(x1, y2, z2); + tess.draw(); // Draw join top and bottom faces - obf.startDrawing(GL11.GL_LINES); + tess.startDrawing(GL11.GL_LINES); tempColor.prepareColor(); - obf.addVertex(x1, y1, z1); - obf.addVertex(x1, y2, z1); + tess.addVertex(x1, y1, z1); + tess.addVertex(x1, y2, z1); - obf.addVertex(x2, y1, z1); - obf.addVertex(x2, y2, z1); + tess.addVertex(x2, y1, z1); + tess.addVertex(x2, y2, z1); - obf.addVertex(x2, y1, z2); - obf.addVertex(x2, y2, z2); + tess.addVertex(x2, y1, z2); + tess.addVertex(x2, y2, z2); - obf.addVertex(x1, y1, z2); - obf.addVertex(x1, y2, z2); + tess.addVertex(x1, y1, z2); + tess.addVertex(x1, y2, z2); - obf.finishDrawing(); + tess.draw(); } } } diff --git a/src/main/java/wecui/render/shapes/Render3DGrid.java b/src/main/java/wecui/render/shapes/Render3DGrid.java index 74063f3a..855c3689 100644 --- a/src/main/java/wecui/render/shapes/Render3DGrid.java +++ b/src/main/java/wecui/render/shapes/Render3DGrid.java @@ -1,7 +1,9 @@ package wecui.render.shapes; +import net.minecraft.src.Tessellator; + import org.lwjgl.opengl.GL11; -import wecui.obfuscation.RenderObfuscation; + import wecui.render.LineColor; import wecui.render.LineInfo; import wecui.util.Vector3; @@ -14,7 +16,6 @@ */ public class Render3DGrid { - protected RenderObfuscation obf = RenderObfuscation.getInstance(); protected LineColor color; protected Vector3 first; protected Vector3 second; @@ -26,6 +27,7 @@ public Render3DGrid(LineColor color, Vector3 first, Vector3 second) { } public void render() { + Tessellator tess = Tessellator.instance; double x1 = first.getX(); double y1 = first.getY(); double z1 = first.getZ(); @@ -36,8 +38,7 @@ public void render() { for (LineInfo tempColor : color.getColors()) { tempColor.prepareRender(); - RenderObfuscation o = RenderObfuscation.getInstance(); - o.startDrawing(GL11.GL_LINES); + tess.startDrawing(GL11.GL_LINES); tempColor.prepareColor(); double x, y, z; @@ -49,8 +50,8 @@ public void render() { int msize = 150; if ((y2 - y / offsetSize) < msize) { for (double yoff = 0; yoff + y <= y2; yoff += offsetSize) { - o.addVertex(x1, y + yoff, z); - o.addVertex(x2, y + yoff, z); + tess.addVertex(x1, y + yoff, z); + tess.addVertex(x2, y + yoff, z); } } @@ -58,8 +59,8 @@ public void render() { z = z1; if ((y2 - y / offsetSize) < msize) { for (double yoff = 0; yoff + y <= y2; yoff += offsetSize) { - o.addVertex(x1, y + yoff, z); - o.addVertex(x2, y + yoff, z); + tess.addVertex(x1, y + yoff, z); + tess.addVertex(x2, y + yoff, z); } } @@ -67,8 +68,8 @@ public void render() { x = x1; if ((y2 - y / offsetSize) < msize) { for (double yoff = 0; yoff + y <= y2; yoff += offsetSize) { - o.addVertex(x, y + yoff, z1); - o.addVertex(x, y + yoff, z2); + tess.addVertex(x, y + yoff, z1); + tess.addVertex(x, y + yoff, z2); } } @@ -76,8 +77,8 @@ public void render() { x = x2; if ((y2 - y / offsetSize) < msize) { for (double yoff = 0; yoff + y <= y2; yoff += offsetSize) { - o.addVertex(x, y + yoff, z1); - o.addVertex(x, y + yoff, z2); + tess.addVertex(x, y + yoff, z1); + tess.addVertex(x, y + yoff, z2); } } @@ -86,32 +87,32 @@ public void render() { z = z1; if ((x2 - x / offsetSize) < msize) { for (double xoff = 0; xoff + x <= x2; xoff += offsetSize) { - o.addVertex(x + xoff, y1, z); - o.addVertex(x + xoff, y2, z); + tess.addVertex(x + xoff, y1, z); + tess.addVertex(x + xoff, y2, z); } } // Zmax XY plane, x axis z = z2; if ((x2 - x / offsetSize) < msize) { for (double xoff = 0; xoff + x <= x2; xoff += offsetSize) { - o.addVertex(x + xoff, y1, z); - o.addVertex(x + xoff, y2, z); + tess.addVertex(x + xoff, y1, z); + tess.addVertex(x + xoff, y2, z); } } // Ymin XZ plane, x axis y = y2; if ((x2 - x / offsetSize) < msize) { for (double xoff = 0; xoff + x <= x2; xoff += offsetSize) { - o.addVertex(x + xoff, y, z1); - o.addVertex(x + xoff, y, z2); + tess.addVertex(x + xoff, y, z1); + tess.addVertex(x + xoff, y, z2); } } // Ymax XZ plane, x axis y = y1; if ((x2 - x / offsetSize) < msize) { for (double xoff = 0; xoff + x <= x2; xoff += offsetSize) { - o.addVertex(x + xoff, y, z1); - o.addVertex(x + xoff, y, z2); + tess.addVertex(x + xoff, y, z1); + tess.addVertex(x + xoff, y, z2); } } @@ -120,36 +121,36 @@ public void render() { y = y1; if ((z2 - z / offsetSize) < msize) { for (double zoff = 0; zoff + z <= z2; zoff += offsetSize) { - o.addVertex(x1, y, z + zoff); - o.addVertex(x2, y, z + zoff); + tess.addVertex(x1, y, z + zoff); + tess.addVertex(x2, y, z + zoff); } } // Ymax XZ plane, z axis y = y2; if ((z2 - z / offsetSize) < msize) { for (double zoff = 0; zoff + z <= z2; zoff += offsetSize) { - o.addVertex(x1, y, z + zoff); - o.addVertex(x2, y, z + zoff); + tess.addVertex(x1, y, z + zoff); + tess.addVertex(x2, y, z + zoff); } } // Xmin YZ plane, z axis x = x2; if ((z2 - z / offsetSize) < msize) { for (double zoff = 0; zoff + z <= z2; zoff += offsetSize) { - o.addVertex(x, y1, z + zoff); - o.addVertex(x, y2, z + zoff); + tess.addVertex(x, y1, z + zoff); + tess.addVertex(x, y2, z + zoff); } } // Xmax YZ plane, z axis x = x1; if ((z2 - z / offsetSize) < msize) { for (double zoff = 0; zoff + z <= z2; zoff += offsetSize) { - o.addVertex(x, y1, z + zoff); - o.addVertex(x, y2, z + zoff); + tess.addVertex(x, y1, z + zoff); + tess.addVertex(x, y2, z + zoff); } } - o.finishDrawing(); + tess.draw(); } } } diff --git a/src/main/java/wecui/render/shapes/RenderCylinderBox.java b/src/main/java/wecui/render/shapes/RenderCylinderBox.java index 7d50f178..62ef8df4 100644 --- a/src/main/java/wecui/render/shapes/RenderCylinderBox.java +++ b/src/main/java/wecui/render/shapes/RenderCylinderBox.java @@ -1,7 +1,9 @@ package wecui.render.shapes; +import net.minecraft.src.Tessellator; + import org.lwjgl.opengl.GL11; -import wecui.obfuscation.RenderObfuscation; + import wecui.render.LineColor; import wecui.render.LineInfo; import wecui.render.points.PointCube; @@ -18,7 +20,6 @@ public class RenderCylinderBox { protected double radZ = 0; protected int minY; protected int maxY; - protected RenderObfuscation obf = RenderObfuscation.getInstance(); protected double centerX; protected double centerZ; @@ -33,12 +34,13 @@ public RenderCylinderBox(LineColor color, PointCube center, double radX, double } public void render() { + Tessellator tess = Tessellator.instance; for (LineInfo tempColor : color.getColors()) { tempColor.prepareRender(); double twoPi = Math.PI * 2; for (int yBlock : new int[]{minY, maxY + 1}) { - obf.startDrawing(GL11.GL_LINE_LOOP); + tess.startDrawing(GL11.GL_LINE_LOOP); tempColor.prepareColor(); for (int i = 0; i <= 75; i++) { @@ -46,9 +48,9 @@ public void render() { double tempX = radX * Math.cos(tempTheta); double tempZ = radZ * Math.sin(tempTheta); - obf.addVertex(centerX + tempX, yBlock, centerZ + tempZ); + tess.addVertex(centerX + tempX, yBlock, centerZ + tempZ); } - obf.finishDrawing(); + tess.draw(); } } } diff --git a/src/main/java/wecui/render/shapes/RenderCylinderCircles.java b/src/main/java/wecui/render/shapes/RenderCylinderCircles.java index 63077fe8..e9963d8f 100644 --- a/src/main/java/wecui/render/shapes/RenderCylinderCircles.java +++ b/src/main/java/wecui/render/shapes/RenderCylinderCircles.java @@ -1,7 +1,9 @@ package wecui.render.shapes; +import net.minecraft.src.Tessellator; + import org.lwjgl.opengl.GL11; -import wecui.obfuscation.RenderObfuscation; + import wecui.render.LineColor; import wecui.render.LineInfo; import wecui.render.points.PointCube; @@ -18,7 +20,6 @@ public class RenderCylinderCircles { protected double radZ = 0; protected int minY; protected int maxY; - protected RenderObfuscation obf = RenderObfuscation.getInstance(); protected double centerX; protected double centerZ; @@ -33,12 +34,13 @@ public RenderCylinderCircles(LineColor color, PointCube center, double radX, dou } public void render() { + Tessellator tess = Tessellator.instance; for (LineInfo tempColor : color.getColors()) { tempColor.prepareRender(); double twoPi = Math.PI * 2; for (int yBlock = minY + 1; yBlock <= maxY; yBlock++) { - obf.startDrawing(GL11.GL_LINE_LOOP); + tess.startDrawing(GL11.GL_LINE_LOOP); tempColor.prepareColor(); for (int i = 0; i <= 75; i++) { @@ -46,9 +48,9 @@ public void render() { double tempX = radX * Math.cos(tempTheta); double tempZ = radZ * Math.sin(tempTheta); - obf.addVertex(centerX + tempX, yBlock, centerZ + tempZ); + tess.addVertex(centerX + tempX, yBlock, centerZ + tempZ); } - obf.finishDrawing(); + tess.draw(); } } } diff --git a/src/main/java/wecui/render/shapes/RenderCylinderGrid.java b/src/main/java/wecui/render/shapes/RenderCylinderGrid.java index 741aab3f..b0051326 100644 --- a/src/main/java/wecui/render/shapes/RenderCylinderGrid.java +++ b/src/main/java/wecui/render/shapes/RenderCylinderGrid.java @@ -1,7 +1,9 @@ package wecui.render.shapes; +import net.minecraft.src.Tessellator; + import org.lwjgl.opengl.GL11; -import wecui.obfuscation.RenderObfuscation; + import wecui.render.LineColor; import wecui.render.LineInfo; import wecui.render.points.PointCube; @@ -18,7 +20,6 @@ public class RenderCylinderGrid { protected double radZ = 0; protected int minY; protected int maxY; - protected RenderObfuscation obf = RenderObfuscation.getInstance(); protected double centerX; protected double centerZ; @@ -33,6 +34,7 @@ public RenderCylinderGrid(LineColor color, PointCube center, double radX, double } public void render() { + Tessellator tess = Tessellator.instance; for (LineInfo tempColor : color.getColors()) { tempColor.prepareRender(); @@ -45,28 +47,28 @@ public void render() { for (double tempX = negRadiusX; tempX <= posRadiusX; ++tempX) { double tempZ = radZ * Math.cos(Math.asin(tempX / radX)); - obf.startDrawing(GL11.GL_LINE_LOOP); + tess.startDrawing(GL11.GL_LINE_LOOP); tempColor.prepareColor(); - obf.addVertex(centerX + tempX, tmaxY, centerZ + tempZ); - obf.addVertex(centerX + tempX, tmaxY, centerZ - tempZ); - obf.addVertex(centerX + tempX, tminY, centerZ - tempZ); - obf.addVertex(centerX + tempX, tminY, centerZ + tempZ); + tess.addVertex(centerX + tempX, tmaxY, centerZ + tempZ); + tess.addVertex(centerX + tempX, tmaxY, centerZ - tempZ); + tess.addVertex(centerX + tempX, tminY, centerZ - tempZ); + tess.addVertex(centerX + tempX, tminY, centerZ + tempZ); - obf.finishDrawing(); + tess.draw(); } for (double tempZ = negRadiusZ; tempZ <= posRadiusZ; ++tempZ) { double tempX = radX * Math.sin(Math.acos(tempZ / radZ)); - obf.startDrawing(GL11.GL_LINE_LOOP); + tess.startDrawing(GL11.GL_LINE_LOOP); tempColor.prepareColor(); - obf.addVertex(centerX + tempX, tmaxY, centerZ + tempZ); - obf.addVertex(centerX - tempX, tmaxY, centerZ + tempZ); - obf.addVertex(centerX - tempX, tminY, centerZ + tempZ); - obf.addVertex(centerX + tempX, tminY, centerZ + tempZ); + tess.addVertex(centerX + tempX, tmaxY, centerZ + tempZ); + tess.addVertex(centerX - tempX, tmaxY, centerZ + tempZ); + tess.addVertex(centerX - tempX, tminY, centerZ + tempZ); + tess.addVertex(centerX + tempX, tminY, centerZ + tempZ); - obf.finishDrawing(); + tess.draw(); } } } diff --git a/src/main/java/wecui/render/shapes/RenderEllipsoid.java b/src/main/java/wecui/render/shapes/RenderEllipsoid.java index 1ba053d4..f3aee0ac 100644 --- a/src/main/java/wecui/render/shapes/RenderEllipsoid.java +++ b/src/main/java/wecui/render/shapes/RenderEllipsoid.java @@ -1,7 +1,9 @@ package wecui.render.shapes; +import net.minecraft.src.Tessellator; + import org.lwjgl.opengl.GL11; -import wecui.obfuscation.RenderObfuscation; + import wecui.render.LineColor; import wecui.render.LineInfo; import wecui.render.points.PointCube; @@ -17,7 +19,6 @@ public class RenderEllipsoid { protected LineColor color; protected PointCube center; protected Vector3 radii; - protected RenderObfuscation obf = RenderObfuscation.getInstance(); protected final static double twoPi = Math.PI * 2; protected double centerX; protected double centerY; @@ -42,9 +43,10 @@ public void render() { } protected void drawXZPlane(LineInfo color) { + Tessellator tess = Tessellator.instance; int yRad = (int) Math.floor(radii.getY()); for (int yBlock = -yRad; yBlock < yRad; yBlock++) { - obf.startDrawing(GL11.GL_LINE_LOOP); + tess.startDrawing(GL11.GL_LINE_LOOP); color.prepareColor(); for (int i = 0; i <= 40; i++) { @@ -52,12 +54,12 @@ protected void drawXZPlane(LineInfo color) { double tempX = radii.getX() * Math.cos(tempTheta) * Math.cos(Math.asin(yBlock / radii.getY())); double tempZ = radii.getZ() * Math.sin(tempTheta) * Math.cos(Math.asin(yBlock / radii.getY())); - obf.addVertex(centerX + tempX, centerY + yBlock, centerZ + tempZ); + tess.addVertex(centerX + tempX, centerY + yBlock, centerZ + tempZ); } - obf.finishDrawing(); + tess.draw(); } - obf.startDrawing(GL11.GL_LINE_LOOP); + tess.startDrawing(GL11.GL_LINE_LOOP); color.prepareColor(); for (int i = 0; i <= 40; i++) { @@ -65,15 +67,16 @@ protected void drawXZPlane(LineInfo color) { double tempX = radii.getX() * Math.cos(tempTheta); double tempZ = radii.getZ() * Math.sin(tempTheta); - obf.addVertex(centerX + tempX, centerY, centerZ + tempZ); + tess.addVertex(centerX + tempX, centerY, centerZ + tempZ); } - obf.finishDrawing(); + tess.draw(); } protected void drawYZPlane(LineInfo color) { + Tessellator tess = Tessellator.instance; int xRad = (int) Math.floor(radii.getX()); for (int xBlock = -xRad; xBlock < xRad; xBlock++) { - obf.startDrawing(GL11.GL_LINE_LOOP); + tess.startDrawing(GL11.GL_LINE_LOOP); color.prepareColor(); for (int i = 0; i <= 40; i++) { @@ -81,12 +84,12 @@ protected void drawYZPlane(LineInfo color) { double tempY = radii.getY() * Math.cos(tempTheta) * Math.sin(Math.acos(xBlock / radii.getX())); double tempZ = radii.getZ() * Math.sin(tempTheta) * Math.sin(Math.acos(xBlock / radii.getX())); - obf.addVertex(centerX + xBlock, centerY + tempY, centerZ + tempZ); + tess.addVertex(centerX + xBlock, centerY + tempY, centerZ + tempZ); } - obf.finishDrawing(); + tess.draw(); } - obf.startDrawing(GL11.GL_LINE_LOOP); + tess.startDrawing(GL11.GL_LINE_LOOP); color.prepareColor(); for (int i = 0; i <= 40; i++) { @@ -94,15 +97,16 @@ protected void drawYZPlane(LineInfo color) { double tempY = radii.getY() * Math.cos(tempTheta); double tempZ = radii.getZ() * Math.sin(tempTheta); - obf.addVertex(centerX, centerY + tempY, centerZ + tempZ); + tess.addVertex(centerX, centerY + tempY, centerZ + tempZ); } - obf.finishDrawing(); + tess.draw(); } protected void drawXYPlane(LineInfo color) { + Tessellator tess = Tessellator.instance; int zRad = (int) Math.floor(radii.getZ()); for (int zBlock = -zRad; zBlock < zRad; zBlock++) { - obf.startDrawing(GL11.GL_LINE_LOOP); + tess.startDrawing(GL11.GL_LINE_LOOP); color.prepareColor(); for (int i = 0; i <= 40; i++) { @@ -110,12 +114,12 @@ protected void drawXYPlane(LineInfo color) { double tempX = radii.getX() * Math.sin(tempTheta) * Math.sin(Math.acos(zBlock / radii.getZ())); double tempY = radii.getY() * Math.cos(tempTheta) * Math.sin(Math.acos(zBlock / radii.getZ())); - obf.addVertex(centerX + tempX, centerY + tempY, centerZ + zBlock); + tess.addVertex(centerX + tempX, centerY + tempY, centerZ + zBlock); } - obf.finishDrawing(); + tess.draw(); } - obf.startDrawing(GL11.GL_LINE_LOOP); + tess.startDrawing(GL11.GL_LINE_LOOP); color.prepareColor(); for (int i = 0; i <= 40; i++) { @@ -123,8 +127,8 @@ protected void drawXYPlane(LineInfo color) { double tempX = radii.getX() * Math.cos(tempTheta); double tempY = radii.getY() * Math.sin(tempTheta); - obf.addVertex(centerX + tempX, centerY + tempY, centerZ); + tess.addVertex(centerX + tempX, centerY + tempY, centerZ); } - obf.finishDrawing(); + tess.draw(); } } diff --git a/src/main/java/wecui/util/ConsoleLogFormatter.java b/src/main/java/wecui/util/ConsoleLogFormatter.java index e334c2ac..792fa8af 100644 --- a/src/main/java/wecui/util/ConsoleLogFormatter.java +++ b/src/main/java/wecui/util/ConsoleLogFormatter.java @@ -18,7 +18,8 @@ public class ConsoleLogFormatter extends Formatter { private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - public String format(LogRecord logrecord) { + @Override + public String format(LogRecord logrecord) { StringBuilder stringbuilder = new StringBuilder(); stringbuilder.append(this.format.format(Long.valueOf(logrecord.getMillis()))); diff --git a/src/main/java/wecui/util/Vector2.java b/src/main/java/wecui/util/Vector2.java index 033f30aa..d53888c7 100644 --- a/src/main/java/wecui/util/Vector2.java +++ b/src/main/java/wecui/util/Vector2.java @@ -1,553 +1,560 @@ -package wecui.util; - -/** - * A 2-dimensional vector represented by float-precision x,y coordinates - * - * Note, this is the Immutable form of Vector2. All operations will construct a - * new Vector2. - */ -public class Vector2 implements Comparable { - - /** - * Represents the Zero vector (0,0) - */ - public final static Vector2 ZERO = new Vector2(0, 0); - /** - * Represents a unit vector in the X direction (1,0) - */ - public final static Vector2 UNIT_X = new Vector2(1, 0); - /** - * Represents a unit vector in the Y direction (0,1) - */ - public final static Vector2 UNIT_Y = new Vector2(0, 1); - /** - * Represents a unit vector (1,1) - */ - public static Vector2 ONE = new Vector2(1, 1); - protected float x, z; - - /** - * Construct and Initialized a Vector2 from the given x, y - * - * @param x the x coordinate - * @param y the y coordinate - */ - public Vector2(float x, float y) { - this.x = x; - this.z = y; - } - - /** - * Construct and Initialized a Vector2 from the given x, y - * - * @param x the x coordinate - * @param y the y coordinate - */ - public Vector2(Double x, Double y) { - this(x.floatValue(), y.floatValue()); - } - - /** - * Construct and Initialized a Vector2 to (0,0) - */ - public Vector2() { - this(0, 0); - } - - /** - * Construct and Initialized a Vector2 from an old Vector2 - * - * @param original - */ - public Vector2(Vector2 original) { - this(original.x, original.z); - } - - /** - * Gets the X coordiante - * - * @return The X coordinate - */ - public float getX() { - return x; - } - - /** - * Gets the Y coordiante - * - * @return The Y coordinate - */ - public float getY() { - return z; - } - - /** - * Adds this Vector2 to the value of the Vector2 argument - * - * @param that The Vector2 to add - * @return the new Vector2 - */ - public Vector2 add(Vector2 that) { - return Vector2.add(this, that); - } - - /** - * Subtracts this Vector2 to the value of the Vector2 argument - * - * @param that The Vector2 to subtract - * @return the new Vector2 - */ - public Vector2 subtract(Vector2 that) { - return Vector2.subtract(this, that); - } - - /** - * Scales this Vector2 by the value of the argument - * - * @param scale The amount to scale by - * @return A new Vector2 scaled by the amount. - */ - public Vector2 scale(float scale) { - return Vector2.scale(this, scale); - } - - /** - * Returns this Vector2 dot the Vector2 argument. Dot Product is defined as - * a.x*b.x + a.y*b.y - * - * @param that The Vector2 to dot with this. - * @return The dot product - */ - public float dot(Vector2 that) { - return Vector2.dot(this, that); - } - - /** - * Returns a Vector3 object with a y-value of 0. - * The x of this Vector2 becomes the x of the Vector3, - * the y of this Vector2 becomes the z of the Vector3. - * - * @return - */ - public Vector3 toVector3() { - return Vector2.toVector3(this); - } - - /** - * Returns a Vector3m object with a y-value of 0. - * The x of this Vector2 becomes the x of the Vector3m, - * the y of this Vector2 becomes the z of the Vector3m. - * - * @return - */ - public Vector3m toVector3m() { - return Vector2.toVector3m(this); - } - - /** - * Returns a Vector3 object with the given y value. - * The x of this Vector2 becomes the x of the Vector3, - * the y of this Vector2 becomes the z of the Vector3. - * - * @param y Y value to use in the new Vector3. - * @return - */ - public Vector3 toVector3(float y) { - return Vector2.toVector3(this, y); - } - - /** - * Returns a Vector3m object with the given y value. - * The x of this Vector2 becomes the x of the Vector3m, - * the y of this Vector2 becomes the z of the Vector3m. - * - * @param y Y value to use in the new Vector3m. - * @return - */ - public Vector3m toVector3m(float y) { - return Vector2.toVector3m(this, y); - } - - /** - * Returns the Cross Product of this Vector2 Note: Cross Product is - * undefined in 2d space. This returns the orthogonal vector to this vector - * - * @return The orthogonal vector to this vector. - */ - public Vector2 cross() { - return new Vector2(z, -x); - } - - /** - * Rounds the X and Y values of this Vector2 up to - * the nearest integer value. - * - * @return - */ - public Vector2 ceil() { - return new Vector2(Math.ceil(x), Math.ceil(z)); - } - - /** - * Rounds the X and Y values of this Vector2 down to - * the nearest integer value. - * - * @return - */ - public Vector2 floor() { - return new Vector2(Math.floor(x), Math.floor(z)); - } - - /** - * Rounds the X and Y values of this Vector2 to - * the nearest integer value. - * - * @return - */ - public Vector2 round() { - return new Vector2(Math.round(x), Math.round(z)); - } - - /** - * Sets the X and Y values of this Vector2 to their - * absolute value. - * - * @return - */ - public Vector2 abs() { - return new Vector2(Math.abs(x), Math.abs(z)); - } - - /** - * Gets the distance between this Vector2 and a given Vector2. - * - * @param a - * @return - */ - public double distance(Vector2 a) { - return Vector2.distance(a, this); - } - - /** - * Raises the X and Y values of this Vector2 to the given power. - * - * @param power - * @return - */ - public Vector2 pow(double power) { - return Vector2.pow(this, power); - } - - /** - * Calculates the length of this Vector2 squared. - * - * @return the squared length - */ - public float lengthSquared() { - return Vector2.lengthSquared(this); - } - - /** - * Calculates the length of this Vector2 Note: This makes use of the sqrt - * function, and is not cached. That could affect performance - * - * @return the length of this vector2 - */ - public float length() { - return Vector2.length(this); - } - - /** - * Returns this Vector2 where the length is equal to 1 - * - * @return This Vector2 with length 1 - */ - public Vector2 normalize() { - return Vector2.normalize(this); - } - - /** - * Returns this Vector2 in an array. Element 0 contains x Element 1 contains - * y - * - * @return The array containing this Vector2 - */ - public float[] toArray() { - return Vector2.toArray(this); - } - - /** - * Compares two Vector3s - */ - public int compareTo(Vector2 o) { - return Vector2.compareTo(this, o); - } - - /** - * Checks if two Vector2s are equal - */ - @Override - public boolean equals(Object o) { - return Vector2.equals(this, o); - } - - /** - * Returns the length of the provided Vector2 Note: This makes use of the - * sqrt function, and is not cached. This could affect performance. - * - * @param a The Vector2 to calculate the length of - * @return The length of the Vector2 - */ - public static float length(Vector2 a) { - return (float) Math.sqrt(lengthSquared(a)); - } - - /** - * Returns the length squared of the provided Vector2 - * - * @param a the Vector2 to calculate the length squared - * @return the length squared of the Vector2 - */ - public static float lengthSquared(Vector2 a) { - return Vector2.dot(a, a); - } - - /** - * Returns a Vector2 that is the unit form of the provided Vector2 - * - * @param a - * @return - */ - public static Vector2 normalize(Vector2 a) { - return Vector2.scale(a, (1.f / a.length())); - } - - /** - * Subtracts one Vector2 from the other Vector2 - * - * @param a - * @param b - * @return - */ - public static Vector2 subtract(Vector2 a, Vector2 b) { - return new Vector2(a.getX() - b.getX(), a.getY() - b.getY()); - } - - /** - * Adds one Vector2 to the other Vector2 - * - * @param a - * @param b - * @return - */ - public static Vector2 add(Vector2 a, Vector2 b) { - return new Vector2(a.getX() + b.getX(), a.getY() + b.getY()); - } - - /** - * Scales the Vector2 by the ammount - * - * @param a - * @param b - * @return - */ - public static Vector2 scale(Vector2 a, float b) { - return new Vector2(a.getX() * b, a.getY() * b); - } - - /** - * Calculates the Dot Product of two Vector2s Dot Product is defined as - * a.x*b.x + a.y*b.y - * - * @param a - * @param b - * @return - */ - public static float dot(Vector2 a, Vector2 b) { - return a.getX() * b.getX() + a.getY() * b.getY(); - } - - /** - * Returns a Vector3 object with a y-value of 0. - * The x of the Vector2 becomes the x of the Vector3, - * the y of the Vector2 becomes the z of the Vector3. - * - * @param o Vector2 to use as the x/z values - * @return - */ - public static Vector3 toVector3(Vector2 o) { - return new Vector3(o.x, 0, o.z); - } - - /** - * Returns a Vector3m object with a y-value of 0. - * The x of the Vector2 becomes the x of the Vector3m, - * the y of the Vector2 becomes the z of the Vector3m. - * - * @param o Vector2 to use as the x/z values - * @return - */ - public static Vector3m toVector3m(Vector2 o) { - return new Vector3m(o.x, 0, o.z); - } - - /** - * Returns a Vector3 object with the given y-value. - * The x of the Vector2 becomes the x of the Vector3, - * the y of the Vector2 becomes the z of the Vector3. - * - * @param o Vector2 to use as the x/z values - * @param y Y value of the new Vector3 - * @return - */ - public static Vector3 toVector3(Vector2 o, float y) { - return new Vector3(o.x, y, o.z); - } - - /** - * Returns a Vector3m object with the given y-value. - * The x of the Vector2 becomes the x of the Vector3m, - * the y of the Vector2 becomes the z of the Vector3m. - * - * @param o Vector2 to use as the x/z values - * @param y Y value of the new Vector3 - * @return - */ - public static Vector3m toVector3m(Vector2 o, float y) { - return new Vector3m(o.x, y, o.z); - } - - /** - * Rounds the X and Y values of the given Vector2 up to - * the nearest integer value. - * - * @param o Vector2 to use - * @return - */ - public static Vector2 ceil(Vector2 o) { - return new Vector2(Math.ceil(o.x), Math.ceil(o.z)); - } - - /** - * Rounds the X and Y values of the given Vector2 down to - * the nearest integer value. - * - * @param o Vector2 to use - * @return - */ - public static Vector2 floor(Vector2 o) { - return new Vector2(Math.floor(o.x), Math.floor(o.z)); - } - - /** - * Rounds the X and Y values of the given Vector2 to - * the nearest integer value. - * - * @param o Vector2 to use - * @return - */ - public static Vector2 round(Vector2 o) { - return new Vector2(Math.round(o.x), Math.round(o.z)); - } - - /** - * Sets the X and Y values of the given Vector2 to their - * absolute value. - * - * @param o Vector2 to use - * @return - */ - public static Vector2 abs(Vector2 o) { - return new Vector2(Math.abs(o.x), Math.abs(o.z)); - } - - /** - * Returns a Vector2 containing the smallest X and Y values. - * - * @param o1 - * @param o2 - * @return - */ - public static Vector2 min(Vector2 o1, Vector2 o2) { - return new Vector2(Math.min(o1.x, o2.x), Math.min(o1.z, o2.z)); - } - - /** - * Returns a Vector2 containing the largest X and Y values. - * - * @param o1 - * @param o2 - * @return - */ - public static Vector2 max(Vector2 o1, Vector2 o2) { - return new Vector2(Math.max(o1.x, o2.x), Math.max(o1.z, o2.z)); - } - - /** - * Returns a Vector2 with random X and Y values (between 0 and 1) - * - * @param o - * @return - */ - public static Vector2 rand() { - return new Vector2(Math.random(), Math.random()); - } - - /** - * Returns the provided Vector2 in an array. Element 0 contains x Element 1 - * contains y - * - * @return The array containing the Vector2 - */ - public static float[] toArray(Vector2 a) { - return new float[]{a.getX(), a.getY()}; - } - - /** - * Compares two Vector3s - */ - public static int compareTo(Vector2 a, Vector2 b) { - return (int) a.lengthSquared() - (int) b.lengthSquared(); - } - - /** - * Gets the distance between two Vector2. - * - * @param a - * @param b - * @return - */ - public static double distance(Vector2 a, Vector2 b) { - Vector2 tempVector = Vector2.pow(Vector2.subtract(a, b), 2); - return Math.sqrt(tempVector.x + tempVector.z); - } - - /** - * Raises the X and Y values of a Vector2 to the given power. - * - * @param o - * @param power - * @return - */ - public static Vector2 pow(Vector2 o, double power) { - return new Vector2(Math.pow(o.x, power), Math.pow(o.z, power)); - } - - /** - * Checks if two Vector2s are equal - */ - public static boolean equals(Object a, Object b) { - if (!(a instanceof Vector2) || !(b instanceof Vector2)) { - return false; - } - if (a == b) { - return true; - } - return compareTo((Vector2) a, (Vector2) b) == 0; - } - - @Override - public String toString() { - return "(" + x + ", " + z + ")"; - } -} +package wecui.util; + +/** + * A 2-dimensional vector represented by float-precision x,y coordinates + * + * Note, this is the Immutable form of Vector2. All operations will construct a + * new Vector2. + */ +public class Vector2 implements Comparable { + + /** + * Represents the Zero vector (0,0) + */ + public final static Vector2 ZERO = new Vector2(0, 0); + /** + * Represents a unit vector in the X direction (1,0) + */ + public final static Vector2 UNIT_X = new Vector2(1, 0); + /** + * Represents a unit vector in the Y direction (0,1) + */ + public final static Vector2 UNIT_Y = new Vector2(0, 1); + /** + * Represents a unit vector (1,1) + */ + public static Vector2 ONE = new Vector2(1, 1); + protected float x, z; + + /** + * Construct and Initialized a Vector2 from the given x, y + * + * @param x the x coordinate + * @param y the y coordinate + */ + public Vector2(float x, float y) { + this.x = x; + this.z = y; + } + + /** + * Construct and Initialized a Vector2 from the given x, y + * + * @param x the x coordinate + * @param y the y coordinate + */ + public Vector2(Double x, Double y) { + this(x.floatValue(), y.floatValue()); + } + + /** + * Construct and Initialized a Vector2 to (0,0) + */ + public Vector2() { + this(0, 0); + } + + /** + * Construct and Initialized a Vector2 from an old Vector2 + * + * @param original + */ + public Vector2(Vector2 original) { + this(original.x, original.z); + } + + /** + * Gets the X coordiante + * + * @return The X coordinate + */ + public float getX() { + return x; + } + + /** + * Gets the Y coordiante + * + * @return The Y coordinate + */ + public float getY() { + return z; + } + + /** + * Adds this Vector2 to the value of the Vector2 argument + * + * @param that The Vector2 to add + * @return the new Vector2 + */ + public Vector2 add(Vector2 that) { + return Vector2.add(this, that); + } + + /** + * Subtracts this Vector2 to the value of the Vector2 argument + * + * @param that The Vector2 to subtract + * @return the new Vector2 + */ + public Vector2 subtract(Vector2 that) { + return Vector2.subtract(this, that); + } + + /** + * Scales this Vector2 by the value of the argument + * + * @param scale The amount to scale by + * @return A new Vector2 scaled by the amount. + */ + public Vector2 scale(float scale) { + return Vector2.scale(this, scale); + } + + /** + * Returns this Vector2 dot the Vector2 argument. Dot Product is defined as + * a.x*b.x + a.y*b.y + * + * @param that The Vector2 to dot with this. + * @return The dot product + */ + public float dot(Vector2 that) { + return Vector2.dot(this, that); + } + + /** + * Returns a Vector3 object with a y-value of 0. + * The x of this Vector2 becomes the x of the Vector3, + * the y of this Vector2 becomes the z of the Vector3. + * + * @return + */ + public Vector3 toVector3() { + return Vector2.toVector3(this); + } + + /** + * Returns a Vector3m object with a y-value of 0. + * The x of this Vector2 becomes the x of the Vector3m, + * the y of this Vector2 becomes the z of the Vector3m. + * + * @return + */ + public Vector3m toVector3m() { + return Vector2.toVector3m(this); + } + + /** + * Returns a Vector3 object with the given y value. + * The x of this Vector2 becomes the x of the Vector3, + * the y of this Vector2 becomes the z of the Vector3. + * + * @param y Y value to use in the new Vector3. + * @return + */ + public Vector3 toVector3(float y) { + return Vector2.toVector3(this, y); + } + + /** + * Returns a Vector3m object with the given y value. + * The x of this Vector2 becomes the x of the Vector3m, + * the y of this Vector2 becomes the z of the Vector3m. + * + * @param y Y value to use in the new Vector3m. + * @return + */ + public Vector3m toVector3m(float y) { + return Vector2.toVector3m(this, y); + } + + /** + * Returns the Cross Product of this Vector2 Note: Cross Product is + * undefined in 2d space. This returns the orthogonal vector to this vector + * + * @return The orthogonal vector to this vector. + */ + public Vector2 cross() { + return new Vector2(z, -x); + } + + /** + * Rounds the X and Y values of this Vector2 up to + * the nearest integer value. + * + * @return + */ + public Vector2 ceil() { + return new Vector2(Math.ceil(x), Math.ceil(z)); + } + + /** + * Rounds the X and Y values of this Vector2 down to + * the nearest integer value. + * + * @return + */ + public Vector2 floor() { + return new Vector2(Math.floor(x), Math.floor(z)); + } + + /** + * Rounds the X and Y values of this Vector2 to + * the nearest integer value. + * + * @return + */ + public Vector2 round() { + return new Vector2(Math.round(x), Math.round(z)); + } + + /** + * Sets the X and Y values of this Vector2 to their + * absolute value. + * + * @return + */ + public Vector2 abs() { + return new Vector2(Math.abs(x), Math.abs(z)); + } + + /** + * Gets the distance between this Vector2 and a given Vector2. + * + * @param a + * @return + */ + public double distance(Vector2 a) { + return Vector2.distance(a, this); + } + + /** + * Raises the X and Y values of this Vector2 to the given power. + * + * @param power + * @return + */ + public Vector2 pow(double power) { + return Vector2.pow(this, power); + } + + /** + * Calculates the length of this Vector2 squared. + * + * @return the squared length + */ + public float lengthSquared() { + return Vector2.lengthSquared(this); + } + + /** + * Calculates the length of this Vector2 Note: This makes use of the sqrt + * function, and is not cached. That could affect performance + * + * @return the length of this vector2 + */ + public float length() { + return Vector2.length(this); + } + + /** + * Returns this Vector2 where the length is equal to 1 + * + * @return This Vector2 with length 1 + */ + public Vector2 normalize() { + return Vector2.normalize(this); + } + + /** + * Returns this Vector2 in an array. Element 0 contains x Element 1 contains + * y + * + * @return The array containing this Vector2 + */ + public float[] toArray() { + return Vector2.toArray(this); + } + + /** + * Compares two Vector3s + */ + @Override + public int compareTo(Vector2 o) { + return Vector2.compareTo(this, o); + } + + /** + * Checks if two Vector2s are equal + */ + @Override + public boolean equals(Object o) { + return Vector2.equals(this, o); + } + + /** + * Returns the length of the provided Vector2 Note: This makes use of the + * sqrt function, and is not cached. This could affect performance. + * + * @param a The Vector2 to calculate the length of + * @return The length of the Vector2 + */ + public static float length(Vector2 a) { + return (float) Math.sqrt(lengthSquared(a)); + } + + /** + * Returns the length squared of the provided Vector2 + * + * @param a the Vector2 to calculate the length squared + * @return the length squared of the Vector2 + */ + public static float lengthSquared(Vector2 a) { + return Vector2.dot(a, a); + } + + /** + * Returns a Vector2 that is the unit form of the provided Vector2 + * + * @param a + * @return + */ + public static Vector2 normalize(Vector2 a) { + return Vector2.scale(a, (1.f / a.length())); + } + + /** + * Subtracts one Vector2 from the other Vector2 + * + * @param a + * @param b + * @return + */ + public static Vector2 subtract(Vector2 a, Vector2 b) { + return new Vector2(a.getX() - b.getX(), a.getY() - b.getY()); + } + + /** + * Adds one Vector2 to the other Vector2 + * + * @param a + * @param b + * @return + */ + public static Vector2 add(Vector2 a, Vector2 b) { + return new Vector2(a.getX() + b.getX(), a.getY() + b.getY()); + } + + /** + * Scales the Vector2 by the ammount + * + * @param a + * @param b + * @return + */ + public static Vector2 scale(Vector2 a, float b) { + return new Vector2(a.getX() * b, a.getY() * b); + } + + /** + * Calculates the Dot Product of two Vector2s Dot Product is defined as + * a.x*b.x + a.y*b.y + * + * @param a + * @param b + * @return + */ + public static float dot(Vector2 a, Vector2 b) { + return a.getX() * b.getX() + a.getY() * b.getY(); + } + + /** + * Returns a Vector3 object with a y-value of 0. + * The x of the Vector2 becomes the x of the Vector3, + * the y of the Vector2 becomes the z of the Vector3. + * + * @param o Vector2 to use as the x/z values + * @return + */ + public static Vector3 toVector3(Vector2 o) { + return new Vector3(o.x, 0, o.z); + } + + /** + * Returns a Vector3m object with a y-value of 0. + * The x of the Vector2 becomes the x of the Vector3m, + * the y of the Vector2 becomes the z of the Vector3m. + * + * @param o Vector2 to use as the x/z values + * @return + */ + public static Vector3m toVector3m(Vector2 o) { + return new Vector3m(o.x, 0, o.z); + } + + /** + * Returns a Vector3 object with the given y-value. + * The x of the Vector2 becomes the x of the Vector3, + * the y of the Vector2 becomes the z of the Vector3. + * + * @param o Vector2 to use as the x/z values + * @param y Y value of the new Vector3 + * @return + */ + public static Vector3 toVector3(Vector2 o, float y) { + return new Vector3(o.x, y, o.z); + } + + /** + * Returns a Vector3m object with the given y-value. + * The x of the Vector2 becomes the x of the Vector3m, + * the y of the Vector2 becomes the z of the Vector3m. + * + * @param o Vector2 to use as the x/z values + * @param y Y value of the new Vector3 + * @return + */ + public static Vector3m toVector3m(Vector2 o, float y) { + return new Vector3m(o.x, y, o.z); + } + + /** + * Rounds the X and Y values of the given Vector2 up to + * the nearest integer value. + * + * @param o Vector2 to use + * @return + */ + public static Vector2 ceil(Vector2 o) { + return new Vector2(Math.ceil(o.x), Math.ceil(o.z)); + } + + /** + * Rounds the X and Y values of the given Vector2 down to + * the nearest integer value. + * + * @param o Vector2 to use + * @return + */ + public static Vector2 floor(Vector2 o) { + return new Vector2(Math.floor(o.x), Math.floor(o.z)); + } + + /** + * Rounds the X and Y values of the given Vector2 to + * the nearest integer value. + * + * @param o Vector2 to use + * @return + */ + public static Vector2 round(Vector2 o) { + return new Vector2(Math.round(o.x), Math.round(o.z)); + } + + /** + * Sets the X and Y values of the given Vector2 to their + * absolute value. + * + * @param o Vector2 to use + * @return + */ + public static Vector2 abs(Vector2 o) { + return new Vector2(Math.abs(o.x), Math.abs(o.z)); + } + + /** + * Returns a Vector2 containing the smallest X and Y values. + * + * @param o1 + * @param o2 + * @return + */ + public static Vector2 min(Vector2 o1, Vector2 o2) { + return new Vector2(Math.min(o1.x, o2.x), Math.min(o1.z, o2.z)); + } + + /** + * Returns a Vector2 containing the largest X and Y values. + * + * @param o1 + * @param o2 + * @return + */ + public static Vector2 max(Vector2 o1, Vector2 o2) { + return new Vector2(Math.max(o1.x, o2.x), Math.max(o1.z, o2.z)); + } + + /** + * Returns a Vector2 with random X and Y values (between 0 and 1) + * + * @param o + * @return + */ + public static Vector2 rand() { + return new Vector2(Math.random(), Math.random()); + } + + /** + * Returns the provided Vector2 in an array. Element 0 contains x Element 1 + * contains y + * + * @return The array containing the Vector2 + */ + public static float[] toArray(Vector2 a) { + return new float[]{a.getX(), a.getY()}; + } + + /** + * Compares two Vector3s + */ + public static int compareTo(Vector2 a, Vector2 b) { + return (int) a.lengthSquared() - (int) b.lengthSquared(); + } + + /** + * Gets the distance between two Vector2. + * + * @param a + * @param b + * @return + */ + public static double distance(Vector2 a, Vector2 b) { + Vector2 tempVector = Vector2.pow(Vector2.subtract(a, b), 2); + return Math.sqrt(tempVector.x + tempVector.z); + } + + /** + * Raises the X and Y values of a Vector2 to the given power. + * + * @param o + * @param power + * @return + */ + public static Vector2 pow(Vector2 o, double power) { + return new Vector2(Math.pow(o.x, power), Math.pow(o.z, power)); + } + + /** + * Checks if two Vector2s are equal + */ + public static boolean equals(Object a, Object b) { + if (!(a instanceof Vector2) || !(b instanceof Vector2)) { + return false; + } + if (a == b) { + return true; + } + return compareTo((Vector2) a, (Vector2) b) == 0; + } + + @Override + public String toString() { + return "(" + x + ", " + z + ")"; + } + + @Override + public int hashCode() + { + return (int)(this.x % this.z); + } +} diff --git a/src/main/java/wecui/util/Vector2m.java b/src/main/java/wecui/util/Vector2m.java index 503c340d..2d4c38c8 100644 --- a/src/main/java/wecui/util/Vector2m.java +++ b/src/main/java/wecui/util/Vector2m.java @@ -1,126 +1,130 @@ -package wecui.util; - -/** - * A version of Vector2 that can be modified. - * - * @author yetanotherx - */ -public class Vector2m extends Vector2 { - - public Vector2m() { - } - - public Vector2m(Double x, Double y) { - super(x, y); - } - - public Vector2m(float x, float y) { - super(x, y); - } - - public Vector2m(Vector2 original) { - super(original); - } - - /** - * Sets the X coordinate - * - * @param x The x coordinate - */ - public void setX(float x) { - this.x = x; - } - - /** - * Sets the Y coordinate - * - * @param y The Y coordinate - */ - public void setY(float y) { - this.z = y; - } - - @Override - public Vector2 add(Vector2 that) { - x += that.x; - z += that.z; - return this; - } - - @Override - public Vector2 subtract(Vector2 that) { - x -= that.x; - z -= that.z; - return this; - } - - @Override - public Vector2 scale(float scale) { - x *= scale; - z *= scale; - return this; - } - - public Vector2 cross(Vector2 that) { - float tmp = z; - z = -x; - x = tmp; - return this; - } - - /** - * Rounds the X and Y values of this Vector2 up to - * the nearest integer value. - * - * @return - */ - public Vector2 ceil() { - x = (float) Math.ceil(x); - z = (float) Math.ceil(z); - return this; - } - - /** - * Rounds the X and Y values of this Vector2 down to - * the nearest integer value. - * - * @return - */ - public Vector2 floor() { - x = (float) Math.floor(x); - z = (float) Math.floor(z); - return this; - } - - /** - * Rounds the X and Y values of this Vector2 to - * the nearest integer value. - * - * @return - */ - public Vector2 round() { - x = Math.round(x); - z = Math.round(z); - return this; - } - - /** - * Sets the X and Y values of this Vector2 to their - * absolute value. - * - * @return - */ - public Vector2 abs() { - x = Math.abs(x); - z = Math.abs(z); - return this; - } - - @Override - public Vector2 normalize() { - float length = this.length(); - x *= 1 / length; - z *= 1 / length; - return this; - } -} +package wecui.util; + +/** + * A version of Vector2 that can be modified. + * + * @author yetanotherx + */ +public class Vector2m extends Vector2 { + + public Vector2m() { + } + + public Vector2m(Double x, Double y) { + super(x, y); + } + + public Vector2m(float x, float y) { + super(x, y); + } + + public Vector2m(Vector2 original) { + super(original); + } + + /** + * Sets the X coordinate + * + * @param x The x coordinate + */ + public void setX(float x) { + this.x = x; + } + + /** + * Sets the Y coordinate + * + * @param y The Y coordinate + */ + public void setY(float y) { + this.z = y; + } + + @Override + public Vector2 add(Vector2 that) { + x += that.x; + z += that.z; + return this; + } + + @Override + public Vector2 subtract(Vector2 that) { + x -= that.x; + z -= that.z; + return this; + } + + @Override + public Vector2 scale(float scale) { + x *= scale; + z *= scale; + return this; + } + + public Vector2 cross(Vector2 that) { + float tmp = z; + z = -x; + x = tmp; + return this; + } + + /** + * Rounds the X and Y values of this Vector2 up to + * the nearest integer value. + * + * @return + */ + @Override + public Vector2 ceil() { + x = (float) Math.ceil(x); + z = (float) Math.ceil(z); + return this; + } + + /** + * Rounds the X and Y values of this Vector2 down to + * the nearest integer value. + * + * @return + */ + @Override + public Vector2 floor() { + x = (float) Math.floor(x); + z = (float) Math.floor(z); + return this; + } + + /** + * Rounds the X and Y values of this Vector2 to + * the nearest integer value. + * + * @return + */ + @Override + public Vector2 round() { + x = Math.round(x); + z = Math.round(z); + return this; + } + + /** + * Sets the X and Y values of this Vector2 to their + * absolute value. + * + * @return + */ + @Override + public Vector2 abs() { + x = Math.abs(x); + z = Math.abs(z); + return this; + } + + @Override + public Vector2 normalize() { + float length = this.length(); + x *= 1 / length; + z *= 1 / length; + return this; + } +} diff --git a/src/main/java/wecui/util/Vector3.java b/src/main/java/wecui/util/Vector3.java index 3768b5cf..b5d30ade 100644 --- a/src/main/java/wecui/util/Vector3.java +++ b/src/main/java/wecui/util/Vector3.java @@ -1,573 +1,582 @@ -package wecui.util; - -/** - * Represents a 3d vector. - */ -public class Vector3 implements Comparable { - - /** - * Vector with all elements set to 0. (0, 0, 0) - */ - public final static Vector3 ZERO = new Vector3(0, 0, 0); - /** - * Unit Vector in the X direction. (1, 0, 0) - */ - public final static Vector3 UNIT_X = new Vector3(1, 0, 0); - /** - * Unit Vector facing Forward. (1, 0, 0) - */ - public final static Vector3 Forward = UNIT_X; - /** - * Unit Vector in the Y direction. (0, 1, 0) - */ - public final static Vector3 UNIT_Y = new Vector3(0, 1, 0); - /** - * Unit Vector pointing Up. (0, 1, 0) - */ - public final static Vector3 Up = UNIT_Y; - /** - * Unit Vector in the Z direction. (0, 0, 1) - */ - public final static Vector3 UNIT_Z = new Vector3(0, 0, 1); - /** - * Unit Vector pointing Right. (0, 0, 1) - */ - public final static Vector3 Right = UNIT_Z; - /** - * Unit Vector with all elements set to 1. (1, 1, 1) - */ - public final static Vector3 ONE = new Vector3(1, 1, 1); - protected float x, y, z; - - /** - * Constructs a new Vector3 with the given x, y, z - * - * @param x - * @param y - * @param z - */ - public Vector3(float x, float y, float z) { - this.x = x; - this.y = y; - this.z = z; - } - - /** - * Constructs a new Vector3 with the given x, y, z - * - * @param x - * @param y - * @param z - */ - public Vector3(Double x, Double y, Double z) { - this(x.floatValue(), y.floatValue(), z.floatValue()); - } - - /** - * Constructs a new Vector3 with all elements set to 0 - */ - public Vector3() { - this(0, 0, 0); - } - - /** - * Constructs a new Vector3 that is a clone of the given vector3 - * - * @param clone - */ - public Vector3(Vector3 clone) { - this(clone.getX(), clone.getY(), clone.getZ()); - } - - /** - * Constructs a new Vector3 from the given Vector2 and z - * - * @param vector - * @param z - */ - public Vector3(Vector2 vector, float z) { - this(vector.getX(), vector.getY(), z); - } - - /** - * Constructs a new Vector3 from the given Vector2 and z set to 0 - * - * @param vector - */ - public Vector3(Vector2 vector) { - this(vector, 0); - } - - public float getX() { - return x; - } - - public float getY() { - return y; - } - - public float getZ() { - return z; - } - - /** - * Adds two vectors - * - * @param that - * @return - */ - public Vector3 add(Vector3 that) { - return Vector3.add(this, that); - } - - /** - * Subtracts two vectors - * - * @param that - * @return - */ - public Vector3 subtract(Vector3 that) { - return Vector3.subtract(this, that); - } - - /** - * Scales by the scalar value - * - * @param scale - * @return - */ - public Vector3 scale(float scale) { - return Vector3.scale(this, scale); - } - - /** - * Takes the dot product of two vectors - * - * @param that - * @return - */ - public float dot(Vector3 that) { - return Vector3.dot(this, that); - } - - /** - * Takes the cross product of two vectors - * - * @param that - * @return - */ - public Vector3 cross(Vector3 that) { - return Vector3.cross(this, that); - } - - /** - * Returns a Vector2 object using the X and Z values of - * this Vector3. The x of this Vector3 becomes the x - * of the Vector2, and the z of this Vector3 becomes the - * y of the Vector2. - * - * @return - */ - public Vector2 toVector2() { - return Vector3.toVector2(this); - } - - /** - * Returns a Vector2m object using the X and Z values of - * this Vector3. The x of this Vector3 becomes the x - * of the Vector2, and the z of this Vector3 becomes the - * y of the Vector2m. - * - * @return - */ - public Vector2m toVector2m() { - return Vector3.toVector2m(this); - } - - /** - * Rounds the X, Y, and Z values of this Vector3 up to - * the nearest integer value. - * - * @return - */ - public Vector3 ceil() { - return new Vector3(Math.ceil(x), Math.ceil(y), Math.ceil(z)); - } - - /** - * Rounds the X, Y, and Z values of this Vector3 down to - * the nearest integer value. - * - * @return - */ - public Vector3 floor() { - return new Vector3(Math.floor(x), Math.floor(y), Math.floor(z)); - } - - /** - * Rounds the X, Y, and Z values of this Vector3 to - * the nearest integer value. - * - * @return - */ - public Vector3 round() { - return new Vector3(Math.round(x), Math.round(y), Math.round(z)); - } - - /** - * Sets the X, Y, and Z values of this Vector3 to their - * absolute value. - * - * @return - */ - public Vector3 abs() { - return new Vector3(Math.abs(x), Math.abs(y), Math.abs(z)); - } - - /** - * Gets the distance between this Vector3 and a given Vector3. - * - * @param a - * @return - */ - public double distance(Vector3 a) { - return Vector3.distance(a, this); - } - - /** - * Raises the X, Y, and Z values of this Vector3 to the given power. - * - * @param power - * @return - */ - public Vector3 pow(double power) { - return Vector3.pow(this, power); - } - - /** - * returns the squared length of the vector - * - * @return - */ - public float lengthSquared() { - return Vector3.lengthSquared(this); - } - - /** - * returns the length of this vector. Note: makes use of Math.sqrt and is - * not cached. - * - * @return - */ - public float length() { - return Vector3.length(this); - } - - /** - * Returns a fast approximation of this vector's length. - * - * @return - */ - public float fastLength() { - return Vector3.fastLength(this); - } - - /** - * returns the vector with a length of 1 - * - * @return - */ - public Vector3 normalize() { - return Vector3.normalize(this); - } - - /** - * returns the vector as [x,y,z] - * - * @return - */ - public float[] toArray() { - return Vector3.toArray(this); - } - - /** - * Compares two Vector3s - */ - public int compareTo(Vector3 o) { - return Vector3.compareTo(this, o); - } - - /** - * Checks if two Vector3s are equal - */ - public boolean equals(Object o) { - return Vector3.equals(this, o); - } - - /** - * toString Override - */ - public String toString() { - return String.format("{ %f, %f, %f }", x, y, z); - } - - /** - * Returns the length of the given vector. - * - * Note: Makes use of Math.sqrt and - * is not cached, so can be slow - * - * Also known as norm. ||a|| - * - * @param a - * @return - */ - public static float length(Vector3 a) { - return (float) Math.sqrt(lengthSquared(a)); - } - - /** - * Returns an approximate length of the given vector. - * - * @param a - * @return - */ - public static float fastLength(Vector3 a) { - return (float) Math.sqrt(lengthSquared(a)); - } - - /** - * returns the length squared to the given vector - * - * @param a - * @return - */ - public static float lengthSquared(Vector3 a) { - return Vector3.dot(a, a); - } - - /** - * Returns a new vector that is the given vector but length 1 - * - * @param a - * @return - */ - public static Vector3 normalize(Vector3 a) { - return Vector3.scale(a, (1.f / a.length())); - } - - /** - * Creates a new vector that is A - B - * - * @param a - * @param b - * @return - */ - public static Vector3 subtract(Vector3 a, Vector3 b) { - return new Vector3(a.getX() - b.getX(), a.getY() - b.getY(), a.getZ() - b.getZ()); - } - - /** - * Creates a new Vector that is A + B - * - * @param a - * @param b - * @return - */ - public static Vector3 add(Vector3 a, Vector3 b) { - return new Vector3(a.getX() + b.getX(), a.getY() + b.getY(), a.getZ() + b.getZ()); - } - - /** - * Creates a new vector that is A multiplied by the uniform scalar B - * - * @param a - * @param b - * @return - */ - public static Vector3 scale(Vector3 a, float b) { - return new Vector3(a.getX() * b, a.getY() * b, a.getZ() * b); - } - - /** - * Returns the dot product of A and B - * - * @param a - * @param b - * @return - */ - public static float dot(Vector3 a, Vector3 b) { - return a.getX() * b.getX() + a.getY() * b.getY() + a.getZ() * b.getZ(); - } - - /** - * Creates a new Vector that is the A x B The Cross Product is the vector - * orthogonal to both A and B - * - * @param a - * @param b - * @return - */ - public static Vector3 cross(Vector3 a, Vector3 b) { - return new Vector3(a.getY() * b.getZ() - a.getZ() * b.getY(), a.getZ() * b.getX() - a.getX() * b.getZ(), a.getX() * b.getY() - a.getY() * b.getX()); - } - - /** - * Rounds the X, Y, and Z values of the given Vector3 up to - * the nearest integer value. - * - * @param o Vector3 to use - * @return - */ - public static Vector3 ceil(Vector3 o) { - return new Vector3(Math.ceil(o.x), Math.ceil(o.y), Math.ceil(o.z)); - } - - /** - * Rounds the X, Y, and Z values of the given Vector3 down to - * the nearest integer value. - * - * @param o Vector3 to use - * @return - */ - public static Vector3 floor(Vector3 o) { - return new Vector3(Math.floor(o.x), Math.floor(o.y), Math.floor(o.z)); - } - - /** - * Rounds the X, Y, and Z values of the given Vector3 to - * the nearest integer value. - * - * @param o Vector3 to use - * @return - */ - public static Vector3 round(Vector3 o) { - return new Vector3(Math.round(o.x), Math.round(o.y), Math.round(o.z)); - } - - /** - * Sets the X, Y, and Z values of the given Vector3 to their - * absolute value. - * - * @param o Vector3 to use - * @return - */ - public static Vector3 abs(Vector3 o) { - return new Vector3(Math.abs(o.x), Math.abs(o.y), Math.abs(o.z)); - } - - /** - * Returns a Vector3 containing the smallest X, Y, and Z values. - * - * @param o1 - * @param o2 - * @return - */ - public static Vector3 min(Vector3 o1, Vector3 o2) { - return new Vector3(Math.min(o1.x, o2.x), Math.min(o1.y, o2.y), Math.min(o1.z, o2.z)); - } - - /** - * Returns a Vector3 containing the largest X, Y, and Z values. - * - * @param o1 - * @param o2 - * @return - */ - public static Vector3 max(Vector3 o1, Vector3 o2) { - return new Vector3(Math.max(o1.x, o2.x), Math.max(o1.y, o2.y), Math.max(o1.z, o2.z)); - } - - /** - * Returns a Vector3 with random X, Y, and Z values (between 0 and 1) - * - * @return - */ - public static Vector3 rand() { - return new Vector3(Math.random(), Math.random(), Math.random()); - } - - /** - * Gets the distance between two Vector3. - * - * @param a - * @param b - * @return - */ - public static double distance(Vector3 a, Vector3 b) { - double xzDist = Vector2.distance(a.toVector2(), b.toVector2()); - return Math.sqrt(Math.pow(xzDist, 2) + Math.pow(Math.abs(Vector3.subtract(a, b).getY()), 2)); - } - - /** - * Raises the X, Y, and Z values of a Vector3 to the given power. - * - * @param o - * @param power - * @return - */ - public static Vector3 pow(Vector3 o, double power) { - return new Vector3(Math.pow(o.x, power), Math.pow(o.y, power), Math.pow(o.z, power)); - } - - /** - * Returns a Vector2 object using the X and Z values of - * the given Vector3. The x of the Vector3 becomes the x - * of the Vector2, and the z of this Vector3 becomes the - * y of the Vector2m. - * - * @param o Vector3 object to use - * @return - */ - public static Vector2 toVector2(Vector3 o) { - return new Vector2(o.x, o.z); - } - - /** - * Returns a Vector2m object using the X and Z values of - * the given Vector3. The x of the Vector3 becomes the x - * of the Vector2m, and the z of this Vector3 becomes the - * y of the Vector2m. - * - * @param o Vector3 object to use - * @return - */ - public static Vector2m toVector2m(Vector3 o) { - return new Vector2m(o.x, o.z); - } - - /** - * Returns a new float array that is {x, y, z} - * - * @param a - * @return - */ - public static float[] toArray(Vector3 a) { - return new float[]{a.getX(), a.getY(), a.getZ()}; - } - - /** - * Compares two Vector3s - */ - public static int compareTo(Vector3 a, Vector3 b) { - return (int) a.lengthSquared() - (int) b.lengthSquared(); - } - - /** - * Checks if two Vector3s are equal - */ - public static boolean equals(Object a, Object b) { - if (!(a instanceof Vector3) || !(b instanceof Vector3)) { - return false; - } - if (a == b) { - return true; - } - Vector3 x = (Vector3) a; - Vector3 y = (Vector3) b; - if (x.getX() == y.getX() && x.getY() == y.getY() && x.getZ() == y.getZ()) { - return true; - } - return false; - } -} +package wecui.util; + +/** + * Represents a 3d vector. + */ +public class Vector3 implements Comparable { + + /** + * Vector with all elements set to 0. (0, 0, 0) + */ + public final static Vector3 ZERO = new Vector3(0, 0, 0); + /** + * Unit Vector in the X direction. (1, 0, 0) + */ + public final static Vector3 UNIT_X = new Vector3(1, 0, 0); + /** + * Unit Vector facing Forward. (1, 0, 0) + */ + public final static Vector3 Forward = UNIT_X; + /** + * Unit Vector in the Y direction. (0, 1, 0) + */ + public final static Vector3 UNIT_Y = new Vector3(0, 1, 0); + /** + * Unit Vector pointing Up. (0, 1, 0) + */ + public final static Vector3 Up = UNIT_Y; + /** + * Unit Vector in the Z direction. (0, 0, 1) + */ + public final static Vector3 UNIT_Z = new Vector3(0, 0, 1); + /** + * Unit Vector pointing Right. (0, 0, 1) + */ + public final static Vector3 Right = UNIT_Z; + /** + * Unit Vector with all elements set to 1. (1, 1, 1) + */ + public final static Vector3 ONE = new Vector3(1, 1, 1); + protected float x, y, z; + + /** + * Constructs a new Vector3 with the given x, y, z + * + * @param x + * @param y + * @param z + */ + public Vector3(float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + } + + /** + * Constructs a new Vector3 with the given x, y, z + * + * @param x + * @param y + * @param z + */ + public Vector3(Double x, Double y, Double z) { + this(x.floatValue(), y.floatValue(), z.floatValue()); + } + + /** + * Constructs a new Vector3 with all elements set to 0 + */ + public Vector3() { + this(0, 0, 0); + } + + /** + * Constructs a new Vector3 that is a clone of the given vector3 + * + * @param clone + */ + public Vector3(Vector3 clone) { + this(clone.getX(), clone.getY(), clone.getZ()); + } + + /** + * Constructs a new Vector3 from the given Vector2 and z + * + * @param vector + * @param z + */ + public Vector3(Vector2 vector, float z) { + this(vector.getX(), vector.getY(), z); + } + + /** + * Constructs a new Vector3 from the given Vector2 and z set to 0 + * + * @param vector + */ + public Vector3(Vector2 vector) { + this(vector, 0); + } + + public float getX() { + return x; + } + + public float getY() { + return y; + } + + public float getZ() { + return z; + } + + /** + * Adds two vectors + * + * @param that + * @return + */ + public Vector3 add(Vector3 that) { + return Vector3.add(this, that); + } + + /** + * Subtracts two vectors + * + * @param that + * @return + */ + public Vector3 subtract(Vector3 that) { + return Vector3.subtract(this, that); + } + + /** + * Scales by the scalar value + * + * @param scale + * @return + */ + public Vector3 scale(float scale) { + return Vector3.scale(this, scale); + } + + /** + * Takes the dot product of two vectors + * + * @param that + * @return + */ + public float dot(Vector3 that) { + return Vector3.dot(this, that); + } + + /** + * Takes the cross product of two vectors + * + * @param that + * @return + */ + public Vector3 cross(Vector3 that) { + return Vector3.cross(this, that); + } + + /** + * Returns a Vector2 object using the X and Z values of + * this Vector3. The x of this Vector3 becomes the x + * of the Vector2, and the z of this Vector3 becomes the + * y of the Vector2. + * + * @return + */ + public Vector2 toVector2() { + return Vector3.toVector2(this); + } + + /** + * Returns a Vector2m object using the X and Z values of + * this Vector3. The x of this Vector3 becomes the x + * of the Vector2, and the z of this Vector3 becomes the + * y of the Vector2m. + * + * @return + */ + public Vector2m toVector2m() { + return Vector3.toVector2m(this); + } + + /** + * Rounds the X, Y, and Z values of this Vector3 up to + * the nearest integer value. + * + * @return + */ + public Vector3 ceil() { + return new Vector3(Math.ceil(x), Math.ceil(y), Math.ceil(z)); + } + + /** + * Rounds the X, Y, and Z values of this Vector3 down to + * the nearest integer value. + * + * @return + */ + public Vector3 floor() { + return new Vector3(Math.floor(x), Math.floor(y), Math.floor(z)); + } + + /** + * Rounds the X, Y, and Z values of this Vector3 to + * the nearest integer value. + * + * @return + */ + public Vector3 round() { + return new Vector3(Math.round(x), Math.round(y), Math.round(z)); + } + + /** + * Sets the X, Y, and Z values of this Vector3 to their + * absolute value. + * + * @return + */ + public Vector3 abs() { + return new Vector3(Math.abs(x), Math.abs(y), Math.abs(z)); + } + + /** + * Gets the distance between this Vector3 and a given Vector3. + * + * @param a + * @return + */ + public double distance(Vector3 a) { + return Vector3.distance(a, this); + } + + /** + * Raises the X, Y, and Z values of this Vector3 to the given power. + * + * @param power + * @return + */ + public Vector3 pow(double power) { + return Vector3.pow(this, power); + } + + /** + * returns the squared length of the vector + * + * @return + */ + public float lengthSquared() { + return Vector3.lengthSquared(this); + } + + /** + * returns the length of this vector. Note: makes use of Math.sqrt and is + * not cached. + * + * @return + */ + public float length() { + return Vector3.length(this); + } + + /** + * Returns a fast approximation of this vector's length. + * + * @return + */ + public float fastLength() { + return Vector3.fastLength(this); + } + + /** + * returns the vector with a length of 1 + * + * @return + */ + public Vector3 normalize() { + return Vector3.normalize(this); + } + + /** + * returns the vector as [x,y,z] + * + * @return + */ + public float[] toArray() { + return Vector3.toArray(this); + } + + /** + * Compares two Vector3s + */ + @Override + public int compareTo(Vector3 o) { + return Vector3.compareTo(this, o); + } + + /** + * Checks if two Vector3s are equal + */ + @Override + public boolean equals(Object o) { + return Vector3.equals(this, o); + } + + /** + * toString Override + */ + @Override + public String toString() { + return String.format("{ %f, %f, %f }", x, y, z); + } + + /** + * Returns the length of the given vector. + * + * Note: Makes use of Math.sqrt and + * is not cached, so can be slow + * + * Also known as norm. ||a|| + * + * @param a + * @return + */ + public static float length(Vector3 a) { + return (float) Math.sqrt(lengthSquared(a)); + } + + /** + * Returns an approximate length of the given vector. + * + * @param a + * @return + */ + public static float fastLength(Vector3 a) { + return (float) Math.sqrt(lengthSquared(a)); + } + + /** + * returns the length squared to the given vector + * + * @param a + * @return + */ + public static float lengthSquared(Vector3 a) { + return Vector3.dot(a, a); + } + + /** + * Returns a new vector that is the given vector but length 1 + * + * @param a + * @return + */ + public static Vector3 normalize(Vector3 a) { + return Vector3.scale(a, (1.f / a.length())); + } + + /** + * Creates a new vector that is A - B + * + * @param a + * @param b + * @return + */ + public static Vector3 subtract(Vector3 a, Vector3 b) { + return new Vector3(a.getX() - b.getX(), a.getY() - b.getY(), a.getZ() - b.getZ()); + } + + /** + * Creates a new Vector that is A + B + * + * @param a + * @param b + * @return + */ + public static Vector3 add(Vector3 a, Vector3 b) { + return new Vector3(a.getX() + b.getX(), a.getY() + b.getY(), a.getZ() + b.getZ()); + } + + /** + * Creates a new vector that is A multiplied by the uniform scalar B + * + * @param a + * @param b + * @return + */ + public static Vector3 scale(Vector3 a, float b) { + return new Vector3(a.getX() * b, a.getY() * b, a.getZ() * b); + } + + /** + * Returns the dot product of A and B + * + * @param a + * @param b + * @return + */ + public static float dot(Vector3 a, Vector3 b) { + return a.getX() * b.getX() + a.getY() * b.getY() + a.getZ() * b.getZ(); + } + + /** + * Creates a new Vector that is the A x B The Cross Product is the vector + * orthogonal to both A and B + * + * @param a + * @param b + * @return + */ + public static Vector3 cross(Vector3 a, Vector3 b) { + return new Vector3(a.getY() * b.getZ() - a.getZ() * b.getY(), a.getZ() * b.getX() - a.getX() * b.getZ(), a.getX() * b.getY() - a.getY() * b.getX()); + } + + /** + * Rounds the X, Y, and Z values of the given Vector3 up to + * the nearest integer value. + * + * @param o Vector3 to use + * @return + */ + public static Vector3 ceil(Vector3 o) { + return new Vector3(Math.ceil(o.x), Math.ceil(o.y), Math.ceil(o.z)); + } + + /** + * Rounds the X, Y, and Z values of the given Vector3 down to + * the nearest integer value. + * + * @param o Vector3 to use + * @return + */ + public static Vector3 floor(Vector3 o) { + return new Vector3(Math.floor(o.x), Math.floor(o.y), Math.floor(o.z)); + } + + /** + * Rounds the X, Y, and Z values of the given Vector3 to + * the nearest integer value. + * + * @param o Vector3 to use + * @return + */ + public static Vector3 round(Vector3 o) { + return new Vector3(Math.round(o.x), Math.round(o.y), Math.round(o.z)); + } + + /** + * Sets the X, Y, and Z values of the given Vector3 to their + * absolute value. + * + * @param o Vector3 to use + * @return + */ + public static Vector3 abs(Vector3 o) { + return new Vector3(Math.abs(o.x), Math.abs(o.y), Math.abs(o.z)); + } + + /** + * Returns a Vector3 containing the smallest X, Y, and Z values. + * + * @param o1 + * @param o2 + * @return + */ + public static Vector3 min(Vector3 o1, Vector3 o2) { + return new Vector3(Math.min(o1.x, o2.x), Math.min(o1.y, o2.y), Math.min(o1.z, o2.z)); + } + + /** + * Returns a Vector3 containing the largest X, Y, and Z values. + * + * @param o1 + * @param o2 + * @return + */ + public static Vector3 max(Vector3 o1, Vector3 o2) { + return new Vector3(Math.max(o1.x, o2.x), Math.max(o1.y, o2.y), Math.max(o1.z, o2.z)); + } + + /** + * Returns a Vector3 with random X, Y, and Z values (between 0 and 1) + * + * @return + */ + public static Vector3 rand() { + return new Vector3(Math.random(), Math.random(), Math.random()); + } + + /** + * Gets the distance between two Vector3. + * + * @param a + * @param b + * @return + */ + public static double distance(Vector3 a, Vector3 b) { + double xzDist = Vector2.distance(a.toVector2(), b.toVector2()); + return Math.sqrt(Math.pow(xzDist, 2) + Math.pow(Math.abs(Vector3.subtract(a, b).getY()), 2)); + } + + /** + * Raises the X, Y, and Z values of a Vector3 to the given power. + * + * @param o + * @param power + * @return + */ + public static Vector3 pow(Vector3 o, double power) { + return new Vector3(Math.pow(o.x, power), Math.pow(o.y, power), Math.pow(o.z, power)); + } + + /** + * Returns a Vector2 object using the X and Z values of + * the given Vector3. The x of the Vector3 becomes the x + * of the Vector2, and the z of this Vector3 becomes the + * y of the Vector2m. + * + * @param o Vector3 object to use + * @return + */ + public static Vector2 toVector2(Vector3 o) { + return new Vector2(o.x, o.z); + } + + /** + * Returns a Vector2m object using the X and Z values of + * the given Vector3. The x of the Vector3 becomes the x + * of the Vector2m, and the z of this Vector3 becomes the + * y of the Vector2m. + * + * @param o Vector3 object to use + * @return + */ + public static Vector2m toVector2m(Vector3 o) { + return new Vector2m(o.x, o.z); + } + + /** + * Returns a new float array that is {x, y, z} + * + * @param a + * @return + */ + public static float[] toArray(Vector3 a) { + return new float[]{a.getX(), a.getY(), a.getZ()}; + } + + /** + * Compares two Vector3s + */ + public static int compareTo(Vector3 a, Vector3 b) { + return (int) a.lengthSquared() - (int) b.lengthSquared(); + } + + /** + * Checks if two Vector3s are equal + */ + public static boolean equals(Object a, Object b) { + if (!(a instanceof Vector3) || !(b instanceof Vector3)) { + return false; + } + if (a == b) { + return true; + } + Vector3 x = (Vector3) a; + Vector3 y = (Vector3) b; + if (x.getX() == y.getX() && x.getY() == y.getY() && x.getZ() == y.getZ()) { + return true; + } + return false; + } + + @Override + public int hashCode() + { + return (int)(this.x * this.y % this.z); + } +} diff --git a/src/main/java/wecui/util/Vector3m.java b/src/main/java/wecui/util/Vector3m.java index 1ed7d18a..24fa0897 100644 --- a/src/main/java/wecui/util/Vector3m.java +++ b/src/main/java/wecui/util/Vector3m.java @@ -1,159 +1,168 @@ -package wecui.util; - -/** - * A version of Vector3 that can be modified. - * - * @author yetanotherx - */ -public class Vector3m extends Vector3 { - - public Vector3m(float x, float y, float z) { - super(x, y, z); - } - - public Vector3m(Double x, Double y, Double z) { - super(x, y, z); - } - - public Vector3m(Vector3 vector) { - super(vector); - } - - public Vector3m() { - } - - public void setZ(float z) { - this.z = z; - } - - public void setY(float y) { - this.y = y; - } - - public void setX(float x) { - this.x = x; - } - - /** - * Adds two vectors - * - * @param that - * @return - */ - - public Vector3 add(Vector3 that) { - x += that.x; - y += that.y; - z += that.z; - return this; - } - - /** - * Subtracts two vectors - * - * @param that - * @return - */ - - public Vector3 subtract(Vector3 that) { - x -= that.x; - y -= that.y; - z -= that.z; - return this; - } - - /** - * Scales by the scalar value - * - * @param scale - * @return - */ - - public Vector3 scale(float scale) { - x *= scale; - y *= scale; - z *= scale; - return this; - } - - /** - * Takes the cross product of two vectors - * - * @param that - * @return - */ - - public Vector3 cross(Vector3 that) { - x = getY() * that.getZ() - getZ() * that.getY(); - y = getZ() * that.getX() - getX() * that.getZ(); - z = getX() * that.getY() - getY() * that.getX(); - - return this; - } - - /** - * Rounds the X, Y, and Z values of this Vector3 up to - * the nearest integer value. - * - * @return - */ - public Vector3 ceil() { - x = (float) Math.ceil(x); - y = (float) Math.ceil(y); - z = (float) Math.ceil(z); - return this; - } - - /** - * Rounds the X, Y, and Z values of this Vector3 down to - * the nearest integer value. - * - * @return - */ - public Vector3 floor() { - x = (float) Math.floor(x); - y = (float) Math.floor(y); - z = (float) Math.floor(z); - return this; - } - - /** - * Rounds the X, Y, and Z values of this Vector3 to - * the nearest integer value. - * - * @return - */ - public Vector3 round() { - x = Math.round(x); - y = Math.round(y); - z = Math.round(z); - return this; - } - - /** - * Sets the X, Y, and Z values of this Vector3 to their - * absolute value. - * - * @return - */ - public Vector3 abs() { - x = Math.abs(x); - y = Math.abs(y); - z = Math.abs(z); - return this; - } - - /** - * returns the vector with a length of 1 - * - * @return - */ - - public Vector3 normalize() { - float length = this.length(); - x *= 1 / length; - y *= 1 / length; - z *= 1 / length; - return this; - } -} +package wecui.util; + +/** + * A version of Vector3 that can be modified. + * + * @author yetanotherx + */ +public class Vector3m extends Vector3 { + + public Vector3m(float x, float y, float z) { + super(x, y, z); + } + + public Vector3m(Double x, Double y, Double z) { + super(x, y, z); + } + + public Vector3m(Vector3 vector) { + super(vector); + } + + public Vector3m() { + } + + public void setZ(float z) { + this.z = z; + } + + public void setY(float y) { + this.y = y; + } + + public void setX(float x) { + this.x = x; + } + + /** + * Adds two vectors + * + * @param that + * @return + */ + + @Override + public Vector3 add(Vector3 that) { + x += that.x; + y += that.y; + z += that.z; + return this; + } + + /** + * Subtracts two vectors + * + * @param that + * @return + */ + + @Override + public Vector3 subtract(Vector3 that) { + x -= that.x; + y -= that.y; + z -= that.z; + return this; + } + + /** + * Scales by the scalar value + * + * @param scale + * @return + */ + + @Override + public Vector3 scale(float scale) { + x *= scale; + y *= scale; + z *= scale; + return this; + } + + /** + * Takes the cross product of two vectors + * + * @param that + * @return + */ + + @Override + public Vector3 cross(Vector3 that) { + x = getY() * that.getZ() - getZ() * that.getY(); + y = getZ() * that.getX() - getX() * that.getZ(); + z = getX() * that.getY() - getY() * that.getX(); + + return this; + } + + /** + * Rounds the X, Y, and Z values of this Vector3 up to + * the nearest integer value. + * + * @return + */ + @Override + public Vector3 ceil() { + x = (float) Math.ceil(x); + y = (float) Math.ceil(y); + z = (float) Math.ceil(z); + return this; + } + + /** + * Rounds the X, Y, and Z values of this Vector3 down to + * the nearest integer value. + * + * @return + */ + @Override + public Vector3 floor() { + x = (float) Math.floor(x); + y = (float) Math.floor(y); + z = (float) Math.floor(z); + return this; + } + + /** + * Rounds the X, Y, and Z values of this Vector3 to + * the nearest integer value. + * + * @return + */ + @Override + public Vector3 round() { + x = Math.round(x); + y = Math.round(y); + z = Math.round(z); + return this; + } + + /** + * Sets the X, Y, and Z values of this Vector3 to their + * absolute value. + * + * @return + */ + @Override + public Vector3 abs() { + x = Math.abs(x); + y = Math.abs(y); + z = Math.abs(z); + return this; + } + + /** + * returns the vector with a length of 1 + * + * @return + */ + + @Override + public Vector3 normalize() { + float length = this.length(); + x *= 1 / length; + y *= 1 / length; + z *= 1 / length; + return this; + } +} diff --git a/src/main/java/wecui/vendor/org/joor/Reflect.java b/src/main/java/wecui/vendor/org/joor/Reflect.java index 4ff492de..e53572ba 100644 --- a/src/main/java/wecui/vendor/org/joor/Reflect.java +++ b/src/main/java/wecui/vendor/org/joor/Reflect.java @@ -392,9 +392,8 @@ private boolean match(Class[] declaredTypes, Class[] actualTypes) { } return true; - } else { - return false; } + return false; } /** @@ -447,9 +446,8 @@ private static Reflect on(Method method, Object object, Object... args) throws R if (method.getReturnType() == void.class) { method.invoke(object, args); return on(object); - } else { - return on(method.invoke(object, args)); } + return on(method.invoke(object, args)); } catch (Exception e) { throw new ReflectException(e); } @@ -506,9 +504,8 @@ private static Class forName(String name) throws ReflectException { private Class type() { if (isClass) { return (Class) object; - } else { - return object.getClass(); } + return object.getClass(); } /** From 8438edd14b7435b685a88678aff499bd8afee458 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Fri, 3 May 2013 21:19:22 +0100 Subject: [PATCH 02/51] Update to 1.5.2, some code cleanup --- build/build_wecui.xml | 322 ++--- src/main/java/wecui/CUIDebug.java | 5 +- src/main/java/wecui/LiteModWorldEditCUI.java | 240 ++-- src/main/java/wecui/Updater.java | 62 +- src/main/java/wecui/WorldEditCUI.java | 16 +- .../java/wecui/config/CUIConfiguration.java | 46 +- src/main/java/wecui/config/Configuration.java | 32 +- .../java/wecui/config/ConfigurationNode.java | 44 +- .../wecui/config/EmptyNullRepresenter.java | 2 +- src/main/java/wecui/event/CUIEvent.java | 20 +- src/main/java/wecui/event/ChannelEvent.java | 2 +- .../java/wecui/event/ChatCommandEvent.java | 19 +- .../java/wecui/event/OutgoingChatEvent.java | 2 +- .../java/wecui/event/WorldRenderEvent.java | 4 +- .../wecui/event/command/CommandEventBase.java | 2 +- .../wecui/event/command/CommandEventType.java | 4 +- .../java/wecui/event/cui/CUIBaseEvent.java | 12 +- .../wecui/event/cui/CUICylinderEvent.java | 6 +- .../wecui/event/cui/CUIEllipsoidEvent.java | 6 +- .../java/wecui/event/cui/CUIEventType.java | 8 +- .../java/wecui/event/cui/CUIMinMaxEvent.java | 4 +- .../java/wecui/event/cui/CUIPoint2DEvent.java | 4 +- .../java/wecui/event/cui/CUIPointEvent.java | 4 +- .../wecui/event/cui/CUISelectionEvent.java | 12 +- .../wecui/event/listeners/CUIListener.java | 4 +- .../event/listeners/ChannelListener.java | 2 +- .../listeners/WorldEditCommandListener.java | 4 +- .../event/listeners/WorldRenderListener.java | 15 +- src/main/java/wecui/fevents/Event.java | 4 +- src/main/java/wecui/fevents/HandlerList.java | 30 +- src/main/java/wecui/fevents/Order.java | 2 +- .../wecui/obfuscation/DataPacketList.java | 10 +- .../wecui/obfuscation/FieldObfuscation.java | 4 +- src/main/java/wecui/render/LineColor.java | 16 +- src/main/java/wecui/render/LineInfo.java | 6 +- .../java/wecui/render/points/PointCube.java | 6 +- .../wecui/render/points/PointRectangle.java | 6 +- .../wecui/render/region/CuboidRegion.java | 26 +- .../wecui/render/region/CylinderRegion.java | 28 +- .../wecui/render/region/EllipsoidRegion.java | 18 +- .../wecui/render/region/PolygonRegion.java | 21 +- .../java/wecui/render/shapes/Render2DBox.java | 8 +- .../wecui/render/shapes/Render2DGrid.java | 8 +- .../java/wecui/render/shapes/Render3DBox.java | 16 +- .../wecui/render/shapes/Render3DGrid.java | 16 +- .../render/shapes/RenderCylinderBox.java | 10 +- .../render/shapes/RenderCylinderCircles.java | 10 +- .../render/shapes/RenderCylinderGrid.java | 34 +- .../wecui/render/shapes/RenderEllipsoid.java | 50 +- src/main/java/wecui/util/ChatColor.java | 4 +- src/main/java/wecui/util/Vector2.java | 1120 ++++++++-------- src/main/java/wecui/util/Vector2m.java | 260 ++-- src/main/java/wecui/util/Vector3.java | 1164 ++++++++--------- src/main/java/wecui/util/Vector3m.java | 336 ++--- .../java/wecui/vendor/org/joor/Reflect.java | 53 +- 55 files changed, 2086 insertions(+), 2083 deletions(-) diff --git a/build/build_wecui.xml b/build/build_wecui.xml index 5a8b33c1..e21b944d 100644 --- a/build/build_wecui.xml +++ b/build/build_wecui.xml @@ -1,162 +1,162 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/wecui/CUIDebug.java b/src/main/java/wecui/CUIDebug.java index 320dc8b6..b959e0fa 100644 --- a/src/main/java/wecui/CUIDebug.java +++ b/src/main/java/wecui/CUIDebug.java @@ -6,6 +6,7 @@ import java.util.logging.FileHandler; import java.util.logging.Level; import java.util.logging.Logger; + import wecui.exception.InitializationException; import wecui.util.ConsoleLogFormatter; @@ -38,7 +39,7 @@ public void initialize() throws InitializationException { try { this.debugFile = new File(WorldEditCUI.getWorldEditCUIDir(), "WorldEditCUI-debug.txt"); - this.debugMode = controller.getConfiguration().isDebugMode(); + this.debugMode = this.controller.getConfiguration().isDebugMode(); if (this.debugMode) { FileHandler newHandler = new FileHandler(this.debugFile.getAbsolutePath()); @@ -58,7 +59,7 @@ public void initialize() throws InitializationException { * @param message */ public void debug(String message) { - if (debugMode) { + if (this.debugMode) { logger.info("WorldEditCUI Debug - " + message); } } diff --git a/src/main/java/wecui/LiteModWorldEditCUI.java b/src/main/java/wecui/LiteModWorldEditCUI.java index ba7a6b4d..193d0083 100644 --- a/src/main/java/wecui/LiteModWorldEditCUI.java +++ b/src/main/java/wecui/LiteModWorldEditCUI.java @@ -1,121 +1,119 @@ -package wecui; - -import java.nio.charset.Charset; -import java.util.Arrays; -import java.util.List; - -import net.minecraft.client.Minecraft; -import net.minecraft.src.EntityPlayerSP; -import net.minecraft.src.NetHandler; -import net.minecraft.src.OpenGlHelper; -import net.minecraft.src.Packet1Login; -import net.minecraft.src.RenderHelper; -import net.minecraft.src.WorldClient; -import wecui.Updater; -import wecui.WorldEditCUI; -import wecui.event.ChannelEvent; -import wecui.event.WorldRenderEvent; -import wecui.obfuscation.DataPacketList; -import wecui.render.region.CuboidRegion; - -import com.mumfrey.liteloader.InitCompleteListener; -import com.mumfrey.liteloader.PluginChannelListener; -import com.mumfrey.liteloader.PostRenderListener; -import com.mumfrey.liteloader.core.LiteLoader; - -public class LiteModWorldEditCUI implements InitCompleteListener, PluginChannelListener, PostRenderListener -{ - protected WorldEditCUI controller; - protected WorldClient lastWorld; - protected EntityPlayerSP lastPlayer; - protected boolean gameStarted = false; - public final static Charset UTF_8_CHARSET = Charset.forName("UTF-8"); - protected int entityUpdateTickCount = 0; - protected WorldRenderEvent event; - - @Override - public void init() - { - } - - /* (non-Javadoc) - * @see com.mumfrey.liteloader.InitCompleteListener#onInitCompleted(net.minecraft.client.Minecraft, com.mumfrey.liteloader.core.LiteLoader) - */ - @Override - public void onInitCompleted(Minecraft minecraft, LiteLoader loader) - { - this.controller = new WorldEditCUI(Minecraft.getMinecraft()); - this.controller.initialize(); - this.event = new WorldRenderEvent(controller); - } - - @Override - public void onLogin(NetHandler netHandler, Packet1Login loginPacket) - { - byte[] buffer = ("v|" + WorldEditCUI.protocolVersion).getBytes(UTF_8_CHARSET); - LiteLoader.getInstance().sendPluginChannelMessage("WECUI", buffer); - } - - @Override - public List getChannels() - { - return Arrays.asList(new String[] { "WECUI" }); - } - - @Override - public void onCustomPayload(String channel, int length, byte[] data) - { - ChannelEvent channelevent = new ChannelEvent(controller, new String(data, UTF_8_CHARSET)); - controller.getEventManager().callEvent(channelevent); - } - - @Override - public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clock) - { - if (inGame && clock && controller != null) - { - if (mc.theWorld != lastWorld || mc.thePlayer != lastPlayer) { - lastWorld = mc.theWorld; - lastPlayer = mc.thePlayer; - - if (!gameStarted) { - gameStarted = true; - - new Updater(controller).start(); - this.controller.setSelection(new CuboidRegion(controller)); - - DataPacketList.register(controller); - } - } - } - } - - @Override - public String getName() - { - return "WorldEditCUI by yetanotherx"; - } - - @Override - public String getVersion() - { - return "1.5.1_02_lite"; - } - - @Override - public void onPostRenderEntities(float partialTicks) - { - RenderHelper.disableStandardItemLighting(); - OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); - event.setPartialTick(partialTicks); - controller.getEventManager().callEvent(event); - RenderHelper.enableStandardItemLighting(); - } - - @Override - public void onPostRender(float partialTicks) - { - // TODO Auto-generated method stub - - } -} +package wecui; + +import java.nio.charset.Charset; +import java.util.Arrays; +import java.util.List; + +import net.minecraft.client.Minecraft; +import net.minecraft.src.EntityPlayerSP; +import net.minecraft.src.NetHandler; +import net.minecraft.src.OpenGlHelper; +import net.minecraft.src.Packet1Login; +import net.minecraft.src.RenderHelper; +import net.minecraft.src.WorldClient; +import wecui.event.ChannelEvent; +import wecui.event.WorldRenderEvent; +import wecui.obfuscation.DataPacketList; +import wecui.render.region.CuboidRegion; + +import com.mumfrey.liteloader.InitCompleteListener; +import com.mumfrey.liteloader.PluginChannelListener; +import com.mumfrey.liteloader.PostRenderListener; +import com.mumfrey.liteloader.core.LiteLoader; + +public class LiteModWorldEditCUI implements InitCompleteListener, PluginChannelListener, PostRenderListener +{ + protected WorldEditCUI controller; + protected WorldClient lastWorld; + protected EntityPlayerSP lastPlayer; + protected boolean gameStarted = false; + public final static Charset UTF_8_CHARSET = Charset.forName("UTF-8"); + protected int entityUpdateTickCount = 0; + protected WorldRenderEvent event; + + @Override + public void init() + { + } + + /* (non-Javadoc) + * @see com.mumfrey.liteloader.InitCompleteListener#onInitCompleted(net.minecraft.client.Minecraft, com.mumfrey.liteloader.core.LiteLoader) + */ + @Override + public void onInitCompleted(Minecraft minecraft, LiteLoader loader) + { + this.controller = new WorldEditCUI(Minecraft.getMinecraft()); + this.controller.initialize(); + this.event = new WorldRenderEvent(this.controller); + } + + @Override + public void onLogin(NetHandler netHandler, Packet1Login loginPacket) + { + byte[] buffer = ("v|" + WorldEditCUI.protocolVersion).getBytes(UTF_8_CHARSET); + LiteLoader.getInstance().sendPluginChannelMessage("WECUI", buffer); + } + + @Override + public List getChannels() + { + return Arrays.asList(new String[] { "WECUI" }); + } + + @Override + public void onCustomPayload(String channel, int length, byte[] data) + { + ChannelEvent channelevent = new ChannelEvent(this.controller, new String(data, UTF_8_CHARSET)); + this.controller.getEventManager().callEvent(channelevent); + } + + @Override + public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clock) + { + if (inGame && clock && this.controller != null) + { + if (mc.theWorld != this.lastWorld || mc.thePlayer != this.lastPlayer) { + this.lastWorld = mc.theWorld; + this.lastPlayer = mc.thePlayer; + + if (!this.gameStarted) { + this.gameStarted = true; + + new Updater(this.controller).start(); + this.controller.setSelection(new CuboidRegion(this.controller)); + + DataPacketList.register(this.controller); + } + } + } + } + + @Override + public String getName() + { + return "WorldEditCUI by yetanotherx"; + } + + @Override + public String getVersion() + { + return "1.5.2_02_lite"; + } + + @Override + public void onPostRenderEntities(float partialTicks) + { + RenderHelper.disableStandardItemLighting(); + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); + this.event.setPartialTick(partialTicks); + this.controller.getEventManager().callEvent(this.event); + RenderHelper.enableStandardItemLighting(); + } + + @Override + public void onPostRender(float partialTicks) + { + // TODO Auto-generated method stub + + } +} diff --git a/src/main/java/wecui/Updater.java b/src/main/java/wecui/Updater.java index e1c9565a..1e8af4d9 100644 --- a/src/main/java/wecui/Updater.java +++ b/src/main/java/wecui/Updater.java @@ -1,25 +1,20 @@ package wecui; +import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import net.minecraft.src.EntityClientPlayerMP; - -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.reader.UnicodeReader; -import wecui.config.ConfigurationNode; -import wecui.exception.ConfigurationException; import wecui.util.ChatColor; public class Updater extends Thread { protected WorldEditCUI controller; protected final int updaterVersion = 1; + + protected final int currentRevision = 100; public Updater(WorldEditCUI controller) { this.controller = controller; @@ -31,44 +26,47 @@ public Updater(WorldEditCUI controller) { * show an error to the user. */ @Override - @SuppressWarnings("unchecked") public void run() { - if (controller.configuration.ignoreUpdates()) { + if (this.controller.configuration.ignoreUpdates()) { return; } InputStream is = null; - ConfigurationNode node = new ConfigurationNode(new HashMap()); try { - URL url = new URL(controller.getConfiguration().getUpdateFile()); + URL url = new URL(this.controller.getConfiguration().getUpdateFile()); url.openConnection(); is = url.openStream(); - Yaml yaml = new Yaml(); - Object out = yaml.load(new UnicodeReader(is)); - - try { - if (null != out) { - node.setRoot((Map) out); - } - } catch (ClassCastException e) { - throw new ConfigurationException("Root document must be an key-value structure"); - } - - String currentVersion = node.getString("updaterVersion" + this.updaterVersion + ".current"); - List supportedVersions = node.getStringList("updaterVersion" + this.updaterVersion + ".supported", new ArrayList()); + StringBuilder readString = new StringBuilder(); + BufferedReader reader = new BufferedReader(new InputStreamReader(is)); - if (currentVersion != null && !currentVersion.equals(WorldEditCUI.VERSION) && !(currentVersion + "beta").equals(WorldEditCUI.VERSION)) { - if (supportedVersions != null && !supportedVersions.contains(WorldEditCUI.VERSION)) { - this.showChatMessage(ChatColor.RED + "Your WorldEditCUI version is out of date! "); - this.showChatMessage(ChatColor.RED + "The latest version is " + currentVersion + ". http://bit.ly/wecui"); + String readLine; + while ((readLine = reader.readLine()) != null) + { + readString.append(readLine).append("\n"); + } + + reader.close(); - } + String[] versions = readString.toString().split("\n"); + int latestVersion = 0; + + for (String version : versions) + { + System.out.println("Version: " + version); + if (version.matches("^" + WorldEditCUI.MCVERSION + "=\\d+$")) + { + latestVersion = Integer.parseInt(version.substring(version.indexOf("=") + 1)); + } + } + + if (latestVersion > this.currentRevision) { + this.showChatMessage(ChatColor.RED + "Your WorldEditCUI version is out of date."); } } catch (Exception e) { - controller.getDebugger().info("Error in fetching update file!", e); + this.controller.getDebugger().info("Error in fetching update file!", e); } finally { if (is != null) { try { diff --git a/src/main/java/wecui/WorldEditCUI.java b/src/main/java/wecui/WorldEditCUI.java index 86832e8c..3bfdcd78 100644 --- a/src/main/java/wecui/WorldEditCUI.java +++ b/src/main/java/wecui/WorldEditCUI.java @@ -7,8 +7,8 @@ import wecui.event.CUIEvent; import wecui.event.ChannelEvent; import wecui.event.ChatCommandEvent; -import wecui.event.listeners.CUIListener; import wecui.event.WorldRenderEvent; +import wecui.event.listeners.CUIListener; import wecui.event.listeners.ChannelListener; import wecui.event.listeners.WorldEditCommandListener; import wecui.event.listeners.WorldRenderListener; @@ -30,8 +30,8 @@ */ public class WorldEditCUI { - public static final String VERSION = "1.5.1"; - public static final String MCVERSION = "1.5.1"; + public static final String VERSION = "1.5.2"; + public static final String MCVERSION = "1.5.2"; public static final int protocolVersion = 2; protected Minecraft minecraft; protected EventManager eventManager; @@ -76,7 +76,7 @@ protected void registerListeners() { } public CUIConfiguration getConfiguration() { - return configuration; + return this.configuration; } public void setConfiguration(CUIConfiguration configuration) { @@ -84,7 +84,7 @@ public void setConfiguration(CUIConfiguration configuration) { } public CUIDebug getDebugger() { - return debugger; + return this.debugger; } public void setDebugger(CUIDebug debugger) { @@ -92,7 +92,7 @@ public void setDebugger(CUIDebug debugger) { } public EventManager getEventManager() { - return eventManager; + return this.eventManager; } public void setEventManager(EventManager eventManager) { @@ -108,7 +108,7 @@ public void setLocalPlugin(LocalPlugin localPlugin) { }*/ public Minecraft getMinecraft() { - return minecraft; + return this.minecraft; } public void setMinecraft(Minecraft minecraft) { @@ -116,7 +116,7 @@ public void setMinecraft(Minecraft minecraft) { } public BaseRegion getSelection() { - return selection; + return this.selection; } public void setSelection(BaseRegion selection) { diff --git a/src/main/java/wecui/config/CUIConfiguration.java b/src/main/java/wecui/config/CUIConfiguration.java index 64d61f56..a4d9a003 100644 --- a/src/main/java/wecui/config/CUIConfiguration.java +++ b/src/main/java/wecui/config/CUIConfiguration.java @@ -32,7 +32,7 @@ public class CUIConfiguration implements InitializationFactory { protected String cylinderGridColor = "#CC3333"; protected String cylinderEdgeColor = "#CC4C4C"; protected String cylinderPointColor = "#CC33CC"; - protected String updateFile = "https://raw.github.com/yetanotherx/WorldEditCUI/master/updates.yml"; + protected String updateFile = "http://update.liteloader.com/wecui.version"; protected Configuration config = null; public CUIConfiguration(WorldEditCUI controller) { @@ -80,24 +80,24 @@ public void initialize() { } } - config = new Configuration(file); - config.load(); - - this.debugMode = config.getBoolean("debug", debugMode); - this.ignoreUpdates = config.getBoolean("ignoreUpdates", ignoreUpdates); - - this.cuboidGridColor = parseColor(config.getString("colors.cuboidGrid"), this.cuboidGridColor); - this.cuboidEdgeColor = parseColor(config.getString("colors.cuboidEdge"), this.cuboidEdgeColor); - this.cuboidFirstPointColor = parseColor(config.getString("colors.cuboidFirstPoint"), this.cuboidFirstPointColor); - this.cuboidSecondPointColor = parseColor(config.getString("colors.cuboidSecondPoint"), this.cuboidSecondPointColor); - this.polyGridColor = parseColor(config.getString("colors.polyGrid"), this.polyGridColor); - this.polyEdgeColor = parseColor(config.getString("colors.polyEdge"), this.polyEdgeColor); - this.polyPointColor = parseColor(config.getString("colors.polyPoint"), this.polyPointColor); - this.ellipsoidGridColor = parseColor(config.getString("colors.ellipsoidGrid"), this.ellipsoidGridColor); - this.ellipsoidPointColor = parseColor(config.getString("colors.ellipsoidPoint"), this.ellipsoidPointColor); - this.cylinderGridColor = parseColor(config.getString("colors.cylinderGrid"), this.cylinderGridColor); - this.cylinderEdgeColor = parseColor(config.getString("colors.cylinderEdge"), this.cylinderEdgeColor); - this.cylinderPointColor = parseColor(config.getString("colors.cylinderPoint"), this.cylinderPointColor); + this.config = new Configuration(file); + this.config.load(); + + this.debugMode = this.config.getBoolean("debug", this.debugMode); + this.ignoreUpdates = this.config.getBoolean("ignoreUpdates", this.ignoreUpdates); + + this.cuboidGridColor = this.parseColor(this.config.getString("colors.cuboidGrid"), this.cuboidGridColor); + this.cuboidEdgeColor = this.parseColor(this.config.getString("colors.cuboidEdge"), this.cuboidEdgeColor); + this.cuboidFirstPointColor = this.parseColor(this.config.getString("colors.cuboidFirstPoint"), this.cuboidFirstPointColor); + this.cuboidSecondPointColor = this.parseColor(this.config.getString("colors.cuboidSecondPoint"), this.cuboidSecondPointColor); + this.polyGridColor = this.parseColor(this.config.getString("colors.polyGrid"), this.polyGridColor); + this.polyEdgeColor = this.parseColor(this.config.getString("colors.polyEdge"), this.polyEdgeColor); + this.polyPointColor = this.parseColor(this.config.getString("colors.polyPoint"), this.polyPointColor); + this.ellipsoidGridColor = this.parseColor(this.config.getString("colors.ellipsoidGrid"), this.ellipsoidGridColor); + this.ellipsoidPointColor = this.parseColor(this.config.getString("colors.ellipsoidPoint"), this.ellipsoidPointColor); + this.cylinderGridColor = this.parseColor(this.config.getString("colors.cylinderGrid"), this.cylinderGridColor); + this.cylinderEdgeColor = this.parseColor(this.config.getString("colors.cylinderEdge"), this.cylinderEdgeColor); + this.cylinderPointColor = this.parseColor(this.config.getString("colors.cylinderPoint"), this.cylinderPointColor); LineColor.CUBOIDBOX.setColor(this.cuboidEdgeColor); LineColor.CUBOIDGRID.setColor(this.cuboidGridColor); @@ -112,7 +112,7 @@ public void initialize() { LineColor.CYLINDERBOX.setColor(this.cylinderEdgeColor); LineColor.CYLINDERCENTER.setColor(this.cylinderPointColor); - this.updateFile = config.getString("updateFile", this.updateFile); + this.updateFile = this.config.getString("updateFile", this.updateFile); } /** @@ -136,14 +136,14 @@ protected String parseColor(String color, String def) { } public boolean isDebugMode() { - return debugMode; + return this.debugMode; } public boolean ignoreUpdates() { - return ignoreUpdates; + return this.ignoreUpdates; } public String getUpdateFile() { - return updateFile; + return this.updateFile; } } diff --git a/src/main/java/wecui/config/Configuration.java b/src/main/java/wecui/config/Configuration.java index 260e5958..571c06f5 100644 --- a/src/main/java/wecui/config/Configuration.java +++ b/src/main/java/wecui/config/Configuration.java @@ -1,6 +1,5 @@ package wecui.config; -import wecui.exception.ConfigurationException; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -8,11 +7,14 @@ import java.io.OutputStreamWriter; import java.util.HashMap; import java.util.Map; + import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.SafeConstructor; import org.yaml.snakeyaml.reader.UnicodeReader; +import wecui.exception.ConfigurationException; + /** * YAML configuration loader. To use this class, construct it with path to * a file and call its load() method. For specifying node paths in the @@ -59,7 +61,7 @@ public Configuration(File file) { options.setIndent(4); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); - yaml = new Yaml(new SafeConstructor(), new EmptyNullRepresenter(), options); + this.yaml = new Yaml(new SafeConstructor(), new EmptyNullRepresenter(), options); this.file = file; } @@ -71,12 +73,12 @@ public void load() { FileInputStream stream = null; try { - stream = new FileInputStream(file); - read(yaml.load(new UnicodeReader(stream))); + stream = new FileInputStream(this.file); + this.read(this.yaml.load(new UnicodeReader(stream))); } catch (IOException e) { - root = new HashMap(); + this.root = new HashMap(); } catch (ConfigurationException e) { - root = new HashMap(); + this.root = new HashMap(); } finally { try { if (stream != null) { @@ -103,7 +105,7 @@ public void setHeader(String... headerLines) { headerTemp.append(line); } - setHeader(headerTemp.toString()); + this.setHeader(headerTemp.toString()); } /** @@ -124,7 +126,7 @@ public void setHeader(String header) { * @return */ public String getHeader() { - return header; + return this.header; } /** @@ -136,20 +138,20 @@ public String getHeader() { public boolean save() { FileOutputStream stream = null; - File parent = file.getParentFile(); + File parent = this.file.getParentFile(); if (parent != null) { parent.mkdirs(); } try { - stream = new FileOutputStream(file); + stream = new FileOutputStream(this.file); OutputStreamWriter writer = new OutputStreamWriter(stream, "UTF-8"); - if (header != null) { - writer.append(header); + if (this.header != null) { + writer.append(this.header); writer.append("\r\n"); } - yaml.dump(root, writer); + this.yaml.dump(this.root, writer); return true; } catch (IOException e) { } finally { @@ -168,9 +170,9 @@ public boolean save() { private void read(Object input) throws ConfigurationException { try { if (null == input) { - root = new HashMap(); + this.root = new HashMap(); } else { - root = (Map) input; + this.root = (Map) input; } } catch (ClassCastException e) { throw new ConfigurationException("Root document must be an key-value structure"); diff --git a/src/main/java/wecui/config/ConfigurationNode.java b/src/main/java/wecui/config/ConfigurationNode.java index 9fc7b7cf..672bb5c5 100644 --- a/src/main/java/wecui/config/ConfigurationNode.java +++ b/src/main/java/wecui/config/ConfigurationNode.java @@ -31,7 +31,7 @@ public ConfigurationNode(Map root) { @SuppressWarnings("unchecked") public Object getProperty(String path) { if (!path.contains(".")) { - Object val = root.get(path); + Object val = this.root.get(path); if (val == null) { return null; @@ -40,7 +40,7 @@ public Object getProperty(String path) { } String[] parts = path.split("\\."); - Map node = root; + Map node = this.root; for (int i = 0; i < parts.length; i++) { Object o = node.get(parts[i]); @@ -73,12 +73,12 @@ public Object getProperty(String path) { @SuppressWarnings("unchecked") public void setProperty(String path, Object value) { if (!path.contains(".")) { - root.put(path, value); + this.root.put(path, value); return; } String[] parts = path.split("\\."); - Map node = root; + Map node = this.root; for (int i = 0; i < parts.length; i++) { Object o = node.get(parts[i]); @@ -109,7 +109,7 @@ public void setProperty(String path, Object value) { * @return string or null */ public String getString(String path) { - Object o = getProperty(path); + Object o = this.getProperty(path); if (o == null) { return null; @@ -127,7 +127,7 @@ public String getString(String path) { * @return string or default */ public String getString(String path, String def) { - String o = getString(path); + String o = this.getString(path); if (o == null) { //setProperty(path, def); @@ -147,7 +147,7 @@ public String getString(String path, String def) { * @return int or default */ public int getInt(String path, int def) { - Integer o = castInt(getProperty(path)); + Integer o = castInt(this.getProperty(path)); if (o == null) { //setProperty(path, def); @@ -167,7 +167,7 @@ public int getInt(String path, int def) { * @return double or default */ public double getDouble(String path, double def) { - Double o = castDouble(getProperty(path)); + Double o = castDouble(this.getProperty(path)); if (o == null) { //setProperty(path, def); @@ -186,7 +186,7 @@ public double getDouble(String path, double def) { * @return boolean or default */ public boolean getBoolean(String path, boolean def) { - Boolean o = castBoolean(getProperty(path)); + Boolean o = castBoolean(this.getProperty(path)); if (o == null) { //setProperty(path, def); @@ -205,9 +205,9 @@ public boolean getBoolean(String path, boolean def) { @SuppressWarnings("unchecked") public List getKeys(String path) { if (path == null) { - return new ArrayList(root.keySet()); + return new ArrayList(this.root.keySet()); } - Object o = getProperty(path); + Object o = this.getProperty(path); if (o == null) { return null; @@ -227,7 +227,7 @@ public List getKeys(String path) { */ @SuppressWarnings("unchecked") public List getList(String path) { - Object o = getProperty(path); + Object o = this.getProperty(path); if (o == null) { return null; @@ -251,7 +251,7 @@ public List getList(String path) { * @return list of strings */ public List getStringList(String path, List def) { - List raw = getList(path); + List raw = this.getList(path); if (raw == null) { return def != null ? def : new ArrayList(); @@ -282,7 +282,7 @@ public List getStringList(String path, List def) { * @return list of integers */ public List getIntList(String path, List def) { - List raw = getList(path); + List raw = this.getList(path); if (raw == null) { return def != null ? def : new ArrayList(); @@ -313,7 +313,7 @@ public List getIntList(String path, List def) { * @return list of integers */ public List getDoubleList(String path, List def) { - List raw = getList(path); + List raw = this.getList(path); if (raw == null) { return def != null ? def : new ArrayList(); @@ -344,7 +344,7 @@ public List getDoubleList(String path, List def) { * @return list of integers */ public List getBooleanList(String path, List def) { - List raw = getList(path); + List raw = this.getList(path); if (raw == null) { return def != null ? def : new ArrayList(); @@ -376,7 +376,7 @@ public List getBooleanList(String path, List def) { */ @SuppressWarnings("unchecked") public List getNodeList(String path, List def) { - List raw = getList(path); + List raw = this.getList(path); if (raw == null) { return def != null ? def : new ArrayList(); @@ -403,7 +403,7 @@ public List getNodeList(String path, List */ @SuppressWarnings("unchecked") public ConfigurationNode getNode(String path) { - Object raw = getProperty(path); + Object raw = this.getProperty(path); if (raw instanceof Map) { return new ConfigurationNode((Map) raw); @@ -421,7 +421,7 @@ public ConfigurationNode getNode(String path) { */ @SuppressWarnings("unchecked") public Map getNodes(String path) { - Object o = getProperty(path); + Object o = this.getProperty(path); if (o == null) { return null; @@ -513,12 +513,12 @@ private static Boolean castBoolean(Object o) { @SuppressWarnings("unchecked") public void removeProperty(String path) { if (!path.contains(".")) { - root.remove(path); + this.root.remove(path); return; } String[] parts = path.split("\\."); - Map node = root; + Map node = this.root; for (int i = 0; i < parts.length; i++) { Object o = node.get(parts[i]); @@ -534,7 +534,7 @@ public void removeProperty(String path) { } public Map getRoot() { - return root; + return this.root; } public void setRoot(Map root) { diff --git a/src/main/java/wecui/config/EmptyNullRepresenter.java b/src/main/java/wecui/config/EmptyNullRepresenter.java index d42934e5..e9ea23d4 100644 --- a/src/main/java/wecui/config/EmptyNullRepresenter.java +++ b/src/main/java/wecui/config/EmptyNullRepresenter.java @@ -21,7 +21,7 @@ protected class EmptyRepresentNull implements Represent { @Override public Node representData(Object data) { - return representScalar(Tag.NULL, ""); // Changed "null" to "" so as to avoid writing nulls + return EmptyNullRepresenter.this.representScalar(Tag.NULL, ""); // Changed "null" to "" so as to avoid writing nulls } } diff --git a/src/main/java/wecui/event/CUIEvent.java b/src/main/java/wecui/event/CUIEvent.java index 9435c390..f6796976 100644 --- a/src/main/java/wecui/event/CUIEvent.java +++ b/src/main/java/wecui/event/CUIEvent.java @@ -1,9 +1,9 @@ package wecui.event; -import wecui.util.Utilities; +import wecui.WorldEditCUI; import wecui.fevents.Event; import wecui.fevents.HandlerList; -import wecui.WorldEditCUI; +import wecui.util.Utilities; /** * CUI communication event @@ -55,32 +55,32 @@ public void setHandled(boolean handled) { * @param reason Error message */ public void markInvalid(String reason) { - this.controller.getDebugger().debug("INVALID WECUIEvent " + type + " - " + Utilities.join(params, "|") + " - Reason: " + reason); - setHandled(true); + this.controller.getDebugger().debug("INVALID WECUIEvent " + this.type + " - " + Utilities.join(this.params, "|") + " - Reason: " + reason); + this.setHandled(true); } public int getInt(int index) { - return (int) Float.parseFloat(params[index]); + return (int) Float.parseFloat(this.params[index]); } public String getString(int index) { - return params[index]; + return this.params[index]; } public boolean isHandled() { - return handled; + return this.handled; } @Override public boolean isCancelled() { - return isHandled(); + return this.isHandled(); } public String[] getParams() { - return params; + return this.params; } public String getType() { - return type; + return this.type; } } diff --git a/src/main/java/wecui/event/ChannelEvent.java b/src/main/java/wecui/event/ChannelEvent.java index 273a74b7..744c45d3 100644 --- a/src/main/java/wecui/event/ChannelEvent.java +++ b/src/main/java/wecui/event/ChannelEvent.java @@ -33,6 +33,6 @@ protected HandlerList getHandlers() { } public String getMessage() { - return message; + return this.message; } } diff --git a/src/main/java/wecui/event/ChatCommandEvent.java b/src/main/java/wecui/event/ChatCommandEvent.java index 35d965d5..27f828f6 100644 --- a/src/main/java/wecui/event/ChatCommandEvent.java +++ b/src/main/java/wecui/event/ChatCommandEvent.java @@ -1,10 +1,11 @@ package wecui.event; -import wecui.fevents.Event; -import wecui.fevents.HandlerList; import java.util.HashMap; + import wecui.WorldEditCUI; import wecui.fevents.Cancellable; +import wecui.fevents.Event; +import wecui.fevents.HandlerList; /** * Events for outgoing commands to server. @@ -61,7 +62,7 @@ public static HandlerList getHandlers(String command) { @Override protected HandlerList getHandlers() { - HandlerList handlers = allhandlers.get(command); + HandlerList handlers = allhandlers.get(this.command); if (handlers == null) { handlers = defaulthandlers; } @@ -69,28 +70,28 @@ protected HandlerList getHandlers() { } public void markHandled() { - handled = true; + this.handled = true; } public boolean isHandled() { - return handled; + return this.handled; } public String[] getArgs() { - return args; + return this.args; } public String getCommand() { - return command; + return this.command; } public String getRawMessage() { - return rawMessage; + return this.rawMessage; } @Override public boolean isCancelled() { - return cancelled; + return this.cancelled; } @Override diff --git a/src/main/java/wecui/event/OutgoingChatEvent.java b/src/main/java/wecui/event/OutgoingChatEvent.java index 0f03a187..2fa16921 100644 --- a/src/main/java/wecui/event/OutgoingChatEvent.java +++ b/src/main/java/wecui/event/OutgoingChatEvent.java @@ -34,7 +34,7 @@ protected HandlerList getHandlers() { } public String getMessage() { - return message; + return this.message; } @Override diff --git a/src/main/java/wecui/event/WorldRenderEvent.java b/src/main/java/wecui/event/WorldRenderEvent.java index aee3661f..7dddcbb0 100644 --- a/src/main/java/wecui/event/WorldRenderEvent.java +++ b/src/main/java/wecui/event/WorldRenderEvent.java @@ -32,11 +32,11 @@ public void setPosition(Vector3 pos) { } public float getPartialTick() { - return partialTick; + return this.partialTick; } public Vector3 getPosition() { - return pos; + return this.pos; } @Override diff --git a/src/main/java/wecui/event/command/CommandEventBase.java b/src/main/java/wecui/event/command/CommandEventBase.java index fe29edf7..7c5af958 100644 --- a/src/main/java/wecui/event/command/CommandEventBase.java +++ b/src/main/java/wecui/event/command/CommandEventBase.java @@ -27,7 +27,7 @@ public CommandEventBase(WorldEditCUI controller, String[] args) { @Override public boolean isCancelled() { - return cancelled; + return this.cancelled; } @Override diff --git a/src/main/java/wecui/event/command/CommandEventType.java b/src/main/java/wecui/event/command/CommandEventType.java index d9bdb4b3..c60015bf 100644 --- a/src/main/java/wecui/event/command/CommandEventType.java +++ b/src/main/java/wecui/event/command/CommandEventType.java @@ -27,11 +27,11 @@ private CommandEventType(Class eventClass, String... } public Class getEventClass() { - return eventClass; + return this.eventClass; } public List getAliases() { - return aliases; + return this.aliases; } public static CommandEventType getTypeFromCommand(String key) { diff --git a/src/main/java/wecui/event/cui/CUIBaseEvent.java b/src/main/java/wecui/event/cui/CUIBaseEvent.java index 2eede934..fd5f8f97 100644 --- a/src/main/java/wecui/event/cui/CUIBaseEvent.java +++ b/src/main/java/wecui/event/cui/CUIBaseEvent.java @@ -52,7 +52,7 @@ public boolean isValid() { } public final String doRun() { - if (controller == null || args == null) { + if (this.controller == null || this.args == null) { throw new RuntimeException("Controller and parameters must both be set."); } @@ -64,8 +64,8 @@ public final String doRun() { message += "between " + this.getEventType().getMinParameters() + " and " + this.getEventType().getMaxParameters() + " parameters. "; } - message += "Received " + args.length + " parameters instead. "; - for (String arg : args) { + message += "Received " + this.args.length + " parameters instead. "; + for (String arg : this.args) { message += arg + " "; } @@ -77,14 +77,14 @@ public final String doRun() { } public int getInt(int index) { - return (int) Float.parseFloat(args[index]); + return (int) Float.parseFloat(this.args[index]); } public double getDouble(int index) { - return Double.parseDouble(args[index]); + return Double.parseDouble(this.args[index]); } public String getString(int index) { - return args[index]; + return this.args[index]; } } diff --git a/src/main/java/wecui/event/cui/CUICylinderEvent.java b/src/main/java/wecui/event/cui/CUICylinderEvent.java index 0f008716..4dee0e69 100644 --- a/src/main/java/wecui/event/cui/CUICylinderEvent.java +++ b/src/main/java/wecui/event/cui/CUICylinderEvent.java @@ -28,10 +28,10 @@ public String run() { double radX = this.getDouble(3); double radZ = this.getDouble(4); - controller.getSelection().setCylinderCenter(x, y, z); - controller.getSelection().setCylinderRadius(radX, radZ); + this.controller.getSelection().setCylinderCenter(x, y, z); + this.controller.getSelection().setCylinderRadius(radX, radZ); - controller.getDebugger().debug("Setting center/radius"); + this.controller.getDebugger().debug("Setting center/radius"); return null; } diff --git a/src/main/java/wecui/event/cui/CUIEllipsoidEvent.java b/src/main/java/wecui/event/cui/CUIEllipsoidEvent.java index 311c2a88..44fd8989 100644 --- a/src/main/java/wecui/event/cui/CUIEllipsoidEvent.java +++ b/src/main/java/wecui/event/cui/CUIEllipsoidEvent.java @@ -28,15 +28,15 @@ public String run() { int x = this.getInt(1); int y = this.getInt(2); int z = this.getInt(3); - controller.getSelection().setEllipsoidCenter(x, y, z); + this.controller.getSelection().setEllipsoidCenter(x, y, z); } else if (id == 1) { double x = this.getDouble(1); double y = this.getDouble(2); double z = this.getDouble(3); - controller.getSelection().setEllipsoidRadii(x, y, z); + this.controller.getSelection().setEllipsoidRadii(x, y, z); } - controller.getDebugger().debug("Setting center/radius"); + this.controller.getDebugger().debug("Setting center/radius"); return null; } diff --git a/src/main/java/wecui/event/cui/CUIEventType.java b/src/main/java/wecui/event/cui/CUIEventType.java index 889e4579..9112476d 100644 --- a/src/main/java/wecui/event/cui/CUIEventType.java +++ b/src/main/java/wecui/event/cui/CUIEventType.java @@ -36,19 +36,19 @@ private CUIEventType(Class eventClass, String key, int p } public Class getEventClass() { - return eventClass; + return this.eventClass; } public String getKey() { - return key; + return this.key; } public int getMaxParameters() { - return max; + return this.max; } public int getMinParameters() { - return min; + return this.min; } public static CUIEventType getTypeFromKey(String key) { diff --git a/src/main/java/wecui/event/cui/CUIMinMaxEvent.java b/src/main/java/wecui/event/cui/CUIMinMaxEvent.java index 92d1f124..82df658e 100644 --- a/src/main/java/wecui/event/cui/CUIMinMaxEvent.java +++ b/src/main/java/wecui/event/cui/CUIMinMaxEvent.java @@ -23,9 +23,9 @@ public CUIEventType getEventType() { public String run() { int min = this.getInt(0); int max = this.getInt(1); - controller.getSelection().setMinMax(min, max); + this.controller.getSelection().setMinMax(min, max); - controller.getDebugger().debug("Expanding/contracting selection."); + this.controller.getDebugger().debug("Expanding/contracting selection."); return null; } diff --git a/src/main/java/wecui/event/cui/CUIPoint2DEvent.java b/src/main/java/wecui/event/cui/CUIPoint2DEvent.java index 27b0a399..40362d6d 100644 --- a/src/main/java/wecui/event/cui/CUIPoint2DEvent.java +++ b/src/main/java/wecui/event/cui/CUIPoint2DEvent.java @@ -26,9 +26,9 @@ public String run() { int x = this.getInt(1); int z = this.getInt(2); @SuppressWarnings("unused") int regionSize = this.getInt(3); - controller.getSelection().setPolygonPoint(id, x, z); + this.controller.getSelection().setPolygonPoint(id, x, z); - controller.getDebugger().debug("Setting point2d #" + id); + this.controller.getDebugger().debug("Setting point2d #" + id); return null; } diff --git a/src/main/java/wecui/event/cui/CUIPointEvent.java b/src/main/java/wecui/event/cui/CUIPointEvent.java index 6399b383..e75ba76d 100644 --- a/src/main/java/wecui/event/cui/CUIPointEvent.java +++ b/src/main/java/wecui/event/cui/CUIPointEvent.java @@ -26,9 +26,9 @@ public String run() { int y = this.getInt(2); int z = this.getInt(3); - controller.getSelection().setCuboidPoint(id, x, y, z); + this.controller.getSelection().setCuboidPoint(id, x, y, z); this.setLocalPoint(id, x, y, z); - controller.getDebugger().debug("Setting point #" + id); + this.controller.getDebugger().debug("Setting point #" + id); return null; } diff --git a/src/main/java/wecui/event/cui/CUISelectionEvent.java b/src/main/java/wecui/event/cui/CUISelectionEvent.java index 8d560fe5..9d0320fd 100644 --- a/src/main/java/wecui/event/cui/CUISelectionEvent.java +++ b/src/main/java/wecui/event/cui/CUISelectionEvent.java @@ -30,19 +30,19 @@ public String run() { BaseRegion newRegion = null; if (this.getString(0).equals("cuboid")) { - newRegion = new CuboidRegion(controller); + newRegion = new CuboidRegion(this.controller); } else if (this.getString(0).equals("polygon2d")) { - newRegion = new PolygonRegion(controller); + newRegion = new PolygonRegion(this.controller); } else if (this.getString(0).equals("ellipsoid")) { - newRegion = new EllipsoidRegion(controller); + newRegion = new EllipsoidRegion(this.controller); } else if (this.getString(0).equals("cylinder")) { - newRegion = new CylinderRegion(controller); + newRegion = new CylinderRegion(this.controller); } else { return "Invalid selection type. Must be cuboid|polygon2d|ellipsoid|cylinder."; } - controller.setSelection(newRegion); - controller.getDebugger().debug("Received selection event, initalizing new region instance."); + this.controller.setSelection(newRegion); + this.controller.getDebugger().debug("Received selection event, initalizing new region instance."); return null; } diff --git a/src/main/java/wecui/event/listeners/CUIListener.java b/src/main/java/wecui/event/listeners/CUIListener.java index 7e91d173..c2fd61ed 100644 --- a/src/main/java/wecui/event/listeners/CUIListener.java +++ b/src/main/java/wecui/event/listeners/CUIListener.java @@ -1,12 +1,12 @@ package wecui.event.listeners; -import wecui.vendor.org.joor.Reflect; -import wecui.fevents.Listener; import wecui.WorldEditCUI; import wecui.event.CUIEvent; import wecui.event.cui.CUIBaseEvent; import wecui.event.cui.CUIEventType; import wecui.exception.ReflectException; +import wecui.fevents.Listener; +import wecui.vendor.org.joor.Reflect; /** * Listener class for CUIEvent diff --git a/src/main/java/wecui/event/listeners/ChannelListener.java b/src/main/java/wecui/event/listeners/ChannelListener.java index 363c5c67..f4dff3e5 100644 --- a/src/main/java/wecui/event/listeners/ChannelListener.java +++ b/src/main/java/wecui/event/listeners/ChannelListener.java @@ -1,9 +1,9 @@ package wecui.event.listeners; -import wecui.fevents.Listener; import wecui.WorldEditCUI; import wecui.event.CUIEvent; import wecui.event.ChannelEvent; +import wecui.fevents.Listener; /** * Listener class for incoming plugin channel messages diff --git a/src/main/java/wecui/event/listeners/WorldEditCommandListener.java b/src/main/java/wecui/event/listeners/WorldEditCommandListener.java index fcb5ca72..57e877dd 100644 --- a/src/main/java/wecui/event/listeners/WorldEditCommandListener.java +++ b/src/main/java/wecui/event/listeners/WorldEditCommandListener.java @@ -1,12 +1,12 @@ package wecui.event.listeners; -import wecui.fevents.Listener; import wecui.WorldEditCUI; import wecui.event.ChatCommandEvent; import wecui.event.command.CommandEventBase; import wecui.event.command.CommandEventType; -import wecui.vendor.org.joor.Reflect; import wecui.exception.ReflectException; +import wecui.fevents.Listener; +import wecui.vendor.org.joor.Reflect; /** * Parses outgoing commands, and checks if they match an existing command. diff --git a/src/main/java/wecui/event/listeners/WorldRenderListener.java b/src/main/java/wecui/event/listeners/WorldRenderListener.java index 75c50a34..16a4ef0c 100644 --- a/src/main/java/wecui/event/listeners/WorldRenderListener.java +++ b/src/main/java/wecui/event/listeners/WorldRenderListener.java @@ -1,11 +1,12 @@ package wecui.event.listeners; -import wecui.fevents.Listener; -import wecui.WorldEditCUI; import net.minecraft.src.EntityClientPlayerMP; import org.lwjgl.opengl.GL11; + +import wecui.WorldEditCUI; import wecui.event.WorldRenderEvent; +import wecui.fevents.Listener; /** * Listener for WorldRenderEvent @@ -40,8 +41,8 @@ public void onEvent(WorldRenderEvent event) { -this.getPlayerYGuess(event.getPartialTick()), -this.getPlayerZGuess(event.getPartialTick())); GL11.glColor3f(1.0f, 1.0f, 1.0f); - if (controller.getSelection() != null) { - controller.getSelection().render(); + if (this.controller.getSelection() != null) { + this.controller.getSelection().render(); } } catch (Exception e) { } @@ -57,19 +58,19 @@ public void onEvent(WorldRenderEvent event) { private double getPlayerXGuess(float renderTick) { - EntityClientPlayerMP thePlayer = controller.getMinecraft().thePlayer; + EntityClientPlayerMP thePlayer = this.controller.getMinecraft().thePlayer; return thePlayer.prevPosX + ((thePlayer.posX - thePlayer.prevPosX) * renderTick); } private double getPlayerYGuess(float renderTick) { - EntityClientPlayerMP thePlayer = controller.getMinecraft().thePlayer; + EntityClientPlayerMP thePlayer = this.controller.getMinecraft().thePlayer; return thePlayer.prevPosY + ((thePlayer.posY - thePlayer.prevPosY) * renderTick); } private double getPlayerZGuess(float renderTick) { - EntityClientPlayerMP thePlayer = controller.getMinecraft().thePlayer; + EntityClientPlayerMP thePlayer = this.controller.getMinecraft().thePlayer; return thePlayer.prevPosZ + ((thePlayer.posZ - thePlayer.prevPosZ) * renderTick); } } diff --git a/src/main/java/wecui/fevents/Event.java b/src/main/java/wecui/fevents/Event.java index 6d9fec73..9e316f0b 100644 --- a/src/main/java/wecui/fevents/Event.java +++ b/src/main/java/wecui/fevents/Event.java @@ -46,7 +46,7 @@ public abstract class Event> { @Override public String toString() { - return getEventName() + " (" + this.getClass().getName() + ")"; + return this.getEventName() + " (" + this.getClass().getName() + ")"; } /** @@ -71,6 +71,6 @@ protected void setCancelled(boolean cancelled) { * Cancellable should never return true here */ public boolean isCancelled() { - return cancelled; + return this.cancelled; } } diff --git a/src/main/java/wecui/fevents/HandlerList.java b/src/main/java/wecui/fevents/HandlerList.java index c40cd455..9d7fc961 100644 --- a/src/main/java/wecui/fevents/HandlerList.java +++ b/src/main/java/wecui/fevents/HandlerList.java @@ -60,9 +60,9 @@ public static void bakeall() { * handlerlist is then added to meta-list for use in bakeall() */ public HandlerList() { - handlerslots = new EnumMap>>(Order.class); + this.handlerslots = new EnumMap>>(Order.class); for (Order o : Order.values()) { - handlerslots.put(o, new ArrayList>()); + this.handlerslots.put(o, new ArrayList>()); } alllists.add(this); } @@ -73,11 +73,11 @@ public HandlerList() { * @param order order location at which to call provided listener */ public void register(Listener listener, Order order) { - if (handlerslots.get(order).contains(listener)) { + if (this.handlerslots.get(order).contains(listener)) { throw new IllegalStateException("This listener is already registered to order " + order.toString()); } - baked = false; - handlerslots.get(order).add(listener); + this.baked = false; + this.handlerslots.get(order).add(listener); } /** @@ -86,7 +86,7 @@ public void register(Listener listener, Order order) { */ public void unregister(Listener listener) { for (Order o : Order.values()) { - unregister(listener, o); + this.unregister(listener, o); } } @@ -96,9 +96,9 @@ public void unregister(Listener listener) { * @param order order from which to remove listener */ public void unregister(Listener listener, Order order) { - if (handlerslots.get(order).contains(listener)) { - baked = false; - handlerslots.get(order).remove(listener); + if (this.handlerslots.get(order).contains(listener)) { + this.baked = false; + this.handlerslots.get(order).remove(listener); } } @@ -106,12 +106,12 @@ public void unregister(Listener listener, Order order) { * Bake HashMap and ArrayLists to 2d array - does nothing if not necessary */ void bake() { - if (baked) { + if (this.baked) { return; // don't re-bake when still valid } ArrayList>[]> handlerslist = new ArrayList>[]>(); ArrayList handleridslist = new ArrayList(); - for (Entry>> entry : handlerslots.entrySet()) { + for (Entry>> entry : this.handlerslots.entrySet()) { Order orderslot = entry.getKey(); ArrayList> list = entry.getValue(); @@ -120,11 +120,11 @@ void bake() { handlerslist.add(list.toArray(new Listener[list.size()])); handleridslist.add(ord); } - handlers = handlerslist.toArray(new Listener[handlerslist.size()][]); - handlerids = new int[handleridslist.size()]; + this.handlers = handlerslist.toArray(new Listener[handlerslist.size()][]); + this.handlerids = new int[handleridslist.size()]; for (int i = 0; i < handleridslist.size(); i++) { - handlerids[i] = handleridslist.get(i); + this.handlerids[i] = handleridslist.get(i); } - baked = true; + this.baked = true; } } diff --git a/src/main/java/wecui/fevents/Order.java b/src/main/java/wecui/fevents/Order.java index cea718f6..df703f68 100644 --- a/src/main/java/wecui/fevents/Order.java +++ b/src/main/java/wecui/fevents/Order.java @@ -72,6 +72,6 @@ public enum Order { * @return the index */ public int getIndex() { - return index; + return this.index; } } \ No newline at end of file diff --git a/src/main/java/wecui/obfuscation/DataPacketList.java b/src/main/java/wecui/obfuscation/DataPacketList.java index dadd4801..03432d3b 100644 --- a/src/main/java/wecui/obfuscation/DataPacketList.java +++ b/src/main/java/wecui/obfuscation/DataPacketList.java @@ -7,9 +7,9 @@ import net.minecraft.src.EntityClientPlayerMP; import net.minecraft.src.INetworkManager; import net.minecraft.src.NetClientHandler; -import net.minecraft.src.TcpConnection; import net.minecraft.src.Packet; import net.minecraft.src.Packet3Chat; +import net.minecraft.src.TcpConnection; import wecui.WorldEditCUI; import wecui.event.ChatCommandEvent; import wecui.event.OutgoingChatEvent; @@ -49,11 +49,11 @@ public boolean add(T packet) { boolean cancelled = false; String s = ((Packet3Chat)packet).message; // Obfuscation.getChatFromPacket((Packet3Chat) packet); - OutgoingChatEvent chatevent = new OutgoingChatEvent(controller, s); - controller.getEventManager().callEvent(chatevent); + OutgoingChatEvent chatevent = new OutgoingChatEvent(this.controller, s); + this.controller.getEventManager().callEvent(chatevent); if (!chatevent.isCancelled() && s.startsWith("/") && s.length() > 1) { - ChatCommandEvent commandevent = new ChatCommandEvent(controller, s); - controller.getEventManager().callEvent(commandevent); + ChatCommandEvent commandevent = new ChatCommandEvent(this.controller, s); + this.controller.getEventManager().callEvent(commandevent); if (commandevent.isHandled() || commandevent.isCancelled()) { cancelled = true; } diff --git a/src/main/java/wecui/obfuscation/FieldObfuscation.java b/src/main/java/wecui/obfuscation/FieldObfuscation.java index 29fc5265..5bf2781c 100644 --- a/src/main/java/wecui/obfuscation/FieldObfuscation.java +++ b/src/main/java/wecui/obfuscation/FieldObfuscation.java @@ -10,7 +10,7 @@ * @author yetanotherx * @author Mumfrey * - * @obfuscated 1.5.1 + * @obfuscated 1.5.2 */ public enum FieldObfuscation { @@ -33,7 +33,7 @@ private FieldObfuscation(String variable, String seargeVariable) { } public String getVariable() { - return ModUtilities.getObfuscatedFieldName(this.toString(), variable, seargeVariable); + return ModUtilities.getObfuscatedFieldName(this.toString(), this.variable, this.seargeVariable); } public static String getVariable(FieldObfuscation type) { diff --git a/src/main/java/wecui/render/LineColor.java b/src/main/java/wecui/render/LineColor.java index 410d84a6..2833b0f5 100644 --- a/src/main/java/wecui/render/LineColor.java +++ b/src/main/java/wecui/render/LineColor.java @@ -31,24 +31,24 @@ public enum LineColor { protected LineInfo hidden; private LineColor(float r, float g, float b) { - normal = new LineInfo(3.0f, r, g, b, 0.8f, GL11.GL_LESS); - hidden = new LineInfo(3.0f, r, g, b, 0.2f, GL11.GL_GEQUAL); + this.normal = new LineInfo(3.0f, r, g, b, 0.8f, GL11.GL_LESS); + this.hidden = new LineInfo(3.0f, r, g, b, 0.2f, GL11.GL_GEQUAL); } private LineColor(String hex) { - setColor(hex); + this.setColor(hex); } public LineInfo getHidden() { - return hidden; + return this.hidden; } public LineInfo getNormal() { - return normal; + return this.normal; } public LineInfo[] getColors() { - return new LineInfo[]{hidden, normal}; + return new LineInfo[]{this.hidden, this.normal}; } /** @@ -64,7 +64,7 @@ public void setColor(String hex) { float gF = g.floatValue() / 256.0F; float bF = b.floatValue() / 256.0F; - normal = new LineInfo(3.0f, rF, gF, bF, 0.8f, GL11.GL_LESS); - hidden = new LineInfo(3.0f, rF, gF, bF, 0.2f, GL11.GL_GEQUAL); + this.normal = new LineInfo(3.0f, rF, gF, bF, 0.8f, GL11.GL_LESS); + this.hidden = new LineInfo(3.0f, rF, gF, bF, 0.2f, GL11.GL_GEQUAL); } } diff --git a/src/main/java/wecui/render/LineInfo.java b/src/main/java/wecui/render/LineInfo.java index 862a4b6a..5a0dd509 100644 --- a/src/main/java/wecui/render/LineInfo.java +++ b/src/main/java/wecui/render/LineInfo.java @@ -44,11 +44,11 @@ public LineInfo(LineInfo orig) { * Sets the lineWidth and depthFunction based on this color */ public void prepareRender() { - GL11.glLineWidth(lineWidth); - GL11.glDepthFunc(depthfunc); + GL11.glLineWidth(this.lineWidth); + GL11.glDepthFunc(this.depthfunc); } public void prepareColor() { - GL11.glColor4f(red, green, blue, alpha); + GL11.glColor4f(this.red, this.green, this.blue, this.alpha); } } diff --git a/src/main/java/wecui/render/points/PointCube.java b/src/main/java/wecui/render/points/PointCube.java index a4e782a1..e0752796 100644 --- a/src/main/java/wecui/render/points/PointCube.java +++ b/src/main/java/wecui/render/points/PointCube.java @@ -35,11 +35,11 @@ public void render() { Vector3 minVec = new Vector3(off, off, off); Vector3 maxVec = new Vector3(off + 1, off + 1, off + 1); - new Render3DBox(color, point.subtract(minVec), point.add(maxVec)).render(); + new Render3DBox(this.color, this.point.subtract(minVec), this.point.add(maxVec)).render(); } public Vector3 getPoint() { - return point; + return this.point; } public void setPoint(Vector3 point) { @@ -47,7 +47,7 @@ public void setPoint(Vector3 point) { } public LineColor getColor() { - return color; + return this.color; } public void setColor(LineColor color) { diff --git a/src/main/java/wecui/render/points/PointRectangle.java b/src/main/java/wecui/render/points/PointRectangle.java index fe192ff2..fe8c5661 100644 --- a/src/main/java/wecui/render/points/PointRectangle.java +++ b/src/main/java/wecui/render/points/PointRectangle.java @@ -31,11 +31,11 @@ public void render(int min, int max) { Vector2 minVec = new Vector2(off, off); Vector2 maxVec = new Vector2(off + 1, off + 1); - new Render3DBox(color, point.subtract(minVec).toVector3(min - off), point.add(maxVec).toVector3(max + 1 + off)).render(); + new Render3DBox(this.color, this.point.subtract(minVec).toVector3(min - off), this.point.add(maxVec).toVector3(max + 1 + off)).render(); } public Vector2 getPoint() { - return point; + return this.point; } public void setPoint(Vector2 point) { @@ -43,7 +43,7 @@ public void setPoint(Vector2 point) { } public LineColor getColor() { - return color; + return this.color; } public void setColor(LineColor color) { diff --git a/src/main/java/wecui/render/region/CuboidRegion.java b/src/main/java/wecui/render/region/CuboidRegion.java index f673d928..8217c88d 100644 --- a/src/main/java/wecui/render/region/CuboidRegion.java +++ b/src/main/java/wecui/render/region/CuboidRegion.java @@ -2,8 +2,8 @@ import wecui.WorldEditCUI; import wecui.render.LineColor; -import wecui.render.shapes.Render3DBox; import wecui.render.points.PointCube; +import wecui.render.shapes.Render3DBox; import wecui.render.shapes.Render3DGrid; import wecui.util.Vector3; import wecui.util.Vector3m; @@ -25,29 +25,29 @@ public CuboidRegion(WorldEditCUI controller) { @Override public void render() { - if (firstPoint != null && secondPoint != null) { - firstPoint.render(); - secondPoint.render(); + if (this.firstPoint != null && this.secondPoint != null) { + this.firstPoint.render(); + this.secondPoint.render(); Vector3[] bounds = this.calcBounds(); new Render3DBox(LineColor.CUBOIDBOX, bounds[0], bounds[1]).render(); new Render3DGrid(LineColor.CUBOIDGRID, bounds[0], bounds[1]).render(); - } else if (firstPoint != null) { - firstPoint.render(); - } else if (secondPoint != null) { - secondPoint.render(); + } else if (this.firstPoint != null) { + this.firstPoint.render(); + } else if (this.secondPoint != null) { + this.secondPoint.render(); } } @Override public void setCuboidPoint(int id, int x, int y, int z) { if (id == 0) { - firstPoint = new PointCube(x, y, z); - firstPoint.setColor(LineColor.CUBOIDPOINT1); + this.firstPoint = new PointCube(x, y, z); + this.firstPoint.setColor(LineColor.CUBOIDPOINT1); } else if (id == 1) { - secondPoint = new PointCube(x, y, z); - secondPoint.setColor(LineColor.CUBOIDPOINT2); + this.secondPoint = new PointCube(x, y, z); + this.secondPoint.setColor(LineColor.CUBOIDPOINT2); } } @@ -64,7 +64,7 @@ protected Vector3m[] calcBounds() { out[0] = new Vector3m(Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE); out[1] = new Vector3m(-Double.MAX_VALUE, -Double.MAX_VALUE, -Double.MAX_VALUE); - for (PointCube point : new PointCube[]{firstPoint, secondPoint}) { + for (PointCube point : new PointCube[]{this.firstPoint, this.secondPoint}) { if (point.getPoint().getX() + off1 > out[1].getX()) { out[1].setX(point.getPoint().getX() + off1); } diff --git a/src/main/java/wecui/render/region/CylinderRegion.java b/src/main/java/wecui/render/region/CylinderRegion.java index 226e4bd0..cb5d11c8 100644 --- a/src/main/java/wecui/render/region/CylinderRegion.java +++ b/src/main/java/wecui/render/region/CylinderRegion.java @@ -26,28 +26,28 @@ public CylinderRegion(WorldEditCUI controller) { @Override public void render() { - if (center != null) { - center.render(); + if (this.center != null) { + this.center.render(); - int tMin = minY; - int tMax = maxY; + int tMin = this.minY; + int tMax = this.maxY; - if (minY == 0 || maxY == 0) { - tMin = (int) center.getPoint().getY(); - tMax = (int) center.getPoint().getY(); + if (this.minY == 0 || this.maxY == 0) { + tMin = (int) this.center.getPoint().getY(); + tMax = (int) this.center.getPoint().getY(); } - new RenderCylinderCircles(LineColor.CYLINDERGRID, center, radX, radZ, tMin, tMax).render(); - new RenderCylinderGrid(LineColor.CYLINDERGRID, center, radX, radZ, tMin, tMax).render(); - new RenderCylinderBox(LineColor.CYLINDERBOX, center, radX, radZ, tMin, tMax).render(); + new RenderCylinderCircles(LineColor.CYLINDERGRID, this.center, this.radX, this.radZ, tMin, tMax).render(); + new RenderCylinderGrid(LineColor.CYLINDERGRID, this.center, this.radX, this.radZ, tMin, tMax).render(); + new RenderCylinderBox(LineColor.CYLINDERBOX, this.center, this.radX, this.radZ, tMin, tMax).render(); } } @Override public void setCylinderCenter(int x, int y, int z) { - center = new PointCube(x, y, z); - center.setColor(LineColor.CYLINDERCENTER); + this.center = new PointCube(x, y, z); + this.center.setColor(LineColor.CYLINDERCENTER); } @Override @@ -58,8 +58,8 @@ public void setCylinderRadius(double x, double z) { @Override public void setMinMax(int min, int max) { - minY = min; - maxY = max; + this.minY = min; + this.maxY = max; } @Override diff --git a/src/main/java/wecui/render/region/EllipsoidRegion.java b/src/main/java/wecui/render/region/EllipsoidRegion.java index 6ad99aa7..45c14c32 100644 --- a/src/main/java/wecui/render/region/EllipsoidRegion.java +++ b/src/main/java/wecui/render/region/EllipsoidRegion.java @@ -2,8 +2,8 @@ import wecui.WorldEditCUI; import wecui.render.LineColor; -import wecui.render.shapes.RenderEllipsoid; import wecui.render.points.PointCube; +import wecui.render.shapes.RenderEllipsoid; import wecui.util.Vector3; /** @@ -23,26 +23,26 @@ public EllipsoidRegion(WorldEditCUI controller) { @Override public void render() { - if( center != null && radii != null ) { - center.render(); + if( this.center != null && this.radii != null ) { + this.center.render(); - new RenderEllipsoid(LineColor.ELLIPSOIDGRID, center, radii).render(); + new RenderEllipsoid(LineColor.ELLIPSOIDGRID, this.center, this.radii).render(); } - else if( center != null ) { - center.render(); + else if( this.center != null ) { + this.center.render(); } } @Override public void setEllipsoidCenter(int x, int y, int z) { - center = new PointCube(x, y, z); - center.setColor(LineColor.ELLIPSOIDCENTER); + this.center = new PointCube(x, y, z); + this.center.setColor(LineColor.ELLIPSOIDCENTER); } @Override public void setEllipsoidRadii(double x, double y, double z) { - radii = new Vector3(x, y, z); + this.radii = new Vector3(x, y, z); } @Override diff --git a/src/main/java/wecui/render/region/PolygonRegion.java b/src/main/java/wecui/render/region/PolygonRegion.java index 269e07cb..ddc8d637 100644 --- a/src/main/java/wecui/render/region/PolygonRegion.java +++ b/src/main/java/wecui/render/region/PolygonRegion.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.List; + import wecui.WorldEditCUI; import wecui.render.LineColor; import wecui.render.points.PointRectangle; @@ -26,16 +27,16 @@ public PolygonRegion(WorldEditCUI controller) { @Override public void render() { - if (points == null) { + if (this.points == null) { return; } - for (PointRectangle point : points) { - point.render(min, max); + for (PointRectangle point : this.points) { + point.render(this.min, this.max); } - new Render2DBox(LineColor.POLYBOX, points, min, max).render(); - new Render2DGrid(LineColor.POLYGRID, points, min, max).render(); + new Render2DBox(LineColor.POLYBOX, this.points, this.min, this.max).render(); + new Render2DGrid(LineColor.POLYGRID, this.points, this.min, this.max).render(); } @@ -50,13 +51,13 @@ public void setPolygonPoint(int id, int x, int z) { PointRectangle point = new PointRectangle(x, z); point.setColor(LineColor.POLYPOINT); - if (id < points.size()) { - points.set(id, point); + if (id < this.points.size()) { + this.points.set(id, point); } else { - for (int i = 0; i < id - points.size(); i++) { - points.add(null); + for (int i = 0; i < id - this.points.size(); i++) { + this.points.add(null); } - points.add(point); + this.points.add(point); } } diff --git a/src/main/java/wecui/render/shapes/Render2DBox.java b/src/main/java/wecui/render/shapes/Render2DBox.java index ffc76e56..fb8fc327 100644 --- a/src/main/java/wecui/render/shapes/Render2DBox.java +++ b/src/main/java/wecui/render/shapes/Render2DBox.java @@ -33,16 +33,16 @@ public Render2DBox(LineColor color, List points, int min, int ma public void render() { Tessellator tess = Tessellator.instance; double off = 0.03; - for (LineInfo tempColor : color.getColors()) { + for (LineInfo tempColor : this.color.getColors()) { tempColor.prepareRender(); tess.startDrawing(GL11.GL_LINES); tempColor.prepareColor(); - for (PointRectangle point : points) { + for (PointRectangle point : this.points) { if (point != null) { - tess.addVertex(point.getPoint().getX() + 0.5, min + off, point.getPoint().getY() + 0.5); - tess.addVertex(point.getPoint().getX() + 0.5, max + 1 + off, point.getPoint().getY() + 0.5); + tess.addVertex(point.getPoint().getX() + 0.5, this.min + off, point.getPoint().getY() + 0.5); + tess.addVertex(point.getPoint().getX() + 0.5, this.max + 1 + off, point.getPoint().getY() + 0.5); } } tess.draw(); diff --git a/src/main/java/wecui/render/shapes/Render2DGrid.java b/src/main/java/wecui/render/shapes/Render2DGrid.java index 97934012..f27caf71 100644 --- a/src/main/java/wecui/render/shapes/Render2DGrid.java +++ b/src/main/java/wecui/render/shapes/Render2DGrid.java @@ -32,19 +32,19 @@ public Render2DGrid(LineColor color, List points, int min, int m public void render() { double off = 0.03; - for (double height = min; height <= max + 1; height++) { - drawPoly(height + off); + for (double height = this.min; height <= this.max + 1; height++) { + this.drawPoly(height + off); } } protected void drawPoly(double height) { Tessellator tess = Tessellator.instance; - for (LineInfo tempColor : color.getColors()) { + for (LineInfo tempColor : this.color.getColors()) { tempColor.prepareRender(); tess.startDrawing(GL11.GL_LINE_LOOP); tempColor.prepareColor(); - for (PointRectangle point : points) { + for (PointRectangle point : this.points) { if (point != null) { tess.addVertex(point.getPoint().getX() + 0.5, height, point.getPoint().getY() + 0.5); } diff --git a/src/main/java/wecui/render/shapes/Render3DBox.java b/src/main/java/wecui/render/shapes/Render3DBox.java index f09468aa..7cbbe866 100644 --- a/src/main/java/wecui/render/shapes/Render3DBox.java +++ b/src/main/java/wecui/render/shapes/Render3DBox.java @@ -28,14 +28,14 @@ public Render3DBox(LineColor color, Vector3 first, Vector3 second) { public void render() { Tessellator tess = Tessellator.instance; - double x1 = first.getX(); - double y1 = first.getY(); - double z1 = first.getZ(); - double x2 = second.getX(); - double y2 = second.getY(); - double z2 = second.getZ(); - - for (LineInfo tempColor : color.getColors()) { + double x1 = this.first.getX(); + double y1 = this.first.getY(); + double z1 = this.first.getZ(); + double x2 = this.second.getX(); + double y2 = this.second.getY(); + double z2 = this.second.getZ(); + + for (LineInfo tempColor : this.color.getColors()) { tempColor.prepareRender(); // Draw bottom face diff --git a/src/main/java/wecui/render/shapes/Render3DGrid.java b/src/main/java/wecui/render/shapes/Render3DGrid.java index 855c3689..ea02d5d1 100644 --- a/src/main/java/wecui/render/shapes/Render3DGrid.java +++ b/src/main/java/wecui/render/shapes/Render3DGrid.java @@ -28,14 +28,14 @@ public Render3DGrid(LineColor color, Vector3 first, Vector3 second) { public void render() { Tessellator tess = Tessellator.instance; - double x1 = first.getX(); - double y1 = first.getY(); - double z1 = first.getZ(); - double x2 = second.getX(); - double y2 = second.getY(); - double z2 = second.getZ(); - - for (LineInfo tempColor : color.getColors()) { + double x1 = this.first.getX(); + double y1 = this.first.getY(); + double z1 = this.first.getZ(); + double x2 = this.second.getX(); + double y2 = this.second.getY(); + double z2 = this.second.getZ(); + + for (LineInfo tempColor : this.color.getColors()) { tempColor.prepareRender(); tess.startDrawing(GL11.GL_LINES); diff --git a/src/main/java/wecui/render/shapes/RenderCylinderBox.java b/src/main/java/wecui/render/shapes/RenderCylinderBox.java index 62ef8df4..92decc85 100644 --- a/src/main/java/wecui/render/shapes/RenderCylinderBox.java +++ b/src/main/java/wecui/render/shapes/RenderCylinderBox.java @@ -35,20 +35,20 @@ public RenderCylinderBox(LineColor color, PointCube center, double radX, double public void render() { Tessellator tess = Tessellator.instance; - for (LineInfo tempColor : color.getColors()) { + for (LineInfo tempColor : this.color.getColors()) { tempColor.prepareRender(); double twoPi = Math.PI * 2; - for (int yBlock : new int[]{minY, maxY + 1}) { + for (int yBlock : new int[]{this.minY, this.maxY + 1}) { tess.startDrawing(GL11.GL_LINE_LOOP); tempColor.prepareColor(); for (int i = 0; i <= 75; i++) { double tempTheta = i * twoPi / 75; - double tempX = radX * Math.cos(tempTheta); - double tempZ = radZ * Math.sin(tempTheta); + double tempX = this.radX * Math.cos(tempTheta); + double tempZ = this.radZ * Math.sin(tempTheta); - tess.addVertex(centerX + tempX, yBlock, centerZ + tempZ); + tess.addVertex(this.centerX + tempX, yBlock, this.centerZ + tempZ); } tess.draw(); } diff --git a/src/main/java/wecui/render/shapes/RenderCylinderCircles.java b/src/main/java/wecui/render/shapes/RenderCylinderCircles.java index e9963d8f..50e1d940 100644 --- a/src/main/java/wecui/render/shapes/RenderCylinderCircles.java +++ b/src/main/java/wecui/render/shapes/RenderCylinderCircles.java @@ -35,20 +35,20 @@ public RenderCylinderCircles(LineColor color, PointCube center, double radX, dou public void render() { Tessellator tess = Tessellator.instance; - for (LineInfo tempColor : color.getColors()) { + for (LineInfo tempColor : this.color.getColors()) { tempColor.prepareRender(); double twoPi = Math.PI * 2; - for (int yBlock = minY + 1; yBlock <= maxY; yBlock++) { + for (int yBlock = this.minY + 1; yBlock <= this.maxY; yBlock++) { tess.startDrawing(GL11.GL_LINE_LOOP); tempColor.prepareColor(); for (int i = 0; i <= 75; i++) { double tempTheta = i * twoPi / 75; - double tempX = radX * Math.cos(tempTheta); - double tempZ = radZ * Math.sin(tempTheta); + double tempX = this.radX * Math.cos(tempTheta); + double tempZ = this.radZ * Math.sin(tempTheta); - tess.addVertex(centerX + tempX, yBlock, centerZ + tempZ); + tess.addVertex(this.centerX + tempX, yBlock, this.centerZ + tempZ); } tess.draw(); } diff --git a/src/main/java/wecui/render/shapes/RenderCylinderGrid.java b/src/main/java/wecui/render/shapes/RenderCylinderGrid.java index b0051326..fd008d9a 100644 --- a/src/main/java/wecui/render/shapes/RenderCylinderGrid.java +++ b/src/main/java/wecui/render/shapes/RenderCylinderGrid.java @@ -35,38 +35,38 @@ public RenderCylinderGrid(LineColor color, PointCube center, double radX, double public void render() { Tessellator tess = Tessellator.instance; - for (LineInfo tempColor : color.getColors()) { + for (LineInfo tempColor : this.color.getColors()) { tempColor.prepareRender(); - int tmaxY = maxY + 1; - int tminY = minY; - int posRadiusX = (int) Math.ceil(radX); - int negRadiusX = (int) -Math.ceil(radX); - int posRadiusZ = (int) Math.ceil(radZ); - int negRadiusZ = (int) -Math.ceil(radZ); + int tmaxY = this.maxY + 1; + int tminY = this.minY; + int posRadiusX = (int) Math.ceil(this.radX); + int negRadiusX = (int) -Math.ceil(this.radX); + int posRadiusZ = (int) Math.ceil(this.radZ); + int negRadiusZ = (int) -Math.ceil(this.radZ); for (double tempX = negRadiusX; tempX <= posRadiusX; ++tempX) { - double tempZ = radZ * Math.cos(Math.asin(tempX / radX)); + double tempZ = this.radZ * Math.cos(Math.asin(tempX / this.radX)); tess.startDrawing(GL11.GL_LINE_LOOP); tempColor.prepareColor(); - tess.addVertex(centerX + tempX, tmaxY, centerZ + tempZ); - tess.addVertex(centerX + tempX, tmaxY, centerZ - tempZ); - tess.addVertex(centerX + tempX, tminY, centerZ - tempZ); - tess.addVertex(centerX + tempX, tminY, centerZ + tempZ); + tess.addVertex(this.centerX + tempX, tmaxY, this.centerZ + tempZ); + tess.addVertex(this.centerX + tempX, tmaxY, this.centerZ - tempZ); + tess.addVertex(this.centerX + tempX, tminY, this.centerZ - tempZ); + tess.addVertex(this.centerX + tempX, tminY, this.centerZ + tempZ); tess.draw(); } for (double tempZ = negRadiusZ; tempZ <= posRadiusZ; ++tempZ) { - double tempX = radX * Math.sin(Math.acos(tempZ / radZ)); + double tempX = this.radX * Math.sin(Math.acos(tempZ / this.radZ)); tess.startDrawing(GL11.GL_LINE_LOOP); tempColor.prepareColor(); - tess.addVertex(centerX + tempX, tmaxY, centerZ + tempZ); - tess.addVertex(centerX - tempX, tmaxY, centerZ + tempZ); - tess.addVertex(centerX - tempX, tminY, centerZ + tempZ); - tess.addVertex(centerX + tempX, tminY, centerZ + tempZ); + tess.addVertex(this.centerX + tempX, tmaxY, this.centerZ + tempZ); + tess.addVertex(this.centerX - tempX, tmaxY, this.centerZ + tempZ); + tess.addVertex(this.centerX - tempX, tminY, this.centerZ + tempZ); + tess.addVertex(this.centerX + tempX, tminY, this.centerZ + tempZ); tess.draw(); } diff --git a/src/main/java/wecui/render/shapes/RenderEllipsoid.java b/src/main/java/wecui/render/shapes/RenderEllipsoid.java index f3aee0ac..d16199b3 100644 --- a/src/main/java/wecui/render/shapes/RenderEllipsoid.java +++ b/src/main/java/wecui/render/shapes/RenderEllipsoid.java @@ -34,27 +34,27 @@ public RenderEllipsoid(LineColor color, PointCube center, Vector3 radii) { } public void render() { - for (LineInfo tempColor : color.getColors()) { + for (LineInfo tempColor : this.color.getColors()) { tempColor.prepareRender(); - drawXZPlane(tempColor); - drawYZPlane(tempColor); - drawXYPlane(tempColor); + this.drawXZPlane(tempColor); + this.drawYZPlane(tempColor); + this.drawXYPlane(tempColor); } } protected void drawXZPlane(LineInfo color) { Tessellator tess = Tessellator.instance; - int yRad = (int) Math.floor(radii.getY()); + int yRad = (int) Math.floor(this.radii.getY()); for (int yBlock = -yRad; yBlock < yRad; yBlock++) { tess.startDrawing(GL11.GL_LINE_LOOP); color.prepareColor(); for (int i = 0; i <= 40; i++) { double tempTheta = i * twoPi / 40; - double tempX = radii.getX() * Math.cos(tempTheta) * Math.cos(Math.asin(yBlock / radii.getY())); - double tempZ = radii.getZ() * Math.sin(tempTheta) * Math.cos(Math.asin(yBlock / radii.getY())); + double tempX = this.radii.getX() * Math.cos(tempTheta) * Math.cos(Math.asin(yBlock / this.radii.getY())); + double tempZ = this.radii.getZ() * Math.sin(tempTheta) * Math.cos(Math.asin(yBlock / this.radii.getY())); - tess.addVertex(centerX + tempX, centerY + yBlock, centerZ + tempZ); + tess.addVertex(this.centerX + tempX, this.centerY + yBlock, this.centerZ + tempZ); } tess.draw(); } @@ -64,27 +64,27 @@ protected void drawXZPlane(LineInfo color) { for (int i = 0; i <= 40; i++) { double tempTheta = i * twoPi / 40; - double tempX = radii.getX() * Math.cos(tempTheta); - double tempZ = radii.getZ() * Math.sin(tempTheta); + double tempX = this.radii.getX() * Math.cos(tempTheta); + double tempZ = this.radii.getZ() * Math.sin(tempTheta); - tess.addVertex(centerX + tempX, centerY, centerZ + tempZ); + tess.addVertex(this.centerX + tempX, this.centerY, this.centerZ + tempZ); } tess.draw(); } protected void drawYZPlane(LineInfo color) { Tessellator tess = Tessellator.instance; - int xRad = (int) Math.floor(radii.getX()); + int xRad = (int) Math.floor(this.radii.getX()); for (int xBlock = -xRad; xBlock < xRad; xBlock++) { tess.startDrawing(GL11.GL_LINE_LOOP); color.prepareColor(); for (int i = 0; i <= 40; i++) { double tempTheta = i * twoPi / 40; - double tempY = radii.getY() * Math.cos(tempTheta) * Math.sin(Math.acos(xBlock / radii.getX())); - double tempZ = radii.getZ() * Math.sin(tempTheta) * Math.sin(Math.acos(xBlock / radii.getX())); + double tempY = this.radii.getY() * Math.cos(tempTheta) * Math.sin(Math.acos(xBlock / this.radii.getX())); + double tempZ = this.radii.getZ() * Math.sin(tempTheta) * Math.sin(Math.acos(xBlock / this.radii.getX())); - tess.addVertex(centerX + xBlock, centerY + tempY, centerZ + tempZ); + tess.addVertex(this.centerX + xBlock, this.centerY + tempY, this.centerZ + tempZ); } tess.draw(); } @@ -94,27 +94,27 @@ protected void drawYZPlane(LineInfo color) { for (int i = 0; i <= 40; i++) { double tempTheta = i * twoPi / 40; - double tempY = radii.getY() * Math.cos(tempTheta); - double tempZ = radii.getZ() * Math.sin(tempTheta); + double tempY = this.radii.getY() * Math.cos(tempTheta); + double tempZ = this.radii.getZ() * Math.sin(tempTheta); - tess.addVertex(centerX, centerY + tempY, centerZ + tempZ); + tess.addVertex(this.centerX, this.centerY + tempY, this.centerZ + tempZ); } tess.draw(); } protected void drawXYPlane(LineInfo color) { Tessellator tess = Tessellator.instance; - int zRad = (int) Math.floor(radii.getZ()); + int zRad = (int) Math.floor(this.radii.getZ()); for (int zBlock = -zRad; zBlock < zRad; zBlock++) { tess.startDrawing(GL11.GL_LINE_LOOP); color.prepareColor(); for (int i = 0; i <= 40; i++) { double tempTheta = i * twoPi / 40; - double tempX = radii.getX() * Math.sin(tempTheta) * Math.sin(Math.acos(zBlock / radii.getZ())); - double tempY = radii.getY() * Math.cos(tempTheta) * Math.sin(Math.acos(zBlock / radii.getZ())); + double tempX = this.radii.getX() * Math.sin(tempTheta) * Math.sin(Math.acos(zBlock / this.radii.getZ())); + double tempY = this.radii.getY() * Math.cos(tempTheta) * Math.sin(Math.acos(zBlock / this.radii.getZ())); - tess.addVertex(centerX + tempX, centerY + tempY, centerZ + zBlock); + tess.addVertex(this.centerX + tempX, this.centerY + tempY, this.centerZ + zBlock); } tess.draw(); } @@ -124,10 +124,10 @@ protected void drawXYPlane(LineInfo color) { for (int i = 0; i <= 40; i++) { double tempTheta = i * twoPi / 40; - double tempX = radii.getX() * Math.cos(tempTheta); - double tempY = radii.getY() * Math.sin(tempTheta); + double tempX = this.radii.getX() * Math.cos(tempTheta); + double tempY = this.radii.getY() * Math.sin(tempTheta); - tess.addVertex(centerX + tempX, centerY + tempY, centerZ); + tess.addVertex(this.centerX + tempX, this.centerY + tempY, this.centerZ); } tess.draw(); } diff --git a/src/main/java/wecui/util/ChatColor.java b/src/main/java/wecui/util/ChatColor.java index a3e2797f..ef2c6b4c 100644 --- a/src/main/java/wecui/util/ChatColor.java +++ b/src/main/java/wecui/util/ChatColor.java @@ -87,12 +87,12 @@ private ChatColor(final int code) { * @return An integer value of this color code */ public int getCode() { - return code; + return this.code; } @Override public String toString() { - return String.format("\u00A7%x", code); + return String.format("\u00A7%x", this.code); } /** diff --git a/src/main/java/wecui/util/Vector2.java b/src/main/java/wecui/util/Vector2.java index d53888c7..362e3896 100644 --- a/src/main/java/wecui/util/Vector2.java +++ b/src/main/java/wecui/util/Vector2.java @@ -1,560 +1,560 @@ -package wecui.util; - -/** - * A 2-dimensional vector represented by float-precision x,y coordinates - * - * Note, this is the Immutable form of Vector2. All operations will construct a - * new Vector2. - */ -public class Vector2 implements Comparable { - - /** - * Represents the Zero vector (0,0) - */ - public final static Vector2 ZERO = new Vector2(0, 0); - /** - * Represents a unit vector in the X direction (1,0) - */ - public final static Vector2 UNIT_X = new Vector2(1, 0); - /** - * Represents a unit vector in the Y direction (0,1) - */ - public final static Vector2 UNIT_Y = new Vector2(0, 1); - /** - * Represents a unit vector (1,1) - */ - public static Vector2 ONE = new Vector2(1, 1); - protected float x, z; - - /** - * Construct and Initialized a Vector2 from the given x, y - * - * @param x the x coordinate - * @param y the y coordinate - */ - public Vector2(float x, float y) { - this.x = x; - this.z = y; - } - - /** - * Construct and Initialized a Vector2 from the given x, y - * - * @param x the x coordinate - * @param y the y coordinate - */ - public Vector2(Double x, Double y) { - this(x.floatValue(), y.floatValue()); - } - - /** - * Construct and Initialized a Vector2 to (0,0) - */ - public Vector2() { - this(0, 0); - } - - /** - * Construct and Initialized a Vector2 from an old Vector2 - * - * @param original - */ - public Vector2(Vector2 original) { - this(original.x, original.z); - } - - /** - * Gets the X coordiante - * - * @return The X coordinate - */ - public float getX() { - return x; - } - - /** - * Gets the Y coordiante - * - * @return The Y coordinate - */ - public float getY() { - return z; - } - - /** - * Adds this Vector2 to the value of the Vector2 argument - * - * @param that The Vector2 to add - * @return the new Vector2 - */ - public Vector2 add(Vector2 that) { - return Vector2.add(this, that); - } - - /** - * Subtracts this Vector2 to the value of the Vector2 argument - * - * @param that The Vector2 to subtract - * @return the new Vector2 - */ - public Vector2 subtract(Vector2 that) { - return Vector2.subtract(this, that); - } - - /** - * Scales this Vector2 by the value of the argument - * - * @param scale The amount to scale by - * @return A new Vector2 scaled by the amount. - */ - public Vector2 scale(float scale) { - return Vector2.scale(this, scale); - } - - /** - * Returns this Vector2 dot the Vector2 argument. Dot Product is defined as - * a.x*b.x + a.y*b.y - * - * @param that The Vector2 to dot with this. - * @return The dot product - */ - public float dot(Vector2 that) { - return Vector2.dot(this, that); - } - - /** - * Returns a Vector3 object with a y-value of 0. - * The x of this Vector2 becomes the x of the Vector3, - * the y of this Vector2 becomes the z of the Vector3. - * - * @return - */ - public Vector3 toVector3() { - return Vector2.toVector3(this); - } - - /** - * Returns a Vector3m object with a y-value of 0. - * The x of this Vector2 becomes the x of the Vector3m, - * the y of this Vector2 becomes the z of the Vector3m. - * - * @return - */ - public Vector3m toVector3m() { - return Vector2.toVector3m(this); - } - - /** - * Returns a Vector3 object with the given y value. - * The x of this Vector2 becomes the x of the Vector3, - * the y of this Vector2 becomes the z of the Vector3. - * - * @param y Y value to use in the new Vector3. - * @return - */ - public Vector3 toVector3(float y) { - return Vector2.toVector3(this, y); - } - - /** - * Returns a Vector3m object with the given y value. - * The x of this Vector2 becomes the x of the Vector3m, - * the y of this Vector2 becomes the z of the Vector3m. - * - * @param y Y value to use in the new Vector3m. - * @return - */ - public Vector3m toVector3m(float y) { - return Vector2.toVector3m(this, y); - } - - /** - * Returns the Cross Product of this Vector2 Note: Cross Product is - * undefined in 2d space. This returns the orthogonal vector to this vector - * - * @return The orthogonal vector to this vector. - */ - public Vector2 cross() { - return new Vector2(z, -x); - } - - /** - * Rounds the X and Y values of this Vector2 up to - * the nearest integer value. - * - * @return - */ - public Vector2 ceil() { - return new Vector2(Math.ceil(x), Math.ceil(z)); - } - - /** - * Rounds the X and Y values of this Vector2 down to - * the nearest integer value. - * - * @return - */ - public Vector2 floor() { - return new Vector2(Math.floor(x), Math.floor(z)); - } - - /** - * Rounds the X and Y values of this Vector2 to - * the nearest integer value. - * - * @return - */ - public Vector2 round() { - return new Vector2(Math.round(x), Math.round(z)); - } - - /** - * Sets the X and Y values of this Vector2 to their - * absolute value. - * - * @return - */ - public Vector2 abs() { - return new Vector2(Math.abs(x), Math.abs(z)); - } - - /** - * Gets the distance between this Vector2 and a given Vector2. - * - * @param a - * @return - */ - public double distance(Vector2 a) { - return Vector2.distance(a, this); - } - - /** - * Raises the X and Y values of this Vector2 to the given power. - * - * @param power - * @return - */ - public Vector2 pow(double power) { - return Vector2.pow(this, power); - } - - /** - * Calculates the length of this Vector2 squared. - * - * @return the squared length - */ - public float lengthSquared() { - return Vector2.lengthSquared(this); - } - - /** - * Calculates the length of this Vector2 Note: This makes use of the sqrt - * function, and is not cached. That could affect performance - * - * @return the length of this vector2 - */ - public float length() { - return Vector2.length(this); - } - - /** - * Returns this Vector2 where the length is equal to 1 - * - * @return This Vector2 with length 1 - */ - public Vector2 normalize() { - return Vector2.normalize(this); - } - - /** - * Returns this Vector2 in an array. Element 0 contains x Element 1 contains - * y - * - * @return The array containing this Vector2 - */ - public float[] toArray() { - return Vector2.toArray(this); - } - - /** - * Compares two Vector3s - */ - @Override - public int compareTo(Vector2 o) { - return Vector2.compareTo(this, o); - } - - /** - * Checks if two Vector2s are equal - */ - @Override - public boolean equals(Object o) { - return Vector2.equals(this, o); - } - - /** - * Returns the length of the provided Vector2 Note: This makes use of the - * sqrt function, and is not cached. This could affect performance. - * - * @param a The Vector2 to calculate the length of - * @return The length of the Vector2 - */ - public static float length(Vector2 a) { - return (float) Math.sqrt(lengthSquared(a)); - } - - /** - * Returns the length squared of the provided Vector2 - * - * @param a the Vector2 to calculate the length squared - * @return the length squared of the Vector2 - */ - public static float lengthSquared(Vector2 a) { - return Vector2.dot(a, a); - } - - /** - * Returns a Vector2 that is the unit form of the provided Vector2 - * - * @param a - * @return - */ - public static Vector2 normalize(Vector2 a) { - return Vector2.scale(a, (1.f / a.length())); - } - - /** - * Subtracts one Vector2 from the other Vector2 - * - * @param a - * @param b - * @return - */ - public static Vector2 subtract(Vector2 a, Vector2 b) { - return new Vector2(a.getX() - b.getX(), a.getY() - b.getY()); - } - - /** - * Adds one Vector2 to the other Vector2 - * - * @param a - * @param b - * @return - */ - public static Vector2 add(Vector2 a, Vector2 b) { - return new Vector2(a.getX() + b.getX(), a.getY() + b.getY()); - } - - /** - * Scales the Vector2 by the ammount - * - * @param a - * @param b - * @return - */ - public static Vector2 scale(Vector2 a, float b) { - return new Vector2(a.getX() * b, a.getY() * b); - } - - /** - * Calculates the Dot Product of two Vector2s Dot Product is defined as - * a.x*b.x + a.y*b.y - * - * @param a - * @param b - * @return - */ - public static float dot(Vector2 a, Vector2 b) { - return a.getX() * b.getX() + a.getY() * b.getY(); - } - - /** - * Returns a Vector3 object with a y-value of 0. - * The x of the Vector2 becomes the x of the Vector3, - * the y of the Vector2 becomes the z of the Vector3. - * - * @param o Vector2 to use as the x/z values - * @return - */ - public static Vector3 toVector3(Vector2 o) { - return new Vector3(o.x, 0, o.z); - } - - /** - * Returns a Vector3m object with a y-value of 0. - * The x of the Vector2 becomes the x of the Vector3m, - * the y of the Vector2 becomes the z of the Vector3m. - * - * @param o Vector2 to use as the x/z values - * @return - */ - public static Vector3m toVector3m(Vector2 o) { - return new Vector3m(o.x, 0, o.z); - } - - /** - * Returns a Vector3 object with the given y-value. - * The x of the Vector2 becomes the x of the Vector3, - * the y of the Vector2 becomes the z of the Vector3. - * - * @param o Vector2 to use as the x/z values - * @param y Y value of the new Vector3 - * @return - */ - public static Vector3 toVector3(Vector2 o, float y) { - return new Vector3(o.x, y, o.z); - } - - /** - * Returns a Vector3m object with the given y-value. - * The x of the Vector2 becomes the x of the Vector3m, - * the y of the Vector2 becomes the z of the Vector3m. - * - * @param o Vector2 to use as the x/z values - * @param y Y value of the new Vector3 - * @return - */ - public static Vector3m toVector3m(Vector2 o, float y) { - return new Vector3m(o.x, y, o.z); - } - - /** - * Rounds the X and Y values of the given Vector2 up to - * the nearest integer value. - * - * @param o Vector2 to use - * @return - */ - public static Vector2 ceil(Vector2 o) { - return new Vector2(Math.ceil(o.x), Math.ceil(o.z)); - } - - /** - * Rounds the X and Y values of the given Vector2 down to - * the nearest integer value. - * - * @param o Vector2 to use - * @return - */ - public static Vector2 floor(Vector2 o) { - return new Vector2(Math.floor(o.x), Math.floor(o.z)); - } - - /** - * Rounds the X and Y values of the given Vector2 to - * the nearest integer value. - * - * @param o Vector2 to use - * @return - */ - public static Vector2 round(Vector2 o) { - return new Vector2(Math.round(o.x), Math.round(o.z)); - } - - /** - * Sets the X and Y values of the given Vector2 to their - * absolute value. - * - * @param o Vector2 to use - * @return - */ - public static Vector2 abs(Vector2 o) { - return new Vector2(Math.abs(o.x), Math.abs(o.z)); - } - - /** - * Returns a Vector2 containing the smallest X and Y values. - * - * @param o1 - * @param o2 - * @return - */ - public static Vector2 min(Vector2 o1, Vector2 o2) { - return new Vector2(Math.min(o1.x, o2.x), Math.min(o1.z, o2.z)); - } - - /** - * Returns a Vector2 containing the largest X and Y values. - * - * @param o1 - * @param o2 - * @return - */ - public static Vector2 max(Vector2 o1, Vector2 o2) { - return new Vector2(Math.max(o1.x, o2.x), Math.max(o1.z, o2.z)); - } - - /** - * Returns a Vector2 with random X and Y values (between 0 and 1) - * - * @param o - * @return - */ - public static Vector2 rand() { - return new Vector2(Math.random(), Math.random()); - } - - /** - * Returns the provided Vector2 in an array. Element 0 contains x Element 1 - * contains y - * - * @return The array containing the Vector2 - */ - public static float[] toArray(Vector2 a) { - return new float[]{a.getX(), a.getY()}; - } - - /** - * Compares two Vector3s - */ - public static int compareTo(Vector2 a, Vector2 b) { - return (int) a.lengthSquared() - (int) b.lengthSquared(); - } - - /** - * Gets the distance between two Vector2. - * - * @param a - * @param b - * @return - */ - public static double distance(Vector2 a, Vector2 b) { - Vector2 tempVector = Vector2.pow(Vector2.subtract(a, b), 2); - return Math.sqrt(tempVector.x + tempVector.z); - } - - /** - * Raises the X and Y values of a Vector2 to the given power. - * - * @param o - * @param power - * @return - */ - public static Vector2 pow(Vector2 o, double power) { - return new Vector2(Math.pow(o.x, power), Math.pow(o.z, power)); - } - - /** - * Checks if two Vector2s are equal - */ - public static boolean equals(Object a, Object b) { - if (!(a instanceof Vector2) || !(b instanceof Vector2)) { - return false; - } - if (a == b) { - return true; - } - return compareTo((Vector2) a, (Vector2) b) == 0; - } - - @Override - public String toString() { - return "(" + x + ", " + z + ")"; - } - - @Override - public int hashCode() - { - return (int)(this.x % this.z); - } -} +package wecui.util; + +/** + * A 2-dimensional vector represented by float-precision x,y coordinates + * + * Note, this is the Immutable form of Vector2. All operations will construct a + * new Vector2. + */ +public class Vector2 implements Comparable { + + /** + * Represents the Zero vector (0,0) + */ + public final static Vector2 ZERO = new Vector2(0, 0); + /** + * Represents a unit vector in the X direction (1,0) + */ + public final static Vector2 UNIT_X = new Vector2(1, 0); + /** + * Represents a unit vector in the Y direction (0,1) + */ + public final static Vector2 UNIT_Y = new Vector2(0, 1); + /** + * Represents a unit vector (1,1) + */ + public static Vector2 ONE = new Vector2(1, 1); + protected float x, z; + + /** + * Construct and Initialized a Vector2 from the given x, y + * + * @param x the x coordinate + * @param y the y coordinate + */ + public Vector2(float x, float y) { + this.x = x; + this.z = y; + } + + /** + * Construct and Initialized a Vector2 from the given x, y + * + * @param x the x coordinate + * @param y the y coordinate + */ + public Vector2(Double x, Double y) { + this(x.floatValue(), y.floatValue()); + } + + /** + * Construct and Initialized a Vector2 to (0,0) + */ + public Vector2() { + this(0, 0); + } + + /** + * Construct and Initialized a Vector2 from an old Vector2 + * + * @param original + */ + public Vector2(Vector2 original) { + this(original.x, original.z); + } + + /** + * Gets the X coordiante + * + * @return The X coordinate + */ + public float getX() { + return this.x; + } + + /** + * Gets the Y coordiante + * + * @return The Y coordinate + */ + public float getY() { + return this.z; + } + + /** + * Adds this Vector2 to the value of the Vector2 argument + * + * @param that The Vector2 to add + * @return the new Vector2 + */ + public Vector2 add(Vector2 that) { + return Vector2.add(this, that); + } + + /** + * Subtracts this Vector2 to the value of the Vector2 argument + * + * @param that The Vector2 to subtract + * @return the new Vector2 + */ + public Vector2 subtract(Vector2 that) { + return Vector2.subtract(this, that); + } + + /** + * Scales this Vector2 by the value of the argument + * + * @param scale The amount to scale by + * @return A new Vector2 scaled by the amount. + */ + public Vector2 scale(float scale) { + return Vector2.scale(this, scale); + } + + /** + * Returns this Vector2 dot the Vector2 argument. Dot Product is defined as + * a.x*b.x + a.y*b.y + * + * @param that The Vector2 to dot with this. + * @return The dot product + */ + public float dot(Vector2 that) { + return Vector2.dot(this, that); + } + + /** + * Returns a Vector3 object with a y-value of 0. + * The x of this Vector2 becomes the x of the Vector3, + * the y of this Vector2 becomes the z of the Vector3. + * + * @return + */ + public Vector3 toVector3() { + return Vector2.toVector3(this); + } + + /** + * Returns a Vector3m object with a y-value of 0. + * The x of this Vector2 becomes the x of the Vector3m, + * the y of this Vector2 becomes the z of the Vector3m. + * + * @return + */ + public Vector3m toVector3m() { + return Vector2.toVector3m(this); + } + + /** + * Returns a Vector3 object with the given y value. + * The x of this Vector2 becomes the x of the Vector3, + * the y of this Vector2 becomes the z of the Vector3. + * + * @param y Y value to use in the new Vector3. + * @return + */ + public Vector3 toVector3(float y) { + return Vector2.toVector3(this, y); + } + + /** + * Returns a Vector3m object with the given y value. + * The x of this Vector2 becomes the x of the Vector3m, + * the y of this Vector2 becomes the z of the Vector3m. + * + * @param y Y value to use in the new Vector3m. + * @return + */ + public Vector3m toVector3m(float y) { + return Vector2.toVector3m(this, y); + } + + /** + * Returns the Cross Product of this Vector2 Note: Cross Product is + * undefined in 2d space. This returns the orthogonal vector to this vector + * + * @return The orthogonal vector to this vector. + */ + public Vector2 cross() { + return new Vector2(this.z, -this.x); + } + + /** + * Rounds the X and Y values of this Vector2 up to + * the nearest integer value. + * + * @return + */ + public Vector2 ceil() { + return new Vector2(Math.ceil(this.x), Math.ceil(this.z)); + } + + /** + * Rounds the X and Y values of this Vector2 down to + * the nearest integer value. + * + * @return + */ + public Vector2 floor() { + return new Vector2(Math.floor(this.x), Math.floor(this.z)); + } + + /** + * Rounds the X and Y values of this Vector2 to + * the nearest integer value. + * + * @return + */ + public Vector2 round() { + return new Vector2(Math.round(this.x), Math.round(this.z)); + } + + /** + * Sets the X and Y values of this Vector2 to their + * absolute value. + * + * @return + */ + public Vector2 abs() { + return new Vector2(Math.abs(this.x), Math.abs(this.z)); + } + + /** + * Gets the distance between this Vector2 and a given Vector2. + * + * @param a + * @return + */ + public double distance(Vector2 a) { + return Vector2.distance(a, this); + } + + /** + * Raises the X and Y values of this Vector2 to the given power. + * + * @param power + * @return + */ + public Vector2 pow(double power) { + return Vector2.pow(this, power); + } + + /** + * Calculates the length of this Vector2 squared. + * + * @return the squared length + */ + public float lengthSquared() { + return Vector2.lengthSquared(this); + } + + /** + * Calculates the length of this Vector2 Note: This makes use of the sqrt + * function, and is not cached. That could affect performance + * + * @return the length of this vector2 + */ + public float length() { + return Vector2.length(this); + } + + /** + * Returns this Vector2 where the length is equal to 1 + * + * @return This Vector2 with length 1 + */ + public Vector2 normalize() { + return Vector2.normalize(this); + } + + /** + * Returns this Vector2 in an array. Element 0 contains x Element 1 contains + * y + * + * @return The array containing this Vector2 + */ + public float[] toArray() { + return Vector2.toArray(this); + } + + /** + * Compares two Vector3s + */ + @Override + public int compareTo(Vector2 o) { + return Vector2.compareTo(this, o); + } + + /** + * Checks if two Vector2s are equal + */ + @Override + public boolean equals(Object o) { + return Vector2.equals(this, o); + } + + /** + * Returns the length of the provided Vector2 Note: This makes use of the + * sqrt function, and is not cached. This could affect performance. + * + * @param a The Vector2 to calculate the length of + * @return The length of the Vector2 + */ + public static float length(Vector2 a) { + return (float) Math.sqrt(lengthSquared(a)); + } + + /** + * Returns the length squared of the provided Vector2 + * + * @param a the Vector2 to calculate the length squared + * @return the length squared of the Vector2 + */ + public static float lengthSquared(Vector2 a) { + return Vector2.dot(a, a); + } + + /** + * Returns a Vector2 that is the unit form of the provided Vector2 + * + * @param a + * @return + */ + public static Vector2 normalize(Vector2 a) { + return Vector2.scale(a, (1.f / a.length())); + } + + /** + * Subtracts one Vector2 from the other Vector2 + * + * @param a + * @param b + * @return + */ + public static Vector2 subtract(Vector2 a, Vector2 b) { + return new Vector2(a.getX() - b.getX(), a.getY() - b.getY()); + } + + /** + * Adds one Vector2 to the other Vector2 + * + * @param a + * @param b + * @return + */ + public static Vector2 add(Vector2 a, Vector2 b) { + return new Vector2(a.getX() + b.getX(), a.getY() + b.getY()); + } + + /** + * Scales the Vector2 by the ammount + * + * @param a + * @param b + * @return + */ + public static Vector2 scale(Vector2 a, float b) { + return new Vector2(a.getX() * b, a.getY() * b); + } + + /** + * Calculates the Dot Product of two Vector2s Dot Product is defined as + * a.x*b.x + a.y*b.y + * + * @param a + * @param b + * @return + */ + public static float dot(Vector2 a, Vector2 b) { + return a.getX() * b.getX() + a.getY() * b.getY(); + } + + /** + * Returns a Vector3 object with a y-value of 0. + * The x of the Vector2 becomes the x of the Vector3, + * the y of the Vector2 becomes the z of the Vector3. + * + * @param o Vector2 to use as the x/z values + * @return + */ + public static Vector3 toVector3(Vector2 o) { + return new Vector3(o.x, 0, o.z); + } + + /** + * Returns a Vector3m object with a y-value of 0. + * The x of the Vector2 becomes the x of the Vector3m, + * the y of the Vector2 becomes the z of the Vector3m. + * + * @param o Vector2 to use as the x/z values + * @return + */ + public static Vector3m toVector3m(Vector2 o) { + return new Vector3m(o.x, 0, o.z); + } + + /** + * Returns a Vector3 object with the given y-value. + * The x of the Vector2 becomes the x of the Vector3, + * the y of the Vector2 becomes the z of the Vector3. + * + * @param o Vector2 to use as the x/z values + * @param y Y value of the new Vector3 + * @return + */ + public static Vector3 toVector3(Vector2 o, float y) { + return new Vector3(o.x, y, o.z); + } + + /** + * Returns a Vector3m object with the given y-value. + * The x of the Vector2 becomes the x of the Vector3m, + * the y of the Vector2 becomes the z of the Vector3m. + * + * @param o Vector2 to use as the x/z values + * @param y Y value of the new Vector3 + * @return + */ + public static Vector3m toVector3m(Vector2 o, float y) { + return new Vector3m(o.x, y, o.z); + } + + /** + * Rounds the X and Y values of the given Vector2 up to + * the nearest integer value. + * + * @param o Vector2 to use + * @return + */ + public static Vector2 ceil(Vector2 o) { + return new Vector2(Math.ceil(o.x), Math.ceil(o.z)); + } + + /** + * Rounds the X and Y values of the given Vector2 down to + * the nearest integer value. + * + * @param o Vector2 to use + * @return + */ + public static Vector2 floor(Vector2 o) { + return new Vector2(Math.floor(o.x), Math.floor(o.z)); + } + + /** + * Rounds the X and Y values of the given Vector2 to + * the nearest integer value. + * + * @param o Vector2 to use + * @return + */ + public static Vector2 round(Vector2 o) { + return new Vector2(Math.round(o.x), Math.round(o.z)); + } + + /** + * Sets the X and Y values of the given Vector2 to their + * absolute value. + * + * @param o Vector2 to use + * @return + */ + public static Vector2 abs(Vector2 o) { + return new Vector2(Math.abs(o.x), Math.abs(o.z)); + } + + /** + * Returns a Vector2 containing the smallest X and Y values. + * + * @param o1 + * @param o2 + * @return + */ + public static Vector2 min(Vector2 o1, Vector2 o2) { + return new Vector2(Math.min(o1.x, o2.x), Math.min(o1.z, o2.z)); + } + + /** + * Returns a Vector2 containing the largest X and Y values. + * + * @param o1 + * @param o2 + * @return + */ + public static Vector2 max(Vector2 o1, Vector2 o2) { + return new Vector2(Math.max(o1.x, o2.x), Math.max(o1.z, o2.z)); + } + + /** + * Returns a Vector2 with random X and Y values (between 0 and 1) + * + * @param o + * @return + */ + public static Vector2 rand() { + return new Vector2(Math.random(), Math.random()); + } + + /** + * Returns the provided Vector2 in an array. Element 0 contains x Element 1 + * contains y + * + * @return The array containing the Vector2 + */ + public static float[] toArray(Vector2 a) { + return new float[]{a.getX(), a.getY()}; + } + + /** + * Compares two Vector3s + */ + public static int compareTo(Vector2 a, Vector2 b) { + return (int) a.lengthSquared() - (int) b.lengthSquared(); + } + + /** + * Gets the distance between two Vector2. + * + * @param a + * @param b + * @return + */ + public static double distance(Vector2 a, Vector2 b) { + Vector2 tempVector = Vector2.pow(Vector2.subtract(a, b), 2); + return Math.sqrt(tempVector.x + tempVector.z); + } + + /** + * Raises the X and Y values of a Vector2 to the given power. + * + * @param o + * @param power + * @return + */ + public static Vector2 pow(Vector2 o, double power) { + return new Vector2(Math.pow(o.x, power), Math.pow(o.z, power)); + } + + /** + * Checks if two Vector2s are equal + */ + public static boolean equals(Object a, Object b) { + if (!(a instanceof Vector2) || !(b instanceof Vector2)) { + return false; + } + if (a == b) { + return true; + } + return compareTo((Vector2) a, (Vector2) b) == 0; + } + + @Override + public String toString() { + return "(" + this.x + ", " + this.z + ")"; + } + + @Override + public int hashCode() + { + return (int)(this.x % this.z); + } +} diff --git a/src/main/java/wecui/util/Vector2m.java b/src/main/java/wecui/util/Vector2m.java index 2d4c38c8..ee6505cc 100644 --- a/src/main/java/wecui/util/Vector2m.java +++ b/src/main/java/wecui/util/Vector2m.java @@ -1,130 +1,130 @@ -package wecui.util; - -/** - * A version of Vector2 that can be modified. - * - * @author yetanotherx - */ -public class Vector2m extends Vector2 { - - public Vector2m() { - } - - public Vector2m(Double x, Double y) { - super(x, y); - } - - public Vector2m(float x, float y) { - super(x, y); - } - - public Vector2m(Vector2 original) { - super(original); - } - - /** - * Sets the X coordinate - * - * @param x The x coordinate - */ - public void setX(float x) { - this.x = x; - } - - /** - * Sets the Y coordinate - * - * @param y The Y coordinate - */ - public void setY(float y) { - this.z = y; - } - - @Override - public Vector2 add(Vector2 that) { - x += that.x; - z += that.z; - return this; - } - - @Override - public Vector2 subtract(Vector2 that) { - x -= that.x; - z -= that.z; - return this; - } - - @Override - public Vector2 scale(float scale) { - x *= scale; - z *= scale; - return this; - } - - public Vector2 cross(Vector2 that) { - float tmp = z; - z = -x; - x = tmp; - return this; - } - - /** - * Rounds the X and Y values of this Vector2 up to - * the nearest integer value. - * - * @return - */ - @Override - public Vector2 ceil() { - x = (float) Math.ceil(x); - z = (float) Math.ceil(z); - return this; - } - - /** - * Rounds the X and Y values of this Vector2 down to - * the nearest integer value. - * - * @return - */ - @Override - public Vector2 floor() { - x = (float) Math.floor(x); - z = (float) Math.floor(z); - return this; - } - - /** - * Rounds the X and Y values of this Vector2 to - * the nearest integer value. - * - * @return - */ - @Override - public Vector2 round() { - x = Math.round(x); - z = Math.round(z); - return this; - } - - /** - * Sets the X and Y values of this Vector2 to their - * absolute value. - * - * @return - */ - @Override - public Vector2 abs() { - x = Math.abs(x); - z = Math.abs(z); - return this; - } - - @Override - public Vector2 normalize() { - float length = this.length(); - x *= 1 / length; - z *= 1 / length; - return this; - } -} +package wecui.util; + +/** + * A version of Vector2 that can be modified. + * + * @author yetanotherx + */ +public class Vector2m extends Vector2 { + + public Vector2m() { + } + + public Vector2m(Double x, Double y) { + super(x, y); + } + + public Vector2m(float x, float y) { + super(x, y); + } + + public Vector2m(Vector2 original) { + super(original); + } + + /** + * Sets the X coordinate + * + * @param x The x coordinate + */ + public void setX(float x) { + this.x = x; + } + + /** + * Sets the Y coordinate + * + * @param y The Y coordinate + */ + public void setY(float y) { + this.z = y; + } + + @Override + public Vector2 add(Vector2 that) { + this.x += that.x; + this.z += that.z; + return this; + } + + @Override + public Vector2 subtract(Vector2 that) { + this.x -= that.x; + this.z -= that.z; + return this; + } + + @Override + public Vector2 scale(float scale) { + this.x *= scale; + this.z *= scale; + return this; + } + + public Vector2 cross(Vector2 that) { + float tmp = this.z; + this.z = -this.x; + this.x = tmp; + return this; + } + + /** + * Rounds the X and Y values of this Vector2 up to + * the nearest integer value. + * + * @return + */ + @Override + public Vector2 ceil() { + this.x = (float) Math.ceil(this.x); + this.z = (float) Math.ceil(this.z); + return this; + } + + /** + * Rounds the X and Y values of this Vector2 down to + * the nearest integer value. + * + * @return + */ + @Override + public Vector2 floor() { + this.x = (float) Math.floor(this.x); + this.z = (float) Math.floor(this.z); + return this; + } + + /** + * Rounds the X and Y values of this Vector2 to + * the nearest integer value. + * + * @return + */ + @Override + public Vector2 round() { + this.x = Math.round(this.x); + this.z = Math.round(this.z); + return this; + } + + /** + * Sets the X and Y values of this Vector2 to their + * absolute value. + * + * @return + */ + @Override + public Vector2 abs() { + this.x = Math.abs(this.x); + this.z = Math.abs(this.z); + return this; + } + + @Override + public Vector2 normalize() { + float length = this.length(); + this.x *= 1 / length; + this.z *= 1 / length; + return this; + } +} diff --git a/src/main/java/wecui/util/Vector3.java b/src/main/java/wecui/util/Vector3.java index b5d30ade..cfa7ffe0 100644 --- a/src/main/java/wecui/util/Vector3.java +++ b/src/main/java/wecui/util/Vector3.java @@ -1,582 +1,582 @@ -package wecui.util; - -/** - * Represents a 3d vector. - */ -public class Vector3 implements Comparable { - - /** - * Vector with all elements set to 0. (0, 0, 0) - */ - public final static Vector3 ZERO = new Vector3(0, 0, 0); - /** - * Unit Vector in the X direction. (1, 0, 0) - */ - public final static Vector3 UNIT_X = new Vector3(1, 0, 0); - /** - * Unit Vector facing Forward. (1, 0, 0) - */ - public final static Vector3 Forward = UNIT_X; - /** - * Unit Vector in the Y direction. (0, 1, 0) - */ - public final static Vector3 UNIT_Y = new Vector3(0, 1, 0); - /** - * Unit Vector pointing Up. (0, 1, 0) - */ - public final static Vector3 Up = UNIT_Y; - /** - * Unit Vector in the Z direction. (0, 0, 1) - */ - public final static Vector3 UNIT_Z = new Vector3(0, 0, 1); - /** - * Unit Vector pointing Right. (0, 0, 1) - */ - public final static Vector3 Right = UNIT_Z; - /** - * Unit Vector with all elements set to 1. (1, 1, 1) - */ - public final static Vector3 ONE = new Vector3(1, 1, 1); - protected float x, y, z; - - /** - * Constructs a new Vector3 with the given x, y, z - * - * @param x - * @param y - * @param z - */ - public Vector3(float x, float y, float z) { - this.x = x; - this.y = y; - this.z = z; - } - - /** - * Constructs a new Vector3 with the given x, y, z - * - * @param x - * @param y - * @param z - */ - public Vector3(Double x, Double y, Double z) { - this(x.floatValue(), y.floatValue(), z.floatValue()); - } - - /** - * Constructs a new Vector3 with all elements set to 0 - */ - public Vector3() { - this(0, 0, 0); - } - - /** - * Constructs a new Vector3 that is a clone of the given vector3 - * - * @param clone - */ - public Vector3(Vector3 clone) { - this(clone.getX(), clone.getY(), clone.getZ()); - } - - /** - * Constructs a new Vector3 from the given Vector2 and z - * - * @param vector - * @param z - */ - public Vector3(Vector2 vector, float z) { - this(vector.getX(), vector.getY(), z); - } - - /** - * Constructs a new Vector3 from the given Vector2 and z set to 0 - * - * @param vector - */ - public Vector3(Vector2 vector) { - this(vector, 0); - } - - public float getX() { - return x; - } - - public float getY() { - return y; - } - - public float getZ() { - return z; - } - - /** - * Adds two vectors - * - * @param that - * @return - */ - public Vector3 add(Vector3 that) { - return Vector3.add(this, that); - } - - /** - * Subtracts two vectors - * - * @param that - * @return - */ - public Vector3 subtract(Vector3 that) { - return Vector3.subtract(this, that); - } - - /** - * Scales by the scalar value - * - * @param scale - * @return - */ - public Vector3 scale(float scale) { - return Vector3.scale(this, scale); - } - - /** - * Takes the dot product of two vectors - * - * @param that - * @return - */ - public float dot(Vector3 that) { - return Vector3.dot(this, that); - } - - /** - * Takes the cross product of two vectors - * - * @param that - * @return - */ - public Vector3 cross(Vector3 that) { - return Vector3.cross(this, that); - } - - /** - * Returns a Vector2 object using the X and Z values of - * this Vector3. The x of this Vector3 becomes the x - * of the Vector2, and the z of this Vector3 becomes the - * y of the Vector2. - * - * @return - */ - public Vector2 toVector2() { - return Vector3.toVector2(this); - } - - /** - * Returns a Vector2m object using the X and Z values of - * this Vector3. The x of this Vector3 becomes the x - * of the Vector2, and the z of this Vector3 becomes the - * y of the Vector2m. - * - * @return - */ - public Vector2m toVector2m() { - return Vector3.toVector2m(this); - } - - /** - * Rounds the X, Y, and Z values of this Vector3 up to - * the nearest integer value. - * - * @return - */ - public Vector3 ceil() { - return new Vector3(Math.ceil(x), Math.ceil(y), Math.ceil(z)); - } - - /** - * Rounds the X, Y, and Z values of this Vector3 down to - * the nearest integer value. - * - * @return - */ - public Vector3 floor() { - return new Vector3(Math.floor(x), Math.floor(y), Math.floor(z)); - } - - /** - * Rounds the X, Y, and Z values of this Vector3 to - * the nearest integer value. - * - * @return - */ - public Vector3 round() { - return new Vector3(Math.round(x), Math.round(y), Math.round(z)); - } - - /** - * Sets the X, Y, and Z values of this Vector3 to their - * absolute value. - * - * @return - */ - public Vector3 abs() { - return new Vector3(Math.abs(x), Math.abs(y), Math.abs(z)); - } - - /** - * Gets the distance between this Vector3 and a given Vector3. - * - * @param a - * @return - */ - public double distance(Vector3 a) { - return Vector3.distance(a, this); - } - - /** - * Raises the X, Y, and Z values of this Vector3 to the given power. - * - * @param power - * @return - */ - public Vector3 pow(double power) { - return Vector3.pow(this, power); - } - - /** - * returns the squared length of the vector - * - * @return - */ - public float lengthSquared() { - return Vector3.lengthSquared(this); - } - - /** - * returns the length of this vector. Note: makes use of Math.sqrt and is - * not cached. - * - * @return - */ - public float length() { - return Vector3.length(this); - } - - /** - * Returns a fast approximation of this vector's length. - * - * @return - */ - public float fastLength() { - return Vector3.fastLength(this); - } - - /** - * returns the vector with a length of 1 - * - * @return - */ - public Vector3 normalize() { - return Vector3.normalize(this); - } - - /** - * returns the vector as [x,y,z] - * - * @return - */ - public float[] toArray() { - return Vector3.toArray(this); - } - - /** - * Compares two Vector3s - */ - @Override - public int compareTo(Vector3 o) { - return Vector3.compareTo(this, o); - } - - /** - * Checks if two Vector3s are equal - */ - @Override - public boolean equals(Object o) { - return Vector3.equals(this, o); - } - - /** - * toString Override - */ - @Override - public String toString() { - return String.format("{ %f, %f, %f }", x, y, z); - } - - /** - * Returns the length of the given vector. - * - * Note: Makes use of Math.sqrt and - * is not cached, so can be slow - * - * Also known as norm. ||a|| - * - * @param a - * @return - */ - public static float length(Vector3 a) { - return (float) Math.sqrt(lengthSquared(a)); - } - - /** - * Returns an approximate length of the given vector. - * - * @param a - * @return - */ - public static float fastLength(Vector3 a) { - return (float) Math.sqrt(lengthSquared(a)); - } - - /** - * returns the length squared to the given vector - * - * @param a - * @return - */ - public static float lengthSquared(Vector3 a) { - return Vector3.dot(a, a); - } - - /** - * Returns a new vector that is the given vector but length 1 - * - * @param a - * @return - */ - public static Vector3 normalize(Vector3 a) { - return Vector3.scale(a, (1.f / a.length())); - } - - /** - * Creates a new vector that is A - B - * - * @param a - * @param b - * @return - */ - public static Vector3 subtract(Vector3 a, Vector3 b) { - return new Vector3(a.getX() - b.getX(), a.getY() - b.getY(), a.getZ() - b.getZ()); - } - - /** - * Creates a new Vector that is A + B - * - * @param a - * @param b - * @return - */ - public static Vector3 add(Vector3 a, Vector3 b) { - return new Vector3(a.getX() + b.getX(), a.getY() + b.getY(), a.getZ() + b.getZ()); - } - - /** - * Creates a new vector that is A multiplied by the uniform scalar B - * - * @param a - * @param b - * @return - */ - public static Vector3 scale(Vector3 a, float b) { - return new Vector3(a.getX() * b, a.getY() * b, a.getZ() * b); - } - - /** - * Returns the dot product of A and B - * - * @param a - * @param b - * @return - */ - public static float dot(Vector3 a, Vector3 b) { - return a.getX() * b.getX() + a.getY() * b.getY() + a.getZ() * b.getZ(); - } - - /** - * Creates a new Vector that is the A x B The Cross Product is the vector - * orthogonal to both A and B - * - * @param a - * @param b - * @return - */ - public static Vector3 cross(Vector3 a, Vector3 b) { - return new Vector3(a.getY() * b.getZ() - a.getZ() * b.getY(), a.getZ() * b.getX() - a.getX() * b.getZ(), a.getX() * b.getY() - a.getY() * b.getX()); - } - - /** - * Rounds the X, Y, and Z values of the given Vector3 up to - * the nearest integer value. - * - * @param o Vector3 to use - * @return - */ - public static Vector3 ceil(Vector3 o) { - return new Vector3(Math.ceil(o.x), Math.ceil(o.y), Math.ceil(o.z)); - } - - /** - * Rounds the X, Y, and Z values of the given Vector3 down to - * the nearest integer value. - * - * @param o Vector3 to use - * @return - */ - public static Vector3 floor(Vector3 o) { - return new Vector3(Math.floor(o.x), Math.floor(o.y), Math.floor(o.z)); - } - - /** - * Rounds the X, Y, and Z values of the given Vector3 to - * the nearest integer value. - * - * @param o Vector3 to use - * @return - */ - public static Vector3 round(Vector3 o) { - return new Vector3(Math.round(o.x), Math.round(o.y), Math.round(o.z)); - } - - /** - * Sets the X, Y, and Z values of the given Vector3 to their - * absolute value. - * - * @param o Vector3 to use - * @return - */ - public static Vector3 abs(Vector3 o) { - return new Vector3(Math.abs(o.x), Math.abs(o.y), Math.abs(o.z)); - } - - /** - * Returns a Vector3 containing the smallest X, Y, and Z values. - * - * @param o1 - * @param o2 - * @return - */ - public static Vector3 min(Vector3 o1, Vector3 o2) { - return new Vector3(Math.min(o1.x, o2.x), Math.min(o1.y, o2.y), Math.min(o1.z, o2.z)); - } - - /** - * Returns a Vector3 containing the largest X, Y, and Z values. - * - * @param o1 - * @param o2 - * @return - */ - public static Vector3 max(Vector3 o1, Vector3 o2) { - return new Vector3(Math.max(o1.x, o2.x), Math.max(o1.y, o2.y), Math.max(o1.z, o2.z)); - } - - /** - * Returns a Vector3 with random X, Y, and Z values (between 0 and 1) - * - * @return - */ - public static Vector3 rand() { - return new Vector3(Math.random(), Math.random(), Math.random()); - } - - /** - * Gets the distance between two Vector3. - * - * @param a - * @param b - * @return - */ - public static double distance(Vector3 a, Vector3 b) { - double xzDist = Vector2.distance(a.toVector2(), b.toVector2()); - return Math.sqrt(Math.pow(xzDist, 2) + Math.pow(Math.abs(Vector3.subtract(a, b).getY()), 2)); - } - - /** - * Raises the X, Y, and Z values of a Vector3 to the given power. - * - * @param o - * @param power - * @return - */ - public static Vector3 pow(Vector3 o, double power) { - return new Vector3(Math.pow(o.x, power), Math.pow(o.y, power), Math.pow(o.z, power)); - } - - /** - * Returns a Vector2 object using the X and Z values of - * the given Vector3. The x of the Vector3 becomes the x - * of the Vector2, and the z of this Vector3 becomes the - * y of the Vector2m. - * - * @param o Vector3 object to use - * @return - */ - public static Vector2 toVector2(Vector3 o) { - return new Vector2(o.x, o.z); - } - - /** - * Returns a Vector2m object using the X and Z values of - * the given Vector3. The x of the Vector3 becomes the x - * of the Vector2m, and the z of this Vector3 becomes the - * y of the Vector2m. - * - * @param o Vector3 object to use - * @return - */ - public static Vector2m toVector2m(Vector3 o) { - return new Vector2m(o.x, o.z); - } - - /** - * Returns a new float array that is {x, y, z} - * - * @param a - * @return - */ - public static float[] toArray(Vector3 a) { - return new float[]{a.getX(), a.getY(), a.getZ()}; - } - - /** - * Compares two Vector3s - */ - public static int compareTo(Vector3 a, Vector3 b) { - return (int) a.lengthSquared() - (int) b.lengthSquared(); - } - - /** - * Checks if two Vector3s are equal - */ - public static boolean equals(Object a, Object b) { - if (!(a instanceof Vector3) || !(b instanceof Vector3)) { - return false; - } - if (a == b) { - return true; - } - Vector3 x = (Vector3) a; - Vector3 y = (Vector3) b; - if (x.getX() == y.getX() && x.getY() == y.getY() && x.getZ() == y.getZ()) { - return true; - } - return false; - } - - @Override - public int hashCode() - { - return (int)(this.x * this.y % this.z); - } -} +package wecui.util; + +/** + * Represents a 3d vector. + */ +public class Vector3 implements Comparable { + + /** + * Vector with all elements set to 0. (0, 0, 0) + */ + public final static Vector3 ZERO = new Vector3(0, 0, 0); + /** + * Unit Vector in the X direction. (1, 0, 0) + */ + public final static Vector3 UNIT_X = new Vector3(1, 0, 0); + /** + * Unit Vector facing Forward. (1, 0, 0) + */ + public final static Vector3 Forward = UNIT_X; + /** + * Unit Vector in the Y direction. (0, 1, 0) + */ + public final static Vector3 UNIT_Y = new Vector3(0, 1, 0); + /** + * Unit Vector pointing Up. (0, 1, 0) + */ + public final static Vector3 Up = UNIT_Y; + /** + * Unit Vector in the Z direction. (0, 0, 1) + */ + public final static Vector3 UNIT_Z = new Vector3(0, 0, 1); + /** + * Unit Vector pointing Right. (0, 0, 1) + */ + public final static Vector3 Right = UNIT_Z; + /** + * Unit Vector with all elements set to 1. (1, 1, 1) + */ + public final static Vector3 ONE = new Vector3(1, 1, 1); + protected float x, y, z; + + /** + * Constructs a new Vector3 with the given x, y, z + * + * @param x + * @param y + * @param z + */ + public Vector3(float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + } + + /** + * Constructs a new Vector3 with the given x, y, z + * + * @param x + * @param y + * @param z + */ + public Vector3(Double x, Double y, Double z) { + this(x.floatValue(), y.floatValue(), z.floatValue()); + } + + /** + * Constructs a new Vector3 with all elements set to 0 + */ + public Vector3() { + this(0, 0, 0); + } + + /** + * Constructs a new Vector3 that is a clone of the given vector3 + * + * @param clone + */ + public Vector3(Vector3 clone) { + this(clone.getX(), clone.getY(), clone.getZ()); + } + + /** + * Constructs a new Vector3 from the given Vector2 and z + * + * @param vector + * @param z + */ + public Vector3(Vector2 vector, float z) { + this(vector.getX(), vector.getY(), z); + } + + /** + * Constructs a new Vector3 from the given Vector2 and z set to 0 + * + * @param vector + */ + public Vector3(Vector2 vector) { + this(vector, 0); + } + + public float getX() { + return this.x; + } + + public float getY() { + return this.y; + } + + public float getZ() { + return this.z; + } + + /** + * Adds two vectors + * + * @param that + * @return + */ + public Vector3 add(Vector3 that) { + return Vector3.add(this, that); + } + + /** + * Subtracts two vectors + * + * @param that + * @return + */ + public Vector3 subtract(Vector3 that) { + return Vector3.subtract(this, that); + } + + /** + * Scales by the scalar value + * + * @param scale + * @return + */ + public Vector3 scale(float scale) { + return Vector3.scale(this, scale); + } + + /** + * Takes the dot product of two vectors + * + * @param that + * @return + */ + public float dot(Vector3 that) { + return Vector3.dot(this, that); + } + + /** + * Takes the cross product of two vectors + * + * @param that + * @return + */ + public Vector3 cross(Vector3 that) { + return Vector3.cross(this, that); + } + + /** + * Returns a Vector2 object using the X and Z values of + * this Vector3. The x of this Vector3 becomes the x + * of the Vector2, and the z of this Vector3 becomes the + * y of the Vector2. + * + * @return + */ + public Vector2 toVector2() { + return Vector3.toVector2(this); + } + + /** + * Returns a Vector2m object using the X and Z values of + * this Vector3. The x of this Vector3 becomes the x + * of the Vector2, and the z of this Vector3 becomes the + * y of the Vector2m. + * + * @return + */ + public Vector2m toVector2m() { + return Vector3.toVector2m(this); + } + + /** + * Rounds the X, Y, and Z values of this Vector3 up to + * the nearest integer value. + * + * @return + */ + public Vector3 ceil() { + return new Vector3(Math.ceil(this.x), Math.ceil(this.y), Math.ceil(this.z)); + } + + /** + * Rounds the X, Y, and Z values of this Vector3 down to + * the nearest integer value. + * + * @return + */ + public Vector3 floor() { + return new Vector3(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z)); + } + + /** + * Rounds the X, Y, and Z values of this Vector3 to + * the nearest integer value. + * + * @return + */ + public Vector3 round() { + return new Vector3(Math.round(this.x), Math.round(this.y), Math.round(this.z)); + } + + /** + * Sets the X, Y, and Z values of this Vector3 to their + * absolute value. + * + * @return + */ + public Vector3 abs() { + return new Vector3(Math.abs(this.x), Math.abs(this.y), Math.abs(this.z)); + } + + /** + * Gets the distance between this Vector3 and a given Vector3. + * + * @param a + * @return + */ + public double distance(Vector3 a) { + return Vector3.distance(a, this); + } + + /** + * Raises the X, Y, and Z values of this Vector3 to the given power. + * + * @param power + * @return + */ + public Vector3 pow(double power) { + return Vector3.pow(this, power); + } + + /** + * returns the squared length of the vector + * + * @return + */ + public float lengthSquared() { + return Vector3.lengthSquared(this); + } + + /** + * returns the length of this vector. Note: makes use of Math.sqrt and is + * not cached. + * + * @return + */ + public float length() { + return Vector3.length(this); + } + + /** + * Returns a fast approximation of this vector's length. + * + * @return + */ + public float fastLength() { + return Vector3.fastLength(this); + } + + /** + * returns the vector with a length of 1 + * + * @return + */ + public Vector3 normalize() { + return Vector3.normalize(this); + } + + /** + * returns the vector as [x,y,z] + * + * @return + */ + public float[] toArray() { + return Vector3.toArray(this); + } + + /** + * Compares two Vector3s + */ + @Override + public int compareTo(Vector3 o) { + return Vector3.compareTo(this, o); + } + + /** + * Checks if two Vector3s are equal + */ + @Override + public boolean equals(Object o) { + return Vector3.equals(this, o); + } + + /** + * toString Override + */ + @Override + public String toString() { + return String.format("{ %f, %f, %f }", this.x, this.y, this.z); + } + + /** + * Returns the length of the given vector. + * + * Note: Makes use of Math.sqrt and + * is not cached, so can be slow + * + * Also known as norm. ||a|| + * + * @param a + * @return + */ + public static float length(Vector3 a) { + return (float) Math.sqrt(lengthSquared(a)); + } + + /** + * Returns an approximate length of the given vector. + * + * @param a + * @return + */ + public static float fastLength(Vector3 a) { + return (float) Math.sqrt(lengthSquared(a)); + } + + /** + * returns the length squared to the given vector + * + * @param a + * @return + */ + public static float lengthSquared(Vector3 a) { + return Vector3.dot(a, a); + } + + /** + * Returns a new vector that is the given vector but length 1 + * + * @param a + * @return + */ + public static Vector3 normalize(Vector3 a) { + return Vector3.scale(a, (1.f / a.length())); + } + + /** + * Creates a new vector that is A - B + * + * @param a + * @param b + * @return + */ + public static Vector3 subtract(Vector3 a, Vector3 b) { + return new Vector3(a.getX() - b.getX(), a.getY() - b.getY(), a.getZ() - b.getZ()); + } + + /** + * Creates a new Vector that is A + B + * + * @param a + * @param b + * @return + */ + public static Vector3 add(Vector3 a, Vector3 b) { + return new Vector3(a.getX() + b.getX(), a.getY() + b.getY(), a.getZ() + b.getZ()); + } + + /** + * Creates a new vector that is A multiplied by the uniform scalar B + * + * @param a + * @param b + * @return + */ + public static Vector3 scale(Vector3 a, float b) { + return new Vector3(a.getX() * b, a.getY() * b, a.getZ() * b); + } + + /** + * Returns the dot product of A and B + * + * @param a + * @param b + * @return + */ + public static float dot(Vector3 a, Vector3 b) { + return a.getX() * b.getX() + a.getY() * b.getY() + a.getZ() * b.getZ(); + } + + /** + * Creates a new Vector that is the A x B The Cross Product is the vector + * orthogonal to both A and B + * + * @param a + * @param b + * @return + */ + public static Vector3 cross(Vector3 a, Vector3 b) { + return new Vector3(a.getY() * b.getZ() - a.getZ() * b.getY(), a.getZ() * b.getX() - a.getX() * b.getZ(), a.getX() * b.getY() - a.getY() * b.getX()); + } + + /** + * Rounds the X, Y, and Z values of the given Vector3 up to + * the nearest integer value. + * + * @param o Vector3 to use + * @return + */ + public static Vector3 ceil(Vector3 o) { + return new Vector3(Math.ceil(o.x), Math.ceil(o.y), Math.ceil(o.z)); + } + + /** + * Rounds the X, Y, and Z values of the given Vector3 down to + * the nearest integer value. + * + * @param o Vector3 to use + * @return + */ + public static Vector3 floor(Vector3 o) { + return new Vector3(Math.floor(o.x), Math.floor(o.y), Math.floor(o.z)); + } + + /** + * Rounds the X, Y, and Z values of the given Vector3 to + * the nearest integer value. + * + * @param o Vector3 to use + * @return + */ + public static Vector3 round(Vector3 o) { + return new Vector3(Math.round(o.x), Math.round(o.y), Math.round(o.z)); + } + + /** + * Sets the X, Y, and Z values of the given Vector3 to their + * absolute value. + * + * @param o Vector3 to use + * @return + */ + public static Vector3 abs(Vector3 o) { + return new Vector3(Math.abs(o.x), Math.abs(o.y), Math.abs(o.z)); + } + + /** + * Returns a Vector3 containing the smallest X, Y, and Z values. + * + * @param o1 + * @param o2 + * @return + */ + public static Vector3 min(Vector3 o1, Vector3 o2) { + return new Vector3(Math.min(o1.x, o2.x), Math.min(o1.y, o2.y), Math.min(o1.z, o2.z)); + } + + /** + * Returns a Vector3 containing the largest X, Y, and Z values. + * + * @param o1 + * @param o2 + * @return + */ + public static Vector3 max(Vector3 o1, Vector3 o2) { + return new Vector3(Math.max(o1.x, o2.x), Math.max(o1.y, o2.y), Math.max(o1.z, o2.z)); + } + + /** + * Returns a Vector3 with random X, Y, and Z values (between 0 and 1) + * + * @return + */ + public static Vector3 rand() { + return new Vector3(Math.random(), Math.random(), Math.random()); + } + + /** + * Gets the distance between two Vector3. + * + * @param a + * @param b + * @return + */ + public static double distance(Vector3 a, Vector3 b) { + double xzDist = Vector2.distance(a.toVector2(), b.toVector2()); + return Math.sqrt(Math.pow(xzDist, 2) + Math.pow(Math.abs(Vector3.subtract(a, b).getY()), 2)); + } + + /** + * Raises the X, Y, and Z values of a Vector3 to the given power. + * + * @param o + * @param power + * @return + */ + public static Vector3 pow(Vector3 o, double power) { + return new Vector3(Math.pow(o.x, power), Math.pow(o.y, power), Math.pow(o.z, power)); + } + + /** + * Returns a Vector2 object using the X and Z values of + * the given Vector3. The x of the Vector3 becomes the x + * of the Vector2, and the z of this Vector3 becomes the + * y of the Vector2m. + * + * @param o Vector3 object to use + * @return + */ + public static Vector2 toVector2(Vector3 o) { + return new Vector2(o.x, o.z); + } + + /** + * Returns a Vector2m object using the X and Z values of + * the given Vector3. The x of the Vector3 becomes the x + * of the Vector2m, and the z of this Vector3 becomes the + * y of the Vector2m. + * + * @param o Vector3 object to use + * @return + */ + public static Vector2m toVector2m(Vector3 o) { + return new Vector2m(o.x, o.z); + } + + /** + * Returns a new float array that is {x, y, z} + * + * @param a + * @return + */ + public static float[] toArray(Vector3 a) { + return new float[]{a.getX(), a.getY(), a.getZ()}; + } + + /** + * Compares two Vector3s + */ + public static int compareTo(Vector3 a, Vector3 b) { + return (int) a.lengthSquared() - (int) b.lengthSquared(); + } + + /** + * Checks if two Vector3s are equal + */ + public static boolean equals(Object a, Object b) { + if (!(a instanceof Vector3) || !(b instanceof Vector3)) { + return false; + } + if (a == b) { + return true; + } + Vector3 x = (Vector3) a; + Vector3 y = (Vector3) b; + if (x.getX() == y.getX() && x.getY() == y.getY() && x.getZ() == y.getZ()) { + return true; + } + return false; + } + + @Override + public int hashCode() + { + return (int)(this.x * this.y % this.z); + } +} diff --git a/src/main/java/wecui/util/Vector3m.java b/src/main/java/wecui/util/Vector3m.java index 24fa0897..64ed8f69 100644 --- a/src/main/java/wecui/util/Vector3m.java +++ b/src/main/java/wecui/util/Vector3m.java @@ -1,168 +1,168 @@ -package wecui.util; - -/** - * A version of Vector3 that can be modified. - * - * @author yetanotherx - */ -public class Vector3m extends Vector3 { - - public Vector3m(float x, float y, float z) { - super(x, y, z); - } - - public Vector3m(Double x, Double y, Double z) { - super(x, y, z); - } - - public Vector3m(Vector3 vector) { - super(vector); - } - - public Vector3m() { - } - - public void setZ(float z) { - this.z = z; - } - - public void setY(float y) { - this.y = y; - } - - public void setX(float x) { - this.x = x; - } - - /** - * Adds two vectors - * - * @param that - * @return - */ - - @Override - public Vector3 add(Vector3 that) { - x += that.x; - y += that.y; - z += that.z; - return this; - } - - /** - * Subtracts two vectors - * - * @param that - * @return - */ - - @Override - public Vector3 subtract(Vector3 that) { - x -= that.x; - y -= that.y; - z -= that.z; - return this; - } - - /** - * Scales by the scalar value - * - * @param scale - * @return - */ - - @Override - public Vector3 scale(float scale) { - x *= scale; - y *= scale; - z *= scale; - return this; - } - - /** - * Takes the cross product of two vectors - * - * @param that - * @return - */ - - @Override - public Vector3 cross(Vector3 that) { - x = getY() * that.getZ() - getZ() * that.getY(); - y = getZ() * that.getX() - getX() * that.getZ(); - z = getX() * that.getY() - getY() * that.getX(); - - return this; - } - - /** - * Rounds the X, Y, and Z values of this Vector3 up to - * the nearest integer value. - * - * @return - */ - @Override - public Vector3 ceil() { - x = (float) Math.ceil(x); - y = (float) Math.ceil(y); - z = (float) Math.ceil(z); - return this; - } - - /** - * Rounds the X, Y, and Z values of this Vector3 down to - * the nearest integer value. - * - * @return - */ - @Override - public Vector3 floor() { - x = (float) Math.floor(x); - y = (float) Math.floor(y); - z = (float) Math.floor(z); - return this; - } - - /** - * Rounds the X, Y, and Z values of this Vector3 to - * the nearest integer value. - * - * @return - */ - @Override - public Vector3 round() { - x = Math.round(x); - y = Math.round(y); - z = Math.round(z); - return this; - } - - /** - * Sets the X, Y, and Z values of this Vector3 to their - * absolute value. - * - * @return - */ - @Override - public Vector3 abs() { - x = Math.abs(x); - y = Math.abs(y); - z = Math.abs(z); - return this; - } - - /** - * returns the vector with a length of 1 - * - * @return - */ - - @Override - public Vector3 normalize() { - float length = this.length(); - x *= 1 / length; - y *= 1 / length; - z *= 1 / length; - return this; - } -} +package wecui.util; + +/** + * A version of Vector3 that can be modified. + * + * @author yetanotherx + */ +public class Vector3m extends Vector3 { + + public Vector3m(float x, float y, float z) { + super(x, y, z); + } + + public Vector3m(Double x, Double y, Double z) { + super(x, y, z); + } + + public Vector3m(Vector3 vector) { + super(vector); + } + + public Vector3m() { + } + + public void setZ(float z) { + this.z = z; + } + + public void setY(float y) { + this.y = y; + } + + public void setX(float x) { + this.x = x; + } + + /** + * Adds two vectors + * + * @param that + * @return + */ + + @Override + public Vector3 add(Vector3 that) { + this.x += that.x; + this.y += that.y; + this.z += that.z; + return this; + } + + /** + * Subtracts two vectors + * + * @param that + * @return + */ + + @Override + public Vector3 subtract(Vector3 that) { + this.x -= that.x; + this.y -= that.y; + this.z -= that.z; + return this; + } + + /** + * Scales by the scalar value + * + * @param scale + * @return + */ + + @Override + public Vector3 scale(float scale) { + this.x *= scale; + this.y *= scale; + this.z *= scale; + return this; + } + + /** + * Takes the cross product of two vectors + * + * @param that + * @return + */ + + @Override + public Vector3 cross(Vector3 that) { + this.x = this.getY() * that.getZ() - this.getZ() * that.getY(); + this.y = this.getZ() * that.getX() - this.getX() * that.getZ(); + this.z = this.getX() * that.getY() - this.getY() * that.getX(); + + return this; + } + + /** + * Rounds the X, Y, and Z values of this Vector3 up to + * the nearest integer value. + * + * @return + */ + @Override + public Vector3 ceil() { + this.x = (float) Math.ceil(this.x); + this.y = (float) Math.ceil(this.y); + this.z = (float) Math.ceil(this.z); + return this; + } + + /** + * Rounds the X, Y, and Z values of this Vector3 down to + * the nearest integer value. + * + * @return + */ + @Override + public Vector3 floor() { + this.x = (float) Math.floor(this.x); + this.y = (float) Math.floor(this.y); + this.z = (float) Math.floor(this.z); + return this; + } + + /** + * Rounds the X, Y, and Z values of this Vector3 to + * the nearest integer value. + * + * @return + */ + @Override + public Vector3 round() { + this.x = Math.round(this.x); + this.y = Math.round(this.y); + this.z = Math.round(this.z); + return this; + } + + /** + * Sets the X, Y, and Z values of this Vector3 to their + * absolute value. + * + * @return + */ + @Override + public Vector3 abs() { + this.x = Math.abs(this.x); + this.y = Math.abs(this.y); + this.z = Math.abs(this.z); + return this; + } + + /** + * returns the vector with a length of 1 + * + * @return + */ + + @Override + public Vector3 normalize() { + float length = this.length(); + this.x *= 1 / length; + this.y *= 1 / length; + this.z *= 1 / length; + return this; + } +} diff --git a/src/main/java/wecui/vendor/org/joor/Reflect.java b/src/main/java/wecui/vendor/org/joor/Reflect.java index e53572ba..0d731c29 100644 --- a/src/main/java/wecui/vendor/org/joor/Reflect.java +++ b/src/main/java/wecui/vendor/org/joor/Reflect.java @@ -35,7 +35,6 @@ */ package wecui.vendor.org.joor; -import wecui.exception.ReflectException; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -43,6 +42,8 @@ import java.util.LinkedHashMap; import java.util.Map; +import wecui.exception.ReflectException; + /** * A wrapper for an {@link Object} or {@link Class} upon which reflective calls * can be made. @@ -147,7 +148,7 @@ private Reflect(Object object) { */ @SuppressWarnings("unchecked") public T get() { - return (T) object; + return (T) this.object; } /** @@ -165,11 +166,11 @@ public T get() { */ public Reflect set(String name, Object value) throws ReflectException { try { - Field field = type().getField(name); + Field field = this.type().getField(name); if (!field.isAccessible()) { field.setAccessible(true); } - field.set(object, unwrap(value)); + field.set(this.object, unwrap(value)); return this; } catch (Exception e) { throw new ReflectException(e); @@ -193,7 +194,7 @@ public Reflect set(String name, Object value) throws ReflectException { * @see #field(String) */ public Object get(String name) throws ReflectException { - return field(name).get(); + return this.field(name).get(); } /** @@ -210,11 +211,11 @@ public Object get(String name) throws ReflectException { */ public Reflect field(String name) throws ReflectException { try { - Field field = type().getField(name); + Field field = this.type().getField(name); if (!field.isAccessible()) { field.setAccessible(true); } - return on(field.get(object)); + return on(field.get(this.object)); } catch (Exception e) { throw new ReflectException(e); } @@ -238,10 +239,10 @@ public Reflect field(String name) throws ReflectException { public Map fields() { Map result = new LinkedHashMap(); - for (Field field : type().getFields()) { - if (!isClass ^ Modifier.isStatic(field.getModifiers())) { + for (Field field : this.type().getFields()) { + if (!this.isClass ^ Modifier.isStatic(field.getModifiers())) { String name = field.getName(); - result.put(name, field(name)); + result.put(name, this.field(name)); } } @@ -262,7 +263,7 @@ public Map fields() { * @see #call(String, Object...) */ public Reflect call(String name) throws ReflectException { - return call(name, new Object[0]); + return this.call(name, new Object[0]); } /** @@ -300,14 +301,14 @@ public Reflect call(String name, Object... args) throws ReflectException { // Try invoking the "canonical" method, i.e. the one with exact // matching argument types try { - Method method = type().getMethod(name, types); - return on(method, object, args); + Method method = this.type().getMethod(name, types); + return on(method, this.object, args); } // If there is no exact match, try to find one that has a "similar" // signature if primitive argument types are converted to their wrappers catch (NoSuchMethodException e) { - for (Method method : type().getMethods()) { - if (method.getName().equals(name) && match(method.getParameterTypes(), types)) { - return on(method, object, args); + for (Method method : this.type().getMethods()) { + if (method.getName().equals(name) && this.match(method.getParameterTypes(), types)) { + return on(method, this.object, args); } } @@ -326,7 +327,7 @@ public Reflect call(String name, Object... args) throws ReflectException { * @see #create(Object...) */ public Reflect create() throws ReflectException { - return create(new Object[0]); + return this.create(new Object[0]); } /** @@ -361,13 +362,13 @@ public Reflect create(Object... args) throws ReflectException { // Try invoking the "canonical" constructor, i.e. the one with exact // matching argument types try { - Constructor constructor = type().getConstructor(types); + Constructor constructor = this.type().getConstructor(types); return on(constructor, args); } // If there is no exact match, try to find one that has a "similar" // signature if primitive argument types are converted to their wrappers catch (NoSuchMethodException e) { - for (Constructor constructor : type().getConstructors()) { - if (match(constructor.getParameterTypes(), types)) { + for (Constructor constructor : this.type().getConstructors()) { + if (this.match(constructor.getParameterTypes(), types)) { return on(constructor, args); } } @@ -401,7 +402,7 @@ private boolean match(Class[] declaredTypes, Class[] actualTypes) { */ @Override public int hashCode() { - return object.hashCode(); + return this.object.hashCode(); } /** @@ -410,7 +411,7 @@ public int hashCode() { @Override public boolean equals(Object obj) { if (obj instanceof Reflect) { - return object.equals(((Reflect) obj).get()); + return this.object.equals(((Reflect) obj).get()); } return false; @@ -421,7 +422,7 @@ public boolean equals(Object obj) { */ @Override public String toString() { - return object.toString(); + return this.object.toString(); } // --------------------------------------------------------------------- @@ -502,10 +503,10 @@ private static Class forName(String name) throws ReflectException { * @see Object#getClass() */ private Class type() { - if (isClass) { - return (Class) object; + if (this.isClass) { + return (Class) this.object; } - return object.getClass(); + return this.object.getClass(); } /** From adb5d823039f4f7aeee30090957454441910c4ca Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Sat, 4 May 2013 15:50:49 +0100 Subject: [PATCH 03/51] Removed unwanted debug message --- src/main/java/wecui/Updater.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/wecui/Updater.java b/src/main/java/wecui/Updater.java index 1e8af4d9..224da04a 100644 --- a/src/main/java/wecui/Updater.java +++ b/src/main/java/wecui/Updater.java @@ -54,7 +54,6 @@ public void run() { for (String version : versions) { - System.out.println("Version: " + version); if (version.matches("^" + WorldEditCUI.MCVERSION + "=\\d+$")) { latestVersion = Integer.parseInt(version.substring(version.indexOf("=") + 1)); From 6905bd968077c9e1778b0ab840f11c325fcad54a Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Wed, 31 Jul 2013 00:46:29 +0100 Subject: [PATCH 04/51] WorldEditCUI for 1.6.2 - version bump onl --- build/build_wecui.xml | 6 +- src/main/java/wecui/LiteModWorldEditCUI.java | 15 ++- src/main/java/wecui/WorldEditCUI.java | 7 +- .../wecui/obfuscation/DataPacketList.java | 109 ------------------ .../wecui/obfuscation/FieldObfuscation.java | 42 ------- 5 files changed, 17 insertions(+), 162 deletions(-) delete mode 100644 src/main/java/wecui/obfuscation/DataPacketList.java delete mode 100644 src/main/java/wecui/obfuscation/FieldObfuscation.java diff --git a/build/build_wecui.xml b/build/build_wecui.xml index e21b944d..2ae27e79 100644 --- a/build/build_wecui.xml +++ b/build/build_wecui.xml @@ -4,9 +4,9 @@ - - - + + + diff --git a/src/main/java/wecui/LiteModWorldEditCUI.java b/src/main/java/wecui/LiteModWorldEditCUI.java index 193d0083..bd95dced 100644 --- a/src/main/java/wecui/LiteModWorldEditCUI.java +++ b/src/main/java/wecui/LiteModWorldEditCUI.java @@ -1,10 +1,11 @@ package wecui; +import java.io.File; import java.nio.charset.Charset; import java.util.Arrays; import java.util.List; -import net.minecraft.client.Minecraft; +import net.minecraft.src.Minecraft; import net.minecraft.src.EntityPlayerSP; import net.minecraft.src.NetHandler; import net.minecraft.src.OpenGlHelper; @@ -13,7 +14,6 @@ import net.minecraft.src.WorldClient; import wecui.event.ChannelEvent; import wecui.event.WorldRenderEvent; -import wecui.obfuscation.DataPacketList; import wecui.render.region.CuboidRegion; import com.mumfrey.liteloader.InitCompleteListener; @@ -32,7 +32,12 @@ public class LiteModWorldEditCUI implements InitCompleteListener, PluginChannelL protected WorldRenderEvent event; @Override - public void init() + public void init(File configPath) + { + } + + @Override + public void upgradeSettings(String version, File configPath, File oldConfigPath) { } @@ -82,7 +87,7 @@ public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clo new Updater(this.controller).start(); this.controller.setSelection(new CuboidRegion(this.controller)); - DataPacketList.register(this.controller); +// DataPacketList.register(this.controller); } } } @@ -97,7 +102,7 @@ public String getName() @Override public String getVersion() { - return "1.5.2_02_lite"; + return "1.6.2_00_lite"; } @Override diff --git a/src/main/java/wecui/WorldEditCUI.java b/src/main/java/wecui/WorldEditCUI.java index 3bfdcd78..e06f1550 100644 --- a/src/main/java/wecui/WorldEditCUI.java +++ b/src/main/java/wecui/WorldEditCUI.java @@ -2,7 +2,9 @@ import java.io.File; -import net.minecraft.client.Minecraft; +import com.mumfrey.liteloader.core.LiteLoader; + +import net.minecraft.src.Minecraft; import wecui.config.CUIConfiguration; import wecui.event.CUIEvent; import wecui.event.ChannelEvent; @@ -129,7 +131,6 @@ public static String getVersion() { public static File getWorldEditCUIDir() { - File modsFolder = new File(Minecraft.getMinecraftDir(), "mods"); - return new File(modsFolder, "WorldEditCUI"); + return new File(LiteLoader.getInstance().getModsFolder(), "WorldEditCUI"); } } diff --git a/src/main/java/wecui/obfuscation/DataPacketList.java b/src/main/java/wecui/obfuscation/DataPacketList.java deleted file mode 100644 index 03432d3b..00000000 --- a/src/main/java/wecui/obfuscation/DataPacketList.java +++ /dev/null @@ -1,109 +0,0 @@ -package wecui.obfuscation; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.src.EntityClientPlayerMP; -import net.minecraft.src.INetworkManager; -import net.minecraft.src.NetClientHandler; -import net.minecraft.src.Packet; -import net.minecraft.src.Packet3Chat; -import net.minecraft.src.TcpConnection; -import wecui.WorldEditCUI; -import wecui.event.ChatCommandEvent; -import wecui.event.OutgoingChatEvent; - -/** - * Overrides the dataPacket list in NetworkManager - * Uses reflection to replace the list with this. It overrides the add() - * method to check if it's a Packet3Chat event. - * - * @author yetanotherx - * - */ -public class DataPacketList extends ArrayList { - - private static final long serialVersionUID = 275687258277L; - protected WorldEditCUI controller; - protected Class typeClass; - public static boolean registered = false; - - public DataPacketList(WorldEditCUI controller, Class typeClass) { - this.controller = controller; - this.typeClass = typeClass; - } - - /** - * Overrides the packet addition class. If a Packet3Chat is added, there's an outgoing - * message and we need to parse it. If it's a command, send a command event. If it's - * cancelled, let's not add it at all. - * - * @param packet - * @return - */ - @Override - public boolean add(T packet) { - if (packet instanceof Packet3Chat) { - - boolean cancelled = false; - String s = ((Packet3Chat)packet).message; // Obfuscation.getChatFromPacket((Packet3Chat) packet); - - OutgoingChatEvent chatevent = new OutgoingChatEvent(this.controller, s); - this.controller.getEventManager().callEvent(chatevent); - if (!chatevent.isCancelled() && s.startsWith("/") && s.length() > 1) { - ChatCommandEvent commandevent = new ChatCommandEvent(this.controller, s); - this.controller.getEventManager().callEvent(commandevent); - if (commandevent.isHandled() || commandevent.isCancelled()) { - cancelled = true; - } - } - - if (!cancelled) { - return super.add(packet); - } - return true; - } - return super.add(packet); - } - - /** - * Attaches the new packet handler to the actual NetworkManager class - * - * @param controller - */ - public static void register(WorldEditCUI controller) { - - if (registered) { - return; - } - registered = true; - - DataPacketList list = new DataPacketList(controller, Packet.class); - - EntityClientPlayerMP player = controller.getMinecraft().thePlayer; - - try { - NetClientHandler nch = player.sendQueue; - INetworkManager nm = nch.getNetManager(); - - if (nm instanceof TcpConnection) - { - Field listField = TcpConnection.class.getDeclaredField(FieldObfuscation.dataPackets.getVariable()); - listField.setAccessible(true); - @SuppressWarnings("unchecked") - List oldPacketList = (List)listField.get(nm); - for (Object item : oldPacketList) { - list.add((Packet) item); - } - - listField.set(nm, list); - } - - } catch (Exception e) { - throw new RuntimeException("Error inserting outgoing chat handler - Certain parts of WorldEditCUI will not work!", e); - } - - controller.getDebugger().debug("Outgoing chat handler registered."); - } -} diff --git a/src/main/java/wecui/obfuscation/FieldObfuscation.java b/src/main/java/wecui/obfuscation/FieldObfuscation.java deleted file mode 100644 index 5bf2781c..00000000 --- a/src/main/java/wecui/obfuscation/FieldObfuscation.java +++ /dev/null @@ -1,42 +0,0 @@ -package wecui.obfuscation; - -import com.mumfrey.liteloader.util.ModUtilities; - -/** - * Method name obfuscation, used whenever we use reflection. - * This lets us keep reflected obfuscated methods in a central - * class to ease updating. - * - * @author yetanotherx - * @author Mumfrey - * - * @obfuscated 1.5.2 - */ -public enum FieldObfuscation { - - /** - * Packet stream list in NetworkManager.class - */ - dataPackets("q", "field_74487_p"), - /** - * ID->Class hashmap for packets in Packet.class - */ - packetIdToClassMap("l", "field_73294_l"); - - protected String variable; - - protected String seargeVariable; - - private FieldObfuscation(String variable, String seargeVariable) { - this.variable = variable; - this.seargeVariable = seargeVariable; - } - - public String getVariable() { - return ModUtilities.getObfuscatedFieldName(this.toString(), this.variable, this.seargeVariable); - } - - public static String getVariable(FieldObfuscation type) { - return ModUtilities.getObfuscatedFieldName(type.toString(), type.variable, type.seargeVariable); - } -} From 54a13a8c57448fefcd536573551498cc8e0359a6 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Tue, 3 Dec 2013 18:00:37 +0000 Subject: [PATCH 05/51] WorldEditCUI for 1.7.2 - preliminary Removed snakeyaml-based config in favour of gson --- .gitignore | 42 -- INSTALL.md | 43 -- README.md | 64 +-- UPGRADE.md | 14 - build/build_wecui.xml | 32 +- build/buildnumber.txt | 3 + build/litemod.template.json | 8 + deobf.xml | 60 -- minecraft.pom | 8 - obfuscation.txt | 49 -- pom.xml | 174 ------ src/main/assembly/package.xml | 38 -- src/main/java/wecui/CUIDebug.java | 4 +- src/main/java/wecui/LiteModWorldEditCUI.java | 33 +- src/main/java/wecui/Updater.java | 92 --- src/main/java/wecui/WorldEditCUI.java | 35 +- .../java/wecui/config/CUIConfiguration.java | 261 ++++----- src/main/java/wecui/config/Colour.java | 84 +++ src/main/java/wecui/config/Configuration.java | 190 ------ .../java/wecui/config/ConfigurationNode.java | 543 ------------------ .../wecui/config/EmptyNullRepresenter.java | 51 -- .../wecui/event/command/CommandEventBase.java | 37 -- .../wecui/event/command/CommandEventType.java | 45 -- .../event/command/VersionCommandEvent.java | 32 -- .../java/wecui/event/cui/CUIEventType.java | 3 +- .../java/wecui/event/cui/CUIPointEvent.java | 8 +- .../java/wecui/event/cui/CUIPolygonEvent.java | 34 ++ .../wecui/event/cui/CUISelectionEvent.java | 5 +- .../listeners/WorldEditCommandListener.java | 48 -- .../event/listeners/WorldRenderListener.java | 2 +- src/main/java/wecui/render/LineColor.java | 19 +- .../java/wecui/render/region/BaseRegion.java | 5 +- .../wecui/render/region/CuboidRegion.java | 2 +- .../wecui/render/region/PolyhedronRegion.java | 73 +++ .../java/wecui/render/region/RegionType.java | 3 +- .../java/wecui/render/shapes/Render2DBox.java | 2 +- .../wecui/render/shapes/Render2DGrid.java | 2 +- .../java/wecui/render/shapes/Render3DBox.java | 2 +- .../wecui/render/shapes/Render3DGrid.java | 2 +- .../wecui/render/shapes/Render3DPolygon.java | 41 ++ .../render/shapes/RenderCylinderBox.java | 2 +- .../render/shapes/RenderCylinderCircles.java | 2 +- .../render/shapes/RenderCylinderGrid.java | 2 +- .../wecui/render/shapes/RenderEllipsoid.java | 2 +- src/main/resources/Configuration.yml | 20 - updates.yml | 6 - 46 files changed, 441 insertions(+), 1786 deletions(-) delete mode 100644 .gitignore delete mode 100644 INSTALL.md delete mode 100644 UPGRADE.md create mode 100644 build/buildnumber.txt create mode 100644 build/litemod.template.json delete mode 100644 deobf.xml delete mode 100644 minecraft.pom delete mode 100644 obfuscation.txt delete mode 100644 pom.xml delete mode 100644 src/main/assembly/package.xml delete mode 100644 src/main/java/wecui/Updater.java create mode 100644 src/main/java/wecui/config/Colour.java delete mode 100644 src/main/java/wecui/config/Configuration.java delete mode 100644 src/main/java/wecui/config/ConfigurationNode.java delete mode 100644 src/main/java/wecui/config/EmptyNullRepresenter.java delete mode 100644 src/main/java/wecui/event/command/CommandEventBase.java delete mode 100644 src/main/java/wecui/event/command/CommandEventType.java delete mode 100644 src/main/java/wecui/event/command/VersionCommandEvent.java create mode 100644 src/main/java/wecui/event/cui/CUIPolygonEvent.java delete mode 100644 src/main/java/wecui/event/listeners/WorldEditCommandListener.java create mode 100644 src/main/java/wecui/render/region/PolyhedronRegion.java create mode 100644 src/main/java/wecui/render/shapes/Render3DPolygon.java delete mode 100644 src/main/resources/Configuration.yml delete mode 100644 updates.yml diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 740dbd77..00000000 --- a/.gitignore +++ /dev/null @@ -1,42 +0,0 @@ -/target -/run* -/build.sh -/minecraft.jar -/repackaging/ - -# Compiled source # -################### -*.com -*.class -*.dll -*.exe -*.o -*.so - -# Packages # -############ -# it's better to unpack these files and commit the raw source -# git has its own built in compression methods -*.7z -*.dmg -*.gz -*.iso -*.jar -*.rar -*.tar -*.zip - -# Logs and databases # -###################### -*.log -*.sql -*.sqlite - -# OS generated files # -###################### -.DS_Store* -ehthumbs.db -Icon? -Thumbs.db - -*.howto diff --git a/INSTALL.md b/INSTALL.md deleted file mode 100644 index 1dc924ba..00000000 --- a/INSTALL.md +++ /dev/null @@ -1,43 +0,0 @@ -Installing WorldEditCUI ------------------------ - -WorldEditCUI is installed the same way as every other mod in Minecraft. -Before installing, ensure that you have done all of the requirements: - -1. You have installed ModLoader (http://bit.ly/snQajN) to minecraft.jar, -and have ensured that it works. -2. You have deleted META-INF/ from minecraft.jar -3. You are competent enough to provide useful error messages if it breaks. - -Congratulations! You're ready to install WorldEditCUI! Please note that installing -via the mods/ folder is no longer supported, and I will not help you if you ask. - - -Installation ------------- - -WorldEditCUI can be installed the old fashioned way, by patching minecraft.jar. -To install using this method, do the following steps: - -1. Download WorldEditCUI-(version).zip and unzip it. -2. In the WorldEditCUI-(version)/ folder, copy the contents of the classes/ - directory into minecraft.jar. (If you don't know how to do this, there is - a handy guide at http://bit.ly/v9Ymqz on how to install mods) - -The minecraft directory structure should look something like this: - - .minecraft/ - bin/ - minecraft.jar/ - (lots of other classes) - mod_WorldEditCUI.class - Configuration.yml - wecui/ - WorldEditCUI.class - Updater.class - (and a lot of folders and other classes) - mods/ - resources/ - saves/ - stats/ - texturepacks/ diff --git a/README.md b/README.md index 75292bcd..6f4ed3a3 100644 --- a/README.md +++ b/README.md @@ -12,70 +12,8 @@ WorldEdit installed on your server or in SinglePlayerCommands to use this mod. Compiling --------- -You need to have Maven installed (http://maven.apache.org), as that will -include the necessary dependencies and package the mod automatically. If -there are any missing dependencies, you may need to download and build -them manually. +You will need a [LiteLoader MCP workspace](https://www.youtube.com/watch?v=RMpvo-F4AFc), once you have that set up simply import the project and run the ant build script. -Note: For Maven to work properly, be sure to add Maven to your "PATH". - -Once installed, there is a setup process before building WorldEditCUI. - -1) Put the most recent minecraft.jar into the root WorldEditCUI folder. -Note that minecraft.jar needs to have the most recent ModLoader installed. -Afterwards, run the following code: - - mvn install:install-file -Dfile=minecraft.jar -DpomFile=minecraft.pom - -This will install minecraft.jar into the maven repository. - -2) Go back to the WorldEditCUI root folder, and run the following code: - - mvn -f deobf.xml clean install - -This will create a new minecraft jar in your repository with some renamed -classes, to aid in development. - -3) Finally, run the following code to build WorldEditCUI: - - mvn clean install - -This will build the classes, and reobfuscate them to Minecraft's default -class naming scheme. - -After you have done steps 1, you do not need to do this again unless -Minecraft updates, which means that a new version needs to be added to the -local repository. Step 2 only needs to be run if obfuscation.txt is changed. - - -Contributing ------------- - -Developing is a tricky business, and the more eyes, the better! I'm always -welcome to contributions to the code! If you find a security problem, a -rendering improvement, or any way to make the code better, feel free to fork -WorldEditCUI on GitHub, add your changes, and then submit a pull request. We'll -look at it, make comments, and merge it if we think your changes are good enough. - - -Support -------- - -If you need help installing, find a bug, or just want to talk about WorldEditCUI, -feel free to pop in to #lahwran on irc.esper.net. If you want to talk to me in -private, you can also send me a message on GitHub. All messages on GitHub are sent -to my email, so I'll get back to you quickly. - - -Continuous Integration ----------------------- - -WorldEditCUI is continuously integrated, which means that each time a commit is -made to the repository, it is also build and packaged automatically. WorldEditCUI -uses Bamboo, and it is hosted at [bamboo.thezomg.com](http://bamboo.thezomg.com). - -Development builds are run automatically, and should not be relied upon. - Credits ------- diff --git a/UPGRADE.md b/UPGRADE.md deleted file mode 100644 index ac367fb7..00000000 --- a/UPGRADE.md +++ /dev/null @@ -1,14 +0,0 @@ -Upgrading WorldEditCUI ----------------------- - -Occasionally, WorldEditCUI will release an update in between Minecraft -release cycles. This means that class files will need to be rewritten, -replaced, and it will often break your client. - -To update, you have no other options but to reinstall everything, including all -of your other mods. To do this, open the Minecraft launcher, hit the -"Options" button, and click "Force Update". This will redownload the -minecraft.jar. From there, follow the instructions in INSTALL.txt. - -If anything breaks due to this update, you should start over with a clean -minecraft.jar before seeking help. diff --git a/build/build_wecui.xml b/build/build_wecui.xml index 2ae27e79..c86432ab 100644 --- a/build/build_wecui.xml +++ b/build/build_wecui.xml @@ -4,14 +4,14 @@ - - - - + + + + - - + + @@ -23,8 +23,9 @@ - - + + + @@ -107,7 +108,7 @@ - + @@ -135,13 +136,12 @@ - - - - - - - + + + + + + diff --git a/build/buildnumber.txt b/build/buildnumber.txt new file mode 100644 index 00000000..926ba844 --- /dev/null +++ b/build/buildnumber.txt @@ -0,0 +1,3 @@ +#Build Number for ANT. Do not edit! +#Mon Dec 02 23:30:17 GMT 2013 +build.number=1626 diff --git a/build/litemod.template.json b/build/litemod.template.json new file mode 100644 index 00000000..0da0a4d9 --- /dev/null +++ b/build/litemod.template.json @@ -0,0 +1,8 @@ +{ + "name": "wecui", + "mcversion": "${litemodversion}", + "version": "${version}", + "revision": "${build.number}", + "author": "${author}", + "description": "Client-side user interface for WorldEdit" +} diff --git a/deobf.xml b/deobf.xml deleted file mode 100644 index 5a619ab5..00000000 --- a/deobf.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - 4.0.0 - net.minecraft - minecraft-deobf - 1.4.5-wecui - WorldEditCUI deobfuscator - - deobf - - - maven-compiler-plugin - 2.3.2 - - true - - - - net.lahwran - renamer-maven-plugin - 1.0 - - - process-classes - - rename-dependencies - - - - - net.minecraft:minecraft - - - - - - notch - wecui - ${basedir}/obfuscation.txt - - - notch - wecui - ${basedir}/repackaging.txt - - - - - - - - - - - net.minecraft - minecraft - 1.4.5 - - - diff --git a/minecraft.pom b/minecraft.pom deleted file mode 100644 index 4348eadc..00000000 --- a/minecraft.pom +++ /dev/null @@ -1,8 +0,0 @@ - - - 4.0.0 - net.minecraft - minecraft - 1.4.5 - minecraft - diff --git a/obfuscation.txt b/obfuscation.txt deleted file mode 100644 index a55648b5..00000000 --- a/obfuscation.txt +++ /dev/null @@ -1,49 +0,0 @@ -renames: - - notch: do - wecui: doclass - packageOnly: false - - notch: if - wecui: ifclass - packageOnly: false - - notch: lq - wecui: Entity - packageOnly: false - - notch: ayk - wecui: EntityClientPlayerMP - packageOnly: false - - notch: azv - wecui: EntityPlayerSP - packageOnly: false - - notch: bq - wecui: NBTTagCompound - packageOnly: false - - notch: axz - wecui: NetClientHandler - packageOnly: false - - notch: cg - wecui: NetworkManager - packageOnly: false - - notch: eg - wecui: Packet - packageOnly: false - - notch: cv - wecui: Packet3Chat - packageOnly: false - - notch: dj - wecui: Packet250CustomPayload - packageOnly: false - - notch: bbk - wecui: Render - packageOnly: false - - notch: aro - wecui: RenderHelper - packageOnly: false - - notch: bao - wecui: Tessellator - packageOnly: false - - notch: ayh - wecui: WorldClient - packageOnly: false - - notch: aob - wecui: Vec3 - packageOnly: false \ No newline at end of file diff --git a/pom.xml b/pom.xml deleted file mode 100644 index e8eec357..00000000 --- a/pom.xml +++ /dev/null @@ -1,174 +0,0 @@ - - - 4.0.0 - wecui - WorldEditCUI - 1.4.5 - WorldEditCUI - - - net.minecraft - minecraft-deobf - 1.4.5-wecui - - - org.lwjgl.lwjgl - lwjgl - 2.8.2 - - - com.sk89q - worldedit - ${WEVersion} - - - org.yaml - snakeyaml - 1.9 - - - com.yetanotherx - SPCInterfaces - 1.0 - - - - 5.4-SNAPSHOT - - - - sk89q-mvn2 - http://maven.sk89q.com/repo/ - - - bukkit-repo - http://repo.bukkit.org/content/repositories/releases/ - - - mcbouncer-repo - http://maven.mcbouncer.com/repo - - - - - mcbouncer-repo - http://maven.mcbouncer.com/repo - - - - WorldEditCUI - ${basedir}/src/main/java - clean install - - - org.apache.maven.plugins - maven-dependency-plugin - 2.3 - - - unpack - process-sources - - unpack - - - com/**,org/** - ${project.build.directory}/classes - - - com.sk89q - worldedit - ${WEVersion} - - - org.yaml - snakeyaml - 1.9 - - - - - - - - maven-assembly-plugin - - - src/main/assembly/package.xml - - - - - build - package - - single - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.0.2 - - 1.5 - 1.5 - - - - net.lahwran - renamer-maven-plugin - 1.0 - - - process-classes - - rename - - - - - net.minecraft:minecraft-deobf - - - - - - wecui - notch - ${basedir}/repackaging.txt - - - wecui - notch - ${basedir}/obfuscation.txt - - - - - - - - - - . - true - ${basedir}/src/main/resources/ - - Configuration.yml - - - - . - true - ${basedir}/ - - INSTALL.md - UPGRADE.md - - - - - - diff --git a/src/main/assembly/package.xml b/src/main/assembly/package.xml deleted file mode 100644 index ca13f216..00000000 --- a/src/main/assembly/package.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - ${project.version} - true - ${project.build.finalName}-${project.version} - - zip - - - - ${project.build.directory}/classes - /classes - - /** - - - deobf - com/** - org/** - StartMC.class - INSTALL.md - UPGRADE.md - - - - - - ${project.build.directory}/classes/INSTALL.md - / - INSTALL.txt - - - ${project.build.directory}/classes/UPGRADE.md - / - UPGRADE.txt - - - \ No newline at end of file diff --git a/src/main/java/wecui/CUIDebug.java b/src/main/java/wecui/CUIDebug.java index b959e0fa..046c8e21 100644 --- a/src/main/java/wecui/CUIDebug.java +++ b/src/main/java/wecui/CUIDebug.java @@ -7,6 +7,8 @@ import java.util.logging.Level; import java.util.logging.Logger; +import com.mumfrey.liteloader.core.LiteLoader; + import wecui.exception.InitializationException; import wecui.util.ConsoleLogFormatter; @@ -38,7 +40,7 @@ public void initialize() throws InitializationException { logger.addHandler(handler); try { - this.debugFile = new File(WorldEditCUI.getWorldEditCUIDir(), "WorldEditCUI-debug.txt"); + this.debugFile = new File(LiteLoader.getCommonConfigFolder(), "worldeditcui.debug.log"); this.debugMode = this.controller.getConfiguration().isDebugMode(); if (this.debugMode) { diff --git a/src/main/java/wecui/LiteModWorldEditCUI.java b/src/main/java/wecui/LiteModWorldEditCUI.java index bd95dced..edba5c7c 100644 --- a/src/main/java/wecui/LiteModWorldEditCUI.java +++ b/src/main/java/wecui/LiteModWorldEditCUI.java @@ -5,13 +5,13 @@ import java.util.Arrays; import java.util.List; -import net.minecraft.src.Minecraft; -import net.minecraft.src.EntityPlayerSP; -import net.minecraft.src.NetHandler; -import net.minecraft.src.OpenGlHelper; -import net.minecraft.src.Packet1Login; -import net.minecraft.src.RenderHelper; -import net.minecraft.src.WorldClient; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.network.INetHandler; +import net.minecraft.network.play.server.S01PacketJoinGame; import wecui.event.ChannelEvent; import wecui.event.WorldRenderEvent; import wecui.render.region.CuboidRegion; @@ -20,10 +20,12 @@ import com.mumfrey.liteloader.PluginChannelListener; import com.mumfrey.liteloader.PostRenderListener; import com.mumfrey.liteloader.core.LiteLoader; +import com.mumfrey.liteloader.core.PluginChannels; public class LiteModWorldEditCUI implements InitCompleteListener, PluginChannelListener, PostRenderListener { - protected WorldEditCUI controller; + private static final String CHANNEL_WECUI = "WECUI"; + protected WorldEditCUI controller; protected WorldClient lastWorld; protected EntityPlayerSP lastPlayer; protected boolean gameStarted = false; @@ -53,16 +55,16 @@ public void onInitCompleted(Minecraft minecraft, LiteLoader loader) } @Override - public void onLogin(NetHandler netHandler, Packet1Login loginPacket) + public void onLogin(INetHandler netHandler, S01PacketJoinGame loginPacket) { byte[] buffer = ("v|" + WorldEditCUI.protocolVersion).getBytes(UTF_8_CHARSET); - LiteLoader.getInstance().sendPluginChannelMessage("WECUI", buffer); + PluginChannels.sendMessage(CHANNEL_WECUI, buffer); } @Override public List getChannels() { - return Arrays.asList(new String[] { "WECUI" }); + return Arrays.asList(new String[] { CHANNEL_WECUI }); } @Override @@ -84,10 +86,7 @@ public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clo if (!this.gameStarted) { this.gameStarted = true; - new Updater(this.controller).start(); this.controller.setSelection(new CuboidRegion(this.controller)); - -// DataPacketList.register(this.controller); } } } @@ -96,13 +95,13 @@ public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clo @Override public String getName() { - return "WorldEditCUI by yetanotherx"; + return "WorldEditCUI"; } @Override public String getVersion() { - return "1.6.2_00_lite"; + return "1.7.2"; } @Override @@ -118,7 +117,5 @@ public void onPostRenderEntities(float partialTicks) @Override public void onPostRender(float partialTicks) { - // TODO Auto-generated method stub - } } diff --git a/src/main/java/wecui/Updater.java b/src/main/java/wecui/Updater.java deleted file mode 100644 index 224da04a..00000000 --- a/src/main/java/wecui/Updater.java +++ /dev/null @@ -1,92 +0,0 @@ -package wecui; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.URL; - -import net.minecraft.src.EntityClientPlayerMP; -import wecui.util.ChatColor; - -public class Updater extends Thread { - - protected WorldEditCUI controller; - protected final int updaterVersion = 1; - - protected final int currentRevision = 100; - - public Updater(WorldEditCUI controller) { - this.controller = controller; - } - - /** - * Checks the most recent version of updates.yml on GitHub, and parses the - * YAML to find supported versions. If the current version isn't supported, - * show an error to the user. - */ - @Override - public void run() { - if (this.controller.configuration.ignoreUpdates()) { - return; - } - - InputStream is = null; - - try { - URL url = new URL(this.controller.getConfiguration().getUpdateFile()); - url.openConnection(); - is = url.openStream(); - - StringBuilder readString = new StringBuilder(); - BufferedReader reader = new BufferedReader(new InputStreamReader(is)); - - String readLine; - while ((readLine = reader.readLine()) != null) - { - readString.append(readLine).append("\n"); - } - - reader.close(); - - String[] versions = readString.toString().split("\n"); - int latestVersion = 0; - - for (String version : versions) - { - if (version.matches("^" + WorldEditCUI.MCVERSION + "=\\d+$")) - { - latestVersion = Integer.parseInt(version.substring(version.indexOf("=") + 1)); - } - } - - if (latestVersion > this.currentRevision) { - this.showChatMessage(ChatColor.RED + "Your WorldEditCUI version is out of date."); - } - - } catch (Exception e) { - this.controller.getDebugger().info("Error in fetching update file!", e); - } finally { - if (is != null) { - try { - is.close(); - } catch (IOException e) { - } - } - } - } - - /** - * Displays a chat message on the screen, if the player is currently playing - * - * @param chat - */ - public void showChatMessage(String chat) - { - EntityClientPlayerMP thePlayer = this.controller.getMinecraft().thePlayer; - if (thePlayer != null) - { - thePlayer.addChatMessage(chat); - } - } -} diff --git a/src/main/java/wecui/WorldEditCUI.java b/src/main/java/wecui/WorldEditCUI.java index e06f1550..786b8001 100644 --- a/src/main/java/wecui/WorldEditCUI.java +++ b/src/main/java/wecui/WorldEditCUI.java @@ -1,18 +1,12 @@ package wecui; -import java.io.File; - -import com.mumfrey.liteloader.core.LiteLoader; - -import net.minecraft.src.Minecraft; +import net.minecraft.client.Minecraft; import wecui.config.CUIConfiguration; import wecui.event.CUIEvent; import wecui.event.ChannelEvent; -import wecui.event.ChatCommandEvent; import wecui.event.WorldRenderEvent; import wecui.event.listeners.CUIListener; import wecui.event.listeners.ChannelListener; -import wecui.event.listeners.WorldEditCommandListener; import wecui.event.listeners.WorldRenderListener; import wecui.exception.InitializationException; import wecui.fevents.EventManager; @@ -32,9 +26,7 @@ */ public class WorldEditCUI { - public static final String VERSION = "1.5.2"; - public static final String MCVERSION = "1.5.2"; - public static final int protocolVersion = 2; + public static final int protocolVersion = 3; protected Minecraft minecraft; protected EventManager eventManager; protected BaseRegion selection; @@ -49,7 +41,7 @@ public WorldEditCUI(Minecraft minecraft) { public void initialize() { this.eventManager = new EventManager(this); this.selection = new CuboidRegion(this); - this.configuration = new CUIConfiguration(this); + this.configuration = CUIConfiguration.create(); this.debugger = new CUIDebug(this); //this.localPlugin = new LocalPlugin(this); @@ -71,10 +63,6 @@ protected void registerListeners() { CUIEvent.handlers.register(new CUIListener(this), Order.Default); ChannelEvent.handlers.register(new ChannelListener(this), Order.Default); WorldRenderEvent.handlers.register(new WorldRenderListener(this), Order.Default); - - WorldEditCommandListener commListener = new WorldEditCommandListener(this); - ChatCommandEvent.getHandlers("worldedit").register(commListener, Order.Default); - ChatCommandEvent.getHandlers("we").register(commListener, Order.Default); } public CUIConfiguration getConfiguration() { @@ -101,14 +89,6 @@ public void setEventManager(EventManager eventManager) { this.eventManager = eventManager; } - /*public LocalPlugin getLocalPlugin() { - return localPlugin; - } - - public void setLocalPlugin(LocalPlugin localPlugin) { - this.localPlugin = localPlugin; - }*/ - public Minecraft getMinecraft() { return this.minecraft; } @@ -124,13 +104,4 @@ public BaseRegion getSelection() { public void setSelection(BaseRegion selection) { this.selection = selection; } - - public static String getVersion() { - return VERSION + " for Minecraft version " + MCVERSION; - } - - public static File getWorldEditCUIDir() - { - return new File(LiteLoader.getInstance().getModsFolder(), "WorldEditCUI"); - } } diff --git a/src/main/java/wecui/config/CUIConfiguration.java b/src/main/java/wecui/config/CUIConfiguration.java index a4d9a003..32ce58b1 100644 --- a/src/main/java/wecui/config/CUIConfiguration.java +++ b/src/main/java/wecui/config/CUIConfiguration.java @@ -1,149 +1,142 @@ package wecui.config; import java.io.File; -import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.FileWriter; import java.io.IOException; -import java.io.InputStream; import wecui.InitializationFactory; -import wecui.WorldEditCUI; import wecui.render.LineColor; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.mumfrey.liteloader.core.LiteLoader; + /** * Stores and reads WorldEditCUI settings * * @author yetanotherx * */ -public class CUIConfiguration implements InitializationFactory { - - protected WorldEditCUI controller; - protected boolean debugMode = false; - protected boolean ignoreUpdates = false; - protected String cuboidGridColor = "#CC3333"; - protected String cuboidEdgeColor = "#CC4C4C"; - protected String cuboidFirstPointColor = "#33CC33"; - protected String cuboidSecondPointColor = "#3333CC"; - protected String polyGridColor = "#CC3333"; - protected String polyEdgeColor = "#CC4C4C"; - protected String polyPointColor = "#33CCCC"; - protected String ellipsoidGridColor = "#CC4C4C"; - protected String ellipsoidPointColor = "#CCCC33"; - protected String cylinderGridColor = "#CC3333"; - protected String cylinderEdgeColor = "#CC4C4C"; - protected String cylinderPointColor = "#CC33CC"; - protected String updateFile = "http://update.liteloader.com/wecui.version"; - protected Configuration config = null; - - public CUIConfiguration(WorldEditCUI controller) { - this.controller = controller; - } - - /** - * Copies the default config file to the proper directory if it does not - * exist. It then reads the file and sets each variable to the proper value. - */ - @Override - public void initialize() { - - File file = new File(WorldEditCUI.getWorldEditCUIDir(), "Configuration.yml"); - file.getParentFile().mkdirs(); - - if (!file.exists()) { - InputStream input = CUIConfiguration.class.getResourceAsStream("/Configuration.yml"); - if (input != null) { - FileOutputStream output = null; - - try { - output = new FileOutputStream(file); - byte[] buf = new byte[8192]; - int length = 0; - while ((length = input.read(buf)) > 0) { - output.write(buf, 0, length); - } - - } catch (IOException e) { - e.printStackTrace(); - } finally { - try { - input.close(); - } catch (IOException e) { - } - - try { - if (output != null) { - output.close(); - } - } catch (IOException e) { - } - } - } - } - - this.config = new Configuration(file); - this.config.load(); - - this.debugMode = this.config.getBoolean("debug", this.debugMode); - this.ignoreUpdates = this.config.getBoolean("ignoreUpdates", this.ignoreUpdates); - - this.cuboidGridColor = this.parseColor(this.config.getString("colors.cuboidGrid"), this.cuboidGridColor); - this.cuboidEdgeColor = this.parseColor(this.config.getString("colors.cuboidEdge"), this.cuboidEdgeColor); - this.cuboidFirstPointColor = this.parseColor(this.config.getString("colors.cuboidFirstPoint"), this.cuboidFirstPointColor); - this.cuboidSecondPointColor = this.parseColor(this.config.getString("colors.cuboidSecondPoint"), this.cuboidSecondPointColor); - this.polyGridColor = this.parseColor(this.config.getString("colors.polyGrid"), this.polyGridColor); - this.polyEdgeColor = this.parseColor(this.config.getString("colors.polyEdge"), this.polyEdgeColor); - this.polyPointColor = this.parseColor(this.config.getString("colors.polyPoint"), this.polyPointColor); - this.ellipsoidGridColor = this.parseColor(this.config.getString("colors.ellipsoidGrid"), this.ellipsoidGridColor); - this.ellipsoidPointColor = this.parseColor(this.config.getString("colors.ellipsoidPoint"), this.ellipsoidPointColor); - this.cylinderGridColor = this.parseColor(this.config.getString("colors.cylinderGrid"), this.cylinderGridColor); - this.cylinderEdgeColor = this.parseColor(this.config.getString("colors.cylinderEdge"), this.cylinderEdgeColor); - this.cylinderPointColor = this.parseColor(this.config.getString("colors.cylinderPoint"), this.cylinderPointColor); - - LineColor.CUBOIDBOX.setColor(this.cuboidEdgeColor); - LineColor.CUBOIDGRID.setColor(this.cuboidGridColor); - LineColor.CUBOIDPOINT1.setColor(this.cuboidFirstPointColor); - LineColor.CUBOIDPOINT2.setColor(this.cuboidSecondPointColor); - LineColor.POLYGRID.setColor(this.polyGridColor); - LineColor.POLYBOX.setColor(this.polyEdgeColor); - LineColor.POLYPOINT.setColor(this.polyPointColor); - LineColor.ELLIPSOIDGRID.setColor(this.ellipsoidGridColor); - LineColor.ELLIPSOIDCENTER.setColor(this.ellipsoidPointColor); - LineColor.CYLINDERGRID.setColor(this.cylinderGridColor); - LineColor.CYLINDERBOX.setColor(this.cylinderEdgeColor); - LineColor.CYLINDERCENTER.setColor(this.cylinderPointColor); - - this.updateFile = this.config.getString("updateFile", this.updateFile); - } - - /** - * Validates a user-entered color code. Ensures that color is not null, it - * starts with #, that it has all 6 digits, and that each hex code is valid. - * @param color - * @param def - * @return - */ - protected String parseColor(String color, String def) { - if (color == null) { - return def; - } else if (!color.startsWith("#")) { - return def; - } else if (color.length() != 7) { - return def; - } - - // Replaced some bloody stupid code with regex - return (color.matches("(?i)^[0-9a-f]{6}$")) ? color : def; - } - - public boolean isDebugMode() { - return this.debugMode; - } - - public boolean ignoreUpdates() { - return this.ignoreUpdates; - } - - public String getUpdateFile() { - return this.updateFile; - } +public class CUIConfiguration implements InitializationFactory +{ + private static Gson gson = new GsonBuilder().setPrettyPrinting().create(); + + protected boolean debugMode = false; + protected boolean ignoreUpdates = false; + + private Colour cuboidGridColor = new Colour("#CC3333"); + private Colour cuboidEdgeColor = new Colour("#CC4C4C"); + private Colour cuboidFirstPointColor = new Colour("#33CC33"); + private Colour cuboidSecondPointColor = new Colour("#3333CC"); + private Colour polyGridColor = new Colour("#CC3333"); + private Colour polyEdgeColor = new Colour("#CC4C4C"); + private Colour polyPointColor = new Colour("#33CCCC"); + private Colour ellipsoidGridColor = new Colour("#CC4C4C"); + private Colour ellipsoidPointColor = new Colour("#CCCC33"); + private Colour cylinderGridColor = new Colour("#CC3333"); + private Colour cylinderEdgeColor = new Colour("#CC4C4C"); + private Colour cylinderPointColor = new Colour("#CC33CC"); + + /** + * Copies the default config file to the proper directory if it does not + * exist. It then reads the file and sets each variable to the proper value. + */ + @Override + public void initialize() + { + this.cuboidGridColor = Colour.setDefault(this.cuboidGridColor, "#CC3333"); + this.cuboidEdgeColor = Colour.setDefault(this.cuboidEdgeColor, "#CC4C4C"); + this.cuboidFirstPointColor = Colour.setDefault(this.cuboidFirstPointColor, "#33CC33"); + this.cuboidSecondPointColor = Colour.setDefault(this.cuboidSecondPointColor, "#3333CC"); + this.polyGridColor = Colour.setDefault(this.polyGridColor, "#CC3333"); + this.polyEdgeColor = Colour.setDefault(this.polyEdgeColor, "#CC4C4C"); + this.polyPointColor = Colour.setDefault(this.polyPointColor, "#33CCCC"); + this.ellipsoidGridColor = Colour.setDefault(this.ellipsoidGridColor, "#CC4C4C"); + this.ellipsoidPointColor = Colour.setDefault(this.ellipsoidPointColor, "#CCCC33"); + this.cylinderGridColor = Colour.setDefault(this.cylinderGridColor, "#CC3333"); + this.cylinderEdgeColor = Colour.setDefault(this.cylinderEdgeColor, "#CC4C4C"); + this.cylinderPointColor = Colour.setDefault(this.cylinderPointColor, "#CC33CC"); + + LineColor.CUBOIDBOX.setColor(this.cuboidEdgeColor); + LineColor.CUBOIDGRID.setColor(this.cuboidGridColor); + LineColor.CUBOIDPOINT1.setColor(this.cuboidFirstPointColor); + LineColor.CUBOIDPOINT2.setColor(this.cuboidSecondPointColor); + LineColor.POLYGRID.setColor(this.polyGridColor); + LineColor.POLYBOX.setColor(this.polyEdgeColor); + LineColor.POLYPOINT.setColor(this.polyPointColor); + LineColor.ELLIPSOIDGRID.setColor(this.ellipsoidGridColor); + LineColor.ELLIPSOIDCENTER.setColor(this.ellipsoidPointColor); + LineColor.CYLINDERGRID.setColor(this.cylinderGridColor); + LineColor.CYLINDERBOX.setColor(this.cylinderEdgeColor); + LineColor.CYLINDERCENTER.setColor(this.cylinderPointColor); + + this.save(); + } + + public boolean isDebugMode() + { + return this.debugMode; + } + + public boolean ignoreUpdates() + { + return this.ignoreUpdates; + } + + public static CUIConfiguration create() + { + File jsonFile = new File(LiteLoader.getCommonConfigFolder(), "worldeditcui.config.json"); + + if (jsonFile.exists()) + { + FileReader fileReader = null; + + try + { + fileReader = new FileReader(jsonFile); + CUIConfiguration config = CUIConfiguration.gson.fromJson(fileReader, CUIConfiguration.class); + return config; + } + catch (IOException ex) + { + ex.printStackTrace(); + } + finally + { + try + { + if (fileReader != null) + fileReader.close(); + } + catch (IOException ex) + { + } + } + } + + return new CUIConfiguration(); + } + + public void save() + { + File jsonFile = new File(LiteLoader.getCommonConfigFolder(), "worldeditcui.config.json"); + + FileWriter fileWriter = null; + + try + { + fileWriter = new FileWriter(jsonFile); + CUIConfiguration.gson.toJson(this, fileWriter); + } + catch (IOException ex) { ex.printStackTrace(); } + finally + { + try + { + if (fileWriter != null) fileWriter.close(); + } + catch (IOException ex) { ex.printStackTrace(); } + } + } } diff --git a/src/main/java/wecui/config/Colour.java b/src/main/java/wecui/config/Colour.java new file mode 100644 index 00000000..ea55f828 --- /dev/null +++ b/src/main/java/wecui/config/Colour.java @@ -0,0 +1,84 @@ +package wecui.config; + +public class Colour +{ + private String hex; + private transient String defaultColour; + + public Colour(String defaultColour) + { + this.hex = defaultColour; + this.defaultColour = defaultColour; + } + + public Colour() + { + } + + public static Colour setDefault(Colour colour, String defaultColour) + { + if (colour == null) + { + return new Colour(defaultColour); + } + + if (colour.hex == null) + { + colour.hex = defaultColour; + colour.defaultColour = defaultColour; + } + else + { + colour.hex = Colour.parseColour(colour.hex, defaultColour); + } + + return colour; + } + + /** + * Validates a user-entered color code. Ensures that color is not null, it + * starts with #, that it has all 6 digits, and that each hex code is valid. + * + * @param colour + * @param def + * @return + */ + private static String parseColour(String colour, String def) + { + if (colour == null) + { + return def; + } + else if (!colour.startsWith("#")) + { + return def; + } + else if (colour.length() != 7) + { + return def; + } + + return (colour.matches("(?i)^#[0-9a-f]{6}$")) ? colour : def; + } + + public float red() + { + if (this.hex == null) this.hex = this.defaultColour; + Integer r = Integer.parseInt(this.hex.substring(1, 3), 16); + return (r.floatValue() / 256.0F); + } + + public float green() + { + if (this.hex == null) this.hex = this.defaultColour; + Integer g = Integer.parseInt(hex.substring(3, 5), 16); + return (g.floatValue() / 256.0F); + } + + public float blue() + { + if (this.hex == null) this.hex = this.defaultColour; + Integer b = Integer.parseInt(hex.substring(5, 7), 16); + return (b.floatValue() / 256.0F); + } +} diff --git a/src/main/java/wecui/config/Configuration.java b/src/main/java/wecui/config/Configuration.java deleted file mode 100644 index 571c06f5..00000000 --- a/src/main/java/wecui/config/Configuration.java +++ /dev/null @@ -1,190 +0,0 @@ -package wecui.config; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.util.HashMap; -import java.util.Map; - -import org.yaml.snakeyaml.DumperOptions; -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.constructor.SafeConstructor; -import org.yaml.snakeyaml.reader.UnicodeReader; - -import wecui.exception.ConfigurationException; - -/** - * YAML configuration loader. To use this class, construct it with path to - * a file and call its load() method. For specifying node paths in the - * various get*() methods, they support SK's path notation, allowing you to - * select child nodes by delimiting node names with periods. - * - *

- * For example, given the following configuration file:

- * - *
members:
- *     - Hollie
- *     - Jason
- *     - Bobo
- *     - Aya
- *     - Tetsu
- * worldguard:
- *     fire:
- *         spread: false
- *         blocks: [cloth, rock, glass]
- * sturmeh:
- *     cool: false
- *     eats:
- *         babies: true
- * - *

Calling code could access sturmeh's baby eating state by using - * getBoolean("sturmeh.eats.babies", false). For lists, there are - * methods such as getStringList that will return a type safe list. - * - *

This class is currently incomplete. It is not yet possible to get a node. - *

- * - */ -public class Configuration extends ConfigurationNode { - - private Yaml yaml; - private File file; - private String header = null; - - public Configuration(File file) { - super(new HashMap()); - - DumperOptions options = new DumperOptions(); - - options.setIndent(4); - options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); - - this.yaml = new Yaml(new SafeConstructor(), new EmptyNullRepresenter(), options); - - this.file = file; - } - - /** - * Loads the configuration file. All errors are thrown away. - */ - public void load() { - FileInputStream stream = null; - - try { - stream = new FileInputStream(this.file); - this.read(this.yaml.load(new UnicodeReader(stream))); - } catch (IOException e) { - this.root = new HashMap(); - } catch (ConfigurationException e) { - this.root = new HashMap(); - } finally { - try { - if (stream != null) { - stream.close(); - } - } catch (IOException e) { - } - } - } - - /** - * Set the header for the file as a series of lines that are terminated - * by a new line sequence. - * - * @param headerLines header lines to prepend - */ - public void setHeader(String... headerLines) { - StringBuilder headerTemp = new StringBuilder(); - - for (String line : headerLines) { - if (headerTemp.length() > 0) { - headerTemp.append("\r\n"); - } - headerTemp.append(line); - } - - this.setHeader(headerTemp.toString()); - } - - /** - * Set the header for the file. A header can be provided to prepend the - * YAML data output on configuration save. The header is - * printed raw and so must be manually commented if used. A new line will - * be appended after the header, however, if a header is provided. - * - * @param header header to prepend - */ - public void setHeader(String header) { - this.header = header; - } - - /** - * Return the set header. - * - * @return - */ - public String getHeader() { - return this.header; - } - - /** - * Saves the configuration to disk. All errors are clobbered. - * - * @param header header to prepend - * @return true if it was successful - */ - public boolean save() { - FileOutputStream stream = null; - - File parent = this.file.getParentFile(); - - if (parent != null) { - parent.mkdirs(); - } - - try { - stream = new FileOutputStream(this.file); - OutputStreamWriter writer = new OutputStreamWriter(stream, "UTF-8"); - if (this.header != null) { - writer.append(this.header); - writer.append("\r\n"); - } - this.yaml.dump(this.root, writer); - return true; - } catch (IOException e) { - } finally { - try { - if (stream != null) { - stream.close(); - } - } catch (IOException e) { - } - } - - return false; - } - - @SuppressWarnings("unchecked") - private void read(Object input) throws ConfigurationException { - try { - if (null == input) { - this.root = new HashMap(); - } else { - this.root = (Map) input; - } - } catch (ClassCastException e) { - throw new ConfigurationException("Root document must be an key-value structure"); - } - } - - /** - * This method returns an empty ConfigurationNode for using as a - * default in methods that select a node from a node list. - * @return - */ - public static ConfigurationNode getEmptyNode() { - return new ConfigurationNode(new HashMap()); - } -} diff --git a/src/main/java/wecui/config/ConfigurationNode.java b/src/main/java/wecui/config/ConfigurationNode.java deleted file mode 100644 index 672bb5c5..00000000 --- a/src/main/java/wecui/config/ConfigurationNode.java +++ /dev/null @@ -1,543 +0,0 @@ -package wecui.config; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Represents a configuration node. - * - * @author sk89q - */ -public class ConfigurationNode { - - protected Map root; - - public ConfigurationNode(Map root) { - this.root = root; - } - - /** - * Gets a property at a location. This will either return an Object - * or null, with null meaning that no configuration value exists at - * that location. This could potentially return a default value (not yet - * implemented) as defined by a plugin, if this is a plugin-tied - * configuration. - * - * @param path path to node (dot notation) - * @return object or null - */ - @SuppressWarnings("unchecked") - public Object getProperty(String path) { - if (!path.contains(".")) { - Object val = this.root.get(path); - - if (val == null) { - return null; - } - return val; - } - - String[] parts = path.split("\\."); - Map node = this.root; - - for (int i = 0; i < parts.length; i++) { - Object o = node.get(parts[i]); - - if (o == null) { - return null; - } - - if (i == parts.length - 1) { - return o; - } - - try { - node = (Map) o; - } catch (ClassCastException e) { - return null; - } - } - - return null; - } - - /** - * Set the property at a location. This will override existing - * configuration data to have it conform to key/value mappings. - * - * @param path - * @param value - */ - @SuppressWarnings("unchecked") - public void setProperty(String path, Object value) { - if (!path.contains(".")) { - this.root.put(path, value); - return; - } - - String[] parts = path.split("\\."); - Map node = this.root; - - for (int i = 0; i < parts.length; i++) { - Object o = node.get(parts[i]); - - // Found our target! - if (i == parts.length - 1) { - node.put(parts[i], value); - return; - } - - if (o == null || !(o instanceof Map)) { - // This will override existing configuration data! - o = new HashMap(); - node.put(parts[i], o); - } - - node = (Map) o; - } - } - - /** - * Gets a string at a location. This will either return an String - * or null, with null meaning that no configuration value exists at - * that location. If the object at the particular location is not actually - * a string, it will be converted to its string representation. - * - * @param path path to node (dot notation) - * @return string or null - */ - public String getString(String path) { - Object o = this.getProperty(path); - - if (o == null) { - return null; - } - return o.toString(); - } - - /** - * Gets a string at a location. This will either return an String - * or the default value. If the object at the particular location is not - * actually a string, it will be converted to its string representation. - * - * @param path path to node (dot notation) - * @param def default value - * @return string or default - */ - public String getString(String path, String def) { - String o = this.getString(path); - - if (o == null) { - //setProperty(path, def); - return def; - } - return o; - } - - /** - * Gets an integer at a location. This will either return an integer - * or the default value. If the object at the particular location is not - * actually a integer, the default value will be returned. However, other - * number types will be casted to an integer. - * - * @param path path to node (dot notation) - * @param def default value - * @return int or default - */ - public int getInt(String path, int def) { - Integer o = castInt(this.getProperty(path)); - - if (o == null) { - //setProperty(path, def); - return def; - } - return o; - } - - /** - * Gets a double at a location. This will either return an double - * or the default value. If the object at the particular location is not - * actually a double, the default value will be returned. However, other - * number types will be casted to an double. - * - * @param path path to node (dot notation) - * @param def default value - * @return double or default - */ - public double getDouble(String path, double def) { - Double o = castDouble(this.getProperty(path)); - - if (o == null) { - //setProperty(path, def); - return def; - } - return o; - } - - /** - * Gets a boolean at a location. This will either return an boolean - * or the default value. If the object at the particular location is not - * actually a boolean, the default value will be returned. - * - * @param path path to node (dot notation) - * @param def default value - * @return boolean or default - */ - public boolean getBoolean(String path, boolean def) { - Boolean o = castBoolean(this.getProperty(path)); - - if (o == null) { - //setProperty(path, def); - return def; - } - return o; - } - - /** - * Get a list of keys at a location. If the map at the particular location - * does not exist or it is not a map, null will be returned. - * - * @param path path to node (dot notation) - * @return list of keys - */ - @SuppressWarnings("unchecked") - public List getKeys(String path) { - if (path == null) { - return new ArrayList(this.root.keySet()); - } - Object o = this.getProperty(path); - - if (o == null) { - return null; - } else if (o instanceof Map) { - return new ArrayList(((Map) o).keySet()); - } else { - return null; - } - } - - /** - * Gets a list of objects at a location. If the list is not defined, - * null will be returned. The node must be an actual list. - * - * @param path path to node (dot notation) - * @return boolean or default - */ - @SuppressWarnings("unchecked") - public List getList(String path) { - Object o = this.getProperty(path); - - if (o == null) { - return null; - } else if (o instanceof List) { - return (List) o; - } else { - return null; - } - } - - /** - * Gets a list of strings. Non-valid entries will not be in the list. - * There will be no null slots. If the list is not defined, the - * default will be returned. 'null' can be passed for the default - * and an empty list will be returned instead. If an item in the list - * is not a string, it will be converted to a string. The node must be - * an actual list and not just a string. - * - * @param path path to node (dot notation) - * @param def default value or null for an empty list as default - * @return list of strings - */ - public List getStringList(String path, List def) { - List raw = this.getList(path); - - if (raw == null) { - return def != null ? def : new ArrayList(); - } - - List list = new ArrayList(); - - for (Object o : raw) { - if (o == null) { - continue; - } - - list.add(o.toString()); - } - - return list; - } - - /** - * Gets a list of integers. Non-valid entries will not be in the list. - * There will be no null slots. If the list is not defined, the - * default will be returned. 'null' can be passed for the default - * and an empty list will be returned instead. The node must be - * an actual list and not just an integer. - * - * @param path path to node (dot notation) - * @param def default value or null for an empty list as default - * @return list of integers - */ - public List getIntList(String path, List def) { - List raw = this.getList(path); - - if (raw == null) { - return def != null ? def : new ArrayList(); - } - - List list = new ArrayList(); - - for (Object o : raw) { - Integer i = castInt(o); - - if (i != null) { - list.add(i); - } - } - - return list; - } - - /** - * Gets a list of doubles. Non-valid entries will not be in the list. - * There will be no null slots. If the list is not defined, the - * default will be returned. 'null' can be passed for the default - * and an empty list will be returned instead. The node must be - * an actual list and cannot be just a double. - * - * @param path path to node (dot notation) - * @param def default value or null for an empty list as default - * @return list of integers - */ - public List getDoubleList(String path, List def) { - List raw = this.getList(path); - - if (raw == null) { - return def != null ? def : new ArrayList(); - } - - List list = new ArrayList(); - - for (Object o : raw) { - Double i = castDouble(o); - - if (i != null) { - list.add(i); - } - } - - return list; - } - - /** - * Gets a list of booleans. Non-valid entries will not be in the list. - * There will be no null slots. If the list is not defined, the - * default will be returned. 'null' can be passed for the default - * and an empty list will be returned instead. The node must be - * an actual list and cannot be just a boolean, - * - * @param path path to node (dot notation) - * @param def default value or null for an empty list as default - * @return list of integers - */ - public List getBooleanList(String path, List def) { - List raw = this.getList(path); - - if (raw == null) { - return def != null ? def : new ArrayList(); - } - - List list = new ArrayList(); - - for (Object o : raw) { - Boolean tetsu = castBoolean(o); - - if (tetsu != null) { - list.add(tetsu); - } - } - - return list; - } - - /** - * Gets a list of nodes. Non-valid entries will not be in the list. - * There will be no null slots. If the list is not defined, the - * default will be returned. 'null' can be passed for the default - * and an empty list will be returned instead. The node must be - * an actual node and cannot be just a boolean, - * - * @param path path to node (dot notation) - * @param def default value or null for an empty list as default - * @return list of integers - */ - @SuppressWarnings("unchecked") - public List getNodeList(String path, List def) { - List raw = this.getList(path); - - if (raw == null) { - return def != null ? def : new ArrayList(); - } - - List list = new ArrayList(); - - for (Object o : raw) { - if (o instanceof Map) { - list.add(new ConfigurationNode((Map) o)); - } - } - - return list; - } - - /** - * Get a configuration node at a path. If the node doesn't exist or the - * path does not lead to a node, null will be returned. A node has - * key/value mappings. - * - * @param path - * @return node or null - */ - @SuppressWarnings("unchecked") - public ConfigurationNode getNode(String path) { - Object raw = this.getProperty(path); - - if (raw instanceof Map) { - return new ConfigurationNode((Map) raw); - } - - return null; - } - - /** - * Get a list of nodes at a location. If the map at the particular location - * does not exist or it is not a map, null will be returned. - * - * @param path path to node (dot notation) - * @return map of nodes - */ - @SuppressWarnings("unchecked") - public Map getNodes(String path) { - Object o = this.getProperty(path); - - if (o == null) { - return null; - } else if (o instanceof Map) { - Map nodes = new HashMap(); - - for (Map.Entry entry : ((Map) o).entrySet()) { - if (entry.getValue() instanceof Map) { - nodes.put(entry.getKey(), new ConfigurationNode((Map) entry.getValue())); - } - } - - return nodes; - } else { - return null; - } - } - - /** - * Casts a value to an integer. May return null. - * - * @param o - * @return - */ - private static Integer castInt(Object o) { - if (o == null) { - return null; - } else if (o instanceof Byte) { - return (int) (Byte) o; - } else if (o instanceof Integer) { - return (Integer) o; - } else if (o instanceof Double) { - return (int) (double) (Double) o; - } else if (o instanceof Float) { - return (int) (float) (Float) o; - } else if (o instanceof Long) { - return (int) (long) (Long) o; - } else { - return null; - } - } - - /** - * Casts a value to a double. May return null. - * - * @param o - * @return - */ - private static Double castDouble(Object o) { - if (o == null) { - return null; - } else if (o instanceof Float) { - return (double) (Float) o; - } else if (o instanceof Double) { - return (Double) o; - } else if (o instanceof Byte) { - return (double) (Byte) o; - } else if (o instanceof Integer) { - return (double) (Integer) o; - } else if (o instanceof Long) { - return (double) (Long) o; - } else { - return null; - } - } - - /** - * Casts a value to a boolean. May return null. - * - * @param o - * @return - */ - private static Boolean castBoolean(Object o) { - if (o == null) { - return null; - } else if (o instanceof Boolean) { - return (Boolean) o; - } else { - return null; - } - } - - /** - * Remove the property at a location. This will override existing - * configuration data to have it conform to key/value mappings. - * - * @param path - */ - @SuppressWarnings("unchecked") - public void removeProperty(String path) { - if (!path.contains(".")) { - this.root.remove(path); - return; - } - - String[] parts = path.split("\\."); - Map node = this.root; - - for (int i = 0; i < parts.length; i++) { - Object o = node.get(parts[i]); - - // Found our target! - if (i == parts.length - 1) { - node.remove(parts[i]); - return; - } - - node = (Map) o; - } - } - - public Map getRoot() { - return this.root; - } - - public void setRoot(Map root) { - this.root = root; - } -} \ No newline at end of file diff --git a/src/main/java/wecui/config/EmptyNullRepresenter.java b/src/main/java/wecui/config/EmptyNullRepresenter.java deleted file mode 100644 index e9ea23d4..00000000 --- a/src/main/java/wecui/config/EmptyNullRepresenter.java +++ /dev/null @@ -1,51 +0,0 @@ -package wecui.config; - -import org.yaml.snakeyaml.introspector.Property; -import org.yaml.snakeyaml.nodes.CollectionNode; -import org.yaml.snakeyaml.nodes.MappingNode; -import org.yaml.snakeyaml.nodes.Node; -import org.yaml.snakeyaml.nodes.NodeTuple; -import org.yaml.snakeyaml.nodes.SequenceNode; -import org.yaml.snakeyaml.nodes.Tag; -import org.yaml.snakeyaml.representer.Represent; -import org.yaml.snakeyaml.representer.Representer; - -public class EmptyNullRepresenter extends Representer { - - public EmptyNullRepresenter() { - super(); - this.nullRepresenter = new EmptyRepresentNull(); - } - - protected class EmptyRepresentNull implements Represent { - - @Override - public Node representData(Object data) { - return EmptyNullRepresenter.this.representScalar(Tag.NULL, ""); // Changed "null" to "" so as to avoid writing nulls - } - } - - // Code borrowed from snakeyaml (http://code.google.com/p/snakeyaml/source/browse/src/test/java/org/yaml/snakeyaml/issues/issue60/SkipBeanTest.java) - @Override - protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue, Tag customTag) { - NodeTuple tuple = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag); - Node valueNode = tuple.getValueNode(); - if (valueNode instanceof CollectionNode) { - // Removed null check - if (Tag.SEQ.equals(valueNode.getTag())) { - SequenceNode seq = (SequenceNode) valueNode; - if (seq.getValue().isEmpty()) { - return null; // skip empty lists - } - } - if (Tag.MAP.equals(valueNode.getTag())) { - MappingNode seq = (MappingNode) valueNode; - if (seq.getValue().isEmpty()) { - return null; // skip empty maps - } - } - } - return tuple; - } - // End of borrowed code -} diff --git a/src/main/java/wecui/event/command/CommandEventBase.java b/src/main/java/wecui/event/command/CommandEventBase.java deleted file mode 100644 index 7c5af958..00000000 --- a/src/main/java/wecui/event/command/CommandEventBase.java +++ /dev/null @@ -1,37 +0,0 @@ -package wecui.event.command; - -import wecui.WorldEditCUI; -import wecui.fevents.Cancellable; - -/** - * Base event for /commands being sent from the client to the server - * Serves to clean the individual commands into unique classes - * - * @author yetanotherx - * - */ -public abstract class CommandEventBase implements Cancellable { - - protected WorldEditCUI controller; - protected String[] args; - protected boolean cancelled = false; - - public CommandEventBase(WorldEditCUI controller, String[] args) { - this.controller = controller; - this.args = args; - } - - public abstract String getCommand(); - - public abstract void run(); - - @Override - public boolean isCancelled() { - return this.cancelled; - } - - @Override - public void setCancelled(boolean cancelled) { - this.cancelled = cancelled; - } -} diff --git a/src/main/java/wecui/event/command/CommandEventType.java b/src/main/java/wecui/event/command/CommandEventType.java deleted file mode 100644 index c60015bf..00000000 --- a/src/main/java/wecui/event/command/CommandEventType.java +++ /dev/null @@ -1,45 +0,0 @@ -package wecui.event.command; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * Enum for command events. Stores the event class and any aliases. - * - * @author yetanotherx - * - */ -public enum CommandEventType { - - VERSION(VersionCommandEvent.class, "ver"); - protected final Class eventClass; - protected List aliases; - - private CommandEventType(Class eventClass) { - this.eventClass = eventClass; - this.aliases = new ArrayList(); - } - - private CommandEventType(Class eventClass, String... aliases) { - this.eventClass = eventClass; - this.aliases = Arrays.asList(aliases); - } - - public Class getEventClass() { - return this.eventClass; - } - - public List getAliases() { - return this.aliases; - } - - public static CommandEventType getTypeFromCommand(String key) { - for (CommandEventType value : CommandEventType.values()) { - if (value.name().toLowerCase().equals(key) || value.getAliases().contains(key)) { - return value; - } - } - return null; - } -} diff --git a/src/main/java/wecui/event/command/VersionCommandEvent.java b/src/main/java/wecui/event/command/VersionCommandEvent.java deleted file mode 100644 index ee05dd40..00000000 --- a/src/main/java/wecui/event/command/VersionCommandEvent.java +++ /dev/null @@ -1,32 +0,0 @@ -package wecui.event.command; - -import net.minecraft.src.EntityClientPlayerMP; -import wecui.WorldEditCUI; -import wecui.util.ChatColor; - -/** - * Called when /we version is called. Inserts a WECUI version message. - * - * @author yetanotherx - * - */ -public class VersionCommandEvent extends CommandEventBase { - - public VersionCommandEvent(WorldEditCUI controller, String[] args) { - super(controller, args); - } - - @Override - public String getCommand() { - return "version"; - } - - @Override - public void run() { - EntityClientPlayerMP thePlayer = this.controller.getMinecraft().thePlayer; - if (thePlayer != null) - { - thePlayer.addChatMessage(ChatColor.LIGHT_PURPLE + "WorldEditCUI version " + WorldEditCUI.getVersion()); - } - } -} diff --git a/src/main/java/wecui/event/cui/CUIEventType.java b/src/main/java/wecui/event/cui/CUIEventType.java index 9112476d..6d540b4d 100644 --- a/src/main/java/wecui/event/cui/CUIEventType.java +++ b/src/main/java/wecui/event/cui/CUIEventType.java @@ -14,7 +14,8 @@ public enum CUIEventType { ELLIPSOID(CUIEllipsoidEvent.class, "e", 4), CYLINDER(CUICylinderEvent.class, "cyl", 5), MINMAX(CUIMinMaxEvent.class, "mm", 2), - UPDATE(CUIUpdateEvent.class, "u", 1); + UPDATE(CUIUpdateEvent.class, "u", 1), + POLYGON(CUIPolygonEvent.class, "poly", 3, 99); private final Class eventClass; private final String key; diff --git a/src/main/java/wecui/event/cui/CUIPointEvent.java b/src/main/java/wecui/event/cui/CUIPointEvent.java index e75ba76d..14f25882 100644 --- a/src/main/java/wecui/event/cui/CUIPointEvent.java +++ b/src/main/java/wecui/event/cui/CUIPointEvent.java @@ -22,9 +22,9 @@ public CUIEventType getEventType() { @Override public String run() { int id = this.getInt(0); - int x = this.getInt(1); - int y = this.getInt(2); - int z = this.getInt(3); + double x = this.getDouble(1); + double y = this.getDouble(2); + double z = this.getDouble(3); this.controller.getSelection().setCuboidPoint(id, x, y, z); this.setLocalPoint(id, x, y, z); @@ -33,7 +33,7 @@ public String run() { return null; } - protected void setLocalPoint(int id, int x, int y, int z) { + protected void setLocalPoint(int id, double x, double y, double z) { /*if (controller.getLocalPlugin().isEnabled()) { WorldEdit plugin = controller.getLocalPlugin().getPlugin(); diff --git a/src/main/java/wecui/event/cui/CUIPolygonEvent.java b/src/main/java/wecui/event/cui/CUIPolygonEvent.java new file mode 100644 index 00000000..6199a66b --- /dev/null +++ b/src/main/java/wecui/event/cui/CUIPolygonEvent.java @@ -0,0 +1,34 @@ +package wecui.event.cui; + +import wecui.WorldEditCUI; + +/** + * Called when polygon event is received + * + * @author lahwran + * @author yetanotherx + */ +public class CUIPolygonEvent extends CUIBaseEvent { + + public CUIPolygonEvent(WorldEditCUI controller, String[] args) { + super(controller, args); + } + + @Override + public CUIEventType getEventType() { + return CUIEventType.POLYGON; + } + + @Override + public String run() { + final int[] vertexIds = new int[args.length]; + for (int i = 0; i < args.length; ++i) { + vertexIds[i] = this.getInt(i); + } + + this.controller.getSelection().addPolygon(vertexIds); + //this.controller.getDebugger().debug("Setting point #" + id); + + return null; + } +} diff --git a/src/main/java/wecui/event/cui/CUISelectionEvent.java b/src/main/java/wecui/event/cui/CUISelectionEvent.java index 9d0320fd..1062d1b6 100644 --- a/src/main/java/wecui/event/cui/CUISelectionEvent.java +++ b/src/main/java/wecui/event/cui/CUISelectionEvent.java @@ -6,6 +6,7 @@ import wecui.render.region.CylinderRegion; import wecui.render.region.EllipsoidRegion; import wecui.render.region.PolygonRegion; +import wecui.render.region.PolyhedronRegion; /** * Called when selection event is received @@ -37,8 +38,10 @@ public String run() { newRegion = new EllipsoidRegion(this.controller); } else if (this.getString(0).equals("cylinder")) { newRegion = new CylinderRegion(this.controller); + } else if (this.getString(0).equals("polyhedron")) { + newRegion = new PolyhedronRegion(this.controller); } else { - return "Invalid selection type. Must be cuboid|polygon2d|ellipsoid|cylinder."; + return "Invalid selection type. Must be cuboid|polygon2d|ellipsoid|cylinder|polyhedron."; } this.controller.setSelection(newRegion); diff --git a/src/main/java/wecui/event/listeners/WorldEditCommandListener.java b/src/main/java/wecui/event/listeners/WorldEditCommandListener.java deleted file mode 100644 index 57e877dd..00000000 --- a/src/main/java/wecui/event/listeners/WorldEditCommandListener.java +++ /dev/null @@ -1,48 +0,0 @@ -package wecui.event.listeners; - -import wecui.WorldEditCUI; -import wecui.event.ChatCommandEvent; -import wecui.event.command.CommandEventBase; -import wecui.event.command.CommandEventType; -import wecui.exception.ReflectException; -import wecui.fevents.Listener; -import wecui.vendor.org.joor.Reflect; - -/** - * Parses outgoing commands, and checks if they match an existing command. - * - * @author lahwran - * @author yetanotherx - * - */ -public class WorldEditCommandListener implements Listener { - - protected WorldEditCUI controller; - - public WorldEditCommandListener(WorldEditCUI controller) { - this.controller = controller; - } - - @Override - public void onEvent(ChatCommandEvent event) { - if (event.getArgs().length == 0) { - return; - } - - CommandEventType commEventType = CommandEventType.getTypeFromCommand(event.getArgs()[0]); - - if (commEventType != null) { - try { - CommandEventBase newEvent = Reflect.on(commEventType.getEventClass()).create(this.controller, event.getArgs()).get(); - newEvent.run(); - - if (newEvent.isCancelled()) { - event.setCancelled(true); - } - - } catch (ReflectException ex) { - } - - } - } -} diff --git a/src/main/java/wecui/event/listeners/WorldRenderListener.java b/src/main/java/wecui/event/listeners/WorldRenderListener.java index 16a4ef0c..87cc7ef9 100644 --- a/src/main/java/wecui/event/listeners/WorldRenderListener.java +++ b/src/main/java/wecui/event/listeners/WorldRenderListener.java @@ -1,6 +1,6 @@ package wecui.event.listeners; -import net.minecraft.src.EntityClientPlayerMP; +import net.minecraft.client.entity.EntityClientPlayerMP; import org.lwjgl.opengl.GL11; diff --git a/src/main/java/wecui/render/LineColor.java b/src/main/java/wecui/render/LineColor.java index 2833b0f5..b1843e10 100644 --- a/src/main/java/wecui/render/LineColor.java +++ b/src/main/java/wecui/render/LineColor.java @@ -2,6 +2,8 @@ import org.lwjgl.opengl.GL11; +import wecui.config.Colour; + /** * Stores color data for each type of line. * @@ -35,8 +37,8 @@ private LineColor(float r, float g, float b) { this.hidden = new LineInfo(3.0f, r, g, b, 0.2f, GL11.GL_GEQUAL); } - private LineColor(String hex) { - this.setColor(hex); + private LineColor(Colour colour) { + this.setColor(colour); } public LineInfo getHidden() { @@ -55,16 +57,9 @@ public LineInfo[] getColors() { * Parses a hex string (#FFFFFF) into each color, and makes a LineInfo. * @param hex */ - public void setColor(String hex) { - Integer r = Integer.parseInt(hex.substring(1, 3), 16); - Integer g = Integer.parseInt(hex.substring(3, 5), 16); - Integer b = Integer.parseInt(hex.substring(5, 7), 16); - - float rF = r.floatValue() / 256.0F; - float gF = g.floatValue() / 256.0F; - float bF = b.floatValue() / 256.0F; + public void setColor(Colour colour) { - this.normal = new LineInfo(3.0f, rF, gF, bF, 0.8f, GL11.GL_LESS); - this.hidden = new LineInfo(3.0f, rF, gF, bF, 0.2f, GL11.GL_GEQUAL); + this.normal = new LineInfo(3.0f, colour.red(), colour.green(), colour.blue(), 0.8f, GL11.GL_LESS); + this.hidden = new LineInfo(3.0f, colour.red(), colour.green(), colour.blue(), 0.2f, GL11.GL_GEQUAL); } } diff --git a/src/main/java/wecui/render/region/BaseRegion.java b/src/main/java/wecui/render/region/BaseRegion.java index 6a37a444..8abd5a6f 100644 --- a/src/main/java/wecui/render/region/BaseRegion.java +++ b/src/main/java/wecui/render/region/BaseRegion.java @@ -25,7 +25,7 @@ public void initialize() { public abstract void render(); - public void setCuboidPoint(int id, int x, int y, int z) { + public void setCuboidPoint(int id, double x, double y, double z) { } public void setPolygonPoint(int id, int x, int z) { @@ -46,5 +46,8 @@ public void setCylinderCenter(int x, int y, int z) { public void setCylinderRadius(double x, double z) { } + public void addPolygon(int[] vertexIds) { + } + public abstract RegionType getType(); } diff --git a/src/main/java/wecui/render/region/CuboidRegion.java b/src/main/java/wecui/render/region/CuboidRegion.java index 8217c88d..8afae64f 100644 --- a/src/main/java/wecui/render/region/CuboidRegion.java +++ b/src/main/java/wecui/render/region/CuboidRegion.java @@ -41,7 +41,7 @@ public void render() { } @Override - public void setCuboidPoint(int id, int x, int y, int z) { + public void setCuboidPoint(int id, double x, double y, double z) { if (id == 0) { this.firstPoint = new PointCube(x, y, z); this.firstPoint.setColor(LineColor.CUBOIDPOINT1); diff --git a/src/main/java/wecui/render/region/PolyhedronRegion.java b/src/main/java/wecui/render/region/PolyhedronRegion.java new file mode 100644 index 00000000..831d1c88 --- /dev/null +++ b/src/main/java/wecui/render/region/PolyhedronRegion.java @@ -0,0 +1,73 @@ +package wecui.render.region; + +import java.util.ArrayList; +import java.util.List; + +import wecui.WorldEditCUI; +import wecui.render.LineColor; +import wecui.render.points.PointCube; +import wecui.render.shapes.Render3DPolygon; +import wecui.util.Vector3; + +/** + * Main controller for a polygon-type region + * + * @author TomyLobo + */ +public class PolyhedronRegion extends BaseRegion { + + protected List vertices = new ArrayList(); + protected List faces = new ArrayList(); + + public PolyhedronRegion(WorldEditCUI controller) { + super(controller); + } + + @Override + public void render() { + for (PointCube vertex : this.vertices) { + vertex.render(); + } + + for (Vector3[] face : this.faces) { + new Render3DPolygon(LineColor.POLYBOX, face).render(); + } + } + + @Override + public void setCuboidPoint(int id, double x, double y, double z) { + final PointCube vertex = new PointCube(x, y, z); + vertex.setColor(id == 0 ? LineColor.CUBOIDPOINT1 : LineColor.POLYPOINT); + + if (id < this.vertices.size()) { + this.vertices.set(id, vertex); + } else { + for (int i = 0; i < id - this.vertices.size(); i++) { + this.vertices.add(null); + } + this.vertices.add(vertex); + } + } + + private static final Vector3 half = new Vector3(0.5, 0.5, 0.5); + + @Override + public void addPolygon(int[] vertexIds) { + final Vector3[] face = new Vector3[vertexIds.length]; + for (int i = 0; i < vertexIds.length; ++i) { + final PointCube vertex = vertices.get(vertexIds[i]); + if (vertex == null) { + // This should never happen + return; + } + + face[i] = vertex.getPoint().add(half); + } + faces.add(face); + } + + @Override + public RegionType getType() { + return RegionType.POLYHEDRON; + } +} diff --git a/src/main/java/wecui/render/region/RegionType.java b/src/main/java/wecui/render/region/RegionType.java index a24ab3c0..33345f95 100644 --- a/src/main/java/wecui/render/region/RegionType.java +++ b/src/main/java/wecui/render/region/RegionType.java @@ -10,6 +10,7 @@ public enum RegionType { CUBOID, POLYGON, ELLIPSOID, - CYLINDER + CYLINDER, + POLYHEDRON } diff --git a/src/main/java/wecui/render/shapes/Render2DBox.java b/src/main/java/wecui/render/shapes/Render2DBox.java index fb8fc327..ba558531 100644 --- a/src/main/java/wecui/render/shapes/Render2DBox.java +++ b/src/main/java/wecui/render/shapes/Render2DBox.java @@ -2,7 +2,7 @@ import java.util.List; -import net.minecraft.src.Tessellator; +import net.minecraft.client.renderer.Tessellator; import org.lwjgl.opengl.GL11; diff --git a/src/main/java/wecui/render/shapes/Render2DGrid.java b/src/main/java/wecui/render/shapes/Render2DGrid.java index f27caf71..013314e7 100644 --- a/src/main/java/wecui/render/shapes/Render2DGrid.java +++ b/src/main/java/wecui/render/shapes/Render2DGrid.java @@ -2,7 +2,7 @@ import java.util.List; -import net.minecraft.src.Tessellator; +import net.minecraft.client.renderer.Tessellator; import org.lwjgl.opengl.GL11; diff --git a/src/main/java/wecui/render/shapes/Render3DBox.java b/src/main/java/wecui/render/shapes/Render3DBox.java index 7cbbe866..34c67178 100644 --- a/src/main/java/wecui/render/shapes/Render3DBox.java +++ b/src/main/java/wecui/render/shapes/Render3DBox.java @@ -1,6 +1,6 @@ package wecui.render.shapes; -import net.minecraft.src.Tessellator; +import net.minecraft.client.renderer.Tessellator; import org.lwjgl.opengl.GL11; diff --git a/src/main/java/wecui/render/shapes/Render3DGrid.java b/src/main/java/wecui/render/shapes/Render3DGrid.java index ea02d5d1..6e381b8f 100644 --- a/src/main/java/wecui/render/shapes/Render3DGrid.java +++ b/src/main/java/wecui/render/shapes/Render3DGrid.java @@ -1,6 +1,6 @@ package wecui.render.shapes; -import net.minecraft.src.Tessellator; +import net.minecraft.client.renderer.Tessellator; import org.lwjgl.opengl.GL11; diff --git a/src/main/java/wecui/render/shapes/Render3DPolygon.java b/src/main/java/wecui/render/shapes/Render3DPolygon.java new file mode 100644 index 00000000..a734de46 --- /dev/null +++ b/src/main/java/wecui/render/shapes/Render3DPolygon.java @@ -0,0 +1,41 @@ +package wecui.render.shapes; + +import net.minecraft.client.renderer.Tessellator; + +import org.lwjgl.opengl.GL11; + +import wecui.render.LineColor; +import wecui.render.LineInfo; +import wecui.util.Vector3; + +/** + * Draws a polygon + * + * @author yetanotherx + * @author lahwran + */ +public class Render3DPolygon { + + protected LineColor color; + protected Vector3[] vertices; + + public Render3DPolygon(LineColor color, Vector3... vertices) { + this.color = color; + this.vertices = vertices; + } + + public void render() { + Tessellator tess = Tessellator.instance; + + for (LineInfo tempColor : this.color.getColors()) { + tempColor.prepareRender(); + + tess.startDrawing(GL11.GL_LINE_LOOP); + tempColor.prepareColor(); + for (Vector3 vertex : vertices) { + tess.addVertex(vertex.getX(), vertex.getY(), vertex.getZ()); + } + tess.draw(); + } + } +} diff --git a/src/main/java/wecui/render/shapes/RenderCylinderBox.java b/src/main/java/wecui/render/shapes/RenderCylinderBox.java index 92decc85..6d954aa8 100644 --- a/src/main/java/wecui/render/shapes/RenderCylinderBox.java +++ b/src/main/java/wecui/render/shapes/RenderCylinderBox.java @@ -1,6 +1,6 @@ package wecui.render.shapes; -import net.minecraft.src.Tessellator; +import net.minecraft.client.renderer.Tessellator; import org.lwjgl.opengl.GL11; diff --git a/src/main/java/wecui/render/shapes/RenderCylinderCircles.java b/src/main/java/wecui/render/shapes/RenderCylinderCircles.java index 50e1d940..1ec0aaaf 100644 --- a/src/main/java/wecui/render/shapes/RenderCylinderCircles.java +++ b/src/main/java/wecui/render/shapes/RenderCylinderCircles.java @@ -1,6 +1,6 @@ package wecui.render.shapes; -import net.minecraft.src.Tessellator; +import net.minecraft.client.renderer.Tessellator; import org.lwjgl.opengl.GL11; diff --git a/src/main/java/wecui/render/shapes/RenderCylinderGrid.java b/src/main/java/wecui/render/shapes/RenderCylinderGrid.java index fd008d9a..b8b1ef02 100644 --- a/src/main/java/wecui/render/shapes/RenderCylinderGrid.java +++ b/src/main/java/wecui/render/shapes/RenderCylinderGrid.java @@ -1,6 +1,6 @@ package wecui.render.shapes; -import net.minecraft.src.Tessellator; +import net.minecraft.client.renderer.Tessellator; import org.lwjgl.opengl.GL11; diff --git a/src/main/java/wecui/render/shapes/RenderEllipsoid.java b/src/main/java/wecui/render/shapes/RenderEllipsoid.java index d16199b3..885bd9e9 100644 --- a/src/main/java/wecui/render/shapes/RenderEllipsoid.java +++ b/src/main/java/wecui/render/shapes/RenderEllipsoid.java @@ -1,6 +1,6 @@ package wecui.render.shapes; -import net.minecraft.src.Tessellator; +import net.minecraft.client.renderer.Tessellator; import org.lwjgl.opengl.GL11; diff --git a/src/main/resources/Configuration.yml b/src/main/resources/Configuration.yml deleted file mode 100644 index b72df809..00000000 --- a/src/main/resources/Configuration.yml +++ /dev/null @@ -1,20 +0,0 @@ -colors: - cuboidGrid: '#CC3333' - cuboidEdge: '#CC4C4C' - cuboidFirstPoint: '#33CC33' - cuboidSecondPoint: '#3333CC' - - cylinderEdge: '#CC4C4C' - cylinderGrid: '#CC3333' - cylinderPoint: '#CC33CC' - - polyGrid: '#CC3333' - polyEdge: '#CC4C4C' - polyPoint: '#33CCCC' - - ellipsoidGrid: '#CC4C4C' - ellipsoidPoint: '#CCCC33' - -debug: false - -ignoreUpdates: false \ No newline at end of file diff --git a/updates.yml b/updates.yml deleted file mode 100644 index fd9109e5..00000000 --- a/updates.yml +++ /dev/null @@ -1,6 +0,0 @@ -updaterVersion1: - current: 1.4.6 - supported: - - 1.4.5 -# - 1.3.1 - From 7a8ef08872980f22d7d85ec4ec381147e8e33aac Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Tue, 3 Dec 2013 18:07:14 +0000 Subject: [PATCH 06/51] WorldEditCUI for 1.7.2 - preliminary Updated eclipse classpath file --- .classpath | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.classpath b/.classpath index 7e98e623..490f94f7 100644 --- a/.classpath +++ b/.classpath @@ -4,10 +4,7 @@ - - - - - + + From 15bd8d38d26ad376c06fa8a5de000bc9260329a0 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Tue, 21 Jan 2014 16:35:42 +0000 Subject: [PATCH 07/51] WorldEditCUI 1.7.2_02 - add ingame colour config --- .classpath | 1 + .gitignore | 2 + .project | 5 + build/build_wecui.xml | 19 +- build/buildnumber.txt | 4 +- repackaging.txt | 7 - src/main/java/wecui/LiteModWorldEditCUI.java | 88 ++- src/main/java/wecui/WorldEditCUI.java | 13 +- .../java/wecui/config/CUIConfiguration.java | 76 +-- src/main/java/wecui/config/Colour.java | 50 +- .../event/listeners/WorldRenderListener.java | 5 +- src/main/java/wecui/gui/GuiColourButton.java | 156 +++++ src/main/java/wecui/gui/GuiColourPicker.java | 337 +++++++++ src/main/java/wecui/gui/GuiControl.java | 642 ++++++++++++++++++ .../wecui/gui/WorldEditCUIConfigPanel.java | 191 ++++++ src/main/java/wecui/render/LineColor.java | 93 ++- .../wecui/render/region/CuboidRegion.java | 7 +- .../resources/assets/wecui/lang/en_US.lang | 20 + .../assets/wecui/textures/gui/checker.png | Bin 0 -> 972 bytes .../assets/wecui/textures/gui/picker.png | Bin 0 -> 2358 bytes 20 files changed, 1591 insertions(+), 125 deletions(-) create mode 100644 .gitignore delete mode 100644 repackaging.txt create mode 100644 src/main/java/wecui/gui/GuiColourButton.java create mode 100644 src/main/java/wecui/gui/GuiColourPicker.java create mode 100644 src/main/java/wecui/gui/GuiControl.java create mode 100644 src/main/java/wecui/gui/WorldEditCUIConfigPanel.java create mode 100644 src/main/resources/assets/wecui/lang/en_US.lang create mode 100644 src/main/resources/assets/wecui/textures/gui/checker.png create mode 100644 src/main/resources/assets/wecui/textures/gui/picker.png diff --git a/.classpath b/.classpath index 490f94f7..104b1ead 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,7 @@ + diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..d8bab97f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +bin +.settings \ No newline at end of file diff --git a/.project b/.project index decc1cc2..35052922 100644 --- a/.project +++ b/.project @@ -25,6 +25,11 @@ 2 PROJECT_LOC/src/main/resources + + resources + 2 + PROJECT_LOC/src/main/resources + diff --git a/build/build_wecui.xml b/build/build_wecui.xml index c86432ab..d26ab14e 100644 --- a/build/build_wecui.xml +++ b/build/build_wecui.xml @@ -4,9 +4,9 @@ - - - + + + @@ -18,13 +18,13 @@ - - + + @@ -97,9 +97,13 @@ + + + + @@ -108,7 +112,7 @@ - + @@ -125,8 +129,7 @@ - - + diff --git a/build/buildnumber.txt b/build/buildnumber.txt index 926ba844..057728b8 100644 --- a/build/buildnumber.txt +++ b/build/buildnumber.txt @@ -1,3 +1,3 @@ #Build Number for ANT. Do not edit! -#Mon Dec 02 23:30:17 GMT 2013 -build.number=1626 +#Fri Jan 10 14:58:39 GMT 2014 +build.number=1638 diff --git a/repackaging.txt b/repackaging.txt deleted file mode 100644 index adc0613e..00000000 --- a/repackaging.txt +++ /dev/null @@ -1,7 +0,0 @@ -renames: - - notch: - wecui: deobf - - notch: wecui.vendor.org.yaml.\1 - wecui: org.yaml.(.*) - - notch: wecui.vendor.com.sk89q.\1 - wecui: com.sk89q.(.*) \ No newline at end of file diff --git a/src/main/java/wecui/LiteModWorldEditCUI.java b/src/main/java/wecui/LiteModWorldEditCUI.java index edba5c7c..7a4404d2 100644 --- a/src/main/java/wecui/LiteModWorldEditCUI.java +++ b/src/main/java/wecui/LiteModWorldEditCUI.java @@ -5,37 +5,52 @@ import java.util.Arrays; import java.util.List; +import org.lwjgl.input.Keyboard; + import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.settings.KeyBinding; import net.minecraft.network.INetHandler; import net.minecraft.network.play.server.S01PacketJoinGame; import wecui.event.ChannelEvent; import wecui.event.WorldRenderEvent; +import wecui.gui.WorldEditCUIConfigPanel; import wecui.render.region.CuboidRegion; +import com.mumfrey.liteloader.Configurable; import com.mumfrey.liteloader.InitCompleteListener; import com.mumfrey.liteloader.PluginChannelListener; import com.mumfrey.liteloader.PostRenderListener; +import com.mumfrey.liteloader.core.ClientPluginChannels; import com.mumfrey.liteloader.core.LiteLoader; -import com.mumfrey.liteloader.core.PluginChannels; +import com.mumfrey.liteloader.core.PluginChannels.ChannelPolicy; +import com.mumfrey.liteloader.modconfig.ConfigPanel; +import com.mumfrey.liteloader.util.ModUtilities; -public class LiteModWorldEditCUI implements InitCompleteListener, PluginChannelListener, PostRenderListener +public class LiteModWorldEditCUI implements InitCompleteListener, PluginChannelListener, PostRenderListener, Configurable { private static final String CHANNEL_WECUI = "WECUI"; - protected WorldEditCUI controller; - protected WorldClient lastWorld; - protected EntityPlayerSP lastPlayer; - protected boolean gameStarted = false; - public final static Charset UTF_8_CHARSET = Charset.forName("UTF-8"); - protected int entityUpdateTickCount = 0; - protected WorldRenderEvent event; - + private final static Charset UTF_8_CHARSET = Charset.forName("UTF-8"); + + private WorldEditCUI controller; + private WorldClient lastWorld; + private EntityPlayerSP lastPlayer; + private boolean gameStarted = false; + private WorldRenderEvent event; + + private KeyBinding keyBindToggleUI = new KeyBinding("wecui.keys.toggle", Keyboard.KEY_NONE, "wecui.keys.category"); + private KeyBinding keyBindClearSel = new KeyBinding("wecui.keys.clear", Keyboard.KEY_NONE, "wecui.keys.category"); + + private boolean visible = true; + @Override public void init(File configPath) { + ModUtilities.registerKey(this.keyBindToggleUI); + ModUtilities.registerKey(this.keyBindClearSel); } @Override @@ -55,10 +70,19 @@ public void onInitCompleted(Minecraft minecraft, LiteLoader loader) } @Override - public void onLogin(INetHandler netHandler, S01PacketJoinGame loginPacket) + public void onJoinGame(INetHandler netHandler, S01PacketJoinGame loginPacket) + { + this.visible = true; + this.helo(); + } + + /** + * + */ + private void helo() { byte[] buffer = ("v|" + WorldEditCUI.protocolVersion).getBytes(UTF_8_CHARSET); - PluginChannels.sendMessage(CHANNEL_WECUI, buffer); + ClientPluginChannels.sendMessage(CHANNEL_WECUI, buffer, ChannelPolicy.DISPATCH_ALWAYS); } @Override @@ -77,6 +101,19 @@ public void onCustomPayload(String channel, int length, byte[] data) @Override public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clock) { + if (inGame && mc.currentScreen == null) + { + if (this.keyBindToggleUI.isPressed()) + { + this.visible = !this.visible; + } + + if (this.keyBindClearSel.isPressed()) + { + if (mc.thePlayer != null) mc.thePlayer.sendChatMessage("//sel"); + } + } + if (inGame && clock && this.controller != null) { if (mc.theWorld != this.lastWorld || mc.thePlayer != this.lastPlayer) { @@ -87,6 +124,7 @@ public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clo this.gameStarted = true; this.controller.setSelection(new CuboidRegion(this.controller)); + this.helo(); } } } @@ -101,21 +139,35 @@ public String getName() @Override public String getVersion() { - return "1.7.2"; + return "1.7.2_02"; + } + + @Override + public Class getConfigPanelClass() + { + return WorldEditCUIConfigPanel.class; } @Override public void onPostRenderEntities(float partialTicks) { - RenderHelper.disableStandardItemLighting(); - OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); - this.event.setPartialTick(partialTicks); - this.controller.getEventManager().callEvent(this.event); - RenderHelper.enableStandardItemLighting(); + if (this.visible && this.event != null) + { + RenderHelper.disableStandardItemLighting(); + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); + this.event.setPartialTick(partialTicks); + this.controller.getEventManager().callEvent(this.event); + RenderHelper.enableStandardItemLighting(); + } } @Override public void onPostRender(float partialTicks) { } + + public WorldEditCUI getController() + { + return this.controller; + } } diff --git a/src/main/java/wecui/WorldEditCUI.java b/src/main/java/wecui/WorldEditCUI.java index 786b8001..e9334bb0 100644 --- a/src/main/java/wecui/WorldEditCUI.java +++ b/src/main/java/wecui/WorldEditCUI.java @@ -27,13 +27,12 @@ public class WorldEditCUI { public static final int protocolVersion = 3; - protected Minecraft minecraft; - protected EventManager eventManager; - protected BaseRegion selection; - protected CUIDebug debugger; - protected CUIConfiguration configuration; - //protected LocalPlugin localPlugin; - + private Minecraft minecraft; + private EventManager eventManager; + private BaseRegion selection; + private CUIDebug debugger; + private CUIConfiguration configuration; + public WorldEditCUI(Minecraft minecraft) { this.minecraft = minecraft; } diff --git a/src/main/java/wecui/config/CUIConfiguration.java b/src/main/java/wecui/config/CUIConfiguration.java index 32ce58b1..a8cad45d 100644 --- a/src/main/java/wecui/config/CUIConfiguration.java +++ b/src/main/java/wecui/config/CUIConfiguration.java @@ -22,21 +22,21 @@ public class CUIConfiguration implements InitializationFactory { private static Gson gson = new GsonBuilder().setPrettyPrinting().create(); - protected boolean debugMode = false; - protected boolean ignoreUpdates = false; + private boolean debugMode = false; + private boolean ignoreUpdates = false; - private Colour cuboidGridColor = new Colour("#CC3333"); - private Colour cuboidEdgeColor = new Colour("#CC4C4C"); - private Colour cuboidFirstPointColor = new Colour("#33CC33"); - private Colour cuboidSecondPointColor = new Colour("#3333CC"); - private Colour polyGridColor = new Colour("#CC3333"); - private Colour polyEdgeColor = new Colour("#CC4C4C"); - private Colour polyPointColor = new Colour("#33CCCC"); - private Colour ellipsoidGridColor = new Colour("#CC4C4C"); - private Colour ellipsoidPointColor = new Colour("#CCCC33"); - private Colour cylinderGridColor = new Colour("#CC3333"); - private Colour cylinderEdgeColor = new Colour("#CC4C4C"); - private Colour cylinderPointColor = new Colour("#CC33CC"); + private Colour cuboidGridColor = new Colour("#CC3333CC"); + private Colour cuboidEdgeColor = new Colour("#CC4C4CCC"); + private Colour cuboidFirstPointColor = new Colour("#33CC33CC"); + private Colour cuboidSecondPointColor = new Colour("#3333CCCC"); + private Colour polyGridColor = new Colour("#CC3333CC"); + private Colour polyEdgeColor = new Colour("#CC4C4CCC"); + private Colour polyPointColor = new Colour("#33CCCCCC"); + private Colour ellipsoidGridColor = new Colour("#CC4C4CCC"); + private Colour ellipsoidPointColor = new Colour("#CCCC33CC"); + private Colour cylinderGridColor = new Colour("#CC3333CC"); + private Colour cylinderEdgeColor = new Colour("#CC4C4CCC"); + private Colour cylinderPointColor = new Colour("#CC33CCCC"); /** * Copies the default config file to the proper directory if it does not @@ -45,31 +45,31 @@ public class CUIConfiguration implements InitializationFactory @Override public void initialize() { - this.cuboidGridColor = Colour.setDefault(this.cuboidGridColor, "#CC3333"); - this.cuboidEdgeColor = Colour.setDefault(this.cuboidEdgeColor, "#CC4C4C"); - this.cuboidFirstPointColor = Colour.setDefault(this.cuboidFirstPointColor, "#33CC33"); - this.cuboidSecondPointColor = Colour.setDefault(this.cuboidSecondPointColor, "#3333CC"); - this.polyGridColor = Colour.setDefault(this.polyGridColor, "#CC3333"); - this.polyEdgeColor = Colour.setDefault(this.polyEdgeColor, "#CC4C4C"); - this.polyPointColor = Colour.setDefault(this.polyPointColor, "#33CCCC"); - this.ellipsoidGridColor = Colour.setDefault(this.ellipsoidGridColor, "#CC4C4C"); - this.ellipsoidPointColor = Colour.setDefault(this.ellipsoidPointColor, "#CCCC33"); - this.cylinderGridColor = Colour.setDefault(this.cylinderGridColor, "#CC3333"); - this.cylinderEdgeColor = Colour.setDefault(this.cylinderEdgeColor, "#CC4C4C"); - this.cylinderPointColor = Colour.setDefault(this.cylinderPointColor, "#CC33CC"); + this.cuboidGridColor = Colour.setDefault(this.cuboidGridColor, "#CC3333CC"); + this.cuboidEdgeColor = Colour.setDefault(this.cuboidEdgeColor, "#CC4C4CCC"); + this.cuboidFirstPointColor = Colour.setDefault(this.cuboidFirstPointColor, "#33CC33CC"); + this.cuboidSecondPointColor = Colour.setDefault(this.cuboidSecondPointColor, "#3333CCCC"); + this.polyGridColor = Colour.setDefault(this.polyGridColor, "#CC3333CC"); + this.polyEdgeColor = Colour.setDefault(this.polyEdgeColor, "#CC4C4CCC"); + this.polyPointColor = Colour.setDefault(this.polyPointColor, "#33CCCCCC"); + this.ellipsoidGridColor = Colour.setDefault(this.ellipsoidGridColor, "#CC4C4CCC"); + this.ellipsoidPointColor = Colour.setDefault(this.ellipsoidPointColor, "#CCCC33CC"); + this.cylinderGridColor = Colour.setDefault(this.cylinderGridColor, "#CC3333CC"); + this.cylinderEdgeColor = Colour.setDefault(this.cylinderEdgeColor, "#CC4C4CCC"); + this.cylinderPointColor = Colour.setDefault(this.cylinderPointColor, "#CC33CCCC"); - LineColor.CUBOIDBOX.setColor(this.cuboidEdgeColor); - LineColor.CUBOIDGRID.setColor(this.cuboidGridColor); - LineColor.CUBOIDPOINT1.setColor(this.cuboidFirstPointColor); - LineColor.CUBOIDPOINT2.setColor(this.cuboidSecondPointColor); - LineColor.POLYGRID.setColor(this.polyGridColor); - LineColor.POLYBOX.setColor(this.polyEdgeColor); - LineColor.POLYPOINT.setColor(this.polyPointColor); - LineColor.ELLIPSOIDGRID.setColor(this.ellipsoidGridColor); - LineColor.ELLIPSOIDCENTER.setColor(this.ellipsoidPointColor); - LineColor.CYLINDERGRID.setColor(this.cylinderGridColor); - LineColor.CYLINDERBOX.setColor(this.cylinderEdgeColor); - LineColor.CYLINDERCENTER.setColor(this.cylinderPointColor); + LineColor.CUBOIDBOX.setColour(this.cuboidEdgeColor); + LineColor.CUBOIDGRID.setColour(this.cuboidGridColor); + LineColor.CUBOIDPOINT1.setColour(this.cuboidFirstPointColor); + LineColor.CUBOIDPOINT2.setColour(this.cuboidSecondPointColor); + LineColor.POLYGRID.setColour(this.polyGridColor); + LineColor.POLYBOX.setColour(this.polyEdgeColor); + LineColor.POLYPOINT.setColour(this.polyPointColor); + LineColor.ELLIPSOIDGRID.setColour(this.ellipsoidGridColor); + LineColor.ELLIPSOIDCENTER.setColour(this.ellipsoidPointColor); + LineColor.CYLINDERGRID.setColour(this.cylinderGridColor); + LineColor.CYLINDERBOX.setColour(this.cylinderEdgeColor); + LineColor.CYLINDERCENTER.setColour(this.cylinderPointColor); this.save(); } diff --git a/src/main/java/wecui/config/Colour.java b/src/main/java/wecui/config/Colour.java index ea55f828..7d3ecd67 100644 --- a/src/main/java/wecui/config/Colour.java +++ b/src/main/java/wecui/config/Colour.java @@ -53,32 +53,60 @@ else if (!colour.startsWith("#")) { return def; } - else if (colour.length() != 7) + else if (colour.length() != 7 && colour.length() != 9) { return def; } - return (colour.matches("(?i)^#[0-9a-f]{6}$")) ? colour : def; + return (colour.matches("(?i)^#[0-9a-f]{6,8}$")) ? colour : def; } - public float red() + public void setHex(String hex) + { + if (hex.length() < 8) hex = "00000000".substring(0, 8 - hex.length()) + hex; + this.hex = "#" + hex; + } + + public String getHex() { if (this.hex == null) this.hex = this.defaultColour; - Integer r = Integer.parseInt(this.hex.substring(1, 3), 16); - return (r.floatValue() / 256.0F); + if (this.hex.length() == 7) this.hex = this.hex + "CC"; + return this.hex; + } + + public int getIntARGB() + { + String hex = this.getHex(); + return (int)Long.parseLong(hex.substring(7, 9) + hex.substring(1, 7), 16); + } + + public float red() + { + String hex = this.getHex(); + return (((Integer)Integer.parseInt(hex.substring(1, 3), 16)).floatValue() / 256.0F); } public float green() { - if (this.hex == null) this.hex = this.defaultColour; - Integer g = Integer.parseInt(hex.substring(3, 5), 16); - return (g.floatValue() / 256.0F); + String hex = this.getHex(); + return (((Integer)Integer.parseInt(hex.substring(3, 5), 16)).floatValue() / 256.0F); } public float blue() { - if (this.hex == null) this.hex = this.defaultColour; - Integer b = Integer.parseInt(hex.substring(5, 7), 16); - return (b.floatValue() / 256.0F); + String hex = this.getHex(); + return (((Integer)Integer.parseInt(hex.substring(5, 7), 16)).floatValue() / 256.0F); + } + + public float alpha() + { + String hex = this.getHex(); + return (((Integer)Integer.parseInt(hex.substring(7, 9), 16)).floatValue() / 256.0F); + } + + public Colour copyFrom(Colour other) + { + this.hex = other.getHex(); + return this; } } diff --git a/src/main/java/wecui/event/listeners/WorldRenderListener.java b/src/main/java/wecui/event/listeners/WorldRenderListener.java index 87cc7ef9..d9591c98 100644 --- a/src/main/java/wecui/event/listeners/WorldRenderListener.java +++ b/src/main/java/wecui/event/listeners/WorldRenderListener.java @@ -31,7 +31,8 @@ public WorldRenderListener(WorldEditCUI controller) { public void onEvent(WorldRenderEvent event) { GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glEnable(GL11.GL_BLEND); - //GL11.glDisable(GL11.GL_ALPHA_TEST); + GL11.glEnable(GL11.GL_ALPHA_TEST); + GL11.glAlphaFunc(GL11.GL_GREATER, 0.0F); GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glDepthMask(false); GL11.glPushMatrix(); @@ -53,7 +54,7 @@ public void onEvent(WorldRenderEvent event) { GL11.glDepthMask(true); GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glDisable(GL11.GL_BLEND); - //GL11.glEnable(GL11.GL_ALPHA_TEST); + GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F); } private double getPlayerXGuess(float renderTick) diff --git a/src/main/java/wecui/gui/GuiColourButton.java b/src/main/java/wecui/gui/GuiColourButton.java new file mode 100644 index 00000000..8b3836ee --- /dev/null +++ b/src/main/java/wecui/gui/GuiColourButton.java @@ -0,0 +1,156 @@ +package wecui.gui; + +import static org.lwjgl.opengl.GL11.*; +import wecui.render.LineColor; +import net.minecraft.client.Minecraft; + +/** + * Colour picker button control, spawns a colour picker when clicked + * + * @author Adam Mummery-Smith + */ +public class GuiColourButton extends GuiControl +{ + /** + * Picker active colour + */ + private int colour = 0xFF000000; + + private LineColor lineColour; + + private GuiColourPicker picker; + + private boolean pickerClicked = false; + + public GuiColourButton(Minecraft minecraft, int id, int xPosition, int yPosition, int controlWidth, int controlHeight, LineColor lineColour) + { + super(minecraft, id, xPosition, yPosition, controlWidth, controlHeight, lineColour.getDisplayName()); + this.lineColour = lineColour; + this.updateColour(lineColour); + } + + /** + * @param lineColour + */ + public void updateColour(LineColor lineColour) + { + if (lineColour == this.lineColour) + { + this.colour = lineColour.getColourIntARGB(); + } + } + + public int getColour() + { + return this.colour; + } + + public void save() + { + this.lineColour.setColourIntRGBA(this.colour); + } + + @Override + public void drawControl(Minecraft minecraft, int mouseX, int mouseY) + { + if (this.field_146125_m) + { + boolean mouseOver = mouseX >= this.field_146128_h && mouseY >= this.field_146129_i && mouseX < this.field_146128_h + this.field_146120_f && mouseY < this.field_146129_i + this.field_146121_g; + int borderColour = mouseOver || this.picker != null ? 0xFFFFFFFF : 0xFFA0A0A0; + + drawRect(this.field_146128_h, this.field_146129_i, this.field_146128_h + this.field_146120_f, this.field_146129_i + this.field_146121_g, borderColour); + + int v = Math.min(Math.max((int)(((float)this.field_146121_g / (float)this.field_146120_f) * 1024F), 256), 1024); + + minecraft.getTextureManager().bindTexture(GuiColourPicker.COLOURPICKER_CHECKER); + glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.drawTexturedModalRect(this.field_146128_h + 1, this.field_146129_i + 1, this.field_146128_h + this.field_146120_f - 1, this.field_146129_i + this.field_146121_g - 1, 0, 0, 1024, v); + + drawRect(this.field_146128_h + 1, this.field_146129_i + 1, this.field_146128_h + this.field_146120_f - 1, this.field_146129_i + this.field_146121_g - 1, this.colour); + + this.mouseDragged(minecraft, mouseX, mouseY); + + if (this.displayString != null && this.displayString.length() > 0) + { + this.drawString(minecraft.fontRenderer, this.displayString, this.field_146128_h + this.field_146120_f + 8, this.field_146129_i + (this.field_146121_g - 8) / 2, 0xFFFFFFFF); + } + } + } + + public void drawPicker(Minecraft minecraft, int mouseX, int mouseY) + { + if (this.field_146125_m && this.picker != null) + { + this.picker.drawButton(minecraft, mouseX, mouseY); + + if (this.picker.getDialogResult() == DialogResult.OK) + { + this.closePicker(true); + } + else if (this.picker.getDialogResult() == DialogResult.Cancel) + { + this.closePicker(false); + } + } + } + + /** + * + */ + public void closePicker(boolean getColour) + { + if (getColour) this.colour = this.picker.getColour(); + this.picker = null; + this.pickerClicked = false; + } + + /* (non-Javadoc) + * @see net.minecraft.src.GuiButton#mouseReleased(int, int) + */ + @Override + public void mouseReleased(int mouseX, int mouseY) + { + if (this.pickerClicked && this.picker != null) + { + this.picker.mouseReleased(mouseX, mouseY); + this.pickerClicked = false; + } + } + + /* (non-Javadoc) + * @see net.minecraft.src.GuiButton#mousePressed(net.minecraft.src.Minecraft, int, int) + */ + @Override + public boolean mousePressed(Minecraft minecraft, int mouseX, int mouseY) + { + boolean pressed = super.mousePressed(minecraft, mouseX, mouseY); + + if (this.picker == null) + { + if (pressed) + { + int xPos = Math.min(this.field_146128_h + this.field_146120_f, GuiControl.lastScreenWidth - 233); + int yPos = Math.min(this.field_146129_i, GuiControl.lastScreenHeight - 175); + + this.picker = new GuiColourPicker(minecraft, 1, xPos, yPos, this.colour, "Choose colour"); + this.pickerClicked = false; + } + + return pressed; + } + + this.pickerClicked = this.picker.mousePressed(minecraft, mouseX, mouseY); + + if (pressed && !this.pickerClicked) + { + this.closePicker(true); + } + + return this.pickerClicked; + } + + public boolean keyTyped(char keyChar, int keyCode) + { + return (this.picker != null) ? this.picker.textBoxKeyTyped(keyChar, keyCode) : false; + } +} diff --git a/src/main/java/wecui/gui/GuiColourPicker.java b/src/main/java/wecui/gui/GuiColourPicker.java new file mode 100644 index 00000000..2bc7d0f1 --- /dev/null +++ b/src/main/java/wecui/gui/GuiColourPicker.java @@ -0,0 +1,337 @@ +package wecui.gui; + +import static org.lwjgl.opengl.GL11.*; + +import java.awt.Color; +import java.awt.Rectangle; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiTextField; +import net.minecraft.client.resources.I18n; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.input.Keyboard; + +/** + * Colour picker flyout control, for use with the designable GUI properties window + * + * @author Adam Mummery-Smith + */ +public class GuiColourPicker extends GuiControl +{ + public static final ResourceLocation COLOURPICKER_CHECKER = new ResourceLocation("wecui", "textures/gui/checker.png"); + public static final ResourceLocation COLOURPICKER_PICKER = new ResourceLocation("wecui", "textures/gui/picker.png"); + + /** + * Indices into the hsb array + */ + private static final int H = 0, S = 1, B = 2; + + /** + * HSB values from Colour.RGBtoHSB, combined with opacity this is the authoritative version of the + * colour we are editing + */ + private float[] hsb; + + /** + * Original and altered RGB values + */ + private int rgb; + + /** + * Current opacity, stored as an offset byte in the usual position, eg. 0xFF << 24 + */ + private int opacity; + + /** + * Text boxes for manual entry + */ + private GuiTextField txtRed, txtGreen, txtBlue, txtAlpha; + + /** + * OK and cancel buttons + */ + private GuiControl btnOk, btnCancel; + + /** + * Flags to track whether dragging a slider + */ + private boolean draggingHS, draggingB, draggingA; + + /** + * Slider rects + */ + private Rectangle rectHSArea, rectBArea, rectAArea; + + /** + * Set when the user clicks ok or cancel + */ + private DialogResult result = DialogResult.None; + + private FontRenderer fontRenderer; + + public GuiColourPicker(Minecraft minecraft, int controlId, int xPos, int yPos, int initialColour, String displayText) + { + super(minecraft, controlId, xPos, yPos, 231, 173, displayText); + + Color colour = new Color(initialColour); + this.hsb = Color.RGBtoHSB(colour.getRed(), colour.getGreen(), colour.getBlue(), null); + this.opacity = initialColour & 0xFF000000; + if (this.opacity == 0x01000000) this.opacity = 0; + + this.fontRenderer = minecraft.fontRenderer; + this.txtRed = new GuiTextField(this.fontRenderer, this.field_146128_h + 188, this.field_146129_i + 10, 32, 16); + this.txtGreen = new GuiTextField(this.fontRenderer, this.field_146128_h + 188, this.field_146129_i + 30, 32, 16); + this.txtBlue = new GuiTextField(this.fontRenderer, this.field_146128_h + 188, this.field_146129_i + 50, 32, 16); + this.txtAlpha = new GuiTextField(this.fontRenderer, this.field_146128_h + 188, this.field_146129_i + 70, 32, 16); + + this.txtRed.func_146203_f(3); + this.txtGreen.func_146203_f(3); + this.txtBlue.func_146203_f(3); + this.txtAlpha.func_146203_f(3); + + this.rectHSArea = new Rectangle(this.field_146128_h + 10, this.field_146129_i + 10, 128, 128); + this.rectBArea = new Rectangle(this.field_146128_h + 143, this.field_146129_i + 10, 15, 128); + this.rectAArea = new Rectangle(this.field_146128_h + 163, this.field_146129_i + 10, 15, 128); + + this.btnOk = new GuiControl(minecraft, 0, this.field_146128_h + 9, this.field_146129_i + 145, 55, 20, I18n.format("gui.ok")); + this.btnCancel = new GuiControl(minecraft, 1, this.field_146128_h + 70, this.field_146129_i + 145, 65, 20, I18n.format("gui.cancel")); + + this.updateColour(); + } + + public DialogResult getDialogResult() + { + return this.result; + } + + public int getColour() + { + int opacity = this.opacity == 0 ? 0x01000000 : this.opacity; + int rgb = opacity | (0xFFFFFF & Color.HSBtoRGB(this.hsb[H], this.hsb[S], this.hsb[B])); + return rgb; + } + + @Override + protected void drawControl(Minecraft minecraft, int mouseX, int mouseY) + { + this.mouseDragged(minecraft, mouseX, mouseY); + + // Calculate coordinates for the selectors + int hPos = this.field_146128_h + 10 + (int)(128F * this.hsb[H]); + int sPos = this.field_146129_i + 10 + (128 - (int)(128F * this.hsb[S])); + int bPos = this.field_146129_i + 10 + (128 - (int)(128F * this.hsb[B])); + int aPos = this.field_146129_i + 10 + ((256 - ((this.opacity >> 24) & 0xFF)) / 2) ; + + // Calculate B colour + int brightness = Color.HSBtoRGB(this.hsb[H], this.hsb[S], 1.0F) | 0xFF000000; + + // Draw backgrounds + drawRect(this.field_146128_h, this.field_146129_i, this.field_146128_h + this.field_146120_f, this.field_146129_i + this.field_146121_g, 0xAA000000); // Background + drawRect(this.field_146128_h + 9, this.field_146129_i + 9, this.field_146128_h + 139, this.field_146129_i + 139, 0xFFA0A0A0); // HS background + drawRect(this.field_146128_h + 142, this.field_146129_i + 9, this.field_146128_h + 159, this.field_146129_i + 139, 0xFFA0A0A0); // B background + drawRect(this.field_146128_h + 162, this.field_146129_i + 9, this.field_146128_h + 179, this.field_146129_i + 139, 0xFFA0A0A0); // A background + drawRect(this.field_146128_h + 187, this.field_146129_i + 105, this.field_146128_h + 221, this.field_146129_i + 139, 0xFFA0A0A0); // Preview background + + // Draw colour picker + this.mc.getTextureManager().bindTexture(GuiColourPicker.COLOURPICKER_PICKER); + glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.drawTexturedModalRect(this.field_146128_h + 10, this.field_146129_i + 10, this.field_146128_h + 138, this.field_146129_i + 138, 0, 0, 256, 256); + this.drawCrossHair(hPos, sPos, 5, 1, 0xFF000000); + + // Draw brightness bar + this.drawGradientRect(this.field_146128_h + 143, this.field_146129_i + 10, this.field_146128_h + 158, this.field_146129_i + 138, brightness, 0xFF000000); + this.drawRotText(this.fontRenderer, "Luminosity", this.field_146128_h + 150, this.field_146129_i + 74, 0xFF000000, false); + drawRect(this.field_146128_h + 142, bPos - 1, this.field_146128_h + 159, bPos + 1, 0xFFFFFFFF); + + // Draw opacity bar + this.drawGradientRect(this.field_146128_h + 163, this.field_146129_i + 10, this.field_146128_h + 178, this.field_146129_i + 138, 0xFFFFFFFF, 0xFF000000); + this.drawRotText(this.fontRenderer, "Opacity", this.field_146128_h + 170, this.field_146129_i + 74, 0xFF000000, false); + drawRect(this.field_146128_h + 162, aPos - 1, this.field_146128_h + 179, aPos + 1, 0xFFFFFFFF); + + // Draw preview + this.mc.getTextureManager().bindTexture(GuiColourPicker.COLOURPICKER_CHECKER); + glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.drawTexturedModalRect(this.field_146128_h + 188, this.field_146129_i + 106, this.field_146128_h + 220, this.field_146129_i + 138, 0, 0, 1024, 1024); + drawRect(this.field_146128_h + 188, this.field_146129_i + 106, this.field_146128_h + 220, this.field_146129_i + 138, this.rgb); + + // Draw text boxes + this.txtRed.drawTextBox(); + this.txtGreen.drawTextBox(); + this.txtBlue.drawTextBox(); + this.txtAlpha.drawTextBox(); + + this.btnOk.drawButton(minecraft, mouseX, mouseY); + this.btnCancel.drawButton(minecraft, mouseX, mouseY); + } + + public void updateCursorCounter() + { + this.txtRed.updateCursorCounter(); + this.txtGreen.updateCursorCounter(); + this.txtBlue.updateCursorCounter(); + this.txtAlpha.updateCursorCounter(); + } + + protected void updateColour() + { + this.rgb = this.opacity | (0xFFFFFF & Color.HSBtoRGB(this.hsb[H], this.hsb[S], this.hsb[B])); + this.txtRed.setText(String.valueOf((this.rgb >> 16) & 0xFF)); + this.txtGreen.setText(String.valueOf((this.rgb >> 8) & 0xFF)); + this.txtBlue.setText(String.valueOf(this.rgb & 0xFF)); + this.txtAlpha.setText(String.valueOf((this.opacity >> 24) & 0xFF)); + } + + protected void updateColourFromTextEntry() + { + int currentRed = (this.rgb >> 16) & 0xFF; + int currentGreen = (this.rgb >> 8) & 0xFF; + int currentBlue = this.rgb & 0xFF; + int currentOpacity = (this.opacity >> 24) & 0xFF; + + currentRed = (int)clamp(this.tryParseInt(this.txtRed.getText(), currentRed), 0, 255); + currentGreen = (int)clamp(this.tryParseInt(this.txtGreen.getText(), currentGreen), 0, 255); + currentBlue = (int)clamp(this.tryParseInt(this.txtBlue.getText(), currentBlue), 0, 255); + currentOpacity = (int)clamp(this.tryParseInt(this.txtAlpha.getText(), currentOpacity), 0, 255); + + this.hsb = Color.RGBtoHSB(currentRed, currentGreen, currentBlue, null); + this.opacity = (currentOpacity << 24) & 0xFF000000; + this.updateColour(); + } + + protected int tryParseInt(String text, int defaultValue) + { + try + { + return Integer.parseInt(text); + } + catch (Exception ex) { return "".equals(text) ? 0 : defaultValue; } + } + + /* (non-Javadoc) + * @see net.minecraft.src.GuiButton#mouseDragged(net.minecraft.src.Minecraft, int, int) + */ + @Override + protected void mouseDragged(Minecraft minecraft, int mouseX, int mouseY) + { + super.mouseDragged(minecraft, mouseX, mouseY); + + if (this.draggingHS) + { + this.hsb[H] = clamp(mouseX - this.field_146128_h - 10, 0, 128) / 128F; + this.hsb[S] = (128F - clamp(mouseY - this.field_146129_i - 10, 0, 128)) / 128F; + this.updateColour(); + } + + if (this.draggingB) + { + this.hsb[B] = (128F - clamp(mouseY - this.field_146129_i - 10, 0, 128)) / 128F; + this.updateColour(); + } + + if (this.draggingA) + { + this.opacity = (mouseY - this.field_146129_i < 11) ? 0xFF000000 : (((128 - (int)clamp(mouseY - this.field_146129_i - 10, 0, 128)) << 25) & 0xFF000000); + this.updateColour(); + } + } + + /* (non-Javadoc) + * @see net.minecraft.src.GuiButton#mousePressed(net.minecraft.src.Minecraft, int, int) + */ + @Override + public boolean mousePressed(Minecraft minecraft, int mouseX, int mouseY) + { + if (super.mousePressed(minecraft, mouseX, mouseY)) + { + + if (this.btnOk.mousePressed(minecraft, mouseX, mouseY)) + this.result = DialogResult.OK; + + if (this.btnCancel.mousePressed(minecraft, mouseX, mouseY)) + this.result = DialogResult.Cancel; + + if (this.rectHSArea.contains(mouseX, mouseY)) + this.draggingHS = true; + + if (this.rectBArea.contains(mouseX, mouseY)) + this.draggingB = true; + + if (this.rectAArea.contains(mouseX, mouseY)) + this.draggingA = true; + + this.txtRed.mouseClicked(mouseX, mouseY, 0); + this.txtGreen.mouseClicked(mouseX, mouseY, 0); + this.txtBlue.mouseClicked(mouseX, mouseY, 0); + this.txtAlpha.mouseClicked(mouseX, mouseY, 0); + + return true; + } + else if (this.enabled) + { + this.result = DialogResult.Cancel; + } + + return false; + } + + /* (non-Javadoc) + * @see net.minecraft.src.GuiButton#mouseReleased(int, int) + */ + @Override + public void mouseReleased(int mouseX, int mouseY) + { + this.draggingHS = false; + this.draggingB = false; + this.draggingA = false; + } + + public boolean textBoxKeyTyped(char keyChar, int keyCode) + { + this.txtRed.textboxKeyTyped(keyChar, keyCode); + this.txtGreen.textboxKeyTyped(keyChar, keyCode); + this.txtBlue.textboxKeyTyped(keyChar, keyCode); + this.txtAlpha.textboxKeyTyped(keyChar, keyCode); + this.updateColourFromTextEntry(); + + if (keyCode == Keyboard.KEY_TAB) + { + if (this.txtRed.isFocused()) + { + this.txtRed.setFocused(false); + this.txtGreen.setFocused(true); + this.txtBlue.setFocused(false); + this.txtAlpha.setFocused(false); + } + else if (this.txtGreen.isFocused()) + { + this.txtRed.setFocused(false); + this.txtGreen.setFocused(false); + this.txtBlue.setFocused(true); + this.txtAlpha.setFocused(false); + } + else if (this.txtBlue.isFocused()) + { + this.txtRed.setFocused(false); + this.txtGreen.setFocused(false); + this.txtBlue.setFocused(false); + this.txtAlpha.setFocused(true); + } + else + { + this.txtRed.setFocused(true); + this.txtGreen.setFocused(false); + this.txtBlue.setFocused(false); + this.txtAlpha.setFocused(false); + } + } + + return true; + } + + public static float clamp(float value, float min, float max) + { + return Math.min(Math.max(value, min), max); + } +} diff --git a/src/main/java/wecui/gui/GuiControl.java b/src/main/java/wecui/gui/GuiControl.java new file mode 100644 index 00000000..319b5113 --- /dev/null +++ b/src/main/java/wecui/gui/GuiControl.java @@ -0,0 +1,642 @@ +package wecui.gui; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.renderer.Tessellator; + +import static org.lwjgl.opengl.GL11.*; + +/** + * GuiControlEx is the base class for additional controls. It includes some advanced drawing methods + * which are used by several derived classes + * + * @author Adam Mummery-Smith + * + */ +public class GuiControl extends GuiButton +{ + /** + * Used by some controls to indicate the manner in which they have handled a keypress + */ + public enum KeyHandledState + { + /** + * The control did not handle the keypress + */ + None, + + /** + * The control handled the keypress and the container should do no further processing + */ + Handled, + + /** + * The control handled the keypress and the container should call actionPerformed + */ + ActionPerformed; + } + + public enum DialogResult + { + /** + * No result (maybe the dialog was not closed yet?) + */ + None, + + /** + * Dialog result OK (user clicked OK or pressed RETURN) + */ + OK, + + /** + * Dialog result Cancel (user clicked Cancel or pressed ESCAPE) + */ + Cancel, + + Yes, + + No + } + + /** + * Set by parent screen to enable cursor flash etc + */ + public int updateCounter; + + /** + * Reference to the minecraft game instance + */ + protected Minecraft mc; + + /** + * Flag indicating whether an action was performed, to support GuiScreenEx's callback mechanism + */ + protected boolean actionPerformed; + + /** + * Flag tracking whether an item was double-clicked + */ + protected boolean doubleClicked; + + /** + * Scale factor which translates texture pixel coordinates to relative coordinates + */ + protected static float texMapScale = 0.00390625F; + + protected static float guiScaleFactor; + + protected static int lastScreenWidth; + protected static int lastScreenHeight; + + /** + * Override from GuiButton, handle this call and forward it to DrawControl for neatness + * + * @param minecraft Reference to the minecraft game instance + * @param mouseX Mouse X coordinate + * @param mouseY Mouse Y coordinate + */ + @Override + public final void drawButton(Minecraft minecraft, int mouseX, int mouseY) + { + this.drawControl(minecraft, mouseX, mouseY); + } + + /** + * Draw the control + * + * @param minecraft Reference to the minecraft game instance + * @param mouseX Mouse X coordinate + * @param mouseY Mouse Y coordinate + */ + protected void drawControl(Minecraft minecraft, int mouseX, int mouseY) + { + super.drawButton(minecraft, mouseX, mouseY); + } + + /** + * Constructor, passes through to GuiButton constructor + * + * @param minecraft Minecraft game instance + * @param controlId Control's ID (used for actionPerformed) + * @param xPos Control X position (left) + * @param yPos Control Y position (top) + * @param controlWidth Control width + * @param controlHeight Control height + * @param displayText Control display text + */ + public GuiControl(Minecraft minecraft, int controlId, int xPos, int yPos, int controlWidth, int controlHeight, String displayText) + { + super(controlId, xPos, yPos, controlWidth, controlHeight, displayText); + this.mc = minecraft; + } + + public GuiControl(Minecraft minecraft, int controlId, int xPos, int yPos, String displayText) + { + super(controlId, xPos, yPos, displayText); + this.mc = minecraft; + } + + /** + * GuiControlEx returns true from mousePressed if the mouse was captured, NOT if an action was performed. Containers + * should call this function afterwards to determine whether an action was performed. + * + * @return True if actionPerformed should be dispatched + */ + public boolean isActionPerformed() + { + return this.actionPerformed; + } + + /** + * Get whether an actionPerformed was a double-click event + * + * @return + */ + public boolean isDoubleClicked(boolean resetDoubleClicked) + { + boolean result = this.doubleClicked; + if (resetDoubleClicked) this.doubleClicked = false; + return result; + } + + /** + * Draws a line between two points with the specified width and colour + * + * @param x1 Origin x coordinate + * @param y1 Origin y coordinate + * @param x2 End x coordinate + * @param y2 End y coordinate + * @param width Line width in pixels + * @param colour Line colour + */ + public static void drawLine(int x1, int y1, int x2, int y2, int width, int colour) + { + drawArrow(x1, y1, x2, y2, 0, width, colour, false, 0); + } + + /** + * Draws an OpenGL line + * + * @param x1 Start x position + * @param y1 Start y position + * @param x2 End x position + * @param y2 End y position + * @param width Line width + * @param colour Line colour + */ + @SuppressWarnings("cast") + public static void drawNativeLine(float x1, float y1, float x2, float y2, float width, int colour) + { + float f = (float)(colour >> 24 & 0xff) / 255F; + float f1 = (float)(colour >> 16 & 0xff) / 255F; + float f2 = (float)(colour >> 8 & 0xff) / 255F; + float f3 = (float)(colour & 0xff) / 255F; + + glEnable(GL_BLEND); + glDisable(GL_TEXTURE_2D); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4f(f1, f2, f3, f); + glLineWidth(width); + + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawing(GL_LINES); + tessellator.addVertex(x1, y1, 0); + tessellator.addVertex(x2, y2, 0); + tessellator.draw(); + + glEnable(GL_TEXTURE_2D); + glDisable(GL_BLEND); + } + + /** + * Draws an arrow between two points with the specified width and colour + * + * @param x1 Origin x coordinate + * @param y1 Origin y coordinate + * @param x2 End x coordinate + * @param y2 End y coordinate + * @param width Line width in pixels + * @param arrowHeadSize Size of the arrow head + * @param colour Colour + */ + public static void drawArrow(int x1, int y1, int x2, int y2, int z, int width, int arrowHeadSize, int colour) + { + drawArrow(x1, y1, x2, y2, z, width, colour, true, arrowHeadSize); + } + + /** + * Internal function for drawing lines and arrows + * + * @param x1 Origin x coordinate + * @param y1 Origin y coordinate + * @param x2 End x coordinate + * @param y2 End y coordinate + * @param width Line width in pixels + * @param colour Colour + * @param arrowHead True to draw an arrow, otherwise draws a line + * @param arrowHeadSize Size of the arrow head + */ + @SuppressWarnings("cast") + public static void drawArrow(int x1, int y1, int x2, int y2, int z, int width, int colour, boolean arrowHead, int arrowHeadSize) + { + // Calculate the line length and angle defined by the specified points + int length = (int)Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2)); + float angle = (float)Math.toDegrees(Math.atan2(y2 - y1, x2 - x1)); + + // Local rotation + glPushMatrix(); + glTranslatef(x1, y1, 0.0f); + glRotatef(angle, 0.0f, 0.0f, 1.0f); + + // Calc coordinates for the line and arrow points + x1 = 0; + x2 = length - (arrowHead ? arrowHeadSize : 0); + y1 = (int)(width * -0.5); + y2 = y1 + width; + + // Calc colour components + float f = (float)(colour >> 24 & 0xff) / 255F; + float f1 = (float)(colour >> 16 & 0xff) / 255F; + float f2 = (float)(colour >> 8 & 0xff) / 255F; + float f3 = (float)(colour & 0xff) / 255F; + + glEnable(GL_BLEND); + glDisable(GL_TEXTURE_2D); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4f(f1, f2, f3, f); + + // Draw the line + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.addVertex(x1, y2, z); + tessellator.addVertex(x2, y2, z); + tessellator.addVertex(x2, y1, z); + tessellator.addVertex(x1, y1, z); + tessellator.draw(); + + // If an arrow then draw the arrow head + if (arrowHead && arrowHeadSize > 0) + { + tessellator.startDrawing(4); + tessellator.addVertex(x2, 0 - arrowHeadSize / 2, z); + tessellator.addVertex(x2, arrowHeadSize / 2, z); + tessellator.addVertex(length, 0, z); + tessellator.draw(); + } + + glEnable(GL_TEXTURE_2D); + glDisable(GL_BLEND); + + glPopMatrix(); + } + + /** + * Set the texmap scale factor + * + * @param textureSize + */ + @SuppressWarnings("cast") + public void setTexMapSize(int textureSize) + { + texMapScale = 1F / (float)textureSize; + } + + /** + * Draws a textured rectangle at 90 degrees + * + * @param x Left edge X coordinate + * @param y Top edge Y coordinate + * @param x2 Right edge X coordinate + * @param y2 Bottom edge Y coordinate + * @param u U coordinate + * @param v V coordinate + * @param u2 Right edge U coordinate + * @param v2 Bottom edge V coordinate + */ + @SuppressWarnings("cast") + public void drawTexturedModalRectRot(int x, int y, int x2, int y2, int u, int v, int u2, int v2) + { + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.addVertexWithUV(x2, y2, this.zLevel, (float)(u) * texMapScale, (float)(v2) * texMapScale); + tessellator.addVertexWithUV(x2, y, this.zLevel, (float)(u2) * texMapScale, (float)(v2) * texMapScale); + tessellator.addVertexWithUV(x, y, this.zLevel, (float)(u2) * texMapScale, (float)(v) * texMapScale); + tessellator.addVertexWithUV(x, y2, this.zLevel, (float)(u) * texMapScale, (float)(v) * texMapScale); + tessellator.draw(); + } + + /** + * Draws a textured rectangle at 90 degrees + * + * @param x Left edge X coordinate + * @param y Top edge Y coordinate + * @param u U coordinate + * @param v V coordinate + * @param width Width of texture to draw + * @param height Height of texture to draw + */ + @SuppressWarnings("cast") + public void drawTexturedModalRectRot(int x, int y, int u, int v, int width, int height) + { + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.addVertexWithUV(x + height, y + width, this.zLevel, (float)(u) * texMapScale, (float)(v + height) * texMapScale); + tessellator.addVertexWithUV(x + height, y, this.zLevel, (float)(u + width) * texMapScale, (float)(v + height) * texMapScale); + tessellator.addVertexWithUV(x, y, this.zLevel, (float)(u + width) * texMapScale, (float)(v) * texMapScale); + tessellator.addVertexWithUV(x, y + width, this.zLevel, (float)(u) * texMapScale, (float)(v) * texMapScale); + tessellator.draw(); + } + + /** + * Draws a tesselated rectangle where the texture is stretched horizontally but vertical scaling + * is achieved by splitting the texture in half and repeating the middle pixels + * + * @param x Left edge X coordinate + * @param y Top edge Y coordinate + * @param x2 Right edge X coordinate + * @param y2 Bottom edge Y coordinate + * @param u U coordinate + * @param v V coordinate + * @param u2 Right edge U coordinate + * @param v2 Bottom edge V coordinate + */ + public void drawTessellatedModalRectV(int x, int y, int x2, int y2, int u, int v, int u2, int v2) + { + int tileSize = ((v2 - v) / 2); + int vMidTop = v + tileSize; + int vMidBtm = vMidTop + 1; + + this.drawTexturedModalRect(x, y, x2, y + tileSize, u, v, u2, vMidTop); + this.drawTexturedModalRect(x, y + tileSize, x2, y2 - tileSize + 1, u, vMidTop, u2, vMidBtm); + this.drawTexturedModalRect(x, y2 - tileSize + 1, x2, y2, u, vMidBtm, u2, v2); + } + + /** + * Draws a tesselated rectangle where the texture is stretched vertically but horizontal scaling + * is achieved by splitting the texture in half and repeating the middle pixels + * + * @param x Left edge X coordinate + * @param y Top edge Y coordinate + * @param x2 Right edge X coordinate + * @param y2 Bottom edge Y coordinate + * @param u U coordinate + * @param v V coordinate + * @param u2 Right edge U coordinate + * @param v2 Bottom edge V coordinate + */ + public void drawTessellatedModalRectH(int x, int y, int x2, int y2, int u, int v, int u2, int v2) + { + int tileSize = ((u2 - u) / 2); + int uMidLeft = u + tileSize; + int uMidRight = uMidLeft + 1; + + this.drawTexturedModalRect(x, y, x + tileSize, y2, u, v, uMidLeft, v2); + this.drawTexturedModalRect(x + tileSize, y, x2 - tileSize + 1, y2, uMidLeft, v, uMidRight, v2); + this.drawTexturedModalRect(x2 - tileSize + 1, y, x2, y2, uMidRight, v, u2, v2); + } + + /** + * Draws a tesselated rectangle where the texture is stretched vertically and horizontally but the middle + * pixels are repeated whilst the joining pixels are stretched. + * + * @param x Left edge X coordinate + * @param y Top edge Y coordinate + * @param x2 Right edge X coordinate + * @param y2 Bottom edge Y coordinate + * @param u U coordinate + * @param v V coordinate + * @param u2 Right edge U coordinate + * @param v2 Bottom edge V coordinate + */ + public void drawTessellatedModalBorderRect(int x, int y, int x2, int y2, int u, int v, int u2, int v2) + { + this.drawTessellatedModalBorderRect(x, y, x2, y2, u, v, u2, v2, Math.min(((x2 - x) / 2) - 1, ((y2 - y) / 2) - 1)); + } + + /** + * Draws a tesselated rectangle where the texture is stretched vertically and horizontally but the middle + * pixels are repeated whilst the joining pixels are stretched. Bordersize specifies the portion of the texture which + * will remain unstretched. + * + * @param x Left edge X coordinate + * @param y Top edge Y coordinate + * @param x2 Right edge X coordinate + * @param y2 Bottom edge Y coordinate + * @param u U coordinate + * @param v V coordinate + * @param u2 Right edge U coordinate + * @param v2 Bottom edge V coordinate + * @param borderSize Number of pixels to leave unstretched, must be less than half of the width or height (whichever is smallest) + */ + public void drawTessellatedModalBorderRect(int x, int y, int x2, int y2, int u, int v, int u2, int v2, int borderSize) + { + int tileSize = Math.min(((u2 - u) / 2) - 1, ((v2 - v) / 2) - 1); + + int ul = u + tileSize, ur = u2 - tileSize, vt = v + tileSize, vb = v2 - tileSize; + int xl = x + borderSize, xr = x2 - borderSize, yt = y + borderSize, yb = y2 - borderSize; + + this.drawTexturedModalRect(x, y, xl, yt, u, v, ul, vt); + this.drawTexturedModalRect(xl, y, xr, yt, ul, v, ur, vt); + this.drawTexturedModalRect(xr, y, x2, yt, ur, v, u2, vt); + this.drawTexturedModalRect(x, yb, xl, y2, u, vb, ul, v2); + this.drawTexturedModalRect(xl, yb, xr, y2, ul, vb, ur, v2); + this.drawTexturedModalRect(xr, yb, x2, y2, ur, vb, u2, v2); + this.drawTexturedModalRect(x, yt, xl, yb, u, vt, ul, vb); + this.drawTexturedModalRect(xr, yt, x2, yb, ur, vt, u2, vb); + this.drawTexturedModalRect(xl, yt, xr, yb, ul, vt, ur, vb); + } + + /** + * Draw a string but cut it off if it's too long to fit in the specified width + * + * @param fontrenderer + * @param s + * @param x + * @param y + * @param width + * @param colour + */ + public static void drawStringWithEllipsis(FontRenderer fontrenderer, String s, int x, int y, int width, int colour) + { + if (fontrenderer.getStringWidth(s) <= width) + { + fontrenderer.drawStringWithShadow(s, x, y, colour); + } + else if (width < 8) + { + fontrenderer.drawStringWithShadow("..", x, y, colour); + } + else + { + String trimmedText = s; + + while (fontrenderer.getStringWidth(trimmedText) > width - 8 && trimmedText.length() > 0) + trimmedText = trimmedText.substring(0, trimmedText.length() - 1); + + fontrenderer.drawStringWithShadow(trimmedText + "...", x, y, colour); + } + } + + /** + * @param boundingBox + */ + @SuppressWarnings("cast") + protected void drawCrossHair(int x, int y, int size, int width, int colour) + { + float alpha = (float)(colour >> 24 & 0xff) / 255F; + float red = (float)(colour >> 16 & 0xff) / 255F; + float green = (float)(colour >> 8 & 0xff) / 255F; + float blue = (float)(colour & 0xff) / 255F; + + glLineWidth(GuiControl.guiScaleFactor * width); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); + glDisable(GL_TEXTURE_2D); + glDisable(GL_LIGHTING); + glColor4f(red, green, blue, alpha); + glEnable(GL_COLOR_LOGIC_OP); + glLogicOp(GL_OR_REVERSE); + + // Draw the frame + Tessellator tessellator = Tessellator.instance; + + tessellator.startDrawing(GL_LINES); + tessellator.addVertex(x - size, y, 0); + tessellator.addVertex(x + size, y, 0); + tessellator.draw(); + + tessellator.startDrawing(GL_LINES); + tessellator.addVertex(x, y - size, 0); + tessellator.addVertex(x, y + size, 0); + tessellator.draw(); + + glDisable(GL_COLOR_LOGIC_OP); + glEnable(GL_TEXTURE_2D); + } + + protected void drawRotText(FontRenderer fontRenderer, String text, int xPosition, int yPosition, int colour, boolean colourOrOp) + { + if (colourOrOp) + { + glEnable(GL_COLOR_LOGIC_OP); + glLogicOp(GL_OR_REVERSE); + } + + int textWidth = fontRenderer.getStringWidth(text) / 2; + + glPushMatrix(); + glTranslatef(xPosition, yPosition, 0); + glRotatef(-90, 0, 0, 1); + glTranslatef(-textWidth, -4, 0); + + fontRenderer.drawString(text, 0, 0, colour); + + glPopMatrix(); + + if (colourOrOp) + { + glDisable(GL_COLOR_LOGIC_OP); + glEnable(GL_TEXTURE_2D); + } + } + + /** + * Draw a tooltip at the specified location and clip to screenWidth and screenHeight + * + * @param fontRenderer + * @param tooltipText + * @param mouseX + * @param mouseY + * @param screenWidth + * @param screenHeight + * @param colour + * @param backgroundColour + */ + protected void drawTooltip(FontRenderer fontRenderer, String tooltipText, int mouseX, int mouseY, int screenWidth, int screenHeight, int colour, int backgroundColour) + { + int textSize = fontRenderer.getStringWidth(tooltipText); + mouseX = Math.max(0, Math.min(screenWidth - textSize - 6, mouseX - 6)); + mouseY = Math.max(0, Math.min(screenHeight - 16, mouseY - 18)); + + drawRect(mouseX, mouseY, mouseX + textSize + 6, mouseY + 16, backgroundColour); + this.drawString(fontRenderer, tooltipText, mouseX + 3, mouseY + 4, colour); + } + + /** + * Draws a textured rectangle with custom UV coordinates + * + * @param x Left edge X coordinate + * @param y Top edge Y coordinate + * @param x2 Right edge X coordinate + * @param y2 Bottom edge Y coordinate + * @param u U coordinate + * @param v V coordinate + * @param u2 Right edge U coordinate + * @param v2 Bottom edge V coordinate + */ + @SuppressWarnings("cast") + public void drawTexturedModalRect(int x, int y, int x2, int y2, int u, int v, int u2, int v2) + { + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.addVertexWithUV(x, y2, this.zLevel, (float)(u) * texMapScale, (float)(v2) * texMapScale); + tessellator.addVertexWithUV(x2, y2, this.zLevel, (float)(u2) * texMapScale, (float)(v2) * texMapScale); + tessellator.addVertexWithUV(x2, y, this.zLevel, (float)(u2) * texMapScale, (float)(v) * texMapScale); + tessellator.addVertexWithUV(x, y, this.zLevel, (float)(u) * texMapScale, (float)(v) * texMapScale); + tessellator.draw(); + } + + /** + * Draws a textured rectangle with custom UV coordinates + * + * @param x Left edge X coordinate + * @param y Top edge Y coordinate + * @param x2 Right edge X coordinate + * @param y2 Bottom edge Y coordinate + * @param u U coordinate + * @param v V coordinate + * @param u2 Right edge U coordinate + * @param v2 Bottom edge V coordinate + */ + public void drawTexturedModalRectF(int x, int y, int x2, int y2, float u, float v, float u2, float v2) + { + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.addVertexWithUV(x, y2, this.zLevel, u , v2); + tessellator.addVertexWithUV(x2, y2, this.zLevel, u2, v2); + tessellator.addVertexWithUV(x2, y, this.zLevel, u2, v ); + tessellator.addVertexWithUV(x, y, this.zLevel, u , v ); + tessellator.draw(); + } + + /** + * Draws a textured rectangle with the specified texture map size + * + * @param x Left edge X coordinate + * @param y Top edge Y coordinate + * @param u Texture U coordinate + * @param v Texture V coordinate + * @param width Width + * @param height Height + * @param texMapScale Texture map scale for scaling UV coordinate + */ + @SuppressWarnings("cast") + public void drawTexturedModalRect(int x, int y, int u, int v, int width, int height, float texMapScale) + { + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.addVertexWithUV(x + 0, y + height, this.zLevel, (float)(u + 0) * texMapScale, (float)(v + height) * texMapScale); + tessellator.addVertexWithUV(x + width, y + height, this.zLevel, (float)(u + width) * texMapScale, (float)(v + height) * texMapScale); + tessellator.addVertexWithUV(x + width, y + 0, this.zLevel, (float)(u + width) * texMapScale, (float)(v + 0) * texMapScale); + tessellator.addVertexWithUV(x + 0, y + 0, this.zLevel, (float)(u + 0) * texMapScale, (float)(v + 0) * texMapScale); + tessellator.draw(); + } + + public static void setScreenSizeAndScale(int width, int height, int scaleFactor) + { + GuiControl.lastScreenWidth = width; + GuiControl.lastScreenHeight = height; + GuiControl.guiScaleFactor = scaleFactor; + } +} diff --git a/src/main/java/wecui/gui/WorldEditCUIConfigPanel.java b/src/main/java/wecui/gui/WorldEditCUIConfigPanel.java new file mode 100644 index 00000000..665a8aee --- /dev/null +++ b/src/main/java/wecui/gui/WorldEditCUIConfigPanel.java @@ -0,0 +1,191 @@ +package wecui.gui; + +import static org.lwjgl.opengl.GL11.*; + +import java.util.ArrayList; +import java.util.List; + +import org.lwjgl.input.Keyboard; + +import wecui.LiteModWorldEditCUI; +import wecui.render.LineColor; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.resources.I18n; + +import com.mumfrey.liteloader.modconfig.ConfigPanel; +import com.mumfrey.liteloader.modconfig.ConfigPanelHost; + +public class WorldEditCUIConfigPanel extends Gui implements ConfigPanel +{ + private Minecraft mc; + + private LiteModWorldEditCUI mod; + + private List controlList = new ArrayList(); + + private List colourButtonList = new ArrayList(); + + private GuiControl activeControl; + + public WorldEditCUIConfigPanel() + { + this.mc = Minecraft.getMinecraft(); + } + + @Override + public String getPanelTitle() + { + return I18n.format("wecui.options.title"); + } + + @Override + public int getContentHeight() + { + return LineColor.values().length * 24; + } + + @Override + public void onPanelShown(ConfigPanelHost host) + { + this.mod = host.getMod(); + + ScaledResolution scaledresolution = new ScaledResolution(this.mc.gameSettings, this.mc.displayWidth, this.mc.displayHeight); + GuiControl.setScreenSizeAndScale(host.getWidth(), this.getContentHeight(), scaledresolution.getScaleFactor()); + + this.controlList.clear(); + int nextId = 0; + + for (LineColor color : LineColor.values()) + { + this.controlList.add(new GuiColourButton(this.mc, nextId, 10, nextId * 24, 40, 20, color)); + this.controlList.add(new GuiControl(this.mc, 100 + nextId, 220, nextId * 24, 60, 20, "Reset")); + nextId++; + } + + for (GuiControl control : this.controlList) + { + if (control instanceof GuiColourButton) + this.colourButtonList.add((GuiColourButton)control); + } + } + + @Override + public void onPanelResize(ConfigPanelHost host) + { + } + + @Override + public void onPanelHidden() + { + for (GuiColourButton colourButton : this.colourButtonList) + { + colourButton.save(); + } + + this.mod.getController().getConfiguration().save(); + } + + @Override + public void onTick(ConfigPanelHost host) + { + } + + @Override + public void drawPanel(ConfigPanelHost host, int mouseX, int mouseY, float partialTicks) + { + for (GuiControl control : this.controlList) + { + control.drawControl(this.mc, mouseX, mouseY); + } + + for (GuiColourButton colourButton : this.colourButtonList) + { + colourButton.drawPicker(this.mc, mouseX, mouseY); + } + } + + @Override + public void mousePressed(ConfigPanelHost host, int mouseX, int mouseY, int mouseButton) + { + boolean makeActive = true; + + for (GuiControl control : this.controlList) + { + if (control.mousePressed(this.mc, mouseX, mouseY)) + { + if (makeActive) + { + makeActive = false; + this.activeControl = control; + this.actionPerformed(control); + } + } + } + } + + private void actionPerformed(GuiControl control) + { + if (control.id >= 100) + { + LineColor lineColour = LineColor.values()[control.id - 100]; + lineColour.setDefaultColour(); + + for (GuiColourButton colourButton : this.colourButtonList) + colourButton.updateColour(lineColour); + } + } + + @Override + public void mouseReleased(ConfigPanelHost host, int mouseX, int mouseY, int mouseButton) + { + if (this.activeControl != null) + { + this.activeControl.mouseReleased(mouseX, mouseY); + this.activeControl = null; + } + } + + @Override + public void mouseMoved(ConfigPanelHost host, int mouseX, int mouseY) + { + } + + @Override + public void keyPressed(ConfigPanelHost host, char keyChar, int keyCode) + { + if (keyCode == Keyboard.KEY_ESCAPE) + { + host.close(); + return; + } + + for (GuiColourButton colourButton : this.colourButtonList) + { + colourButton.keyTyped(keyChar, keyCode); + } + } + + /** + * Enable OpenGL clipping planes (uses planes 2, 3, 4 and 5) + */ + protected final void enableClipping() + { + glEnable(GL_CLIP_PLANE2); + glEnable(GL_CLIP_PLANE3); + glEnable(GL_CLIP_PLANE4); + glEnable(GL_CLIP_PLANE5); + } + + /** + * Disable OpenGL clipping planes (uses planes 2, 3, 4 and 5) + */ + protected final void disableClipping() + { + glDisable(GL_CLIP_PLANE5); + glDisable(GL_CLIP_PLANE4); + glDisable(GL_CLIP_PLANE3); + glDisable(GL_CLIP_PLANE2); + } +} diff --git a/src/main/java/wecui/render/LineColor.java b/src/main/java/wecui/render/LineColor.java index b1843e10..b6a1bcc5 100644 --- a/src/main/java/wecui/render/LineColor.java +++ b/src/main/java/wecui/render/LineColor.java @@ -1,6 +1,8 @@ package wecui.render; -import org.lwjgl.opengl.GL11; +import net.minecraft.client.resources.I18n; + +import static org.lwjgl.opengl.GL11.*; import wecui.config.Colour; @@ -17,29 +19,42 @@ */ public enum LineColor { - CUBOIDGRID(0.8F, 0.2F, 0.2F), - CUBOIDBOX(0.8F, 0.3F, 0.3F), - CUBOIDPOINT1(0.2F, 0.8F, 0.2F), //33CC33 - CUBOIDPOINT2(0.2F, 0.2F, 0.8F), //3333CC - POLYGRID(0.8F, 0.2F, 0.2F), - POLYBOX(0.8F, 0.3F, 0.3F), - POLYPOINT(0.2F, 0.8F, 0.8F), //33CCCC - ELLIPSOIDGRID(0.8F, 0.3F, 0.3F), - ELLIPSOIDCENTER(0.8F, 0.8F, 0.2F), //CCCC33 - CYLINDERGRID(0.8F, 0.2F, 0.2F), - CYLINDERBOX(0.8F, 0.3F, 0.3F), - CYLINDERCENTER(0.8F, 0.2F, 0.8F); //CC33CC - protected LineInfo normal; - protected LineInfo hidden; + CUBOIDBOX ("colour.cuboidedge", new Colour("#CC3333CC")), + CUBOIDGRID ("colour.cuboidgrid", new Colour("#CC4C4CCC")), + CUBOIDPOINT1 ("colour.cuboidpoint1", new Colour("#33CC33CC")), + CUBOIDPOINT2 ("colour.cuboidpoint2", new Colour("#3333CCCC")), + POLYGRID ("colour.polygrid", new Colour("#CC3333CC")), + POLYBOX ("colour.polyedge", new Colour("#CC4C4CCC")), + POLYPOINT ("colour.polypoint", new Colour("#33CCCCCC")), + ELLIPSOIDGRID ("colour.ellipsoidgrid", new Colour("#CC4C4CCC")), + ELLIPSOIDCENTER("colour.ellipsoidpoint", new Colour("#CCCC33CC")), + CYLINDERGRID ("colour.cylindergrid", new Colour("#CC3333CC")), + CYLINDERBOX ("colour.cylinderedge", new Colour("#CC4C4CCC")), + CYLINDERCENTER ("colour.cylinderpoint", new Colour("#CC33CCCC")); + + private String displayName; + + private Colour defaultColour; + private Colour colour; + + private LineInfo normal; + private LineInfo hidden; - private LineColor(float r, float g, float b) { - this.normal = new LineInfo(3.0f, r, g, b, 0.8f, GL11.GL_LESS); - this.hidden = new LineInfo(3.0f, r, g, b, 0.2f, GL11.GL_GEQUAL); + private LineColor(String displayName, Colour colour) { + this.displayName = displayName; + this.colour = colour; + this.defaultColour = new Colour().copyFrom(colour);; } - private LineColor(Colour colour) { - this.setColor(colour); - } + public String getDisplayName() + { + return I18n.format(this.displayName); + } + + public Colour getColour() + { + return this.colour; + } public LineInfo getHidden() { return this.hidden; @@ -53,13 +68,33 @@ public LineInfo[] getColors() { return new LineInfo[]{this.hidden, this.normal}; } - /** - * Parses a hex string (#FFFFFF) into each color, and makes a LineInfo. - * @param hex - */ - public void setColor(Colour colour) { - - this.normal = new LineInfo(3.0f, colour.red(), colour.green(), colour.blue(), 0.8f, GL11.GL_LESS); - this.hidden = new LineInfo(3.0f, colour.red(), colour.green(), colour.blue(), 0.2f, GL11.GL_GEQUAL); + public void setColour(Colour colour) + { + this.colour = colour; + this.updateColor(); + } + + public void updateColor() + { + this.normal = new LineInfo(3.0f, colour.red(), colour.green(), colour.blue(), colour.alpha(), GL_LESS); + this.hidden = new LineInfo(3.0f, colour.red(), colour.green(), colour.blue(), colour.alpha() * 0.25F, GL_GEQUAL); } + + public void setDefaultColour() + { + this.colour.copyFrom(this.defaultColour); + this.updateColor(); + } + + public void setColourIntRGBA(int argb) + { + int rgba = ((argb << 8) & 0xFFFFFF00) | (((argb & 0xFF000000) >> 24) & 0xFF); + this.colour.setHex(Integer.toHexString(rgba)); + this.updateColor(); + } + + public int getColourIntARGB() + { + return this.colour.getIntARGB(); + } } diff --git a/src/main/java/wecui/render/region/CuboidRegion.java b/src/main/java/wecui/render/region/CuboidRegion.java index 8afae64f..1d79a84b 100644 --- a/src/main/java/wecui/render/region/CuboidRegion.java +++ b/src/main/java/wecui/render/region/CuboidRegion.java @@ -26,13 +26,14 @@ public CuboidRegion(WorldEditCUI controller) { @Override public void render() { if (this.firstPoint != null && this.secondPoint != null) { - this.firstPoint.render(); - this.secondPoint.render(); Vector3[] bounds = this.calcBounds(); - new Render3DBox(LineColor.CUBOIDBOX, bounds[0], bounds[1]).render(); new Render3DGrid(LineColor.CUBOIDGRID, bounds[0], bounds[1]).render(); + new Render3DBox(LineColor.CUBOIDBOX, bounds[0], bounds[1]).render(); + this.firstPoint.render(); + this.secondPoint.render(); + } else if (this.firstPoint != null) { this.firstPoint.render(); } else if (this.secondPoint != null) { diff --git a/src/main/resources/assets/wecui/lang/en_US.lang b/src/main/resources/assets/wecui/lang/en_US.lang new file mode 100644 index 00000000..4d61571a --- /dev/null +++ b/src/main/resources/assets/wecui/lang/en_US.lang @@ -0,0 +1,20 @@ +wecui.options.title=WorldEditCUI Options + +wecui.keys.toggle=Toggle CUI visibility +wecui.keys.clear=Clear WorldEdit selection +wecui.keys.category=WorldEditCUI + +gui.ok=OK + +colour.cuboidedge=Cuboid Edge Colour +colour.cuboidgrid=Cuboid Grid Colour +colour.cuboidpoint1=Cuboid First Point Colour +colour.cuboidpoint2=Cuboid Second Point Colour +colour.polygrid=Polygon Grid Colour +colour.polyedge=Polygon Edge Colour +colour.polypoint=Polygon Point Colour +colour.ellipsoidgrid=Ellipsoid Grid Colour +colour.ellipsoidpoint=Ellipsoid Centre Point Colour +colour.cylindergrid=Cylinder Grid Colour +colour.cylinderedge=Cylinder Edge Colour +colour.cylinderpoint=Cylinder Centre Point Colour diff --git a/src/main/resources/assets/wecui/textures/gui/checker.png b/src/main/resources/assets/wecui/textures/gui/checker.png new file mode 100644 index 0000000000000000000000000000000000000000..d7ca6a320c06bce9d7afcd42b6336c36eb64e04a GIT binary patch literal 972 zcmaJ=J#W)M7&a84s!Az>DJ(tQmDoPVX|Po{Bz8(8;V4QXH47?^eMzj=K4V{rlL0{& zsQ3e6L2PV@ih%(MI%GizegJ=g0X7Cc#5qmU4g^c*`_S_|@AJO*-a(~&b8+Fy0>dzi zrA@s`=lOWdpQr!f(z_>gN|IuO)NqS*%>XfZ8#fUsxn>(xk!knten4vsGY6b{gEWj= ziiKUyj4@o~`jpKuYq`ibtsO)_6SW;rWxu_B&jQC**{zHr7`}!&&SpPAwSKv7^>-}U zW^?OcEmEj}i--v#ch?J*NM%R53SGy?JPSq;vZJ!crW!^CXgEM1!wD%%SQWr3`JMm{roEA_!pou{2s>x0I^BF^)xdD%&B%S9reL?Q-2Thl4f`Wm%3j zL@`AXsj%k}GfH{k%0xj&p%pkjaj*wsMYDpdUwRTSdAz@it|T8TsXiWVS~;GmB2?xc#94kkG4U>|6; z4A^o!8+XGI+Ax%o7ZTI6P)S!=%I6%%Ra zj;%cxd1S)1Pq@XI+_({3pGMYE;M_y@Mu1%~N?37bdnwG+8*}a1UbLB9o|@s~Ydv+% zlOx(Y@p9U{^JdO5QUPSuSZ{+zn0D=5{c!9gXPD`&(GA44-$jt zQf}_T(eMUyv3|7gy*NCC_b>nX{qxcGnPF|Pu+AP_eVt^^CYYz&mu`O_eti|cuTrtB JzbxF@{|j)^F0}vv literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/wecui/textures/gui/picker.png b/src/main/resources/assets/wecui/textures/gui/picker.png new file mode 100644 index 0000000000000000000000000000000000000000..18e1c9dd8e632295377ca35e1332e9621247323d GIT binary patch literal 2358 zcmbVOc~BEs8qYxl5;;A{dc-EcDoBowk&p;OfCNDaV8{%putko>L?9iL00BHAs1OE~ zK@^2mg1D&Tv8<@0f}*G#I$lH>ZxN6~Mn#3;hHX^b{ll8A+OFz;-+S--{l2@Z4PhZm zt?;w(C=|*nD3B*aR_?@WfkD15gmwe6{6));)P}>c+GMdBLix&I2?PWsh}S?uNGwZP z*8q8;P*|Bl6se6A1aqWt0#!VrL)9gy5Ht$q<)c%HrE!oJkU(n`N^kPJ%4#y8ka?3M z77OSCl|Lj`1g5H?@YE2IG&N4jmXUqF1H5z`gdhRZiUD0hyi&u_d6Pf!au9jqm_`OZ zsc7T8$)BBy6odi(uo?muQ|S~b-GdHzfK+f1lf`1W0}MJyr_mWSkU;@ioJ9-{oeq3? z$cQzyES4kW1$?oE?7YcxtyaaM(UOyssmY6|uzC#*WV6{591I2p(V%Ejlv=TlqSQD| zGVmacRIN~H6|fSRU=&N>M6EX&@$_>D2`Yi$E3s1ZB~eJqXgaZq22$y?goKH>K51*T zLg+tkd{bK^N>M>HA*6v5)l#G$u}+g=LpfG|0%g*9?m z1^91jz!_a02ityBx(gtpD$*KVxP8PsV77Gqj1;_^(!( zJVN?!Lj2nJ$mZ+lKuTm@)W~3*^S4u=P&j!I&sU^-d}!6plTSUSy1177C<`}opNx-R zaOU3qp2a_T|2!$~c->3?1Dk)^3NJ8_Q>^E;5Ai!;VR3b5@r%ycNAHB**gfVfHEgP$ z^ar1CR^$7?v;p0P7ay;8zuP%pbf=@_GG$O|dAoyCNPqI7 zuIuBOwAV9ZmU67{y_}x)Q{O(fsw~DkcVLFFLCH<`r$^F!%bCeViTEuxAFfm)l#o84wjV1CuFOdK=q3SyJ7-8uvoADLtdqobmwpd%U z`o8qs6Vp z<)pw0g1}R6ox4Z2W1Tm>#?$qDm|vehM3zG_Iyz=HD$Y9Q*55Fff-z0ZhS2th%i8TL zy=-@GCYqVK+g?Nwu~pdCXg9~bc;chbSmLc#tE4*pZ}X$wt`w+_8<&laUBK1TyW(Ji$D&lnBL7 z-w*^*u`^zI+Wcr*LfoX#S2QO1d3r?0#!3;Od$w=k?+f`zDnK6=cL zOH+x_X{$LF=lb+9M97#?wWMvK+cx!rtgFuy`wgaB?aEmaz{{~PhWV;Kcl&O~Cw0)~ z(RSs5==z1Pe`8B``l+8_*i2_pVdXFG0GeESH}}L5-prpBhea)K3O)Ii_)<*&tHG;V zSD4q1rgG!nlF&V;xMzndW^Ea*q2CDMz&-lkH>_>GuJ>8fj*)Qv8ZLjt_>2U37twz( zbid769^hc#*ZUJeq~nfUYPLg#;&Q-?HP<#U`mODR;2N1lrfC2m{7zrDuLx5Gb`=l# z9SnKAeYVkrd35w@FmF~htccFdnw!`W37l}dg2UQdp` zgBs8}UML7*4Mt_mC~-eLo)6EwyKatk*Xus|t%fKdYe~upcCg#d{Ee0}v}t4O+dDqB zv9j#-&y{!jm)~W~_gGR1o%SCt9s5Tn<%KKIG^R3~UVuuByd9QlGFhBJ6Zf|brr+bb zMLo7JSl=nNA=%_^>!0S4=6O5gk5HWR(3#CsZzqow;;xO$-z9E1bJ4W`V=rhgbJ`t_ z_I0iqz+@I=VosrJZf^a+cy2OvDXyzyE1r)v*%e~u;8AV6d2`u2_#SnkDd_!s|~o0jhsv6^_GC9h)@KJ3Bp_aj4; f!SWtpyc&f?8BhdbR)c)Y#GgzMKZJMEFDCup*6Fd0 literal 0 HcmV?d00001 From e40dbf6fcc994a5a379911e4343803afefe1ea94 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Tue, 21 Jan 2014 17:41:44 +0000 Subject: [PATCH 08/51] Code cleanup and purge old events system --- src/main/java/wecui/CUIDebug.java | 121 +- .../java/wecui/InitializationFactory.java | 7 +- src/main/java/wecui/LiteModWorldEditCUI.java | 111 +- src/main/java/wecui/WorldEditCUI.java | 143 +- .../java/wecui/config/CUIConfiguration.java | 59 +- src/main/java/wecui/config/Colour.java | 29 +- src/main/java/wecui/event/CUIEvent.java | 111 +- src/main/java/wecui/event/ChannelEvent.java | 38 - .../java/wecui/event/ChatCommandEvent.java | 101 -- .../java/wecui/event/OutgoingChatEvent.java | 44 - .../java/wecui/event/WorldRenderEvent.java | 51 - .../java/wecui/event/cui/CUIBaseEvent.java | 175 +-- .../wecui/event/cui/CUICylinderEvent.java | 58 +- .../wecui/event/cui/CUIEllipsoidEvent.java | 71 +- .../java/wecui/event/cui/CUIEventType.java | 117 +- .../java/wecui/event/cui/CUIMinMaxEvent.java | 46 +- .../java/wecui/event/cui/CUIPoint2DEvent.java | 53 +- .../java/wecui/event/cui/CUIPointEvent.java | 89 +- .../java/wecui/event/cui/CUIPolygonEvent.java | 51 +- .../wecui/event/cui/CUISelectionEvent.java | 85 +- .../java/wecui/event/cui/CUIUpdateEvent.java | 34 +- .../wecui/event/listeners/CUIListener.java | 52 - .../event/listeners/ChannelListener.java | 76 +- .../event/listeners/WorldRenderListener.java | 108 +- .../exception/ConfigurationException.java | 14 - .../exception/InitializationException.java | 23 +- .../wecui/exception/ReflectException.java | 51 +- src/main/java/wecui/fevents/Cancellable.java | 27 - src/main/java/wecui/fevents/Event.java | 76 -- src/main/java/wecui/fevents/EventManager.java | 54 - src/main/java/wecui/fevents/HandlerList.java | 130 -- src/main/java/wecui/fevents/Listener.java | 14 - src/main/java/wecui/fevents/Order.java | 77 -- src/main/java/wecui/gui/GuiColourButton.java | 85 +- src/main/java/wecui/gui/GuiColourPicker.java | 58 +- src/main/java/wecui/gui/GuiControl.java | 1011 +++++++------- .../wecui/gui/WorldEditCUIConfigPanel.java | 52 +- src/main/java/wecui/plugin/CUIPlayer.java | 80 -- .../java/wecui/plugin/CUIServerInterface.java | 36 - .../java/wecui/plugin/CUIWEConfiguration.java | 19 - src/main/java/wecui/plugin/CUIWorld.java | 124 -- src/main/java/wecui/plugin/LocalPlugin.java | 121 -- src/main/java/wecui/render/LineColor.java | 129 +- src/main/java/wecui/render/LineInfo.java | 92 +- .../java/wecui/render/points/PointCube.java | 89 +- .../wecui/render/points/PointRectangle.java | 80 +- .../java/wecui/render/region/BaseRegion.java | 89 +- .../wecui/render/region/CuboidRegion.java | 189 +-- .../wecui/render/region/CylinderRegion.java | 117 +- .../wecui/render/region/EllipsoidRegion.java | 84 +- .../wecui/render/region/PolygonRegion.java | 112 +- .../wecui/render/region/PolyhedronRegion.java | 126 +- .../java/wecui/render/region/RegionType.java | 15 +- .../java/wecui/render/shapes/Render2DBox.java | 72 +- .../wecui/render/shapes/Render2DGrid.java | 81 +- .../java/wecui/render/shapes/Render3DBox.java | 128 +- .../wecui/render/shapes/Render3DGrid.java | 308 +++-- .../wecui/render/shapes/Render3DPolygon.java | 55 +- .../render/shapes/RenderCylinderBox.java | 90 +- .../render/shapes/RenderCylinderCircles.java | 90 +- .../render/shapes/RenderCylinderGrid.java | 126 +- .../wecui/render/shapes/RenderEllipsoid.java | 252 ++-- src/main/java/wecui/util/ChatColor.java | 127 -- .../java/wecui/util/ConsoleLogFormatter.java | 98 +- src/main/java/wecui/util/Utilities.java | 271 ++-- src/main/java/wecui/util/Vector2.java | 1156 ++++++++-------- src/main/java/wecui/util/Vector2m.java | 260 ++-- src/main/java/wecui/util/Vector3.java | 1209 +++++++++-------- src/main/java/wecui/util/Vector3m.java | 99 +- .../java/wecui/vendor/org/joor/Reflect.java | 1020 +++++++------- 70 files changed, 4894 insertions(+), 5552 deletions(-) delete mode 100644 src/main/java/wecui/event/ChannelEvent.java delete mode 100644 src/main/java/wecui/event/ChatCommandEvent.java delete mode 100644 src/main/java/wecui/event/OutgoingChatEvent.java delete mode 100644 src/main/java/wecui/event/WorldRenderEvent.java delete mode 100644 src/main/java/wecui/event/listeners/CUIListener.java delete mode 100644 src/main/java/wecui/exception/ConfigurationException.java delete mode 100644 src/main/java/wecui/fevents/Cancellable.java delete mode 100644 src/main/java/wecui/fevents/Event.java delete mode 100644 src/main/java/wecui/fevents/EventManager.java delete mode 100644 src/main/java/wecui/fevents/HandlerList.java delete mode 100644 src/main/java/wecui/fevents/Listener.java delete mode 100644 src/main/java/wecui/fevents/Order.java delete mode 100644 src/main/java/wecui/plugin/CUIPlayer.java delete mode 100644 src/main/java/wecui/plugin/CUIServerInterface.java delete mode 100644 src/main/java/wecui/plugin/CUIWEConfiguration.java delete mode 100644 src/main/java/wecui/plugin/CUIWorld.java delete mode 100644 src/main/java/wecui/plugin/LocalPlugin.java delete mode 100644 src/main/java/wecui/util/ChatColor.java diff --git a/src/main/java/wecui/CUIDebug.java b/src/main/java/wecui/CUIDebug.java index 046c8e21..10683e8d 100644 --- a/src/main/java/wecui/CUIDebug.java +++ b/src/main/java/wecui/CUIDebug.java @@ -18,59 +18,70 @@ * @author yetanotherx * */ -public class CUIDebug implements InitializationFactory { - - protected WorldEditCUI controller; - protected File debugFile; - protected boolean debugMode = false; - protected final static Logger logger = Logger.getLogger("WorldEditCUI"); - - public CUIDebug(WorldEditCUI controller) { - this.controller = controller; - } - - @Override - public void initialize() throws InitializationException { - - ConsoleLogFormatter formatter = new ConsoleLogFormatter(); - ConsoleHandler handler = new ConsoleHandler(); - handler.setFormatter(formatter); - - logger.setUseParentHandlers(false); - logger.addHandler(handler); - - try { - this.debugFile = new File(LiteLoader.getCommonConfigFolder(), "worldeditcui.debug.log"); - this.debugMode = this.controller.getConfiguration().isDebugMode(); - - if (this.debugMode) { - FileHandler newHandler = new FileHandler(this.debugFile.getAbsolutePath()); - newHandler.setFormatter(formatter); - logger.addHandler(newHandler); - } - - } catch (IOException e) { - e.printStackTrace(System.err); - throw new InitializationException(); - } - - } - - /** - * Shows a message if debug mode is true - * @param message - */ - public void debug(String message) { - if (this.debugMode) { - logger.info("WorldEditCUI Debug - " + message); - } - } - - public void info(String message) { - logger.info(message); - } - - public void info(String message, Throwable e) { - logger.log(Level.INFO, message, e); - } +public class CUIDebug implements InitializationFactory +{ + + protected WorldEditCUI controller; + protected File debugFile; + protected boolean debugMode = false; + protected final static Logger logger = Logger.getLogger("WorldEditCUI"); + + public CUIDebug(WorldEditCUI controller) + { + this.controller = controller; + } + + @Override + public void initialize() throws InitializationException + { + + ConsoleLogFormatter formatter = new ConsoleLogFormatter(); + ConsoleHandler handler = new ConsoleHandler(); + handler.setFormatter(formatter); + + logger.setUseParentHandlers(false); + logger.addHandler(handler); + + try + { + this.debugFile = new File(LiteLoader.getCommonConfigFolder(), "worldeditcui.debug.log"); + this.debugMode = this.controller.getConfiguration().isDebugMode(); + + if (this.debugMode) + { + FileHandler newHandler = new FileHandler(this.debugFile.getAbsolutePath()); + newHandler.setFormatter(formatter); + logger.addHandler(newHandler); + } + + } + catch (IOException e) + { + e.printStackTrace(System.err); + throw new InitializationException(); + } + + } + + /** + * Shows a message if debug mode is true + * @param message + */ + public void debug(String message) + { + if (this.debugMode) + { + logger.info("WorldEditCUI Debug - " + message); + } + } + + public void info(String message) + { + logger.info(message); + } + + public void info(String message, Throwable e) + { + logger.log(Level.INFO, message, e); + } } diff --git a/src/main/java/wecui/InitializationFactory.java b/src/main/java/wecui/InitializationFactory.java index 436ba90b..121d970f 100644 --- a/src/main/java/wecui/InitializationFactory.java +++ b/src/main/java/wecui/InitializationFactory.java @@ -8,7 +8,8 @@ * * @author yetanotherx */ -public interface InitializationFactory { - - public void initialize() throws InitializationException; +public interface InitializationFactory +{ + + public void initialize() throws InitializationException; } diff --git a/src/main/java/wecui/LiteModWorldEditCUI.java b/src/main/java/wecui/LiteModWorldEditCUI.java index 7a4404d2..004d830c 100644 --- a/src/main/java/wecui/LiteModWorldEditCUI.java +++ b/src/main/java/wecui/LiteModWorldEditCUI.java @@ -10,13 +10,11 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.multiplayer.WorldClient; -import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.settings.KeyBinding; import net.minecraft.network.INetHandler; import net.minecraft.network.play.server.S01PacketJoinGame; -import wecui.event.ChannelEvent; -import wecui.event.WorldRenderEvent; +import wecui.event.listeners.ChannelListener; +import wecui.event.listeners.WorldRenderListener; import wecui.gui.WorldEditCUIConfigPanel; import wecui.render.region.CuboidRegion; @@ -32,20 +30,22 @@ public class LiteModWorldEditCUI implements InitCompleteListener, PluginChannelListener, PostRenderListener, Configurable { - private static final String CHANNEL_WECUI = "WECUI"; - private final static Charset UTF_8_CHARSET = Charset.forName("UTF-8"); - + private static final String CHANNEL_WECUI = "WECUI"; + private final static Charset UTF_8_CHARSET = Charset.forName("UTF-8"); + private WorldEditCUI controller; - private WorldClient lastWorld; - private EntityPlayerSP lastPlayer; - private boolean gameStarted = false; - private WorldRenderEvent event; - - private KeyBinding keyBindToggleUI = new KeyBinding("wecui.keys.toggle", Keyboard.KEY_NONE, "wecui.keys.category"); - private KeyBinding keyBindClearSel = new KeyBinding("wecui.keys.clear", Keyboard.KEY_NONE, "wecui.keys.category"); - - private boolean visible = true; - + private WorldClient lastWorld; + private EntityPlayerSP lastPlayer; + private boolean gameStarted = false; + + private KeyBinding keyBindToggleUI = new KeyBinding("wecui.keys.toggle", Keyboard.KEY_NONE, "wecui.keys.category"); + private KeyBinding keyBindClearSel = new KeyBinding("wecui.keys.clear", Keyboard.KEY_NONE, "wecui.keys.category"); + + private boolean visible = true; + + private WorldRenderListener worldRenderListener; + private ChannelListener channelListener; + @Override public void init(File configPath) { @@ -57,25 +57,27 @@ public void init(File configPath) public void upgradeSettings(String version, File configPath, File oldConfigPath) { } - - /* (non-Javadoc) + + /* (non-Javadoc) * @see com.mumfrey.liteloader.InitCompleteListener#onInitCompleted(net.minecraft.client.Minecraft, com.mumfrey.liteloader.core.LiteLoader) */ @Override public void onInitCompleted(Minecraft minecraft, LiteLoader loader) { - this.controller = new WorldEditCUI(Minecraft.getMinecraft()); - this.controller.initialize(); - this.event = new WorldRenderEvent(this.controller); + this.controller = new WorldEditCUI(); + this.controller.initialize(); + + this.worldRenderListener = new WorldRenderListener(this.controller, minecraft); + this.channelListener = new ChannelListener(this.controller); } - + @Override public void onJoinGame(INetHandler netHandler, S01PacketJoinGame loginPacket) { this.visible = true; this.helo(); } - + /** * */ @@ -84,20 +86,24 @@ private void helo() byte[] buffer = ("v|" + WorldEditCUI.protocolVersion).getBytes(UTF_8_CHARSET); ClientPluginChannels.sendMessage(CHANNEL_WECUI, buffer, ChannelPolicy.DISPATCH_ALWAYS); } - + @Override public List getChannels() { return Arrays.asList(new String[] { CHANNEL_WECUI }); } - + @Override public void onCustomPayload(String channel, int length, byte[] data) { - ChannelEvent channelevent = new ChannelEvent(this.controller, new String(data, UTF_8_CHARSET)); - this.controller.getEventManager().callEvent(channelevent); + try + { + String payload = new String(data, LiteModWorldEditCUI.UTF_8_CHARSET); + this.channelListener.onMessage(payload); + } + catch (Exception ex) {} } - + @Override public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clock) { @@ -110,32 +116,35 @@ public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clo if (this.keyBindClearSel.isPressed()) { - if (mc.thePlayer != null) mc.thePlayer.sendChatMessage("//sel"); + if (mc.thePlayer != null) + mc.thePlayer.sendChatMessage("//sel"); } } if (inGame && clock && this.controller != null) { - if (mc.theWorld != this.lastWorld || mc.thePlayer != this.lastPlayer) { - this.lastWorld = mc.theWorld; - this.lastPlayer = mc.thePlayer; - - if (!this.gameStarted) { - this.gameStarted = true; - - this.controller.setSelection(new CuboidRegion(this.controller)); - this.helo(); - } - } + if (mc.theWorld != this.lastWorld || mc.thePlayer != this.lastPlayer) + { + this.lastWorld = mc.theWorld; + this.lastPlayer = mc.thePlayer; + + if (!this.gameStarted) + { + this.gameStarted = true; + + this.controller.setSelection(new CuboidRegion(this.controller)); + this.helo(); + } + } } } - + @Override public String getName() { return "WorldEditCUI"; } - + @Override public String getVersion() { @@ -147,20 +156,20 @@ public Class getConfigPanelClass() { return WorldEditCUIConfigPanel.class; } - + @Override public void onPostRenderEntities(float partialTicks) { - if (this.visible && this.event != null) + if (this.visible) { - RenderHelper.disableStandardItemLighting(); - OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); - this.event.setPartialTick(partialTicks); - this.controller.getEventManager().callEvent(this.event); - RenderHelper.enableStandardItemLighting(); + try + { + this.worldRenderListener.onRender(partialTicks); + } + catch (Exception ex) {} } } - + @Override public void onPostRender(float partialTicks) { diff --git a/src/main/java/wecui/WorldEditCUI.java b/src/main/java/wecui/WorldEditCUI.java index e9334bb0..8f87f0db 100644 --- a/src/main/java/wecui/WorldEditCUI.java +++ b/src/main/java/wecui/WorldEditCUI.java @@ -1,16 +1,7 @@ package wecui; -import net.minecraft.client.Minecraft; import wecui.config.CUIConfiguration; -import wecui.event.CUIEvent; -import wecui.event.ChannelEvent; -import wecui.event.WorldRenderEvent; -import wecui.event.listeners.CUIListener; -import wecui.event.listeners.ChannelListener; -import wecui.event.listeners.WorldRenderListener; import wecui.exception.InitializationException; -import wecui.fevents.EventManager; -import wecui.fevents.Order; import wecui.render.region.BaseRegion; import wecui.render.region.CuboidRegion; @@ -24,83 +15,59 @@ * * @author yetanotherx */ -public class WorldEditCUI { - - public static final int protocolVersion = 3; - private Minecraft minecraft; - private EventManager eventManager; - private BaseRegion selection; - private CUIDebug debugger; - private CUIConfiguration configuration; - - public WorldEditCUI(Minecraft minecraft) { - this.minecraft = minecraft; - } - - public void initialize() { - this.eventManager = new EventManager(this); - this.selection = new CuboidRegion(this); - this.configuration = CUIConfiguration.create(); - this.debugger = new CUIDebug(this); - //this.localPlugin = new LocalPlugin(this); - - try { - this.eventManager.initialize(); - this.selection.initialize(); - this.configuration.initialize(); - this.debugger.initialize(); - //this.localPlugin.initialize(); - } catch (InitializationException e) { - e.printStackTrace(); - return; - } - - this.registerListeners(); - } - - protected void registerListeners() { - CUIEvent.handlers.register(new CUIListener(this), Order.Default); - ChannelEvent.handlers.register(new ChannelListener(this), Order.Default); - WorldRenderEvent.handlers.register(new WorldRenderListener(this), Order.Default); - } - - public CUIConfiguration getConfiguration() { - return this.configuration; - } - - public void setConfiguration(CUIConfiguration configuration) { - this.configuration = configuration; - } - - public CUIDebug getDebugger() { - return this.debugger; - } - - public void setDebugger(CUIDebug debugger) { - this.debugger = debugger; - } - - public EventManager getEventManager() { - return this.eventManager; - } - - public void setEventManager(EventManager eventManager) { - this.eventManager = eventManager; - } - - public Minecraft getMinecraft() { - return this.minecraft; - } - - public void setMinecraft(Minecraft minecraft) { - this.minecraft = minecraft; - } - - public BaseRegion getSelection() { - return this.selection; - } - - public void setSelection(BaseRegion selection) { - this.selection = selection; - } +public class WorldEditCUI +{ + public static final int protocolVersion = 3; + private BaseRegion selection; + private CUIDebug debugger; + private CUIConfiguration configuration; + + public void initialize() + { + this.selection = new CuboidRegion(this); + this.configuration = CUIConfiguration.create(); + this.debugger = new CUIDebug(this); + + try + { + this.selection.initialize(); + this.configuration.initialize(); + this.debugger.initialize(); + } + catch (InitializationException e) + { + e.printStackTrace(); + return; + } + } + + public CUIConfiguration getConfiguration() + { + return this.configuration; + } + + public void setConfiguration(CUIConfiguration configuration) + { + this.configuration = configuration; + } + + public CUIDebug getDebugger() + { + return this.debugger; + } + + public void setDebugger(CUIDebug debugger) + { + this.debugger = debugger; + } + + public BaseRegion getSelection() + { + return this.selection; + } + + public void setSelection(BaseRegion selection) + { + this.selection = selection; + } } diff --git a/src/main/java/wecui/config/CUIConfiguration.java b/src/main/java/wecui/config/CUIConfiguration.java index a8cad45d..605baacc 100644 --- a/src/main/java/wecui/config/CUIConfiguration.java +++ b/src/main/java/wecui/config/CUIConfiguration.java @@ -25,18 +25,18 @@ public class CUIConfiguration implements InitializationFactory private boolean debugMode = false; private boolean ignoreUpdates = false; - private Colour cuboidGridColor = new Colour("#CC3333CC"); - private Colour cuboidEdgeColor = new Colour("#CC4C4CCC"); - private Colour cuboidFirstPointColor = new Colour("#33CC33CC"); + private Colour cuboidGridColor = new Colour("#CC3333CC"); + private Colour cuboidEdgeColor = new Colour("#CC4C4CCC"); + private Colour cuboidFirstPointColor = new Colour("#33CC33CC"); private Colour cuboidSecondPointColor = new Colour("#3333CCCC"); - private Colour polyGridColor = new Colour("#CC3333CC"); - private Colour polyEdgeColor = new Colour("#CC4C4CCC"); - private Colour polyPointColor = new Colour("#33CCCCCC"); - private Colour ellipsoidGridColor = new Colour("#CC4C4CCC"); - private Colour ellipsoidPointColor = new Colour("#CCCC33CC"); - private Colour cylinderGridColor = new Colour("#CC3333CC"); - private Colour cylinderEdgeColor = new Colour("#CC4C4CCC"); - private Colour cylinderPointColor = new Colour("#CC33CCCC"); + private Colour polyGridColor = new Colour("#CC3333CC"); + private Colour polyEdgeColor = new Colour("#CC4C4CCC"); + private Colour polyPointColor = new Colour("#33CCCCCC"); + private Colour ellipsoidGridColor = new Colour("#CC4C4CCC"); + private Colour ellipsoidPointColor = new Colour("#CCCC33CC"); + private Colour cylinderGridColor = new Colour("#CC3333CC"); + private Colour cylinderEdgeColor = new Colour("#CC4C4CCC"); + private Colour cylinderPointColor = new Colour("#CC33CCCC"); /** * Copies the default config file to the proper directory if it does not @@ -45,18 +45,18 @@ public class CUIConfiguration implements InitializationFactory @Override public void initialize() { - this.cuboidGridColor = Colour.setDefault(this.cuboidGridColor, "#CC3333CC"); - this.cuboidEdgeColor = Colour.setDefault(this.cuboidEdgeColor, "#CC4C4CCC"); - this.cuboidFirstPointColor = Colour.setDefault(this.cuboidFirstPointColor, "#33CC33CC"); + this.cuboidGridColor = Colour.setDefault(this.cuboidGridColor, "#CC3333CC"); + this.cuboidEdgeColor = Colour.setDefault(this.cuboidEdgeColor, "#CC4C4CCC"); + this.cuboidFirstPointColor = Colour.setDefault(this.cuboidFirstPointColor, "#33CC33CC"); this.cuboidSecondPointColor = Colour.setDefault(this.cuboidSecondPointColor, "#3333CCCC"); - this.polyGridColor = Colour.setDefault(this.polyGridColor, "#CC3333CC"); - this.polyEdgeColor = Colour.setDefault(this.polyEdgeColor, "#CC4C4CCC"); - this.polyPointColor = Colour.setDefault(this.polyPointColor, "#33CCCCCC"); - this.ellipsoidGridColor = Colour.setDefault(this.ellipsoidGridColor, "#CC4C4CCC"); - this.ellipsoidPointColor = Colour.setDefault(this.ellipsoidPointColor, "#CCCC33CC"); - this.cylinderGridColor = Colour.setDefault(this.cylinderGridColor, "#CC3333CC"); - this.cylinderEdgeColor = Colour.setDefault(this.cylinderEdgeColor, "#CC4C4CCC"); - this.cylinderPointColor = Colour.setDefault(this.cylinderPointColor, "#CC33CCCC"); + this.polyGridColor = Colour.setDefault(this.polyGridColor, "#CC3333CC"); + this.polyEdgeColor = Colour.setDefault(this.polyEdgeColor, "#CC4C4CCC"); + this.polyPointColor = Colour.setDefault(this.polyPointColor, "#33CCCCCC"); + this.ellipsoidGridColor = Colour.setDefault(this.ellipsoidGridColor, "#CC4C4CCC"); + this.ellipsoidPointColor = Colour.setDefault(this.ellipsoidPointColor, "#CCCC33CC"); + this.cylinderGridColor = Colour.setDefault(this.cylinderGridColor, "#CC3333CC"); + this.cylinderEdgeColor = Colour.setDefault(this.cylinderEdgeColor, "#CC4C4CCC"); + this.cylinderPointColor = Colour.setDefault(this.cylinderPointColor, "#CC33CCCC"); LineColor.CUBOIDBOX.setColour(this.cuboidEdgeColor); LineColor.CUBOIDGRID.setColour(this.cuboidGridColor); @@ -117,7 +117,7 @@ public static CUIConfiguration create() return new CUIConfiguration(); } - + public void save() { File jsonFile = new File(LiteLoader.getCommonConfigFolder(), "worldeditcui.config.json"); @@ -129,14 +129,21 @@ public void save() fileWriter = new FileWriter(jsonFile); CUIConfiguration.gson.toJson(this, fileWriter); } - catch (IOException ex) { ex.printStackTrace(); } + catch (IOException ex) + { + ex.printStackTrace(); + } finally { try { - if (fileWriter != null) fileWriter.close(); + if (fileWriter != null) + fileWriter.close(); + } + catch (IOException ex) + { + ex.printStackTrace(); } - catch (IOException ex) { ex.printStackTrace(); } } } } diff --git a/src/main/java/wecui/config/Colour.java b/src/main/java/wecui/config/Colour.java index 7d3ecd67..d2181891 100644 --- a/src/main/java/wecui/config/Colour.java +++ b/src/main/java/wecui/config/Colour.java @@ -4,7 +4,7 @@ public class Colour { private String hex; private transient String defaultColour; - + public Colour(String defaultColour) { this.hex = defaultColour; @@ -60,17 +60,20 @@ else if (colour.length() != 7 && colour.length() != 9) return (colour.matches("(?i)^#[0-9a-f]{6,8}$")) ? colour : def; } - + public void setHex(String hex) { - if (hex.length() < 8) hex = "00000000".substring(0, 8 - hex.length()) + hex; + if (hex.length() < 8) + hex = "00000000".substring(0, 8 - hex.length()) + hex; this.hex = "#" + hex; } - + public String getHex() { - if (this.hex == null) this.hex = this.defaultColour; - if (this.hex.length() == 7) this.hex = this.hex + "CC"; + if (this.hex == null) + this.hex = this.defaultColour; + if (this.hex.length() == 7) + this.hex = this.hex + "CC"; return this.hex; } @@ -79,23 +82,23 @@ public int getIntARGB() String hex = this.getHex(); return (int)Long.parseLong(hex.substring(7, 9) + hex.substring(1, 7), 16); } - + public float red() { String hex = this.getHex(); - return (((Integer)Integer.parseInt(hex.substring(1, 3), 16)).floatValue() / 256.0F); + return (((Integer)Integer.parseInt(hex.substring(1, 3), 16)).floatValue() / 256.0F); } - + public float green() { String hex = this.getHex(); - return (((Integer)Integer.parseInt(hex.substring(3, 5), 16)).floatValue() / 256.0F); + return (((Integer)Integer.parseInt(hex.substring(3, 5), 16)).floatValue() / 256.0F); } - + public float blue() { String hex = this.getHex(); - return (((Integer)Integer.parseInt(hex.substring(5, 7), 16)).floatValue() / 256.0F); + return (((Integer)Integer.parseInt(hex.substring(5, 7), 16)).floatValue() / 256.0F); } public float alpha() @@ -103,7 +106,7 @@ public float alpha() String hex = this.getHex(); return (((Integer)Integer.parseInt(hex.substring(7, 9), 16)).floatValue() / 256.0F); } - + public Colour copyFrom(Colour other) { this.hex = other.getHex(); diff --git a/src/main/java/wecui/event/CUIEvent.java b/src/main/java/wecui/event/CUIEvent.java index f6796976..31e73687 100644 --- a/src/main/java/wecui/event/CUIEvent.java +++ b/src/main/java/wecui/event/CUIEvent.java @@ -1,8 +1,6 @@ package wecui.event; import wecui.WorldEditCUI; -import wecui.fevents.Event; -import wecui.fevents.HandlerList; import wecui.util.Utilities; /** @@ -13,74 +11,43 @@ * @author yetanotherx * */ -public class CUIEvent extends Event { - - protected WorldEditCUI controller; - protected String type; - protected String[] params; - protected boolean handled = false; - public static final HandlerList handlers = new HandlerList(); - - public CUIEvent(WorldEditCUI controller, String type, String[] params) { - this.controller = controller; - this.type = type; - - //"".split("[|]") returns String[] {""} for some reason, instead of String[] {}. - if (params.length == 1 && params[0].length() == 0) { - params = new String[]{}; - } - - this.params = params; - this.controller.getDebugger().debug("CUI Event (" + type + ") - Params: " + Utilities.join(params, ", ")); - } - - @Override - protected String getEventName() { - return "CUIEvent"; - } - - @Override - protected HandlerList getHandlers() { - return handlers; - } - - public void setHandled(boolean handled) { - this.handled = handled; - } - - /** - * Called upon receiving an invalid event. - * Debugs an error message and handles the event. - * - * @param reason Error message - */ - public void markInvalid(String reason) { - this.controller.getDebugger().debug("INVALID WECUIEvent " + this.type + " - " + Utilities.join(this.params, "|") + " - Reason: " + reason); - this.setHandled(true); - } - - public int getInt(int index) { - return (int) Float.parseFloat(this.params[index]); - } - - public String getString(int index) { - return this.params[index]; - } - - public boolean isHandled() { - return this.handled; - } - - @Override - public boolean isCancelled() { - return this.isHandled(); - } - - public String[] getParams() { - return this.params; - } - - public String getType() { - return this.type; - } +public class CUIEvent +{ + private WorldEditCUI controller; + private String type; + private String[] params; + + public CUIEvent(WorldEditCUI controller, String type, String[] params) + { + this.controller = controller; + this.type = type; + + if (params.length == 1 && params[0].length() == 0) + { + params = new String[] {}; + } + + this.params = params; + this.controller.getDebugger().debug("CUI Event (" + type + ") - Params: " + Utilities.join(params, ", ")); + } + + public int getInt(int index) + { + return (int)Float.parseFloat(this.params[index]); + } + + public String getString(int index) + { + return this.params[index]; + } + + public String[] getParams() + { + return this.params; + } + + public String getType() + { + return this.type; + } } diff --git a/src/main/java/wecui/event/ChannelEvent.java b/src/main/java/wecui/event/ChannelEvent.java deleted file mode 100644 index 744c45d3..00000000 --- a/src/main/java/wecui/event/ChannelEvent.java +++ /dev/null @@ -1,38 +0,0 @@ -package wecui.event; - -import wecui.WorldEditCUI; -import wecui.fevents.Event; -import wecui.fevents.HandlerList; - -/** - * Events for chat messages to/from server - * - * @author lahwran - * @author yetanotherx - * - */ -public class ChannelEvent extends Event { - - protected WorldEditCUI controller; - protected String message; - public static final HandlerList handlers = new HandlerList(); - - public ChannelEvent(WorldEditCUI controller, String message) { - this.controller = controller; - this.message = message; - } - - @Override - protected String getEventName() { - return "ChannelEvent"; - } - - @Override - protected HandlerList getHandlers() { - return handlers; - } - - public String getMessage() { - return this.message; - } -} diff --git a/src/main/java/wecui/event/ChatCommandEvent.java b/src/main/java/wecui/event/ChatCommandEvent.java deleted file mode 100644 index 27f828f6..00000000 --- a/src/main/java/wecui/event/ChatCommandEvent.java +++ /dev/null @@ -1,101 +0,0 @@ -package wecui.event; - -import java.util.HashMap; - -import wecui.WorldEditCUI; -import wecui.fevents.Cancellable; -import wecui.fevents.Event; -import wecui.fevents.HandlerList; - -/** - * Events for outgoing commands to server. - * Handlers can be registered to a certain command. - * - * @author lahwran - * @author yetanotherx - * - */ -public class ChatCommandEvent extends Event implements Cancellable { - - protected WorldEditCUI controller; - protected String rawMessage; - protected String command; - protected String[] args; - protected boolean handled; - protected static final HashMap> allhandlers = - new HashMap>(); - protected static final HandlerList defaulthandlers = - new HandlerList(); - - public ChatCommandEvent(WorldEditCUI controller, String chat) { - this.controller = controller; - this.rawMessage = chat; - - int firstspace = chat.indexOf(' '); - if (firstspace < 0) { - this.command = chat.substring(1); - this.args = new String[0]; - } else { - this.command = chat.substring(1, firstspace); - if (chat.length() - firstspace > 0) { - this.args = chat.substring(firstspace + 1).split(" "); - } else { - this.args = new String[0]; - } - } - - } - - @Override - protected String getEventName() { - return "ChatCommandEvent"; - } - - public static HandlerList getHandlers(String command) { - HandlerList handlers = allhandlers.get(command); - if (handlers == null) { - handlers = new HandlerList(); - allhandlers.put(command, handlers); - } - return handlers; - } - - @Override - protected HandlerList getHandlers() { - HandlerList handlers = allhandlers.get(this.command); - if (handlers == null) { - handlers = defaulthandlers; - } - return handlers; - } - - public void markHandled() { - this.handled = true; - } - - public boolean isHandled() { - return this.handled; - } - - public String[] getArgs() { - return this.args; - } - - public String getCommand() { - return this.command; - } - - public String getRawMessage() { - return this.rawMessage; - } - - @Override - public boolean isCancelled() { - return this.cancelled; - } - - @Override - public void setCancelled(boolean cancelled) { - this.cancelled = cancelled; - } -} \ No newline at end of file diff --git a/src/main/java/wecui/event/OutgoingChatEvent.java b/src/main/java/wecui/event/OutgoingChatEvent.java deleted file mode 100644 index 2fa16921..00000000 --- a/src/main/java/wecui/event/OutgoingChatEvent.java +++ /dev/null @@ -1,44 +0,0 @@ -package wecui.event; - -import wecui.WorldEditCUI; -import wecui.fevents.Cancellable; -import wecui.fevents.Event; -import wecui.fevents.HandlerList; - -/** - * Events for chat messages to/from server - * - * @author lahwran - * @author yetanotherx - * - */ -public class OutgoingChatEvent extends Event implements Cancellable { - - protected WorldEditCUI controller; - protected String message; - public static final HandlerList handlers = new HandlerList(); - - public OutgoingChatEvent(WorldEditCUI controller, String message) { - this.controller = controller; - this.message = message; - } - - @Override - protected String getEventName() { - return "OutgoingChatEvent"; - } - - @Override - protected HandlerList getHandlers() { - return handlers; - } - - public String getMessage() { - return this.message; - } - - @Override - public void setCancelled(boolean cancelled) { - this.cancelled = cancelled; - } -} diff --git a/src/main/java/wecui/event/WorldRenderEvent.java b/src/main/java/wecui/event/WorldRenderEvent.java deleted file mode 100644 index 7dddcbb0..00000000 --- a/src/main/java/wecui/event/WorldRenderEvent.java +++ /dev/null @@ -1,51 +0,0 @@ -package wecui.event; - -import wecui.WorldEditCUI; -import wecui.fevents.Event; -import wecui.fevents.HandlerList; -import wecui.util.Vector3; - -/** - * Event class triggered at world rendering, called at each rendering tick. - * Only one instance of this class should exist, to save processing time. - * - * @author lahwran - * @author yetanotherx - * - */ -public class WorldRenderEvent extends Event { - - protected WorldEditCUI controller; - protected float partialTick; - protected Vector3 pos; - public static final HandlerList handlers = new HandlerList(); - - public WorldRenderEvent(WorldEditCUI controller) { - } - - public void setPartialTick(float partialTick) { - this.partialTick = partialTick; - } - - public void setPosition(Vector3 pos) { - this.pos = pos; - } - - public float getPartialTick() { - return this.partialTick; - } - - public Vector3 getPosition() { - return this.pos; - } - - @Override - protected String getEventName() { - return "WorldRenderEvent"; - } - - @Override - protected HandlerList getHandlers() { - return handlers; - } -} diff --git a/src/main/java/wecui/event/cui/CUIBaseEvent.java b/src/main/java/wecui/event/cui/CUIBaseEvent.java index fd5f8f97..8d391f5d 100644 --- a/src/main/java/wecui/event/cui/CUIBaseEvent.java +++ b/src/main/java/wecui/event/cui/CUIBaseEvent.java @@ -8,83 +8,102 @@ * @author yetanotherx * */ -public abstract class CUIBaseEvent { - - protected WorldEditCUI controller; - protected String[] args; - - public CUIBaseEvent(WorldEditCUI controller, String[] args) { - this.controller = controller; - this.args = args; - } - - public abstract String run(); - - public abstract CUIEventType getEventType(); - - public String getEventName() { - //Hack for String.uppercaseFirstLetter, which doesn't exist. - String name = this.getEventType().name().toLowerCase(); - name = name.substring(0, 1).toUpperCase() + name.substring(1); - return name; - } - - /** - * Checks if the parameters match the required length. - * @return - */ - public boolean isValid() { - int max = this.getEventType().getMaxParameters(); - int min = this.getEventType().getMinParameters(); - - if (max == min) { - if (this.args.length != max) { - return false; - } - } else { - if (this.args.length > max || this.args.length < min) { - return false; - } - } - - return true; - - } - - public final String doRun() { - if (this.controller == null || this.args == null) { - throw new RuntimeException("Controller and parameters must both be set."); - } - - if (!this.isValid()) { - String message = "Invalid number of parameters. " + this.getEventName() + " event requires "; - if (this.getEventType().getMaxParameters() == this.getEventType().getMinParameters()) { - message += this.getEventType().getMaxParameters() + " parameters. "; - } else { - message += "between " + this.getEventType().getMinParameters() + " and " + this.getEventType().getMaxParameters() + " parameters. "; - } - - message += "Received " + this.args.length + " parameters instead. "; - for (String arg : this.args) { - message += arg + " "; - } - - throw new RuntimeException(message); - } - +public abstract class CUIBaseEvent +{ + + protected WorldEditCUI controller; + protected String[] args; + + public CUIBaseEvent(WorldEditCUI controller, String[] args) + { + this.controller = controller; + this.args = args; + } + + public abstract String run(); + + public abstract CUIEventType getEventType(); + + public String getEventName() + { + //Hack for String.uppercaseFirstLetter, which doesn't exist. + String name = this.getEventType().name().toLowerCase(); + name = name.substring(0, 1).toUpperCase() + name.substring(1); + return name; + } + + /** + * Checks if the parameters match the required length. + * @return + */ + public boolean isValid() + { + int max = this.getEventType().getMaxParameters(); + int min = this.getEventType().getMinParameters(); + + if (max == min) + { + if (this.args.length != max) + { + return false; + } + } + else + { + if (this.args.length > max || this.args.length < min) + { + return false; + } + } + + return true; + + } + + public final String doRun() + { + if (this.controller == null || this.args == null) + { + throw new RuntimeException("Controller and parameters must both be set."); + } + + if (!this.isValid()) + { + String message = "Invalid number of parameters. " + this.getEventName() + " event requires "; + if (this.getEventType().getMaxParameters() == this.getEventType().getMinParameters()) + { + message += this.getEventType().getMaxParameters() + " parameters. "; + } + else + { + message += "between " + this.getEventType().getMinParameters() + " and " + this.getEventType().getMaxParameters() + " parameters. "; + } + + message += "Received " + this.args.length + " parameters instead. "; + for (String arg : this.args) + { + message += arg + " "; + } + + throw new RuntimeException(message); + } + return this.run(); - - } - - public int getInt(int index) { - return (int) Float.parseFloat(this.args[index]); - } - - public double getDouble(int index) { - return Double.parseDouble(this.args[index]); - } - - public String getString(int index) { - return this.args[index]; - } + + } + + public int getInt(int index) + { + return (int)Float.parseFloat(this.args[index]); + } + + public double getDouble(int index) + { + return Double.parseDouble(this.args[index]); + } + + public String getString(int index) + { + return this.args[index]; + } } diff --git a/src/main/java/wecui/event/cui/CUICylinderEvent.java b/src/main/java/wecui/event/cui/CUICylinderEvent.java index 4dee0e69..23bda14a 100644 --- a/src/main/java/wecui/event/cui/CUICylinderEvent.java +++ b/src/main/java/wecui/event/cui/CUICylinderEvent.java @@ -8,31 +8,35 @@ * @author lahwran * @author yetanotherx */ -public class CUICylinderEvent extends CUIBaseEvent { - - public CUICylinderEvent(WorldEditCUI controller, String[] args) { - super(controller, args); - } - - @Override - public CUIEventType getEventType() { - return CUIEventType.CYLINDER; - } - - @Override - public String run() { - - int x = this.getInt(0); - int y = this.getInt(1); - int z = this.getInt(2); - double radX = this.getDouble(3); - double radZ = this.getDouble(4); - - this.controller.getSelection().setCylinderCenter(x, y, z); - this.controller.getSelection().setCylinderRadius(radX, radZ); - - this.controller.getDebugger().debug("Setting center/radius"); - - return null; - } +public class CUICylinderEvent extends CUIBaseEvent +{ + + public CUICylinderEvent(WorldEditCUI controller, String[] args) + { + super(controller, args); + } + + @Override + public CUIEventType getEventType() + { + return CUIEventType.CYLINDER; + } + + @Override + public String run() + { + + int x = this.getInt(0); + int y = this.getInt(1); + int z = this.getInt(2); + double radX = this.getDouble(3); + double radZ = this.getDouble(4); + + this.controller.getSelection().setCylinderCenter(x, y, z); + this.controller.getSelection().setCylinderRadius(radX, radZ); + + this.controller.getDebugger().debug("Setting center/radius"); + + return null; + } } diff --git a/src/main/java/wecui/event/cui/CUIEllipsoidEvent.java b/src/main/java/wecui/event/cui/CUIEllipsoidEvent.java index 44fd8989..df7acb1a 100644 --- a/src/main/java/wecui/event/cui/CUIEllipsoidEvent.java +++ b/src/main/java/wecui/event/cui/CUIEllipsoidEvent.java @@ -8,36 +8,43 @@ * @author lahwran * @author yetanotherx */ -public class CUIEllipsoidEvent extends CUIBaseEvent { - - public CUIEllipsoidEvent(WorldEditCUI controller, String[] args) { - super(controller, args); - } - - @Override - public CUIEventType getEventType() { - return CUIEventType.ELLIPSOID; - } - - @Override - public String run() { - - int id = this.getInt(0); - - if (id == 0) { - int x = this.getInt(1); - int y = this.getInt(2); - int z = this.getInt(3); - this.controller.getSelection().setEllipsoidCenter(x, y, z); - } else if (id == 1) { - double x = this.getDouble(1); - double y = this.getDouble(2); - double z = this.getDouble(3); - this.controller.getSelection().setEllipsoidRadii(x, y, z); - } - - this.controller.getDebugger().debug("Setting center/radius"); - - return null; - } +public class CUIEllipsoidEvent extends CUIBaseEvent +{ + + public CUIEllipsoidEvent(WorldEditCUI controller, String[] args) + { + super(controller, args); + } + + @Override + public CUIEventType getEventType() + { + return CUIEventType.ELLIPSOID; + } + + @Override + public String run() + { + + int id = this.getInt(0); + + if (id == 0) + { + int x = this.getInt(1); + int y = this.getInt(2); + int z = this.getInt(3); + this.controller.getSelection().setEllipsoidCenter(x, y, z); + } + else if (id == 1) + { + double x = this.getDouble(1); + double y = this.getDouble(2); + double z = this.getDouble(3); + this.controller.getSelection().setEllipsoidRadii(x, y, z); + } + + this.controller.getDebugger().debug("Setting center/radius"); + + return null; + } } diff --git a/src/main/java/wecui/event/cui/CUIEventType.java b/src/main/java/wecui/event/cui/CUIEventType.java index 6d540b4d..1e931c32 100644 --- a/src/main/java/wecui/event/cui/CUIEventType.java +++ b/src/main/java/wecui/event/cui/CUIEventType.java @@ -6,58 +6,67 @@ * @author yetanotherx * */ -public enum CUIEventType { - - SELECTION(CUISelectionEvent.class, "s", 1), - POINT(CUIPointEvent.class, "p", 5, 6), - POINT2D(CUIPoint2DEvent.class, "p2", 4, 5), - ELLIPSOID(CUIEllipsoidEvent.class, "e", 4), - CYLINDER(CUICylinderEvent.class, "cyl", 5), - MINMAX(CUIMinMaxEvent.class, "mm", 2), - UPDATE(CUIUpdateEvent.class, "u", 1), - POLYGON(CUIPolygonEvent.class, "poly", 3, 99); - - private final Class eventClass; - private final String key; - private final int min; - private final int max; - - private CUIEventType(Class eventClass, String key, int min, int max) { - this.eventClass = eventClass; - this.key = key; - this.min = min; - this.max = max; - } - - private CUIEventType(Class eventClass, String key, int paramCount) { - this.eventClass = eventClass; - this.key = key; - this.min = paramCount; - this.max = paramCount; - } - - public Class getEventClass() { - return this.eventClass; - } - - public String getKey() { - return this.key; - } - - public int getMaxParameters() { - return this.max; - } - - public int getMinParameters() { - return this.min; - } - - public static CUIEventType getTypeFromKey(String key) { - for (CUIEventType value : CUIEventType.values()) { - if (value.getKey().equals(key)) { - return value; - } - } - return null; - } +public enum CUIEventType +{ + SELECTION(CUISelectionEvent.class, "s", 1), + POINT(CUIPointEvent.class, "p", 5, 6), + POINT2D(CUIPoint2DEvent.class, "p2", 4, 5), + ELLIPSOID(CUIEllipsoidEvent.class, "e", 4), + CYLINDER(CUICylinderEvent.class, "cyl", 5), + MINMAX(CUIMinMaxEvent.class, "mm", 2), + UPDATE(CUIUpdateEvent.class, "u", 1), + POLYGON(CUIPolygonEvent.class, "poly", 3, 99); + + private final Class eventClass; + private final String key; + private final int min; + private final int max; + + private CUIEventType(Class eventClass, String key, int min, int max) + { + this.eventClass = eventClass; + this.key = key; + this.min = min; + this.max = max; + } + + private CUIEventType(Class eventClass, String key, int paramCount) + { + this.eventClass = eventClass; + this.key = key; + this.min = paramCount; + this.max = paramCount; + } + + public Class getEventClass() + { + return this.eventClass; + } + + public String getKey() + { + return this.key; + } + + public int getMaxParameters() + { + return this.max; + } + + public int getMinParameters() + { + return this.min; + } + + public static CUIEventType getTypeFromKey(String key) + { + for (CUIEventType value : CUIEventType.values()) + { + if (value.getKey().equals(key)) + { + return value; + } + } + return null; + } } diff --git a/src/main/java/wecui/event/cui/CUIMinMaxEvent.java b/src/main/java/wecui/event/cui/CUIMinMaxEvent.java index 82df658e..b7cfaba0 100644 --- a/src/main/java/wecui/event/cui/CUIMinMaxEvent.java +++ b/src/main/java/wecui/event/cui/CUIMinMaxEvent.java @@ -8,25 +8,29 @@ * @author lahwran * @author yetanotherx */ -public class CUIMinMaxEvent extends CUIBaseEvent { - - public CUIMinMaxEvent(WorldEditCUI controller, String[] args) { - super(controller, args); - } - - @Override - public CUIEventType getEventType() { - return CUIEventType.MINMAX; - } - - @Override - public String run() { - int min = this.getInt(0); - int max = this.getInt(1); - this.controller.getSelection().setMinMax(min, max); - - this.controller.getDebugger().debug("Expanding/contracting selection."); - - return null; - } +public class CUIMinMaxEvent extends CUIBaseEvent +{ + + public CUIMinMaxEvent(WorldEditCUI controller, String[] args) + { + super(controller, args); + } + + @Override + public CUIEventType getEventType() + { + return CUIEventType.MINMAX; + } + + @Override + public String run() + { + int min = this.getInt(0); + int max = this.getInt(1); + this.controller.getSelection().setMinMax(min, max); + + this.controller.getDebugger().debug("Expanding/contracting selection."); + + return null; + } } diff --git a/src/main/java/wecui/event/cui/CUIPoint2DEvent.java b/src/main/java/wecui/event/cui/CUIPoint2DEvent.java index 40362d6d..4f31e5e6 100644 --- a/src/main/java/wecui/event/cui/CUIPoint2DEvent.java +++ b/src/main/java/wecui/event/cui/CUIPoint2DEvent.java @@ -8,28 +8,33 @@ * @author lahwran * @author yetanotherx */ -public class CUIPoint2DEvent extends CUIPointEvent { - - public CUIPoint2DEvent(WorldEditCUI controller, String[] args) { - super(controller, args); - } - - @Override - public CUIEventType getEventType() { - return CUIEventType.POINT2D; - } - - @Override - public String run() { - - int id = this.getInt(0); - int x = this.getInt(1); - int z = this.getInt(2); - @SuppressWarnings("unused") int regionSize = this.getInt(3); - this.controller.getSelection().setPolygonPoint(id, x, z); - - this.controller.getDebugger().debug("Setting point2d #" + id); - - return null; - } +public class CUIPoint2DEvent extends CUIPointEvent +{ + + public CUIPoint2DEvent(WorldEditCUI controller, String[] args) + { + super(controller, args); + } + + @Override + public CUIEventType getEventType() + { + return CUIEventType.POINT2D; + } + + @Override + public String run() + { + + int id = this.getInt(0); + int x = this.getInt(1); + int z = this.getInt(2); + @SuppressWarnings("unused") + int regionSize = this.getInt(3); + this.controller.getSelection().setPolygonPoint(id, x, z); + + this.controller.getDebugger().debug("Setting point2d #" + id); + + return null; + } } diff --git a/src/main/java/wecui/event/cui/CUIPointEvent.java b/src/main/java/wecui/event/cui/CUIPointEvent.java index 14f25882..6b83065e 100644 --- a/src/main/java/wecui/event/cui/CUIPointEvent.java +++ b/src/main/java/wecui/event/cui/CUIPointEvent.java @@ -8,46 +8,51 @@ * @author lahwran * @author yetanotherx */ -public class CUIPointEvent extends CUIBaseEvent { - - public CUIPointEvent(WorldEditCUI controller, String[] args) { - super(controller, args); - } - - @Override - public CUIEventType getEventType() { - return CUIEventType.POINT; - } - - @Override - public String run() { - int id = this.getInt(0); - double x = this.getDouble(1); - double y = this.getDouble(2); - double z = this.getDouble(3); - - this.controller.getSelection().setCuboidPoint(id, x, y, z); - this.setLocalPoint(id, x, y, z); - this.controller.getDebugger().debug("Setting point #" + id); - - return null; - } - - protected void setLocalPoint(int id, double x, double y, double z) { - /*if (controller.getLocalPlugin().isEnabled()) { - - WorldEdit plugin = controller.getLocalPlugin().getPlugin(); - CUIWorld world = controller.getLocalPlugin().getWorld(); - - WorldVector clicked = new WorldVector(world, x, y, z); - LocalSession session = plugin.getSession("player"); - RegionSelector selector = session.getRegionSelector(world); - - if (id == 0) { - selector.selectPrimary(clicked); - } else { - selector.selectSecondary(clicked); - } - }*/ - } +public class CUIPointEvent extends CUIBaseEvent +{ + + public CUIPointEvent(WorldEditCUI controller, String[] args) + { + super(controller, args); + } + + @Override + public CUIEventType getEventType() + { + return CUIEventType.POINT; + } + + @Override + public String run() + { + int id = this.getInt(0); + double x = this.getDouble(1); + double y = this.getDouble(2); + double z = this.getDouble(3); + + this.controller.getSelection().setCuboidPoint(id, x, y, z); + this.setLocalPoint(id, x, y, z); + this.controller.getDebugger().debug("Setting point #" + id); + + return null; + } + + protected void setLocalPoint(int id, double x, double y, double z) + { + /*if (controller.getLocalPlugin().isEnabled()) { + + WorldEdit plugin = controller.getLocalPlugin().getPlugin(); + CUIWorld world = controller.getLocalPlugin().getWorld(); + + WorldVector clicked = new WorldVector(world, x, y, z); + LocalSession session = plugin.getSession("player"); + RegionSelector selector = session.getRegionSelector(world); + + if (id == 0) { + selector.selectPrimary(clicked); + } else { + selector.selectSecondary(clicked); + } + }*/ + } } diff --git a/src/main/java/wecui/event/cui/CUIPolygonEvent.java b/src/main/java/wecui/event/cui/CUIPolygonEvent.java index 6199a66b..06d24523 100644 --- a/src/main/java/wecui/event/cui/CUIPolygonEvent.java +++ b/src/main/java/wecui/event/cui/CUIPolygonEvent.java @@ -8,27 +8,32 @@ * @author lahwran * @author yetanotherx */ -public class CUIPolygonEvent extends CUIBaseEvent { - - public CUIPolygonEvent(WorldEditCUI controller, String[] args) { - super(controller, args); - } - - @Override - public CUIEventType getEventType() { - return CUIEventType.POLYGON; - } - - @Override - public String run() { - final int[] vertexIds = new int[args.length]; - for (int i = 0; i < args.length; ++i) { - vertexIds[i] = this.getInt(i); - } - - this.controller.getSelection().addPolygon(vertexIds); - //this.controller.getDebugger().debug("Setting point #" + id); - - return null; - } +public class CUIPolygonEvent extends CUIBaseEvent +{ + + public CUIPolygonEvent(WorldEditCUI controller, String[] args) + { + super(controller, args); + } + + @Override + public CUIEventType getEventType() + { + return CUIEventType.POLYGON; + } + + @Override + public String run() + { + final int[] vertexIds = new int[args.length]; + for (int i = 0; i < args.length; ++i) + { + vertexIds[i] = this.getInt(i); + } + + this.controller.getSelection().addPolygon(vertexIds); + //this.controller.getDebugger().debug("Setting point #" + id); + + return null; + } } diff --git a/src/main/java/wecui/event/cui/CUISelectionEvent.java b/src/main/java/wecui/event/cui/CUISelectionEvent.java index 1062d1b6..f7729bcb 100644 --- a/src/main/java/wecui/event/cui/CUISelectionEvent.java +++ b/src/main/java/wecui/event/cui/CUISelectionEvent.java @@ -14,39 +14,54 @@ * @author lahwran * @author yetanotherx */ -public class CUISelectionEvent extends CUIBaseEvent { - - public CUISelectionEvent(WorldEditCUI controller, String[] args) { - super(controller, args); - } - - @Override - public CUIEventType getEventType() { - return CUIEventType.SELECTION; - } - - @Override - public String run() { - - BaseRegion newRegion = null; - - if (this.getString(0).equals("cuboid")) { - newRegion = new CuboidRegion(this.controller); - } else if (this.getString(0).equals("polygon2d")) { - newRegion = new PolygonRegion(this.controller); - } else if (this.getString(0).equals("ellipsoid")) { - newRegion = new EllipsoidRegion(this.controller); - } else if (this.getString(0).equals("cylinder")) { - newRegion = new CylinderRegion(this.controller); - } else if (this.getString(0).equals("polyhedron")) { - newRegion = new PolyhedronRegion(this.controller); - } else { - return "Invalid selection type. Must be cuboid|polygon2d|ellipsoid|cylinder|polyhedron."; - } - - this.controller.setSelection(newRegion); - this.controller.getDebugger().debug("Received selection event, initalizing new region instance."); - - return null; - } +public class CUISelectionEvent extends CUIBaseEvent +{ + + public CUISelectionEvent(WorldEditCUI controller, String[] args) + { + super(controller, args); + } + + @Override + public CUIEventType getEventType() + { + return CUIEventType.SELECTION; + } + + @Override + public String run() + { + + BaseRegion newRegion = null; + + if (this.getString(0).equals("cuboid")) + { + newRegion = new CuboidRegion(this.controller); + } + else if (this.getString(0).equals("polygon2d")) + { + newRegion = new PolygonRegion(this.controller); + } + else if (this.getString(0).equals("ellipsoid")) + { + newRegion = new EllipsoidRegion(this.controller); + } + else if (this.getString(0).equals("cylinder")) + { + newRegion = new CylinderRegion(this.controller); + } + else if (this.getString(0).equals("polyhedron")) + { + newRegion = new PolyhedronRegion(this.controller); + } + else + { + return "Invalid selection type. Must be cuboid|polygon2d|ellipsoid|cylinder|polyhedron."; + } + + this.controller.setSelection(newRegion); + this.controller.getDebugger().debug("Received selection event, initalizing new region instance."); + + return null; + } } diff --git a/src/main/java/wecui/event/cui/CUIUpdateEvent.java b/src/main/java/wecui/event/cui/CUIUpdateEvent.java index 5cc62a3f..d432ff04 100644 --- a/src/main/java/wecui/event/cui/CUIUpdateEvent.java +++ b/src/main/java/wecui/event/cui/CUIUpdateEvent.java @@ -8,19 +8,23 @@ * @author lahwran * @author yetanotherx */ -public class CUIUpdateEvent extends CUIBaseEvent { - - public CUIUpdateEvent(WorldEditCUI controller, String[] args) { - super(controller, args); - } - - @Override - public CUIEventType getEventType() { - return CUIEventType.UPDATE; - } - - @Override - public String run() { - return null; - } +public class CUIUpdateEvent extends CUIBaseEvent +{ + + public CUIUpdateEvent(WorldEditCUI controller, String[] args) + { + super(controller, args); + } + + @Override + public CUIEventType getEventType() + { + return CUIEventType.UPDATE; + } + + @Override + public String run() + { + return null; + } } diff --git a/src/main/java/wecui/event/listeners/CUIListener.java b/src/main/java/wecui/event/listeners/CUIListener.java deleted file mode 100644 index c2fd61ed..00000000 --- a/src/main/java/wecui/event/listeners/CUIListener.java +++ /dev/null @@ -1,52 +0,0 @@ -package wecui.event.listeners; - -import wecui.WorldEditCUI; -import wecui.event.CUIEvent; -import wecui.event.cui.CUIBaseEvent; -import wecui.event.cui.CUIEventType; -import wecui.exception.ReflectException; -import wecui.fevents.Listener; -import wecui.vendor.org.joor.Reflect; - -/** - * Listener class for CUIEvent - * - * @author lahwran - * @author yetanotherx - * - */ -public class CUIListener implements Listener { - - protected WorldEditCUI controller; - - public CUIListener(WorldEditCUI controller) { - this.controller = controller; - } - - @Override - public void onEvent(CUIEvent event) { - - //Get a CUIEventType enum value from the first section of the CUI message - CUIEventType eventType = CUIEventType.getTypeFromKey(event.getType()); - if (eventType == null || eventType.getEventClass() == null) { - event.markInvalid("Unknown CUIEvent identifier."); - } - - if (eventType == null) return; - - try { - CUIBaseEvent newEvent = Reflect.on(eventType.getEventClass()).create(this.controller, event.getParams()).get(); - - //Run the event. If doRun returns null, the event was successful. - //If it returns a string, it uses that as the error message. - String result = newEvent.doRun(); - if (result != null) { - event.markInvalid(result); - } else { - event.setHandled(true); - } - } catch (ReflectException e) { - return; - } - } -} diff --git a/src/main/java/wecui/event/listeners/ChannelListener.java b/src/main/java/wecui/event/listeners/ChannelListener.java index f4dff3e5..27785eca 100644 --- a/src/main/java/wecui/event/listeners/ChannelListener.java +++ b/src/main/java/wecui/event/listeners/ChannelListener.java @@ -2,8 +2,10 @@ import wecui.WorldEditCUI; import wecui.event.CUIEvent; -import wecui.event.ChannelEvent; -import wecui.fevents.Listener; +import wecui.event.cui.CUIBaseEvent; +import wecui.event.cui.CUIEventType; +import wecui.exception.ReflectException; +import wecui.vendor.org.joor.Reflect; /** * Listener class for incoming plugin channel messages @@ -12,27 +14,53 @@ * @author yetanotherx * */ -public class ChannelListener implements Listener { +public class ChannelListener +{ + private WorldEditCUI controller; + + public ChannelListener(WorldEditCUI controller) + { + this.controller = controller; + } + + public void onMessage(String message) + { + String[] split = message.split("[|]"); + String type = split[0]; + String args = message.substring(type.length() + 1); + + this.controller.getDebugger().debug("Received CUI event from server: " + message); + + try + { + CUIEvent cuiEvent = new CUIEvent(this.controller, type, args.split("[|]")); + this.processCUIEvent(cuiEvent); + } + catch (Exception ex) + { + } + } - protected WorldEditCUI controller; - - public ChannelListener(WorldEditCUI controller) { - this.controller = controller; - } - - @Override - public void onEvent(ChannelEvent event) { - String[] split = event.getMessage().split("[|]"); - String type = split[0]; - String args = event.getMessage().substring(type.length() + 1); - - this.controller.getDebugger().debug("Received CUI event from server: " + event.getMessage()); - - CUIEvent cuievent = new CUIEvent(this.controller, type, args.split("[|]")); - this.controller.getEventManager().callEvent(cuievent); - - if (!cuievent.isHandled()) { - cuievent.markInvalid("Invalid message type. Update WorldEditCUI to the latest version."); - } - } + public void processCUIEvent(CUIEvent event) + { + // Get a CUIEventType enum value from the first section of the CUI message + CUIEventType eventType = CUIEventType.getTypeFromKey(event.getType()); + if (eventType == null || eventType.getEventClass() == null) + { + return; + } + + try + { + CUIBaseEvent newEvent = Reflect.on(eventType.getEventClass()).create(this.controller, event.getParams()).get(); + + //Run the event. If doRun returns null, the event was successful. + //If it returns a string, it uses that as the error message. + newEvent.doRun(); + } + catch (ReflectException e) + { + return; + } + } } diff --git a/src/main/java/wecui/event/listeners/WorldRenderListener.java b/src/main/java/wecui/event/listeners/WorldRenderListener.java index d9591c98..7bed7e28 100644 --- a/src/main/java/wecui/event/listeners/WorldRenderListener.java +++ b/src/main/java/wecui/event/listeners/WorldRenderListener.java @@ -1,12 +1,11 @@ package wecui.event.listeners; +import static org.lwjgl.opengl.GL11.*; +import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityClientPlayerMP; - -import org.lwjgl.opengl.GL11; - +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.RenderHelper; import wecui.WorldEditCUI; -import wecui.event.WorldRenderEvent; -import wecui.fevents.Listener; /** * Listener for WorldRenderEvent @@ -15,63 +14,68 @@ * @author yetanotherx * */ -public class WorldRenderListener implements Listener { - - private WorldEditCUI controller; - - public WorldRenderListener(WorldEditCUI controller) { - this.controller = controller; - } - - /** - * Renders the current selection if it exists - * @param event - */ - @Override - public void onEvent(WorldRenderEvent event) { - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - GL11.glEnable(GL11.GL_BLEND); - GL11.glEnable(GL11.GL_ALPHA_TEST); - GL11.glAlphaFunc(GL11.GL_GREATER, 0.0F); - GL11.glDisable(GL11.GL_TEXTURE_2D); - GL11.glDepthMask(false); - GL11.glPushMatrix(); - - try { - GL11.glTranslated(-this.getPlayerXGuess(event.getPartialTick()), - -this.getPlayerYGuess(event.getPartialTick()), - -this.getPlayerZGuess(event.getPartialTick())); - GL11.glColor3f(1.0f, 1.0f, 1.0f); - if (this.controller.getSelection() != null) { - this.controller.getSelection().render(); - } - } catch (Exception e) { - } - - GL11.glDepthFunc(GL11.GL_LEQUAL); - GL11.glPopMatrix(); - - GL11.glDepthMask(true); - GL11.glEnable(GL11.GL_TEXTURE_2D); - GL11.glDisable(GL11.GL_BLEND); - GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F); - } +public class WorldRenderListener +{ + private WorldEditCUI controller; + + private Minecraft minecraft; + + public WorldRenderListener(WorldEditCUI controller, Minecraft minecraft) + { + this.controller = controller; + this.minecraft = minecraft; + } + + public void onRender(float partialTicks) + { + RenderHelper.disableStandardItemLighting(); + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); + glEnable(GL_ALPHA_TEST); + glAlphaFunc(GL_GREATER, 0.0F); + glDisable(GL_TEXTURE_2D); + glDepthMask(false); + glPushMatrix(); + + try + { + EntityClientPlayerMP thePlayer = this.minecraft.thePlayer; + glTranslated(-this.getPlayerXGuess(thePlayer, partialTicks), -this.getPlayerYGuess(thePlayer, partialTicks), -this.getPlayerZGuess(thePlayer, partialTicks)); + glColor3f(1.0f, 1.0f, 1.0f); + if (this.controller.getSelection() != null) + { + this.controller.getSelection().render(); + } + } + catch (Exception e) + { + } + + glDepthFunc(GL_LEQUAL); + glPopMatrix(); + + glDepthMask(true); + glEnable(GL_TEXTURE_2D); + glDisable(GL_BLEND); + glAlphaFunc(GL_GREATER, 0.1F); - private double getPlayerXGuess(float renderTick) + RenderHelper.enableStandardItemLighting(); + } + + private double getPlayerXGuess(EntityClientPlayerMP thePlayer, float renderTick) { - EntityClientPlayerMP thePlayer = this.controller.getMinecraft().thePlayer; return thePlayer.prevPosX + ((thePlayer.posX - thePlayer.prevPosX) * renderTick); } - private double getPlayerYGuess(float renderTick) + private double getPlayerYGuess(EntityClientPlayerMP thePlayer, float renderTick) { - EntityClientPlayerMP thePlayer = this.controller.getMinecraft().thePlayer; return thePlayer.prevPosY + ((thePlayer.posY - thePlayer.prevPosY) * renderTick); } - private double getPlayerZGuess(float renderTick) + private double getPlayerZGuess(EntityClientPlayerMP thePlayer, float renderTick) { - EntityClientPlayerMP thePlayer = this.controller.getMinecraft().thePlayer; return thePlayer.prevPosZ + ((thePlayer.posZ - thePlayer.prevPosZ) * renderTick); } } diff --git a/src/main/java/wecui/exception/ConfigurationException.java b/src/main/java/wecui/exception/ConfigurationException.java deleted file mode 100644 index d1147eaf..00000000 --- a/src/main/java/wecui/exception/ConfigurationException.java +++ /dev/null @@ -1,14 +0,0 @@ -package wecui.exception; - -public class ConfigurationException extends Exception { - - private static final long serialVersionUID = -2442886939908724203L; - - public ConfigurationException() { - super(); - } - - public ConfigurationException(String msg) { - super(msg); - } -} \ No newline at end of file diff --git a/src/main/java/wecui/exception/InitializationException.java b/src/main/java/wecui/exception/InitializationException.java index 68ff8a82..4075b5d2 100644 --- a/src/main/java/wecui/exception/InitializationException.java +++ b/src/main/java/wecui/exception/InitializationException.java @@ -7,14 +7,17 @@ * @author yetanotherx * */ -public class InitializationException extends Exception { - - private static final long serialVersionUID = 1L; - - public InitializationException(String string) { - super(string); - } - - public InitializationException() { - } +public class InitializationException extends Exception +{ + + private static final long serialVersionUID = 1L; + + public InitializationException(String string) + { + super(string); + } + + public InitializationException() + { + } } diff --git a/src/main/java/wecui/exception/ReflectException.java b/src/main/java/wecui/exception/ReflectException.java index 8a3671ff..eb160709 100644 --- a/src/main/java/wecui/exception/ReflectException.java +++ b/src/main/java/wecui/exception/ReflectException.java @@ -54,26 +54,31 @@ * * @author Lukas Eder */ -public class ReflectException extends RuntimeException { - - /** - * Generated UID - */ - private static final long serialVersionUID = -6213149635297151443L; - - public ReflectException(String message) { - super(message); - } - - public ReflectException(String message, Throwable cause) { - super(message, cause); - } - - public ReflectException() { - super(); - } - - public ReflectException(Throwable cause) { - super(cause); - } -} \ No newline at end of file +public class ReflectException extends RuntimeException +{ + + /** + * Generated UID + */ + private static final long serialVersionUID = -6213149635297151443L; + + public ReflectException(String message) + { + super(message); + } + + public ReflectException(String message, Throwable cause) + { + super(message, cause); + } + + public ReflectException() + { + super(); + } + + public ReflectException(Throwable cause) + { + super(cause); + } +} diff --git a/src/main/java/wecui/fevents/Cancellable.java b/src/main/java/wecui/fevents/Cancellable.java deleted file mode 100644 index 9d5e4ea2..00000000 --- a/src/main/java/wecui/fevents/Cancellable.java +++ /dev/null @@ -1,27 +0,0 @@ -package wecui.fevents; - -/** - * Sets the setCancelled() method of events to public. - * Implement this interface to use the cancelling methods - * - * @author lahwran - * - */ -public interface Cancellable { - - /** - * If an event stops propogating (ie, is cancelled) partway through an even - * slot, that slot will not cease execution, but future even slots will not - * be called. - * - * @param cancelled True to set event canceled, False to uncancel event. - */ - public void setCancelled(boolean cancelled); - - /** - * Get event canceled state. - * - * @return whether event is cancelled - */ - public boolean isCancelled(); -} diff --git a/src/main/java/wecui/fevents/Event.java b/src/main/java/wecui/fevents/Event.java deleted file mode 100644 index 9e316f0b..00000000 --- a/src/main/java/wecui/fevents/Event.java +++ /dev/null @@ -1,76 +0,0 @@ -package wecui.fevents; - -/** - * Event superclass. should be extended as: - *
- *     class MyEvent extends Event {
- *         public static final HandlerList handlers = new HandlerList();
- *
- *         @Override
- *         HandlerList getHandlers() {
- *             return handlers;
- *         }
- *         @Override
- *         void call(Listener listener) {
- *             listener.onEvent(this);
- *         }
- *     }
- * 
- * - * @author lahwran - * - * @param Event class - * - */ -public abstract class Event> { - - /** - * Stores cancelled status. will be false unless a subclass publishes - * setCancelled. - */ - protected boolean cancelled = false; - - /** - * Get the static handler list of this event subclass. - * - * @return HandlerList to call event with - */ - protected abstract HandlerList getHandlers(); - - /** - * Get event type name. - * - * @return event name - */ - protected abstract String getEventName(); - - @Override - public String toString() { - return this.getEventName() + " (" + this.getClass().getName() + ")"; - } - - /** - * Set cancelled status. Events which wish to be cancellable should - * implement Cancellable and implement setCancelled as: - *
-     *     public void setCancelled(boolean cancelled) {
-     *         super.setCancelled(cancelled);
-     *     }
-     * 
- * @param cancelled True to cancel event - */ - protected void setCancelled(boolean cancelled) { - this.cancelled = cancelled; - } - - /** - * Returning true will prevent calling any even Order slots. - * - * @see Order - * @return false if the event is propogating; events which do not implement - * Cancellable should never return true here - */ - public boolean isCancelled() { - return this.cancelled; - } -} diff --git a/src/main/java/wecui/fevents/EventManager.java b/src/main/java/wecui/fevents/EventManager.java deleted file mode 100644 index 00cad71c..00000000 --- a/src/main/java/wecui/fevents/EventManager.java +++ /dev/null @@ -1,54 +0,0 @@ -package wecui.fevents; - -import wecui.InitializationFactory; -import wecui.WorldEditCUI; -import wecui.exception.InitializationException; - -/** - * This class doesn't actually need to exist, but it feels wrong to have this - * part of the event call logic inside Event - * - * @author lahwran - */ -public class EventManager implements InitializationFactory { - - protected WorldEditCUI controller; - - public EventManager(WorldEditCUI controller) { - this.controller = controller; - } - - /** - * Call an event. - * - * @param Event subclass - * @param event Event to handle - */ - public > void callEvent(TEvent event) { - HandlerList handlerlist = event.getHandlers(); - handlerlist.bake(); - - Listener[][] handlers = handlerlist.handlers; - int[] handlerids = handlerlist.handlerids; - - for (int arrayidx = 0; arrayidx < handlers.length; arrayidx++) { - - // if the order slot is even and the event has stopped propogating - if (event.isCancelled() && (handlerids[arrayidx] & 1) == 0) { - continue; // then don't call this order slot - } - for (int handler = 0; handler < handlers[arrayidx].length; handler++) { - try { - handlers[arrayidx][handler].onEvent(event); - } catch (Throwable t) { - System.err.println("Error while passing event " + event); - t.printStackTrace(); - } - } - } - } - - @Override - public void initialize() throws InitializationException { - } -} diff --git a/src/main/java/wecui/fevents/HandlerList.java b/src/main/java/wecui/fevents/HandlerList.java deleted file mode 100644 index 9d7fc961..00000000 --- a/src/main/java/wecui/fevents/HandlerList.java +++ /dev/null @@ -1,130 +0,0 @@ -package wecui.fevents; - -import java.util.ArrayList; -import java.util.EnumMap; -import java.util.Map.Entry; - -/** - * @author lahwran - * @param Event type - * - */ -@SuppressWarnings("unchecked") -public class HandlerList> { - - /** - * handler array. this field being an array is the key to this system's speed. - * - * is initialized in bake(). - */ - public Listener[][] handlers; - /** - * Int array same length as handlers. each value in this array is the index - * of an Order slot, corossponding to the equivalent value in handlers. - * - * is initialized in bake(). - */ - public int[] handlerids; - /** - * Dynamic handler lists. These are changed using register() and - * unregister() and are automatically baked to the handlers array any - * time they have changed. - */ - private final EnumMap>> handlerslots; - /** - * Whether the current handlerslist has been fully baked. When this is set - * to false, the Map> will be baked to Listener[][] - * next time the event is called. - * - * @see EventManager.callEvent - */ - private boolean baked = false; - /** - * List of all handlerlists which have been created, for use in bakeall() - */ - private static ArrayList>> alllists = new ArrayList>>(); - - /** - * Bake all handler lists. Best used just after all normal event - * registration is complete, ie just after all plugins are loaded if - * you're using fevents in a plugin system. - */ - public static void bakeall() { - for (HandlerList> h : alllists) { - h.bake(); - } - } - - /** - * Create a new handler list and initialize using EventManager.Order - * handlerlist is then added to meta-list for use in bakeall() - */ - public HandlerList() { - this.handlerslots = new EnumMap>>(Order.class); - for (Order o : Order.values()) { - this.handlerslots.put(o, new ArrayList>()); - } - alllists.add(this); - } - - /** - * Register a new listener in this handler list - * @param listener listener to register - * @param order order location at which to call provided listener - */ - public void register(Listener listener, Order order) { - if (this.handlerslots.get(order).contains(listener)) { - throw new IllegalStateException("This listener is already registered to order " + order.toString()); - } - this.baked = false; - this.handlerslots.get(order).add(listener); - } - - /** - * Remove a listener from all order slots - * @param listener listener to purge - */ - public void unregister(Listener listener) { - for (Order o : Order.values()) { - this.unregister(listener, o); - } - } - - /** - * Remove a listener from a specific order slot - * @param listener listener to remove - * @param order order from which to remove listener - */ - public void unregister(Listener listener, Order order) { - if (this.handlerslots.get(order).contains(listener)) { - this.baked = false; - this.handlerslots.get(order).remove(listener); - } - } - - /** - * Bake HashMap and ArrayLists to 2d array - does nothing if not necessary - */ - void bake() { - if (this.baked) { - return; // don't re-bake when still valid - } - ArrayList>[]> handlerslist = new ArrayList>[]>(); - ArrayList handleridslist = new ArrayList(); - for (Entry>> entry : this.handlerslots.entrySet()) { - Order orderslot = entry.getKey(); - - ArrayList> list = entry.getValue(); - - int ord = orderslot.getIndex(); - handlerslist.add(list.toArray(new Listener[list.size()])); - handleridslist.add(ord); - } - this.handlers = handlerslist.toArray(new Listener[handlerslist.size()][]); - this.handlerids = new int[handleridslist.size()]; - for (int i = 0; i < handleridslist.size(); i++) { - this.handlerids[i] = handleridslist.get(i); - } - this.baked = true; - } -} diff --git a/src/main/java/wecui/fevents/Listener.java b/src/main/java/wecui/fevents/Listener.java deleted file mode 100644 index 5f30385e..00000000 --- a/src/main/java/wecui/fevents/Listener.java +++ /dev/null @@ -1,14 +0,0 @@ -package wecui.fevents; - -/** - * @author lahwran - * @param Event type - */ -public interface Listener> { - - /** - * Handle an event - * @param event Event to handle - */ - public void onEvent(TEvent event); -} diff --git a/src/main/java/wecui/fevents/Order.java b/src/main/java/wecui/fevents/Order.java deleted file mode 100644 index df703f68..00000000 --- a/src/main/java/wecui/fevents/Order.java +++ /dev/null @@ -1,77 +0,0 @@ -package wecui.fevents; - -/** - * Order of event listener calls. - * - * Odd-numbered slots are called even when - * events are marked "not propogating". If an event stops propogating partway - * through an even slot, that slot will not cease execution, but future even - * slots will not be called. - * - * @author lahwran - */ -public enum Order { - - /** - * Called before all other handlers. - * Should be used for high-priority event canceling. - */ - Earliest(0), - /** - * Called after "Earliest" handlers and before "Early" handlers. Is called - * even when event has been canceled. Should generally be used to uncancel - * events canceled in Earliest. - */ - Early_IgnoreCancelled(1), - /** - * Called after "Earliest" handlers. Should generally be used for low - * priority event canceling. - */ - Early(2), - /** - * Called after "Early" handlers and before "Default" handlers. Is called - * even when event has been canceled. This is for general-purpose - * always-run events. - */ - Default_IgnoreCancelled(3), - /** - * Default call, for general purpose handlers - */ - Default(4), - /** - * Called after "Default" handlers and before "Late" handlers. Is called - * even when event has been canceled. - */ - Late_IgnoreCancelled(5), - /** - * Called after "Default" handlers. - */ - Late(6), - /** - * Called after "Late" handlers and before "Latest" handlers. Is called - * even when event has been canceled. - */ - Latest_IgnoreCancelled(7), - /** - * Called after "Late" handlers. - */ - Latest(8), - /** - * Called after "Latest" handlers. No changes to the event should be made - * in this order slot (though it is not enforced). Is called even when - * event has been cancelled. - */ - Monitor(9); - private int index; - - Order(int index) { - this.index = index; - } - - /** - * @return the index - */ - public int getIndex() { - return this.index; - } -} \ No newline at end of file diff --git a/src/main/java/wecui/gui/GuiColourButton.java b/src/main/java/wecui/gui/GuiColourButton.java index 8b3836ee..42679ed9 100644 --- a/src/main/java/wecui/gui/GuiColourButton.java +++ b/src/main/java/wecui/gui/GuiColourButton.java @@ -28,7 +28,7 @@ public GuiColourButton(Minecraft minecraft, int id, int xPosition, int yPosition this.lineColour = lineColour; this.updateColour(lineColour); } - + /** * @param lineColour */ @@ -53,53 +53,54 @@ public void save() @Override public void drawControl(Minecraft minecraft, int mouseX, int mouseY) { - if (this.field_146125_m) - { - boolean mouseOver = mouseX >= this.field_146128_h && mouseY >= this.field_146129_i && mouseX < this.field_146128_h + this.field_146120_f && mouseY < this.field_146129_i + this.field_146121_g; - int borderColour = mouseOver || this.picker != null ? 0xFFFFFFFF : 0xFFA0A0A0; - - drawRect(this.field_146128_h, this.field_146129_i, this.field_146128_h + this.field_146120_f, this.field_146129_i + this.field_146121_g, borderColour); - - int v = Math.min(Math.max((int)(((float)this.field_146121_g / (float)this.field_146120_f) * 1024F), 256), 1024); - - minecraft.getTextureManager().bindTexture(GuiColourPicker.COLOURPICKER_CHECKER); - glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - this.drawTexturedModalRect(this.field_146128_h + 1, this.field_146129_i + 1, this.field_146128_h + this.field_146120_f - 1, this.field_146129_i + this.field_146121_g - 1, 0, 0, 1024, v); - - drawRect(this.field_146128_h + 1, this.field_146129_i + 1, this.field_146128_h + this.field_146120_f - 1, this.field_146129_i + this.field_146121_g - 1, this.colour); - - this.mouseDragged(minecraft, mouseX, mouseY); - - if (this.displayString != null && this.displayString.length() > 0) - { - this.drawString(minecraft.fontRenderer, this.displayString, this.field_146128_h + this.field_146120_f + 8, this.field_146129_i + (this.field_146121_g - 8) / 2, 0xFFFFFFFF); - } - } + if (this.field_146125_m) + { + boolean mouseOver = mouseX >= this.field_146128_h && mouseY >= this.field_146129_i && mouseX < this.field_146128_h + this.field_146120_f && mouseY < this.field_146129_i + this.field_146121_g; + int borderColour = mouseOver || this.picker != null ? 0xFFFFFFFF : 0xFFA0A0A0; + + drawRect(this.field_146128_h, this.field_146129_i, this.field_146128_h + this.field_146120_f, this.field_146129_i + this.field_146121_g, borderColour); + + int v = Math.min(Math.max((int)(((float)this.field_146121_g / (float)this.field_146120_f) * 1024F), 256), 1024); + + minecraft.getTextureManager().bindTexture(GuiColourPicker.COLOURPICKER_CHECKER); + glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.drawTexturedModalRect(this.field_146128_h + 1, this.field_146129_i + 1, this.field_146128_h + this.field_146120_f - 1, this.field_146129_i + this.field_146121_g - 1, 0, 0, 1024, v); + + drawRect(this.field_146128_h + 1, this.field_146129_i + 1, this.field_146128_h + this.field_146120_f - 1, this.field_146129_i + this.field_146121_g - 1, this.colour); + + this.mouseDragged(minecraft, mouseX, mouseY); + + if (this.displayString != null && this.displayString.length() > 0) + { + this.drawString(minecraft.fontRenderer, this.displayString, this.field_146128_h + this.field_146120_f + 8, this.field_146129_i + (this.field_146121_g - 8) / 2, 0xFFFFFFFF); + } + } } public void drawPicker(Minecraft minecraft, int mouseX, int mouseY) { - if (this.field_146125_m && this.picker != null) - { - this.picker.drawButton(minecraft, mouseX, mouseY); - - if (this.picker.getDialogResult() == DialogResult.OK) - { - this.closePicker(true); - } - else if (this.picker.getDialogResult() == DialogResult.Cancel) - { - this.closePicker(false); - } - } + if (this.field_146125_m && this.picker != null) + { + this.picker.drawButton(minecraft, mouseX, mouseY); + + if (this.picker.getDialogResult() == DialogResult.OK) + { + this.closePicker(true); + } + else if (this.picker.getDialogResult() == DialogResult.Cancel) + { + this.closePicker(false); + } + } } - + /** * */ public void closePicker(boolean getColour) { - if (getColour) this.colour = this.picker.getColour(); + if (getColour) + this.colour = this.picker.getColour(); this.picker = null; this.pickerClicked = false; } @@ -116,7 +117,7 @@ public void mouseReleased(int mouseX, int mouseY) this.pickerClicked = false; } } - + /* (non-Javadoc) * @see net.minecraft.src.GuiButton#mousePressed(net.minecraft.src.Minecraft, int, int) */ @@ -124,7 +125,7 @@ public void mouseReleased(int mouseX, int mouseY) public boolean mousePressed(Minecraft minecraft, int mouseX, int mouseY) { boolean pressed = super.mousePressed(minecraft, mouseX, mouseY); - + if (this.picker == null) { if (pressed) @@ -140,7 +141,7 @@ public boolean mousePressed(Minecraft minecraft, int mouseX, int mouseY) } this.pickerClicked = this.picker.mousePressed(minecraft, mouseX, mouseY); - + if (pressed && !this.pickerClicked) { this.closePicker(true); @@ -148,7 +149,7 @@ public boolean mousePressed(Minecraft minecraft, int mouseX, int mouseY) return this.pickerClicked; } - + public boolean keyTyped(char keyChar, int keyCode) { return (this.picker != null) ? this.picker.textBoxKeyTyped(keyChar, keyCode) : false; diff --git a/src/main/java/wecui/gui/GuiColourPicker.java b/src/main/java/wecui/gui/GuiColourPicker.java index 2bc7d0f1..12e31a9f 100644 --- a/src/main/java/wecui/gui/GuiColourPicker.java +++ b/src/main/java/wecui/gui/GuiColourPicker.java @@ -21,8 +21,8 @@ public class GuiColourPicker extends GuiControl { public static final ResourceLocation COLOURPICKER_CHECKER = new ResourceLocation("wecui", "textures/gui/checker.png"); - public static final ResourceLocation COLOURPICKER_PICKER = new ResourceLocation("wecui", "textures/gui/picker.png"); - + public static final ResourceLocation COLOURPICKER_PICKER = new ResourceLocation("wecui", "textures/gui/picker.png"); + /** * Indices into the hsb array */ @@ -78,12 +78,13 @@ public GuiColourPicker(Minecraft minecraft, int controlId, int xPos, int yPos, i Color colour = new Color(initialColour); this.hsb = Color.RGBtoHSB(colour.getRed(), colour.getGreen(), colour.getBlue(), null); this.opacity = initialColour & 0xFF000000; - if (this.opacity == 0x01000000) this.opacity = 0; + if (this.opacity == 0x01000000) + this.opacity = 0; this.fontRenderer = minecraft.fontRenderer; - this.txtRed = new GuiTextField(this.fontRenderer, this.field_146128_h + 188, this.field_146129_i + 10, 32, 16); + this.txtRed = new GuiTextField(this.fontRenderer, this.field_146128_h + 188, this.field_146129_i + 10, 32, 16); this.txtGreen = new GuiTextField(this.fontRenderer, this.field_146128_h + 188, this.field_146129_i + 30, 32, 16); - this.txtBlue = new GuiTextField(this.fontRenderer, this.field_146128_h + 188, this.field_146129_i + 50, 32, 16); + this.txtBlue = new GuiTextField(this.fontRenderer, this.field_146128_h + 188, this.field_146129_i + 50, 32, 16); this.txtAlpha = new GuiTextField(this.fontRenderer, this.field_146128_h + 188, this.field_146129_i + 70, 32, 16); this.txtRed.func_146203_f(3); @@ -91,13 +92,13 @@ public GuiColourPicker(Minecraft minecraft, int controlId, int xPos, int yPos, i this.txtBlue.func_146203_f(3); this.txtAlpha.func_146203_f(3); - this.rectHSArea = new Rectangle(this.field_146128_h + 10, this.field_146129_i + 10, 128, 128); - this.rectBArea = new Rectangle(this.field_146128_h + 143, this.field_146129_i + 10, 15, 128); - this.rectAArea = new Rectangle(this.field_146128_h + 163, this.field_146129_i + 10, 15, 128); + this.rectHSArea = new Rectangle(this.field_146128_h + 10, this.field_146129_i + 10, 128, 128); + this.rectBArea = new Rectangle(this.field_146128_h + 143, this.field_146129_i + 10, 15, 128); + this.rectAArea = new Rectangle(this.field_146128_h + 163, this.field_146129_i + 10, 15, 128); this.btnOk = new GuiControl(minecraft, 0, this.field_146128_h + 9, this.field_146129_i + 145, 55, 20, I18n.format("gui.ok")); this.btnCancel = new GuiControl(minecraft, 1, this.field_146128_h + 70, this.field_146129_i + 145, 65, 20, I18n.format("gui.cancel")); - + this.updateColour(); } @@ -112,27 +113,27 @@ public int getColour() int rgb = opacity | (0xFFFFFF & Color.HSBtoRGB(this.hsb[H], this.hsb[S], this.hsb[B])); return rgb; } - + @Override protected void drawControl(Minecraft minecraft, int mouseX, int mouseY) { this.mouseDragged(minecraft, mouseX, mouseY); - + // Calculate coordinates for the selectors int hPos = this.field_146128_h + 10 + (int)(128F * this.hsb[H]); int sPos = this.field_146129_i + 10 + (128 - (int)(128F * this.hsb[S])); int bPos = this.field_146129_i + 10 + (128 - (int)(128F * this.hsb[B])); - int aPos = this.field_146129_i + 10 + ((256 - ((this.opacity >> 24) & 0xFF)) / 2) ; + int aPos = this.field_146129_i + 10 + ((256 - ((this.opacity >> 24) & 0xFF)) / 2); // Calculate B colour int brightness = Color.HSBtoRGB(this.hsb[H], this.hsb[S], 1.0F) | 0xFF000000; // Draw backgrounds - drawRect(this.field_146128_h, this.field_146129_i, this.field_146128_h + this.field_146120_f, this.field_146129_i + this.field_146121_g, 0xAA000000); // Background - drawRect(this.field_146128_h + 9, this.field_146129_i + 9, this.field_146128_h + 139, this.field_146129_i + 139, 0xFFA0A0A0); // HS background - drawRect(this.field_146128_h + 142, this.field_146129_i + 9, this.field_146128_h + 159, this.field_146129_i + 139, 0xFFA0A0A0); // B background - drawRect(this.field_146128_h + 162, this.field_146129_i + 9, this.field_146128_h + 179, this.field_146129_i + 139, 0xFFA0A0A0); // A background - drawRect(this.field_146128_h + 187, this.field_146129_i + 105, this.field_146128_h + 221, this.field_146129_i + 139, 0xFFA0A0A0); // Preview background + drawRect(this.field_146128_h, this.field_146129_i, this.field_146128_h + this.field_146120_f, this.field_146129_i + this.field_146121_g, 0xAA000000); // Background + drawRect(this.field_146128_h + 9, this.field_146129_i + 9, this.field_146128_h + 139, this.field_146129_i + 139, 0xFFA0A0A0); // HS background + drawRect(this.field_146128_h + 142, this.field_146129_i + 9, this.field_146128_h + 159, this.field_146129_i + 139, 0xFFA0A0A0); // B background + drawRect(this.field_146128_h + 162, this.field_146129_i + 9, this.field_146128_h + 179, this.field_146129_i + 139, 0xFFA0A0A0); // A background + drawRect(this.field_146128_h + 187, this.field_146129_i + 105, this.field_146128_h + 221, this.field_146129_i + 139, 0xFFA0A0A0); // Preview background // Draw colour picker this.mc.getTextureManager().bindTexture(GuiColourPicker.COLOURPICKER_PICKER); @@ -144,7 +145,7 @@ protected void drawControl(Minecraft minecraft, int mouseX, int mouseY) this.drawGradientRect(this.field_146128_h + 143, this.field_146129_i + 10, this.field_146128_h + 158, this.field_146129_i + 138, brightness, 0xFF000000); this.drawRotText(this.fontRenderer, "Luminosity", this.field_146128_h + 150, this.field_146129_i + 74, 0xFF000000, false); drawRect(this.field_146128_h + 142, bPos - 1, this.field_146128_h + 159, bPos + 1, 0xFFFFFFFF); - + // Draw opacity bar this.drawGradientRect(this.field_146128_h + 163, this.field_146129_i + 10, this.field_146128_h + 178, this.field_146129_i + 138, 0xFFFFFFFF, 0xFF000000); this.drawRotText(this.fontRenderer, "Opacity", this.field_146128_h + 170, this.field_146129_i + 74, 0xFF000000, false); @@ -155,7 +156,7 @@ protected void drawControl(Minecraft minecraft, int mouseX, int mouseY) glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.drawTexturedModalRect(this.field_146128_h + 188, this.field_146129_i + 106, this.field_146128_h + 220, this.field_146129_i + 138, 0, 0, 1024, 1024); drawRect(this.field_146128_h + 188, this.field_146129_i + 106, this.field_146128_h + 220, this.field_146129_i + 138, this.rgb); - + // Draw text boxes this.txtRed.drawTextBox(); this.txtGreen.drawTextBox(); @@ -190,9 +191,9 @@ protected void updateColourFromTextEntry() int currentBlue = this.rgb & 0xFF; int currentOpacity = (this.opacity >> 24) & 0xFF; - currentRed = (int)clamp(this.tryParseInt(this.txtRed.getText(), currentRed), 0, 255); - currentGreen = (int)clamp(this.tryParseInt(this.txtGreen.getText(), currentGreen), 0, 255); - currentBlue = (int)clamp(this.tryParseInt(this.txtBlue.getText(), currentBlue), 0, 255); + currentRed = (int)clamp(this.tryParseInt(this.txtRed.getText(), currentRed), 0, 255); + currentGreen = (int)clamp(this.tryParseInt(this.txtGreen.getText(), currentGreen), 0, 255); + currentBlue = (int)clamp(this.tryParseInt(this.txtBlue.getText(), currentBlue), 0, 255); currentOpacity = (int)clamp(this.tryParseInt(this.txtAlpha.getText(), currentOpacity), 0, 255); this.hsb = Color.RGBtoHSB(currentRed, currentGreen, currentBlue, null); @@ -206,7 +207,10 @@ protected int tryParseInt(String text, int defaultValue) { return Integer.parseInt(text); } - catch (Exception ex) { return "".equals(text) ? 0 : defaultValue; } + catch (Exception ex) + { + return "".equals(text) ? 0 : defaultValue; + } } /* (non-Javadoc) @@ -236,7 +240,7 @@ protected void mouseDragged(Minecraft minecraft, int mouseX, int mouseY) this.updateColour(); } } - + /* (non-Javadoc) * @see net.minecraft.src.GuiButton#mousePressed(net.minecraft.src.Minecraft, int, int) */ @@ -254,7 +258,7 @@ public boolean mousePressed(Minecraft minecraft, int mouseX, int mouseY) if (this.rectHSArea.contains(mouseX, mouseY)) this.draggingHS = true; - + if (this.rectBArea.contains(mouseX, mouseY)) this.draggingB = true; @@ -275,7 +279,7 @@ else if (this.enabled) return false; } - + /* (non-Javadoc) * @see net.minecraft.src.GuiButton#mouseReleased(int, int) */ @@ -329,7 +333,7 @@ else if (this.txtBlue.isFocused()) return true; } - + public static float clamp(float value, float min, float max) { return Math.min(Math.max(value, min), max); diff --git a/src/main/java/wecui/gui/GuiControl.java b/src/main/java/wecui/gui/GuiControl.java index 319b5113..56dd5f7d 100644 --- a/src/main/java/wecui/gui/GuiControl.java +++ b/src/main/java/wecui/gui/GuiControl.java @@ -58,7 +58,7 @@ public enum DialogResult No } - + /** * Set by parent screen to enable cursor flash etc */ @@ -78,481 +78,482 @@ public enum DialogResult * Flag tracking whether an item was double-clicked */ protected boolean doubleClicked; - + /** * Scale factor which translates texture pixel coordinates to relative coordinates */ - protected static float texMapScale = 0.00390625F; - + protected static float texMapScale = 0.00390625F; + protected static float guiScaleFactor; - + protected static int lastScreenWidth; protected static int lastScreenHeight; - /** - * Override from GuiButton, handle this call and forward it to DrawControl for neatness - * - * @param minecraft Reference to the minecraft game instance - * @param mouseX Mouse X coordinate - * @param mouseY Mouse Y coordinate - */ - @Override + /** + * Override from GuiButton, handle this call and forward it to DrawControl for neatness + * + * @param minecraft Reference to the minecraft game instance + * @param mouseX Mouse X coordinate + * @param mouseY Mouse Y coordinate + */ + @Override public final void drawButton(Minecraft minecraft, int mouseX, int mouseY) - { - this.drawControl(minecraft, mouseX, mouseY); - } - - /** - * Draw the control - * - * @param minecraft Reference to the minecraft game instance - * @param mouseX Mouse X coordinate - * @param mouseY Mouse Y coordinate - */ - protected void drawControl(Minecraft minecraft, int mouseX, int mouseY) - { - super.drawButton(minecraft, mouseX, mouseY); - } - - /** - * Constructor, passes through to GuiButton constructor - * - * @param minecraft Minecraft game instance - * @param controlId Control's ID (used for actionPerformed) - * @param xPos Control X position (left) - * @param yPos Control Y position (top) - * @param controlWidth Control width - * @param controlHeight Control height - * @param displayText Control display text - */ - public GuiControl(Minecraft minecraft, int controlId, int xPos, int yPos, int controlWidth, int controlHeight, String displayText) - { - super(controlId, xPos, yPos, controlWidth, controlHeight, displayText); - this.mc = minecraft; - } - + { + this.drawControl(minecraft, mouseX, mouseY); + } + + /** + * Draw the control + * + * @param minecraft Reference to the minecraft game instance + * @param mouseX Mouse X coordinate + * @param mouseY Mouse Y coordinate + */ + protected void drawControl(Minecraft minecraft, int mouseX, int mouseY) + { + super.drawButton(minecraft, mouseX, mouseY); + } + + /** + * Constructor, passes through to GuiButton constructor + * + * @param minecraft Minecraft game instance + * @param controlId Control's ID (used for actionPerformed) + * @param xPos Control X position (left) + * @param yPos Control Y position (top) + * @param controlWidth Control width + * @param controlHeight Control height + * @param displayText Control display text + */ + public GuiControl(Minecraft minecraft, int controlId, int xPos, int yPos, int controlWidth, int controlHeight, String displayText) + { + super(controlId, xPos, yPos, controlWidth, controlHeight, displayText); + this.mc = minecraft; + } + public GuiControl(Minecraft minecraft, int controlId, int xPos, int yPos, String displayText) { super(controlId, xPos, yPos, displayText); - this.mc = minecraft; + this.mc = minecraft; } - + /** - * GuiControlEx returns true from mousePressed if the mouse was captured, NOT if an action was performed. Containers - * should call this function afterwards to determine whether an action was performed. - * - * @return True if actionPerformed should be dispatched - */ - public boolean isActionPerformed() - { - return this.actionPerformed; - } - - /** - * Get whether an actionPerformed was a double-click event - * - * @return - */ - public boolean isDoubleClicked(boolean resetDoubleClicked) - { - boolean result = this.doubleClicked; - if (resetDoubleClicked) this.doubleClicked = false; - return result; - } - - /** - * Draws a line between two points with the specified width and colour - * - * @param x1 Origin x coordinate - * @param y1 Origin y coordinate - * @param x2 End x coordinate - * @param y2 End y coordinate - * @param width Line width in pixels - * @param colour Line colour - */ - public static void drawLine(int x1, int y1, int x2, int y2, int width, int colour) - { - drawArrow(x1, y1, x2, y2, 0, width, colour, false, 0); - } - - /** - * Draws an OpenGL line - * - * @param x1 Start x position - * @param y1 Start y position - * @param x2 End x position - * @param y2 End y position - * @param width Line width - * @param colour Line colour - */ - @SuppressWarnings("cast") + * GuiControlEx returns true from mousePressed if the mouse was captured, NOT if an action was performed. Containers + * should call this function afterwards to determine whether an action was performed. + * + * @return True if actionPerformed should be dispatched + */ + public boolean isActionPerformed() + { + return this.actionPerformed; + } + + /** + * Get whether an actionPerformed was a double-click event + * + * @return + */ + public boolean isDoubleClicked(boolean resetDoubleClicked) + { + boolean result = this.doubleClicked; + if (resetDoubleClicked) + this.doubleClicked = false; + return result; + } + + /** + * Draws a line between two points with the specified width and colour + * + * @param x1 Origin x coordinate + * @param y1 Origin y coordinate + * @param x2 End x coordinate + * @param y2 End y coordinate + * @param width Line width in pixels + * @param colour Line colour + */ + public static void drawLine(int x1, int y1, int x2, int y2, int width, int colour) + { + drawArrow(x1, y1, x2, y2, 0, width, colour, false, 0); + } + + /** + * Draws an OpenGL line + * + * @param x1 Start x position + * @param y1 Start y position + * @param x2 End x position + * @param y2 End y position + * @param width Line width + * @param colour Line colour + */ + @SuppressWarnings("cast") public static void drawNativeLine(float x1, float y1, float x2, float y2, float width, int colour) { - float f = (float)(colour >> 24 & 0xff) / 255F; - float f1 = (float)(colour >> 16 & 0xff) / 255F; - float f2 = (float)(colour >> 8 & 0xff) / 255F; - float f3 = (float)(colour & 0xff) / 255F; - - glEnable(GL_BLEND); - glDisable(GL_TEXTURE_2D); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor4f(f1, f2, f3, f); - glLineWidth(width); - - Tessellator tessellator = Tessellator.instance; - tessellator.startDrawing(GL_LINES); - tessellator.addVertex(x1, y1, 0); - tessellator.addVertex(x2, y2, 0); - tessellator.draw(); - - glEnable(GL_TEXTURE_2D); - glDisable(GL_BLEND); + float f = (float)(colour >> 24 & 0xff) / 255F; + float f1 = (float)(colour >> 16 & 0xff) / 255F; + float f2 = (float)(colour >> 8 & 0xff) / 255F; + float f3 = (float)(colour & 0xff) / 255F; + + glEnable(GL_BLEND); + glDisable(GL_TEXTURE_2D); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4f(f1, f2, f3, f); + glLineWidth(width); + + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawing(GL_LINES); + tessellator.addVertex(x1, y1, 0); + tessellator.addVertex(x2, y2, 0); + tessellator.draw(); + + glEnable(GL_TEXTURE_2D); + glDisable(GL_BLEND); } - - /** - * Draws an arrow between two points with the specified width and colour - * - * @param x1 Origin x coordinate - * @param y1 Origin y coordinate - * @param x2 End x coordinate - * @param y2 End y coordinate - * @param width Line width in pixels - * @param arrowHeadSize Size of the arrow head - * @param colour Colour - */ + + /** + * Draws an arrow between two points with the specified width and colour + * + * @param x1 Origin x coordinate + * @param y1 Origin y coordinate + * @param x2 End x coordinate + * @param y2 End y coordinate + * @param width Line width in pixels + * @param arrowHeadSize Size of the arrow head + * @param colour Colour + */ public static void drawArrow(int x1, int y1, int x2, int y2, int z, int width, int arrowHeadSize, int colour) - { - drawArrow(x1, y1, x2, y2, z, width, colour, true, arrowHeadSize); - } - - /** - * Internal function for drawing lines and arrows - * - * @param x1 Origin x coordinate - * @param y1 Origin y coordinate - * @param x2 End x coordinate - * @param y2 End y coordinate - * @param width Line width in pixels - * @param colour Colour - * @param arrowHead True to draw an arrow, otherwise draws a line - * @param arrowHeadSize Size of the arrow head - */ - @SuppressWarnings("cast") + { + drawArrow(x1, y1, x2, y2, z, width, colour, true, arrowHeadSize); + } + + /** + * Internal function for drawing lines and arrows + * + * @param x1 Origin x coordinate + * @param y1 Origin y coordinate + * @param x2 End x coordinate + * @param y2 End y coordinate + * @param width Line width in pixels + * @param colour Colour + * @param arrowHead True to draw an arrow, otherwise draws a line + * @param arrowHeadSize Size of the arrow head + */ + @SuppressWarnings("cast") public static void drawArrow(int x1, int y1, int x2, int y2, int z, int width, int colour, boolean arrowHead, int arrowHeadSize) - { - // Calculate the line length and angle defined by the specified points - int length = (int)Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2)); - float angle = (float)Math.toDegrees(Math.atan2(y2 - y1, x2 - x1)); - - // Local rotation - glPushMatrix(); - glTranslatef(x1, y1, 0.0f); - glRotatef(angle, 0.0f, 0.0f, 1.0f); - - // Calc coordinates for the line and arrow points - x1 = 0; - x2 = length - (arrowHead ? arrowHeadSize : 0); - y1 = (int)(width * -0.5); - y2 = y1 + width; - - // Calc colour components - float f = (float)(colour >> 24 & 0xff) / 255F; - float f1 = (float)(colour >> 16 & 0xff) / 255F; - float f2 = (float)(colour >> 8 & 0xff) / 255F; - float f3 = (float)(colour & 0xff) / 255F; - - glEnable(GL_BLEND); - glDisable(GL_TEXTURE_2D); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor4f(f1, f2, f3, f); - - // Draw the line - Tessellator tessellator = Tessellator.instance; - tessellator.startDrawingQuads(); - tessellator.addVertex(x1, y2, z); - tessellator.addVertex(x2, y2, z); - tessellator.addVertex(x2, y1, z); - tessellator.addVertex(x1, y1, z); - tessellator.draw(); - - // If an arrow then draw the arrow head - if (arrowHead && arrowHeadSize > 0) - { - tessellator.startDrawing(4); - tessellator.addVertex(x2, 0 - arrowHeadSize / 2, z); - tessellator.addVertex(x2, arrowHeadSize / 2, z); - tessellator.addVertex(length, 0, z); - tessellator.draw(); - } - - glEnable(GL_TEXTURE_2D); - glDisable(GL_BLEND); - - glPopMatrix(); - } - - /** - * Set the texmap scale factor - * - * @param textureSize - */ - @SuppressWarnings("cast") + { + // Calculate the line length and angle defined by the specified points + int length = (int)Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2)); + float angle = (float)Math.toDegrees(Math.atan2(y2 - y1, x2 - x1)); + + // Local rotation + glPushMatrix(); + glTranslatef(x1, y1, 0.0f); + glRotatef(angle, 0.0f, 0.0f, 1.0f); + + // Calc coordinates for the line and arrow points + x1 = 0; + x2 = length - (arrowHead ? arrowHeadSize : 0); + y1 = (int)(width * -0.5); + y2 = y1 + width; + + // Calc colour components + float f = (float)(colour >> 24 & 0xff) / 255F; + float f1 = (float)(colour >> 16 & 0xff) / 255F; + float f2 = (float)(colour >> 8 & 0xff) / 255F; + float f3 = (float)(colour & 0xff) / 255F; + + glEnable(GL_BLEND); + glDisable(GL_TEXTURE_2D); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4f(f1, f2, f3, f); + + // Draw the line + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.addVertex(x1, y2, z); + tessellator.addVertex(x2, y2, z); + tessellator.addVertex(x2, y1, z); + tessellator.addVertex(x1, y1, z); + tessellator.draw(); + + // If an arrow then draw the arrow head + if (arrowHead && arrowHeadSize > 0) + { + tessellator.startDrawing(4); + tessellator.addVertex(x2, 0 - arrowHeadSize / 2, z); + tessellator.addVertex(x2, arrowHeadSize / 2, z); + tessellator.addVertex(length, 0, z); + tessellator.draw(); + } + + glEnable(GL_TEXTURE_2D); + glDisable(GL_BLEND); + + glPopMatrix(); + } + + /** + * Set the texmap scale factor + * + * @param textureSize + */ + @SuppressWarnings("cast") public void setTexMapSize(int textureSize) - { - texMapScale = 1F / (float)textureSize; - } - - /** - * Draws a textured rectangle at 90 degrees - * - * @param x Left edge X coordinate - * @param y Top edge Y coordinate - * @param x2 Right edge X coordinate - * @param y2 Bottom edge Y coordinate - * @param u U coordinate - * @param v V coordinate - * @param u2 Right edge U coordinate - * @param v2 Bottom edge V coordinate - */ - @SuppressWarnings("cast") + { + texMapScale = 1F / (float)textureSize; + } + + /** + * Draws a textured rectangle at 90 degrees + * + * @param x Left edge X coordinate + * @param y Top edge Y coordinate + * @param x2 Right edge X coordinate + * @param y2 Bottom edge Y coordinate + * @param u U coordinate + * @param v V coordinate + * @param u2 Right edge U coordinate + * @param v2 Bottom edge V coordinate + */ + @SuppressWarnings("cast") public void drawTexturedModalRectRot(int x, int y, int x2, int y2, int u, int v, int u2, int v2) - { - Tessellator tessellator = Tessellator.instance; - tessellator.startDrawingQuads(); - tessellator.addVertexWithUV(x2, y2, this.zLevel, (float)(u) * texMapScale, (float)(v2) * texMapScale); - tessellator.addVertexWithUV(x2, y, this.zLevel, (float)(u2) * texMapScale, (float)(v2) * texMapScale); - tessellator.addVertexWithUV(x, y, this.zLevel, (float)(u2) * texMapScale, (float)(v) * texMapScale); - tessellator.addVertexWithUV(x, y2, this.zLevel, (float)(u) * texMapScale, (float)(v) * texMapScale); - tessellator.draw(); - } - - /** - * Draws a textured rectangle at 90 degrees - * - * @param x Left edge X coordinate - * @param y Top edge Y coordinate - * @param u U coordinate - * @param v V coordinate - * @param width Width of texture to draw - * @param height Height of texture to draw - */ - @SuppressWarnings("cast") + { + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.addVertexWithUV(x2, y2, this.zLevel, (float)(u) * texMapScale, (float)(v2) * texMapScale); + tessellator.addVertexWithUV(x2, y, this.zLevel, (float)(u2) * texMapScale, (float)(v2) * texMapScale); + tessellator.addVertexWithUV(x, y, this.zLevel, (float)(u2) * texMapScale, (float)(v) * texMapScale); + tessellator.addVertexWithUV(x, y2, this.zLevel, (float)(u) * texMapScale, (float)(v) * texMapScale); + tessellator.draw(); + } + + /** + * Draws a textured rectangle at 90 degrees + * + * @param x Left edge X coordinate + * @param y Top edge Y coordinate + * @param u U coordinate + * @param v V coordinate + * @param width Width of texture to draw + * @param height Height of texture to draw + */ + @SuppressWarnings("cast") public void drawTexturedModalRectRot(int x, int y, int u, int v, int width, int height) - { - Tessellator tessellator = Tessellator.instance; - tessellator.startDrawingQuads(); - tessellator.addVertexWithUV(x + height, y + width, this.zLevel, (float)(u) * texMapScale, (float)(v + height) * texMapScale); - tessellator.addVertexWithUV(x + height, y, this.zLevel, (float)(u + width) * texMapScale, (float)(v + height) * texMapScale); - tessellator.addVertexWithUV(x, y, this.zLevel, (float)(u + width) * texMapScale, (float)(v) * texMapScale); - tessellator.addVertexWithUV(x, y + width, this.zLevel, (float)(u) * texMapScale, (float)(v) * texMapScale); - tessellator.draw(); - } - - /** - * Draws a tesselated rectangle where the texture is stretched horizontally but vertical scaling - * is achieved by splitting the texture in half and repeating the middle pixels - * - * @param x Left edge X coordinate - * @param y Top edge Y coordinate - * @param x2 Right edge X coordinate - * @param y2 Bottom edge Y coordinate - * @param u U coordinate - * @param v V coordinate - * @param u2 Right edge U coordinate - * @param v2 Bottom edge V coordinate - */ - public void drawTessellatedModalRectV(int x, int y, int x2, int y2, int u, int v, int u2, int v2) - { - int tileSize = ((v2 - v) / 2); - int vMidTop = v + tileSize; - int vMidBtm = vMidTop + 1; - - this.drawTexturedModalRect(x, y, x2, y + tileSize, u, v, u2, vMidTop); - this.drawTexturedModalRect(x, y + tileSize, x2, y2 - tileSize + 1, u, vMidTop, u2, vMidBtm); - this.drawTexturedModalRect(x, y2 - tileSize + 1, x2, y2, u, vMidBtm, u2, v2); - } - - /** - * Draws a tesselated rectangle where the texture is stretched vertically but horizontal scaling - * is achieved by splitting the texture in half and repeating the middle pixels - * - * @param x Left edge X coordinate - * @param y Top edge Y coordinate - * @param x2 Right edge X coordinate - * @param y2 Bottom edge Y coordinate - * @param u U coordinate - * @param v V coordinate - * @param u2 Right edge U coordinate - * @param v2 Bottom edge V coordinate - */ - public void drawTessellatedModalRectH(int x, int y, int x2, int y2, int u, int v, int u2, int v2) - { - int tileSize = ((u2 - u) / 2); - int uMidLeft = u + tileSize; - int uMidRight = uMidLeft + 1; - - this.drawTexturedModalRect(x, y, x + tileSize, y2, u, v, uMidLeft, v2); - this.drawTexturedModalRect(x + tileSize, y, x2 - tileSize + 1, y2, uMidLeft, v, uMidRight, v2); - this.drawTexturedModalRect(x2 - tileSize + 1, y, x2, y2, uMidRight, v, u2, v2); - } - - /** - * Draws a tesselated rectangle where the texture is stretched vertically and horizontally but the middle - * pixels are repeated whilst the joining pixels are stretched. - * - * @param x Left edge X coordinate - * @param y Top edge Y coordinate - * @param x2 Right edge X coordinate - * @param y2 Bottom edge Y coordinate - * @param u U coordinate - * @param v V coordinate - * @param u2 Right edge U coordinate - * @param v2 Bottom edge V coordinate - */ - public void drawTessellatedModalBorderRect(int x, int y, int x2, int y2, int u, int v, int u2, int v2) - { - this.drawTessellatedModalBorderRect(x, y, x2, y2, u, v, u2, v2, Math.min(((x2 - x) / 2) - 1, ((y2 - y) / 2) - 1)); - } - - /** - * Draws a tesselated rectangle where the texture is stretched vertically and horizontally but the middle - * pixels are repeated whilst the joining pixels are stretched. Bordersize specifies the portion of the texture which - * will remain unstretched. - * - * @param x Left edge X coordinate - * @param y Top edge Y coordinate - * @param x2 Right edge X coordinate - * @param y2 Bottom edge Y coordinate - * @param u U coordinate - * @param v V coordinate - * @param u2 Right edge U coordinate - * @param v2 Bottom edge V coordinate - * @param borderSize Number of pixels to leave unstretched, must be less than half of the width or height (whichever is smallest) - */ - public void drawTessellatedModalBorderRect(int x, int y, int x2, int y2, int u, int v, int u2, int v2, int borderSize) - { - int tileSize = Math.min(((u2 - u) / 2) - 1, ((v2 - v) / 2) - 1); - - int ul = u + tileSize, ur = u2 - tileSize, vt = v + tileSize, vb = v2 - tileSize; - int xl = x + borderSize, xr = x2 - borderSize, yt = y + borderSize, yb = y2 - borderSize; - - this.drawTexturedModalRect(x, y, xl, yt, u, v, ul, vt); - this.drawTexturedModalRect(xl, y, xr, yt, ul, v, ur, vt); - this.drawTexturedModalRect(xr, y, x2, yt, ur, v, u2, vt); - this.drawTexturedModalRect(x, yb, xl, y2, u, vb, ul, v2); - this.drawTexturedModalRect(xl, yb, xr, y2, ul, vb, ur, v2); - this.drawTexturedModalRect(xr, yb, x2, y2, ur, vb, u2, v2); - this.drawTexturedModalRect(x, yt, xl, yb, u, vt, ul, vb); - this.drawTexturedModalRect(xr, yt, x2, yb, ur, vt, u2, vb); - this.drawTexturedModalRect(xl, yt, xr, yb, ul, vt, ur, vb); - } - - /** - * Draw a string but cut it off if it's too long to fit in the specified width - * - * @param fontrenderer - * @param s - * @param x - * @param y - * @param width - * @param colour - */ - public static void drawStringWithEllipsis(FontRenderer fontrenderer, String s, int x, int y, int width, int colour) - { - if (fontrenderer.getStringWidth(s) <= width) - { - fontrenderer.drawStringWithShadow(s, x, y, colour); - } - else if (width < 8) - { - fontrenderer.drawStringWithShadow("..", x, y, colour); - } - else - { - String trimmedText = s; - - while (fontrenderer.getStringWidth(trimmedText) > width - 8 && trimmedText.length() > 0) - trimmedText = trimmedText.substring(0, trimmedText.length() - 1); - - fontrenderer.drawStringWithShadow(trimmedText + "...", x, y, colour); - } - } - + { + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.addVertexWithUV(x + height, y + width, this.zLevel, (float)(u) * texMapScale, (float)(v + height) * texMapScale); + tessellator.addVertexWithUV(x + height, y, this.zLevel, (float)(u + width) * texMapScale, (float)(v + height) * texMapScale); + tessellator.addVertexWithUV(x, y, this.zLevel, (float)(u + width) * texMapScale, (float)(v) * texMapScale); + tessellator.addVertexWithUV(x, y + width, this.zLevel, (float)(u) * texMapScale, (float)(v) * texMapScale); + tessellator.draw(); + } + + /** + * Draws a tesselated rectangle where the texture is stretched horizontally but vertical scaling + * is achieved by splitting the texture in half and repeating the middle pixels + * + * @param x Left edge X coordinate + * @param y Top edge Y coordinate + * @param x2 Right edge X coordinate + * @param y2 Bottom edge Y coordinate + * @param u U coordinate + * @param v V coordinate + * @param u2 Right edge U coordinate + * @param v2 Bottom edge V coordinate + */ + public void drawTessellatedModalRectV(int x, int y, int x2, int y2, int u, int v, int u2, int v2) + { + int tileSize = ((v2 - v) / 2); + int vMidTop = v + tileSize; + int vMidBtm = vMidTop + 1; + + this.drawTexturedModalRect(x, y, x2, y + tileSize, u, v, u2, vMidTop); + this.drawTexturedModalRect(x, y + tileSize, x2, y2 - tileSize + 1, u, vMidTop, u2, vMidBtm); + this.drawTexturedModalRect(x, y2 - tileSize + 1, x2, y2, u, vMidBtm, u2, v2); + } + + /** + * Draws a tesselated rectangle where the texture is stretched vertically but horizontal scaling + * is achieved by splitting the texture in half and repeating the middle pixels + * + * @param x Left edge X coordinate + * @param y Top edge Y coordinate + * @param x2 Right edge X coordinate + * @param y2 Bottom edge Y coordinate + * @param u U coordinate + * @param v V coordinate + * @param u2 Right edge U coordinate + * @param v2 Bottom edge V coordinate + */ + public void drawTessellatedModalRectH(int x, int y, int x2, int y2, int u, int v, int u2, int v2) + { + int tileSize = ((u2 - u) / 2); + int uMidLeft = u + tileSize; + int uMidRight = uMidLeft + 1; + + this.drawTexturedModalRect(x, y, x + tileSize, y2, u, v, uMidLeft, v2); + this.drawTexturedModalRect(x + tileSize, y, x2 - tileSize + 1, y2, uMidLeft, v, uMidRight, v2); + this.drawTexturedModalRect(x2 - tileSize + 1, y, x2, y2, uMidRight, v, u2, v2); + } + + /** + * Draws a tesselated rectangle where the texture is stretched vertically and horizontally but the middle + * pixels are repeated whilst the joining pixels are stretched. + * + * @param x Left edge X coordinate + * @param y Top edge Y coordinate + * @param x2 Right edge X coordinate + * @param y2 Bottom edge Y coordinate + * @param u U coordinate + * @param v V coordinate + * @param u2 Right edge U coordinate + * @param v2 Bottom edge V coordinate + */ + public void drawTessellatedModalBorderRect(int x, int y, int x2, int y2, int u, int v, int u2, int v2) + { + this.drawTessellatedModalBorderRect(x, y, x2, y2, u, v, u2, v2, Math.min(((x2 - x) / 2) - 1, ((y2 - y) / 2) - 1)); + } + + /** + * Draws a tesselated rectangle where the texture is stretched vertically and horizontally but the middle + * pixels are repeated whilst the joining pixels are stretched. Bordersize specifies the portion of the texture which + * will remain unstretched. + * + * @param x Left edge X coordinate + * @param y Top edge Y coordinate + * @param x2 Right edge X coordinate + * @param y2 Bottom edge Y coordinate + * @param u U coordinate + * @param v V coordinate + * @param u2 Right edge U coordinate + * @param v2 Bottom edge V coordinate + * @param borderSize Number of pixels to leave unstretched, must be less than half of the width or height (whichever is smallest) + */ + public void drawTessellatedModalBorderRect(int x, int y, int x2, int y2, int u, int v, int u2, int v2, int borderSize) + { + int tileSize = Math.min(((u2 - u) / 2) - 1, ((v2 - v) / 2) - 1); + + int ul = u + tileSize, ur = u2 - tileSize, vt = v + tileSize, vb = v2 - tileSize; + int xl = x + borderSize, xr = x2 - borderSize, yt = y + borderSize, yb = y2 - borderSize; + + this.drawTexturedModalRect(x, y, xl, yt, u, v, ul, vt); + this.drawTexturedModalRect(xl, y, xr, yt, ul, v, ur, vt); + this.drawTexturedModalRect(xr, y, x2, yt, ur, v, u2, vt); + this.drawTexturedModalRect(x, yb, xl, y2, u, vb, ul, v2); + this.drawTexturedModalRect(xl, yb, xr, y2, ul, vb, ur, v2); + this.drawTexturedModalRect(xr, yb, x2, y2, ur, vb, u2, v2); + this.drawTexturedModalRect(x, yt, xl, yb, u, vt, ul, vb); + this.drawTexturedModalRect(xr, yt, x2, yb, ur, vt, u2, vb); + this.drawTexturedModalRect(xl, yt, xr, yb, ul, vt, ur, vb); + } + + /** + * Draw a string but cut it off if it's too long to fit in the specified width + * + * @param fontrenderer + * @param s + * @param x + * @param y + * @param width + * @param colour + */ + public static void drawStringWithEllipsis(FontRenderer fontrenderer, String s, int x, int y, int width, int colour) + { + if (fontrenderer.getStringWidth(s) <= width) + { + fontrenderer.drawStringWithShadow(s, x, y, colour); + } + else if (width < 8) + { + fontrenderer.drawStringWithShadow("..", x, y, colour); + } + else + { + String trimmedText = s; + + while (fontrenderer.getStringWidth(trimmedText) > width - 8 && trimmedText.length() > 0) + trimmedText = trimmedText.substring(0, trimmedText.length() - 1); + + fontrenderer.drawStringWithShadow(trimmedText + "...", x, y, colour); + } + } + /** * @param boundingBox */ @SuppressWarnings("cast") protected void drawCrossHair(int x, int y, int size, int width, int colour) { - float alpha = (float)(colour >> 24 & 0xff) / 255F; - float red = (float)(colour >> 16 & 0xff) / 255F; - float green = (float)(colour >> 8 & 0xff) / 255F; - float blue = (float)(colour & 0xff) / 255F; - - glLineWidth(GuiControl.guiScaleFactor * width); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_BLEND); - glDisable(GL_TEXTURE_2D); - glDisable(GL_LIGHTING); - glColor4f(red, green, blue, alpha); - glEnable(GL_COLOR_LOGIC_OP); - glLogicOp(GL_OR_REVERSE); - - // Draw the frame - Tessellator tessellator = Tessellator.instance; - - tessellator.startDrawing(GL_LINES); - tessellator.addVertex(x - size, y, 0); - tessellator.addVertex(x + size, y, 0); - tessellator.draw(); - - tessellator.startDrawing(GL_LINES); - tessellator.addVertex(x, y - size, 0); - tessellator.addVertex(x, y + size, 0); - tessellator.draw(); - - glDisable(GL_COLOR_LOGIC_OP); - glEnable(GL_TEXTURE_2D); + float alpha = (float)(colour >> 24 & 0xff) / 255F; + float red = (float)(colour >> 16 & 0xff) / 255F; + float green = (float)(colour >> 8 & 0xff) / 255F; + float blue = (float)(colour & 0xff) / 255F; + + glLineWidth(GuiControl.guiScaleFactor * width); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); + glDisable(GL_TEXTURE_2D); + glDisable(GL_LIGHTING); + glColor4f(red, green, blue, alpha); + glEnable(GL_COLOR_LOGIC_OP); + glLogicOp(GL_OR_REVERSE); + + // Draw the frame + Tessellator tessellator = Tessellator.instance; + + tessellator.startDrawing(GL_LINES); + tessellator.addVertex(x - size, y, 0); + tessellator.addVertex(x + size, y, 0); + tessellator.draw(); + + tessellator.startDrawing(GL_LINES); + tessellator.addVertex(x, y - size, 0); + tessellator.addVertex(x, y + size, 0); + tessellator.draw(); + + glDisable(GL_COLOR_LOGIC_OP); + glEnable(GL_TEXTURE_2D); } protected void drawRotText(FontRenderer fontRenderer, String text, int xPosition, int yPosition, int colour, boolean colourOrOp) { - if (colourOrOp) + if (colourOrOp) { glEnable(GL_COLOR_LOGIC_OP); glLogicOp(GL_OR_REVERSE); } - + int textWidth = fontRenderer.getStringWidth(text) / 2; - - glPushMatrix(); - glTranslatef(xPosition, yPosition, 0); - glRotatef(-90, 0, 0, 1); - glTranslatef(-textWidth, -4, 0); - - fontRenderer.drawString(text, 0, 0, colour); - - glPopMatrix(); - - if (colourOrOp) + + glPushMatrix(); + glTranslatef(xPosition, yPosition, 0); + glRotatef(-90, 0, 0, 1); + glTranslatef(-textWidth, -4, 0); + + fontRenderer.drawString(text, 0, 0, colour); + + glPopMatrix(); + + if (colourOrOp) { glDisable(GL_COLOR_LOGIC_OP); glEnable(GL_TEXTURE_2D); } } - - /** - * Draw a tooltip at the specified location and clip to screenWidth and screenHeight - * - * @param fontRenderer - * @param tooltipText - * @param mouseX - * @param mouseY - * @param screenWidth - * @param screenHeight - * @param colour - * @param backgroundColour - */ + + /** + * Draw a tooltip at the specified location and clip to screenWidth and screenHeight + * + * @param fontRenderer + * @param tooltipText + * @param mouseX + * @param mouseY + * @param screenWidth + * @param screenHeight + * @param colour + * @param backgroundColour + */ protected void drawTooltip(FontRenderer fontRenderer, String tooltipText, int mouseX, int mouseY, int screenWidth, int screenHeight, int colour, int backgroundColour) { int textSize = fontRenderer.getStringWidth(tooltipText); @@ -562,81 +563,81 @@ protected void drawTooltip(FontRenderer fontRenderer, String tooltipText, int mo drawRect(mouseX, mouseY, mouseX + textSize + 6, mouseY + 16, backgroundColour); this.drawString(fontRenderer, tooltipText, mouseX + 3, mouseY + 4, colour); } - - /** - * Draws a textured rectangle with custom UV coordinates - * - * @param x Left edge X coordinate - * @param y Top edge Y coordinate - * @param x2 Right edge X coordinate - * @param y2 Bottom edge Y coordinate - * @param u U coordinate - * @param v V coordinate - * @param u2 Right edge U coordinate - * @param v2 Bottom edge V coordinate - */ - @SuppressWarnings("cast") + + /** + * Draws a textured rectangle with custom UV coordinates + * + * @param x Left edge X coordinate + * @param y Top edge Y coordinate + * @param x2 Right edge X coordinate + * @param y2 Bottom edge Y coordinate + * @param u U coordinate + * @param v V coordinate + * @param u2 Right edge U coordinate + * @param v2 Bottom edge V coordinate + */ + @SuppressWarnings("cast") public void drawTexturedModalRect(int x, int y, int x2, int y2, int u, int v, int u2, int v2) - { - Tessellator tessellator = Tessellator.instance; - tessellator.startDrawingQuads(); - tessellator.addVertexWithUV(x, y2, this.zLevel, (float)(u) * texMapScale, (float)(v2) * texMapScale); - tessellator.addVertexWithUV(x2, y2, this.zLevel, (float)(u2) * texMapScale, (float)(v2) * texMapScale); - tessellator.addVertexWithUV(x2, y, this.zLevel, (float)(u2) * texMapScale, (float)(v) * texMapScale); - tessellator.addVertexWithUV(x, y, this.zLevel, (float)(u) * texMapScale, (float)(v) * texMapScale); - tessellator.draw(); - } - - /** - * Draws a textured rectangle with custom UV coordinates - * - * @param x Left edge X coordinate - * @param y Top edge Y coordinate - * @param x2 Right edge X coordinate - * @param y2 Bottom edge Y coordinate - * @param u U coordinate - * @param v V coordinate - * @param u2 Right edge U coordinate - * @param v2 Bottom edge V coordinate - */ - public void drawTexturedModalRectF(int x, int y, int x2, int y2, float u, float v, float u2, float v2) - { - Tessellator tessellator = Tessellator.instance; - tessellator.startDrawingQuads(); - tessellator.addVertexWithUV(x, y2, this.zLevel, u , v2); - tessellator.addVertexWithUV(x2, y2, this.zLevel, u2, v2); - tessellator.addVertexWithUV(x2, y, this.zLevel, u2, v ); - tessellator.addVertexWithUV(x, y, this.zLevel, u , v ); - tessellator.draw(); - } - - /** - * Draws a textured rectangle with the specified texture map size - * - * @param x Left edge X coordinate - * @param y Top edge Y coordinate - * @param u Texture U coordinate - * @param v Texture V coordinate - * @param width Width - * @param height Height - * @param texMapScale Texture map scale for scaling UV coordinate - */ - @SuppressWarnings("cast") + { + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.addVertexWithUV(x, y2, this.zLevel, (float)(u) * texMapScale, (float)(v2) * texMapScale); + tessellator.addVertexWithUV(x2, y2, this.zLevel, (float)(u2) * texMapScale, (float)(v2) * texMapScale); + tessellator.addVertexWithUV(x2, y, this.zLevel, (float)(u2) * texMapScale, (float)(v) * texMapScale); + tessellator.addVertexWithUV(x, y, this.zLevel, (float)(u) * texMapScale, (float)(v) * texMapScale); + tessellator.draw(); + } + + /** + * Draws a textured rectangle with custom UV coordinates + * + * @param x Left edge X coordinate + * @param y Top edge Y coordinate + * @param x2 Right edge X coordinate + * @param y2 Bottom edge Y coordinate + * @param u U coordinate + * @param v V coordinate + * @param u2 Right edge U coordinate + * @param v2 Bottom edge V coordinate + */ + public void drawTexturedModalRectF(int x, int y, int x2, int y2, float u, float v, float u2, float v2) + { + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.addVertexWithUV(x, y2, this.zLevel, u, v2); + tessellator.addVertexWithUV(x2, y2, this.zLevel, u2, v2); + tessellator.addVertexWithUV(x2, y, this.zLevel, u2, v); + tessellator.addVertexWithUV(x, y, this.zLevel, u, v); + tessellator.draw(); + } + + /** + * Draws a textured rectangle with the specified texture map size + * + * @param x Left edge X coordinate + * @param y Top edge Y coordinate + * @param u Texture U coordinate + * @param v Texture V coordinate + * @param width Width + * @param height Height + * @param texMapScale Texture map scale for scaling UV coordinate + */ + @SuppressWarnings("cast") public void drawTexturedModalRect(int x, int y, int u, int v, int width, int height, float texMapScale) - { - Tessellator tessellator = Tessellator.instance; - tessellator.startDrawingQuads(); - tessellator.addVertexWithUV(x + 0, y + height, this.zLevel, (float)(u + 0) * texMapScale, (float)(v + height) * texMapScale); - tessellator.addVertexWithUV(x + width, y + height, this.zLevel, (float)(u + width) * texMapScale, (float)(v + height) * texMapScale); - tessellator.addVertexWithUV(x + width, y + 0, this.zLevel, (float)(u + width) * texMapScale, (float)(v + 0) * texMapScale); - tessellator.addVertexWithUV(x + 0, y + 0, this.zLevel, (float)(u + 0) * texMapScale, (float)(v + 0) * texMapScale); - tessellator.draw(); - } - + { + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.addVertexWithUV(x + 0, y + height, this.zLevel, (float)(u + 0) * texMapScale, (float)(v + height) * texMapScale); + tessellator.addVertexWithUV(x + width, y + height, this.zLevel, (float)(u + width) * texMapScale, (float)(v + height) * texMapScale); + tessellator.addVertexWithUV(x + width, y + 0, this.zLevel, (float)(u + width) * texMapScale, (float)(v + 0) * texMapScale); + tessellator.addVertexWithUV(x + 0, y + 0, this.zLevel, (float)(u + 0) * texMapScale, (float)(v + 0) * texMapScale); + tessellator.draw(); + } + public static void setScreenSizeAndScale(int width, int height, int scaleFactor) { GuiControl.lastScreenWidth = width; GuiControl.lastScreenHeight = height; - GuiControl.guiScaleFactor = scaleFactor; + GuiControl.guiScaleFactor = scaleFactor; } } diff --git a/src/main/java/wecui/gui/WorldEditCUIConfigPanel.java b/src/main/java/wecui/gui/WorldEditCUIConfigPanel.java index 665a8aee..dbbdb86e 100644 --- a/src/main/java/wecui/gui/WorldEditCUIConfigPanel.java +++ b/src/main/java/wecui/gui/WorldEditCUIConfigPanel.java @@ -33,25 +33,25 @@ public WorldEditCUIConfigPanel() { this.mc = Minecraft.getMinecraft(); } - + @Override public String getPanelTitle() { return I18n.format("wecui.options.title"); } - + @Override public int getContentHeight() { return LineColor.values().length * 24; } - + @Override public void onPanelShown(ConfigPanelHost host) { this.mod = host.getMod(); - ScaledResolution scaledresolution = new ScaledResolution(this.mc.gameSettings, this.mc.displayWidth, this.mc.displayHeight); + ScaledResolution scaledresolution = new ScaledResolution(this.mc.gameSettings, this.mc.displayWidth, this.mc.displayHeight); GuiControl.setScreenSizeAndScale(host.getWidth(), this.getContentHeight(), scaledresolution.getScaleFactor()); this.controlList.clear(); @@ -70,12 +70,12 @@ public void onPanelShown(ConfigPanelHost host) this.colourButtonList.add((GuiColourButton)control); } } - + @Override public void onPanelResize(ConfigPanelHost host) { } - + @Override public void onPanelHidden() { @@ -83,15 +83,15 @@ public void onPanelHidden() { colourButton.save(); } - + this.mod.getController().getConfiguration().save(); } - + @Override public void onTick(ConfigPanelHost host) { } - + @Override public void drawPanel(ConfigPanelHost host, int mouseX, int mouseY, float partialTicks) { @@ -105,7 +105,7 @@ public void drawPanel(ConfigPanelHost host, int mouseX, int mouseY, float partia colourButton.drawPicker(this.mc, mouseX, mouseY); } } - + @Override public void mousePressed(ConfigPanelHost host, int mouseX, int mouseY, int mouseButton) { @@ -124,19 +124,19 @@ public void mousePressed(ConfigPanelHost host, int mouseX, int mouseY, int mouse } } } - + private void actionPerformed(GuiControl control) { if (control.id >= 100) { LineColor lineColour = LineColor.values()[control.id - 100]; lineColour.setDefaultColour(); - + for (GuiColourButton colourButton : this.colourButtonList) colourButton.updateColour(lineColour); } } - + @Override public void mouseReleased(ConfigPanelHost host, int mouseX, int mouseY, int mouseButton) { @@ -146,12 +146,12 @@ public void mouseReleased(ConfigPanelHost host, int mouseX, int mouseY, int mous this.activeControl = null; } } - + @Override public void mouseMoved(ConfigPanelHost host, int mouseX, int mouseY) { } - + @Override public void keyPressed(ConfigPanelHost host, char keyChar, int keyCode) { @@ -166,26 +166,26 @@ public void keyPressed(ConfigPanelHost host, char keyChar, int keyCode) colourButton.keyTyped(keyChar, keyCode); } } - + /** * Enable OpenGL clipping planes (uses planes 2, 3, 4 and 5) */ protected final void enableClipping() - { - glEnable(GL_CLIP_PLANE2); + { + glEnable(GL_CLIP_PLANE2); glEnable(GL_CLIP_PLANE3); glEnable(GL_CLIP_PLANE4); glEnable(GL_CLIP_PLANE5); - } - + } + /** * Disable OpenGL clipping planes (uses planes 2, 3, 4 and 5) */ protected final void disableClipping() - { - glDisable(GL_CLIP_PLANE5); - glDisable(GL_CLIP_PLANE4); - glDisable(GL_CLIP_PLANE3); - glDisable(GL_CLIP_PLANE2); - } + { + glDisable(GL_CLIP_PLANE5); + glDisable(GL_CLIP_PLANE4); + glDisable(GL_CLIP_PLANE3); + glDisable(GL_CLIP_PLANE2); + } } diff --git a/src/main/java/wecui/plugin/CUIPlayer.java b/src/main/java/wecui/plugin/CUIPlayer.java deleted file mode 100644 index fc1c3d55..00000000 --- a/src/main/java/wecui/plugin/CUIPlayer.java +++ /dev/null @@ -1,80 +0,0 @@ -package wecui.plugin; - -public class CUIPlayer {} /*extends LocalPlayer { - - protected WorldEditCUI controller; - - public CUIPlayer(ServerInterface server, WorldEditCUI controller) { - super(server); - this.controller = controller; - } - - @Override - public int getItemInHand() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public String getName() { - return "player"; - } - - @Override - public WorldVector getPosition() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public LocalWorld getWorld() { - return controller.getLocalPlugin().getWorld(); - } - - @Override - public double getPitch() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public double getYaw() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public void giveItem(int type, int amt) { - } - - @Override - public void printRaw(String msg) { - } - - @Override - public void printDebug(String msg) { - } - - @Override - public void print(String msg) { - } - - @Override - public void printError(String msg) { - } - - @Override - public void setPosition(Vector pos, float pitch, float yaw) { - } - - @Override - public String[] getGroups() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public BlockBag getInventoryBlockBag() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public boolean hasPermission(String perm) { - return true; - } -}*/ diff --git a/src/main/java/wecui/plugin/CUIServerInterface.java b/src/main/java/wecui/plugin/CUIServerInterface.java deleted file mode 100644 index d42e7bc6..00000000 --- a/src/main/java/wecui/plugin/CUIServerInterface.java +++ /dev/null @@ -1,36 +0,0 @@ -package wecui.plugin; - -/** - * Stub class for a WorldEdit server interface - * This may need more stuff in the future, but it works for now. - * - * @author yetanotherx - */ -public class CUIServerInterface {} /*extends ServerInterface { - - protected WorldEditCUI controller; - - public CUIServerInterface(WorldEditCUI controller) { - this.controller = controller; - } - - @Override - public int resolveItem(String name) { - return 0; - } - - @Override - public boolean isValidMobType(String type) { - return true; - } - - @Override - public void reload() { - } - - @Override - public BiomeTypes getBiomes() { - throw new UnsupportedOperationException("Not supported yet."); - } -} -*/ \ No newline at end of file diff --git a/src/main/java/wecui/plugin/CUIWEConfiguration.java b/src/main/java/wecui/plugin/CUIWEConfiguration.java deleted file mode 100644 index 5a2b61dd..00000000 --- a/src/main/java/wecui/plugin/CUIWEConfiguration.java +++ /dev/null @@ -1,19 +0,0 @@ -package wecui.plugin; - -/** - * Stub class for WorldEdit configuration. This places the - * configuration file in the mods/ directory. - * - * @author yetanotherx - */ -public class CUIWEConfiguration {} /* extends PropertiesConfiguration { - - protected WorldEditCUI controller; - protected File directory; - - public CUIWEConfiguration(WorldEditCUI controller) { - super(new File(Obfuscation.getWorldEditCUIDir(), "WorldEdit-config.txt")); - this.controller = controller; - } -} -*/ \ No newline at end of file diff --git a/src/main/java/wecui/plugin/CUIWorld.java b/src/main/java/wecui/plugin/CUIWorld.java deleted file mode 100644 index 6459a0d9..00000000 --- a/src/main/java/wecui/plugin/CUIWorld.java +++ /dev/null @@ -1,124 +0,0 @@ -package wecui.plugin; - -public class CUIWorld {} /* extends LocalWorld { - - protected WorldEditCUI controller; - - public CUIWorld(WorldEditCUI controller) { - this.controller = controller; - } - - @Override - public String getName() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public boolean setBlockType(Vector pt, int type) { - System.out.println("Block: " + pt.toString() + " to type " + type); - return true; - } - - @Override - public int getBlockType(Vector pt) { - return 0; - } - - @Override - public void setBlockData(Vector pt, int data) { - } - - @Override - public void setBlockDataFast(Vector pt, int data) { - } - - @Override - public int getBlockData(Vector pt) { - return 0; - } - - @Override - public int getBlockLightLevel(Vector pt) { - return 0; - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof CUIWorld)) { - return false; - } - - return true; - } - - @Override - public int hashCode() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public boolean setBlockType(Vector pt, int type, EditSession session) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public int getBlockType(Vector pt, EditSession session) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public void setBlockData(Vector pt, int data, EditSession session) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public void setBlockDataFast(Vector pt, int data, EditSession session) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public BiomeType getBiome(Vector2D pt) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public void setBiome(Vector2D pt, BiomeType biome) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public int getBlockData(Vector pt, EditSession session) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public boolean regenerate(Region region, EditSession editSession) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public boolean copyToWorld(Vector pt, BaseBlock block) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public boolean copyFromWorld(Vector pt, BaseBlock block) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public boolean clearContainerBlockContents(Vector pt) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public void dropItem(Vector pt, BaseItemStack item) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public int removeEntities(EntityType type, Vector origin, int radius) { - throw new UnsupportedOperationException("Not supported yet."); - } -} -*/ \ No newline at end of file diff --git a/src/main/java/wecui/plugin/LocalPlugin.java b/src/main/java/wecui/plugin/LocalPlugin.java deleted file mode 100644 index 8bb1af41..00000000 --- a/src/main/java/wecui/plugin/LocalPlugin.java +++ /dev/null @@ -1,121 +0,0 @@ -package wecui.plugin; - -/** - * WorldEdit local plugin controller. - * - * @author yetanotherx - */ -public class LocalPlugin {} /* implements InitializationFactory { - - protected WorldEditCUI controller; - protected boolean enabled = false; - protected boolean initialized = false; - protected WorldEdit plugin; - protected CUIWEConfiguration conf; - protected CUIServerInterface serv; - protected CUIWorld world; - protected LocalSession session; - - public LocalPlugin(WorldEditCUI controller) { - this.controller = controller; - } - - @Override - public void initialize() { - controller.setLocalPlugin(new LocalPlugin(controller)); - } - - public String onVersionEvent(String plugin) { - //If for some reason, the local plugin is already disabled, let's not continue. - if (controller.getLocalPlugin().isInitialized()) { - return null; - } - controller.getLocalPlugin().setInitialized(true); - - /*String local = WorldEdit.getVersion(); - - String versions = "Server version - " + plugin + " | Local version - " + local; - controller.getDebugger().debug(versions); - - if (!local.equals(plugin)) { - controller.getDebugger().info(versions); - return throwError("Server and local versions of WorldEdit do not match!"); - } - - if (!WorldEditCUI.WEVERSIONS.contains(local)) { - return throwError("WorldEdit version is not compatible with WorldEditCUI! Certain features will not work!"); - }* / - - this.setConfiguration(new CUIWEConfiguration(controller)); - this.setServerInterface(new CUIServerInterface(controller)); - this.setWorld(new CUIWorld(controller)); - this.setPlugin(new WorldEdit(this.getServerInterface(), this.getConfiguration())); - this.setSession(this.getPlugin().getSession(new CUIPlayer(this.getServerInterface(), controller))); - - controller.getLocalPlugin().setEnabled(true); - return null; - } - - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - public WorldEdit getPlugin() { - return plugin; - } - - public void setPlugin(WorldEdit plugin) { - this.plugin = plugin; - } - - public String throwError(String message) { - enabled = false; - controller.getDebugger().info(message); - controller.getObfuscation().showChatMessage(message); - return message; - } - - public CUIWEConfiguration getConfiguration() { - return conf; - } - - public CUIServerInterface getServerInterface() { - return serv; - } - - public void setConfiguration(CUIWEConfiguration conf) { - this.conf = conf; - } - - public void setServerInterface(CUIServerInterface serv) { - this.serv = serv; - } - - public CUIWorld getWorld() { - return world; - } - - public void setWorld(CUIWorld world) { - this.world = world; - } - - public LocalSession getSession() { - return session; - } - - public void setSession(LocalSession session) { - this.session = session; - } - - public boolean isInitialized() { - return initialized; - } - - public void setInitialized(boolean initialized) { - this.initialized = initialized; - } -} */ diff --git a/src/main/java/wecui/render/LineColor.java b/src/main/java/wecui/render/LineColor.java index b6a1bcc5..71184b47 100644 --- a/src/main/java/wecui/render/LineColor.java +++ b/src/main/java/wecui/render/LineColor.java @@ -17,82 +17,87 @@ * @author yetanotherx * @author lahwran */ -public enum LineColor { - +public enum LineColor +{ CUBOIDBOX ("colour.cuboidedge", new Colour("#CC3333CC")), - CUBOIDGRID ("colour.cuboidgrid", new Colour("#CC4C4CCC")), - CUBOIDPOINT1 ("colour.cuboidpoint1", new Colour("#33CC33CC")), - CUBOIDPOINT2 ("colour.cuboidpoint2", new Colour("#3333CCCC")), - POLYGRID ("colour.polygrid", new Colour("#CC3333CC")), - POLYBOX ("colour.polyedge", new Colour("#CC4C4CCC")), - POLYPOINT ("colour.polypoint", new Colour("#33CCCCCC")), - ELLIPSOIDGRID ("colour.ellipsoidgrid", new Colour("#CC4C4CCC")), - ELLIPSOIDCENTER("colour.ellipsoidpoint", new Colour("#CCCC33CC")), - CYLINDERGRID ("colour.cylindergrid", new Colour("#CC3333CC")), - CYLINDERBOX ("colour.cylinderedge", new Colour("#CC4C4CCC")), - CYLINDERCENTER ("colour.cylinderpoint", new Colour("#CC33CCCC")); + CUBOIDGRID ("colour.cuboidgrid", new Colour("#CC4C4CCC")), + CUBOIDPOINT1 ("colour.cuboidpoint1", new Colour("#33CC33CC")), + CUBOIDPOINT2 ("colour.cuboidpoint2", new Colour("#3333CCCC")), + POLYGRID ("colour.polygrid", new Colour("#CC3333CC")), + POLYBOX ("colour.polyedge", new Colour("#CC4C4CCC")), + POLYPOINT ("colour.polypoint", new Colour("#33CCCCCC")), + ELLIPSOIDGRID ("colour.ellipsoidgrid", new Colour("#CC4C4CCC")), + ELLIPSOIDCENTER("colour.ellipsoidpoint", new Colour("#CCCC33CC")), + CYLINDERGRID ("colour.cylindergrid", new Colour("#CC3333CC")), + CYLINDERBOX ("colour.cylinderedge", new Colour("#CC4C4CCC")), + CYLINDERCENTER ("colour.cylinderpoint", new Colour("#CC33CCCC")); - private String displayName; - - private Colour defaultColour; - private Colour colour; - - private LineInfo normal; - private LineInfo hidden; - - private LineColor(String displayName, Colour colour) { - this.displayName = displayName; - this.colour = colour; - this.defaultColour = new Colour().copyFrom(colour);; - } - - public String getDisplayName() + private String displayName; + + private Colour defaultColour; + private Colour colour; + + private LineInfo normal; + private LineInfo hidden; + + private LineColor(String displayName, Colour colour) + { + this.displayName = displayName; + this.colour = colour; + this.defaultColour = new Colour().copyFrom(colour); + ; + } + + public String getDisplayName() { return I18n.format(this.displayName); } - - public Colour getColour() + + public Colour getColour() { return this.colour; } - - public LineInfo getHidden() { - return this.hidden; - } - - public LineInfo getNormal() { - return this.normal; - } - - public LineInfo[] getColors() { - return new LineInfo[]{this.hidden, this.normal}; - } - + + public LineInfo getHidden() + { + return this.hidden; + } + + public LineInfo getNormal() + { + return this.normal; + } + + public LineInfo[] getColors() + { + return new LineInfo[] { this.hidden, this.normal }; + } + public void setColour(Colour colour) { this.colour = colour; this.updateColor(); } - public void updateColor() - { - this.normal = new LineInfo(3.0f, colour.red(), colour.green(), colour.blue(), colour.alpha(), GL_LESS); - this.hidden = new LineInfo(3.0f, colour.red(), colour.green(), colour.blue(), colour.alpha() * 0.25F, GL_GEQUAL); - } - - public void setDefaultColour() - { - this.colour.copyFrom(this.defaultColour); - this.updateColor(); - } - - public void setColourIntRGBA(int argb) - { - int rgba = ((argb << 8) & 0xFFFFFF00) | (((argb & 0xFF000000) >> 24) & 0xFF); - this.colour.setHex(Integer.toHexString(rgba)); - this.updateColor(); - } - + public void updateColor() + { + this.normal = new LineInfo(3.0f, colour.red(), colour.green(), colour.blue(), colour.alpha(), GL_LESS); + this.hidden = new LineInfo(3.0f, colour.red(), colour.green(), colour.blue(), colour.alpha() * 0.25F, GL_GEQUAL); + } + + public void setDefaultColour() + { + this.colour.copyFrom(this.defaultColour); + this.updateColor(); + } + + public void setColourIntRGBA(int argb) + { + int rgba = ((argb << 8) & 0xFFFFFF00) | (((argb & 0xFF000000) >> 24) & 0xFF); + this.colour.setHex(Integer.toHexString(rgba)); + this.updateColor(); + } + public int getColourIntARGB() { return this.colour.getIntARGB(); diff --git a/src/main/java/wecui/render/LineInfo.java b/src/main/java/wecui/render/LineInfo.java index 5a0dd509..f7b7c1a7 100644 --- a/src/main/java/wecui/render/LineInfo.java +++ b/src/main/java/wecui/render/LineInfo.java @@ -1,6 +1,6 @@ package wecui.render; -import org.lwjgl.opengl.GL11; +import static org.lwjgl.opengl.GL11.*; /** * Stores data about a line that can be rendered @@ -9,46 +9,52 @@ * @author yetanotherx * */ -public class LineInfo { - - public float lineWidth; - public float red; - public float green; - public float blue; - public float alpha; - public int depthfunc; - - public LineInfo(float lineWidth, float r, float g, float b, float a, int depthfunc) { - this.lineWidth = lineWidth; - this.red = r; - this.green = g; - this.blue = b; - this.alpha = a; - this.depthfunc = depthfunc; - } - - public LineInfo(float lineWidth, float r, float g, float b) { - this(lineWidth, r, g, b, 1.0f, GL11.GL_LEQUAL); - } - - public LineInfo(LineInfo orig) { - this.lineWidth = orig.lineWidth; - this.red = orig.red; - this.green = orig.green; - this.blue = orig.blue; - this.alpha = orig.alpha; - this.depthfunc = orig.depthfunc; - } - - /** - * Sets the lineWidth and depthFunction based on this color - */ - public void prepareRender() { - GL11.glLineWidth(this.lineWidth); - GL11.glDepthFunc(this.depthfunc); - } - - public void prepareColor() { - GL11.glColor4f(this.red, this.green, this.blue, this.alpha); - } +public class LineInfo +{ + + public float lineWidth; + public float red; + public float green; + public float blue; + public float alpha; + public int depthfunc; + + public LineInfo(float lineWidth, float r, float g, float b, float a, int depthfunc) + { + this.lineWidth = lineWidth; + this.red = r; + this.green = g; + this.blue = b; + this.alpha = a; + this.depthfunc = depthfunc; + } + + public LineInfo(float lineWidth, float r, float g, float b) + { + this(lineWidth, r, g, b, 1.0f, GL_LEQUAL); + } + + public LineInfo(LineInfo orig) + { + this.lineWidth = orig.lineWidth; + this.red = orig.red; + this.green = orig.green; + this.blue = orig.blue; + this.alpha = orig.alpha; + this.depthfunc = orig.depthfunc; + } + + /** + * Sets the lineWidth and depthFunction based on this color + */ + public void prepareRender() + { + glLineWidth(this.lineWidth); + glDepthFunc(this.depthfunc); + } + + public void prepareColor() + { + glColor4f(this.red, this.green, this.blue, this.alpha); + } } diff --git a/src/main/java/wecui/render/points/PointCube.java b/src/main/java/wecui/render/points/PointCube.java index e0752796..881af4e5 100644 --- a/src/main/java/wecui/render/points/PointCube.java +++ b/src/main/java/wecui/render/points/PointCube.java @@ -13,44 +13,53 @@ * @author yetanotherx * @author lahwran */ -public class PointCube { - - protected Vector3 point; - protected LineColor color = LineColor.CUBOIDPOINT1; - - public PointCube(Vector3 point) { - this.point = point; - } - - public PointCube(int x, int y, int z) { - this.point = new Vector3(x, y, z); - } - - public PointCube(double x, double y, double z) { - this.point = new Vector3(x, y, z); - } - - public void render() { - double off = 0.03f; - Vector3 minVec = new Vector3(off, off, off); - Vector3 maxVec = new Vector3(off + 1, off + 1, off + 1); - - new Render3DBox(this.color, this.point.subtract(minVec), this.point.add(maxVec)).render(); - } - - public Vector3 getPoint() { - return this.point; - } - - public void setPoint(Vector3 point) { - this.point = point; - } - - public LineColor getColor() { - return this.color; - } - - public void setColor(LineColor color) { - this.color = color; - } +public class PointCube +{ + + protected Vector3 point; + protected LineColor color = LineColor.CUBOIDPOINT1; + + public PointCube(Vector3 point) + { + this.point = point; + } + + public PointCube(int x, int y, int z) + { + this.point = new Vector3(x, y, z); + } + + public PointCube(double x, double y, double z) + { + this.point = new Vector3(x, y, z); + } + + public void render() + { + double off = 0.03f; + Vector3 minVec = new Vector3(off, off, off); + Vector3 maxVec = new Vector3(off + 1, off + 1, off + 1); + + new Render3DBox(this.color, this.point.subtract(minVec), this.point.add(maxVec)).render(); + } + + public Vector3 getPoint() + { + return this.point; + } + + public void setPoint(Vector3 point) + { + this.point = point; + } + + public LineColor getColor() + { + return this.color; + } + + public void setColor(LineColor color) + { + this.color = color; + } } diff --git a/src/main/java/wecui/render/points/PointRectangle.java b/src/main/java/wecui/render/points/PointRectangle.java index fe8c5661..45988c0f 100644 --- a/src/main/java/wecui/render/points/PointRectangle.java +++ b/src/main/java/wecui/render/points/PointRectangle.java @@ -13,40 +13,48 @@ * @author yetanotherx * @author lahwran */ -public class PointRectangle { - - protected Vector2 point; - protected LineColor color = LineColor.POLYPOINT; - - public PointRectangle(Vector2 point) { - this.point = point; - } - - public PointRectangle(int x, int z) { - this.point = new Vector2(x, z); - } - - public void render(int min, int max) { - float off = 0.03f; - Vector2 minVec = new Vector2(off, off); - Vector2 maxVec = new Vector2(off + 1, off + 1); - - new Render3DBox(this.color, this.point.subtract(minVec).toVector3(min - off), this.point.add(maxVec).toVector3(max + 1 + off)).render(); - } - - public Vector2 getPoint() { - return this.point; - } - - public void setPoint(Vector2 point) { - this.point = point; - } - - public LineColor getColor() { - return this.color; - } - - public void setColor(LineColor color) { - this.color = color; - } +public class PointRectangle +{ + + protected Vector2 point; + protected LineColor color = LineColor.POLYPOINT; + + public PointRectangle(Vector2 point) + { + this.point = point; + } + + public PointRectangle(int x, int z) + { + this.point = new Vector2(x, z); + } + + public void render(int min, int max) + { + float off = 0.03f; + Vector2 minVec = new Vector2(off, off); + Vector2 maxVec = new Vector2(off + 1, off + 1); + + new Render3DBox(this.color, this.point.subtract(minVec).toVector3(min - off), this.point.add(maxVec).toVector3(max + 1 + off)).render(); + } + + public Vector2 getPoint() + { + return this.point; + } + + public void setPoint(Vector2 point) + { + this.point = point; + } + + public LineColor getColor() + { + return this.color; + } + + public void setColor(LineColor color) + { + this.color = color; + } } diff --git a/src/main/java/wecui/render/region/BaseRegion.java b/src/main/java/wecui/render/region/BaseRegion.java index 8abd5a6f..1cbc705d 100644 --- a/src/main/java/wecui/render/region/BaseRegion.java +++ b/src/main/java/wecui/render/region/BaseRegion.java @@ -11,43 +11,54 @@ * @author yetanotherx * @author lahwran */ -public abstract class BaseRegion implements InitializationFactory { - - protected WorldEditCUI controller; - - public BaseRegion(WorldEditCUI controller) { - this.controller = controller; - } - - @Override - public void initialize() { - } - - public abstract void render(); - - public void setCuboidPoint(int id, double x, double y, double z) { - } - - public void setPolygonPoint(int id, int x, int z) { - } - - public void setEllipsoidCenter(int x, int y, int z) { - } - - public void setEllipsoidRadii(double x, double y, double z) { - } - - public void setMinMax(int min, int max) { - } - - public void setCylinderCenter(int x, int y, int z) { - } - - public void setCylinderRadius(double x, double z) { - } - - public void addPolygon(int[] vertexIds) { - } - - public abstract RegionType getType(); +public abstract class BaseRegion implements InitializationFactory +{ + + protected WorldEditCUI controller; + + public BaseRegion(WorldEditCUI controller) + { + this.controller = controller; + } + + @Override + public void initialize() + { + } + + public abstract void render(); + + public void setCuboidPoint(int id, double x, double y, double z) + { + } + + public void setPolygonPoint(int id, int x, int z) + { + } + + public void setEllipsoidCenter(int x, int y, int z) + { + } + + public void setEllipsoidRadii(double x, double y, double z) + { + } + + public void setMinMax(int min, int max) + { + } + + public void setCylinderCenter(int x, int y, int z) + { + } + + public void setCylinderRadius(double x, double z) + { + } + + public void addPolygon(int[] vertexIds) + { + } + + public abstract RegionType getType(); } diff --git a/src/main/java/wecui/render/region/CuboidRegion.java b/src/main/java/wecui/render/region/CuboidRegion.java index 1d79a84b..74af4307 100644 --- a/src/main/java/wecui/render/region/CuboidRegion.java +++ b/src/main/java/wecui/render/region/CuboidRegion.java @@ -14,88 +14,109 @@ * @author yetanotherx * @author lahwran */ -public class CuboidRegion extends BaseRegion { - - protected PointCube firstPoint; - protected PointCube secondPoint; - - public CuboidRegion(WorldEditCUI controller) { - super(controller); - } - - @Override - public void render() { - if (this.firstPoint != null && this.secondPoint != null) { - - Vector3[] bounds = this.calcBounds(); - new Render3DGrid(LineColor.CUBOIDGRID, bounds[0], bounds[1]).render(); - new Render3DBox(LineColor.CUBOIDBOX, bounds[0], bounds[1]).render(); - - this.firstPoint.render(); - this.secondPoint.render(); - - } else if (this.firstPoint != null) { - this.firstPoint.render(); - } else if (this.secondPoint != null) { - this.secondPoint.render(); - } - } - - @Override - public void setCuboidPoint(int id, double x, double y, double z) { - if (id == 0) { - this.firstPoint = new PointCube(x, y, z); - this.firstPoint.setColor(LineColor.CUBOIDPOINT1); - } else if (id == 1) { - this.secondPoint = new PointCube(x, y, z); - this.secondPoint.setColor(LineColor.CUBOIDPOINT2); - } - } - - /** - * Calculates the boundary points of the actual box. - * I have no idea what I'm doing. - * @return - */ - protected Vector3m[] calcBounds() { - float off = 0.02f; - float off1 = 1 + off; - - Vector3m[] out = new Vector3m[2]; - out[0] = new Vector3m(Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE); - out[1] = new Vector3m(-Double.MAX_VALUE, -Double.MAX_VALUE, -Double.MAX_VALUE); - - for (PointCube point : new PointCube[]{this.firstPoint, this.secondPoint}) { - if (point.getPoint().getX() + off1 > out[1].getX()) { - out[1].setX(point.getPoint().getX() + off1); - } - - if (point.getPoint().getX() - off < out[0].getX()) { - out[0].setX(point.getPoint().getX() - off); - } - - if (point.getPoint().getY() + off1 > out[1].getY()) { - out[1].setY(point.getPoint().getY() + off1); - } - - if (point.getPoint().getY() - off < out[0].getY()) { - out[0].setY(point.getPoint().getY() - off); - } - - if (point.getPoint().getZ() + off1 > out[1].getZ()) { - out[1].setZ(point.getPoint().getZ() + off1); - } - - if (point.getPoint().getZ() - off < out[0].getZ()) { - out[0].setZ(point.getPoint().getZ() - off); - } - } - - return out; - } - - @Override - public RegionType getType() { - return RegionType.CUBOID; - } +public class CuboidRegion extends BaseRegion +{ + + protected PointCube firstPoint; + protected PointCube secondPoint; + + public CuboidRegion(WorldEditCUI controller) + { + super(controller); + } + + @Override + public void render() + { + if (this.firstPoint != null && this.secondPoint != null) + { + + Vector3[] bounds = this.calcBounds(); + new Render3DGrid(LineColor.CUBOIDGRID, bounds[0], bounds[1]).render(); + new Render3DBox(LineColor.CUBOIDBOX, bounds[0], bounds[1]).render(); + + this.firstPoint.render(); + this.secondPoint.render(); + + } + else if (this.firstPoint != null) + { + this.firstPoint.render(); + } + else if (this.secondPoint != null) + { + this.secondPoint.render(); + } + } + + @Override + public void setCuboidPoint(int id, double x, double y, double z) + { + if (id == 0) + { + this.firstPoint = new PointCube(x, y, z); + this.firstPoint.setColor(LineColor.CUBOIDPOINT1); + } + else if (id == 1) + { + this.secondPoint = new PointCube(x, y, z); + this.secondPoint.setColor(LineColor.CUBOIDPOINT2); + } + } + + /** + * Calculates the boundary points of the actual box. + * I have no idea what I'm doing. + * @return + */ + protected Vector3m[] calcBounds() + { + float off = 0.02f; + float off1 = 1 + off; + + Vector3m[] out = new Vector3m[2]; + out[0] = new Vector3m(Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE); + out[1] = new Vector3m(-Double.MAX_VALUE, -Double.MAX_VALUE, -Double.MAX_VALUE); + + for (PointCube point : new PointCube[] { this.firstPoint, this.secondPoint }) + { + if (point.getPoint().getX() + off1 > out[1].getX()) + { + out[1].setX(point.getPoint().getX() + off1); + } + + if (point.getPoint().getX() - off < out[0].getX()) + { + out[0].setX(point.getPoint().getX() - off); + } + + if (point.getPoint().getY() + off1 > out[1].getY()) + { + out[1].setY(point.getPoint().getY() + off1); + } + + if (point.getPoint().getY() - off < out[0].getY()) + { + out[0].setY(point.getPoint().getY() - off); + } + + if (point.getPoint().getZ() + off1 > out[1].getZ()) + { + out[1].setZ(point.getPoint().getZ() + off1); + } + + if (point.getPoint().getZ() - off < out[0].getZ()) + { + out[0].setZ(point.getPoint().getZ() - off); + } + } + + return out; + } + + @Override + public RegionType getType() + { + return RegionType.CUBOID; + } } diff --git a/src/main/java/wecui/render/region/CylinderRegion.java b/src/main/java/wecui/render/region/CylinderRegion.java index cb5d11c8..5dc6de8f 100644 --- a/src/main/java/wecui/render/region/CylinderRegion.java +++ b/src/main/java/wecui/render/region/CylinderRegion.java @@ -12,58 +12,67 @@ * * @author yetanotherx */ -public class CylinderRegion extends BaseRegion { - - protected PointCube center; - protected double radX = 0; - protected double radZ = 0; - protected int minY = 0; - protected int maxY = 0; - - public CylinderRegion(WorldEditCUI controller) { - super(controller); - } - - @Override - public void render() { - if (this.center != null) { - this.center.render(); - - int tMin = this.minY; - int tMax = this.maxY; - - if (this.minY == 0 || this.maxY == 0) { - tMin = (int) this.center.getPoint().getY(); - tMax = (int) this.center.getPoint().getY(); - } - - new RenderCylinderCircles(LineColor.CYLINDERGRID, this.center, this.radX, this.radZ, tMin, tMax).render(); - new RenderCylinderGrid(LineColor.CYLINDERGRID, this.center, this.radX, this.radZ, tMin, tMax).render(); - new RenderCylinderBox(LineColor.CYLINDERBOX, this.center, this.radX, this.radZ, tMin, tMax).render(); - - } - } - - @Override - public void setCylinderCenter(int x, int y, int z) { - this.center = new PointCube(x, y, z); - this.center.setColor(LineColor.CYLINDERCENTER); - } - - @Override - public void setCylinderRadius(double x, double z) { - this.radX = x; - this.radZ = z; - } - - @Override - public void setMinMax(int min, int max) { - this.minY = min; - this.maxY = max; - } - - @Override - public RegionType getType() { - return RegionType.CYLINDER; - } +public class CylinderRegion extends BaseRegion +{ + + protected PointCube center; + protected double radX = 0; + protected double radZ = 0; + protected int minY = 0; + protected int maxY = 0; + + public CylinderRegion(WorldEditCUI controller) + { + super(controller); + } + + @Override + public void render() + { + if (this.center != null) + { + this.center.render(); + + int tMin = this.minY; + int tMax = this.maxY; + + if (this.minY == 0 || this.maxY == 0) + { + tMin = (int)this.center.getPoint().getY(); + tMax = (int)this.center.getPoint().getY(); + } + + new RenderCylinderCircles(LineColor.CYLINDERGRID, this.center, this.radX, this.radZ, tMin, tMax).render(); + new RenderCylinderGrid(LineColor.CYLINDERGRID, this.center, this.radX, this.radZ, tMin, tMax).render(); + new RenderCylinderBox(LineColor.CYLINDERBOX, this.center, this.radX, this.radZ, tMin, tMax).render(); + + } + } + + @Override + public void setCylinderCenter(int x, int y, int z) + { + this.center = new PointCube(x, y, z); + this.center.setColor(LineColor.CYLINDERCENTER); + } + + @Override + public void setCylinderRadius(double x, double z) + { + this.radX = x; + this.radZ = z; + } + + @Override + public void setMinMax(int min, int max) + { + this.minY = min; + this.maxY = max; + } + + @Override + public RegionType getType() + { + return RegionType.CYLINDER; + } } diff --git a/src/main/java/wecui/render/region/EllipsoidRegion.java b/src/main/java/wecui/render/region/EllipsoidRegion.java index 45c14c32..6859e13d 100644 --- a/src/main/java/wecui/render/region/EllipsoidRegion.java +++ b/src/main/java/wecui/render/region/EllipsoidRegion.java @@ -12,42 +12,50 @@ * @author yetanotherx * @author lahwran */ -public class EllipsoidRegion extends BaseRegion { - - protected PointCube center; - protected Vector3 radii; - - public EllipsoidRegion(WorldEditCUI controller) { - super(controller); - } - - @Override - public void render() { - if( this.center != null && this.radii != null ) { - this.center.render(); - - new RenderEllipsoid(LineColor.ELLIPSOIDGRID, this.center, this.radii).render(); - - } - else if( this.center != null ) { - this.center.render(); - } - } - - @Override - public void setEllipsoidCenter(int x, int y, int z) { - this.center = new PointCube(x, y, z); - this.center.setColor(LineColor.ELLIPSOIDCENTER); - } - - @Override - public void setEllipsoidRadii(double x, double y, double z) { - this.radii = new Vector3(x, y, z); - } - - @Override - public RegionType getType() { - return RegionType.ELLIPSOID; - } - +public class EllipsoidRegion extends BaseRegion +{ + + protected PointCube center; + protected Vector3 radii; + + public EllipsoidRegion(WorldEditCUI controller) + { + super(controller); + } + + @Override + public void render() + { + if (this.center != null && this.radii != null) + { + this.center.render(); + + new RenderEllipsoid(LineColor.ELLIPSOIDGRID, this.center, this.radii).render(); + + } + else if (this.center != null) + { + this.center.render(); + } + } + + @Override + public void setEllipsoidCenter(int x, int y, int z) + { + this.center = new PointCube(x, y, z); + this.center.setColor(LineColor.ELLIPSOIDCENTER); + } + + @Override + public void setEllipsoidRadii(double x, double y, double z) + { + this.radii = new Vector3(x, y, z); + } + + @Override + public RegionType getType() + { + return RegionType.ELLIPSOID; + } + } diff --git a/src/main/java/wecui/render/region/PolygonRegion.java b/src/main/java/wecui/render/region/PolygonRegion.java index ddc8d637..6a0d5973 100644 --- a/src/main/java/wecui/render/region/PolygonRegion.java +++ b/src/main/java/wecui/render/region/PolygonRegion.java @@ -15,54 +15,66 @@ * @author yetanotherx * @author lahwran */ -public class PolygonRegion extends BaseRegion { - - protected List points = new ArrayList(); - protected int min; - protected int max; - - public PolygonRegion(WorldEditCUI controller) { - super(controller); - } - - @Override - public void render() { - if (this.points == null) { - return; - } - - for (PointRectangle point : this.points) { - point.render(this.min, this.max); - } - - new Render2DBox(LineColor.POLYBOX, this.points, this.min, this.max).render(); - new Render2DGrid(LineColor.POLYGRID, this.points, this.min, this.max).render(); - - } - - @Override - public void setMinMax(int min, int max) { - this.min = min; - this.max = max; - } - - @Override - public void setPolygonPoint(int id, int x, int z) { - PointRectangle point = new PointRectangle(x, z); - point.setColor(LineColor.POLYPOINT); - - if (id < this.points.size()) { - this.points.set(id, point); - } else { - for (int i = 0; i < id - this.points.size(); i++) { - this.points.add(null); - } - this.points.add(point); - } - } - - @Override - public RegionType getType() { - return RegionType.POLYGON; - } +public class PolygonRegion extends BaseRegion +{ + + protected List points = new ArrayList(); + protected int min; + protected int max; + + public PolygonRegion(WorldEditCUI controller) + { + super(controller); + } + + @Override + public void render() + { + if (this.points == null) + { + return; + } + + for (PointRectangle point : this.points) + { + point.render(this.min, this.max); + } + + new Render2DBox(LineColor.POLYBOX, this.points, this.min, this.max).render(); + new Render2DGrid(LineColor.POLYGRID, this.points, this.min, this.max).render(); + + } + + @Override + public void setMinMax(int min, int max) + { + this.min = min; + this.max = max; + } + + @Override + public void setPolygonPoint(int id, int x, int z) + { + PointRectangle point = new PointRectangle(x, z); + point.setColor(LineColor.POLYPOINT); + + if (id < this.points.size()) + { + this.points.set(id, point); + } + else + { + for (int i = 0; i < id - this.points.size(); i++) + { + this.points.add(null); + } + this.points.add(point); + } + } + + @Override + public RegionType getType() + { + return RegionType.POLYGON; + } } diff --git a/src/main/java/wecui/render/region/PolyhedronRegion.java b/src/main/java/wecui/render/region/PolyhedronRegion.java index 831d1c88..8759a40c 100644 --- a/src/main/java/wecui/render/region/PolyhedronRegion.java +++ b/src/main/java/wecui/render/region/PolyhedronRegion.java @@ -14,60 +14,74 @@ * * @author TomyLobo */ -public class PolyhedronRegion extends BaseRegion { - - protected List vertices = new ArrayList(); - protected List faces = new ArrayList(); - - public PolyhedronRegion(WorldEditCUI controller) { - super(controller); - } - - @Override - public void render() { - for (PointCube vertex : this.vertices) { - vertex.render(); - } - - for (Vector3[] face : this.faces) { - new Render3DPolygon(LineColor.POLYBOX, face).render(); - } - } - - @Override - public void setCuboidPoint(int id, double x, double y, double z) { - final PointCube vertex = new PointCube(x, y, z); - vertex.setColor(id == 0 ? LineColor.CUBOIDPOINT1 : LineColor.POLYPOINT); - - if (id < this.vertices.size()) { - this.vertices.set(id, vertex); - } else { - for (int i = 0; i < id - this.vertices.size(); i++) { - this.vertices.add(null); - } - this.vertices.add(vertex); - } - } - - private static final Vector3 half = new Vector3(0.5, 0.5, 0.5); - - @Override - public void addPolygon(int[] vertexIds) { - final Vector3[] face = new Vector3[vertexIds.length]; - for (int i = 0; i < vertexIds.length; ++i) { - final PointCube vertex = vertices.get(vertexIds[i]); - if (vertex == null) { - // This should never happen - return; - } - - face[i] = vertex.getPoint().add(half); - } - faces.add(face); - } - - @Override - public RegionType getType() { - return RegionType.POLYHEDRON; - } +public class PolyhedronRegion extends BaseRegion +{ + + protected List vertices = new ArrayList(); + protected List faces = new ArrayList(); + + public PolyhedronRegion(WorldEditCUI controller) + { + super(controller); + } + + @Override + public void render() + { + for (PointCube vertex : this.vertices) + { + vertex.render(); + } + + for (Vector3[] face : this.faces) + { + new Render3DPolygon(LineColor.POLYBOX, face).render(); + } + } + + @Override + public void setCuboidPoint(int id, double x, double y, double z) + { + final PointCube vertex = new PointCube(x, y, z); + vertex.setColor(id == 0 ? LineColor.CUBOIDPOINT1 : LineColor.POLYPOINT); + + if (id < this.vertices.size()) + { + this.vertices.set(id, vertex); + } + else + { + for (int i = 0; i < id - this.vertices.size(); i++) + { + this.vertices.add(null); + } + this.vertices.add(vertex); + } + } + + private static final Vector3 half = new Vector3(0.5, 0.5, 0.5); + + @Override + public void addPolygon(int[] vertexIds) + { + final Vector3[] face = new Vector3[vertexIds.length]; + for (int i = 0; i < vertexIds.length; ++i) + { + final PointCube vertex = vertices.get(vertexIds[i]); + if (vertex == null) + { + // This should never happen + return; + } + + face[i] = vertex.getPoint().add(half); + } + faces.add(face); + } + + @Override + public RegionType getType() + { + return RegionType.POLYHEDRON; + } } diff --git a/src/main/java/wecui/render/region/RegionType.java b/src/main/java/wecui/render/region/RegionType.java index 33345f95..1e159854 100644 --- a/src/main/java/wecui/render/region/RegionType.java +++ b/src/main/java/wecui/render/region/RegionType.java @@ -5,12 +5,11 @@ * * @author yetanotherx */ -public enum RegionType { - - CUBOID, - POLYGON, - ELLIPSOID, - CYLINDER, - POLYHEDRON - +public enum RegionType +{ + CUBOID, + POLYGON, + ELLIPSOID, + CYLINDER, + POLYHEDRON } diff --git a/src/main/java/wecui/render/shapes/Render2DBox.java b/src/main/java/wecui/render/shapes/Render2DBox.java index ba558531..178ee6d1 100644 --- a/src/main/java/wecui/render/shapes/Render2DBox.java +++ b/src/main/java/wecui/render/shapes/Render2DBox.java @@ -4,7 +4,7 @@ import net.minecraft.client.renderer.Tessellator; -import org.lwjgl.opengl.GL11; +import static org.lwjgl.opengl.GL11.*; import wecui.render.LineColor; import wecui.render.LineInfo; @@ -16,36 +16,42 @@ * @author yetanotherx * @author lahwran */ -public class Render2DBox { - - protected LineColor color; - protected List points; - protected int min; - protected int max; - - public Render2DBox(LineColor color, List points, int min, int max) { - this.color = color; - this.points = points; - this.min = min; - this.max = max; - } - - public void render() { - Tessellator tess = Tessellator.instance; - double off = 0.03; - for (LineInfo tempColor : this.color.getColors()) { - tempColor.prepareRender(); - - tess.startDrawing(GL11.GL_LINES); - tempColor.prepareColor(); - - for (PointRectangle point : this.points) { - if (point != null) { - tess.addVertex(point.getPoint().getX() + 0.5, this.min + off, point.getPoint().getY() + 0.5); - tess.addVertex(point.getPoint().getX() + 0.5, this.max + 1 + off, point.getPoint().getY() + 0.5); - } - } - tess.draw(); - } - } +public class Render2DBox +{ + + protected LineColor color; + protected List points; + protected int min; + protected int max; + + public Render2DBox(LineColor color, List points, int min, int max) + { + this.color = color; + this.points = points; + this.min = min; + this.max = max; + } + + public void render() + { + Tessellator tess = Tessellator.instance; + double off = 0.03; + for (LineInfo tempColor : this.color.getColors()) + { + tempColor.prepareRender(); + + tess.startDrawing(GL_LINES); + tempColor.prepareColor(); + + for (PointRectangle point : this.points) + { + if (point != null) + { + tess.addVertex(point.getPoint().getX() + 0.5, this.min + off, point.getPoint().getY() + 0.5); + tess.addVertex(point.getPoint().getX() + 0.5, this.max + 1 + off, point.getPoint().getY() + 0.5); + } + } + tess.draw(); + } + } } diff --git a/src/main/java/wecui/render/shapes/Render2DGrid.java b/src/main/java/wecui/render/shapes/Render2DGrid.java index 013314e7..123f406f 100644 --- a/src/main/java/wecui/render/shapes/Render2DGrid.java +++ b/src/main/java/wecui/render/shapes/Render2DGrid.java @@ -4,7 +4,7 @@ import net.minecraft.client.renderer.Tessellator; -import org.lwjgl.opengl.GL11; +import static org.lwjgl.opengl.GL11.*; import wecui.render.LineColor; import wecui.render.LineInfo; @@ -16,40 +16,47 @@ * @author yetanotherx * @author lahwran */ -public class Render2DGrid { - - protected LineColor color; - protected List points; - protected int min; - protected int max; - - public Render2DGrid(LineColor color, List points, int min, int max) { - this.color = color; - this.points = points; - this.min = min; - this.max = max; - } - - public void render() { - double off = 0.03; - for (double height = this.min; height <= this.max + 1; height++) { - this.drawPoly(height + off); - } - } - - protected void drawPoly(double height) { - Tessellator tess = Tessellator.instance; - for (LineInfo tempColor : this.color.getColors()) { - tempColor.prepareRender(); - - tess.startDrawing(GL11.GL_LINE_LOOP); - tempColor.prepareColor(); - for (PointRectangle point : this.points) { - if (point != null) { - tess.addVertex(point.getPoint().getX() + 0.5, height, point.getPoint().getY() + 0.5); - } - } - tess.draw(); - } - } +public class Render2DGrid +{ + protected LineColor color; + protected List points; + protected int min; + protected int max; + + public Render2DGrid(LineColor color, List points, int min, int max) + { + this.color = color; + this.points = points; + this.min = min; + this.max = max; + } + + public void render() + { + double off = 0.03; + for (double height = this.min; height <= this.max + 1; height++) + { + this.drawPoly(height + off); + } + } + + protected void drawPoly(double height) + { + Tessellator tess = Tessellator.instance; + for (LineInfo tempColor : this.color.getColors()) + { + tempColor.prepareRender(); + + tess.startDrawing(GL_LINE_LOOP); + tempColor.prepareColor(); + for (PointRectangle point : this.points) + { + if (point != null) + { + tess.addVertex(point.getPoint().getX() + 0.5, height, point.getPoint().getY() + 0.5); + } + } + tess.draw(); + } + } } diff --git a/src/main/java/wecui/render/shapes/Render3DBox.java b/src/main/java/wecui/render/shapes/Render3DBox.java index 34c67178..a326feec 100644 --- a/src/main/java/wecui/render/shapes/Render3DBox.java +++ b/src/main/java/wecui/render/shapes/Render3DBox.java @@ -2,7 +2,7 @@ import net.minecraft.client.renderer.Tessellator; -import org.lwjgl.opengl.GL11; +import static org.lwjgl.opengl.GL11.*; import wecui.render.LineColor; import wecui.render.LineInfo; @@ -14,65 +14,69 @@ * @author yetanotherx * @author lahwran */ -public class Render3DBox { - - protected LineColor color; - protected Vector3 first; - protected Vector3 second; - - public Render3DBox(LineColor color, Vector3 first, Vector3 second) { - this.color = color; - this.first = first; - this.second = second; - } - - public void render() { - Tessellator tess = Tessellator.instance; - double x1 = this.first.getX(); - double y1 = this.first.getY(); - double z1 = this.first.getZ(); - double x2 = this.second.getX(); - double y2 = this.second.getY(); - double z2 = this.second.getZ(); - - for (LineInfo tempColor : this.color.getColors()) { - tempColor.prepareRender(); - - // Draw bottom face - tess.startDrawing(GL11.GL_LINE_LOOP); - tempColor.prepareColor(); - tess.addVertex(x1, y1, z1); - tess.addVertex(x2, y1, z1); - tess.addVertex(x2, y1, z2); - tess.addVertex(x1, y1, z2); - tess.draw(); - - // Draw top face - tess.startDrawing(GL11.GL_LINE_LOOP); - tempColor.prepareColor(); - tess.addVertex(x1, y2, z1); - tess.addVertex(x2, y2, z1); - tess.addVertex(x2, y2, z2); - tess.addVertex(x1, y2, z2); - tess.draw(); - - // Draw join top and bottom faces - tess.startDrawing(GL11.GL_LINES); - tempColor.prepareColor(); - - tess.addVertex(x1, y1, z1); - tess.addVertex(x1, y2, z1); - - tess.addVertex(x2, y1, z1); - tess.addVertex(x2, y2, z1); - - tess.addVertex(x2, y1, z2); - tess.addVertex(x2, y2, z2); - - tess.addVertex(x1, y1, z2); - tess.addVertex(x1, y2, z2); - - tess.draw(); - } - } +public class Render3DBox +{ + + protected LineColor color; + protected Vector3 first; + protected Vector3 second; + + public Render3DBox(LineColor color, Vector3 first, Vector3 second) + { + this.color = color; + this.first = first; + this.second = second; + } + + public void render() + { + Tessellator tess = Tessellator.instance; + double x1 = this.first.getX(); + double y1 = this.first.getY(); + double z1 = this.first.getZ(); + double x2 = this.second.getX(); + double y2 = this.second.getY(); + double z2 = this.second.getZ(); + + for (LineInfo tempColor : this.color.getColors()) + { + tempColor.prepareRender(); + + // Draw bottom face + tess.startDrawing(GL_LINE_LOOP); + tempColor.prepareColor(); + tess.addVertex(x1, y1, z1); + tess.addVertex(x2, y1, z1); + tess.addVertex(x2, y1, z2); + tess.addVertex(x1, y1, z2); + tess.draw(); + + // Draw top face + tess.startDrawing(GL_LINE_LOOP); + tempColor.prepareColor(); + tess.addVertex(x1, y2, z1); + tess.addVertex(x2, y2, z1); + tess.addVertex(x2, y2, z2); + tess.addVertex(x1, y2, z2); + tess.draw(); + + // Draw join top and bottom faces + tess.startDrawing(GL_LINES); + tempColor.prepareColor(); + + tess.addVertex(x1, y1, z1); + tess.addVertex(x1, y2, z1); + + tess.addVertex(x2, y1, z1); + tess.addVertex(x2, y2, z1); + + tess.addVertex(x2, y1, z2); + tess.addVertex(x2, y2, z2); + + tess.addVertex(x1, y1, z2); + tess.addVertex(x1, y2, z2); + + tess.draw(); + } + } } diff --git a/src/main/java/wecui/render/shapes/Render3DGrid.java b/src/main/java/wecui/render/shapes/Render3DGrid.java index 6e381b8f..a02c3c24 100644 --- a/src/main/java/wecui/render/shapes/Render3DGrid.java +++ b/src/main/java/wecui/render/shapes/Render3DGrid.java @@ -2,7 +2,7 @@ import net.minecraft.client.renderer.Tessellator; -import org.lwjgl.opengl.GL11; +import static org.lwjgl.opengl.GL11.*; import wecui.render.LineColor; import wecui.render.LineInfo; @@ -14,143 +14,171 @@ * * @author yetanotherx */ -public class Render3DGrid { - - protected LineColor color; - protected Vector3 first; - protected Vector3 second; - - public Render3DGrid(LineColor color, Vector3 first, Vector3 second) { - this.color = color; - this.first = first; - this.second = second; - } - - public void render() { - Tessellator tess = Tessellator.instance; - double x1 = this.first.getX(); - double y1 = this.first.getY(); - double z1 = this.first.getZ(); - double x2 = this.second.getX(); - double y2 = this.second.getY(); - double z2 = this.second.getZ(); - - for (LineInfo tempColor : this.color.getColors()) { - tempColor.prepareRender(); - - tess.startDrawing(GL11.GL_LINES); - tempColor.prepareColor(); - - double x, y, z; - double offsetSize = 1.0; - - // Zmax XY plane, y axis - z = z2; - y = y1; - int msize = 150; - if ((y2 - y / offsetSize) < msize) { - for (double yoff = 0; yoff + y <= y2; yoff += offsetSize) { - tess.addVertex(x1, y + yoff, z); - tess.addVertex(x2, y + yoff, z); - } - } - - // Zmin XY plane, y axis - z = z1; - if ((y2 - y / offsetSize) < msize) { - for (double yoff = 0; yoff + y <= y2; yoff += offsetSize) { - tess.addVertex(x1, y + yoff, z); - tess.addVertex(x2, y + yoff, z); - } - } - - // Xmin YZ plane, y axis - x = x1; - if ((y2 - y / offsetSize) < msize) { - for (double yoff = 0; yoff + y <= y2; yoff += offsetSize) { - tess.addVertex(x, y + yoff, z1); - tess.addVertex(x, y + yoff, z2); - } - } - - // Xmax YZ plane, y axis - x = x2; - if ((y2 - y / offsetSize) < msize) { - for (double yoff = 0; yoff + y <= y2; yoff += offsetSize) { - tess.addVertex(x, y + yoff, z1); - tess.addVertex(x, y + yoff, z2); - } - } - - // Zmin XY plane, x axis - x = x1; - z = z1; - if ((x2 - x / offsetSize) < msize) { - for (double xoff = 0; xoff + x <= x2; xoff += offsetSize) { - tess.addVertex(x + xoff, y1, z); - tess.addVertex(x + xoff, y2, z); - } - } - // Zmax XY plane, x axis - z = z2; - if ((x2 - x / offsetSize) < msize) { - for (double xoff = 0; xoff + x <= x2; xoff += offsetSize) { - tess.addVertex(x + xoff, y1, z); - tess.addVertex(x + xoff, y2, z); - } - } - // Ymin XZ plane, x axis - y = y2; - if ((x2 - x / offsetSize) < msize) { - for (double xoff = 0; xoff + x <= x2; xoff += offsetSize) { - tess.addVertex(x + xoff, y, z1); - tess.addVertex(x + xoff, y, z2); - } - } - // Ymax XZ plane, x axis - y = y1; - if ((x2 - x / offsetSize) < msize) { - for (double xoff = 0; xoff + x <= x2; xoff += offsetSize) { - tess.addVertex(x + xoff, y, z1); - tess.addVertex(x + xoff, y, z2); - } - } - - // Ymin XZ plane, z axis - z = z1; - y = y1; - if ((z2 - z / offsetSize) < msize) { - for (double zoff = 0; zoff + z <= z2; zoff += offsetSize) { - tess.addVertex(x1, y, z + zoff); - tess.addVertex(x2, y, z + zoff); - } - } - // Ymax XZ plane, z axis - y = y2; - if ((z2 - z / offsetSize) < msize) { - for (double zoff = 0; zoff + z <= z2; zoff += offsetSize) { - tess.addVertex(x1, y, z + zoff); - tess.addVertex(x2, y, z + zoff); - } - } - // Xmin YZ plane, z axis - x = x2; - if ((z2 - z / offsetSize) < msize) { - for (double zoff = 0; zoff + z <= z2; zoff += offsetSize) { - tess.addVertex(x, y1, z + zoff); - tess.addVertex(x, y2, z + zoff); - } - } - // Xmax YZ plane, z axis - x = x1; - if ((z2 - z / offsetSize) < msize) { - for (double zoff = 0; zoff + z <= z2; zoff += offsetSize) { - tess.addVertex(x, y1, z + zoff); - tess.addVertex(x, y2, z + zoff); - } - } - - tess.draw(); - } - } +public class Render3DGrid +{ + + protected LineColor color; + protected Vector3 first; + protected Vector3 second; + + public Render3DGrid(LineColor color, Vector3 first, Vector3 second) + { + this.color = color; + this.first = first; + this.second = second; + } + + public void render() + { + Tessellator tess = Tessellator.instance; + double x1 = this.first.getX(); + double y1 = this.first.getY(); + double z1 = this.first.getZ(); + double x2 = this.second.getX(); + double y2 = this.second.getY(); + double z2 = this.second.getZ(); + + for (LineInfo tempColor : this.color.getColors()) + { + tempColor.prepareRender(); + + tess.startDrawing(GL_LINES); + tempColor.prepareColor(); + + double x, y, z; + double offsetSize = 1.0; + + // Zmax XY plane, y axis + z = z2; + y = y1; + int msize = 150; + if ((y2 - y / offsetSize) < msize) + { + for (double yoff = 0; yoff + y <= y2; yoff += offsetSize) + { + tess.addVertex(x1, y + yoff, z); + tess.addVertex(x2, y + yoff, z); + } + } + + // Zmin XY plane, y axis + z = z1; + if ((y2 - y / offsetSize) < msize) + { + for (double yoff = 0; yoff + y <= y2; yoff += offsetSize) + { + tess.addVertex(x1, y + yoff, z); + tess.addVertex(x2, y + yoff, z); + } + } + + // Xmin YZ plane, y axis + x = x1; + if ((y2 - y / offsetSize) < msize) + { + for (double yoff = 0; yoff + y <= y2; yoff += offsetSize) + { + tess.addVertex(x, y + yoff, z1); + tess.addVertex(x, y + yoff, z2); + } + } + + // Xmax YZ plane, y axis + x = x2; + if ((y2 - y / offsetSize) < msize) + { + for (double yoff = 0; yoff + y <= y2; yoff += offsetSize) + { + tess.addVertex(x, y + yoff, z1); + tess.addVertex(x, y + yoff, z2); + } + } + + // Zmin XY plane, x axis + x = x1; + z = z1; + if ((x2 - x / offsetSize) < msize) + { + for (double xoff = 0; xoff + x <= x2; xoff += offsetSize) + { + tess.addVertex(x + xoff, y1, z); + tess.addVertex(x + xoff, y2, z); + } + } + // Zmax XY plane, x axis + z = z2; + if ((x2 - x / offsetSize) < msize) + { + for (double xoff = 0; xoff + x <= x2; xoff += offsetSize) + { + tess.addVertex(x + xoff, y1, z); + tess.addVertex(x + xoff, y2, z); + } + } + // Ymin XZ plane, x axis + y = y2; + if ((x2 - x / offsetSize) < msize) + { + for (double xoff = 0; xoff + x <= x2; xoff += offsetSize) + { + tess.addVertex(x + xoff, y, z1); + tess.addVertex(x + xoff, y, z2); + } + } + // Ymax XZ plane, x axis + y = y1; + if ((x2 - x / offsetSize) < msize) + { + for (double xoff = 0; xoff + x <= x2; xoff += offsetSize) + { + tess.addVertex(x + xoff, y, z1); + tess.addVertex(x + xoff, y, z2); + } + } + + // Ymin XZ plane, z axis + z = z1; + y = y1; + if ((z2 - z / offsetSize) < msize) + { + for (double zoff = 0; zoff + z <= z2; zoff += offsetSize) + { + tess.addVertex(x1, y, z + zoff); + tess.addVertex(x2, y, z + zoff); + } + } + // Ymax XZ plane, z axis + y = y2; + if ((z2 - z / offsetSize) < msize) + { + for (double zoff = 0; zoff + z <= z2; zoff += offsetSize) + { + tess.addVertex(x1, y, z + zoff); + tess.addVertex(x2, y, z + zoff); + } + } + // Xmin YZ plane, z axis + x = x2; + if ((z2 - z / offsetSize) < msize) + { + for (double zoff = 0; zoff + z <= z2; zoff += offsetSize) + { + tess.addVertex(x, y1, z + zoff); + tess.addVertex(x, y2, z + zoff); + } + } + // Xmax YZ plane, z axis + x = x1; + if ((z2 - z / offsetSize) < msize) + { + for (double zoff = 0; zoff + z <= z2; zoff += offsetSize) + { + tess.addVertex(x, y1, z + zoff); + tess.addVertex(x, y2, z + zoff); + } + } + + tess.draw(); + } + } } diff --git a/src/main/java/wecui/render/shapes/Render3DPolygon.java b/src/main/java/wecui/render/shapes/Render3DPolygon.java index a734de46..4ad15a95 100644 --- a/src/main/java/wecui/render/shapes/Render3DPolygon.java +++ b/src/main/java/wecui/render/shapes/Render3DPolygon.java @@ -2,7 +2,7 @@ import net.minecraft.client.renderer.Tessellator; -import org.lwjgl.opengl.GL11; +import static org.lwjgl.opengl.GL11.*; import wecui.render.LineColor; import wecui.render.LineInfo; @@ -14,28 +14,33 @@ * @author yetanotherx * @author lahwran */ -public class Render3DPolygon { - - protected LineColor color; - protected Vector3[] vertices; - - public Render3DPolygon(LineColor color, Vector3... vertices) { - this.color = color; - this.vertices = vertices; - } - - public void render() { - Tessellator tess = Tessellator.instance; - - for (LineInfo tempColor : this.color.getColors()) { - tempColor.prepareRender(); - - tess.startDrawing(GL11.GL_LINE_LOOP); - tempColor.prepareColor(); - for (Vector3 vertex : vertices) { - tess.addVertex(vertex.getX(), vertex.getY(), vertex.getZ()); - } - tess.draw(); - } - } +public class Render3DPolygon +{ + + protected LineColor color; + protected Vector3[] vertices; + + public Render3DPolygon(LineColor color, Vector3... vertices) + { + this.color = color; + this.vertices = vertices; + } + + public void render() + { + Tessellator tess = Tessellator.instance; + + for (LineInfo tempColor : this.color.getColors()) + { + tempColor.prepareRender(); + + tess.startDrawing(GL_LINE_LOOP); + tempColor.prepareColor(); + for (Vector3 vertex : vertices) + { + tess.addVertex(vertex.getX(), vertex.getY(), vertex.getZ()); + } + tess.draw(); + } + } } diff --git a/src/main/java/wecui/render/shapes/RenderCylinderBox.java b/src/main/java/wecui/render/shapes/RenderCylinderBox.java index 6d954aa8..0fe6ff41 100644 --- a/src/main/java/wecui/render/shapes/RenderCylinderBox.java +++ b/src/main/java/wecui/render/shapes/RenderCylinderBox.java @@ -2,7 +2,7 @@ import net.minecraft.client.renderer.Tessellator; -import org.lwjgl.opengl.GL11; +import static org.lwjgl.opengl.GL11.*; import wecui.render.LineColor; import wecui.render.LineInfo; @@ -13,45 +13,51 @@ * * @author yetanotherx */ -public class RenderCylinderBox { - - protected LineColor color; - protected double radX = 0; - protected double radZ = 0; - protected int minY; - protected int maxY; - protected double centerX; - protected double centerZ; - - public RenderCylinderBox(LineColor color, PointCube center, double radX, double radZ, int minY, int maxY) { - this.color = color; - this.radX = radX; - this.radZ = radZ; - this.minY = minY; - this.maxY = maxY; - this.centerX = center.getPoint().getX() + 0.5; - this.centerZ = center.getPoint().getZ() + 0.5; - } - - public void render() { - Tessellator tess = Tessellator.instance; - for (LineInfo tempColor : this.color.getColors()) { - tempColor.prepareRender(); - - double twoPi = Math.PI * 2; - for (int yBlock : new int[]{this.minY, this.maxY + 1}) { - tess.startDrawing(GL11.GL_LINE_LOOP); - tempColor.prepareColor(); - - for (int i = 0; i <= 75; i++) { - double tempTheta = i * twoPi / 75; - double tempX = this.radX * Math.cos(tempTheta); - double tempZ = this.radZ * Math.sin(tempTheta); - - tess.addVertex(this.centerX + tempX, yBlock, this.centerZ + tempZ); - } - tess.draw(); - } - } - } +public class RenderCylinderBox +{ + + protected LineColor color; + protected double radX = 0; + protected double radZ = 0; + protected int minY; + protected int maxY; + protected double centerX; + protected double centerZ; + + public RenderCylinderBox(LineColor color, PointCube center, double radX, double radZ, int minY, int maxY) + { + this.color = color; + this.radX = radX; + this.radZ = radZ; + this.minY = minY; + this.maxY = maxY; + this.centerX = center.getPoint().getX() + 0.5; + this.centerZ = center.getPoint().getZ() + 0.5; + } + + public void render() + { + Tessellator tess = Tessellator.instance; + for (LineInfo tempColor : this.color.getColors()) + { + tempColor.prepareRender(); + + double twoPi = Math.PI * 2; + for (int yBlock : new int[] { this.minY, this.maxY + 1 }) + { + tess.startDrawing(GL_LINE_LOOP); + tempColor.prepareColor(); + + for (int i = 0; i <= 75; i++) + { + double tempTheta = i * twoPi / 75; + double tempX = this.radX * Math.cos(tempTheta); + double tempZ = this.radZ * Math.sin(tempTheta); + + tess.addVertex(this.centerX + tempX, yBlock, this.centerZ + tempZ); + } + tess.draw(); + } + } + } } diff --git a/src/main/java/wecui/render/shapes/RenderCylinderCircles.java b/src/main/java/wecui/render/shapes/RenderCylinderCircles.java index 1ec0aaaf..a6325eb1 100644 --- a/src/main/java/wecui/render/shapes/RenderCylinderCircles.java +++ b/src/main/java/wecui/render/shapes/RenderCylinderCircles.java @@ -2,7 +2,7 @@ import net.minecraft.client.renderer.Tessellator; -import org.lwjgl.opengl.GL11; +import static org.lwjgl.opengl.GL11.*; import wecui.render.LineColor; import wecui.render.LineInfo; @@ -13,45 +13,51 @@ * * @author yetanotherx */ -public class RenderCylinderCircles { - - protected LineColor color; - protected double radX = 0; - protected double radZ = 0; - protected int minY; - protected int maxY; - protected double centerX; - protected double centerZ; - - public RenderCylinderCircles(LineColor color, PointCube center, double radX, double radZ, int minY, int maxY) { - this.color = color; - this.radX = radX; - this.radZ = radZ; - this.minY = minY; - this.maxY = maxY; - this.centerX = center.getPoint().getX() + 0.5; - this.centerZ = center.getPoint().getZ() + 0.5; - } - - public void render() { - Tessellator tess = Tessellator.instance; - for (LineInfo tempColor : this.color.getColors()) { - tempColor.prepareRender(); - - double twoPi = Math.PI * 2; - for (int yBlock = this.minY + 1; yBlock <= this.maxY; yBlock++) { - tess.startDrawing(GL11.GL_LINE_LOOP); - tempColor.prepareColor(); - - for (int i = 0; i <= 75; i++) { - double tempTheta = i * twoPi / 75; - double tempX = this.radX * Math.cos(tempTheta); - double tempZ = this.radZ * Math.sin(tempTheta); - - tess.addVertex(this.centerX + tempX, yBlock, this.centerZ + tempZ); - } - tess.draw(); - } - } - } +public class RenderCylinderCircles +{ + + protected LineColor color; + protected double radX = 0; + protected double radZ = 0; + protected int minY; + protected int maxY; + protected double centerX; + protected double centerZ; + + public RenderCylinderCircles(LineColor color, PointCube center, double radX, double radZ, int minY, int maxY) + { + this.color = color; + this.radX = radX; + this.radZ = radZ; + this.minY = minY; + this.maxY = maxY; + this.centerX = center.getPoint().getX() + 0.5; + this.centerZ = center.getPoint().getZ() + 0.5; + } + + public void render() + { + Tessellator tess = Tessellator.instance; + for (LineInfo tempColor : this.color.getColors()) + { + tempColor.prepareRender(); + + double twoPi = Math.PI * 2; + for (int yBlock = this.minY + 1; yBlock <= this.maxY; yBlock++) + { + tess.startDrawing(GL_LINE_LOOP); + tempColor.prepareColor(); + + for (int i = 0; i <= 75; i++) + { + double tempTheta = i * twoPi / 75; + double tempX = this.radX * Math.cos(tempTheta); + double tempZ = this.radZ * Math.sin(tempTheta); + + tess.addVertex(this.centerX + tempX, yBlock, this.centerZ + tempZ); + } + tess.draw(); + } + } + } } diff --git a/src/main/java/wecui/render/shapes/RenderCylinderGrid.java b/src/main/java/wecui/render/shapes/RenderCylinderGrid.java index b8b1ef02..a2da9029 100644 --- a/src/main/java/wecui/render/shapes/RenderCylinderGrid.java +++ b/src/main/java/wecui/render/shapes/RenderCylinderGrid.java @@ -2,7 +2,7 @@ import net.minecraft.client.renderer.Tessellator; -import org.lwjgl.opengl.GL11; +import static org.lwjgl.opengl.GL11.*; import wecui.render.LineColor; import wecui.render.LineInfo; @@ -13,63 +13,69 @@ * * @author yetanotherx */ -public class RenderCylinderGrid { - - protected LineColor color; - protected double radX = 0; - protected double radZ = 0; - protected int minY; - protected int maxY; - protected double centerX; - protected double centerZ; - - public RenderCylinderGrid(LineColor color, PointCube center, double radX, double radZ, int minY, int maxY) { - this.color = color; - this.radX = radX; - this.radZ = radZ; - this.minY = minY; - this.maxY = maxY; - this.centerX = center.getPoint().getX() + 0.5; - this.centerZ = center.getPoint().getZ() + 0.5; - } - - public void render() { - Tessellator tess = Tessellator.instance; - for (LineInfo tempColor : this.color.getColors()) { - tempColor.prepareRender(); - - int tmaxY = this.maxY + 1; - int tminY = this.minY; - int posRadiusX = (int) Math.ceil(this.radX); - int negRadiusX = (int) -Math.ceil(this.radX); - int posRadiusZ = (int) Math.ceil(this.radZ); - int negRadiusZ = (int) -Math.ceil(this.radZ); - - for (double tempX = negRadiusX; tempX <= posRadiusX; ++tempX) { - double tempZ = this.radZ * Math.cos(Math.asin(tempX / this.radX)); - tess.startDrawing(GL11.GL_LINE_LOOP); - tempColor.prepareColor(); - - tess.addVertex(this.centerX + tempX, tmaxY, this.centerZ + tempZ); - tess.addVertex(this.centerX + tempX, tmaxY, this.centerZ - tempZ); - tess.addVertex(this.centerX + tempX, tminY, this.centerZ - tempZ); - tess.addVertex(this.centerX + tempX, tminY, this.centerZ + tempZ); - - tess.draw(); - } - - for (double tempZ = negRadiusZ; tempZ <= posRadiusZ; ++tempZ) { - double tempX = this.radX * Math.sin(Math.acos(tempZ / this.radZ)); - tess.startDrawing(GL11.GL_LINE_LOOP); - tempColor.prepareColor(); - - tess.addVertex(this.centerX + tempX, tmaxY, this.centerZ + tempZ); - tess.addVertex(this.centerX - tempX, tmaxY, this.centerZ + tempZ); - tess.addVertex(this.centerX - tempX, tminY, this.centerZ + tempZ); - tess.addVertex(this.centerX + tempX, tminY, this.centerZ + tempZ); - - tess.draw(); - } - } - } +public class RenderCylinderGrid +{ + + protected LineColor color; + protected double radX = 0; + protected double radZ = 0; + protected int minY; + protected int maxY; + protected double centerX; + protected double centerZ; + + public RenderCylinderGrid(LineColor color, PointCube center, double radX, double radZ, int minY, int maxY) + { + this.color = color; + this.radX = radX; + this.radZ = radZ; + this.minY = minY; + this.maxY = maxY; + this.centerX = center.getPoint().getX() + 0.5; + this.centerZ = center.getPoint().getZ() + 0.5; + } + + public void render() + { + Tessellator tess = Tessellator.instance; + for (LineInfo tempColor : this.color.getColors()) + { + tempColor.prepareRender(); + + int tmaxY = this.maxY + 1; + int tminY = this.minY; + int posRadiusX = (int)Math.ceil(this.radX); + int negRadiusX = (int)-Math.ceil(this.radX); + int posRadiusZ = (int)Math.ceil(this.radZ); + int negRadiusZ = (int)-Math.ceil(this.radZ); + + for (double tempX = negRadiusX; tempX <= posRadiusX; ++tempX) + { + double tempZ = this.radZ * Math.cos(Math.asin(tempX / this.radX)); + tess.startDrawing(GL_LINE_LOOP); + tempColor.prepareColor(); + + tess.addVertex(this.centerX + tempX, tmaxY, this.centerZ + tempZ); + tess.addVertex(this.centerX + tempX, tmaxY, this.centerZ - tempZ); + tess.addVertex(this.centerX + tempX, tminY, this.centerZ - tempZ); + tess.addVertex(this.centerX + tempX, tminY, this.centerZ + tempZ); + + tess.draw(); + } + + for (double tempZ = negRadiusZ; tempZ <= posRadiusZ; ++tempZ) + { + double tempX = this.radX * Math.sin(Math.acos(tempZ / this.radZ)); + tess.startDrawing(GL_LINE_LOOP); + tempColor.prepareColor(); + + tess.addVertex(this.centerX + tempX, tmaxY, this.centerZ + tempZ); + tess.addVertex(this.centerX - tempX, tmaxY, this.centerZ + tempZ); + tess.addVertex(this.centerX - tempX, tminY, this.centerZ + tempZ); + tess.addVertex(this.centerX + tempX, tminY, this.centerZ + tempZ); + + tess.draw(); + } + } + } } diff --git a/src/main/java/wecui/render/shapes/RenderEllipsoid.java b/src/main/java/wecui/render/shapes/RenderEllipsoid.java index 885bd9e9..10a4a470 100644 --- a/src/main/java/wecui/render/shapes/RenderEllipsoid.java +++ b/src/main/java/wecui/render/shapes/RenderEllipsoid.java @@ -2,7 +2,7 @@ import net.minecraft.client.renderer.Tessellator; -import org.lwjgl.opengl.GL11; +import static org.lwjgl.opengl.GL11.*; import wecui.render.LineColor; import wecui.render.LineInfo; @@ -14,121 +14,137 @@ * * @author yetanotherx */ -public class RenderEllipsoid { - - protected LineColor color; - protected PointCube center; - protected Vector3 radii; - protected final static double twoPi = Math.PI * 2; - protected double centerX; - protected double centerY; - protected double centerZ; - - public RenderEllipsoid(LineColor color, PointCube center, Vector3 radii) { - this.color = color; - this.center = center; - this.radii = radii; - this.centerX = center.getPoint().getX() + 0.5; - this.centerY = center.getPoint().getY() + 0.5; - this.centerZ = center.getPoint().getZ() + 0.5; - } - - public void render() { - for (LineInfo tempColor : this.color.getColors()) { - tempColor.prepareRender(); - this.drawXZPlane(tempColor); - this.drawYZPlane(tempColor); - this.drawXYPlane(tempColor); - } - } - - protected void drawXZPlane(LineInfo color) { - Tessellator tess = Tessellator.instance; - int yRad = (int) Math.floor(this.radii.getY()); - for (int yBlock = -yRad; yBlock < yRad; yBlock++) { - tess.startDrawing(GL11.GL_LINE_LOOP); - color.prepareColor(); - - for (int i = 0; i <= 40; i++) { - double tempTheta = i * twoPi / 40; - double tempX = this.radii.getX() * Math.cos(tempTheta) * Math.cos(Math.asin(yBlock / this.radii.getY())); - double tempZ = this.radii.getZ() * Math.sin(tempTheta) * Math.cos(Math.asin(yBlock / this.radii.getY())); - - tess.addVertex(this.centerX + tempX, this.centerY + yBlock, this.centerZ + tempZ); - } - tess.draw(); - } - - tess.startDrawing(GL11.GL_LINE_LOOP); - color.prepareColor(); - - for (int i = 0; i <= 40; i++) { - double tempTheta = i * twoPi / 40; - double tempX = this.radii.getX() * Math.cos(tempTheta); - double tempZ = this.radii.getZ() * Math.sin(tempTheta); - - tess.addVertex(this.centerX + tempX, this.centerY, this.centerZ + tempZ); - } - tess.draw(); - } - - protected void drawYZPlane(LineInfo color) { - Tessellator tess = Tessellator.instance; - int xRad = (int) Math.floor(this.radii.getX()); - for (int xBlock = -xRad; xBlock < xRad; xBlock++) { - tess.startDrawing(GL11.GL_LINE_LOOP); - color.prepareColor(); - - for (int i = 0; i <= 40; i++) { - double tempTheta = i * twoPi / 40; - double tempY = this.radii.getY() * Math.cos(tempTheta) * Math.sin(Math.acos(xBlock / this.radii.getX())); - double tempZ = this.radii.getZ() * Math.sin(tempTheta) * Math.sin(Math.acos(xBlock / this.radii.getX())); - - tess.addVertex(this.centerX + xBlock, this.centerY + tempY, this.centerZ + tempZ); - } - tess.draw(); - } - - tess.startDrawing(GL11.GL_LINE_LOOP); - color.prepareColor(); - - for (int i = 0; i <= 40; i++) { - double tempTheta = i * twoPi / 40; - double tempY = this.radii.getY() * Math.cos(tempTheta); - double tempZ = this.radii.getZ() * Math.sin(tempTheta); - - tess.addVertex(this.centerX, this.centerY + tempY, this.centerZ + tempZ); - } - tess.draw(); - } - - protected void drawXYPlane(LineInfo color) { - Tessellator tess = Tessellator.instance; - int zRad = (int) Math.floor(this.radii.getZ()); - for (int zBlock = -zRad; zBlock < zRad; zBlock++) { - tess.startDrawing(GL11.GL_LINE_LOOP); - color.prepareColor(); - - for (int i = 0; i <= 40; i++) { - double tempTheta = i * twoPi / 40; - double tempX = this.radii.getX() * Math.sin(tempTheta) * Math.sin(Math.acos(zBlock / this.radii.getZ())); - double tempY = this.radii.getY() * Math.cos(tempTheta) * Math.sin(Math.acos(zBlock / this.radii.getZ())); - - tess.addVertex(this.centerX + tempX, this.centerY + tempY, this.centerZ + zBlock); - } - tess.draw(); - } - - tess.startDrawing(GL11.GL_LINE_LOOP); - color.prepareColor(); - - for (int i = 0; i <= 40; i++) { - double tempTheta = i * twoPi / 40; - double tempX = this.radii.getX() * Math.cos(tempTheta); - double tempY = this.radii.getY() * Math.sin(tempTheta); - - tess.addVertex(this.centerX + tempX, this.centerY + tempY, this.centerZ); - } - tess.draw(); - } +public class RenderEllipsoid +{ + + protected LineColor color; + protected PointCube center; + protected Vector3 radii; + protected final static double twoPi = Math.PI * 2; + protected double centerX; + protected double centerY; + protected double centerZ; + + public RenderEllipsoid(LineColor color, PointCube center, Vector3 radii) + { + this.color = color; + this.center = center; + this.radii = radii; + this.centerX = center.getPoint().getX() + 0.5; + this.centerY = center.getPoint().getY() + 0.5; + this.centerZ = center.getPoint().getZ() + 0.5; + } + + public void render() + { + for (LineInfo tempColor : this.color.getColors()) + { + tempColor.prepareRender(); + this.drawXZPlane(tempColor); + this.drawYZPlane(tempColor); + this.drawXYPlane(tempColor); + } + } + + protected void drawXZPlane(LineInfo color) + { + Tessellator tess = Tessellator.instance; + int yRad = (int)Math.floor(this.radii.getY()); + for (int yBlock = -yRad; yBlock < yRad; yBlock++) + { + tess.startDrawing(GL_LINE_LOOP); + color.prepareColor(); + + for (int i = 0; i <= 40; i++) + { + double tempTheta = i * twoPi / 40; + double tempX = this.radii.getX() * Math.cos(tempTheta) * Math.cos(Math.asin(yBlock / this.radii.getY())); + double tempZ = this.radii.getZ() * Math.sin(tempTheta) * Math.cos(Math.asin(yBlock / this.radii.getY())); + + tess.addVertex(this.centerX + tempX, this.centerY + yBlock, this.centerZ + tempZ); + } + tess.draw(); + } + + tess.startDrawing(GL_LINE_LOOP); + color.prepareColor(); + + for (int i = 0; i <= 40; i++) + { + double tempTheta = i * twoPi / 40; + double tempX = this.radii.getX() * Math.cos(tempTheta); + double tempZ = this.radii.getZ() * Math.sin(tempTheta); + + tess.addVertex(this.centerX + tempX, this.centerY, this.centerZ + tempZ); + } + tess.draw(); + } + + protected void drawYZPlane(LineInfo color) + { + Tessellator tess = Tessellator.instance; + int xRad = (int)Math.floor(this.radii.getX()); + for (int xBlock = -xRad; xBlock < xRad; xBlock++) + { + tess.startDrawing(GL_LINE_LOOP); + color.prepareColor(); + + for (int i = 0; i <= 40; i++) + { + double tempTheta = i * twoPi / 40; + double tempY = this.radii.getY() * Math.cos(tempTheta) * Math.sin(Math.acos(xBlock / this.radii.getX())); + double tempZ = this.radii.getZ() * Math.sin(tempTheta) * Math.sin(Math.acos(xBlock / this.radii.getX())); + + tess.addVertex(this.centerX + xBlock, this.centerY + tempY, this.centerZ + tempZ); + } + tess.draw(); + } + + tess.startDrawing(GL_LINE_LOOP); + color.prepareColor(); + + for (int i = 0; i <= 40; i++) + { + double tempTheta = i * twoPi / 40; + double tempY = this.radii.getY() * Math.cos(tempTheta); + double tempZ = this.radii.getZ() * Math.sin(tempTheta); + + tess.addVertex(this.centerX, this.centerY + tempY, this.centerZ + tempZ); + } + tess.draw(); + } + + protected void drawXYPlane(LineInfo color) + { + Tessellator tess = Tessellator.instance; + int zRad = (int)Math.floor(this.radii.getZ()); + for (int zBlock = -zRad; zBlock < zRad; zBlock++) + { + tess.startDrawing(GL_LINE_LOOP); + color.prepareColor(); + + for (int i = 0; i <= 40; i++) + { + double tempTheta = i * twoPi / 40; + double tempX = this.radii.getX() * Math.sin(tempTheta) * Math.sin(Math.acos(zBlock / this.radii.getZ())); + double tempY = this.radii.getY() * Math.cos(tempTheta) * Math.sin(Math.acos(zBlock / this.radii.getZ())); + + tess.addVertex(this.centerX + tempX, this.centerY + tempY, this.centerZ + zBlock); + } + tess.draw(); + } + + tess.startDrawing(GL_LINE_LOOP); + color.prepareColor(); + + for (int i = 0; i <= 40; i++) + { + double tempTheta = i * twoPi / 40; + double tempX = this.radii.getX() * Math.cos(tempTheta); + double tempY = this.radii.getY() * Math.sin(tempTheta); + + tess.addVertex(this.centerX + tempX, this.centerY + tempY, this.centerZ); + } + tess.draw(); + } } diff --git a/src/main/java/wecui/util/ChatColor.java b/src/main/java/wecui/util/ChatColor.java deleted file mode 100644 index ef2c6b4c..00000000 --- a/src/main/java/wecui/util/ChatColor.java +++ /dev/null @@ -1,127 +0,0 @@ -package wecui.util; - -import java.util.HashMap; -import java.util.Map; - -/** - * All supported color values for chat - * - * @author bukkit - */ -public enum ChatColor { - - /** - * Represents black - */ - BLACK(0x0), - /** - * Represents dark blue - */ - DARK_BLUE(0x1), - /** - * Represents dark green - */ - DARK_GREEN(0x2), - /** - * Represents dark blue (aqua) - */ - DARK_AQUA(0x3), - /** - * Represents dark red - */ - DARK_RED(0x4), - /** - * Represents dark purple - */ - DARK_PURPLE(0x5), - /** - * Represents gold - */ - GOLD(0x6), - /** - * Represents gray - */ - GRAY(0x7), - /** - * Represents dark gray - */ - DARK_GRAY(0x8), - /** - * Represents blue - */ - BLUE(0x9), - /** - * Represents green - */ - GREEN(0xA), - /** - * Represents aqua - */ - AQUA(0xB), - /** - * Represents red - */ - RED(0xC), - /** - * Represents light purple - */ - LIGHT_PURPLE(0xD), - /** - * Represents yellow - */ - YELLOW(0xE), - /** - * Represents white - */ - WHITE(0xF); - private final int code; - private final static Map colors = new HashMap(); - - private ChatColor(final int code) { - this.code = code; - } - - /** - * Gets the data value associated with this color - * - * @return An integer value of this color code - */ - public int getCode() { - return this.code; - } - - @Override - public String toString() { - return String.format("\u00A7%x", this.code); - } - - /** - * Gets the color represented by the specified color code - * - * @param code Code to check - * @return Associative {@link org.bukkit.ChatColor} with the given code, or null if it doesn't exist - */ - public static ChatColor getByCode(final int code) { - return colors.get(code); - } - - /** - * Strips the given message of all color codes - * - * @param input String to strip of color - * @return A copy of the input string, without any coloring - */ - public static String stripColor(final String input) { - if (input == null) { - return null; - } - - return input.replaceAll("(?i)\u00A7[0-9A-F]", ""); - } - - static { - for (ChatColor color : ChatColor.values()) { - colors.put(color.getCode(), color); - } - } -} diff --git a/src/main/java/wecui/util/ConsoleLogFormatter.java b/src/main/java/wecui/util/ConsoleLogFormatter.java index 792fa8af..694b6980 100644 --- a/src/main/java/wecui/util/ConsoleLogFormatter.java +++ b/src/main/java/wecui/util/ConsoleLogFormatter.java @@ -14,44 +14,60 @@ * TODO: Necessary anymore? * @author Mojang */ -public class ConsoleLogFormatter extends Formatter { - - private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - - @Override - public String format(LogRecord logrecord) { - StringBuilder stringbuilder = new StringBuilder(); - - stringbuilder.append(this.format.format(Long.valueOf(logrecord.getMillis()))); - Level level = logrecord.getLevel(); - - if (level == Level.FINEST) { - stringbuilder.append(" [FINEST] "); - } else if (level == Level.FINER) { - stringbuilder.append(" [FINER] "); - } else if (level == Level.FINE) { - stringbuilder.append(" [FINE] "); - } else if (level == Level.INFO) { - stringbuilder.append(" [INFO] "); - } else if (level == Level.WARNING) { - stringbuilder.append(" [WARNING] "); - } else if (level == Level.SEVERE) { - stringbuilder.append(" [SEVERE] "); - } else { - stringbuilder.append(" [").append(level.getLocalizedName()).append("] "); - } - - stringbuilder.append(logrecord.getMessage()); - stringbuilder.append('\n'); - Throwable throwable = logrecord.getThrown(); - - if (throwable != null) { - StringWriter stringwriter = new StringWriter(); - - throwable.printStackTrace(new PrintWriter(stringwriter)); - stringbuilder.append(stringwriter.toString()); - } - - return stringbuilder.toString(); - } -} \ No newline at end of file +public class ConsoleLogFormatter extends Formatter +{ + + private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + @Override + public String format(LogRecord logrecord) + { + StringBuilder stringbuilder = new StringBuilder(); + + stringbuilder.append(this.format.format(Long.valueOf(logrecord.getMillis()))); + Level level = logrecord.getLevel(); + + if (level == Level.FINEST) + { + stringbuilder.append(" [FINEST] "); + } + else if (level == Level.FINER) + { + stringbuilder.append(" [FINER] "); + } + else if (level == Level.FINE) + { + stringbuilder.append(" [FINE] "); + } + else if (level == Level.INFO) + { + stringbuilder.append(" [INFO] "); + } + else if (level == Level.WARNING) + { + stringbuilder.append(" [WARNING] "); + } + else if (level == Level.SEVERE) + { + stringbuilder.append(" [SEVERE] "); + } + else + { + stringbuilder.append(" [").append(level.getLocalizedName()).append("] "); + } + + stringbuilder.append(logrecord.getMessage()); + stringbuilder.append('\n'); + Throwable throwable = logrecord.getThrown(); + + if (throwable != null) + { + StringWriter stringwriter = new StringWriter(); + + throwable.printStackTrace(new PrintWriter(stringwriter)); + stringbuilder.append(stringwriter.toString()); + } + + return stringbuilder.toString(); + } +} diff --git a/src/main/java/wecui/util/Utilities.java b/src/main/java/wecui/util/Utilities.java index 1e64a7de..844c275c 100644 --- a/src/main/java/wecui/util/Utilities.java +++ b/src/main/java/wecui/util/Utilities.java @@ -8,133 +8,146 @@ * @author yetanotherx * @author Apache Commons */ -public class Utilities { - - // Joining - //----------------------------------------------------------------------- - /** - *

Joins the elements of the provided array into a single String - * containing the provided list of elements.

- * - *

No separator is added to the joined String. - * Null objects or empty strings within the array are represented by - * empty strings.

- * - *
-     * StringUtils.join(null)            = null
-     * StringUtils.join([])              = ""
-     * StringUtils.join([null])          = ""
-     * StringUtils.join(["a", "b", "c"]) = "abc"
-     * StringUtils.join([null, "", "a"]) = "a"
-     * 
- * - * @param the specific type of values to join together - * @param elements the values to join together, may be null - * @return the joined String, {@code null} if null array input - * @since 2.0 - * @since 3.0 Changed signature to use varargs - */ - public static String join(T... elements) { - return join(elements, null); - } - - /** - *

Joins the elements of the provided array into a single String - * containing the provided list of elements.

- * - *

No delimiter is added before or after the list. - * A {@code null} separator is the same as an empty String (""). - * Null objects or empty strings within the array are represented by - * empty strings.

- * - *
-     * StringUtils.join(null, *)                = null
-     * StringUtils.join([], *)                  = ""
-     * StringUtils.join([null], *)              = ""
-     * StringUtils.join(["a", "b", "c"], "--")  = "a--b--c"
-     * StringUtils.join(["a", "b", "c"], null)  = "abc"
-     * StringUtils.join(["a", "b", "c"], "")    = "abc"
-     * StringUtils.join([null, "", "a"], ',')   = ",,a"
-     * 
- * - * @param array the array of values to join together, may be null - * @param separator the separator character to use, null treated as "" - * @return the joined String, {@code null} if null array input - */ - public static String join(Object[] array, String separator) { - if (array == null) { - return null; - } - return join(array, separator, 0, array.length); - } - - /** - *

Joins the elements of the provided array into a single String - * containing the provided list of elements.

- * - *

No delimiter is added before or after the list. - * A {@code null} separator is the same as an empty String (""). - * Null objects or empty strings within the array are represented by - * empty strings.

- * - *
-     * StringUtils.join(null, *)                = null
-     * StringUtils.join([], *)                  = ""
-     * StringUtils.join([null], *)              = ""
-     * StringUtils.join(["a", "b", "c"], "--")  = "a--b--c"
-     * StringUtils.join(["a", "b", "c"], null)  = "abc"
-     * StringUtils.join(["a", "b", "c"], "")    = "abc"
-     * StringUtils.join([null, "", "a"], ',')   = ",,a"
-     * 
- * - * @param array the array of values to join together, may be null - * @param separator the separator character to use, null treated as "" - * @param startIndex the first index to start joining from. It is - * an error to pass in an end index past the end of the array - * @param endIndex the index to stop joining from (exclusive). It is - * an error to pass in an end index past the end of the array - * @return the joined String, {@code null} if null array input - */ - public static String join(Object[] array, String separator, int startIndex, int endIndex) { - if (array == null) { - return null; - } - if (separator == null) { - separator = ""; - } - - // endIndex - startIndex > 0: Len = NofStrings *(len(firstString) + len(separator)) - // (Assuming that all Strings are roughly equally long) - int noOfItems = endIndex - startIndex; - if (noOfItems <= 0) { - return ""; - } - - StringBuilder buf = new StringBuilder(noOfItems * 16); - - for (int i = startIndex; i < endIndex; i++) { - if (i > startIndex) { - buf.append(separator); - } - if (array[i] != null) { - buf.append(array[i]); - } - } - return buf.toString(); - } - - /** - * Creates a pretty representation of a Map - * @param map - * @return - */ - public static String debugMap(Map map) { - StringBuilder build = new StringBuilder(); - - for (Object key : map.keySet()) { - build.append(key.toString()).append(" - ").append(map.get(key).toString()).append("\n"); - } - - return build.toString(); - } +public class Utilities +{ + + // Joining + //----------------------------------------------------------------------- + /** + *

Joins the elements of the provided array into a single String + * containing the provided list of elements.

+ * + *

No separator is added to the joined String. + * Null objects or empty strings within the array are represented by + * empty strings.

+ * + *
+	 * StringUtils.join(null)            = null
+	 * StringUtils.join([])              = ""
+	 * StringUtils.join([null])          = ""
+	 * StringUtils.join(["a", "b", "c"]) = "abc"
+	 * StringUtils.join([null, "", "a"]) = "a"
+	 * 
+ * + * @param the specific type of values to join together + * @param elements the values to join together, may be null + * @return the joined String, {@code null} if null array input + * @since 2.0 + * @since 3.0 Changed signature to use varargs + */ + public static String join(T... elements) + { + return join(elements, null); + } + + /** + *

Joins the elements of the provided array into a single String + * containing the provided list of elements.

+ * + *

No delimiter is added before or after the list. + * A {@code null} separator is the same as an empty String (""). + * Null objects or empty strings within the array are represented by + * empty strings.

+ * + *
+	 * StringUtils.join(null, *)                = null
+	 * StringUtils.join([], *)                  = ""
+	 * StringUtils.join([null], *)              = ""
+	 * StringUtils.join(["a", "b", "c"], "--")  = "a--b--c"
+	 * StringUtils.join(["a", "b", "c"], null)  = "abc"
+	 * StringUtils.join(["a", "b", "c"], "")    = "abc"
+	 * StringUtils.join([null, "", "a"], ',')   = ",,a"
+	 * 
+ * + * @param array the array of values to join together, may be null + * @param separator the separator character to use, null treated as "" + * @return the joined String, {@code null} if null array input + */ + public static String join(Object[] array, String separator) + { + if (array == null) + { + return null; + } + return join(array, separator, 0, array.length); + } + + /** + *

Joins the elements of the provided array into a single String + * containing the provided list of elements.

+ * + *

No delimiter is added before or after the list. + * A {@code null} separator is the same as an empty String (""). + * Null objects or empty strings within the array are represented by + * empty strings.

+ * + *
+	 * StringUtils.join(null, *)                = null
+	 * StringUtils.join([], *)                  = ""
+	 * StringUtils.join([null], *)              = ""
+	 * StringUtils.join(["a", "b", "c"], "--")  = "a--b--c"
+	 * StringUtils.join(["a", "b", "c"], null)  = "abc"
+	 * StringUtils.join(["a", "b", "c"], "")    = "abc"
+	 * StringUtils.join([null, "", "a"], ',')   = ",,a"
+	 * 
+ * + * @param array the array of values to join together, may be null + * @param separator the separator character to use, null treated as "" + * @param startIndex the first index to start joining from. It is + * an error to pass in an end index past the end of the array + * @param endIndex the index to stop joining from (exclusive). It is + * an error to pass in an end index past the end of the array + * @return the joined String, {@code null} if null array input + */ + public static String join(Object[] array, String separator, int startIndex, int endIndex) + { + if (array == null) + { + return null; + } + if (separator == null) + { + separator = ""; + } + + // endIndex - startIndex > 0: Len = NofStrings *(len(firstString) + len(separator)) + // (Assuming that all Strings are roughly equally long) + int noOfItems = endIndex - startIndex; + if (noOfItems <= 0) + { + return ""; + } + + StringBuilder buf = new StringBuilder(noOfItems * 16); + + for (int i = startIndex; i < endIndex; i++) + { + if (i > startIndex) + { + buf.append(separator); + } + if (array[i] != null) + { + buf.append(array[i]); + } + } + return buf.toString(); + } + + /** + * Creates a pretty representation of a Map + * @param map + * @return + */ + public static String debugMap(Map map) + { + StringBuilder build = new StringBuilder(); + + for (Object key : map.keySet()) + { + build.append(key.toString()).append(" - ").append(map.get(key).toString()).append("\n"); + } + + return build.toString(); + } } diff --git a/src/main/java/wecui/util/Vector2.java b/src/main/java/wecui/util/Vector2.java index 362e3896..cc9970d8 100644 --- a/src/main/java/wecui/util/Vector2.java +++ b/src/main/java/wecui/util/Vector2.java @@ -6,555 +6,609 @@ * Note, this is the Immutable form of Vector2. All operations will construct a * new Vector2. */ -public class Vector2 implements Comparable { - - /** - * Represents the Zero vector (0,0) - */ - public final static Vector2 ZERO = new Vector2(0, 0); - /** - * Represents a unit vector in the X direction (1,0) - */ - public final static Vector2 UNIT_X = new Vector2(1, 0); - /** - * Represents a unit vector in the Y direction (0,1) - */ - public final static Vector2 UNIT_Y = new Vector2(0, 1); - /** - * Represents a unit vector (1,1) - */ - public static Vector2 ONE = new Vector2(1, 1); - protected float x, z; - - /** - * Construct and Initialized a Vector2 from the given x, y - * - * @param x the x coordinate - * @param y the y coordinate - */ - public Vector2(float x, float y) { - this.x = x; - this.z = y; - } - - /** - * Construct and Initialized a Vector2 from the given x, y - * - * @param x the x coordinate - * @param y the y coordinate - */ - public Vector2(Double x, Double y) { - this(x.floatValue(), y.floatValue()); - } - - /** - * Construct and Initialized a Vector2 to (0,0) - */ - public Vector2() { - this(0, 0); - } - - /** - * Construct and Initialized a Vector2 from an old Vector2 - * - * @param original - */ - public Vector2(Vector2 original) { - this(original.x, original.z); - } - - /** - * Gets the X coordiante - * - * @return The X coordinate - */ - public float getX() { - return this.x; - } - - /** - * Gets the Y coordiante - * - * @return The Y coordinate - */ - public float getY() { - return this.z; - } - - /** - * Adds this Vector2 to the value of the Vector2 argument - * - * @param that The Vector2 to add - * @return the new Vector2 - */ - public Vector2 add(Vector2 that) { - return Vector2.add(this, that); - } - - /** - * Subtracts this Vector2 to the value of the Vector2 argument - * - * @param that The Vector2 to subtract - * @return the new Vector2 - */ - public Vector2 subtract(Vector2 that) { - return Vector2.subtract(this, that); - } - - /** - * Scales this Vector2 by the value of the argument - * - * @param scale The amount to scale by - * @return A new Vector2 scaled by the amount. - */ - public Vector2 scale(float scale) { - return Vector2.scale(this, scale); - } - - /** - * Returns this Vector2 dot the Vector2 argument. Dot Product is defined as - * a.x*b.x + a.y*b.y - * - * @param that The Vector2 to dot with this. - * @return The dot product - */ - public float dot(Vector2 that) { - return Vector2.dot(this, that); - } - - /** - * Returns a Vector3 object with a y-value of 0. - * The x of this Vector2 becomes the x of the Vector3, - * the y of this Vector2 becomes the z of the Vector3. - * - * @return - */ - public Vector3 toVector3() { - return Vector2.toVector3(this); - } - - /** - * Returns a Vector3m object with a y-value of 0. - * The x of this Vector2 becomes the x of the Vector3m, - * the y of this Vector2 becomes the z of the Vector3m. - * - * @return - */ - public Vector3m toVector3m() { - return Vector2.toVector3m(this); - } - - /** - * Returns a Vector3 object with the given y value. - * The x of this Vector2 becomes the x of the Vector3, - * the y of this Vector2 becomes the z of the Vector3. - * - * @param y Y value to use in the new Vector3. - * @return - */ - public Vector3 toVector3(float y) { - return Vector2.toVector3(this, y); - } - - /** - * Returns a Vector3m object with the given y value. - * The x of this Vector2 becomes the x of the Vector3m, - * the y of this Vector2 becomes the z of the Vector3m. - * - * @param y Y value to use in the new Vector3m. - * @return - */ - public Vector3m toVector3m(float y) { - return Vector2.toVector3m(this, y); - } - - /** - * Returns the Cross Product of this Vector2 Note: Cross Product is - * undefined in 2d space. This returns the orthogonal vector to this vector - * - * @return The orthogonal vector to this vector. - */ - public Vector2 cross() { - return new Vector2(this.z, -this.x); - } - - /** - * Rounds the X and Y values of this Vector2 up to - * the nearest integer value. - * - * @return - */ - public Vector2 ceil() { - return new Vector2(Math.ceil(this.x), Math.ceil(this.z)); - } - - /** - * Rounds the X and Y values of this Vector2 down to - * the nearest integer value. - * - * @return - */ - public Vector2 floor() { - return new Vector2(Math.floor(this.x), Math.floor(this.z)); - } - - /** - * Rounds the X and Y values of this Vector2 to - * the nearest integer value. - * - * @return - */ - public Vector2 round() { - return new Vector2(Math.round(this.x), Math.round(this.z)); - } - - /** - * Sets the X and Y values of this Vector2 to their - * absolute value. - * - * @return - */ - public Vector2 abs() { - return new Vector2(Math.abs(this.x), Math.abs(this.z)); - } - - /** - * Gets the distance between this Vector2 and a given Vector2. - * - * @param a - * @return - */ - public double distance(Vector2 a) { - return Vector2.distance(a, this); - } - - /** - * Raises the X and Y values of this Vector2 to the given power. - * - * @param power - * @return - */ - public Vector2 pow(double power) { - return Vector2.pow(this, power); - } - - /** - * Calculates the length of this Vector2 squared. - * - * @return the squared length - */ - public float lengthSquared() { - return Vector2.lengthSquared(this); - } - - /** - * Calculates the length of this Vector2 Note: This makes use of the sqrt - * function, and is not cached. That could affect performance - * - * @return the length of this vector2 - */ - public float length() { - return Vector2.length(this); - } - - /** - * Returns this Vector2 where the length is equal to 1 - * - * @return This Vector2 with length 1 - */ - public Vector2 normalize() { - return Vector2.normalize(this); - } - - /** - * Returns this Vector2 in an array. Element 0 contains x Element 1 contains - * y - * - * @return The array containing this Vector2 - */ - public float[] toArray() { - return Vector2.toArray(this); - } - - /** - * Compares two Vector3s - */ - @Override - public int compareTo(Vector2 o) { - return Vector2.compareTo(this, o); - } - - /** - * Checks if two Vector2s are equal - */ - @Override - public boolean equals(Object o) { - return Vector2.equals(this, o); - } - - /** - * Returns the length of the provided Vector2 Note: This makes use of the - * sqrt function, and is not cached. This could affect performance. - * - * @param a The Vector2 to calculate the length of - * @return The length of the Vector2 - */ - public static float length(Vector2 a) { - return (float) Math.sqrt(lengthSquared(a)); - } - - /** - * Returns the length squared of the provided Vector2 - * - * @param a the Vector2 to calculate the length squared - * @return the length squared of the Vector2 - */ - public static float lengthSquared(Vector2 a) { - return Vector2.dot(a, a); - } - - /** - * Returns a Vector2 that is the unit form of the provided Vector2 - * - * @param a - * @return - */ - public static Vector2 normalize(Vector2 a) { - return Vector2.scale(a, (1.f / a.length())); - } - - /** - * Subtracts one Vector2 from the other Vector2 - * - * @param a - * @param b - * @return - */ - public static Vector2 subtract(Vector2 a, Vector2 b) { - return new Vector2(a.getX() - b.getX(), a.getY() - b.getY()); - } - - /** - * Adds one Vector2 to the other Vector2 - * - * @param a - * @param b - * @return - */ - public static Vector2 add(Vector2 a, Vector2 b) { - return new Vector2(a.getX() + b.getX(), a.getY() + b.getY()); - } - - /** - * Scales the Vector2 by the ammount - * - * @param a - * @param b - * @return - */ - public static Vector2 scale(Vector2 a, float b) { - return new Vector2(a.getX() * b, a.getY() * b); - } - - /** - * Calculates the Dot Product of two Vector2s Dot Product is defined as - * a.x*b.x + a.y*b.y - * - * @param a - * @param b - * @return - */ - public static float dot(Vector2 a, Vector2 b) { - return a.getX() * b.getX() + a.getY() * b.getY(); - } - - /** - * Returns a Vector3 object with a y-value of 0. - * The x of the Vector2 becomes the x of the Vector3, - * the y of the Vector2 becomes the z of the Vector3. - * - * @param o Vector2 to use as the x/z values - * @return - */ - public static Vector3 toVector3(Vector2 o) { - return new Vector3(o.x, 0, o.z); - } - - /** - * Returns a Vector3m object with a y-value of 0. - * The x of the Vector2 becomes the x of the Vector3m, - * the y of the Vector2 becomes the z of the Vector3m. - * - * @param o Vector2 to use as the x/z values - * @return - */ - public static Vector3m toVector3m(Vector2 o) { - return new Vector3m(o.x, 0, o.z); - } - - /** - * Returns a Vector3 object with the given y-value. - * The x of the Vector2 becomes the x of the Vector3, - * the y of the Vector2 becomes the z of the Vector3. - * - * @param o Vector2 to use as the x/z values - * @param y Y value of the new Vector3 - * @return - */ - public static Vector3 toVector3(Vector2 o, float y) { - return new Vector3(o.x, y, o.z); - } - - /** - * Returns a Vector3m object with the given y-value. - * The x of the Vector2 becomes the x of the Vector3m, - * the y of the Vector2 becomes the z of the Vector3m. - * - * @param o Vector2 to use as the x/z values - * @param y Y value of the new Vector3 - * @return - */ - public static Vector3m toVector3m(Vector2 o, float y) { - return new Vector3m(o.x, y, o.z); - } - - /** - * Rounds the X and Y values of the given Vector2 up to - * the nearest integer value. - * - * @param o Vector2 to use - * @return - */ - public static Vector2 ceil(Vector2 o) { - return new Vector2(Math.ceil(o.x), Math.ceil(o.z)); - } - - /** - * Rounds the X and Y values of the given Vector2 down to - * the nearest integer value. - * - * @param o Vector2 to use - * @return - */ - public static Vector2 floor(Vector2 o) { - return new Vector2(Math.floor(o.x), Math.floor(o.z)); - } - - /** - * Rounds the X and Y values of the given Vector2 to - * the nearest integer value. - * - * @param o Vector2 to use - * @return - */ - public static Vector2 round(Vector2 o) { - return new Vector2(Math.round(o.x), Math.round(o.z)); - } - - /** - * Sets the X and Y values of the given Vector2 to their - * absolute value. - * - * @param o Vector2 to use - * @return - */ - public static Vector2 abs(Vector2 o) { - return new Vector2(Math.abs(o.x), Math.abs(o.z)); - } - - /** - * Returns a Vector2 containing the smallest X and Y values. - * - * @param o1 - * @param o2 - * @return - */ - public static Vector2 min(Vector2 o1, Vector2 o2) { - return new Vector2(Math.min(o1.x, o2.x), Math.min(o1.z, o2.z)); - } - - /** - * Returns a Vector2 containing the largest X and Y values. - * - * @param o1 - * @param o2 - * @return - */ - public static Vector2 max(Vector2 o1, Vector2 o2) { - return new Vector2(Math.max(o1.x, o2.x), Math.max(o1.z, o2.z)); - } - - /** - * Returns a Vector2 with random X and Y values (between 0 and 1) - * - * @param o - * @return - */ - public static Vector2 rand() { - return new Vector2(Math.random(), Math.random()); - } - - /** - * Returns the provided Vector2 in an array. Element 0 contains x Element 1 - * contains y - * - * @return The array containing the Vector2 - */ - public static float[] toArray(Vector2 a) { - return new float[]{a.getX(), a.getY()}; - } - - /** - * Compares two Vector3s - */ - public static int compareTo(Vector2 a, Vector2 b) { - return (int) a.lengthSquared() - (int) b.lengthSquared(); - } - - /** - * Gets the distance between two Vector2. - * - * @param a - * @param b - * @return - */ - public static double distance(Vector2 a, Vector2 b) { - Vector2 tempVector = Vector2.pow(Vector2.subtract(a, b), 2); - return Math.sqrt(tempVector.x + tempVector.z); - } - - /** - * Raises the X and Y values of a Vector2 to the given power. - * - * @param o - * @param power - * @return - */ - public static Vector2 pow(Vector2 o, double power) { - return new Vector2(Math.pow(o.x, power), Math.pow(o.z, power)); - } - - /** - * Checks if two Vector2s are equal - */ - public static boolean equals(Object a, Object b) { - if (!(a instanceof Vector2) || !(b instanceof Vector2)) { - return false; - } - if (a == b) { - return true; - } - return compareTo((Vector2) a, (Vector2) b) == 0; - } - - @Override - public String toString() { - return "(" + this.x + ", " + this.z + ")"; - } - - @Override - public int hashCode() - { - return (int)(this.x % this.z); - } +public class Vector2 implements Comparable +{ + + /** + * Represents the Zero vector (0,0) + */ + public final static Vector2 ZERO = new Vector2(0, 0); + /** + * Represents a unit vector in the X direction (1,0) + */ + public final static Vector2 UNIT_X = new Vector2(1, 0); + /** + * Represents a unit vector in the Y direction (0,1) + */ + public final static Vector2 UNIT_Y = new Vector2(0, 1); + /** + * Represents a unit vector (1,1) + */ + public static Vector2 ONE = new Vector2(1, 1); + protected float x, z; + + /** + * Construct and Initialized a Vector2 from the given x, y + * + * @param x the x coordinate + * @param y the y coordinate + */ + public Vector2(float x, float y) + { + this.x = x; + this.z = y; + } + + /** + * Construct and Initialized a Vector2 from the given x, y + * + * @param x the x coordinate + * @param y the y coordinate + */ + public Vector2(Double x, Double y) + { + this(x.floatValue(), y.floatValue()); + } + + /** + * Construct and Initialized a Vector2 to (0,0) + */ + public Vector2() + { + this(0, 0); + } + + /** + * Construct and Initialized a Vector2 from an old Vector2 + * + * @param original + */ + public Vector2(Vector2 original) + { + this(original.x, original.z); + } + + /** + * Gets the X coordiante + * + * @return The X coordinate + */ + public float getX() + { + return this.x; + } + + /** + * Gets the Y coordiante + * + * @return The Y coordinate + */ + public float getY() + { + return this.z; + } + + /** + * Adds this Vector2 to the value of the Vector2 argument + * + * @param that The Vector2 to add + * @return the new Vector2 + */ + public Vector2 add(Vector2 that) + { + return Vector2.add(this, that); + } + + /** + * Subtracts this Vector2 to the value of the Vector2 argument + * + * @param that The Vector2 to subtract + * @return the new Vector2 + */ + public Vector2 subtract(Vector2 that) + { + return Vector2.subtract(this, that); + } + + /** + * Scales this Vector2 by the value of the argument + * + * @param scale The amount to scale by + * @return A new Vector2 scaled by the amount. + */ + public Vector2 scale(float scale) + { + return Vector2.scale(this, scale); + } + + /** + * Returns this Vector2 dot the Vector2 argument. Dot Product is defined as + * a.x*b.x + a.y*b.y + * + * @param that The Vector2 to dot with this. + * @return The dot product + */ + public float dot(Vector2 that) + { + return Vector2.dot(this, that); + } + + /** + * Returns a Vector3 object with a y-value of 0. + * The x of this Vector2 becomes the x of the Vector3, + * the y of this Vector2 becomes the z of the Vector3. + * + * @return + */ + public Vector3 toVector3() + { + return Vector2.toVector3(this); + } + + /** + * Returns a Vector3m object with a y-value of 0. + * The x of this Vector2 becomes the x of the Vector3m, + * the y of this Vector2 becomes the z of the Vector3m. + * + * @return + */ + public Vector3m toVector3m() + { + return Vector2.toVector3m(this); + } + + /** + * Returns a Vector3 object with the given y value. + * The x of this Vector2 becomes the x of the Vector3, + * the y of this Vector2 becomes the z of the Vector3. + * + * @param y Y value to use in the new Vector3. + * @return + */ + public Vector3 toVector3(float y) + { + return Vector2.toVector3(this, y); + } + + /** + * Returns a Vector3m object with the given y value. + * The x of this Vector2 becomes the x of the Vector3m, + * the y of this Vector2 becomes the z of the Vector3m. + * + * @param y Y value to use in the new Vector3m. + * @return + */ + public Vector3m toVector3m(float y) + { + return Vector2.toVector3m(this, y); + } + + /** + * Returns the Cross Product of this Vector2 Note: Cross Product is + * undefined in 2d space. This returns the orthogonal vector to this vector + * + * @return The orthogonal vector to this vector. + */ + public Vector2 cross() + { + return new Vector2(this.z, -this.x); + } + + /** + * Rounds the X and Y values of this Vector2 up to + * the nearest integer value. + * + * @return + */ + public Vector2 ceil() + { + return new Vector2(Math.ceil(this.x), Math.ceil(this.z)); + } + + /** + * Rounds the X and Y values of this Vector2 down to + * the nearest integer value. + * + * @return + */ + public Vector2 floor() + { + return new Vector2(Math.floor(this.x), Math.floor(this.z)); + } + + /** + * Rounds the X and Y values of this Vector2 to + * the nearest integer value. + * + * @return + */ + public Vector2 round() + { + return new Vector2(Math.round(this.x), Math.round(this.z)); + } + + /** + * Sets the X and Y values of this Vector2 to their + * absolute value. + * + * @return + */ + public Vector2 abs() + { + return new Vector2(Math.abs(this.x), Math.abs(this.z)); + } + + /** + * Gets the distance between this Vector2 and a given Vector2. + * + * @param a + * @return + */ + public double distance(Vector2 a) + { + return Vector2.distance(a, this); + } + + /** + * Raises the X and Y values of this Vector2 to the given power. + * + * @param power + * @return + */ + public Vector2 pow(double power) + { + return Vector2.pow(this, power); + } + + /** + * Calculates the length of this Vector2 squared. + * + * @return the squared length + */ + public float lengthSquared() + { + return Vector2.lengthSquared(this); + } + + /** + * Calculates the length of this Vector2 Note: This makes use of the sqrt + * function, and is not cached. That could affect performance + * + * @return the length of this vector2 + */ + public float length() + { + return Vector2.length(this); + } + + /** + * Returns this Vector2 where the length is equal to 1 + * + * @return This Vector2 with length 1 + */ + public Vector2 normalize() + { + return Vector2.normalize(this); + } + + /** + * Returns this Vector2 in an array. Element 0 contains x Element 1 contains + * y + * + * @return The array containing this Vector2 + */ + public float[] toArray() + { + return Vector2.toArray(this); + } + + /** + * Compares two Vector3s + */ + @Override + public int compareTo(Vector2 o) + { + return Vector2.compareTo(this, o); + } + + /** + * Checks if two Vector2s are equal + */ + @Override + public boolean equals(Object o) + { + return Vector2.equals(this, o); + } + + /** + * Returns the length of the provided Vector2 Note: This makes use of the + * sqrt function, and is not cached. This could affect performance. + * + * @param a The Vector2 to calculate the length of + * @return The length of the Vector2 + */ + public static float length(Vector2 a) + { + return (float)Math.sqrt(lengthSquared(a)); + } + + /** + * Returns the length squared of the provided Vector2 + * + * @param a the Vector2 to calculate the length squared + * @return the length squared of the Vector2 + */ + public static float lengthSquared(Vector2 a) + { + return Vector2.dot(a, a); + } + + /** + * Returns a Vector2 that is the unit form of the provided Vector2 + * + * @param a + * @return + */ + public static Vector2 normalize(Vector2 a) + { + return Vector2.scale(a, (1.f / a.length())); + } + + /** + * Subtracts one Vector2 from the other Vector2 + * + * @param a + * @param b + * @return + */ + public static Vector2 subtract(Vector2 a, Vector2 b) + { + return new Vector2(a.getX() - b.getX(), a.getY() - b.getY()); + } + + /** + * Adds one Vector2 to the other Vector2 + * + * @param a + * @param b + * @return + */ + public static Vector2 add(Vector2 a, Vector2 b) + { + return new Vector2(a.getX() + b.getX(), a.getY() + b.getY()); + } + + /** + * Scales the Vector2 by the ammount + * + * @param a + * @param b + * @return + */ + public static Vector2 scale(Vector2 a, float b) + { + return new Vector2(a.getX() * b, a.getY() * b); + } + + /** + * Calculates the Dot Product of two Vector2s Dot Product is defined as + * a.x*b.x + a.y*b.y + * + * @param a + * @param b + * @return + */ + public static float dot(Vector2 a, Vector2 b) + { + return a.getX() * b.getX() + a.getY() * b.getY(); + } + + /** + * Returns a Vector3 object with a y-value of 0. + * The x of the Vector2 becomes the x of the Vector3, + * the y of the Vector2 becomes the z of the Vector3. + * + * @param o Vector2 to use as the x/z values + * @return + */ + public static Vector3 toVector3(Vector2 o) + { + return new Vector3(o.x, 0, o.z); + } + + /** + * Returns a Vector3m object with a y-value of 0. + * The x of the Vector2 becomes the x of the Vector3m, + * the y of the Vector2 becomes the z of the Vector3m. + * + * @param o Vector2 to use as the x/z values + * @return + */ + public static Vector3m toVector3m(Vector2 o) + { + return new Vector3m(o.x, 0, o.z); + } + + /** + * Returns a Vector3 object with the given y-value. + * The x of the Vector2 becomes the x of the Vector3, + * the y of the Vector2 becomes the z of the Vector3. + * + * @param o Vector2 to use as the x/z values + * @param y Y value of the new Vector3 + * @return + */ + public static Vector3 toVector3(Vector2 o, float y) + { + return new Vector3(o.x, y, o.z); + } + + /** + * Returns a Vector3m object with the given y-value. + * The x of the Vector2 becomes the x of the Vector3m, + * the y of the Vector2 becomes the z of the Vector3m. + * + * @param o Vector2 to use as the x/z values + * @param y Y value of the new Vector3 + * @return + */ + public static Vector3m toVector3m(Vector2 o, float y) + { + return new Vector3m(o.x, y, o.z); + } + + /** + * Rounds the X and Y values of the given Vector2 up to + * the nearest integer value. + * + * @param o Vector2 to use + * @return + */ + public static Vector2 ceil(Vector2 o) + { + return new Vector2(Math.ceil(o.x), Math.ceil(o.z)); + } + + /** + * Rounds the X and Y values of the given Vector2 down to + * the nearest integer value. + * + * @param o Vector2 to use + * @return + */ + public static Vector2 floor(Vector2 o) + { + return new Vector2(Math.floor(o.x), Math.floor(o.z)); + } + + /** + * Rounds the X and Y values of the given Vector2 to + * the nearest integer value. + * + * @param o Vector2 to use + * @return + */ + public static Vector2 round(Vector2 o) + { + return new Vector2(Math.round(o.x), Math.round(o.z)); + } + + /** + * Sets the X and Y values of the given Vector2 to their + * absolute value. + * + * @param o Vector2 to use + * @return + */ + public static Vector2 abs(Vector2 o) + { + return new Vector2(Math.abs(o.x), Math.abs(o.z)); + } + + /** + * Returns a Vector2 containing the smallest X and Y values. + * + * @param o1 + * @param o2 + * @return + */ + public static Vector2 min(Vector2 o1, Vector2 o2) + { + return new Vector2(Math.min(o1.x, o2.x), Math.min(o1.z, o2.z)); + } + + /** + * Returns a Vector2 containing the largest X and Y values. + * + * @param o1 + * @param o2 + * @return + */ + public static Vector2 max(Vector2 o1, Vector2 o2) + { + return new Vector2(Math.max(o1.x, o2.x), Math.max(o1.z, o2.z)); + } + + /** + * Returns a Vector2 with random X and Y values (between 0 and 1) + * + * @param o + * @return + */ + public static Vector2 rand() + { + return new Vector2(Math.random(), Math.random()); + } + + /** + * Returns the provided Vector2 in an array. Element 0 contains x Element 1 + * contains y + * + * @return The array containing the Vector2 + */ + public static float[] toArray(Vector2 a) + { + return new float[] { a.getX(), a.getY() }; + } + + /** + * Compares two Vector3s + */ + public static int compareTo(Vector2 a, Vector2 b) + { + return (int)a.lengthSquared() - (int)b.lengthSquared(); + } + + /** + * Gets the distance between two Vector2. + * + * @param a + * @param b + * @return + */ + public static double distance(Vector2 a, Vector2 b) + { + Vector2 tempVector = Vector2.pow(Vector2.subtract(a, b), 2); + return Math.sqrt(tempVector.x + tempVector.z); + } + + /** + * Raises the X and Y values of a Vector2 to the given power. + * + * @param o + * @param power + * @return + */ + public static Vector2 pow(Vector2 o, double power) + { + return new Vector2(Math.pow(o.x, power), Math.pow(o.z, power)); + } + + /** + * Checks if two Vector2s are equal + */ + public static boolean equals(Object a, Object b) + { + if (!(a instanceof Vector2) || !(b instanceof Vector2)) + { + return false; + } + if (a == b) + { + return true; + } + return compareTo((Vector2)a, (Vector2)b) == 0; + } + + @Override + public String toString() + { + return "(" + this.x + ", " + this.z + ")"; + } + + @Override + public int hashCode() + { + return (int)(this.x % this.z); + } } diff --git a/src/main/java/wecui/util/Vector2m.java b/src/main/java/wecui/util/Vector2m.java index ee6505cc..1afc561c 100644 --- a/src/main/java/wecui/util/Vector2m.java +++ b/src/main/java/wecui/util/Vector2m.java @@ -5,126 +5,142 @@ * * @author yetanotherx */ -public class Vector2m extends Vector2 { - - public Vector2m() { - } - - public Vector2m(Double x, Double y) { - super(x, y); - } - - public Vector2m(float x, float y) { - super(x, y); - } - - public Vector2m(Vector2 original) { - super(original); - } - - /** - * Sets the X coordinate - * - * @param x The x coordinate - */ - public void setX(float x) { - this.x = x; - } - - /** - * Sets the Y coordinate - * - * @param y The Y coordinate - */ - public void setY(float y) { - this.z = y; - } - - @Override - public Vector2 add(Vector2 that) { - this.x += that.x; - this.z += that.z; - return this; - } - - @Override - public Vector2 subtract(Vector2 that) { - this.x -= that.x; - this.z -= that.z; - return this; - } - - @Override - public Vector2 scale(float scale) { - this.x *= scale; - this.z *= scale; - return this; - } - - public Vector2 cross(Vector2 that) { - float tmp = this.z; - this.z = -this.x; - this.x = tmp; - return this; - } - - /** - * Rounds the X and Y values of this Vector2 up to - * the nearest integer value. - * - * @return - */ - @Override - public Vector2 ceil() { - this.x = (float) Math.ceil(this.x); - this.z = (float) Math.ceil(this.z); - return this; - } - - /** - * Rounds the X and Y values of this Vector2 down to - * the nearest integer value. - * - * @return - */ - @Override - public Vector2 floor() { - this.x = (float) Math.floor(this.x); - this.z = (float) Math.floor(this.z); - return this; - } - - /** - * Rounds the X and Y values of this Vector2 to - * the nearest integer value. - * - * @return - */ - @Override - public Vector2 round() { - this.x = Math.round(this.x); - this.z = Math.round(this.z); - return this; - } - - /** - * Sets the X and Y values of this Vector2 to their - * absolute value. - * - * @return - */ - @Override - public Vector2 abs() { - this.x = Math.abs(this.x); - this.z = Math.abs(this.z); - return this; - } - - @Override - public Vector2 normalize() { - float length = this.length(); - this.x *= 1 / length; - this.z *= 1 / length; - return this; - } +public class Vector2m extends Vector2 +{ + + public Vector2m() + { + } + + public Vector2m(Double x, Double y) + { + super(x, y); + } + + public Vector2m(float x, float y) + { + super(x, y); + } + + public Vector2m(Vector2 original) + { + super(original); + } + + /** + * Sets the X coordinate + * + * @param x The x coordinate + */ + public void setX(float x) + { + this.x = x; + } + + /** + * Sets the Y coordinate + * + * @param y The Y coordinate + */ + public void setY(float y) + { + this.z = y; + } + + @Override + public Vector2 add(Vector2 that) + { + this.x += that.x; + this.z += that.z; + return this; + } + + @Override + public Vector2 subtract(Vector2 that) + { + this.x -= that.x; + this.z -= that.z; + return this; + } + + @Override + public Vector2 scale(float scale) + { + this.x *= scale; + this.z *= scale; + return this; + } + + public Vector2 cross(Vector2 that) + { + float tmp = this.z; + this.z = -this.x; + this.x = tmp; + return this; + } + + /** + * Rounds the X and Y values of this Vector2 up to + * the nearest integer value. + * + * @return + */ + @Override + public Vector2 ceil() + { + this.x = (float)Math.ceil(this.x); + this.z = (float)Math.ceil(this.z); + return this; + } + + /** + * Rounds the X and Y values of this Vector2 down to + * the nearest integer value. + * + * @return + */ + @Override + public Vector2 floor() + { + this.x = (float)Math.floor(this.x); + this.z = (float)Math.floor(this.z); + return this; + } + + /** + * Rounds the X and Y values of this Vector2 to + * the nearest integer value. + * + * @return + */ + @Override + public Vector2 round() + { + this.x = Math.round(this.x); + this.z = Math.round(this.z); + return this; + } + + /** + * Sets the X and Y values of this Vector2 to their + * absolute value. + * + * @return + */ + @Override + public Vector2 abs() + { + this.x = Math.abs(this.x); + this.z = Math.abs(this.z); + return this; + } + + @Override + public Vector2 normalize() + { + float length = this.length(); + this.x *= 1 / length; + this.z *= 1 / length; + return this; + } } diff --git a/src/main/java/wecui/util/Vector3.java b/src/main/java/wecui/util/Vector3.java index cfa7ffe0..92daf61f 100644 --- a/src/main/java/wecui/util/Vector3.java +++ b/src/main/java/wecui/util/Vector3.java @@ -3,580 +3,637 @@ /** * Represents a 3d vector. */ -public class Vector3 implements Comparable { - - /** - * Vector with all elements set to 0. (0, 0, 0) - */ - public final static Vector3 ZERO = new Vector3(0, 0, 0); - /** - * Unit Vector in the X direction. (1, 0, 0) - */ - public final static Vector3 UNIT_X = new Vector3(1, 0, 0); - /** - * Unit Vector facing Forward. (1, 0, 0) - */ - public final static Vector3 Forward = UNIT_X; - /** - * Unit Vector in the Y direction. (0, 1, 0) - */ - public final static Vector3 UNIT_Y = new Vector3(0, 1, 0); - /** - * Unit Vector pointing Up. (0, 1, 0) - */ - public final static Vector3 Up = UNIT_Y; - /** - * Unit Vector in the Z direction. (0, 0, 1) - */ - public final static Vector3 UNIT_Z = new Vector3(0, 0, 1); - /** - * Unit Vector pointing Right. (0, 0, 1) - */ - public final static Vector3 Right = UNIT_Z; - /** - * Unit Vector with all elements set to 1. (1, 1, 1) - */ - public final static Vector3 ONE = new Vector3(1, 1, 1); - protected float x, y, z; - - /** - * Constructs a new Vector3 with the given x, y, z - * - * @param x - * @param y - * @param z - */ - public Vector3(float x, float y, float z) { - this.x = x; - this.y = y; - this.z = z; - } - - /** - * Constructs a new Vector3 with the given x, y, z - * - * @param x - * @param y - * @param z - */ - public Vector3(Double x, Double y, Double z) { - this(x.floatValue(), y.floatValue(), z.floatValue()); - } - - /** - * Constructs a new Vector3 with all elements set to 0 - */ - public Vector3() { - this(0, 0, 0); - } - - /** - * Constructs a new Vector3 that is a clone of the given vector3 - * - * @param clone - */ - public Vector3(Vector3 clone) { - this(clone.getX(), clone.getY(), clone.getZ()); - } - - /** - * Constructs a new Vector3 from the given Vector2 and z - * - * @param vector - * @param z - */ - public Vector3(Vector2 vector, float z) { - this(vector.getX(), vector.getY(), z); - } - - /** - * Constructs a new Vector3 from the given Vector2 and z set to 0 - * - * @param vector - */ - public Vector3(Vector2 vector) { - this(vector, 0); - } - - public float getX() { - return this.x; - } - - public float getY() { - return this.y; - } - - public float getZ() { - return this.z; - } - - /** - * Adds two vectors - * - * @param that - * @return - */ - public Vector3 add(Vector3 that) { - return Vector3.add(this, that); - } - - /** - * Subtracts two vectors - * - * @param that - * @return - */ - public Vector3 subtract(Vector3 that) { - return Vector3.subtract(this, that); - } - - /** - * Scales by the scalar value - * - * @param scale - * @return - */ - public Vector3 scale(float scale) { - return Vector3.scale(this, scale); - } - - /** - * Takes the dot product of two vectors - * - * @param that - * @return - */ - public float dot(Vector3 that) { - return Vector3.dot(this, that); - } - - /** - * Takes the cross product of two vectors - * - * @param that - * @return - */ - public Vector3 cross(Vector3 that) { - return Vector3.cross(this, that); - } - - /** - * Returns a Vector2 object using the X and Z values of - * this Vector3. The x of this Vector3 becomes the x - * of the Vector2, and the z of this Vector3 becomes the - * y of the Vector2. - * - * @return - */ - public Vector2 toVector2() { - return Vector3.toVector2(this); - } - - /** - * Returns a Vector2m object using the X and Z values of - * this Vector3. The x of this Vector3 becomes the x - * of the Vector2, and the z of this Vector3 becomes the - * y of the Vector2m. - * - * @return - */ - public Vector2m toVector2m() { - return Vector3.toVector2m(this); - } - - /** - * Rounds the X, Y, and Z values of this Vector3 up to - * the nearest integer value. - * - * @return - */ - public Vector3 ceil() { - return new Vector3(Math.ceil(this.x), Math.ceil(this.y), Math.ceil(this.z)); - } - - /** - * Rounds the X, Y, and Z values of this Vector3 down to - * the nearest integer value. - * - * @return - */ - public Vector3 floor() { - return new Vector3(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z)); - } - - /** - * Rounds the X, Y, and Z values of this Vector3 to - * the nearest integer value. - * - * @return - */ - public Vector3 round() { - return new Vector3(Math.round(this.x), Math.round(this.y), Math.round(this.z)); - } - - /** - * Sets the X, Y, and Z values of this Vector3 to their - * absolute value. - * - * @return - */ - public Vector3 abs() { - return new Vector3(Math.abs(this.x), Math.abs(this.y), Math.abs(this.z)); - } - - /** - * Gets the distance between this Vector3 and a given Vector3. - * - * @param a - * @return - */ - public double distance(Vector3 a) { - return Vector3.distance(a, this); - } - - /** - * Raises the X, Y, and Z values of this Vector3 to the given power. - * - * @param power - * @return - */ - public Vector3 pow(double power) { - return Vector3.pow(this, power); - } - - /** - * returns the squared length of the vector - * - * @return - */ - public float lengthSquared() { - return Vector3.lengthSquared(this); - } - - /** - * returns the length of this vector. Note: makes use of Math.sqrt and is - * not cached. - * - * @return - */ - public float length() { - return Vector3.length(this); - } - - /** - * Returns a fast approximation of this vector's length. - * - * @return - */ - public float fastLength() { - return Vector3.fastLength(this); - } - - /** - * returns the vector with a length of 1 - * - * @return - */ - public Vector3 normalize() { - return Vector3.normalize(this); - } - - /** - * returns the vector as [x,y,z] - * - * @return - */ - public float[] toArray() { - return Vector3.toArray(this); - } - - /** - * Compares two Vector3s - */ - @Override - public int compareTo(Vector3 o) { - return Vector3.compareTo(this, o); - } - - /** - * Checks if two Vector3s are equal - */ - @Override - public boolean equals(Object o) { - return Vector3.equals(this, o); - } - - /** - * toString Override - */ - @Override - public String toString() { - return String.format("{ %f, %f, %f }", this.x, this.y, this.z); - } - - /** - * Returns the length of the given vector. - * - * Note: Makes use of Math.sqrt and - * is not cached, so can be slow - * - * Also known as norm. ||a|| - * - * @param a - * @return - */ - public static float length(Vector3 a) { - return (float) Math.sqrt(lengthSquared(a)); - } - - /** - * Returns an approximate length of the given vector. - * - * @param a - * @return - */ - public static float fastLength(Vector3 a) { - return (float) Math.sqrt(lengthSquared(a)); - } - - /** - * returns the length squared to the given vector - * - * @param a - * @return - */ - public static float lengthSquared(Vector3 a) { - return Vector3.dot(a, a); - } - - /** - * Returns a new vector that is the given vector but length 1 - * - * @param a - * @return - */ - public static Vector3 normalize(Vector3 a) { - return Vector3.scale(a, (1.f / a.length())); - } - - /** - * Creates a new vector that is A - B - * - * @param a - * @param b - * @return - */ - public static Vector3 subtract(Vector3 a, Vector3 b) { - return new Vector3(a.getX() - b.getX(), a.getY() - b.getY(), a.getZ() - b.getZ()); - } - - /** - * Creates a new Vector that is A + B - * - * @param a - * @param b - * @return - */ - public static Vector3 add(Vector3 a, Vector3 b) { - return new Vector3(a.getX() + b.getX(), a.getY() + b.getY(), a.getZ() + b.getZ()); - } - - /** - * Creates a new vector that is A multiplied by the uniform scalar B - * - * @param a - * @param b - * @return - */ - public static Vector3 scale(Vector3 a, float b) { - return new Vector3(a.getX() * b, a.getY() * b, a.getZ() * b); - } - - /** - * Returns the dot product of A and B - * - * @param a - * @param b - * @return - */ - public static float dot(Vector3 a, Vector3 b) { - return a.getX() * b.getX() + a.getY() * b.getY() + a.getZ() * b.getZ(); - } - - /** - * Creates a new Vector that is the A x B The Cross Product is the vector - * orthogonal to both A and B - * - * @param a - * @param b - * @return - */ - public static Vector3 cross(Vector3 a, Vector3 b) { - return new Vector3(a.getY() * b.getZ() - a.getZ() * b.getY(), a.getZ() * b.getX() - a.getX() * b.getZ(), a.getX() * b.getY() - a.getY() * b.getX()); - } - - /** - * Rounds the X, Y, and Z values of the given Vector3 up to - * the nearest integer value. - * - * @param o Vector3 to use - * @return - */ - public static Vector3 ceil(Vector3 o) { - return new Vector3(Math.ceil(o.x), Math.ceil(o.y), Math.ceil(o.z)); - } - - /** - * Rounds the X, Y, and Z values of the given Vector3 down to - * the nearest integer value. - * - * @param o Vector3 to use - * @return - */ - public static Vector3 floor(Vector3 o) { - return new Vector3(Math.floor(o.x), Math.floor(o.y), Math.floor(o.z)); - } - - /** - * Rounds the X, Y, and Z values of the given Vector3 to - * the nearest integer value. - * - * @param o Vector3 to use - * @return - */ - public static Vector3 round(Vector3 o) { - return new Vector3(Math.round(o.x), Math.round(o.y), Math.round(o.z)); - } - - /** - * Sets the X, Y, and Z values of the given Vector3 to their - * absolute value. - * - * @param o Vector3 to use - * @return - */ - public static Vector3 abs(Vector3 o) { - return new Vector3(Math.abs(o.x), Math.abs(o.y), Math.abs(o.z)); - } - - /** - * Returns a Vector3 containing the smallest X, Y, and Z values. - * - * @param o1 - * @param o2 - * @return - */ - public static Vector3 min(Vector3 o1, Vector3 o2) { - return new Vector3(Math.min(o1.x, o2.x), Math.min(o1.y, o2.y), Math.min(o1.z, o2.z)); - } - - /** - * Returns a Vector3 containing the largest X, Y, and Z values. - * - * @param o1 - * @param o2 - * @return - */ - public static Vector3 max(Vector3 o1, Vector3 o2) { - return new Vector3(Math.max(o1.x, o2.x), Math.max(o1.y, o2.y), Math.max(o1.z, o2.z)); - } - - /** - * Returns a Vector3 with random X, Y, and Z values (between 0 and 1) - * - * @return - */ - public static Vector3 rand() { - return new Vector3(Math.random(), Math.random(), Math.random()); - } - - /** - * Gets the distance between two Vector3. - * - * @param a - * @param b - * @return - */ - public static double distance(Vector3 a, Vector3 b) { - double xzDist = Vector2.distance(a.toVector2(), b.toVector2()); - return Math.sqrt(Math.pow(xzDist, 2) + Math.pow(Math.abs(Vector3.subtract(a, b).getY()), 2)); - } - - /** - * Raises the X, Y, and Z values of a Vector3 to the given power. - * - * @param o - * @param power - * @return - */ - public static Vector3 pow(Vector3 o, double power) { - return new Vector3(Math.pow(o.x, power), Math.pow(o.y, power), Math.pow(o.z, power)); - } - - /** - * Returns a Vector2 object using the X and Z values of - * the given Vector3. The x of the Vector3 becomes the x - * of the Vector2, and the z of this Vector3 becomes the - * y of the Vector2m. - * - * @param o Vector3 object to use - * @return - */ - public static Vector2 toVector2(Vector3 o) { - return new Vector2(o.x, o.z); - } - - /** - * Returns a Vector2m object using the X and Z values of - * the given Vector3. The x of the Vector3 becomes the x - * of the Vector2m, and the z of this Vector3 becomes the - * y of the Vector2m. - * - * @param o Vector3 object to use - * @return - */ - public static Vector2m toVector2m(Vector3 o) { - return new Vector2m(o.x, o.z); - } - - /** - * Returns a new float array that is {x, y, z} - * - * @param a - * @return - */ - public static float[] toArray(Vector3 a) { - return new float[]{a.getX(), a.getY(), a.getZ()}; - } - - /** - * Compares two Vector3s - */ - public static int compareTo(Vector3 a, Vector3 b) { - return (int) a.lengthSquared() - (int) b.lengthSquared(); - } - - /** - * Checks if two Vector3s are equal - */ - public static boolean equals(Object a, Object b) { - if (!(a instanceof Vector3) || !(b instanceof Vector3)) { - return false; - } - if (a == b) { - return true; - } - Vector3 x = (Vector3) a; - Vector3 y = (Vector3) b; - if (x.getX() == y.getX() && x.getY() == y.getY() && x.getZ() == y.getZ()) { - return true; - } - return false; - } - - @Override - public int hashCode() - { - return (int)(this.x * this.y % this.z); - } +public class Vector3 implements Comparable +{ + + /** + * Vector with all elements set to 0. (0, 0, 0) + */ + public final static Vector3 ZERO = new Vector3(0, 0, 0); + /** + * Unit Vector in the X direction. (1, 0, 0) + */ + public final static Vector3 UNIT_X = new Vector3(1, 0, 0); + /** + * Unit Vector facing Forward. (1, 0, 0) + */ + public final static Vector3 Forward = UNIT_X; + /** + * Unit Vector in the Y direction. (0, 1, 0) + */ + public final static Vector3 UNIT_Y = new Vector3(0, 1, 0); + /** + * Unit Vector pointing Up. (0, 1, 0) + */ + public final static Vector3 Up = UNIT_Y; + /** + * Unit Vector in the Z direction. (0, 0, 1) + */ + public final static Vector3 UNIT_Z = new Vector3(0, 0, 1); + /** + * Unit Vector pointing Right. (0, 0, 1) + */ + public final static Vector3 Right = UNIT_Z; + /** + * Unit Vector with all elements set to 1. (1, 1, 1) + */ + public final static Vector3 ONE = new Vector3(1, 1, 1); + protected float x, y, z; + + /** + * Constructs a new Vector3 with the given x, y, z + * + * @param x + * @param y + * @param z + */ + public Vector3(float x, float y, float z) + { + this.x = x; + this.y = y; + this.z = z; + } + + /** + * Constructs a new Vector3 with the given x, y, z + * + * @param x + * @param y + * @param z + */ + public Vector3(Double x, Double y, Double z) + { + this(x.floatValue(), y.floatValue(), z.floatValue()); + } + + /** + * Constructs a new Vector3 with all elements set to 0 + */ + public Vector3() + { + this(0, 0, 0); + } + + /** + * Constructs a new Vector3 that is a clone of the given vector3 + * + * @param clone + */ + public Vector3(Vector3 clone) + { + this(clone.getX(), clone.getY(), clone.getZ()); + } + + /** + * Constructs a new Vector3 from the given Vector2 and z + * + * @param vector + * @param z + */ + public Vector3(Vector2 vector, float z) + { + this(vector.getX(), vector.getY(), z); + } + + /** + * Constructs a new Vector3 from the given Vector2 and z set to 0 + * + * @param vector + */ + public Vector3(Vector2 vector) + { + this(vector, 0); + } + + public float getX() + { + return this.x; + } + + public float getY() + { + return this.y; + } + + public float getZ() + { + return this.z; + } + + /** + * Adds two vectors + * + * @param that + * @return + */ + public Vector3 add(Vector3 that) + { + return Vector3.add(this, that); + } + + /** + * Subtracts two vectors + * + * @param that + * @return + */ + public Vector3 subtract(Vector3 that) + { + return Vector3.subtract(this, that); + } + + /** + * Scales by the scalar value + * + * @param scale + * @return + */ + public Vector3 scale(float scale) + { + return Vector3.scale(this, scale); + } + + /** + * Takes the dot product of two vectors + * + * @param that + * @return + */ + public float dot(Vector3 that) + { + return Vector3.dot(this, that); + } + + /** + * Takes the cross product of two vectors + * + * @param that + * @return + */ + public Vector3 cross(Vector3 that) + { + return Vector3.cross(this, that); + } + + /** + * Returns a Vector2 object using the X and Z values of + * this Vector3. The x of this Vector3 becomes the x + * of the Vector2, and the z of this Vector3 becomes the + * y of the Vector2. + * + * @return + */ + public Vector2 toVector2() + { + return Vector3.toVector2(this); + } + + /** + * Returns a Vector2m object using the X and Z values of + * this Vector3. The x of this Vector3 becomes the x + * of the Vector2, and the z of this Vector3 becomes the + * y of the Vector2m. + * + * @return + */ + public Vector2m toVector2m() + { + return Vector3.toVector2m(this); + } + + /** + * Rounds the X, Y, and Z values of this Vector3 up to + * the nearest integer value. + * + * @return + */ + public Vector3 ceil() + { + return new Vector3(Math.ceil(this.x), Math.ceil(this.y), Math.ceil(this.z)); + } + + /** + * Rounds the X, Y, and Z values of this Vector3 down to + * the nearest integer value. + * + * @return + */ + public Vector3 floor() + { + return new Vector3(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z)); + } + + /** + * Rounds the X, Y, and Z values of this Vector3 to + * the nearest integer value. + * + * @return + */ + public Vector3 round() + { + return new Vector3(Math.round(this.x), Math.round(this.y), Math.round(this.z)); + } + + /** + * Sets the X, Y, and Z values of this Vector3 to their + * absolute value. + * + * @return + */ + public Vector3 abs() + { + return new Vector3(Math.abs(this.x), Math.abs(this.y), Math.abs(this.z)); + } + + /** + * Gets the distance between this Vector3 and a given Vector3. + * + * @param a + * @return + */ + public double distance(Vector3 a) + { + return Vector3.distance(a, this); + } + + /** + * Raises the X, Y, and Z values of this Vector3 to the given power. + * + * @param power + * @return + */ + public Vector3 pow(double power) + { + return Vector3.pow(this, power); + } + + /** + * returns the squared length of the vector + * + * @return + */ + public float lengthSquared() + { + return Vector3.lengthSquared(this); + } + + /** + * returns the length of this vector. Note: makes use of Math.sqrt and is + * not cached. + * + * @return + */ + public float length() + { + return Vector3.length(this); + } + + /** + * Returns a fast approximation of this vector's length. + * + * @return + */ + public float fastLength() + { + return Vector3.fastLength(this); + } + + /** + * returns the vector with a length of 1 + * + * @return + */ + public Vector3 normalize() + { + return Vector3.normalize(this); + } + + /** + * returns the vector as [x,y,z] + * + * @return + */ + public float[] toArray() + { + return Vector3.toArray(this); + } + + /** + * Compares two Vector3s + */ + @Override + public int compareTo(Vector3 o) + { + return Vector3.compareTo(this, o); + } + + /** + * Checks if two Vector3s are equal + */ + @Override + public boolean equals(Object o) + { + return Vector3.equals(this, o); + } + + /** + * toString Override + */ + @Override + public String toString() + { + return String.format("{ %f, %f, %f }", this.x, this.y, this.z); + } + + /** + * Returns the length of the given vector. + * + * Note: Makes use of Math.sqrt and + * is not cached, so can be slow + * + * Also known as norm. ||a|| + * + * @param a + * @return + */ + public static float length(Vector3 a) + { + return (float)Math.sqrt(lengthSquared(a)); + } + + /** + * Returns an approximate length of the given vector. + * + * @param a + * @return + */ + public static float fastLength(Vector3 a) + { + return (float)Math.sqrt(lengthSquared(a)); + } + + /** + * returns the length squared to the given vector + * + * @param a + * @return + */ + public static float lengthSquared(Vector3 a) + { + return Vector3.dot(a, a); + } + + /** + * Returns a new vector that is the given vector but length 1 + * + * @param a + * @return + */ + public static Vector3 normalize(Vector3 a) + { + return Vector3.scale(a, (1.f / a.length())); + } + + /** + * Creates a new vector that is A - B + * + * @param a + * @param b + * @return + */ + public static Vector3 subtract(Vector3 a, Vector3 b) + { + return new Vector3(a.getX() - b.getX(), a.getY() - b.getY(), a.getZ() - b.getZ()); + } + + /** + * Creates a new Vector that is A + B + * + * @param a + * @param b + * @return + */ + public static Vector3 add(Vector3 a, Vector3 b) + { + return new Vector3(a.getX() + b.getX(), a.getY() + b.getY(), a.getZ() + b.getZ()); + } + + /** + * Creates a new vector that is A multiplied by the uniform scalar B + * + * @param a + * @param b + * @return + */ + public static Vector3 scale(Vector3 a, float b) + { + return new Vector3(a.getX() * b, a.getY() * b, a.getZ() * b); + } + + /** + * Returns the dot product of A and B + * + * @param a + * @param b + * @return + */ + public static float dot(Vector3 a, Vector3 b) + { + return a.getX() * b.getX() + a.getY() * b.getY() + a.getZ() * b.getZ(); + } + + /** + * Creates a new Vector that is the A x B The Cross Product is the vector + * orthogonal to both A and B + * + * @param a + * @param b + * @return + */ + public static Vector3 cross(Vector3 a, Vector3 b) + { + return new Vector3(a.getY() * b.getZ() - a.getZ() * b.getY(), a.getZ() * b.getX() - a.getX() * b.getZ(), a.getX() * b.getY() - a.getY() * b.getX()); + } + + /** + * Rounds the X, Y, and Z values of the given Vector3 up to + * the nearest integer value. + * + * @param o Vector3 to use + * @return + */ + public static Vector3 ceil(Vector3 o) + { + return new Vector3(Math.ceil(o.x), Math.ceil(o.y), Math.ceil(o.z)); + } + + /** + * Rounds the X, Y, and Z values of the given Vector3 down to + * the nearest integer value. + * + * @param o Vector3 to use + * @return + */ + public static Vector3 floor(Vector3 o) + { + return new Vector3(Math.floor(o.x), Math.floor(o.y), Math.floor(o.z)); + } + + /** + * Rounds the X, Y, and Z values of the given Vector3 to + * the nearest integer value. + * + * @param o Vector3 to use + * @return + */ + public static Vector3 round(Vector3 o) + { + return new Vector3(Math.round(o.x), Math.round(o.y), Math.round(o.z)); + } + + /** + * Sets the X, Y, and Z values of the given Vector3 to their + * absolute value. + * + * @param o Vector3 to use + * @return + */ + public static Vector3 abs(Vector3 o) + { + return new Vector3(Math.abs(o.x), Math.abs(o.y), Math.abs(o.z)); + } + + /** + * Returns a Vector3 containing the smallest X, Y, and Z values. + * + * @param o1 + * @param o2 + * @return + */ + public static Vector3 min(Vector3 o1, Vector3 o2) + { + return new Vector3(Math.min(o1.x, o2.x), Math.min(o1.y, o2.y), Math.min(o1.z, o2.z)); + } + + /** + * Returns a Vector3 containing the largest X, Y, and Z values. + * + * @param o1 + * @param o2 + * @return + */ + public static Vector3 max(Vector3 o1, Vector3 o2) + { + return new Vector3(Math.max(o1.x, o2.x), Math.max(o1.y, o2.y), Math.max(o1.z, o2.z)); + } + + /** + * Returns a Vector3 with random X, Y, and Z values (between 0 and 1) + * + * @return + */ + public static Vector3 rand() + { + return new Vector3(Math.random(), Math.random(), Math.random()); + } + + /** + * Gets the distance between two Vector3. + * + * @param a + * @param b + * @return + */ + public static double distance(Vector3 a, Vector3 b) + { + double xzDist = Vector2.distance(a.toVector2(), b.toVector2()); + return Math.sqrt(Math.pow(xzDist, 2) + Math.pow(Math.abs(Vector3.subtract(a, b).getY()), 2)); + } + + /** + * Raises the X, Y, and Z values of a Vector3 to the given power. + * + * @param o + * @param power + * @return + */ + public static Vector3 pow(Vector3 o, double power) + { + return new Vector3(Math.pow(o.x, power), Math.pow(o.y, power), Math.pow(o.z, power)); + } + + /** + * Returns a Vector2 object using the X and Z values of + * the given Vector3. The x of the Vector3 becomes the x + * of the Vector2, and the z of this Vector3 becomes the + * y of the Vector2m. + * + * @param o Vector3 object to use + * @return + */ + public static Vector2 toVector2(Vector3 o) + { + return new Vector2(o.x, o.z); + } + + /** + * Returns a Vector2m object using the X and Z values of + * the given Vector3. The x of the Vector3 becomes the x + * of the Vector2m, and the z of this Vector3 becomes the + * y of the Vector2m. + * + * @param o Vector3 object to use + * @return + */ + public static Vector2m toVector2m(Vector3 o) + { + return new Vector2m(o.x, o.z); + } + + /** + * Returns a new float array that is {x, y, z} + * + * @param a + * @return + */ + public static float[] toArray(Vector3 a) + { + return new float[] { a.getX(), a.getY(), a.getZ() }; + } + + /** + * Compares two Vector3s + */ + public static int compareTo(Vector3 a, Vector3 b) + { + return (int)a.lengthSquared() - (int)b.lengthSquared(); + } + + /** + * Checks if two Vector3s are equal + */ + public static boolean equals(Object a, Object b) + { + if (!(a instanceof Vector3) || !(b instanceof Vector3)) + { + return false; + } + if (a == b) + { + return true; + } + Vector3 x = (Vector3)a; + Vector3 y = (Vector3)b; + if (x.getX() == y.getX() && x.getY() == y.getY() && x.getZ() == y.getZ()) + { + return true; + } + return false; + } + + @Override + public int hashCode() + { + return (int)(this.x * this.y % this.z); + } } diff --git a/src/main/java/wecui/util/Vector3m.java b/src/main/java/wecui/util/Vector3m.java index 64ed8f69..46481b44 100644 --- a/src/main/java/wecui/util/Vector3m.java +++ b/src/main/java/wecui/util/Vector3m.java @@ -5,93 +5,105 @@ * * @author yetanotherx */ -public class Vector3m extends Vector3 { - - public Vector3m(float x, float y, float z) { +public class Vector3m extends Vector3 +{ + + public Vector3m(float x, float y, float z) + { super(x, y, z); } - - public Vector3m(Double x, Double y, Double z) { + + public Vector3m(Double x, Double y, Double z) + { super(x, y, z); } - - public Vector3m(Vector3 vector) { + + public Vector3m(Vector3 vector) + { super(vector); } - - public Vector3m() { + + public Vector3m() + { } - - public void setZ(float z) { + + public void setZ(float z) + { this.z = z; } - - public void setY(float y) { + + public void setY(float y) + { this.y = y; } - - public void setX(float x) { + + public void setX(float x) + { this.x = x; } - + /** * Adds two vectors * * @param that * @return */ - + @Override - public Vector3 add(Vector3 that) { + public Vector3 add(Vector3 that) + { this.x += that.x; this.y += that.y; this.z += that.z; return this; } - + /** * Subtracts two vectors * * @param that * @return */ - + @Override - public Vector3 subtract(Vector3 that) { + public Vector3 subtract(Vector3 that) + { this.x -= that.x; this.y -= that.y; this.z -= that.z; return this; } - + /** * Scales by the scalar value * * @param scale * @return */ - + @Override - public Vector3 scale(float scale) { + public Vector3 scale(float scale) + { this.x *= scale; this.y *= scale; this.z *= scale; return this; } - + /** * Takes the cross product of two vectors * * @param that * @return */ - + @Override - public Vector3 cross(Vector3 that) { + public Vector3 cross(Vector3 that) + { this.x = this.getY() * that.getZ() - this.getZ() * that.getY(); this.y = this.getZ() * that.getX() - this.getX() * that.getZ(); this.z = this.getX() * that.getY() - this.getY() * that.getX(); - + return this; } @@ -102,10 +114,11 @@ public Vector3 cross(Vector3 that) { * @return */ @Override - public Vector3 ceil() { - this.x = (float) Math.ceil(this.x); - this.y = (float) Math.ceil(this.y); - this.z = (float) Math.ceil(this.z); + public Vector3 ceil() + { + this.x = (float)Math.ceil(this.x); + this.y = (float)Math.ceil(this.y); + this.z = (float)Math.ceil(this.z); return this; } @@ -116,10 +129,11 @@ public Vector3 ceil() { * @return */ @Override - public Vector3 floor() { - this.x = (float) Math.floor(this.x); - this.y = (float) Math.floor(this.y); - this.z = (float) Math.floor(this.z); + public Vector3 floor() + { + this.x = (float)Math.floor(this.x); + this.y = (float)Math.floor(this.y); + this.z = (float)Math.floor(this.z); return this; } @@ -130,7 +144,8 @@ public Vector3 floor() { * @return */ @Override - public Vector3 round() { + public Vector3 round() + { this.x = Math.round(this.x); this.y = Math.round(this.y); this.z = Math.round(this.z); @@ -144,21 +159,23 @@ public Vector3 round() { * @return */ @Override - public Vector3 abs() { + public Vector3 abs() + { this.x = Math.abs(this.x); this.y = Math.abs(this.y); this.z = Math.abs(this.z); return this; } - + /** * returns the vector with a length of 1 * * @return */ - + @Override - public Vector3 normalize() { + public Vector3 normalize() + { float length = this.length(); this.x *= 1 / length; this.y *= 1 / length; diff --git a/src/main/java/wecui/vendor/org/joor/Reflect.java b/src/main/java/wecui/vendor/org/joor/Reflect.java index 0d731c29..e10fac9e 100644 --- a/src/main/java/wecui/vendor/org/joor/Reflect.java +++ b/src/main/java/wecui/vendor/org/joor/Reflect.java @@ -62,476 +62,556 @@ * * @author Lukas Eder */ -public class Reflect { - - // --------------------------------------------------------------------- - // Static API used as entrance points to the fluent API - // --------------------------------------------------------------------- - /** - * Wrap a class name. - *

- * This is the same as calling on(Class.forName(name)) - * - * @param name A fully qualified class name - * @return A wrapped class object, to be used for further reflection. - * @throws ReflectException If any reflection exception occurred. - * @see #on(Class) - */ - public static Reflect on(String name) throws ReflectException { - return on(forName(name)); - } - - /** - * Wrap a class. - *

- * Use this when you want to access static fields and methods on a - * {@link Class} object, or as a basis for constructing objects of that - * class using {@link #create(Object...)} - * - * @param clazz The class to be wrapped - * @return A wrapped class object, to be used for further reflection. - */ - public static Reflect on(Class clazz) { - return new Reflect(clazz); - } - - /** - * Wrap an object. - *

- * Use this when you want to access instance fields and methods on any - * {@link Object} - * - * @param object The object to be wrapped - * @return A wrapped object, to be used for further reflection. - */ - public static Reflect on(Object object) { - return new Reflect(object); - } - // --------------------------------------------------------------------- - // Members - // --------------------------------------------------------------------- - /** - * The wrapped object - */ - private final Object object; - /** - * A flag indicating whether the wrapped object is a {@link Class} (for - * accessing static fields and methods), or any other type of {@link Object} - * (for accessing instance fields and methods). - */ - private final boolean isClass; - - // --------------------------------------------------------------------- - // Constructors - // --------------------------------------------------------------------- - private Reflect(Class type) { - this.object = type; - this.isClass = true; - } - - private Reflect(Object object) { - this.object = object; - this.isClass = false; - } - - // --------------------------------------------------------------------- - // Fluent Configuration API - // --------------------------------------------------------------------- - // TO_DO: Allow for accessing non-public members, methods, etc - // --------------------------------------------------------------------- - // Fluent Reflection API - // --------------------------------------------------------------------- - /** - * Get the wrapped object - * - * @param A convenience generic parameter for automatic unsafe casting - */ - @SuppressWarnings("unchecked") - public T get() { - return (T) this.object; - } - - /** - * Set a field value. - *

- * This is roughly equivalent to {@link Field#set(Object, Object)}. If the - * wrapped object is a {@link Class}, then this will set a value to a static - * member field. If the wrapped object is any other {@link Object}, then - * this will set a value to an instance member field. - * - * @param name The field name - * @param value The new field value - * @return The same wrapped object, to be used for further reflection. - * @throws ReflectException If any reflection exception occurred. - */ - public Reflect set(String name, Object value) throws ReflectException { - try { - Field field = this.type().getField(name); - if (!field.isAccessible()) { - field.setAccessible(true); - } - field.set(this.object, unwrap(value)); - return this; - } catch (Exception e) { - throw new ReflectException(e); - } - } - - /** - * Get a field value. - *

- * This is roughly equivalent to {@link Field#get(Object)}. If the wrapped - * object is a {@link Class}, then this will get a value from a static - * member field. If the wrapped object is any other {@link Object}, then - * this will get a value from an instance member field. - *

- * If you want to "navigate" to a wrapped version of the field, use - * {@link #field(String)} instead. - * - * @param name The field name - * @return The field value - * @throws ReflectException If any reflection exception occurred. - * @see #field(String) - */ - public Object get(String name) throws ReflectException { - return this.field(name).get(); - } - - /** - * Get a wrapped field. - *

- * This is roughly equivalent to {@link Field#get(Object)}. If the wrapped - * object is a {@link Class}, then this will wrap a static member field. If - * the wrapped object is any other {@link Object}, then this wrap an - * instance member field. - * - * @param name The field name - * @return The wrapped field - * @throws ReflectException If any reflection exception occurred. - */ - public Reflect field(String name) throws ReflectException { - try { - Field field = this.type().getField(name); - if (!field.isAccessible()) { - field.setAccessible(true); - } - return on(field.get(this.object)); - } catch (Exception e) { - throw new ReflectException(e); - } - } - - /** - * Get a Map containing field names and wrapped values for the fields' - * values. - *

- * If the wrapped object is a {@link Class}, then this will return static - * fields. If the wrapped object is any other {@link Object}, then this will - * return instance fields. - *

- * These two calls are equivalent

-     * on(object).field("myField");
-     * on(object).fields().get("myField");
-     * 
- * - * @return A map containing field names and wrapped values. - */ - public Map fields() { - Map result = new LinkedHashMap(); - - for (Field field : this.type().getFields()) { - if (!this.isClass ^ Modifier.isStatic(field.getModifiers())) { - String name = field.getName(); - result.put(name, this.field(name)); - } - } - - return result; - } - - /** - * Call a method by its name. - *

- * This is a convenience method for calling - * call(name, new Object[0]) - * - * @param name The method name - * @return The wrapped method result or the same wrapped object if the - * method returns void, to be used for further - * reflection. - * @throws ReflectException If any reflection exception occurred. - * @see #call(String, Object...) - */ - public Reflect call(String name) throws ReflectException { - return this.call(name, new Object[0]); - } - - /** - * Call a method by its name. - *

- * This is roughly equivalent to {@link Method#invoke(Object, Object...)}. - * If the wrapped object is a {@link Class}, then this will invoke a static - * method. If the wrapped object is any other {@link Object}, then this will - * invoke an instance method. - *

- * Just like {@link Method#invoke(Object, Object...)}, this will try to wrap - * primitive types or unwrap primitive type wrappers if applicable. If - * several methods are applicable, by that rule, the first one encountered - * is called. i.e. when calling

-     * on(...).call("method", 1, 1);
-     * 
The first of the following methods will be called: - *
-     * public void method(int param1, Integer param2);
-     * public void method(Integer param1, int param2);
-     * public void method(Number param1, Number param2);
-     * public void method(Number param1, Object param2);
-     * public void method(int param1, Object param2);
-     * 
- * - * @param name The method name - * @param args The method arguments - * @return The wrapped method result or the same wrapped object if the - * method returns void, to be used for further - * reflection. - * @throws ReflectException If any reflection exception occurred. - */ - public Reflect call(String name, Object... args) throws ReflectException { - Class[] types = types(args); - - // Try invoking the "canonical" method, i.e. the one with exact - // matching argument types - try { - Method method = this.type().getMethod(name, types); - return on(method, this.object, args); - } // If there is no exact match, try to find one that has a "similar" - // signature if primitive argument types are converted to their wrappers - catch (NoSuchMethodException e) { - for (Method method : this.type().getMethods()) { - if (method.getName().equals(name) && this.match(method.getParameterTypes(), types)) { - return on(method, this.object, args); - } - } - - throw new ReflectException(e); - } - } - - /** - * Call a constructor. - *

- * This is a convenience method for calling - * create(new Object[0]) - * - * @return The wrapped new object, to be used for further reflection. - * @throws ReflectException If any reflection exception occurred. - * @see #create(Object...) - */ - public Reflect create() throws ReflectException { - return this.create(new Object[0]); - } - - /** - * Call a constructor. - *

- * This is roughly equivalent to {@link Constructor#newInstance(Object...)}. - * If the wrapped object is a {@link Class}, then this will create a new - * object of that class. If the wrapped object is any other {@link Object}, - * then this will create a new object of the same type. - *

- * Just like {@link Constructor#newInstance(Object...)}, this will try to - * wrap primitive types or unwrap primitive type wrappers if applicable. If - * several constructors are applicable, by that rule, the first one - * encountered is called. i.e. when calling

-     * on(C.class).create(1, 1);
-     * 
The first of the following constructors will be applied: - *
-     * public C(int param1, Integer param2);
-     * public C(Integer param1, int param2);
-     * public C(Number param1, Number param2);
-     * public C(Number param1, Object param2);
-     * public C(int param1, Object param2);
-     * 
- * - * @param args The constructor arguments - * @return The wrapped new object, to be used for further reflection. - * @throws ReflectException If any reflection exception occurred. - */ - public Reflect create(Object... args) throws ReflectException { - Class[] types = types(args); - - // Try invoking the "canonical" constructor, i.e. the one with exact - // matching argument types - try { - Constructor constructor = this.type().getConstructor(types); - return on(constructor, args); - } // If there is no exact match, try to find one that has a "similar" - // signature if primitive argument types are converted to their wrappers - catch (NoSuchMethodException e) { - for (Constructor constructor : this.type().getConstructors()) { - if (this.match(constructor.getParameterTypes(), types)) { - return on(constructor, args); - } - } - - throw new ReflectException(e); - } - } - - // --------------------------------------------------------------------- - // Object API - // --------------------------------------------------------------------- - /** - * Check whether two arrays of types match, converting primitive types to - * their corresponding wrappers. - */ - private boolean match(Class[] declaredTypes, Class[] actualTypes) { - if (declaredTypes.length == actualTypes.length) { - for (int i = 0; i < actualTypes.length; i++) { - if (!wrapper(declaredTypes[i]).isAssignableFrom(wrapper(actualTypes[i]))) { - return false; - } - } - - return true; - } +public class Reflect +{ + + // --------------------------------------------------------------------- + // Static API used as entrance points to the fluent API + // --------------------------------------------------------------------- + /** + * Wrap a class name. + *

+ * This is the same as calling on(Class.forName(name)) + * + * @param name A fully qualified class name + * @return A wrapped class object, to be used for further reflection. + * @throws ReflectException If any reflection exception occurred. + * @see #on(Class) + */ + public static Reflect on(String name) throws ReflectException + { + return on(forName(name)); + } + + /** + * Wrap a class. + *

+ * Use this when you want to access static fields and methods on a + * {@link Class} object, or as a basis for constructing objects of that + * class using {@link #create(Object...)} + * + * @param clazz The class to be wrapped + * @return A wrapped class object, to be used for further reflection. + */ + public static Reflect on(Class clazz) + { + return new Reflect(clazz); + } + + /** + * Wrap an object. + *

+ * Use this when you want to access instance fields and methods on any + * {@link Object} + * + * @param object The object to be wrapped + * @return A wrapped object, to be used for further reflection. + */ + public static Reflect on(Object object) + { + return new Reflect(object); + } + + // --------------------------------------------------------------------- + // Members + // --------------------------------------------------------------------- + /** + * The wrapped object + */ + private final Object object; + /** + * A flag indicating whether the wrapped object is a {@link Class} (for + * accessing static fields and methods), or any other type of {@link Object} + * (for accessing instance fields and methods). + */ + private final boolean isClass; + + // --------------------------------------------------------------------- + // Constructors + // --------------------------------------------------------------------- + private Reflect(Class type) + { + this.object = type; + this.isClass = true; + } + + private Reflect(Object object) + { + this.object = object; + this.isClass = false; + } + + // --------------------------------------------------------------------- + // Fluent Configuration API + // --------------------------------------------------------------------- + // TO_DO: Allow for accessing non-public members, methods, etc + // --------------------------------------------------------------------- + // Fluent Reflection API + // --------------------------------------------------------------------- + /** + * Get the wrapped object + * + * @param A convenience generic parameter for automatic unsafe casting + */ + @SuppressWarnings("unchecked") + public T get() + { + return (T)this.object; + } + + /** + * Set a field value. + *

+ * This is roughly equivalent to {@link Field#set(Object, Object)}. If the + * wrapped object is a {@link Class}, then this will set a value to a static + * member field. If the wrapped object is any other {@link Object}, then + * this will set a value to an instance member field. + * + * @param name The field name + * @param value The new field value + * @return The same wrapped object, to be used for further reflection. + * @throws ReflectException If any reflection exception occurred. + */ + public Reflect set(String name, Object value) throws ReflectException + { + try + { + Field field = this.type().getField(name); + if (!field.isAccessible()) + { + field.setAccessible(true); + } + field.set(this.object, unwrap(value)); + return this; + } + catch (Exception e) + { + throw new ReflectException(e); + } + } + + /** + * Get a field value. + *

+ * This is roughly equivalent to {@link Field#get(Object)}. If the wrapped + * object is a {@link Class}, then this will get a value from a static + * member field. If the wrapped object is any other {@link Object}, then + * this will get a value from an instance member field. + *

+ * If you want to "navigate" to a wrapped version of the field, use + * {@link #field(String)} instead. + * + * @param name The field name + * @return The field value + * @throws ReflectException If any reflection exception occurred. + * @see #field(String) + */ + public Object get(String name) throws ReflectException + { + return this.field(name).get(); + } + + /** + * Get a wrapped field. + *

+ * This is roughly equivalent to {@link Field#get(Object)}. If the wrapped + * object is a {@link Class}, then this will wrap a static member field. If + * the wrapped object is any other {@link Object}, then this wrap an + * instance member field. + * + * @param name The field name + * @return The wrapped field + * @throws ReflectException If any reflection exception occurred. + */ + public Reflect field(String name) throws ReflectException + { + try + { + Field field = this.type().getField(name); + if (!field.isAccessible()) + { + field.setAccessible(true); + } + return on(field.get(this.object)); + } + catch (Exception e) + { + throw new ReflectException(e); + } + } + + /** + * Get a Map containing field names and wrapped values for the fields' + * values. + *

+ * If the wrapped object is a {@link Class}, then this will return static + * fields. If the wrapped object is any other {@link Object}, then this will + * return instance fields. + *

+ * These two calls are equivalent

+	 * on(object).field("myField");
+	 * on(object).fields().get("myField");
+	 * 
+ * + * @return A map containing field names and wrapped values. + */ + public Map fields() + { + Map result = new LinkedHashMap(); + + for (Field field : this.type().getFields()) + { + if (!this.isClass ^ Modifier.isStatic(field.getModifiers())) + { + String name = field.getName(); + result.put(name, this.field(name)); + } + } + + return result; + } + + /** + * Call a method by its name. + *

+ * This is a convenience method for calling + * call(name, new Object[0]) + * + * @param name The method name + * @return The wrapped method result or the same wrapped object if the + * method returns void, to be used for further + * reflection. + * @throws ReflectException If any reflection exception occurred. + * @see #call(String, Object...) + */ + public Reflect call(String name) throws ReflectException + { + return this.call(name, new Object[0]); + } + + /** + * Call a method by its name. + *

+ * This is roughly equivalent to {@link Method#invoke(Object, Object...)}. + * If the wrapped object is a {@link Class}, then this will invoke a static + * method. If the wrapped object is any other {@link Object}, then this will + * invoke an instance method. + *

+ * Just like {@link Method#invoke(Object, Object...)}, this will try to wrap + * primitive types or unwrap primitive type wrappers if applicable. If + * several methods are applicable, by that rule, the first one encountered + * is called. i.e. when calling

+	 * on(...).call("method", 1, 1);
+	 * 
The first of the following methods will be called: + *
+	 * public void method(int param1, Integer param2);
+	 * public void method(Integer param1, int param2);
+	 * public void method(Number param1, Number param2);
+	 * public void method(Number param1, Object param2);
+	 * public void method(int param1, Object param2);
+	 * 
+ * + * @param name The method name + * @param args The method arguments + * @return The wrapped method result or the same wrapped object if the + * method returns void, to be used for further + * reflection. + * @throws ReflectException If any reflection exception occurred. + */ + public Reflect call(String name, Object... args) throws ReflectException + { + Class[] types = types(args); + + // Try invoking the "canonical" method, i.e. the one with exact + // matching argument types + try + { + Method method = this.type().getMethod(name, types); + return on(method, this.object, args); + } // If there is no exact match, try to find one that has a "similar" + // signature if primitive argument types are converted to their wrappers + catch (NoSuchMethodException e) + { + for (Method method : this.type().getMethods()) + { + if (method.getName().equals(name) && this.match(method.getParameterTypes(), types)) + { + return on(method, this.object, args); + } + } + + throw new ReflectException(e); + } + } + + /** + * Call a constructor. + *

+ * This is a convenience method for calling + * create(new Object[0]) + * + * @return The wrapped new object, to be used for further reflection. + * @throws ReflectException If any reflection exception occurred. + * @see #create(Object...) + */ + public Reflect create() throws ReflectException + { + return this.create(new Object[0]); + } + + /** + * Call a constructor. + *

+ * This is roughly equivalent to {@link Constructor#newInstance(Object...)}. + * If the wrapped object is a {@link Class}, then this will create a new + * object of that class. If the wrapped object is any other {@link Object}, + * then this will create a new object of the same type. + *

+ * Just like {@link Constructor#newInstance(Object...)}, this will try to + * wrap primitive types or unwrap primitive type wrappers if applicable. If + * several constructors are applicable, by that rule, the first one + * encountered is called. i.e. when calling

+	 * on(C.class).create(1, 1);
+	 * 
The first of the following constructors will be applied: + *
+	 * public C(int param1, Integer param2);
+	 * public C(Integer param1, int param2);
+	 * public C(Number param1, Number param2);
+	 * public C(Number param1, Object param2);
+	 * public C(int param1, Object param2);
+	 * 
+ * + * @param args The constructor arguments + * @return The wrapped new object, to be used for further reflection. + * @throws ReflectException If any reflection exception occurred. + */ + public Reflect create(Object... args) throws ReflectException + { + Class[] types = types(args); + + // Try invoking the "canonical" constructor, i.e. the one with exact + // matching argument types + try + { + Constructor constructor = this.type().getConstructor(types); + return on(constructor, args); + } // If there is no exact match, try to find one that has a "similar" + // signature if primitive argument types are converted to their wrappers + catch (NoSuchMethodException e) + { + for (Constructor constructor : this.type().getConstructors()) + { + if (this.match(constructor.getParameterTypes(), types)) + { + return on(constructor, args); + } + } + + throw new ReflectException(e); + } + } + + // --------------------------------------------------------------------- + // Object API + // --------------------------------------------------------------------- + /** + * Check whether two arrays of types match, converting primitive types to + * their corresponding wrappers. + */ + private boolean match(Class[] declaredTypes, Class[] actualTypes) + { + if (declaredTypes.length == actualTypes.length) + { + for (int i = 0; i < actualTypes.length; i++) + { + if (!wrapper(declaredTypes[i]).isAssignableFrom(wrapper(actualTypes[i]))) + { + return false; + } + } + + return true; + } return false; - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.object.hashCode(); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (obj instanceof Reflect) { - return this.object.equals(((Reflect) obj).get()); - } - - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return this.object.toString(); - } - - // --------------------------------------------------------------------- - // Utility methods - // --------------------------------------------------------------------- - /** - * Wrap an object created from a constructor - */ - private static Reflect on(Constructor constructor, Object... args) throws ReflectException { - try { - return on(constructor.newInstance(args)); - } catch (Exception e) { - throw new ReflectException(e); - } - } - - /** - * Wrap an object returned from a method - */ - private static Reflect on(Method method, Object object, Object... args) throws ReflectException { - try { - if (method.getReturnType() == void.class) { - method.invoke(object, args); - return on(object); - } + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() + { + return this.object.hashCode(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) + { + if (obj instanceof Reflect) + { + return this.object.equals(((Reflect)obj).get()); + } + + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() + { + return this.object.toString(); + } + + // --------------------------------------------------------------------- + // Utility methods + // --------------------------------------------------------------------- + /** + * Wrap an object created from a constructor + */ + private static Reflect on(Constructor constructor, Object... args) throws ReflectException + { + try + { + return on(constructor.newInstance(args)); + } + catch (Exception e) + { + throw new ReflectException(e); + } + } + + /** + * Wrap an object returned from a method + */ + private static Reflect on(Method method, Object object, Object... args) throws ReflectException + { + try + { + if (method.getReturnType() == void.class) + { + method.invoke(object, args); + return on(object); + } return on(method.invoke(object, args)); - } catch (Exception e) { - throw new ReflectException(e); - } - } - - /** - * Unwrap an object - */ - private static Object unwrap(Object object) { - if (object instanceof Reflect) { - return ((Reflect) object).get(); - } - - return object; - } - - /** - * Get an array of types for an array of objects - * - * @see Object#getClass() - */ - private static Class[] types(Object... values) { - if (values == null) { - return new Class[0]; - } - - Class[] result = new Class[values.length]; - - for (int i = 0; i < values.length; i++) { - result[i] = values[i].getClass(); - } - - return result; - } - - /** - * Load a class - * - * @see Class#forName(String) - */ - private static Class forName(String name) throws ReflectException { - try { - return Class.forName(name); - } catch (Exception e) { - throw new ReflectException(e); - } - } - - /** - * Get the type of the wrapped object. - * - * @see Object#getClass() - */ - private Class type() { - if (this.isClass) { - return (Class) this.object; - } + } + catch (Exception e) + { + throw new ReflectException(e); + } + } + + /** + * Unwrap an object + */ + private static Object unwrap(Object object) + { + if (object instanceof Reflect) + { + return ((Reflect)object).get(); + } + + return object; + } + + /** + * Get an array of types for an array of objects + * + * @see Object#getClass() + */ + private static Class[] types(Object... values) + { + if (values == null) + { + return new Class[0]; + } + + Class[] result = new Class[values.length]; + + for (int i = 0; i < values.length; i++) + { + result[i] = values[i].getClass(); + } + + return result; + } + + /** + * Load a class + * + * @see Class#forName(String) + */ + private static Class forName(String name) throws ReflectException + { + try + { + return Class.forName(name); + } + catch (Exception e) + { + throw new ReflectException(e); + } + } + + /** + * Get the type of the wrapped object. + * + * @see Object#getClass() + */ + private Class type() + { + if (this.isClass) + { + return (Class)this.object; + } return this.object.getClass(); - } - - /** - * Get a wrapper type for a primitive type, or the argument type itself, if - * it is not a primitive type. - */ - private static Class wrapper(Class type) { - if (boolean.class == type) { - return Boolean.class; - } else if (int.class == type) { - return Integer.class; - } else if (long.class == type) { - return Long.class; - } else if (short.class == type) { - return Short.class; - } else if (byte.class == type) { - return Byte.class; - } else if (double.class == type) { - return Double.class; - } else if (float.class == type) { - return Float.class; - } else if (char.class == type) { - return Character.class; - } else { - return type; - } - } -} \ No newline at end of file + } + + /** + * Get a wrapper type for a primitive type, or the argument type itself, if + * it is not a primitive type. + */ + private static Class wrapper(Class type) + { + if (boolean.class == type) + { + return Boolean.class; + } + else if (int.class == type) + { + return Integer.class; + } + else if (long.class == type) + { + return Long.class; + } + else if (short.class == type) + { + return Short.class; + } + else if (byte.class == type) + { + return Byte.class; + } + else if (double.class == type) + { + return Double.class; + } + else if (float.class == type) + { + return Float.class; + } + else if (char.class == type) + { + return Character.class; + } + else + { + return type; + } + } +} From 2d87782b1db628c6ebba680bf1bf272adc867dd6 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Tue, 21 Jan 2014 17:43:52 +0000 Subject: [PATCH 09/51] This is not a maven project any more --- .classpath | 2 +- .project | 17 ----------------- {src/main/java => java}/wecui/CUIDebug.java | 0 .../wecui/InitializationFactory.java | 0 .../wecui/LiteModWorldEditCUI.java | 0 .../main/java => java}/wecui/WorldEditCUI.java | 0 .../wecui/config/CUIConfiguration.java | 0 .../java => java}/wecui/config/Colour.java | 0 .../java => java}/wecui/event/CUIEvent.java | 0 .../wecui/event/cui/CUIBaseEvent.java | 0 .../wecui/event/cui/CUICylinderEvent.java | 0 .../wecui/event/cui/CUIEllipsoidEvent.java | 0 .../wecui/event/cui/CUIEventType.java | 0 .../wecui/event/cui/CUIMinMaxEvent.java | 0 .../wecui/event/cui/CUIPoint2DEvent.java | 0 .../wecui/event/cui/CUIPointEvent.java | 0 .../wecui/event/cui/CUIPolygonEvent.java | 0 .../wecui/event/cui/CUISelectionEvent.java | 0 .../wecui/event/cui/CUIUpdateEvent.java | 0 .../wecui/event/listeners/ChannelListener.java | 0 .../event/listeners/WorldRenderListener.java | 0 .../exception/InitializationException.java | 0 .../wecui/exception/ReflectException.java | 0 .../wecui/gui/GuiColourButton.java | 0 .../wecui/gui/GuiColourPicker.java | 0 .../java => java}/wecui/gui/GuiControl.java | 0 .../wecui/gui/WorldEditCUIConfigPanel.java | 0 .../java => java}/wecui/render/LineColor.java | 0 .../java => java}/wecui/render/LineInfo.java | 0 .../wecui/render/points/PointCube.java | 0 .../wecui/render/points/PointRectangle.java | 0 .../wecui/render/region/BaseRegion.java | 0 .../wecui/render/region/CuboidRegion.java | 0 .../wecui/render/region/CylinderRegion.java | 0 .../wecui/render/region/EllipsoidRegion.java | 0 .../wecui/render/region/PolygonRegion.java | 0 .../wecui/render/region/PolyhedronRegion.java | 0 .../wecui/render/region/RegionType.java | 0 .../wecui/render/shapes/Render2DBox.java | 0 .../wecui/render/shapes/Render2DGrid.java | 0 .../wecui/render/shapes/Render3DBox.java | 0 .../wecui/render/shapes/Render3DGrid.java | 0 .../wecui/render/shapes/Render3DPolygon.java | 0 .../wecui/render/shapes/RenderCylinderBox.java | 0 .../render/shapes/RenderCylinderCircles.java | 0 .../render/shapes/RenderCylinderGrid.java | 0 .../wecui/render/shapes/RenderEllipsoid.java | 0 .../wecui/util/ConsoleLogFormatter.java | 0 .../java => java}/wecui/util/Utilities.java | 0 .../main/java => java}/wecui/util/Vector2.java | 0 .../java => java}/wecui/util/Vector2m.java | 0 .../main/java => java}/wecui/util/Vector3.java | 0 .../java => java}/wecui/util/Vector3m.java | 0 .../wecui/vendor/org/joor/Reflect.java | 0 .../assets/wecui/lang/en_US.lang | 0 .../assets/wecui/textures/gui/checker.png | Bin .../assets/wecui/textures/gui/picker.png | Bin 57 files changed, 1 insertion(+), 18 deletions(-) rename {src/main/java => java}/wecui/CUIDebug.java (100%) rename {src/main/java => java}/wecui/InitializationFactory.java (100%) rename {src/main/java => java}/wecui/LiteModWorldEditCUI.java (100%) rename {src/main/java => java}/wecui/WorldEditCUI.java (100%) rename {src/main/java => java}/wecui/config/CUIConfiguration.java (100%) rename {src/main/java => java}/wecui/config/Colour.java (100%) rename {src/main/java => java}/wecui/event/CUIEvent.java (100%) rename {src/main/java => java}/wecui/event/cui/CUIBaseEvent.java (100%) rename {src/main/java => java}/wecui/event/cui/CUICylinderEvent.java (100%) rename {src/main/java => java}/wecui/event/cui/CUIEllipsoidEvent.java (100%) rename {src/main/java => java}/wecui/event/cui/CUIEventType.java (100%) rename {src/main/java => java}/wecui/event/cui/CUIMinMaxEvent.java (100%) rename {src/main/java => java}/wecui/event/cui/CUIPoint2DEvent.java (100%) rename {src/main/java => java}/wecui/event/cui/CUIPointEvent.java (100%) rename {src/main/java => java}/wecui/event/cui/CUIPolygonEvent.java (100%) rename {src/main/java => java}/wecui/event/cui/CUISelectionEvent.java (100%) rename {src/main/java => java}/wecui/event/cui/CUIUpdateEvent.java (100%) rename {src/main/java => java}/wecui/event/listeners/ChannelListener.java (100%) rename {src/main/java => java}/wecui/event/listeners/WorldRenderListener.java (100%) rename {src/main/java => java}/wecui/exception/InitializationException.java (100%) rename {src/main/java => java}/wecui/exception/ReflectException.java (100%) rename {src/main/java => java}/wecui/gui/GuiColourButton.java (100%) rename {src/main/java => java}/wecui/gui/GuiColourPicker.java (100%) rename {src/main/java => java}/wecui/gui/GuiControl.java (100%) rename {src/main/java => java}/wecui/gui/WorldEditCUIConfigPanel.java (100%) rename {src/main/java => java}/wecui/render/LineColor.java (100%) rename {src/main/java => java}/wecui/render/LineInfo.java (100%) rename {src/main/java => java}/wecui/render/points/PointCube.java (100%) rename {src/main/java => java}/wecui/render/points/PointRectangle.java (100%) rename {src/main/java => java}/wecui/render/region/BaseRegion.java (100%) rename {src/main/java => java}/wecui/render/region/CuboidRegion.java (100%) rename {src/main/java => java}/wecui/render/region/CylinderRegion.java (100%) rename {src/main/java => java}/wecui/render/region/EllipsoidRegion.java (100%) rename {src/main/java => java}/wecui/render/region/PolygonRegion.java (100%) rename {src/main/java => java}/wecui/render/region/PolyhedronRegion.java (100%) rename {src/main/java => java}/wecui/render/region/RegionType.java (100%) rename {src/main/java => java}/wecui/render/shapes/Render2DBox.java (100%) rename {src/main/java => java}/wecui/render/shapes/Render2DGrid.java (100%) rename {src/main/java => java}/wecui/render/shapes/Render3DBox.java (100%) rename {src/main/java => java}/wecui/render/shapes/Render3DGrid.java (100%) rename {src/main/java => java}/wecui/render/shapes/Render3DPolygon.java (100%) rename {src/main/java => java}/wecui/render/shapes/RenderCylinderBox.java (100%) rename {src/main/java => java}/wecui/render/shapes/RenderCylinderCircles.java (100%) rename {src/main/java => java}/wecui/render/shapes/RenderCylinderGrid.java (100%) rename {src/main/java => java}/wecui/render/shapes/RenderEllipsoid.java (100%) rename {src/main/java => java}/wecui/util/ConsoleLogFormatter.java (100%) rename {src/main/java => java}/wecui/util/Utilities.java (100%) rename {src/main/java => java}/wecui/util/Vector2.java (100%) rename {src/main/java => java}/wecui/util/Vector2m.java (100%) rename {src/main/java => java}/wecui/util/Vector3.java (100%) rename {src/main/java => java}/wecui/util/Vector3m.java (100%) rename {src/main/java => java}/wecui/vendor/org/joor/Reflect.java (100%) rename {src/main/resources => res}/assets/wecui/lang/en_US.lang (100%) rename {src/main/resources => res}/assets/wecui/textures/gui/checker.png (100%) rename {src/main/resources => res}/assets/wecui/textures/gui/picker.png (100%) diff --git a/.classpath b/.classpath index 104b1ead..c7eed1f5 100644 --- a/.classpath +++ b/.classpath @@ -1,7 +1,7 @@ - + diff --git a/.project b/.project index 35052922..2b062ce5 100644 --- a/.project +++ b/.project @@ -14,23 +14,6 @@ org.eclipse.jdt.core.javanature - - - java - 2 - PROJECT_LOC/src/main/java - - - res - 2 - PROJECT_LOC/src/main/resources - - - resources - 2 - PROJECT_LOC/src/main/resources - - MCP_LOC diff --git a/src/main/java/wecui/CUIDebug.java b/java/wecui/CUIDebug.java similarity index 100% rename from src/main/java/wecui/CUIDebug.java rename to java/wecui/CUIDebug.java diff --git a/src/main/java/wecui/InitializationFactory.java b/java/wecui/InitializationFactory.java similarity index 100% rename from src/main/java/wecui/InitializationFactory.java rename to java/wecui/InitializationFactory.java diff --git a/src/main/java/wecui/LiteModWorldEditCUI.java b/java/wecui/LiteModWorldEditCUI.java similarity index 100% rename from src/main/java/wecui/LiteModWorldEditCUI.java rename to java/wecui/LiteModWorldEditCUI.java diff --git a/src/main/java/wecui/WorldEditCUI.java b/java/wecui/WorldEditCUI.java similarity index 100% rename from src/main/java/wecui/WorldEditCUI.java rename to java/wecui/WorldEditCUI.java diff --git a/src/main/java/wecui/config/CUIConfiguration.java b/java/wecui/config/CUIConfiguration.java similarity index 100% rename from src/main/java/wecui/config/CUIConfiguration.java rename to java/wecui/config/CUIConfiguration.java diff --git a/src/main/java/wecui/config/Colour.java b/java/wecui/config/Colour.java similarity index 100% rename from src/main/java/wecui/config/Colour.java rename to java/wecui/config/Colour.java diff --git a/src/main/java/wecui/event/CUIEvent.java b/java/wecui/event/CUIEvent.java similarity index 100% rename from src/main/java/wecui/event/CUIEvent.java rename to java/wecui/event/CUIEvent.java diff --git a/src/main/java/wecui/event/cui/CUIBaseEvent.java b/java/wecui/event/cui/CUIBaseEvent.java similarity index 100% rename from src/main/java/wecui/event/cui/CUIBaseEvent.java rename to java/wecui/event/cui/CUIBaseEvent.java diff --git a/src/main/java/wecui/event/cui/CUICylinderEvent.java b/java/wecui/event/cui/CUICylinderEvent.java similarity index 100% rename from src/main/java/wecui/event/cui/CUICylinderEvent.java rename to java/wecui/event/cui/CUICylinderEvent.java diff --git a/src/main/java/wecui/event/cui/CUIEllipsoidEvent.java b/java/wecui/event/cui/CUIEllipsoidEvent.java similarity index 100% rename from src/main/java/wecui/event/cui/CUIEllipsoidEvent.java rename to java/wecui/event/cui/CUIEllipsoidEvent.java diff --git a/src/main/java/wecui/event/cui/CUIEventType.java b/java/wecui/event/cui/CUIEventType.java similarity index 100% rename from src/main/java/wecui/event/cui/CUIEventType.java rename to java/wecui/event/cui/CUIEventType.java diff --git a/src/main/java/wecui/event/cui/CUIMinMaxEvent.java b/java/wecui/event/cui/CUIMinMaxEvent.java similarity index 100% rename from src/main/java/wecui/event/cui/CUIMinMaxEvent.java rename to java/wecui/event/cui/CUIMinMaxEvent.java diff --git a/src/main/java/wecui/event/cui/CUIPoint2DEvent.java b/java/wecui/event/cui/CUIPoint2DEvent.java similarity index 100% rename from src/main/java/wecui/event/cui/CUIPoint2DEvent.java rename to java/wecui/event/cui/CUIPoint2DEvent.java diff --git a/src/main/java/wecui/event/cui/CUIPointEvent.java b/java/wecui/event/cui/CUIPointEvent.java similarity index 100% rename from src/main/java/wecui/event/cui/CUIPointEvent.java rename to java/wecui/event/cui/CUIPointEvent.java diff --git a/src/main/java/wecui/event/cui/CUIPolygonEvent.java b/java/wecui/event/cui/CUIPolygonEvent.java similarity index 100% rename from src/main/java/wecui/event/cui/CUIPolygonEvent.java rename to java/wecui/event/cui/CUIPolygonEvent.java diff --git a/src/main/java/wecui/event/cui/CUISelectionEvent.java b/java/wecui/event/cui/CUISelectionEvent.java similarity index 100% rename from src/main/java/wecui/event/cui/CUISelectionEvent.java rename to java/wecui/event/cui/CUISelectionEvent.java diff --git a/src/main/java/wecui/event/cui/CUIUpdateEvent.java b/java/wecui/event/cui/CUIUpdateEvent.java similarity index 100% rename from src/main/java/wecui/event/cui/CUIUpdateEvent.java rename to java/wecui/event/cui/CUIUpdateEvent.java diff --git a/src/main/java/wecui/event/listeners/ChannelListener.java b/java/wecui/event/listeners/ChannelListener.java similarity index 100% rename from src/main/java/wecui/event/listeners/ChannelListener.java rename to java/wecui/event/listeners/ChannelListener.java diff --git a/src/main/java/wecui/event/listeners/WorldRenderListener.java b/java/wecui/event/listeners/WorldRenderListener.java similarity index 100% rename from src/main/java/wecui/event/listeners/WorldRenderListener.java rename to java/wecui/event/listeners/WorldRenderListener.java diff --git a/src/main/java/wecui/exception/InitializationException.java b/java/wecui/exception/InitializationException.java similarity index 100% rename from src/main/java/wecui/exception/InitializationException.java rename to java/wecui/exception/InitializationException.java diff --git a/src/main/java/wecui/exception/ReflectException.java b/java/wecui/exception/ReflectException.java similarity index 100% rename from src/main/java/wecui/exception/ReflectException.java rename to java/wecui/exception/ReflectException.java diff --git a/src/main/java/wecui/gui/GuiColourButton.java b/java/wecui/gui/GuiColourButton.java similarity index 100% rename from src/main/java/wecui/gui/GuiColourButton.java rename to java/wecui/gui/GuiColourButton.java diff --git a/src/main/java/wecui/gui/GuiColourPicker.java b/java/wecui/gui/GuiColourPicker.java similarity index 100% rename from src/main/java/wecui/gui/GuiColourPicker.java rename to java/wecui/gui/GuiColourPicker.java diff --git a/src/main/java/wecui/gui/GuiControl.java b/java/wecui/gui/GuiControl.java similarity index 100% rename from src/main/java/wecui/gui/GuiControl.java rename to java/wecui/gui/GuiControl.java diff --git a/src/main/java/wecui/gui/WorldEditCUIConfigPanel.java b/java/wecui/gui/WorldEditCUIConfigPanel.java similarity index 100% rename from src/main/java/wecui/gui/WorldEditCUIConfigPanel.java rename to java/wecui/gui/WorldEditCUIConfigPanel.java diff --git a/src/main/java/wecui/render/LineColor.java b/java/wecui/render/LineColor.java similarity index 100% rename from src/main/java/wecui/render/LineColor.java rename to java/wecui/render/LineColor.java diff --git a/src/main/java/wecui/render/LineInfo.java b/java/wecui/render/LineInfo.java similarity index 100% rename from src/main/java/wecui/render/LineInfo.java rename to java/wecui/render/LineInfo.java diff --git a/src/main/java/wecui/render/points/PointCube.java b/java/wecui/render/points/PointCube.java similarity index 100% rename from src/main/java/wecui/render/points/PointCube.java rename to java/wecui/render/points/PointCube.java diff --git a/src/main/java/wecui/render/points/PointRectangle.java b/java/wecui/render/points/PointRectangle.java similarity index 100% rename from src/main/java/wecui/render/points/PointRectangle.java rename to java/wecui/render/points/PointRectangle.java diff --git a/src/main/java/wecui/render/region/BaseRegion.java b/java/wecui/render/region/BaseRegion.java similarity index 100% rename from src/main/java/wecui/render/region/BaseRegion.java rename to java/wecui/render/region/BaseRegion.java diff --git a/src/main/java/wecui/render/region/CuboidRegion.java b/java/wecui/render/region/CuboidRegion.java similarity index 100% rename from src/main/java/wecui/render/region/CuboidRegion.java rename to java/wecui/render/region/CuboidRegion.java diff --git a/src/main/java/wecui/render/region/CylinderRegion.java b/java/wecui/render/region/CylinderRegion.java similarity index 100% rename from src/main/java/wecui/render/region/CylinderRegion.java rename to java/wecui/render/region/CylinderRegion.java diff --git a/src/main/java/wecui/render/region/EllipsoidRegion.java b/java/wecui/render/region/EllipsoidRegion.java similarity index 100% rename from src/main/java/wecui/render/region/EllipsoidRegion.java rename to java/wecui/render/region/EllipsoidRegion.java diff --git a/src/main/java/wecui/render/region/PolygonRegion.java b/java/wecui/render/region/PolygonRegion.java similarity index 100% rename from src/main/java/wecui/render/region/PolygonRegion.java rename to java/wecui/render/region/PolygonRegion.java diff --git a/src/main/java/wecui/render/region/PolyhedronRegion.java b/java/wecui/render/region/PolyhedronRegion.java similarity index 100% rename from src/main/java/wecui/render/region/PolyhedronRegion.java rename to java/wecui/render/region/PolyhedronRegion.java diff --git a/src/main/java/wecui/render/region/RegionType.java b/java/wecui/render/region/RegionType.java similarity index 100% rename from src/main/java/wecui/render/region/RegionType.java rename to java/wecui/render/region/RegionType.java diff --git a/src/main/java/wecui/render/shapes/Render2DBox.java b/java/wecui/render/shapes/Render2DBox.java similarity index 100% rename from src/main/java/wecui/render/shapes/Render2DBox.java rename to java/wecui/render/shapes/Render2DBox.java diff --git a/src/main/java/wecui/render/shapes/Render2DGrid.java b/java/wecui/render/shapes/Render2DGrid.java similarity index 100% rename from src/main/java/wecui/render/shapes/Render2DGrid.java rename to java/wecui/render/shapes/Render2DGrid.java diff --git a/src/main/java/wecui/render/shapes/Render3DBox.java b/java/wecui/render/shapes/Render3DBox.java similarity index 100% rename from src/main/java/wecui/render/shapes/Render3DBox.java rename to java/wecui/render/shapes/Render3DBox.java diff --git a/src/main/java/wecui/render/shapes/Render3DGrid.java b/java/wecui/render/shapes/Render3DGrid.java similarity index 100% rename from src/main/java/wecui/render/shapes/Render3DGrid.java rename to java/wecui/render/shapes/Render3DGrid.java diff --git a/src/main/java/wecui/render/shapes/Render3DPolygon.java b/java/wecui/render/shapes/Render3DPolygon.java similarity index 100% rename from src/main/java/wecui/render/shapes/Render3DPolygon.java rename to java/wecui/render/shapes/Render3DPolygon.java diff --git a/src/main/java/wecui/render/shapes/RenderCylinderBox.java b/java/wecui/render/shapes/RenderCylinderBox.java similarity index 100% rename from src/main/java/wecui/render/shapes/RenderCylinderBox.java rename to java/wecui/render/shapes/RenderCylinderBox.java diff --git a/src/main/java/wecui/render/shapes/RenderCylinderCircles.java b/java/wecui/render/shapes/RenderCylinderCircles.java similarity index 100% rename from src/main/java/wecui/render/shapes/RenderCylinderCircles.java rename to java/wecui/render/shapes/RenderCylinderCircles.java diff --git a/src/main/java/wecui/render/shapes/RenderCylinderGrid.java b/java/wecui/render/shapes/RenderCylinderGrid.java similarity index 100% rename from src/main/java/wecui/render/shapes/RenderCylinderGrid.java rename to java/wecui/render/shapes/RenderCylinderGrid.java diff --git a/src/main/java/wecui/render/shapes/RenderEllipsoid.java b/java/wecui/render/shapes/RenderEllipsoid.java similarity index 100% rename from src/main/java/wecui/render/shapes/RenderEllipsoid.java rename to java/wecui/render/shapes/RenderEllipsoid.java diff --git a/src/main/java/wecui/util/ConsoleLogFormatter.java b/java/wecui/util/ConsoleLogFormatter.java similarity index 100% rename from src/main/java/wecui/util/ConsoleLogFormatter.java rename to java/wecui/util/ConsoleLogFormatter.java diff --git a/src/main/java/wecui/util/Utilities.java b/java/wecui/util/Utilities.java similarity index 100% rename from src/main/java/wecui/util/Utilities.java rename to java/wecui/util/Utilities.java diff --git a/src/main/java/wecui/util/Vector2.java b/java/wecui/util/Vector2.java similarity index 100% rename from src/main/java/wecui/util/Vector2.java rename to java/wecui/util/Vector2.java diff --git a/src/main/java/wecui/util/Vector2m.java b/java/wecui/util/Vector2m.java similarity index 100% rename from src/main/java/wecui/util/Vector2m.java rename to java/wecui/util/Vector2m.java diff --git a/src/main/java/wecui/util/Vector3.java b/java/wecui/util/Vector3.java similarity index 100% rename from src/main/java/wecui/util/Vector3.java rename to java/wecui/util/Vector3.java diff --git a/src/main/java/wecui/util/Vector3m.java b/java/wecui/util/Vector3m.java similarity index 100% rename from src/main/java/wecui/util/Vector3m.java rename to java/wecui/util/Vector3m.java diff --git a/src/main/java/wecui/vendor/org/joor/Reflect.java b/java/wecui/vendor/org/joor/Reflect.java similarity index 100% rename from src/main/java/wecui/vendor/org/joor/Reflect.java rename to java/wecui/vendor/org/joor/Reflect.java diff --git a/src/main/resources/assets/wecui/lang/en_US.lang b/res/assets/wecui/lang/en_US.lang similarity index 100% rename from src/main/resources/assets/wecui/lang/en_US.lang rename to res/assets/wecui/lang/en_US.lang diff --git a/src/main/resources/assets/wecui/textures/gui/checker.png b/res/assets/wecui/textures/gui/checker.png similarity index 100% rename from src/main/resources/assets/wecui/textures/gui/checker.png rename to res/assets/wecui/textures/gui/checker.png diff --git a/src/main/resources/assets/wecui/textures/gui/picker.png b/res/assets/wecui/textures/gui/picker.png similarity index 100% rename from src/main/resources/assets/wecui/textures/gui/picker.png rename to res/assets/wecui/textures/gui/picker.png From 838d0007efc6bc5eb937ad709c92135b42570320 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Wed, 22 Jan 2014 12:45:59 +0000 Subject: [PATCH 10/51] Cleaning up codebase, remove redundant classes --- .classpath | 1 + build/build_wecui.xml | 2 +- build/buildnumber.txt | 4 +- .../worldeditcui}/InitializationFactory.java | 4 +- .../worldeditcui}/LiteModWorldEditCUI.java | 20 +- .../mumfrey/worldeditcui}/WorldEditCUI.java | 39 +- .../worldeditcui/config/CUIConfiguration.java | 146 +++++ .../mumfrey/worldeditcui}/config/Colour.java | 4 +- .../mumfrey/worldeditcui/debug}/CUIDebug.java | 9 +- .../mumfrey/worldeditcui/event/CUIEvent.java | 99 +++ .../worldeditcui/event/CUIEventArgs.java} | 12 +- .../event/CUIEventDispatcher.java | 73 +++ .../worldeditcui/event/CUIEventType.java | 77 +++ .../event/cui/CUIEventBounds.java} | 12 +- .../event/cui/CUIEventCylinder.java} | 12 +- .../event/cui/CUIEventEllipsoid.java} | 12 +- .../event/cui/CUIEventPoint2D.java} | 11 +- .../event/cui/CUIEventPoint3D.java | 39 ++ .../event/cui/CUIEventPolygon.java} | 12 +- .../event/cui/CUIEventSelection.java | 43 ++ .../event/cui/CUIEventUpdate.java | 32 + .../event/listeners/CUIListenerChannel.java | 39 ++ .../listeners/CUIListenerWorldRender.java} | 10 +- .../exceptions}/InitializationException.java | 2 +- .../InvalidSelectionTypeException.java | 11 + .../worldeditcui/gui/CUIConfigPanel.java} | 22 +- .../gui/controls}/GuiColourButton.java | 12 +- .../gui/controls}/GuiColourPicker.java | 2 +- .../gui/controls}/GuiControl.java | 2 +- .../render/CUISelectionProvider.java | 66 ++ .../worldeditcui/render/LineColour.java} | 24 +- .../worldeditcui}/render/LineInfo.java | 6 +- .../render/points/PointCube.java | 22 +- .../render/points/PointRectangle.java | 22 +- .../render/region/BaseRegion.java | 15 +- .../render/region/CuboidRegion.java | 24 +- .../render/region/CylinderRegion.java | 22 +- .../render/region/EllipsoidRegion.java | 16 +- .../render/region/PolygonRegion.java | 18 +- .../render/region/PolyhedronRegion.java | 16 +- .../render/region/RegionType.java | 43 ++ .../render/shapes/Render2DBox.java | 23 +- .../render/shapes/Render2DGrid.java | 23 +- .../render/shapes/Render3DBox.java | 27 +- .../render/shapes/Render3DGrid.java | 23 +- .../render/shapes/Render3DPolygon.java | 23 +- .../render/shapes/RenderCylinderBox.java | 23 +- .../render/shapes/RenderCylinderCircles.java | 23 +- .../render/shapes/RenderCylinderGrid.java | 25 +- .../render/shapes/RenderEllipsoid.java | 47 +- .../util/ConsoleLogFormatter.java | 2 +- .../mumfrey/worldeditcui}/util/Vector2.java | 2 +- .../mumfrey/worldeditcui}/util/Vector2m.java | 2 +- .../mumfrey/worldeditcui}/util/Vector3.java | 2 +- .../mumfrey/worldeditcui}/util/Vector3m.java | 2 +- java/wecui/config/CUIConfiguration.java | 149 ----- java/wecui/event/cui/CUIBaseEvent.java | 109 ---- java/wecui/event/cui/CUIEventType.java | 72 -- java/wecui/event/cui/CUIPointEvent.java | 58 -- java/wecui/event/cui/CUISelectionEvent.java | 67 -- java/wecui/event/cui/CUIUpdateEvent.java | 30 - .../event/listeners/ChannelListener.java | 66 -- java/wecui/exception/ReflectException.java | 84 --- java/wecui/render/region/RegionType.java | 15 - java/wecui/util/Utilities.java | 153 ----- java/wecui/vendor/org/joor/Reflect.java | 617 ------------------ 66 files changed, 998 insertions(+), 1726 deletions(-) rename java/{wecui => com/mumfrey/worldeditcui}/InitializationFactory.java (74%) rename java/{wecui => com/mumfrey/worldeditcui}/LiteModWorldEditCUI.java (84%) rename java/{wecui => com/mumfrey/worldeditcui}/WorldEditCUI.java (55%) create mode 100644 java/com/mumfrey/worldeditcui/config/CUIConfiguration.java rename java/{wecui => com/mumfrey/worldeditcui}/config/Colour.java (94%) rename java/{wecui => com/mumfrey/worldeditcui/debug}/CUIDebug.java (86%) create mode 100644 java/com/mumfrey/worldeditcui/event/CUIEvent.java rename java/{wecui/event/CUIEvent.java => com/mumfrey/worldeditcui/event/CUIEventArgs.java} (73%) create mode 100644 java/com/mumfrey/worldeditcui/event/CUIEventDispatcher.java create mode 100644 java/com/mumfrey/worldeditcui/event/CUIEventType.java rename java/{wecui/event/cui/CUIMinMaxEvent.java => com/mumfrey/worldeditcui/event/cui/CUIEventBounds.java} (58%) rename java/{wecui/event/cui/CUICylinderEvent.java => com/mumfrey/worldeditcui/event/cui/CUIEventCylinder.java} (65%) rename java/{wecui/event/cui/CUIEllipsoidEvent.java => com/mumfrey/worldeditcui/event/cui/CUIEventEllipsoid.java} (68%) rename java/{wecui/event/cui/CUIPoint2DEvent.java => com/mumfrey/worldeditcui/event/cui/CUIEventPoint2D.java} (65%) create mode 100644 java/com/mumfrey/worldeditcui/event/cui/CUIEventPoint3D.java rename java/{wecui/event/cui/CUIPolygonEvent.java => com/mumfrey/worldeditcui/event/cui/CUIEventPolygon.java} (61%) create mode 100644 java/com/mumfrey/worldeditcui/event/cui/CUIEventSelection.java create mode 100644 java/com/mumfrey/worldeditcui/event/cui/CUIEventUpdate.java create mode 100644 java/com/mumfrey/worldeditcui/event/listeners/CUIListenerChannel.java rename java/{wecui/event/listeners/WorldRenderListener.java => com/mumfrey/worldeditcui/event/listeners/CUIListenerWorldRender.java} (90%) rename java/{wecui/exception => com/mumfrey/worldeditcui/exceptions}/InitializationException.java (89%) create mode 100644 java/com/mumfrey/worldeditcui/exceptions/InvalidSelectionTypeException.java rename java/{wecui/gui/WorldEditCUIConfigPanel.java => com/mumfrey/worldeditcui/gui/CUIConfigPanel.java} (86%) rename java/{wecui/gui => com/mumfrey/worldeditcui/gui/controls}/GuiColourButton.java (95%) rename java/{wecui/gui => com/mumfrey/worldeditcui/gui/controls}/GuiColourPicker.java (99%) rename java/{wecui/gui => com/mumfrey/worldeditcui/gui/controls}/GuiControl.java (99%) create mode 100644 java/com/mumfrey/worldeditcui/render/CUISelectionProvider.java rename java/{wecui/render/LineColor.java => com/mumfrey/worldeditcui/render/LineColour.java} (87%) rename java/{wecui => com/mumfrey/worldeditcui}/render/LineInfo.java (88%) rename java/{wecui => com/mumfrey/worldeditcui}/render/points/PointCube.java (60%) rename java/{wecui => com/mumfrey/worldeditcui}/render/points/PointRectangle.java (55%) rename java/{wecui => com/mumfrey/worldeditcui}/render/region/BaseRegion.java (50%) rename java/{wecui => com/mumfrey/worldeditcui}/render/region/CuboidRegion.java (76%) rename java/{wecui => com/mumfrey/worldeditcui}/render/region/CylinderRegion.java (57%) rename java/{wecui => com/mumfrey/worldeditcui}/render/region/EllipsoidRegion.java (63%) rename java/{wecui => com/mumfrey/worldeditcui}/render/region/PolygonRegion.java (66%) rename java/{wecui => com/mumfrey/worldeditcui}/render/region/PolyhedronRegion.java (75%) create mode 100644 java/com/mumfrey/worldeditcui/render/region/RegionType.java rename java/{wecui => com/mumfrey/worldeditcui}/render/shapes/Render2DBox.java (64%) rename java/{wecui => com/mumfrey/worldeditcui}/render/shapes/Render2DGrid.java (65%) rename java/{wecui => com/mumfrey/worldeditcui}/render/shapes/Render3DBox.java (73%) rename java/{wecui => com/mumfrey/worldeditcui}/render/shapes/Render3DGrid.java (89%) rename java/{wecui => com/mumfrey/worldeditcui}/render/shapes/Render3DPolygon.java (54%) rename java/{wecui => com/mumfrey/worldeditcui}/render/shapes/RenderCylinderBox.java (69%) rename java/{wecui => com/mumfrey/worldeditcui}/render/shapes/RenderCylinderCircles.java (68%) rename java/{wecui => com/mumfrey/worldeditcui}/render/shapes/RenderCylinderGrid.java (78%) rename java/{wecui => com/mumfrey/worldeditcui}/render/shapes/RenderEllipsoid.java (80%) rename java/{wecui => com/mumfrey/worldeditcui}/util/ConsoleLogFormatter.java (97%) rename java/{wecui => com/mumfrey/worldeditcui}/util/Vector2.java (94%) rename java/{wecui => com/mumfrey/worldeditcui}/util/Vector2m.java (91%) rename java/{wecui => com/mumfrey/worldeditcui}/util/Vector3.java (94%) rename java/{wecui => com/mumfrey/worldeditcui}/util/Vector3m.java (92%) delete mode 100644 java/wecui/config/CUIConfiguration.java delete mode 100644 java/wecui/event/cui/CUIBaseEvent.java delete mode 100644 java/wecui/event/cui/CUIEventType.java delete mode 100644 java/wecui/event/cui/CUIPointEvent.java delete mode 100644 java/wecui/event/cui/CUISelectionEvent.java delete mode 100644 java/wecui/event/cui/CUIUpdateEvent.java delete mode 100644 java/wecui/event/listeners/ChannelListener.java delete mode 100644 java/wecui/exception/ReflectException.java delete mode 100644 java/wecui/render/region/RegionType.java delete mode 100644 java/wecui/util/Utilities.java delete mode 100644 java/wecui/vendor/org/joor/Reflect.java diff --git a/.classpath b/.classpath index c7eed1f5..b0e4e0e7 100644 --- a/.classpath +++ b/.classpath @@ -7,5 +7,6 @@ + diff --git a/build/build_wecui.xml b/build/build_wecui.xml index d26ab14e..67352721 100644 --- a/build/build_wecui.xml +++ b/build/build_wecui.xml @@ -5,7 +5,7 @@ - + diff --git a/build/buildnumber.txt b/build/buildnumber.txt index 057728b8..04818f17 100644 --- a/build/buildnumber.txt +++ b/build/buildnumber.txt @@ -1,3 +1,3 @@ #Build Number for ANT. Do not edit! -#Fri Jan 10 14:58:39 GMT 2014 -build.number=1638 +#Wed Jan 22 12:44:35 GMT 2014 +build.number=1723 diff --git a/java/wecui/InitializationFactory.java b/java/com/mumfrey/worldeditcui/InitializationFactory.java similarity index 74% rename from java/wecui/InitializationFactory.java rename to java/com/mumfrey/worldeditcui/InitializationFactory.java index 121d970f..8eb14a52 100644 --- a/java/wecui/InitializationFactory.java +++ b/java/com/mumfrey/worldeditcui/InitializationFactory.java @@ -1,6 +1,6 @@ -package wecui; +package com.mumfrey.worldeditcui; -import wecui.exception.InitializationException; +import com.mumfrey.worldeditcui.exceptions.InitializationException; /** * Simple interface to trace what needs to be initialized at mod loading. diff --git a/java/wecui/LiteModWorldEditCUI.java b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java similarity index 84% rename from java/wecui/LiteModWorldEditCUI.java rename to java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java index 004d830c..4b249390 100644 --- a/java/wecui/LiteModWorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java @@ -1,4 +1,4 @@ -package wecui; +package com.mumfrey.worldeditcui; import java.io.File; import java.nio.charset.Charset; @@ -13,10 +13,6 @@ import net.minecraft.client.settings.KeyBinding; import net.minecraft.network.INetHandler; import net.minecraft.network.play.server.S01PacketJoinGame; -import wecui.event.listeners.ChannelListener; -import wecui.event.listeners.WorldRenderListener; -import wecui.gui.WorldEditCUIConfigPanel; -import wecui.render.region.CuboidRegion; import com.mumfrey.liteloader.Configurable; import com.mumfrey.liteloader.InitCompleteListener; @@ -27,6 +23,10 @@ import com.mumfrey.liteloader.core.PluginChannels.ChannelPolicy; import com.mumfrey.liteloader.modconfig.ConfigPanel; import com.mumfrey.liteloader.util.ModUtilities; +import com.mumfrey.worldeditcui.event.listeners.CUIListenerChannel; +import com.mumfrey.worldeditcui.event.listeners.CUIListenerWorldRender; +import com.mumfrey.worldeditcui.gui.CUIConfigPanel; +import com.mumfrey.worldeditcui.render.region.CuboidRegion; public class LiteModWorldEditCUI implements InitCompleteListener, PluginChannelListener, PostRenderListener, Configurable { @@ -43,8 +43,8 @@ public class LiteModWorldEditCUI implements InitCompleteListener, PluginChannelL private boolean visible = true; - private WorldRenderListener worldRenderListener; - private ChannelListener channelListener; + private CUIListenerWorldRender worldRenderListener; + private CUIListenerChannel channelListener; @Override public void init(File configPath) @@ -67,8 +67,8 @@ public void onInitCompleted(Minecraft minecraft, LiteLoader loader) this.controller = new WorldEditCUI(); this.controller.initialize(); - this.worldRenderListener = new WorldRenderListener(this.controller, minecraft); - this.channelListener = new ChannelListener(this.controller); + this.worldRenderListener = new CUIListenerWorldRender(this.controller, minecraft); + this.channelListener = new CUIListenerChannel(this.controller); } @Override @@ -154,7 +154,7 @@ public String getVersion() @Override public Class getConfigPanelClass() { - return WorldEditCUIConfigPanel.class; + return CUIConfigPanel.class; } @Override diff --git a/java/wecui/WorldEditCUI.java b/java/com/mumfrey/worldeditcui/WorldEditCUI.java similarity index 55% rename from java/wecui/WorldEditCUI.java rename to java/com/mumfrey/worldeditcui/WorldEditCUI.java index 8f87f0db..8252bbe1 100644 --- a/java/wecui/WorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/WorldEditCUI.java @@ -1,9 +1,12 @@ -package wecui; +package com.mumfrey.worldeditcui; -import wecui.config.CUIConfiguration; -import wecui.exception.InitializationException; -import wecui.render.region.BaseRegion; -import wecui.render.region.CuboidRegion; +import com.mumfrey.worldeditcui.config.CUIConfiguration; +import com.mumfrey.worldeditcui.debug.CUIDebug; +import com.mumfrey.worldeditcui.event.CUIEventDispatcher; +import com.mumfrey.worldeditcui.exceptions.InitializationException; +import com.mumfrey.worldeditcui.render.CUISelectionProvider; +import com.mumfrey.worldeditcui.render.region.BaseRegion; +import com.mumfrey.worldeditcui.render.region.CuboidRegion; /** * Main controller class. Uses a pseudo-JavaBeans paradigm. The only real @@ -21,18 +24,24 @@ public class WorldEditCUI private BaseRegion selection; private CUIDebug debugger; private CUIConfiguration configuration; + private CUIEventDispatcher dispatcher; + private CUISelectionProvider selectionProvider; public void initialize() { this.selection = new CuboidRegion(this); this.configuration = CUIConfiguration.create(); this.debugger = new CUIDebug(this); + this.dispatcher = new CUIEventDispatcher(this); + this.selectionProvider = new CUISelectionProvider(this); try { this.selection.initialize(); this.configuration.initialize(); this.debugger.initialize(); + this.dispatcher.initialize(); + this.selectionProvider.initialize(); } catch (InitializationException e) { @@ -40,25 +49,25 @@ public void initialize() return; } } - - public CUIConfiguration getConfiguration() + + public CUIEventDispatcher getDispatcher() { - return this.configuration; + return this.dispatcher; } - public void setConfiguration(CUIConfiguration configuration) + public CUISelectionProvider getSelectionProvider() { - this.configuration = configuration; + return this.selectionProvider; } - - public CUIDebug getDebugger() + + public CUIConfiguration getConfiguration() { - return this.debugger; + return this.configuration; } - public void setDebugger(CUIDebug debugger) + public CUIDebug getDebugger() { - this.debugger = debugger; + return this.debugger; } public BaseRegion getSelection() diff --git a/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java b/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java new file mode 100644 index 00000000..6b7b61af --- /dev/null +++ b/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java @@ -0,0 +1,146 @@ +package com.mumfrey.worldeditcui.config; + +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.mumfrey.liteloader.core.LiteLoader; +import com.mumfrey.worldeditcui.InitializationFactory; +import com.mumfrey.worldeditcui.render.LineColour; + +/** + * Stores and reads WorldEditCUI settings + * + * @author yetanotherx + * + */ +public class CUIConfiguration implements InitializationFactory +{ + private static final String CONFIG_FILE_NAME = "worldeditcui.config.json"; + + private static Gson gson = new GsonBuilder().setPrettyPrinting().create(); + + private boolean debugMode = false; + private boolean ignoreUpdates = false; + + private Colour cuboidGridColor = new Colour("#CC3333CC"); + private Colour cuboidEdgeColor = new Colour("#CC4C4CCC"); + private Colour cuboidFirstPointColor = new Colour("#33CC33CC"); + private Colour cuboidSecondPointColor = new Colour("#3333CCCC"); + private Colour polyGridColor = new Colour("#CC3333CC"); + private Colour polyEdgeColor = new Colour("#CC4C4CCC"); + private Colour polyPointColor = new Colour("#33CCCCCC"); + private Colour ellipsoidGridColor = new Colour("#CC4C4CCC"); + private Colour ellipsoidPointColor = new Colour("#CCCC33CC"); + private Colour cylinderGridColor = new Colour("#CC3333CC"); + private Colour cylinderEdgeColor = new Colour("#CC4C4CCC"); + private Colour cylinderPointColor = new Colour("#CC33CCCC"); + + /** + * Copies the default config file to the proper directory if it does not + * exist. It then reads the file and sets each variable to the proper value. + */ + @Override + public void initialize() + { + this.cuboidGridColor = Colour.setDefault(this.cuboidGridColor, "#CC3333CC"); + this.cuboidEdgeColor = Colour.setDefault(this.cuboidEdgeColor, "#CC4C4CCC"); + this.cuboidFirstPointColor = Colour.setDefault(this.cuboidFirstPointColor, "#33CC33CC"); + this.cuboidSecondPointColor = Colour.setDefault(this.cuboidSecondPointColor, "#3333CCCC"); + this.polyGridColor = Colour.setDefault(this.polyGridColor, "#CC3333CC"); + this.polyEdgeColor = Colour.setDefault(this.polyEdgeColor, "#CC4C4CCC"); + this.polyPointColor = Colour.setDefault(this.polyPointColor, "#33CCCCCC"); + this.ellipsoidGridColor = Colour.setDefault(this.ellipsoidGridColor, "#CC4C4CCC"); + this.ellipsoidPointColor = Colour.setDefault(this.ellipsoidPointColor, "#CCCC33CC"); + this.cylinderGridColor = Colour.setDefault(this.cylinderGridColor, "#CC3333CC"); + this.cylinderEdgeColor = Colour.setDefault(this.cylinderEdgeColor, "#CC4C4CCC"); + this.cylinderPointColor = Colour.setDefault(this.cylinderPointColor, "#CC33CCCC"); + + LineColour.CUBOIDBOX.setColour(this.cuboidEdgeColor); + LineColour.CUBOIDGRID.setColour(this.cuboidGridColor); + LineColour.CUBOIDPOINT1.setColour(this.cuboidFirstPointColor); + LineColour.CUBOIDPOINT2.setColour(this.cuboidSecondPointColor); + LineColour.POLYGRID.setColour(this.polyGridColor); + LineColour.POLYBOX.setColour(this.polyEdgeColor); + LineColour.POLYPOINT.setColour(this.polyPointColor); + LineColour.ELLIPSOIDGRID.setColour(this.ellipsoidGridColor); + LineColour.ELLIPSOIDCENTER.setColour(this.ellipsoidPointColor); + LineColour.CYLINDERGRID.setColour(this.cylinderGridColor); + LineColour.CYLINDERBOX.setColour(this.cylinderEdgeColor); + LineColour.CYLINDERCENTER.setColour(this.cylinderPointColor); + + this.save(); + } + + public boolean isDebugMode() + { + return this.debugMode; + } + + public boolean ignoreUpdates() + { + return this.ignoreUpdates; + } + + public static CUIConfiguration create() + { + File jsonFile = new File(LiteLoader.getCommonConfigFolder(), CUIConfiguration.CONFIG_FILE_NAME); + + if (jsonFile.exists()) + { + FileReader fileReader = null; + + try + { + fileReader = new FileReader(jsonFile); + CUIConfiguration config = CUIConfiguration.gson.fromJson(fileReader, CUIConfiguration.class); + return config; + } + catch (IOException ex) + { + ex.printStackTrace(); + } + finally + { + try + { + if (fileReader != null) fileReader.close(); + } + catch (IOException ex) {} + } + } + + return new CUIConfiguration(); + } + + public void save() + { + File jsonFile = new File(LiteLoader.getCommonConfigFolder(), CUIConfiguration.CONFIG_FILE_NAME); + + FileWriter fileWriter = null; + + try + { + fileWriter = new FileWriter(jsonFile); + CUIConfiguration.gson.toJson(this, fileWriter); + } + catch (IOException ex) + { + ex.printStackTrace(); + } + finally + { + try + { + if (fileWriter != null) fileWriter.close(); + } + catch (IOException ex) + { + ex.printStackTrace(); + } + } + } +} diff --git a/java/wecui/config/Colour.java b/java/com/mumfrey/worldeditcui/config/Colour.java similarity index 94% rename from java/wecui/config/Colour.java rename to java/com/mumfrey/worldeditcui/config/Colour.java index d2181891..7bbab516 100644 --- a/java/wecui/config/Colour.java +++ b/java/com/mumfrey/worldeditcui/config/Colour.java @@ -1,4 +1,4 @@ -package wecui.config; +package com.mumfrey.worldeditcui.config; public class Colour { @@ -36,7 +36,7 @@ public static Colour setDefault(Colour colour, String defaultColour) } /** - * Validates a user-entered color code. Ensures that color is not null, it + * Validates a user-entered colour code. Ensures that colour is not null, it * starts with #, that it has all 6 digits, and that each hex code is valid. * * @param colour diff --git a/java/wecui/CUIDebug.java b/java/com/mumfrey/worldeditcui/debug/CUIDebug.java similarity index 86% rename from java/wecui/CUIDebug.java rename to java/com/mumfrey/worldeditcui/debug/CUIDebug.java index 10683e8d..fc18fcad 100644 --- a/java/wecui/CUIDebug.java +++ b/java/com/mumfrey/worldeditcui/debug/CUIDebug.java @@ -1,4 +1,4 @@ -package wecui; +package com.mumfrey.worldeditcui.debug; import java.io.File; import java.io.IOException; @@ -8,9 +8,10 @@ import java.util.logging.Logger; import com.mumfrey.liteloader.core.LiteLoader; - -import wecui.exception.InitializationException; -import wecui.util.ConsoleLogFormatter; +import com.mumfrey.worldeditcui.InitializationFactory; +import com.mumfrey.worldeditcui.WorldEditCUI; +import com.mumfrey.worldeditcui.exceptions.InitializationException; +import com.mumfrey.worldeditcui.util.ConsoleLogFormatter; /** * Debugging helper class diff --git a/java/com/mumfrey/worldeditcui/event/CUIEvent.java b/java/com/mumfrey/worldeditcui/event/CUIEvent.java new file mode 100644 index 00000000..7f42a38f --- /dev/null +++ b/java/com/mumfrey/worldeditcui/event/CUIEvent.java @@ -0,0 +1,99 @@ +package com.mumfrey.worldeditcui.event; + +import com.google.common.base.Joiner; +import com.mumfrey.worldeditcui.WorldEditCUI; + +/** + * Base event for CUI events, handles parameter validation and running the logic + * + * @author yetanotherx + * + */ +public abstract class CUIEvent +{ + + protected WorldEditCUI controller; + protected String[] args; + + public CUIEvent(WorldEditCUI controller, String[] args) + { + this.controller = controller; + this.args = args; + } + + public abstract String raise(); + + public abstract CUIEventType getEventType(); + + public String getEventName() + { + return this.getEventType().getName(); + } + + /** + * Checks if the parameters match the required length. + * @return + */ + public boolean isValid() + { + int max = this.getEventType().getMaxParameters(); + int min = this.getEventType().getMinParameters(); + + if (max == min) + { + if (this.args.length != max) + { + return false; + } + } + else + { + if (this.args.length > max || this.args.length < min) + { + return false; + } + } + + return true; + + } + + public final void prepare() + { + if (this.controller == null || this.args == null) + { + throw new IllegalStateException("Controller and parameters must both be set."); + } + + if (!this.isValid()) + { + String message = String.format("Invalid number of parameters. %s event requires %s parameters but received %s [%s]", this.getEventName(), this.getRequiredParameterString(), this.args.length, Joiner.on(", ").join(this.args)); + throw new IllegalArgumentException(message); + } + } + + private String getRequiredParameterString() + { + if (this.getEventType().getMaxParameters() == this.getEventType().getMinParameters()) + { + return String.valueOf(this.getEventType().getMaxParameters()); + } + + return String.format("between %d and %d", this.getEventType().getMinParameters(), this.getEventType().getMaxParameters()); + } + + public int getInt(int index) + { + return (int)Float.parseFloat(this.args[index]); + } + + public double getDouble(int index) + { + return Double.parseDouble(this.args[index]); + } + + public String getString(int index) + { + return this.args[index]; + } +} diff --git a/java/wecui/event/CUIEvent.java b/java/com/mumfrey/worldeditcui/event/CUIEventArgs.java similarity index 73% rename from java/wecui/event/CUIEvent.java rename to java/com/mumfrey/worldeditcui/event/CUIEventArgs.java index 31e73687..7d146b2e 100644 --- a/java/wecui/event/CUIEvent.java +++ b/java/com/mumfrey/worldeditcui/event/CUIEventArgs.java @@ -1,7 +1,7 @@ -package wecui.event; +package com.mumfrey.worldeditcui.event; -import wecui.WorldEditCUI; -import wecui.util.Utilities; +import com.google.common.base.Joiner; +import com.mumfrey.worldeditcui.WorldEditCUI; /** * CUI communication event @@ -11,13 +11,13 @@ * @author yetanotherx * */ -public class CUIEvent +public class CUIEventArgs { private WorldEditCUI controller; private String type; private String[] params; - public CUIEvent(WorldEditCUI controller, String type, String[] params) + public CUIEventArgs(WorldEditCUI controller, String type, String[] params) { this.controller = controller; this.type = type; @@ -28,7 +28,7 @@ public CUIEvent(WorldEditCUI controller, String type, String[] params) } this.params = params; - this.controller.getDebugger().debug("CUI Event (" + type + ") - Params: " + Utilities.join(params, ", ")); + this.controller.getDebugger().debug("CUI Event (" + type + ") - Params: " + Joiner.on(", ").join(params)); } public int getInt(int index) diff --git a/java/com/mumfrey/worldeditcui/event/CUIEventDispatcher.java b/java/com/mumfrey/worldeditcui/event/CUIEventDispatcher.java new file mode 100644 index 00000000..0502a058 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/event/CUIEventDispatcher.java @@ -0,0 +1,73 @@ +package com.mumfrey.worldeditcui.event; + +import java.lang.reflect.Constructor; +import java.util.HashMap; +import java.util.Map; + +import com.mumfrey.worldeditcui.InitializationFactory; +import com.mumfrey.worldeditcui.WorldEditCUI; +import com.mumfrey.worldeditcui.exceptions.InitializationException; + +/** + * + * @author Adam Mummery-Smith + */ +public class CUIEventDispatcher implements InitializationFactory +{ + private WorldEditCUI controller; + + private Map> eventConstructors = new HashMap>(); + + public CUIEventDispatcher(WorldEditCUI controller) + { + this.controller = controller; + } + + @Override + public void initialize() throws InitializationException + { + for (CUIEventType eventType : CUIEventType.values()) + { + try + { + Class eventClass = eventType.getEventClass(); + Constructor ctor = eventClass.getDeclaredConstructor(WorldEditCUI.class, String[].class); + + this.eventConstructors.put(eventType.getKey(), ctor); + } + catch (NoSuchMethodException ex) + { + this.controller.getDebugger().debug("Error getting constructor for event " + eventType.getKey()); + } + } + } + + public void raiseEvent(CUIEventArgs eventArgs) + { + try + { + Constructor eventCtor = this.eventConstructors.get(eventArgs.getType()); + CUIEvent event = eventCtor.newInstance(this.controller, eventArgs.getParams()); + event.prepare(); + + String response = event.raise(); + if (response != null) + { + this.handleEventResponse(response); + } + } + catch (NullPointerException ex) + { + this.controller.getDebugger().debug("No such event " + eventArgs.getType()); + } + catch (Exception ex) + { + ex.printStackTrace(); + this.controller.getDebugger().debug("Error raising event " + eventArgs.getType() + ": " + ex.getClass().getSimpleName() + " " + ex.getMessage()); + } + } + + private void handleEventResponse(String response) + { + } +} diff --git a/java/com/mumfrey/worldeditcui/event/CUIEventType.java b/java/com/mumfrey/worldeditcui/event/CUIEventType.java new file mode 100644 index 00000000..b3116102 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/event/CUIEventType.java @@ -0,0 +1,77 @@ +package com.mumfrey.worldeditcui.event; + +import com.mumfrey.worldeditcui.event.cui.CUIEventBounds; +import com.mumfrey.worldeditcui.event.cui.CUIEventCylinder; +import com.mumfrey.worldeditcui.event.cui.CUIEventEllipsoid; +import com.mumfrey.worldeditcui.event.cui.CUIEventPoint2D; +import com.mumfrey.worldeditcui.event.cui.CUIEventPoint3D; +import com.mumfrey.worldeditcui.event.cui.CUIEventPolygon; +import com.mumfrey.worldeditcui.event.cui.CUIEventSelection; +import com.mumfrey.worldeditcui.event.cui.CUIEventUpdate; + +/** + * Event type enum for CUI events. Also stores class, arguments, and key for each value. + * + * @author yetanotherx + * + */ +public enum CUIEventType +{ + SELECTION(CUIEventSelection.class, "s", 1 ), + POINT (CUIEventPoint3D.class, "p", 5, 6 ), + POINT2D (CUIEventPoint2D.class, "p2", 4, 5 ), + ELLIPSOID(CUIEventEllipsoid.class, "e", 4 ), + CYLINDER (CUIEventCylinder.class, "cyl", 5 ), + MINMAX (CUIEventBounds.class, "mm", 2 ), + UPDATE (CUIEventUpdate.class, "u", 1 ), + POLYGON (CUIEventPolygon.class, "poly", 3, 99); + + private final Class eventClass; + private final String key; + private final String name; + private final int minParams; + private final int maxParams; + + private CUIEventType(Class eventClass, String key, int minParams, int maxParams) + { + this.eventClass = eventClass; + this.key = key; + this.name = eventClass.getSimpleName().substring(8); + this.minParams = minParams; + this.maxParams = maxParams; + } + + private CUIEventType(Class eventClass, String key, int paramCount) + { + this.eventClass = eventClass; + this.key = key; + this.name = eventClass.getSimpleName().substring(8); + this.minParams = paramCount; + this.maxParams = paramCount; + } + + public Class getEventClass() + { + return this.eventClass; + } + + public String getKey() + { + return this.key; + } + + public String getName() + { + return this.name; + } + + public int getMaxParameters() + { + return this.maxParams; + } + + public int getMinParameters() + { + return this.minParams; + } +} diff --git a/java/wecui/event/cui/CUIMinMaxEvent.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventBounds.java similarity index 58% rename from java/wecui/event/cui/CUIMinMaxEvent.java rename to java/com/mumfrey/worldeditcui/event/cui/CUIEventBounds.java index b7cfaba0..25057982 100644 --- a/java/wecui/event/cui/CUIMinMaxEvent.java +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventBounds.java @@ -1,6 +1,8 @@ -package wecui.event.cui; +package com.mumfrey.worldeditcui.event.cui; -import wecui.WorldEditCUI; +import com.mumfrey.worldeditcui.WorldEditCUI; +import com.mumfrey.worldeditcui.event.CUIEvent; +import com.mumfrey.worldeditcui.event.CUIEventType; /** * Called when resize event is received @@ -8,10 +10,10 @@ * @author lahwran * @author yetanotherx */ -public class CUIMinMaxEvent extends CUIBaseEvent +public class CUIEventBounds extends CUIEvent { - public CUIMinMaxEvent(WorldEditCUI controller, String[] args) + public CUIEventBounds(WorldEditCUI controller, String[] args) { super(controller, args); } @@ -23,7 +25,7 @@ public CUIEventType getEventType() } @Override - public String run() + public String raise() { int min = this.getInt(0); int max = this.getInt(1); diff --git a/java/wecui/event/cui/CUICylinderEvent.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventCylinder.java similarity index 65% rename from java/wecui/event/cui/CUICylinderEvent.java rename to java/com/mumfrey/worldeditcui/event/cui/CUIEventCylinder.java index 23bda14a..ebc8d1dd 100644 --- a/java/wecui/event/cui/CUICylinderEvent.java +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventCylinder.java @@ -1,6 +1,8 @@ -package wecui.event.cui; +package com.mumfrey.worldeditcui.event.cui; -import wecui.WorldEditCUI; +import com.mumfrey.worldeditcui.WorldEditCUI; +import com.mumfrey.worldeditcui.event.CUIEvent; +import com.mumfrey.worldeditcui.event.CUIEventType; /** * Called when cylinder event is received @@ -8,10 +10,10 @@ * @author lahwran * @author yetanotherx */ -public class CUICylinderEvent extends CUIBaseEvent +public class CUIEventCylinder extends CUIEvent { - public CUICylinderEvent(WorldEditCUI controller, String[] args) + public CUIEventCylinder(WorldEditCUI controller, String[] args) { super(controller, args); } @@ -23,7 +25,7 @@ public CUIEventType getEventType() } @Override - public String run() + public String raise() { int x = this.getInt(0); diff --git a/java/wecui/event/cui/CUIEllipsoidEvent.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventEllipsoid.java similarity index 68% rename from java/wecui/event/cui/CUIEllipsoidEvent.java rename to java/com/mumfrey/worldeditcui/event/cui/CUIEventEllipsoid.java index df7acb1a..1506a3af 100644 --- a/java/wecui/event/cui/CUIEllipsoidEvent.java +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventEllipsoid.java @@ -1,6 +1,8 @@ -package wecui.event.cui; +package com.mumfrey.worldeditcui.event.cui; -import wecui.WorldEditCUI; +import com.mumfrey.worldeditcui.WorldEditCUI; +import com.mumfrey.worldeditcui.event.CUIEvent; +import com.mumfrey.worldeditcui.event.CUIEventType; /** * Called when ellipsoid event is received @@ -8,10 +10,10 @@ * @author lahwran * @author yetanotherx */ -public class CUIEllipsoidEvent extends CUIBaseEvent +public class CUIEventEllipsoid extends CUIEvent { - public CUIEllipsoidEvent(WorldEditCUI controller, String[] args) + public CUIEventEllipsoid(WorldEditCUI controller, String[] args) { super(controller, args); } @@ -23,7 +25,7 @@ public CUIEventType getEventType() } @Override - public String run() + public String raise() { int id = this.getInt(0); diff --git a/java/wecui/event/cui/CUIPoint2DEvent.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventPoint2D.java similarity index 65% rename from java/wecui/event/cui/CUIPoint2DEvent.java rename to java/com/mumfrey/worldeditcui/event/cui/CUIEventPoint2D.java index 4f31e5e6..e6ed57d6 100644 --- a/java/wecui/event/cui/CUIPoint2DEvent.java +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventPoint2D.java @@ -1,6 +1,7 @@ -package wecui.event.cui; +package com.mumfrey.worldeditcui.event.cui; -import wecui.WorldEditCUI; +import com.mumfrey.worldeditcui.WorldEditCUI; +import com.mumfrey.worldeditcui.event.CUIEventType; /** * Called when poly point event is received @@ -8,10 +9,10 @@ * @author lahwran * @author yetanotherx */ -public class CUIPoint2DEvent extends CUIPointEvent +public class CUIEventPoint2D extends CUIEventPoint3D { - public CUIPoint2DEvent(WorldEditCUI controller, String[] args) + public CUIEventPoint2D(WorldEditCUI controller, String[] args) { super(controller, args); } @@ -23,7 +24,7 @@ public CUIEventType getEventType() } @Override - public String run() + public String raise() { int id = this.getInt(0); diff --git a/java/com/mumfrey/worldeditcui/event/cui/CUIEventPoint3D.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventPoint3D.java new file mode 100644 index 00000000..7b12ae6c --- /dev/null +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventPoint3D.java @@ -0,0 +1,39 @@ +package com.mumfrey.worldeditcui.event.cui; + +import com.mumfrey.worldeditcui.WorldEditCUI; +import com.mumfrey.worldeditcui.event.CUIEvent; +import com.mumfrey.worldeditcui.event.CUIEventType; + +/** + * Called when point event is received + * + * @author lahwran + * @author yetanotherx + */ +public class CUIEventPoint3D extends CUIEvent +{ + public CUIEventPoint3D(WorldEditCUI controller, String[] args) + { + super(controller, args); + } + + @Override + public CUIEventType getEventType() + { + return CUIEventType.POINT; + } + + @Override + public String raise() + { + int id = this.getInt(0); + double x = this.getDouble(1); + double y = this.getDouble(2); + double z = this.getDouble(3); + + this.controller.getSelection().setCuboidPoint(id, x, y, z); + this.controller.getDebugger().debug("Setting point #" + id); + + return null; + } +} diff --git a/java/wecui/event/cui/CUIPolygonEvent.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventPolygon.java similarity index 61% rename from java/wecui/event/cui/CUIPolygonEvent.java rename to java/com/mumfrey/worldeditcui/event/cui/CUIEventPolygon.java index 06d24523..08d1f43f 100644 --- a/java/wecui/event/cui/CUIPolygonEvent.java +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventPolygon.java @@ -1,6 +1,8 @@ -package wecui.event.cui; +package com.mumfrey.worldeditcui.event.cui; -import wecui.WorldEditCUI; +import com.mumfrey.worldeditcui.WorldEditCUI; +import com.mumfrey.worldeditcui.event.CUIEvent; +import com.mumfrey.worldeditcui.event.CUIEventType; /** * Called when polygon event is received @@ -8,10 +10,10 @@ * @author lahwran * @author yetanotherx */ -public class CUIPolygonEvent extends CUIBaseEvent +public class CUIEventPolygon extends CUIEvent { - public CUIPolygonEvent(WorldEditCUI controller, String[] args) + public CUIEventPolygon(WorldEditCUI controller, String[] args) { super(controller, args); } @@ -23,7 +25,7 @@ public CUIEventType getEventType() } @Override - public String run() + public String raise() { final int[] vertexIds = new int[args.length]; for (int i = 0; i < args.length; ++i) diff --git a/java/com/mumfrey/worldeditcui/event/cui/CUIEventSelection.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventSelection.java new file mode 100644 index 00000000..faacfb57 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventSelection.java @@ -0,0 +1,43 @@ +package com.mumfrey.worldeditcui.event.cui; + +import com.mumfrey.worldeditcui.WorldEditCUI; +import com.mumfrey.worldeditcui.event.CUIEvent; +import com.mumfrey.worldeditcui.event.CUIEventType; +import com.mumfrey.worldeditcui.render.region.BaseRegion; + +/** + * Called when selection event is received + * + * @author lahwran + * @author yetanotherx + */ +public class CUIEventSelection extends CUIEvent +{ + public CUIEventSelection(WorldEditCUI controller, String[] args) + { + super(controller, args); + } + + @Override + public CUIEventType getEventType() + { + return CUIEventType.SELECTION; + } + + @Override + public String raise() + { + String key = this.getString(0); + BaseRegion selection = this.controller.getSelectionProvider().createSelection(key); + + if (selection != null) + { + selection.initialize(); + } + + this.controller.setSelection(selection); + this.controller.getDebugger().debug("Received selection event, initalizing new region instance."); + + return null; + } +} diff --git a/java/com/mumfrey/worldeditcui/event/cui/CUIEventUpdate.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventUpdate.java new file mode 100644 index 00000000..c6384d42 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventUpdate.java @@ -0,0 +1,32 @@ +package com.mumfrey.worldeditcui.event.cui; + +import com.mumfrey.worldeditcui.WorldEditCUI; +import com.mumfrey.worldeditcui.event.CUIEvent; +import com.mumfrey.worldeditcui.event.CUIEventType; + +/** + * Called when update event is received + * + * @author lahwran + * @author yetanotherx + */ +public class CUIEventUpdate extends CUIEvent +{ + + public CUIEventUpdate(WorldEditCUI controller, String[] args) + { + super(controller, args); + } + + @Override + public CUIEventType getEventType() + { + return CUIEventType.UPDATE; + } + + @Override + public String raise() + { + return null; + } +} diff --git a/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerChannel.java b/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerChannel.java new file mode 100644 index 00000000..15d2f5d6 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerChannel.java @@ -0,0 +1,39 @@ +package com.mumfrey.worldeditcui.event.listeners; + +import com.mumfrey.worldeditcui.WorldEditCUI; +import com.mumfrey.worldeditcui.event.CUIEventArgs; + +/** + * Listener class for incoming plugin channel messages + * + * @author lahwran + * @author yetanotherx + * + */ +public class CUIListenerChannel +{ + private WorldEditCUI controller; + + public CUIListenerChannel(WorldEditCUI controller) + { + this.controller = controller; + } + + public void onMessage(String message) + { + String[] split = message.split("[|]"); + String type = split[0]; + String args = message.substring(type.length() + 1); + + this.controller.getDebugger().debug("Received CUI event from server: " + message); + + try + { + CUIEventArgs eventArgs = new CUIEventArgs(this.controller, type, args.split("[|]")); + this.controller.getDispatcher().raiseEvent(eventArgs); + } + catch (Exception ex) + { + } + } +} diff --git a/java/wecui/event/listeners/WorldRenderListener.java b/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerWorldRender.java similarity index 90% rename from java/wecui/event/listeners/WorldRenderListener.java rename to java/com/mumfrey/worldeditcui/event/listeners/CUIListenerWorldRender.java index 7bed7e28..2b46d691 100644 --- a/java/wecui/event/listeners/WorldRenderListener.java +++ b/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerWorldRender.java @@ -1,11 +1,13 @@ -package wecui.event.listeners; +package com.mumfrey.worldeditcui.event.listeners; import static org.lwjgl.opengl.GL11.*; + +import com.mumfrey.worldeditcui.WorldEditCUI; + import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityClientPlayerMP; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; -import wecui.WorldEditCUI; /** * Listener for WorldRenderEvent @@ -14,13 +16,13 @@ * @author yetanotherx * */ -public class WorldRenderListener +public class CUIListenerWorldRender { private WorldEditCUI controller; private Minecraft minecraft; - public WorldRenderListener(WorldEditCUI controller, Minecraft minecraft) + public CUIListenerWorldRender(WorldEditCUI controller, Minecraft minecraft) { this.controller = controller; this.minecraft = minecraft; diff --git a/java/wecui/exception/InitializationException.java b/java/com/mumfrey/worldeditcui/exceptions/InitializationException.java similarity index 89% rename from java/wecui/exception/InitializationException.java rename to java/com/mumfrey/worldeditcui/exceptions/InitializationException.java index 4075b5d2..f55fa9eb 100644 --- a/java/wecui/exception/InitializationException.java +++ b/java/com/mumfrey/worldeditcui/exceptions/InitializationException.java @@ -1,4 +1,4 @@ -package wecui.exception; +package com.mumfrey.worldeditcui.exceptions; /** * Special exception that only gets called during initialization diff --git a/java/com/mumfrey/worldeditcui/exceptions/InvalidSelectionTypeException.java b/java/com/mumfrey/worldeditcui/exceptions/InvalidSelectionTypeException.java new file mode 100644 index 00000000..2b3d92c7 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/exceptions/InvalidSelectionTypeException.java @@ -0,0 +1,11 @@ +package com.mumfrey.worldeditcui.exceptions; + +public class InvalidSelectionTypeException extends RuntimeException +{ + private static final long serialVersionUID = 1L; + + public InvalidSelectionTypeException(String regionType, String eventName) + { + super(String.format("Selection event %s is not supported for selection type %s", eventName, regionType)); + } +} diff --git a/java/wecui/gui/WorldEditCUIConfigPanel.java b/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java similarity index 86% rename from java/wecui/gui/WorldEditCUIConfigPanel.java rename to java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java index dbbdb86e..8360bd0f 100644 --- a/java/wecui/gui/WorldEditCUIConfigPanel.java +++ b/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java @@ -1,4 +1,4 @@ -package wecui.gui; +package com.mumfrey.worldeditcui.gui; import static org.lwjgl.opengl.GL11.*; @@ -7,8 +7,6 @@ import org.lwjgl.input.Keyboard; -import wecui.LiteModWorldEditCUI; -import wecui.render.LineColor; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; @@ -16,8 +14,12 @@ import com.mumfrey.liteloader.modconfig.ConfigPanel; import com.mumfrey.liteloader.modconfig.ConfigPanelHost; +import com.mumfrey.worldeditcui.LiteModWorldEditCUI; +import com.mumfrey.worldeditcui.gui.controls.GuiColourButton; +import com.mumfrey.worldeditcui.gui.controls.GuiControl; +import com.mumfrey.worldeditcui.render.LineColour; -public class WorldEditCUIConfigPanel extends Gui implements ConfigPanel +public class CUIConfigPanel extends Gui implements ConfigPanel { private Minecraft mc; @@ -29,7 +31,7 @@ public class WorldEditCUIConfigPanel extends Gui implements ConfigPanel private GuiControl activeControl; - public WorldEditCUIConfigPanel() + public CUIConfigPanel() { this.mc = Minecraft.getMinecraft(); } @@ -43,7 +45,7 @@ public String getPanelTitle() @Override public int getContentHeight() { - return LineColor.values().length * 24; + return LineColour.values().length * 24; } @Override @@ -57,9 +59,9 @@ public void onPanelShown(ConfigPanelHost host) this.controlList.clear(); int nextId = 0; - for (LineColor color : LineColor.values()) + for (LineColour colour : LineColour.values()) { - this.controlList.add(new GuiColourButton(this.mc, nextId, 10, nextId * 24, 40, 20, color)); + this.controlList.add(new GuiColourButton(this.mc, nextId, 10, nextId * 24, 40, 20, colour)); this.controlList.add(new GuiControl(this.mc, 100 + nextId, 220, nextId * 24, 60, 20, "Reset")); nextId++; } @@ -97,7 +99,7 @@ public void drawPanel(ConfigPanelHost host, int mouseX, int mouseY, float partia { for (GuiControl control : this.controlList) { - control.drawControl(this.mc, mouseX, mouseY); + control.drawButton(this.mc, mouseX, mouseY); } for (GuiColourButton colourButton : this.colourButtonList) @@ -129,7 +131,7 @@ private void actionPerformed(GuiControl control) { if (control.id >= 100) { - LineColor lineColour = LineColor.values()[control.id - 100]; + LineColour lineColour = LineColour.values()[control.id - 100]; lineColour.setDefaultColour(); for (GuiColourButton colourButton : this.colourButtonList) diff --git a/java/wecui/gui/GuiColourButton.java b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java similarity index 95% rename from java/wecui/gui/GuiColourButton.java rename to java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java index 42679ed9..eeaba03b 100644 --- a/java/wecui/gui/GuiColourButton.java +++ b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java @@ -1,7 +1,9 @@ -package wecui.gui; +package com.mumfrey.worldeditcui.gui.controls; import static org.lwjgl.opengl.GL11.*; -import wecui.render.LineColor; + +import com.mumfrey.worldeditcui.render.LineColour; + import net.minecraft.client.Minecraft; /** @@ -16,13 +18,13 @@ public class GuiColourButton extends GuiControl */ private int colour = 0xFF000000; - private LineColor lineColour; + private LineColour lineColour; private GuiColourPicker picker; private boolean pickerClicked = false; - public GuiColourButton(Minecraft minecraft, int id, int xPosition, int yPosition, int controlWidth, int controlHeight, LineColor lineColour) + public GuiColourButton(Minecraft minecraft, int id, int xPosition, int yPosition, int controlWidth, int controlHeight, LineColour lineColour) { super(minecraft, id, xPosition, yPosition, controlWidth, controlHeight, lineColour.getDisplayName()); this.lineColour = lineColour; @@ -32,7 +34,7 @@ public GuiColourButton(Minecraft minecraft, int id, int xPosition, int yPosition /** * @param lineColour */ - public void updateColour(LineColor lineColour) + public void updateColour(LineColour lineColour) { if (lineColour == this.lineColour) { diff --git a/java/wecui/gui/GuiColourPicker.java b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java similarity index 99% rename from java/wecui/gui/GuiColourPicker.java rename to java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java index 12e31a9f..98ab1b10 100644 --- a/java/wecui/gui/GuiColourPicker.java +++ b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java @@ -1,4 +1,4 @@ -package wecui.gui; +package com.mumfrey.worldeditcui.gui.controls; import static org.lwjgl.opengl.GL11.*; diff --git a/java/wecui/gui/GuiControl.java b/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java similarity index 99% rename from java/wecui/gui/GuiControl.java rename to java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java index 56dd5f7d..ada19ec3 100644 --- a/java/wecui/gui/GuiControl.java +++ b/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java @@ -1,4 +1,4 @@ -package wecui.gui; +package com.mumfrey.worldeditcui.gui.controls; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; diff --git a/java/com/mumfrey/worldeditcui/render/CUISelectionProvider.java b/java/com/mumfrey/worldeditcui/render/CUISelectionProvider.java new file mode 100644 index 00000000..03d9194b --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/CUISelectionProvider.java @@ -0,0 +1,66 @@ +package com.mumfrey.worldeditcui.render; + +import java.lang.reflect.Constructor; +import java.util.HashMap; +import java.util.Map; + +import com.mumfrey.worldeditcui.InitializationFactory; +import com.mumfrey.worldeditcui.WorldEditCUI; +import com.mumfrey.worldeditcui.exceptions.InitializationException; +import com.mumfrey.worldeditcui.render.region.BaseRegion; +import com.mumfrey.worldeditcui.render.region.RegionType; + +/** + * + * @author Adam Mummery-Smith + */ +public class CUISelectionProvider implements InitializationFactory +{ + private Map> regionConstructors = new HashMap>(); + + private WorldEditCUI controller; + + public CUISelectionProvider(WorldEditCUI controller) + { + this.controller = controller; + } + + @Override + public void initialize() throws InitializationException + { + for (RegionType regionType : RegionType.values()) + { + try + { + Class eventClass = regionType.getRegionClass(); + Constructor ctor = eventClass.getDeclaredConstructor(WorldEditCUI.class); + + this.regionConstructors.put(regionType.getKey(), ctor); + } + catch (NoSuchMethodException ex) + { + this.controller.getDebugger().debug("Error getting constructor for region type " + regionType.getKey()); + } + } + } + + public BaseRegion createSelection(String key) + { + try + { + Constructor regionCtor = this.regionConstructors.get(key); + BaseRegion region = regionCtor.newInstance(this.controller); + return region; + } + catch (NullPointerException ex) + { + this.controller.getDebugger().debug("No such selection type " + key); + } + catch (Exception ex) + { + this.controller.getDebugger().debug("Error creation " + key + " selection: " + ex.getClass().getSimpleName() + " " + ex.getMessage()); + } + + return null; + } +} diff --git a/java/wecui/render/LineColor.java b/java/com/mumfrey/worldeditcui/render/LineColour.java similarity index 87% rename from java/wecui/render/LineColor.java rename to java/com/mumfrey/worldeditcui/render/LineColour.java index 71184b47..92efa916 100644 --- a/java/wecui/render/LineColor.java +++ b/java/com/mumfrey/worldeditcui/render/LineColour.java @@ -1,13 +1,12 @@ -package wecui.render; +package com.mumfrey.worldeditcui.render; -import net.minecraft.client.resources.I18n; +import com.mumfrey.worldeditcui.config.Colour; +import net.minecraft.client.resources.I18n; import static org.lwjgl.opengl.GL11.*; -import wecui.config.Colour; - /** - * Stores color data for each type of line. + * Stores colour data for each type of line. * * Each line has a normal line, and a hidden line. * The normal line has an alpha value of 0.8f, and @@ -17,7 +16,7 @@ * @author yetanotherx * @author lahwran */ -public enum LineColor +public enum LineColour { CUBOIDBOX ("colour.cuboidedge", new Colour("#CC3333CC")), CUBOIDGRID ("colour.cuboidgrid", new Colour("#CC4C4CCC")), @@ -40,12 +39,11 @@ public enum LineColor private LineInfo normal; private LineInfo hidden; - private LineColor(String displayName, Colour colour) + private LineColour(String displayName, Colour colour) { this.displayName = displayName; this.colour = colour; this.defaultColour = new Colour().copyFrom(colour); - ; } public String getDisplayName() @@ -68,7 +66,7 @@ public LineInfo getNormal() return this.normal; } - public LineInfo[] getColors() + public LineInfo[] getColours() { return new LineInfo[] { this.hidden, this.normal }; } @@ -76,10 +74,10 @@ public LineInfo[] getColors() public void setColour(Colour colour) { this.colour = colour; - this.updateColor(); + this.updateColour(); } - public void updateColor() + public void updateColour() { this.normal = new LineInfo(3.0f, colour.red(), colour.green(), colour.blue(), colour.alpha(), GL_LESS); this.hidden = new LineInfo(3.0f, colour.red(), colour.green(), colour.blue(), colour.alpha() * 0.25F, GL_GEQUAL); @@ -88,14 +86,14 @@ public void updateColor() public void setDefaultColour() { this.colour.copyFrom(this.defaultColour); - this.updateColor(); + this.updateColour(); } public void setColourIntRGBA(int argb) { int rgba = ((argb << 8) & 0xFFFFFF00) | (((argb & 0xFF000000) >> 24) & 0xFF); this.colour.setHex(Integer.toHexString(rgba)); - this.updateColor(); + this.updateColour(); } public int getColourIntARGB() diff --git a/java/wecui/render/LineInfo.java b/java/com/mumfrey/worldeditcui/render/LineInfo.java similarity index 88% rename from java/wecui/render/LineInfo.java rename to java/com/mumfrey/worldeditcui/render/LineInfo.java index f7b7c1a7..888875c8 100644 --- a/java/wecui/render/LineInfo.java +++ b/java/com/mumfrey/worldeditcui/render/LineInfo.java @@ -1,4 +1,4 @@ -package wecui.render; +package com.mumfrey.worldeditcui.render; import static org.lwjgl.opengl.GL11.*; @@ -45,7 +45,7 @@ public LineInfo(LineInfo orig) } /** - * Sets the lineWidth and depthFunction based on this color + * Sets the lineWidth and depthFunction based on this colour */ public void prepareRender() { @@ -53,7 +53,7 @@ public void prepareRender() glDepthFunc(this.depthfunc); } - public void prepareColor() + public void prepareColour() { glColor4f(this.red, this.green, this.blue, this.alpha); } diff --git a/java/wecui/render/points/PointCube.java b/java/com/mumfrey/worldeditcui/render/points/PointCube.java similarity index 60% rename from java/wecui/render/points/PointCube.java rename to java/com/mumfrey/worldeditcui/render/points/PointCube.java index 881af4e5..ac2a38cb 100644 --- a/java/wecui/render/points/PointCube.java +++ b/java/com/mumfrey/worldeditcui/render/points/PointCube.java @@ -1,14 +1,14 @@ -package wecui.render.points; +package com.mumfrey.worldeditcui.render.points; -import wecui.render.LineColor; -import wecui.render.shapes.Render3DBox; -import wecui.util.Vector3; +import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.shapes.Render3DBox; +import com.mumfrey.worldeditcui.util.Vector3; /** * Stores data about a cube surrounding a * block in the world. Used to store info * about the selector blocks. Keeps track - * of color, x/y/z values, and rendering. + * of colour, x/y/z values, and rendering. * * @author yetanotherx * @author lahwran @@ -17,7 +17,7 @@ public class PointCube { protected Vector3 point; - protected LineColor color = LineColor.CUBOIDPOINT1; + protected LineColour colour = LineColour.CUBOIDPOINT1; public PointCube(Vector3 point) { @@ -40,7 +40,7 @@ public void render() Vector3 minVec = new Vector3(off, off, off); Vector3 maxVec = new Vector3(off + 1, off + 1, off + 1); - new Render3DBox(this.color, this.point.subtract(minVec), this.point.add(maxVec)).render(); + new Render3DBox(this.colour, this.point.subtract(minVec), this.point.add(maxVec)).render(); } public Vector3 getPoint() @@ -53,13 +53,13 @@ public void setPoint(Vector3 point) this.point = point; } - public LineColor getColor() + public LineColour getColour() { - return this.color; + return this.colour; } - public void setColor(LineColor color) + public void setColour(LineColour colour) { - this.color = color; + this.colour = colour; } } diff --git a/java/wecui/render/points/PointRectangle.java b/java/com/mumfrey/worldeditcui/render/points/PointRectangle.java similarity index 55% rename from java/wecui/render/points/PointRectangle.java rename to java/com/mumfrey/worldeditcui/render/points/PointRectangle.java index 45988c0f..be576c33 100644 --- a/java/wecui/render/points/PointRectangle.java +++ b/java/com/mumfrey/worldeditcui/render/points/PointRectangle.java @@ -1,14 +1,14 @@ -package wecui.render.points; +package com.mumfrey.worldeditcui.render.points; -import wecui.render.LineColor; -import wecui.render.shapes.Render3DBox; -import wecui.util.Vector2; +import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.shapes.Render3DBox; +import com.mumfrey.worldeditcui.util.Vector2; /** * Stores data about a prism surrounding two * blocks in the world. Used to store info * about the selector blocks for polys. Keeps - * track of color, x/y/z values, and rendering. + * track of colour, x/y/z values, and rendering. * * @author yetanotherx * @author lahwran @@ -17,7 +17,7 @@ public class PointRectangle { protected Vector2 point; - protected LineColor color = LineColor.POLYPOINT; + protected LineColour colour = LineColour.POLYPOINT; public PointRectangle(Vector2 point) { @@ -35,7 +35,7 @@ public void render(int min, int max) Vector2 minVec = new Vector2(off, off); Vector2 maxVec = new Vector2(off + 1, off + 1); - new Render3DBox(this.color, this.point.subtract(minVec).toVector3(min - off), this.point.add(maxVec).toVector3(max + 1 + off)).render(); + new Render3DBox(this.colour, this.point.subtract(minVec).toVector3(min - off), this.point.add(maxVec).toVector3(max + 1 + off)).render(); } public Vector2 getPoint() @@ -48,13 +48,13 @@ public void setPoint(Vector2 point) this.point = point; } - public LineColor getColor() + public LineColour getColour() { - return this.color; + return this.colour; } - public void setColor(LineColor color) + public void setColour(LineColour colour) { - this.color = color; + this.colour = colour; } } diff --git a/java/wecui/render/region/BaseRegion.java b/java/com/mumfrey/worldeditcui/render/region/BaseRegion.java similarity index 50% rename from java/wecui/render/region/BaseRegion.java rename to java/com/mumfrey/worldeditcui/render/region/BaseRegion.java index 1cbc705d..9234927e 100644 --- a/java/wecui/render/region/BaseRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/BaseRegion.java @@ -1,7 +1,8 @@ -package wecui.render.region; +package com.mumfrey.worldeditcui.render.region; -import wecui.InitializationFactory; -import wecui.WorldEditCUI; +import com.mumfrey.worldeditcui.InitializationFactory; +import com.mumfrey.worldeditcui.WorldEditCUI; +import com.mumfrey.worldeditcui.exceptions.InvalidSelectionTypeException; /** * Base region storage class. Provides @@ -30,34 +31,42 @@ public void initialize() public void setCuboidPoint(int id, double x, double y, double z) { + throw new InvalidSelectionTypeException(this.getType().getName(), "setCuboidPoint"); } public void setPolygonPoint(int id, int x, int z) { + throw new InvalidSelectionTypeException(this.getType().getName(), "setPolygonPoint"); } public void setEllipsoidCenter(int x, int y, int z) { + throw new InvalidSelectionTypeException(this.getType().getName(), "setEllipsoidCenter"); } public void setEllipsoidRadii(double x, double y, double z) { + throw new InvalidSelectionTypeException(this.getType().getName(), "setEllipsoidRadii"); } public void setMinMax(int min, int max) { + throw new InvalidSelectionTypeException(this.getType().getName(), "setMinMax"); } public void setCylinderCenter(int x, int y, int z) { + throw new InvalidSelectionTypeException(this.getType().getName(), "setCylinderCenter"); } public void setCylinderRadius(double x, double z) { + throw new InvalidSelectionTypeException(this.getType().getName(), "setCylinderRadius"); } public void addPolygon(int[] vertexIds) { + throw new InvalidSelectionTypeException(this.getType().getName(), "addPolygon"); } public abstract RegionType getType(); diff --git a/java/wecui/render/region/CuboidRegion.java b/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java similarity index 76% rename from java/wecui/render/region/CuboidRegion.java rename to java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java index 74af4307..e3a347a6 100644 --- a/java/wecui/render/region/CuboidRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java @@ -1,12 +1,12 @@ -package wecui.render.region; +package com.mumfrey.worldeditcui.render.region; -import wecui.WorldEditCUI; -import wecui.render.LineColor; -import wecui.render.points.PointCube; -import wecui.render.shapes.Render3DBox; -import wecui.render.shapes.Render3DGrid; -import wecui.util.Vector3; -import wecui.util.Vector3m; +import com.mumfrey.worldeditcui.WorldEditCUI; +import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.points.PointCube; +import com.mumfrey.worldeditcui.render.shapes.Render3DBox; +import com.mumfrey.worldeditcui.render.shapes.Render3DGrid; +import com.mumfrey.worldeditcui.util.Vector3; +import com.mumfrey.worldeditcui.util.Vector3m; /** * Main controller for a cuboid-type region @@ -32,8 +32,8 @@ public void render() { Vector3[] bounds = this.calcBounds(); - new Render3DGrid(LineColor.CUBOIDGRID, bounds[0], bounds[1]).render(); - new Render3DBox(LineColor.CUBOIDBOX, bounds[0], bounds[1]).render(); + new Render3DGrid(LineColour.CUBOIDGRID, bounds[0], bounds[1]).render(); + new Render3DBox(LineColour.CUBOIDBOX, bounds[0], bounds[1]).render(); this.firstPoint.render(); this.secondPoint.render(); @@ -55,12 +55,12 @@ public void setCuboidPoint(int id, double x, double y, double z) if (id == 0) { this.firstPoint = new PointCube(x, y, z); - this.firstPoint.setColor(LineColor.CUBOIDPOINT1); + this.firstPoint.setColour(LineColour.CUBOIDPOINT1); } else if (id == 1) { this.secondPoint = new PointCube(x, y, z); - this.secondPoint.setColor(LineColor.CUBOIDPOINT2); + this.secondPoint.setColour(LineColour.CUBOIDPOINT2); } } diff --git a/java/wecui/render/region/CylinderRegion.java b/java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java similarity index 57% rename from java/wecui/render/region/CylinderRegion.java rename to java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java index 5dc6de8f..a6818af5 100644 --- a/java/wecui/render/region/CylinderRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java @@ -1,11 +1,11 @@ -package wecui.render.region; +package com.mumfrey.worldeditcui.render.region; -import wecui.WorldEditCUI; -import wecui.render.LineColor; -import wecui.render.points.PointCube; -import wecui.render.shapes.RenderCylinderBox; -import wecui.render.shapes.RenderCylinderCircles; -import wecui.render.shapes.RenderCylinderGrid; +import com.mumfrey.worldeditcui.WorldEditCUI; +import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.points.PointCube; +import com.mumfrey.worldeditcui.render.shapes.RenderCylinderBox; +import com.mumfrey.worldeditcui.render.shapes.RenderCylinderCircles; +import com.mumfrey.worldeditcui.render.shapes.RenderCylinderGrid; /** * Main controller for a cylinder-type region @@ -42,9 +42,9 @@ public void render() tMax = (int)this.center.getPoint().getY(); } - new RenderCylinderCircles(LineColor.CYLINDERGRID, this.center, this.radX, this.radZ, tMin, tMax).render(); - new RenderCylinderGrid(LineColor.CYLINDERGRID, this.center, this.radX, this.radZ, tMin, tMax).render(); - new RenderCylinderBox(LineColor.CYLINDERBOX, this.center, this.radX, this.radZ, tMin, tMax).render(); + new RenderCylinderCircles(LineColour.CYLINDERGRID, this.center, this.radX, this.radZ, tMin, tMax).render(); + new RenderCylinderGrid(LineColour.CYLINDERGRID, this.center, this.radX, this.radZ, tMin, tMax).render(); + new RenderCylinderBox(LineColour.CYLINDERBOX, this.center, this.radX, this.radZ, tMin, tMax).render(); } } @@ -53,7 +53,7 @@ public void render() public void setCylinderCenter(int x, int y, int z) { this.center = new PointCube(x, y, z); - this.center.setColor(LineColor.CYLINDERCENTER); + this.center.setColour(LineColour.CYLINDERCENTER); } @Override diff --git a/java/wecui/render/region/EllipsoidRegion.java b/java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java similarity index 63% rename from java/wecui/render/region/EllipsoidRegion.java rename to java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java index 6859e13d..b849fa79 100644 --- a/java/wecui/render/region/EllipsoidRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java @@ -1,10 +1,10 @@ -package wecui.render.region; +package com.mumfrey.worldeditcui.render.region; -import wecui.WorldEditCUI; -import wecui.render.LineColor; -import wecui.render.points.PointCube; -import wecui.render.shapes.RenderEllipsoid; -import wecui.util.Vector3; +import com.mumfrey.worldeditcui.WorldEditCUI; +import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.points.PointCube; +import com.mumfrey.worldeditcui.render.shapes.RenderEllipsoid; +import com.mumfrey.worldeditcui.util.Vector3; /** * Main controller for a ellipsoid-type region @@ -30,7 +30,7 @@ public void render() { this.center.render(); - new RenderEllipsoid(LineColor.ELLIPSOIDGRID, this.center, this.radii).render(); + new RenderEllipsoid(LineColour.ELLIPSOIDGRID, this.center, this.radii).render(); } else if (this.center != null) @@ -43,7 +43,7 @@ else if (this.center != null) public void setEllipsoidCenter(int x, int y, int z) { this.center = new PointCube(x, y, z); - this.center.setColor(LineColor.ELLIPSOIDCENTER); + this.center.setColour(LineColour.ELLIPSOIDCENTER); } @Override diff --git a/java/wecui/render/region/PolygonRegion.java b/java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java similarity index 66% rename from java/wecui/render/region/PolygonRegion.java rename to java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java index 6a0d5973..b79b9b0d 100644 --- a/java/wecui/render/region/PolygonRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java @@ -1,13 +1,13 @@ -package wecui.render.region; +package com.mumfrey.worldeditcui.render.region; import java.util.ArrayList; import java.util.List; -import wecui.WorldEditCUI; -import wecui.render.LineColor; -import wecui.render.points.PointRectangle; -import wecui.render.shapes.Render2DBox; -import wecui.render.shapes.Render2DGrid; +import com.mumfrey.worldeditcui.WorldEditCUI; +import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.points.PointRectangle; +import com.mumfrey.worldeditcui.render.shapes.Render2DBox; +import com.mumfrey.worldeditcui.render.shapes.Render2DGrid; /** * Main controller for a polygon-type region @@ -40,8 +40,8 @@ public void render() point.render(this.min, this.max); } - new Render2DBox(LineColor.POLYBOX, this.points, this.min, this.max).render(); - new Render2DGrid(LineColor.POLYGRID, this.points, this.min, this.max).render(); + new Render2DBox(LineColour.POLYBOX, this.points, this.min, this.max).render(); + new Render2DGrid(LineColour.POLYGRID, this.points, this.min, this.max).render(); } @@ -56,7 +56,7 @@ public void setMinMax(int min, int max) public void setPolygonPoint(int id, int x, int z) { PointRectangle point = new PointRectangle(x, z); - point.setColor(LineColor.POLYPOINT); + point.setColour(LineColour.POLYPOINT); if (id < this.points.size()) { diff --git a/java/wecui/render/region/PolyhedronRegion.java b/java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java similarity index 75% rename from java/wecui/render/region/PolyhedronRegion.java rename to java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java index 8759a40c..bcba17f5 100644 --- a/java/wecui/render/region/PolyhedronRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java @@ -1,13 +1,13 @@ -package wecui.render.region; +package com.mumfrey.worldeditcui.render.region; import java.util.ArrayList; import java.util.List; -import wecui.WorldEditCUI; -import wecui.render.LineColor; -import wecui.render.points.PointCube; -import wecui.render.shapes.Render3DPolygon; -import wecui.util.Vector3; +import com.mumfrey.worldeditcui.WorldEditCUI; +import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.points.PointCube; +import com.mumfrey.worldeditcui.render.shapes.Render3DPolygon; +import com.mumfrey.worldeditcui.util.Vector3; /** * Main controller for a polygon-type region @@ -35,7 +35,7 @@ public void render() for (Vector3[] face : this.faces) { - new Render3DPolygon(LineColor.POLYBOX, face).render(); + new Render3DPolygon(LineColour.POLYBOX, face).render(); } } @@ -43,7 +43,7 @@ public void render() public void setCuboidPoint(int id, double x, double y, double z) { final PointCube vertex = new PointCube(x, y, z); - vertex.setColor(id == 0 ? LineColor.CUBOIDPOINT1 : LineColor.POLYPOINT); + vertex.setColour(id == 0 ? LineColour.CUBOIDPOINT1 : LineColour.POLYPOINT); if (id < this.vertices.size()) { diff --git a/java/com/mumfrey/worldeditcui/render/region/RegionType.java b/java/com/mumfrey/worldeditcui/render/region/RegionType.java new file mode 100644 index 00000000..11ecde37 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/region/RegionType.java @@ -0,0 +1,43 @@ +package com.mumfrey.worldeditcui.render.region; + +/** + * The different types of regions and the classes which we use to display them + * + * @author Adam Mummery-Smith + */ +public enum RegionType +{ + CUBOID ("cuboid", "Cuboid", CuboidRegion.class), + POLYGON ("polygon2d", "2D Polygon", PolygonRegion.class), + ELLIPSOID ("ellipsoid", "Ellipsoid", EllipsoidRegion.class), + CYLINDER ("cylinder", "Cylinder", CylinderRegion.class), + POLYHEDRON("polyhedron", "Polyhedron", PolyhedronRegion.class); + + private final String key; + + private final String name; + + private final Class regionClass; + + private RegionType(String key, String name, Class regionClass) + { + this.key = key; + this.name = name; + this.regionClass = regionClass; + } + + public String getKey() + { + return this.key; + } + + public String getName() + { + return this.name; + } + + public Class getRegionClass() + { + return this.regionClass; + } +} diff --git a/java/wecui/render/shapes/Render2DBox.java b/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java similarity index 64% rename from java/wecui/render/shapes/Render2DBox.java rename to java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java index 178ee6d1..5e6367f1 100644 --- a/java/wecui/render/shapes/Render2DBox.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java @@ -1,15 +1,14 @@ -package wecui.render.shapes; +package com.mumfrey.worldeditcui.render.shapes; import java.util.List; -import net.minecraft.client.renderer.Tessellator; +import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.LineInfo; +import com.mumfrey.worldeditcui.render.points.PointRectangle; +import net.minecraft.client.renderer.Tessellator; import static org.lwjgl.opengl.GL11.*; -import wecui.render.LineColor; -import wecui.render.LineInfo; -import wecui.render.points.PointRectangle; - /** * Draws the top and bottom rings of a polygon region * @@ -19,14 +18,14 @@ public class Render2DBox { - protected LineColor color; + protected LineColour colour; protected List points; protected int min; protected int max; - public Render2DBox(LineColor color, List points, int min, int max) + public Render2DBox(LineColour colour, List points, int min, int max) { - this.color = color; + this.colour = colour; this.points = points; this.min = min; this.max = max; @@ -36,12 +35,12 @@ public void render() { Tessellator tess = Tessellator.instance; double off = 0.03; - for (LineInfo tempColor : this.color.getColors()) + for (LineInfo tempColour : this.colour.getColours()) { - tempColor.prepareRender(); + tempColour.prepareRender(); tess.startDrawing(GL_LINES); - tempColor.prepareColor(); + tempColour.prepareColour(); for (PointRectangle point : this.points) { diff --git a/java/wecui/render/shapes/Render2DGrid.java b/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java similarity index 65% rename from java/wecui/render/shapes/Render2DGrid.java rename to java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java index 123f406f..c68c4113 100644 --- a/java/wecui/render/shapes/Render2DGrid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java @@ -1,15 +1,14 @@ -package wecui.render.shapes; +package com.mumfrey.worldeditcui.render.shapes; import java.util.List; -import net.minecraft.client.renderer.Tessellator; +import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.LineInfo; +import com.mumfrey.worldeditcui.render.points.PointRectangle; +import net.minecraft.client.renderer.Tessellator; import static org.lwjgl.opengl.GL11.*; -import wecui.render.LineColor; -import wecui.render.LineInfo; -import wecui.render.points.PointRectangle; - /** * Draws the grid for a polygon region * @@ -18,14 +17,14 @@ */ public class Render2DGrid { - protected LineColor color; + protected LineColour colour; protected List points; protected int min; protected int max; - public Render2DGrid(LineColor color, List points, int min, int max) + public Render2DGrid(LineColour colour, List points, int min, int max) { - this.color = color; + this.colour = colour; this.points = points; this.min = min; this.max = max; @@ -43,12 +42,12 @@ public void render() protected void drawPoly(double height) { Tessellator tess = Tessellator.instance; - for (LineInfo tempColor : this.color.getColors()) + for (LineInfo tempColour : this.colour.getColours()) { - tempColor.prepareRender(); + tempColour.prepareRender(); tess.startDrawing(GL_LINE_LOOP); - tempColor.prepareColor(); + tempColour.prepareColour(); for (PointRectangle point : this.points) { if (point != null) diff --git a/java/wecui/render/shapes/Render3DBox.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java similarity index 73% rename from java/wecui/render/shapes/Render3DBox.java rename to java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java index a326feec..20eea9ac 100644 --- a/java/wecui/render/shapes/Render3DBox.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java @@ -1,13 +1,12 @@ -package wecui.render.shapes; +package com.mumfrey.worldeditcui.render.shapes; -import net.minecraft.client.renderer.Tessellator; +import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.LineInfo; +import com.mumfrey.worldeditcui.util.Vector3; +import net.minecraft.client.renderer.Tessellator; import static org.lwjgl.opengl.GL11.*; -import wecui.render.LineColor; -import wecui.render.LineInfo; -import wecui.util.Vector3; - /** * Draws a rectangular prism around 2 corners * @@ -17,13 +16,13 @@ public class Render3DBox { - protected LineColor color; + protected LineColour colour; protected Vector3 first; protected Vector3 second; - public Render3DBox(LineColor color, Vector3 first, Vector3 second) + public Render3DBox(LineColour colour, Vector3 first, Vector3 second) { - this.color = color; + this.colour = colour; this.first = first; this.second = second; } @@ -38,13 +37,13 @@ public void render() double y2 = this.second.getY(); double z2 = this.second.getZ(); - for (LineInfo tempColor : this.color.getColors()) + for (LineInfo tempColour : this.colour.getColours()) { - tempColor.prepareRender(); + tempColour.prepareRender(); // Draw bottom face tess.startDrawing(GL_LINE_LOOP); - tempColor.prepareColor(); + tempColour.prepareColour(); tess.addVertex(x1, y1, z1); tess.addVertex(x2, y1, z1); tess.addVertex(x2, y1, z2); @@ -53,7 +52,7 @@ public void render() // Draw top face tess.startDrawing(GL_LINE_LOOP); - tempColor.prepareColor(); + tempColour.prepareColour(); tess.addVertex(x1, y2, z1); tess.addVertex(x2, y2, z1); tess.addVertex(x2, y2, z2); @@ -62,7 +61,7 @@ public void render() // Draw join top and bottom faces tess.startDrawing(GL_LINES); - tempColor.prepareColor(); + tempColour.prepareColour(); tess.addVertex(x1, y1, z1); tess.addVertex(x1, y2, z1); diff --git a/java/wecui/render/shapes/Render3DGrid.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java similarity index 89% rename from java/wecui/render/shapes/Render3DGrid.java rename to java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java index a02c3c24..6668c5a6 100644 --- a/java/wecui/render/shapes/Render3DGrid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java @@ -1,13 +1,12 @@ -package wecui.render.shapes; +package com.mumfrey.worldeditcui.render.shapes; -import net.minecraft.client.renderer.Tessellator; +import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.LineInfo; +import com.mumfrey.worldeditcui.util.Vector3; +import net.minecraft.client.renderer.Tessellator; import static org.lwjgl.opengl.GL11.*; -import wecui.render.LineColor; -import wecui.render.LineInfo; -import wecui.util.Vector3; - /** * Draws the grid for a region between * two corners in a cuboid region. @@ -17,13 +16,13 @@ public class Render3DGrid { - protected LineColor color; + protected LineColour colour; protected Vector3 first; protected Vector3 second; - public Render3DGrid(LineColor color, Vector3 first, Vector3 second) + public Render3DGrid(LineColour colour, Vector3 first, Vector3 second) { - this.color = color; + this.colour = colour; this.first = first; this.second = second; } @@ -38,12 +37,12 @@ public void render() double y2 = this.second.getY(); double z2 = this.second.getZ(); - for (LineInfo tempColor : this.color.getColors()) + for (LineInfo tempColour : this.colour.getColours()) { - tempColor.prepareRender(); + tempColour.prepareRender(); tess.startDrawing(GL_LINES); - tempColor.prepareColor(); + tempColour.prepareColour(); double x, y, z; double offsetSize = 1.0; diff --git a/java/wecui/render/shapes/Render3DPolygon.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java similarity index 54% rename from java/wecui/render/shapes/Render3DPolygon.java rename to java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java index 4ad15a95..53f793c6 100644 --- a/java/wecui/render/shapes/Render3DPolygon.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java @@ -1,13 +1,12 @@ -package wecui.render.shapes; +package com.mumfrey.worldeditcui.render.shapes; -import net.minecraft.client.renderer.Tessellator; +import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.LineInfo; +import com.mumfrey.worldeditcui.util.Vector3; +import net.minecraft.client.renderer.Tessellator; import static org.lwjgl.opengl.GL11.*; -import wecui.render.LineColor; -import wecui.render.LineInfo; -import wecui.util.Vector3; - /** * Draws a polygon * @@ -17,12 +16,12 @@ public class Render3DPolygon { - protected LineColor color; + protected LineColour colour; protected Vector3[] vertices; - public Render3DPolygon(LineColor color, Vector3... vertices) + public Render3DPolygon(LineColour colour, Vector3... vertices) { - this.color = color; + this.colour = colour; this.vertices = vertices; } @@ -30,12 +29,12 @@ public void render() { Tessellator tess = Tessellator.instance; - for (LineInfo tempColor : this.color.getColors()) + for (LineInfo tempColour : this.colour.getColours()) { - tempColor.prepareRender(); + tempColour.prepareRender(); tess.startDrawing(GL_LINE_LOOP); - tempColor.prepareColor(); + tempColour.prepareColour(); for (Vector3 vertex : vertices) { tess.addVertex(vertex.getX(), vertex.getY(), vertex.getZ()); diff --git a/java/wecui/render/shapes/RenderCylinderBox.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java similarity index 69% rename from java/wecui/render/shapes/RenderCylinderBox.java rename to java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java index 0fe6ff41..6f222671 100644 --- a/java/wecui/render/shapes/RenderCylinderBox.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java @@ -1,13 +1,12 @@ -package wecui.render.shapes; +package com.mumfrey.worldeditcui.render.shapes; -import net.minecraft.client.renderer.Tessellator; +import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.LineInfo; +import com.mumfrey.worldeditcui.render.points.PointCube; +import net.minecraft.client.renderer.Tessellator; import static org.lwjgl.opengl.GL11.*; -import wecui.render.LineColor; -import wecui.render.LineInfo; -import wecui.render.points.PointCube; - /** * Draws the top and bottom circles around a cylindrical region * @@ -16,7 +15,7 @@ public class RenderCylinderBox { - protected LineColor color; + protected LineColour colour; protected double radX = 0; protected double radZ = 0; protected int minY; @@ -24,9 +23,9 @@ public class RenderCylinderBox protected double centerX; protected double centerZ; - public RenderCylinderBox(LineColor color, PointCube center, double radX, double radZ, int minY, int maxY) + public RenderCylinderBox(LineColour colour, PointCube center, double radX, double radZ, int minY, int maxY) { - this.color = color; + this.colour = colour; this.radX = radX; this.radZ = radZ; this.minY = minY; @@ -38,15 +37,15 @@ public RenderCylinderBox(LineColor color, PointCube center, double radX, double public void render() { Tessellator tess = Tessellator.instance; - for (LineInfo tempColor : this.color.getColors()) + for (LineInfo tempColour : this.colour.getColours()) { - tempColor.prepareRender(); + tempColour.prepareRender(); double twoPi = Math.PI * 2; for (int yBlock : new int[] { this.minY, this.maxY + 1 }) { tess.startDrawing(GL_LINE_LOOP); - tempColor.prepareColor(); + tempColour.prepareColour(); for (int i = 0; i <= 75; i++) { diff --git a/java/wecui/render/shapes/RenderCylinderCircles.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java similarity index 68% rename from java/wecui/render/shapes/RenderCylinderCircles.java rename to java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java index a6325eb1..3aeca6ca 100644 --- a/java/wecui/render/shapes/RenderCylinderCircles.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java @@ -1,13 +1,12 @@ -package wecui.render.shapes; +package com.mumfrey.worldeditcui.render.shapes; -import net.minecraft.client.renderer.Tessellator; +import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.LineInfo; +import com.mumfrey.worldeditcui.render.points.PointCube; +import net.minecraft.client.renderer.Tessellator; import static org.lwjgl.opengl.GL11.*; -import wecui.render.LineColor; -import wecui.render.LineInfo; -import wecui.render.points.PointCube; - /** * Draws the circles around a cylindrical region * @@ -16,7 +15,7 @@ public class RenderCylinderCircles { - protected LineColor color; + protected LineColour colour; protected double radX = 0; protected double radZ = 0; protected int minY; @@ -24,9 +23,9 @@ public class RenderCylinderCircles protected double centerX; protected double centerZ; - public RenderCylinderCircles(LineColor color, PointCube center, double radX, double radZ, int minY, int maxY) + public RenderCylinderCircles(LineColour colour, PointCube center, double radX, double radZ, int minY, int maxY) { - this.color = color; + this.colour = colour; this.radX = radX; this.radZ = radZ; this.minY = minY; @@ -38,15 +37,15 @@ public RenderCylinderCircles(LineColor color, PointCube center, double radX, dou public void render() { Tessellator tess = Tessellator.instance; - for (LineInfo tempColor : this.color.getColors()) + for (LineInfo tempColour : this.colour.getColours()) { - tempColor.prepareRender(); + tempColour.prepareRender(); double twoPi = Math.PI * 2; for (int yBlock = this.minY + 1; yBlock <= this.maxY; yBlock++) { tess.startDrawing(GL_LINE_LOOP); - tempColor.prepareColor(); + tempColour.prepareColour(); for (int i = 0; i <= 75; i++) { diff --git a/java/wecui/render/shapes/RenderCylinderGrid.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java similarity index 78% rename from java/wecui/render/shapes/RenderCylinderGrid.java rename to java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java index a2da9029..de34a0da 100644 --- a/java/wecui/render/shapes/RenderCylinderGrid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java @@ -1,13 +1,12 @@ -package wecui.render.shapes; +package com.mumfrey.worldeditcui.render.shapes; -import net.minecraft.client.renderer.Tessellator; +import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.LineInfo; +import com.mumfrey.worldeditcui.render.points.PointCube; +import net.minecraft.client.renderer.Tessellator; import static org.lwjgl.opengl.GL11.*; -import wecui.render.LineColor; -import wecui.render.LineInfo; -import wecui.render.points.PointCube; - /** * Draws the grid lines around a cylindrical region * @@ -16,7 +15,7 @@ public class RenderCylinderGrid { - protected LineColor color; + protected LineColour colour; protected double radX = 0; protected double radZ = 0; protected int minY; @@ -24,9 +23,9 @@ public class RenderCylinderGrid protected double centerX; protected double centerZ; - public RenderCylinderGrid(LineColor color, PointCube center, double radX, double radZ, int minY, int maxY) + public RenderCylinderGrid(LineColour colour, PointCube center, double radX, double radZ, int minY, int maxY) { - this.color = color; + this.colour = colour; this.radX = radX; this.radZ = radZ; this.minY = minY; @@ -38,9 +37,9 @@ public RenderCylinderGrid(LineColor color, PointCube center, double radX, double public void render() { Tessellator tess = Tessellator.instance; - for (LineInfo tempColor : this.color.getColors()) + for (LineInfo tempColour : this.colour.getColours()) { - tempColor.prepareRender(); + tempColour.prepareRender(); int tmaxY = this.maxY + 1; int tminY = this.minY; @@ -53,7 +52,7 @@ public void render() { double tempZ = this.radZ * Math.cos(Math.asin(tempX / this.radX)); tess.startDrawing(GL_LINE_LOOP); - tempColor.prepareColor(); + tempColour.prepareColour(); tess.addVertex(this.centerX + tempX, tmaxY, this.centerZ + tempZ); tess.addVertex(this.centerX + tempX, tmaxY, this.centerZ - tempZ); @@ -67,7 +66,7 @@ public void render() { double tempX = this.radX * Math.sin(Math.acos(tempZ / this.radZ)); tess.startDrawing(GL_LINE_LOOP); - tempColor.prepareColor(); + tempColour.prepareColour(); tess.addVertex(this.centerX + tempX, tmaxY, this.centerZ + tempZ); tess.addVertex(this.centerX - tempX, tmaxY, this.centerZ + tempZ); diff --git a/java/wecui/render/shapes/RenderEllipsoid.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java similarity index 80% rename from java/wecui/render/shapes/RenderEllipsoid.java rename to java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java index 10a4a470..59586a08 100644 --- a/java/wecui/render/shapes/RenderEllipsoid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java @@ -1,14 +1,13 @@ -package wecui.render.shapes; +package com.mumfrey.worldeditcui.render.shapes; -import net.minecraft.client.renderer.Tessellator; +import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.LineInfo; +import com.mumfrey.worldeditcui.render.points.PointCube; +import com.mumfrey.worldeditcui.util.Vector3; +import net.minecraft.client.renderer.Tessellator; import static org.lwjgl.opengl.GL11.*; -import wecui.render.LineColor; -import wecui.render.LineInfo; -import wecui.render.points.PointCube; -import wecui.util.Vector3; - /** * Draws an ellipsoid shape around a center point. * @@ -17,7 +16,7 @@ public class RenderEllipsoid { - protected LineColor color; + protected LineColour colour; protected PointCube center; protected Vector3 radii; protected final static double twoPi = Math.PI * 2; @@ -25,9 +24,9 @@ public class RenderEllipsoid protected double centerY; protected double centerZ; - public RenderEllipsoid(LineColor color, PointCube center, Vector3 radii) + public RenderEllipsoid(LineColour colour, PointCube center, Vector3 radii) { - this.color = color; + this.colour = colour; this.center = center; this.radii = radii; this.centerX = center.getPoint().getX() + 0.5; @@ -37,23 +36,23 @@ public RenderEllipsoid(LineColor color, PointCube center, Vector3 radii) public void render() { - for (LineInfo tempColor : this.color.getColors()) + for (LineInfo tempColour : this.colour.getColours()) { - tempColor.prepareRender(); - this.drawXZPlane(tempColor); - this.drawYZPlane(tempColor); - this.drawXYPlane(tempColor); + tempColour.prepareRender(); + this.drawXZPlane(tempColour); + this.drawYZPlane(tempColour); + this.drawXYPlane(tempColour); } } - protected void drawXZPlane(LineInfo color) + protected void drawXZPlane(LineInfo colour) { Tessellator tess = Tessellator.instance; int yRad = (int)Math.floor(this.radii.getY()); for (int yBlock = -yRad; yBlock < yRad; yBlock++) { tess.startDrawing(GL_LINE_LOOP); - color.prepareColor(); + colour.prepareColour(); for (int i = 0; i <= 40; i++) { @@ -67,7 +66,7 @@ protected void drawXZPlane(LineInfo color) } tess.startDrawing(GL_LINE_LOOP); - color.prepareColor(); + colour.prepareColour(); for (int i = 0; i <= 40; i++) { @@ -80,14 +79,14 @@ protected void drawXZPlane(LineInfo color) tess.draw(); } - protected void drawYZPlane(LineInfo color) + protected void drawYZPlane(LineInfo colour) { Tessellator tess = Tessellator.instance; int xRad = (int)Math.floor(this.radii.getX()); for (int xBlock = -xRad; xBlock < xRad; xBlock++) { tess.startDrawing(GL_LINE_LOOP); - color.prepareColor(); + colour.prepareColour(); for (int i = 0; i <= 40; i++) { @@ -101,7 +100,7 @@ protected void drawYZPlane(LineInfo color) } tess.startDrawing(GL_LINE_LOOP); - color.prepareColor(); + colour.prepareColour(); for (int i = 0; i <= 40; i++) { @@ -114,14 +113,14 @@ protected void drawYZPlane(LineInfo color) tess.draw(); } - protected void drawXYPlane(LineInfo color) + protected void drawXYPlane(LineInfo colour) { Tessellator tess = Tessellator.instance; int zRad = (int)Math.floor(this.radii.getZ()); for (int zBlock = -zRad; zBlock < zRad; zBlock++) { tess.startDrawing(GL_LINE_LOOP); - color.prepareColor(); + colour.prepareColour(); for (int i = 0; i <= 40; i++) { @@ -135,7 +134,7 @@ protected void drawXYPlane(LineInfo color) } tess.startDrawing(GL_LINE_LOOP); - color.prepareColor(); + colour.prepareColour(); for (int i = 0; i <= 40; i++) { diff --git a/java/wecui/util/ConsoleLogFormatter.java b/java/com/mumfrey/worldeditcui/util/ConsoleLogFormatter.java similarity index 97% rename from java/wecui/util/ConsoleLogFormatter.java rename to java/com/mumfrey/worldeditcui/util/ConsoleLogFormatter.java index 694b6980..34106415 100644 --- a/java/wecui/util/ConsoleLogFormatter.java +++ b/java/com/mumfrey/worldeditcui/util/ConsoleLogFormatter.java @@ -1,4 +1,4 @@ -package wecui.util; +package com.mumfrey.worldeditcui.util; import java.io.PrintWriter; import java.io.StringWriter; diff --git a/java/wecui/util/Vector2.java b/java/com/mumfrey/worldeditcui/util/Vector2.java similarity index 94% rename from java/wecui/util/Vector2.java rename to java/com/mumfrey/worldeditcui/util/Vector2.java index cc9970d8..dda531d0 100644 --- a/java/wecui/util/Vector2.java +++ b/java/com/mumfrey/worldeditcui/util/Vector2.java @@ -1,4 +1,4 @@ -package wecui.util; +package com.mumfrey.worldeditcui.util; /** * A 2-dimensional vector represented by float-precision x,y coordinates diff --git a/java/wecui/util/Vector2m.java b/java/com/mumfrey/worldeditcui/util/Vector2m.java similarity index 91% rename from java/wecui/util/Vector2m.java rename to java/com/mumfrey/worldeditcui/util/Vector2m.java index 1afc561c..c0b21987 100644 --- a/java/wecui/util/Vector2m.java +++ b/java/com/mumfrey/worldeditcui/util/Vector2m.java @@ -1,4 +1,4 @@ -package wecui.util; +package com.mumfrey.worldeditcui.util; /** * A version of Vector2 that can be modified. diff --git a/java/wecui/util/Vector3.java b/java/com/mumfrey/worldeditcui/util/Vector3.java similarity index 94% rename from java/wecui/util/Vector3.java rename to java/com/mumfrey/worldeditcui/util/Vector3.java index 92daf61f..2fdf0122 100644 --- a/java/wecui/util/Vector3.java +++ b/java/com/mumfrey/worldeditcui/util/Vector3.java @@ -1,4 +1,4 @@ -package wecui.util; +package com.mumfrey.worldeditcui.util; /** * Represents a 3d vector. diff --git a/java/wecui/util/Vector3m.java b/java/com/mumfrey/worldeditcui/util/Vector3m.java similarity index 92% rename from java/wecui/util/Vector3m.java rename to java/com/mumfrey/worldeditcui/util/Vector3m.java index 46481b44..7bd5b080 100644 --- a/java/wecui/util/Vector3m.java +++ b/java/com/mumfrey/worldeditcui/util/Vector3m.java @@ -1,4 +1,4 @@ -package wecui.util; +package com.mumfrey.worldeditcui.util; /** * A version of Vector3 that can be modified. diff --git a/java/wecui/config/CUIConfiguration.java b/java/wecui/config/CUIConfiguration.java deleted file mode 100644 index 605baacc..00000000 --- a/java/wecui/config/CUIConfiguration.java +++ /dev/null @@ -1,149 +0,0 @@ -package wecui.config; - -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; - -import wecui.InitializationFactory; -import wecui.render.LineColor; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.mumfrey.liteloader.core.LiteLoader; - -/** - * Stores and reads WorldEditCUI settings - * - * @author yetanotherx - * - */ -public class CUIConfiguration implements InitializationFactory -{ - private static Gson gson = new GsonBuilder().setPrettyPrinting().create(); - - private boolean debugMode = false; - private boolean ignoreUpdates = false; - - private Colour cuboidGridColor = new Colour("#CC3333CC"); - private Colour cuboidEdgeColor = new Colour("#CC4C4CCC"); - private Colour cuboidFirstPointColor = new Colour("#33CC33CC"); - private Colour cuboidSecondPointColor = new Colour("#3333CCCC"); - private Colour polyGridColor = new Colour("#CC3333CC"); - private Colour polyEdgeColor = new Colour("#CC4C4CCC"); - private Colour polyPointColor = new Colour("#33CCCCCC"); - private Colour ellipsoidGridColor = new Colour("#CC4C4CCC"); - private Colour ellipsoidPointColor = new Colour("#CCCC33CC"); - private Colour cylinderGridColor = new Colour("#CC3333CC"); - private Colour cylinderEdgeColor = new Colour("#CC4C4CCC"); - private Colour cylinderPointColor = new Colour("#CC33CCCC"); - - /** - * Copies the default config file to the proper directory if it does not - * exist. It then reads the file and sets each variable to the proper value. - */ - @Override - public void initialize() - { - this.cuboidGridColor = Colour.setDefault(this.cuboidGridColor, "#CC3333CC"); - this.cuboidEdgeColor = Colour.setDefault(this.cuboidEdgeColor, "#CC4C4CCC"); - this.cuboidFirstPointColor = Colour.setDefault(this.cuboidFirstPointColor, "#33CC33CC"); - this.cuboidSecondPointColor = Colour.setDefault(this.cuboidSecondPointColor, "#3333CCCC"); - this.polyGridColor = Colour.setDefault(this.polyGridColor, "#CC3333CC"); - this.polyEdgeColor = Colour.setDefault(this.polyEdgeColor, "#CC4C4CCC"); - this.polyPointColor = Colour.setDefault(this.polyPointColor, "#33CCCCCC"); - this.ellipsoidGridColor = Colour.setDefault(this.ellipsoidGridColor, "#CC4C4CCC"); - this.ellipsoidPointColor = Colour.setDefault(this.ellipsoidPointColor, "#CCCC33CC"); - this.cylinderGridColor = Colour.setDefault(this.cylinderGridColor, "#CC3333CC"); - this.cylinderEdgeColor = Colour.setDefault(this.cylinderEdgeColor, "#CC4C4CCC"); - this.cylinderPointColor = Colour.setDefault(this.cylinderPointColor, "#CC33CCCC"); - - LineColor.CUBOIDBOX.setColour(this.cuboidEdgeColor); - LineColor.CUBOIDGRID.setColour(this.cuboidGridColor); - LineColor.CUBOIDPOINT1.setColour(this.cuboidFirstPointColor); - LineColor.CUBOIDPOINT2.setColour(this.cuboidSecondPointColor); - LineColor.POLYGRID.setColour(this.polyGridColor); - LineColor.POLYBOX.setColour(this.polyEdgeColor); - LineColor.POLYPOINT.setColour(this.polyPointColor); - LineColor.ELLIPSOIDGRID.setColour(this.ellipsoidGridColor); - LineColor.ELLIPSOIDCENTER.setColour(this.ellipsoidPointColor); - LineColor.CYLINDERGRID.setColour(this.cylinderGridColor); - LineColor.CYLINDERBOX.setColour(this.cylinderEdgeColor); - LineColor.CYLINDERCENTER.setColour(this.cylinderPointColor); - - this.save(); - } - - public boolean isDebugMode() - { - return this.debugMode; - } - - public boolean ignoreUpdates() - { - return this.ignoreUpdates; - } - - public static CUIConfiguration create() - { - File jsonFile = new File(LiteLoader.getCommonConfigFolder(), "worldeditcui.config.json"); - - if (jsonFile.exists()) - { - FileReader fileReader = null; - - try - { - fileReader = new FileReader(jsonFile); - CUIConfiguration config = CUIConfiguration.gson.fromJson(fileReader, CUIConfiguration.class); - return config; - } - catch (IOException ex) - { - ex.printStackTrace(); - } - finally - { - try - { - if (fileReader != null) - fileReader.close(); - } - catch (IOException ex) - { - } - } - } - - return new CUIConfiguration(); - } - - public void save() - { - File jsonFile = new File(LiteLoader.getCommonConfigFolder(), "worldeditcui.config.json"); - - FileWriter fileWriter = null; - - try - { - fileWriter = new FileWriter(jsonFile); - CUIConfiguration.gson.toJson(this, fileWriter); - } - catch (IOException ex) - { - ex.printStackTrace(); - } - finally - { - try - { - if (fileWriter != null) - fileWriter.close(); - } - catch (IOException ex) - { - ex.printStackTrace(); - } - } - } -} diff --git a/java/wecui/event/cui/CUIBaseEvent.java b/java/wecui/event/cui/CUIBaseEvent.java deleted file mode 100644 index 8d391f5d..00000000 --- a/java/wecui/event/cui/CUIBaseEvent.java +++ /dev/null @@ -1,109 +0,0 @@ -package wecui.event.cui; - -import wecui.WorldEditCUI; - -/** - * Base event for CUI events, handles parameter validation and running the logic - * - * @author yetanotherx - * - */ -public abstract class CUIBaseEvent -{ - - protected WorldEditCUI controller; - protected String[] args; - - public CUIBaseEvent(WorldEditCUI controller, String[] args) - { - this.controller = controller; - this.args = args; - } - - public abstract String run(); - - public abstract CUIEventType getEventType(); - - public String getEventName() - { - //Hack for String.uppercaseFirstLetter, which doesn't exist. - String name = this.getEventType().name().toLowerCase(); - name = name.substring(0, 1).toUpperCase() + name.substring(1); - return name; - } - - /** - * Checks if the parameters match the required length. - * @return - */ - public boolean isValid() - { - int max = this.getEventType().getMaxParameters(); - int min = this.getEventType().getMinParameters(); - - if (max == min) - { - if (this.args.length != max) - { - return false; - } - } - else - { - if (this.args.length > max || this.args.length < min) - { - return false; - } - } - - return true; - - } - - public final String doRun() - { - if (this.controller == null || this.args == null) - { - throw new RuntimeException("Controller and parameters must both be set."); - } - - if (!this.isValid()) - { - String message = "Invalid number of parameters. " + this.getEventName() + " event requires "; - if (this.getEventType().getMaxParameters() == this.getEventType().getMinParameters()) - { - message += this.getEventType().getMaxParameters() + " parameters. "; - } - else - { - message += "between " + this.getEventType().getMinParameters() + " and " + this.getEventType().getMaxParameters() + " parameters. "; - } - - message += "Received " + this.args.length + " parameters instead. "; - for (String arg : this.args) - { - message += arg + " "; - } - - throw new RuntimeException(message); - } - - return this.run(); - - } - - public int getInt(int index) - { - return (int)Float.parseFloat(this.args[index]); - } - - public double getDouble(int index) - { - return Double.parseDouble(this.args[index]); - } - - public String getString(int index) - { - return this.args[index]; - } -} diff --git a/java/wecui/event/cui/CUIEventType.java b/java/wecui/event/cui/CUIEventType.java deleted file mode 100644 index 1e931c32..00000000 --- a/java/wecui/event/cui/CUIEventType.java +++ /dev/null @@ -1,72 +0,0 @@ -package wecui.event.cui; - -/** - * Event type enum for CUI events. Also stores class, arguments, and key for each value. - * - * @author yetanotherx - * - */ -public enum CUIEventType -{ - SELECTION(CUISelectionEvent.class, "s", 1), - POINT(CUIPointEvent.class, "p", 5, 6), - POINT2D(CUIPoint2DEvent.class, "p2", 4, 5), - ELLIPSOID(CUIEllipsoidEvent.class, "e", 4), - CYLINDER(CUICylinderEvent.class, "cyl", 5), - MINMAX(CUIMinMaxEvent.class, "mm", 2), - UPDATE(CUIUpdateEvent.class, "u", 1), - POLYGON(CUIPolygonEvent.class, "poly", 3, 99); - - private final Class eventClass; - private final String key; - private final int min; - private final int max; - - private CUIEventType(Class eventClass, String key, int min, int max) - { - this.eventClass = eventClass; - this.key = key; - this.min = min; - this.max = max; - } - - private CUIEventType(Class eventClass, String key, int paramCount) - { - this.eventClass = eventClass; - this.key = key; - this.min = paramCount; - this.max = paramCount; - } - - public Class getEventClass() - { - return this.eventClass; - } - - public String getKey() - { - return this.key; - } - - public int getMaxParameters() - { - return this.max; - } - - public int getMinParameters() - { - return this.min; - } - - public static CUIEventType getTypeFromKey(String key) - { - for (CUIEventType value : CUIEventType.values()) - { - if (value.getKey().equals(key)) - { - return value; - } - } - return null; - } -} diff --git a/java/wecui/event/cui/CUIPointEvent.java b/java/wecui/event/cui/CUIPointEvent.java deleted file mode 100644 index 6b83065e..00000000 --- a/java/wecui/event/cui/CUIPointEvent.java +++ /dev/null @@ -1,58 +0,0 @@ -package wecui.event.cui; - -import wecui.WorldEditCUI; - -/** - * Called when point event is received - * - * @author lahwran - * @author yetanotherx - */ -public class CUIPointEvent extends CUIBaseEvent -{ - - public CUIPointEvent(WorldEditCUI controller, String[] args) - { - super(controller, args); - } - - @Override - public CUIEventType getEventType() - { - return CUIEventType.POINT; - } - - @Override - public String run() - { - int id = this.getInt(0); - double x = this.getDouble(1); - double y = this.getDouble(2); - double z = this.getDouble(3); - - this.controller.getSelection().setCuboidPoint(id, x, y, z); - this.setLocalPoint(id, x, y, z); - this.controller.getDebugger().debug("Setting point #" + id); - - return null; - } - - protected void setLocalPoint(int id, double x, double y, double z) - { - /*if (controller.getLocalPlugin().isEnabled()) { - - WorldEdit plugin = controller.getLocalPlugin().getPlugin(); - CUIWorld world = controller.getLocalPlugin().getWorld(); - - WorldVector clicked = new WorldVector(world, x, y, z); - LocalSession session = plugin.getSession("player"); - RegionSelector selector = session.getRegionSelector(world); - - if (id == 0) { - selector.selectPrimary(clicked); - } else { - selector.selectSecondary(clicked); - } - }*/ - } -} diff --git a/java/wecui/event/cui/CUISelectionEvent.java b/java/wecui/event/cui/CUISelectionEvent.java deleted file mode 100644 index f7729bcb..00000000 --- a/java/wecui/event/cui/CUISelectionEvent.java +++ /dev/null @@ -1,67 +0,0 @@ -package wecui.event.cui; - -import wecui.WorldEditCUI; -import wecui.render.region.BaseRegion; -import wecui.render.region.CuboidRegion; -import wecui.render.region.CylinderRegion; -import wecui.render.region.EllipsoidRegion; -import wecui.render.region.PolygonRegion; -import wecui.render.region.PolyhedronRegion; - -/** - * Called when selection event is received - * - * @author lahwran - * @author yetanotherx - */ -public class CUISelectionEvent extends CUIBaseEvent -{ - - public CUISelectionEvent(WorldEditCUI controller, String[] args) - { - super(controller, args); - } - - @Override - public CUIEventType getEventType() - { - return CUIEventType.SELECTION; - } - - @Override - public String run() - { - - BaseRegion newRegion = null; - - if (this.getString(0).equals("cuboid")) - { - newRegion = new CuboidRegion(this.controller); - } - else if (this.getString(0).equals("polygon2d")) - { - newRegion = new PolygonRegion(this.controller); - } - else if (this.getString(0).equals("ellipsoid")) - { - newRegion = new EllipsoidRegion(this.controller); - } - else if (this.getString(0).equals("cylinder")) - { - newRegion = new CylinderRegion(this.controller); - } - else if (this.getString(0).equals("polyhedron")) - { - newRegion = new PolyhedronRegion(this.controller); - } - else - { - return "Invalid selection type. Must be cuboid|polygon2d|ellipsoid|cylinder|polyhedron."; - } - - this.controller.setSelection(newRegion); - this.controller.getDebugger().debug("Received selection event, initalizing new region instance."); - - return null; - } -} diff --git a/java/wecui/event/cui/CUIUpdateEvent.java b/java/wecui/event/cui/CUIUpdateEvent.java deleted file mode 100644 index d432ff04..00000000 --- a/java/wecui/event/cui/CUIUpdateEvent.java +++ /dev/null @@ -1,30 +0,0 @@ -package wecui.event.cui; - -import wecui.WorldEditCUI; - -/** - * Called when update event is received - * - * @author lahwran - * @author yetanotherx - */ -public class CUIUpdateEvent extends CUIBaseEvent -{ - - public CUIUpdateEvent(WorldEditCUI controller, String[] args) - { - super(controller, args); - } - - @Override - public CUIEventType getEventType() - { - return CUIEventType.UPDATE; - } - - @Override - public String run() - { - return null; - } -} diff --git a/java/wecui/event/listeners/ChannelListener.java b/java/wecui/event/listeners/ChannelListener.java deleted file mode 100644 index 27785eca..00000000 --- a/java/wecui/event/listeners/ChannelListener.java +++ /dev/null @@ -1,66 +0,0 @@ -package wecui.event.listeners; - -import wecui.WorldEditCUI; -import wecui.event.CUIEvent; -import wecui.event.cui.CUIBaseEvent; -import wecui.event.cui.CUIEventType; -import wecui.exception.ReflectException; -import wecui.vendor.org.joor.Reflect; - -/** - * Listener class for incoming plugin channel messages - * - * @author lahwran - * @author yetanotherx - * - */ -public class ChannelListener -{ - private WorldEditCUI controller; - - public ChannelListener(WorldEditCUI controller) - { - this.controller = controller; - } - - public void onMessage(String message) - { - String[] split = message.split("[|]"); - String type = split[0]; - String args = message.substring(type.length() + 1); - - this.controller.getDebugger().debug("Received CUI event from server: " + message); - - try - { - CUIEvent cuiEvent = new CUIEvent(this.controller, type, args.split("[|]")); - this.processCUIEvent(cuiEvent); - } - catch (Exception ex) - { - } - } - - public void processCUIEvent(CUIEvent event) - { - // Get a CUIEventType enum value from the first section of the CUI message - CUIEventType eventType = CUIEventType.getTypeFromKey(event.getType()); - if (eventType == null || eventType.getEventClass() == null) - { - return; - } - - try - { - CUIBaseEvent newEvent = Reflect.on(eventType.getEventClass()).create(this.controller, event.getParams()).get(); - - //Run the event. If doRun returns null, the event was successful. - //If it returns a string, it uses that as the error message. - newEvent.doRun(); - } - catch (ReflectException e) - { - return; - } - } -} diff --git a/java/wecui/exception/ReflectException.java b/java/wecui/exception/ReflectException.java deleted file mode 100644 index eb160709..00000000 --- a/java/wecui/exception/ReflectException.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Copyright (c) 2009-2011, Lukas Eder, lukas.eder@gmail.com - * All rights reserved. - * - * This software is licensed to you under the Apache License, Version 2.0 - * (the "License"); You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * . Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * . Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * . Neither the name "jOOR" nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package wecui.exception; - -import java.lang.reflect.InvocationTargetException; - -/** - * A unchecked wrapper for any of Java's checked reflection exceptions: - *

- * These exceptions are - *

    - *
  • {@link ClassNotFoundException}
  • - *
  • {@link IllegalAccessException}
  • - *
  • {@link IllegalArgumentException}
  • - *
  • {@link InstantiationException}
  • - *
  • {@link InvocationTargetException}
  • - *
  • {@link NoSuchMethodException}
  • - *
  • {@link NoSuchFieldException}
  • - *
  • {@link SecurityException}
  • - *
- * - * @author Lukas Eder - */ -public class ReflectException extends RuntimeException -{ - - /** - * Generated UID - */ - private static final long serialVersionUID = -6213149635297151443L; - - public ReflectException(String message) - { - super(message); - } - - public ReflectException(String message, Throwable cause) - { - super(message, cause); - } - - public ReflectException() - { - super(); - } - - public ReflectException(Throwable cause) - { - super(cause); - } -} diff --git a/java/wecui/render/region/RegionType.java b/java/wecui/render/region/RegionType.java deleted file mode 100644 index 1e159854..00000000 --- a/java/wecui/render/region/RegionType.java +++ /dev/null @@ -1,15 +0,0 @@ -package wecui.render.region; - -/** - * The different types of regions. - * - * @author yetanotherx - */ -public enum RegionType -{ - CUBOID, - POLYGON, - ELLIPSOID, - CYLINDER, - POLYHEDRON -} diff --git a/java/wecui/util/Utilities.java b/java/wecui/util/Utilities.java deleted file mode 100644 index 844c275c..00000000 --- a/java/wecui/util/Utilities.java +++ /dev/null @@ -1,153 +0,0 @@ -package wecui.util; - -import java.util.Map; - -/** - * Common utilities which are useful to always have. - * - * @author yetanotherx - * @author Apache Commons - */ -public class Utilities -{ - - // Joining - //----------------------------------------------------------------------- - /** - *

Joins the elements of the provided array into a single String - * containing the provided list of elements.

- * - *

No separator is added to the joined String. - * Null objects or empty strings within the array are represented by - * empty strings.

- * - *
-	 * StringUtils.join(null)            = null
-	 * StringUtils.join([])              = ""
-	 * StringUtils.join([null])          = ""
-	 * StringUtils.join(["a", "b", "c"]) = "abc"
-	 * StringUtils.join([null, "", "a"]) = "a"
-	 * 
- * - * @param the specific type of values to join together - * @param elements the values to join together, may be null - * @return the joined String, {@code null} if null array input - * @since 2.0 - * @since 3.0 Changed signature to use varargs - */ - public static String join(T... elements) - { - return join(elements, null); - } - - /** - *

Joins the elements of the provided array into a single String - * containing the provided list of elements.

- * - *

No delimiter is added before or after the list. - * A {@code null} separator is the same as an empty String (""). - * Null objects or empty strings within the array are represented by - * empty strings.

- * - *
-	 * StringUtils.join(null, *)                = null
-	 * StringUtils.join([], *)                  = ""
-	 * StringUtils.join([null], *)              = ""
-	 * StringUtils.join(["a", "b", "c"], "--")  = "a--b--c"
-	 * StringUtils.join(["a", "b", "c"], null)  = "abc"
-	 * StringUtils.join(["a", "b", "c"], "")    = "abc"
-	 * StringUtils.join([null, "", "a"], ',')   = ",,a"
-	 * 
- * - * @param array the array of values to join together, may be null - * @param separator the separator character to use, null treated as "" - * @return the joined String, {@code null} if null array input - */ - public static String join(Object[] array, String separator) - { - if (array == null) - { - return null; - } - return join(array, separator, 0, array.length); - } - - /** - *

Joins the elements of the provided array into a single String - * containing the provided list of elements.

- * - *

No delimiter is added before or after the list. - * A {@code null} separator is the same as an empty String (""). - * Null objects or empty strings within the array are represented by - * empty strings.

- * - *
-	 * StringUtils.join(null, *)                = null
-	 * StringUtils.join([], *)                  = ""
-	 * StringUtils.join([null], *)              = ""
-	 * StringUtils.join(["a", "b", "c"], "--")  = "a--b--c"
-	 * StringUtils.join(["a", "b", "c"], null)  = "abc"
-	 * StringUtils.join(["a", "b", "c"], "")    = "abc"
-	 * StringUtils.join([null, "", "a"], ',')   = ",,a"
-	 * 
- * - * @param array the array of values to join together, may be null - * @param separator the separator character to use, null treated as "" - * @param startIndex the first index to start joining from. It is - * an error to pass in an end index past the end of the array - * @param endIndex the index to stop joining from (exclusive). It is - * an error to pass in an end index past the end of the array - * @return the joined String, {@code null} if null array input - */ - public static String join(Object[] array, String separator, int startIndex, int endIndex) - { - if (array == null) - { - return null; - } - if (separator == null) - { - separator = ""; - } - - // endIndex - startIndex > 0: Len = NofStrings *(len(firstString) + len(separator)) - // (Assuming that all Strings are roughly equally long) - int noOfItems = endIndex - startIndex; - if (noOfItems <= 0) - { - return ""; - } - - StringBuilder buf = new StringBuilder(noOfItems * 16); - - for (int i = startIndex; i < endIndex; i++) - { - if (i > startIndex) - { - buf.append(separator); - } - if (array[i] != null) - { - buf.append(array[i]); - } - } - return buf.toString(); - } - - /** - * Creates a pretty representation of a Map - * @param map - * @return - */ - public static String debugMap(Map map) - { - StringBuilder build = new StringBuilder(); - - for (Object key : map.keySet()) - { - build.append(key.toString()).append(" - ").append(map.get(key).toString()).append("\n"); - } - - return build.toString(); - } -} diff --git a/java/wecui/vendor/org/joor/Reflect.java b/java/wecui/vendor/org/joor/Reflect.java deleted file mode 100644 index e10fac9e..00000000 --- a/java/wecui/vendor/org/joor/Reflect.java +++ /dev/null @@ -1,617 +0,0 @@ -/** - * Copyright (c) 2009-2011, Lukas Eder, lukas.eder@gmail.com - * All rights reserved. - * - * This software is licensed to you under the Apache License, Version 2.0 - * (the "License"); You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * . Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * . Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * . Neither the name "jOOR" nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package wecui.vendor.org.joor; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.LinkedHashMap; -import java.util.Map; - -import wecui.exception.ReflectException; - -/** - * A wrapper for an {@link Object} or {@link Class} upon which reflective calls - * can be made. - *

- * An example of using Reflect is

- * // Static import all reflection methods to decrease verbosity
- * import static org.joor.Reflect.*;
- *
- * // Wrap an Object / Class / class name with the on() method:
- * on("java.lang.String")
- * // Invoke constructors using the create() method:
- * .create("Hello World")
- * // Invoke methods using the call() method:
- * .call("toString")
- * // Retrieve the wrapped object
- *
- * @author Lukas Eder
- */
-public class Reflect
-{
-	
-	// ---------------------------------------------------------------------
-	// Static API used as entrance points to the fluent API
-	// ---------------------------------------------------------------------
-	/**
-	 * Wrap a class name.
-	 * 

- * This is the same as calling on(Class.forName(name)) - * - * @param name A fully qualified class name - * @return A wrapped class object, to be used for further reflection. - * @throws ReflectException If any reflection exception occurred. - * @see #on(Class) - */ - public static Reflect on(String name) throws ReflectException - { - return on(forName(name)); - } - - /** - * Wrap a class. - *

- * Use this when you want to access static fields and methods on a - * {@link Class} object, or as a basis for constructing objects of that - * class using {@link #create(Object...)} - * - * @param clazz The class to be wrapped - * @return A wrapped class object, to be used for further reflection. - */ - public static Reflect on(Class clazz) - { - return new Reflect(clazz); - } - - /** - * Wrap an object. - *

- * Use this when you want to access instance fields and methods on any - * {@link Object} - * - * @param object The object to be wrapped - * @return A wrapped object, to be used for further reflection. - */ - public static Reflect on(Object object) - { - return new Reflect(object); - } - - // --------------------------------------------------------------------- - // Members - // --------------------------------------------------------------------- - /** - * The wrapped object - */ - private final Object object; - /** - * A flag indicating whether the wrapped object is a {@link Class} (for - * accessing static fields and methods), or any other type of {@link Object} - * (for accessing instance fields and methods). - */ - private final boolean isClass; - - // --------------------------------------------------------------------- - // Constructors - // --------------------------------------------------------------------- - private Reflect(Class type) - { - this.object = type; - this.isClass = true; - } - - private Reflect(Object object) - { - this.object = object; - this.isClass = false; - } - - // --------------------------------------------------------------------- - // Fluent Configuration API - // --------------------------------------------------------------------- - // TO_DO: Allow for accessing non-public members, methods, etc - // --------------------------------------------------------------------- - // Fluent Reflection API - // --------------------------------------------------------------------- - /** - * Get the wrapped object - * - * @param A convenience generic parameter for automatic unsafe casting - */ - @SuppressWarnings("unchecked") - public T get() - { - return (T)this.object; - } - - /** - * Set a field value. - *

- * This is roughly equivalent to {@link Field#set(Object, Object)}. If the - * wrapped object is a {@link Class}, then this will set a value to a static - * member field. If the wrapped object is any other {@link Object}, then - * this will set a value to an instance member field. - * - * @param name The field name - * @param value The new field value - * @return The same wrapped object, to be used for further reflection. - * @throws ReflectException If any reflection exception occurred. - */ - public Reflect set(String name, Object value) throws ReflectException - { - try - { - Field field = this.type().getField(name); - if (!field.isAccessible()) - { - field.setAccessible(true); - } - field.set(this.object, unwrap(value)); - return this; - } - catch (Exception e) - { - throw new ReflectException(e); - } - } - - /** - * Get a field value. - *

- * This is roughly equivalent to {@link Field#get(Object)}. If the wrapped - * object is a {@link Class}, then this will get a value from a static - * member field. If the wrapped object is any other {@link Object}, then - * this will get a value from an instance member field. - *

- * If you want to "navigate" to a wrapped version of the field, use - * {@link #field(String)} instead. - * - * @param name The field name - * @return The field value - * @throws ReflectException If any reflection exception occurred. - * @see #field(String) - */ - public Object get(String name) throws ReflectException - { - return this.field(name).get(); - } - - /** - * Get a wrapped field. - *

- * This is roughly equivalent to {@link Field#get(Object)}. If the wrapped - * object is a {@link Class}, then this will wrap a static member field. If - * the wrapped object is any other {@link Object}, then this wrap an - * instance member field. - * - * @param name The field name - * @return The wrapped field - * @throws ReflectException If any reflection exception occurred. - */ - public Reflect field(String name) throws ReflectException - { - try - { - Field field = this.type().getField(name); - if (!field.isAccessible()) - { - field.setAccessible(true); - } - return on(field.get(this.object)); - } - catch (Exception e) - { - throw new ReflectException(e); - } - } - - /** - * Get a Map containing field names and wrapped values for the fields' - * values. - *

- * If the wrapped object is a {@link Class}, then this will return static - * fields. If the wrapped object is any other {@link Object}, then this will - * return instance fields. - *

- * These two calls are equivalent

-	 * on(object).field("myField");
-	 * on(object).fields().get("myField");
-	 * 
- * - * @return A map containing field names and wrapped values. - */ - public Map fields() - { - Map result = new LinkedHashMap(); - - for (Field field : this.type().getFields()) - { - if (!this.isClass ^ Modifier.isStatic(field.getModifiers())) - { - String name = field.getName(); - result.put(name, this.field(name)); - } - } - - return result; - } - - /** - * Call a method by its name. - *

- * This is a convenience method for calling - * call(name, new Object[0]) - * - * @param name The method name - * @return The wrapped method result or the same wrapped object if the - * method returns void, to be used for further - * reflection. - * @throws ReflectException If any reflection exception occurred. - * @see #call(String, Object...) - */ - public Reflect call(String name) throws ReflectException - { - return this.call(name, new Object[0]); - } - - /** - * Call a method by its name. - *

- * This is roughly equivalent to {@link Method#invoke(Object, Object...)}. - * If the wrapped object is a {@link Class}, then this will invoke a static - * method. If the wrapped object is any other {@link Object}, then this will - * invoke an instance method. - *

- * Just like {@link Method#invoke(Object, Object...)}, this will try to wrap - * primitive types or unwrap primitive type wrappers if applicable. If - * several methods are applicable, by that rule, the first one encountered - * is called. i.e. when calling

-	 * on(...).call("method", 1, 1);
-	 * 
The first of the following methods will be called: - *
-	 * public void method(int param1, Integer param2);
-	 * public void method(Integer param1, int param2);
-	 * public void method(Number param1, Number param2);
-	 * public void method(Number param1, Object param2);
-	 * public void method(int param1, Object param2);
-	 * 
- * - * @param name The method name - * @param args The method arguments - * @return The wrapped method result or the same wrapped object if the - * method returns void, to be used for further - * reflection. - * @throws ReflectException If any reflection exception occurred. - */ - public Reflect call(String name, Object... args) throws ReflectException - { - Class[] types = types(args); - - // Try invoking the "canonical" method, i.e. the one with exact - // matching argument types - try - { - Method method = this.type().getMethod(name, types); - return on(method, this.object, args); - } // If there is no exact match, try to find one that has a "similar" - // signature if primitive argument types are converted to their wrappers - catch (NoSuchMethodException e) - { - for (Method method : this.type().getMethods()) - { - if (method.getName().equals(name) && this.match(method.getParameterTypes(), types)) - { - return on(method, this.object, args); - } - } - - throw new ReflectException(e); - } - } - - /** - * Call a constructor. - *

- * This is a convenience method for calling - * create(new Object[0]) - * - * @return The wrapped new object, to be used for further reflection. - * @throws ReflectException If any reflection exception occurred. - * @see #create(Object...) - */ - public Reflect create() throws ReflectException - { - return this.create(new Object[0]); - } - - /** - * Call a constructor. - *

- * This is roughly equivalent to {@link Constructor#newInstance(Object...)}. - * If the wrapped object is a {@link Class}, then this will create a new - * object of that class. If the wrapped object is any other {@link Object}, - * then this will create a new object of the same type. - *

- * Just like {@link Constructor#newInstance(Object...)}, this will try to - * wrap primitive types or unwrap primitive type wrappers if applicable. If - * several constructors are applicable, by that rule, the first one - * encountered is called. i.e. when calling

-	 * on(C.class).create(1, 1);
-	 * 
The first of the following constructors will be applied: - *
-	 * public C(int param1, Integer param2);
-	 * public C(Integer param1, int param2);
-	 * public C(Number param1, Number param2);
-	 * public C(Number param1, Object param2);
-	 * public C(int param1, Object param2);
-	 * 
- * - * @param args The constructor arguments - * @return The wrapped new object, to be used for further reflection. - * @throws ReflectException If any reflection exception occurred. - */ - public Reflect create(Object... args) throws ReflectException - { - Class[] types = types(args); - - // Try invoking the "canonical" constructor, i.e. the one with exact - // matching argument types - try - { - Constructor constructor = this.type().getConstructor(types); - return on(constructor, args); - } // If there is no exact match, try to find one that has a "similar" - // signature if primitive argument types are converted to their wrappers - catch (NoSuchMethodException e) - { - for (Constructor constructor : this.type().getConstructors()) - { - if (this.match(constructor.getParameterTypes(), types)) - { - return on(constructor, args); - } - } - - throw new ReflectException(e); - } - } - - // --------------------------------------------------------------------- - // Object API - // --------------------------------------------------------------------- - /** - * Check whether two arrays of types match, converting primitive types to - * their corresponding wrappers. - */ - private boolean match(Class[] declaredTypes, Class[] actualTypes) - { - if (declaredTypes.length == actualTypes.length) - { - for (int i = 0; i < actualTypes.length; i++) - { - if (!wrapper(declaredTypes[i]).isAssignableFrom(wrapper(actualTypes[i]))) - { - return false; - } - } - - return true; - } - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() - { - return this.object.hashCode(); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) - { - if (obj instanceof Reflect) - { - return this.object.equals(((Reflect)obj).get()); - } - - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() - { - return this.object.toString(); - } - - // --------------------------------------------------------------------- - // Utility methods - // --------------------------------------------------------------------- - /** - * Wrap an object created from a constructor - */ - private static Reflect on(Constructor constructor, Object... args) throws ReflectException - { - try - { - return on(constructor.newInstance(args)); - } - catch (Exception e) - { - throw new ReflectException(e); - } - } - - /** - * Wrap an object returned from a method - */ - private static Reflect on(Method method, Object object, Object... args) throws ReflectException - { - try - { - if (method.getReturnType() == void.class) - { - method.invoke(object, args); - return on(object); - } - return on(method.invoke(object, args)); - } - catch (Exception e) - { - throw new ReflectException(e); - } - } - - /** - * Unwrap an object - */ - private static Object unwrap(Object object) - { - if (object instanceof Reflect) - { - return ((Reflect)object).get(); - } - - return object; - } - - /** - * Get an array of types for an array of objects - * - * @see Object#getClass() - */ - private static Class[] types(Object... values) - { - if (values == null) - { - return new Class[0]; - } - - Class[] result = new Class[values.length]; - - for (int i = 0; i < values.length; i++) - { - result[i] = values[i].getClass(); - } - - return result; - } - - /** - * Load a class - * - * @see Class#forName(String) - */ - private static Class forName(String name) throws ReflectException - { - try - { - return Class.forName(name); - } - catch (Exception e) - { - throw new ReflectException(e); - } - } - - /** - * Get the type of the wrapped object. - * - * @see Object#getClass() - */ - private Class type() - { - if (this.isClass) - { - return (Class)this.object; - } - return this.object.getClass(); - } - - /** - * Get a wrapper type for a primitive type, or the argument type itself, if - * it is not a primitive type. - */ - private static Class wrapper(Class type) - { - if (boolean.class == type) - { - return Boolean.class; - } - else if (int.class == type) - { - return Integer.class; - } - else if (long.class == type) - { - return Long.class; - } - else if (short.class == type) - { - return Short.class; - } - else if (byte.class == type) - { - return Byte.class; - } - else if (double.class == type) - { - return Double.class; - } - else if (float.class == type) - { - return Float.class; - } - else if (char.class == type) - { - return Character.class; - } - else - { - return type; - } - } -} From 5169c2a77c075b585cca2d768cebd82d3d4e6a61 Mon Sep 17 00:00:00 2001 From: ReneZeidler Date: Sat, 1 Feb 2014 06:47:26 -0800 Subject: [PATCH 11/51] Fix for Bungee servers and when switching worlds --- .../mumfrey/worldeditcui/LiteModWorldEditCUI.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java index 4b249390..ae8b905d 100644 --- a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java @@ -36,7 +36,6 @@ public class LiteModWorldEditCUI implements InitCompleteListener, PluginChannelL private WorldEditCUI controller; private WorldClient lastWorld; private EntityPlayerSP lastPlayer; - private boolean gameStarted = false; private KeyBinding keyBindToggleUI = new KeyBinding("wecui.keys.toggle", Keyboard.KEY_NONE, "wecui.keys.category"); private KeyBinding keyBindClearSel = new KeyBinding("wecui.keys.clear", Keyboard.KEY_NONE, "wecui.keys.category"); @@ -75,6 +74,7 @@ public void onInitCompleted(Minecraft minecraft, LiteLoader loader) public void onJoinGame(INetHandler netHandler, S01PacketJoinGame loginPacket) { this.visible = true; + this.controller.getDebugger().debug("Joined game, sending initial handshake"); this.helo(); } @@ -128,13 +128,10 @@ public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clo this.lastWorld = mc.theWorld; this.lastPlayer = mc.thePlayer; - if (!this.gameStarted) - { - this.gameStarted = true; - - this.controller.setSelection(new CuboidRegion(this.controller)); - this.helo(); - } + this.controller.getDebugger().debug("World change detected, sending new handshake"); + this.controller.setSelection(new CuboidRegion(this.controller)); + this.helo(); + mc.thePlayer.sendChatMessage("/we cui"); //Tricks WE to send the current selection } } } From 75bb2598a33e29c6974486bf6f921ca490d0d2d4 Mon Sep 17 00:00:00 2001 From: ReneZeidler Date: Sat, 1 Feb 2014 06:51:16 -0800 Subject: [PATCH 12/51] Make sure that there is a player --- java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java index ae8b905d..6387a81d 100644 --- a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java @@ -131,7 +131,7 @@ public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clo this.controller.getDebugger().debug("World change detected, sending new handshake"); this.controller.setSelection(new CuboidRegion(this.controller)); this.helo(); - mc.thePlayer.sendChatMessage("/we cui"); //Tricks WE to send the current selection + if (mc.thePlayer != null) mc.thePlayer.sendChatMessage("/we cui"); //Tricks WE to send the current selection } } } From c53c6eaef37ffdc69fe700be75db96b2be15668b Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Sun, 6 Jul 2014 01:17:31 +0100 Subject: [PATCH 13/51] Rage update to 1.7.10 --- .classpath | 3 - build/build_wecui.xml | 328 ++++++++-------- build/buildnumber.txt | 4 +- .../worldeditcui/LiteModWorldEditCUI.java | 357 +++++++++--------- .../event/cui/CUIEventPolygon.java | 4 +- .../worldeditcui/gui/CUIConfigPanel.java | 10 +- .../gui/controls/GuiColourButton.java | 20 +- .../gui/controls/GuiColourPicker.java | 72 ++-- .../worldeditcui/render/LineColour.java | 4 +- .../render/region/PolyhedronRegion.java | 4 +- .../render/shapes/Render3DPolygon.java | 2 +- 11 files changed, 403 insertions(+), 405 deletions(-) diff --git a/.classpath b/.classpath index b0e4e0e7..21b4c252 100644 --- a/.classpath +++ b/.classpath @@ -5,8 +5,5 @@ - - - diff --git a/build/build_wecui.xml b/build/build_wecui.xml index 67352721..3a19a6e5 100644 --- a/build/build_wecui.xml +++ b/build/build_wecui.xml @@ -1,165 +1,165 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build/buildnumber.txt b/build/buildnumber.txt index 04818f17..f47b007a 100644 --- a/build/buildnumber.txt +++ b/build/buildnumber.txt @@ -1,3 +1,3 @@ #Build Number for ANT. Do not edit! -#Wed Jan 22 12:44:35 GMT 2014 -build.number=1723 +#Sun Jul 06 01:04:36 BST 2014 +build.number=1728 diff --git a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java index 6387a81d..e9843247 100644 --- a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java @@ -1,179 +1,178 @@ -package com.mumfrey.worldeditcui; - -import java.io.File; -import java.nio.charset.Charset; -import java.util.Arrays; -import java.util.List; - -import org.lwjgl.input.Keyboard; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.client.multiplayer.WorldClient; -import net.minecraft.client.settings.KeyBinding; -import net.minecraft.network.INetHandler; -import net.minecraft.network.play.server.S01PacketJoinGame; - -import com.mumfrey.liteloader.Configurable; -import com.mumfrey.liteloader.InitCompleteListener; -import com.mumfrey.liteloader.PluginChannelListener; -import com.mumfrey.liteloader.PostRenderListener; -import com.mumfrey.liteloader.core.ClientPluginChannels; -import com.mumfrey.liteloader.core.LiteLoader; -import com.mumfrey.liteloader.core.PluginChannels.ChannelPolicy; -import com.mumfrey.liteloader.modconfig.ConfigPanel; -import com.mumfrey.liteloader.util.ModUtilities; -import com.mumfrey.worldeditcui.event.listeners.CUIListenerChannel; -import com.mumfrey.worldeditcui.event.listeners.CUIListenerWorldRender; -import com.mumfrey.worldeditcui.gui.CUIConfigPanel; -import com.mumfrey.worldeditcui.render.region.CuboidRegion; - -public class LiteModWorldEditCUI implements InitCompleteListener, PluginChannelListener, PostRenderListener, Configurable -{ - private static final String CHANNEL_WECUI = "WECUI"; - private final static Charset UTF_8_CHARSET = Charset.forName("UTF-8"); - - private WorldEditCUI controller; - private WorldClient lastWorld; - private EntityPlayerSP lastPlayer; - - private KeyBinding keyBindToggleUI = new KeyBinding("wecui.keys.toggle", Keyboard.KEY_NONE, "wecui.keys.category"); - private KeyBinding keyBindClearSel = new KeyBinding("wecui.keys.clear", Keyboard.KEY_NONE, "wecui.keys.category"); - - private boolean visible = true; - - private CUIListenerWorldRender worldRenderListener; - private CUIListenerChannel channelListener; - - @Override - public void init(File configPath) - { - ModUtilities.registerKey(this.keyBindToggleUI); - ModUtilities.registerKey(this.keyBindClearSel); - } - - @Override - public void upgradeSettings(String version, File configPath, File oldConfigPath) - { - } - - /* (non-Javadoc) - * @see com.mumfrey.liteloader.InitCompleteListener#onInitCompleted(net.minecraft.client.Minecraft, com.mumfrey.liteloader.core.LiteLoader) - */ - @Override - public void onInitCompleted(Minecraft minecraft, LiteLoader loader) - { - this.controller = new WorldEditCUI(); - this.controller.initialize(); - - this.worldRenderListener = new CUIListenerWorldRender(this.controller, minecraft); - this.channelListener = new CUIListenerChannel(this.controller); - } - - @Override - public void onJoinGame(INetHandler netHandler, S01PacketJoinGame loginPacket) - { - this.visible = true; - this.controller.getDebugger().debug("Joined game, sending initial handshake"); - this.helo(); - } - - /** - * - */ - private void helo() - { - byte[] buffer = ("v|" + WorldEditCUI.protocolVersion).getBytes(UTF_8_CHARSET); - ClientPluginChannels.sendMessage(CHANNEL_WECUI, buffer, ChannelPolicy.DISPATCH_ALWAYS); - } - - @Override - public List getChannels() - { - return Arrays.asList(new String[] { CHANNEL_WECUI }); - } - - @Override - public void onCustomPayload(String channel, int length, byte[] data) - { - try - { - String payload = new String(data, LiteModWorldEditCUI.UTF_8_CHARSET); - this.channelListener.onMessage(payload); - } - catch (Exception ex) {} - } - - @Override - public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clock) - { - if (inGame && mc.currentScreen == null) - { - if (this.keyBindToggleUI.isPressed()) - { - this.visible = !this.visible; - } - - if (this.keyBindClearSel.isPressed()) - { - if (mc.thePlayer != null) - mc.thePlayer.sendChatMessage("//sel"); - } - } - - if (inGame && clock && this.controller != null) - { - if (mc.theWorld != this.lastWorld || mc.thePlayer != this.lastPlayer) - { - this.lastWorld = mc.theWorld; - this.lastPlayer = mc.thePlayer; - - this.controller.getDebugger().debug("World change detected, sending new handshake"); - this.controller.setSelection(new CuboidRegion(this.controller)); - this.helo(); - if (mc.thePlayer != null) mc.thePlayer.sendChatMessage("/we cui"); //Tricks WE to send the current selection - } - } - } - - @Override - public String getName() - { - return "WorldEditCUI"; - } - - @Override - public String getVersion() - { - return "1.7.2_02"; - } - - @Override - public Class getConfigPanelClass() - { - return CUIConfigPanel.class; - } - - @Override - public void onPostRenderEntities(float partialTicks) - { - if (this.visible) - { - try - { - this.worldRenderListener.onRender(partialTicks); - } - catch (Exception ex) {} - } - } - - @Override - public void onPostRender(float partialTicks) - { - } - - public WorldEditCUI getController() - { - return this.controller; - } -} +package com.mumfrey.worldeditcui; + +import java.io.File; +import java.nio.charset.Charset; +import java.util.Arrays; +import java.util.List; + +import org.lwjgl.input.Keyboard; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.client.settings.KeyBinding; +import net.minecraft.network.INetHandler; +import net.minecraft.network.play.server.S01PacketJoinGame; + +import com.mumfrey.liteloader.Configurable; +import com.mumfrey.liteloader.InitCompleteListener; +import com.mumfrey.liteloader.PluginChannelListener; +import com.mumfrey.liteloader.PostRenderListener; +import com.mumfrey.liteloader.core.ClientPluginChannels; +import com.mumfrey.liteloader.core.LiteLoader; +import com.mumfrey.liteloader.core.PluginChannels.ChannelPolicy; +import com.mumfrey.liteloader.modconfig.ConfigPanel; +import com.mumfrey.worldeditcui.event.listeners.CUIListenerChannel; +import com.mumfrey.worldeditcui.event.listeners.CUIListenerWorldRender; +import com.mumfrey.worldeditcui.gui.CUIConfigPanel; +import com.mumfrey.worldeditcui.render.region.CuboidRegion; + +public class LiteModWorldEditCUI implements InitCompleteListener, PluginChannelListener, PostRenderListener, Configurable +{ + private static final String CHANNEL_WECUI = "WECUI"; + private final static Charset UTF_8_CHARSET = Charset.forName("UTF-8"); + + private WorldEditCUI controller; + private WorldClient lastWorld; + private EntityPlayerSP lastPlayer; + + private KeyBinding keyBindToggleUI = new KeyBinding("wecui.keys.toggle", Keyboard.KEY_NONE, "wecui.keys.category"); + private KeyBinding keyBindClearSel = new KeyBinding("wecui.keys.clear", Keyboard.KEY_NONE, "wecui.keys.category"); + + private boolean visible = true; + + private CUIListenerWorldRender worldRenderListener; + private CUIListenerChannel channelListener; + + @Override + public void init(File configPath) + { + LiteLoader.getInput().registerKeyBinding(this.keyBindToggleUI); + LiteLoader.getInput().registerKeyBinding(this.keyBindClearSel); + } + + @Override + public void upgradeSettings(String version, File configPath, File oldConfigPath) + { + } + + /* (non-Javadoc) + * @see com.mumfrey.liteloader.InitCompleteListener#onInitCompleted(net.minecraft.client.Minecraft, com.mumfrey.liteloader.core.LiteLoader) + */ + @Override + public void onInitCompleted(Minecraft minecraft, LiteLoader loader) + { + this.controller = new WorldEditCUI(); + this.controller.initialize(); + + this.worldRenderListener = new CUIListenerWorldRender(this.controller, minecraft); + this.channelListener = new CUIListenerChannel(this.controller); + } + + @Override + public void onJoinGame(INetHandler netHandler, S01PacketJoinGame loginPacket) + { + this.visible = true; + this.controller.getDebugger().debug("Joined game, sending initial handshake"); + this.helo(); + } + + /** + * + */ + private void helo() + { + byte[] buffer = ("v|" + WorldEditCUI.protocolVersion).getBytes(UTF_8_CHARSET); + ClientPluginChannels.sendMessage(CHANNEL_WECUI, buffer, ChannelPolicy.DISPATCH_ALWAYS); + } + + @Override + public List getChannels() + { + return Arrays.asList(new String[] { CHANNEL_WECUI }); + } + + @Override + public void onCustomPayload(String channel, int length, byte[] data) + { + try + { + String payload = new String(data, LiteModWorldEditCUI.UTF_8_CHARSET); + this.channelListener.onMessage(payload); + } + catch (Exception ex) {} + } + + @Override + public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clock) + { + if (inGame && mc.currentScreen == null) + { + if (this.keyBindToggleUI.isPressed()) + { + this.visible = !this.visible; + } + + if (this.keyBindClearSel.isPressed()) + { + if (mc.thePlayer != null) + mc.thePlayer.sendChatMessage("//sel"); + } + } + + if (inGame && clock && this.controller != null) + { + if (mc.theWorld != this.lastWorld || mc.thePlayer != this.lastPlayer) + { + this.lastWorld = mc.theWorld; + this.lastPlayer = mc.thePlayer; + + this.controller.getDebugger().debug("World change detected, sending new handshake"); + this.controller.setSelection(new CuboidRegion(this.controller)); + this.helo(); + if (mc.thePlayer != null) mc.thePlayer.sendChatMessage("/we cui"); //Tricks WE to send the current selection + } + } + } + + @Override + public String getName() + { + return "WorldEditCUI"; + } + + @Override + public String getVersion() + { + return "1.7.10_00"; + } + + @Override + public Class getConfigPanelClass() + { + return CUIConfigPanel.class; + } + + @Override + public void onPostRenderEntities(float partialTicks) + { + if (this.visible) + { + try + { + this.worldRenderListener.onRender(partialTicks); + } + catch (Exception ex) {} + } + } + + @Override + public void onPostRender(float partialTicks) + { + } + + public WorldEditCUI getController() + { + return this.controller; + } +} diff --git a/java/com/mumfrey/worldeditcui/event/cui/CUIEventPolygon.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventPolygon.java index 08d1f43f..114d5020 100644 --- a/java/com/mumfrey/worldeditcui/event/cui/CUIEventPolygon.java +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventPolygon.java @@ -27,8 +27,8 @@ public CUIEventType getEventType() @Override public String raise() { - final int[] vertexIds = new int[args.length]; - for (int i = 0; i < args.length; ++i) + final int[] vertexIds = new int[this.args.length]; + for (int i = 0; i < this.args.length; ++i) { vertexIds[i] = this.getInt(i); } diff --git a/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java b/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java index 8360bd0f..eb090c99 100644 --- a/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java +++ b/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java @@ -21,6 +21,8 @@ public class CUIConfigPanel extends Gui implements ConfigPanel { + private static final int CONTROL_SPACING = 24; + private Minecraft mc; private LiteModWorldEditCUI mod; @@ -45,7 +47,7 @@ public String getPanelTitle() @Override public int getContentHeight() { - return LineColour.values().length * 24; + return LineColour.values().length * CUIConfigPanel.CONTROL_SPACING; } @Override @@ -53,7 +55,7 @@ public void onPanelShown(ConfigPanelHost host) { this.mod = host.getMod(); - ScaledResolution scaledresolution = new ScaledResolution(this.mc.gameSettings, this.mc.displayWidth, this.mc.displayHeight); + ScaledResolution scaledresolution = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight); GuiControl.setScreenSizeAndScale(host.getWidth(), this.getContentHeight(), scaledresolution.getScaleFactor()); this.controlList.clear(); @@ -61,8 +63,8 @@ public void onPanelShown(ConfigPanelHost host) for (LineColour colour : LineColour.values()) { - this.controlList.add(new GuiColourButton(this.mc, nextId, 10, nextId * 24, 40, 20, colour)); - this.controlList.add(new GuiControl(this.mc, 100 + nextId, 220, nextId * 24, 60, 20, "Reset")); + this.controlList.add(new GuiColourButton(this.mc, nextId, 10, nextId * CUIConfigPanel.CONTROL_SPACING, 40, 20, colour)); + this.controlList.add(new GuiControl(this.mc, 100 + nextId, 220, nextId * CUIConfigPanel.CONTROL_SPACING, 60, 20, "Reset")); nextId++; } diff --git a/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java index eeaba03b..43be52c3 100644 --- a/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java +++ b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java @@ -55,33 +55,33 @@ public void save() @Override public void drawControl(Minecraft minecraft, int mouseX, int mouseY) { - if (this.field_146125_m) + if (this.visible) { - boolean mouseOver = mouseX >= this.field_146128_h && mouseY >= this.field_146129_i && mouseX < this.field_146128_h + this.field_146120_f && mouseY < this.field_146129_i + this.field_146121_g; + boolean mouseOver = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; int borderColour = mouseOver || this.picker != null ? 0xFFFFFFFF : 0xFFA0A0A0; - drawRect(this.field_146128_h, this.field_146129_i, this.field_146128_h + this.field_146120_f, this.field_146129_i + this.field_146121_g, borderColour); + drawRect(this.xPosition, this.yPosition, this.xPosition + this.width, this.yPosition + this.height, borderColour); - int v = Math.min(Math.max((int)(((float)this.field_146121_g / (float)this.field_146120_f) * 1024F), 256), 1024); + int v = Math.min(Math.max((int)(((float)this.height / (float)this.width) * 1024F), 256), 1024); minecraft.getTextureManager().bindTexture(GuiColourPicker.COLOURPICKER_CHECKER); glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - this.drawTexturedModalRect(this.field_146128_h + 1, this.field_146129_i + 1, this.field_146128_h + this.field_146120_f - 1, this.field_146129_i + this.field_146121_g - 1, 0, 0, 1024, v); + this.drawTexturedModalRect(this.xPosition + 1, this.yPosition + 1, this.xPosition + this.width - 1, this.yPosition + this.height - 1, 0, 0, 1024, v); - drawRect(this.field_146128_h + 1, this.field_146129_i + 1, this.field_146128_h + this.field_146120_f - 1, this.field_146129_i + this.field_146121_g - 1, this.colour); + drawRect(this.xPosition + 1, this.yPosition + 1, this.xPosition + this.width - 1, this.yPosition + this.height - 1, this.colour); this.mouseDragged(minecraft, mouseX, mouseY); if (this.displayString != null && this.displayString.length() > 0) { - this.drawString(minecraft.fontRenderer, this.displayString, this.field_146128_h + this.field_146120_f + 8, this.field_146129_i + (this.field_146121_g - 8) / 2, 0xFFFFFFFF); + this.drawString(minecraft.fontRendererObj, this.displayString, this.xPosition + this.width + 8, this.yPosition + (this.height - 8) / 2, 0xFFFFFFFF); } } } public void drawPicker(Minecraft minecraft, int mouseX, int mouseY) { - if (this.field_146125_m && this.picker != null) + if (this.visible && this.picker != null) { this.picker.drawButton(minecraft, mouseX, mouseY); @@ -132,8 +132,8 @@ public boolean mousePressed(Minecraft minecraft, int mouseX, int mouseY) { if (pressed) { - int xPos = Math.min(this.field_146128_h + this.field_146120_f, GuiControl.lastScreenWidth - 233); - int yPos = Math.min(this.field_146129_i, GuiControl.lastScreenHeight - 175); + int xPos = Math.min(this.xPosition + this.width, GuiControl.lastScreenWidth - 233); + int yPos = Math.min(this.yPosition, GuiControl.lastScreenHeight - 175); this.picker = new GuiColourPicker(minecraft, 1, xPos, yPos, this.colour, "Choose colour"); this.pickerClicked = false; diff --git a/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java index 98ab1b10..ce1bc676 100644 --- a/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java +++ b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java @@ -81,23 +81,23 @@ public GuiColourPicker(Minecraft minecraft, int controlId, int xPos, int yPos, i if (this.opacity == 0x01000000) this.opacity = 0; - this.fontRenderer = minecraft.fontRenderer; - this.txtRed = new GuiTextField(this.fontRenderer, this.field_146128_h + 188, this.field_146129_i + 10, 32, 16); - this.txtGreen = new GuiTextField(this.fontRenderer, this.field_146128_h + 188, this.field_146129_i + 30, 32, 16); - this.txtBlue = new GuiTextField(this.fontRenderer, this.field_146128_h + 188, this.field_146129_i + 50, 32, 16); - this.txtAlpha = new GuiTextField(this.fontRenderer, this.field_146128_h + 188, this.field_146129_i + 70, 32, 16); + this.fontRenderer = minecraft.fontRendererObj; + this.txtRed = new GuiTextField(this.fontRenderer, this.xPosition + 188, this.yPosition + 10, 32, 16); + this.txtGreen = new GuiTextField(this.fontRenderer, this.xPosition + 188, this.yPosition + 30, 32, 16); + this.txtBlue = new GuiTextField(this.fontRenderer, this.xPosition + 188, this.yPosition + 50, 32, 16); + this.txtAlpha = new GuiTextField(this.fontRenderer, this.xPosition + 188, this.yPosition + 70, 32, 16); - this.txtRed.func_146203_f(3); - this.txtGreen.func_146203_f(3); - this.txtBlue.func_146203_f(3); - this.txtAlpha.func_146203_f(3); + this.txtRed.setMaxStringLength(3); + this.txtGreen.setMaxStringLength(3); + this.txtBlue.setMaxStringLength(3); + this.txtAlpha.setMaxStringLength(3); - this.rectHSArea = new Rectangle(this.field_146128_h + 10, this.field_146129_i + 10, 128, 128); - this.rectBArea = new Rectangle(this.field_146128_h + 143, this.field_146129_i + 10, 15, 128); - this.rectAArea = new Rectangle(this.field_146128_h + 163, this.field_146129_i + 10, 15, 128); + this.rectHSArea = new Rectangle(this.xPosition + 10, this.yPosition + 10, 128, 128); + this.rectBArea = new Rectangle(this.xPosition + 143, this.yPosition + 10, 15, 128); + this.rectAArea = new Rectangle(this.xPosition + 163, this.yPosition + 10, 15, 128); - this.btnOk = new GuiControl(minecraft, 0, this.field_146128_h + 9, this.field_146129_i + 145, 55, 20, I18n.format("gui.ok")); - this.btnCancel = new GuiControl(minecraft, 1, this.field_146128_h + 70, this.field_146129_i + 145, 65, 20, I18n.format("gui.cancel")); + this.btnOk = new GuiControl(minecraft, 0, this.xPosition + 9, this.yPosition + 145, 55, 20, I18n.format("gui.ok")); + this.btnCancel = new GuiControl(minecraft, 1, this.xPosition + 70, this.yPosition + 145, 65, 20, I18n.format("gui.cancel")); this.updateColour(); } @@ -120,42 +120,42 @@ protected void drawControl(Minecraft minecraft, int mouseX, int mouseY) this.mouseDragged(minecraft, mouseX, mouseY); // Calculate coordinates for the selectors - int hPos = this.field_146128_h + 10 + (int)(128F * this.hsb[H]); - int sPos = this.field_146129_i + 10 + (128 - (int)(128F * this.hsb[S])); - int bPos = this.field_146129_i + 10 + (128 - (int)(128F * this.hsb[B])); - int aPos = this.field_146129_i + 10 + ((256 - ((this.opacity >> 24) & 0xFF)) / 2); + int hPos = this.xPosition + 10 + (int)(128F * this.hsb[H]); + int sPos = this.yPosition + 10 + (128 - (int)(128F * this.hsb[S])); + int bPos = this.yPosition + 10 + (128 - (int)(128F * this.hsb[B])); + int aPos = this.yPosition + 10 + ((256 - ((this.opacity >> 24) & 0xFF)) / 2); // Calculate B colour int brightness = Color.HSBtoRGB(this.hsb[H], this.hsb[S], 1.0F) | 0xFF000000; // Draw backgrounds - drawRect(this.field_146128_h, this.field_146129_i, this.field_146128_h + this.field_146120_f, this.field_146129_i + this.field_146121_g, 0xAA000000); // Background - drawRect(this.field_146128_h + 9, this.field_146129_i + 9, this.field_146128_h + 139, this.field_146129_i + 139, 0xFFA0A0A0); // HS background - drawRect(this.field_146128_h + 142, this.field_146129_i + 9, this.field_146128_h + 159, this.field_146129_i + 139, 0xFFA0A0A0); // B background - drawRect(this.field_146128_h + 162, this.field_146129_i + 9, this.field_146128_h + 179, this.field_146129_i + 139, 0xFFA0A0A0); // A background - drawRect(this.field_146128_h + 187, this.field_146129_i + 105, this.field_146128_h + 221, this.field_146129_i + 139, 0xFFA0A0A0); // Preview background + drawRect(this.xPosition, this.yPosition, this.xPosition + this.width, this.yPosition + this.height, 0xAA000000); // Background + drawRect(this.xPosition + 9, this.yPosition + 9, this.xPosition + 139, this.yPosition + 139, 0xFFA0A0A0); // HS background + drawRect(this.xPosition + 142, this.yPosition + 9, this.xPosition + 159, this.yPosition + 139, 0xFFA0A0A0); // B background + drawRect(this.xPosition + 162, this.yPosition + 9, this.xPosition + 179, this.yPosition + 139, 0xFFA0A0A0); // A background + drawRect(this.xPosition + 187, this.yPosition + 105, this.xPosition + 221, this.yPosition + 139, 0xFFA0A0A0); // Preview background // Draw colour picker this.mc.getTextureManager().bindTexture(GuiColourPicker.COLOURPICKER_PICKER); glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - this.drawTexturedModalRect(this.field_146128_h + 10, this.field_146129_i + 10, this.field_146128_h + 138, this.field_146129_i + 138, 0, 0, 256, 256); + this.drawTexturedModalRect(this.xPosition + 10, this.yPosition + 10, this.xPosition + 138, this.yPosition + 138, 0, 0, 256, 256); this.drawCrossHair(hPos, sPos, 5, 1, 0xFF000000); // Draw brightness bar - this.drawGradientRect(this.field_146128_h + 143, this.field_146129_i + 10, this.field_146128_h + 158, this.field_146129_i + 138, brightness, 0xFF000000); - this.drawRotText(this.fontRenderer, "Luminosity", this.field_146128_h + 150, this.field_146129_i + 74, 0xFF000000, false); - drawRect(this.field_146128_h + 142, bPos - 1, this.field_146128_h + 159, bPos + 1, 0xFFFFFFFF); + this.drawGradientRect(this.xPosition + 143, this.yPosition + 10, this.xPosition + 158, this.yPosition + 138, brightness, 0xFF000000); + this.drawRotText(this.fontRenderer, "Luminosity", this.xPosition + 150, this.yPosition + 74, 0xFF000000, false); + drawRect(this.xPosition + 142, bPos - 1, this.xPosition + 159, bPos + 1, 0xFFFFFFFF); // Draw opacity bar - this.drawGradientRect(this.field_146128_h + 163, this.field_146129_i + 10, this.field_146128_h + 178, this.field_146129_i + 138, 0xFFFFFFFF, 0xFF000000); - this.drawRotText(this.fontRenderer, "Opacity", this.field_146128_h + 170, this.field_146129_i + 74, 0xFF000000, false); - drawRect(this.field_146128_h + 162, aPos - 1, this.field_146128_h + 179, aPos + 1, 0xFFFFFFFF); + this.drawGradientRect(this.xPosition + 163, this.yPosition + 10, this.xPosition + 178, this.yPosition + 138, 0xFFFFFFFF, 0xFF000000); + this.drawRotText(this.fontRenderer, "Opacity", this.xPosition + 170, this.yPosition + 74, 0xFF000000, false); + drawRect(this.xPosition + 162, aPos - 1, this.xPosition + 179, aPos + 1, 0xFFFFFFFF); // Draw preview this.mc.getTextureManager().bindTexture(GuiColourPicker.COLOURPICKER_CHECKER); glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - this.drawTexturedModalRect(this.field_146128_h + 188, this.field_146129_i + 106, this.field_146128_h + 220, this.field_146129_i + 138, 0, 0, 1024, 1024); - drawRect(this.field_146128_h + 188, this.field_146129_i + 106, this.field_146128_h + 220, this.field_146129_i + 138, this.rgb); + this.drawTexturedModalRect(this.xPosition + 188, this.yPosition + 106, this.xPosition + 220, this.yPosition + 138, 0, 0, 1024, 1024); + drawRect(this.xPosition + 188, this.yPosition + 106, this.xPosition + 220, this.yPosition + 138, this.rgb); // Draw text boxes this.txtRed.drawTextBox(); @@ -223,20 +223,20 @@ protected void mouseDragged(Minecraft minecraft, int mouseX, int mouseY) if (this.draggingHS) { - this.hsb[H] = clamp(mouseX - this.field_146128_h - 10, 0, 128) / 128F; - this.hsb[S] = (128F - clamp(mouseY - this.field_146129_i - 10, 0, 128)) / 128F; + this.hsb[H] = clamp(mouseX - this.xPosition - 10, 0, 128) / 128F; + this.hsb[S] = (128F - clamp(mouseY - this.yPosition - 10, 0, 128)) / 128F; this.updateColour(); } if (this.draggingB) { - this.hsb[B] = (128F - clamp(mouseY - this.field_146129_i - 10, 0, 128)) / 128F; + this.hsb[B] = (128F - clamp(mouseY - this.yPosition - 10, 0, 128)) / 128F; this.updateColour(); } if (this.draggingA) { - this.opacity = (mouseY - this.field_146129_i < 11) ? 0xFF000000 : (((128 - (int)clamp(mouseY - this.field_146129_i - 10, 0, 128)) << 25) & 0xFF000000); + this.opacity = (mouseY - this.yPosition < 11) ? 0xFF000000 : (((128 - (int)clamp(mouseY - this.yPosition - 10, 0, 128)) << 25) & 0xFF000000); this.updateColour(); } } diff --git a/java/com/mumfrey/worldeditcui/render/LineColour.java b/java/com/mumfrey/worldeditcui/render/LineColour.java index 92efa916..da442cdc 100644 --- a/java/com/mumfrey/worldeditcui/render/LineColour.java +++ b/java/com/mumfrey/worldeditcui/render/LineColour.java @@ -79,8 +79,8 @@ public void setColour(Colour colour) public void updateColour() { - this.normal = new LineInfo(3.0f, colour.red(), colour.green(), colour.blue(), colour.alpha(), GL_LESS); - this.hidden = new LineInfo(3.0f, colour.red(), colour.green(), colour.blue(), colour.alpha() * 0.25F, GL_GEQUAL); + this.normal = new LineInfo(3.0f, this.colour.red(), this.colour.green(), this.colour.blue(), this.colour.alpha(), GL_LESS); + this.hidden = new LineInfo(3.0f, this.colour.red(), this.colour.green(), this.colour.blue(), this.colour.alpha() * 0.25F, GL_GEQUAL); } public void setDefaultColour() diff --git a/java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java b/java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java index bcba17f5..ba5e1cd0 100644 --- a/java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java @@ -67,7 +67,7 @@ public void addPolygon(int[] vertexIds) final Vector3[] face = new Vector3[vertexIds.length]; for (int i = 0; i < vertexIds.length; ++i) { - final PointCube vertex = vertices.get(vertexIds[i]); + final PointCube vertex = this.vertices.get(vertexIds[i]); if (vertex == null) { // This should never happen @@ -76,7 +76,7 @@ public void addPolygon(int[] vertexIds) face[i] = vertex.getPoint().add(half); } - faces.add(face); + this.faces.add(face); } @Override diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java index 53f793c6..7d7d3963 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java @@ -35,7 +35,7 @@ public void render() tess.startDrawing(GL_LINE_LOOP); tempColour.prepareColour(); - for (Vector3 vertex : vertices) + for (Vector3 vertex : this.vertices) { tess.addVertex(vertex.getX(), vertex.getY(), vertex.getZ()); } From b0b3e95bd5bf9ece02ef83936f702687eb59169c Mon Sep 17 00:00:00 2001 From: Mazdallier Date: Wed, 8 Oct 2014 11:00:24 +0200 Subject: [PATCH 14/51] Create fr_FR.lang --- res/assets/wecui/lang/fr_FR.lang | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 res/assets/wecui/lang/fr_FR.lang diff --git a/res/assets/wecui/lang/fr_FR.lang b/res/assets/wecui/lang/fr_FR.lang new file mode 100644 index 00000000..ac0936f8 --- /dev/null +++ b/res/assets/wecui/lang/fr_FR.lang @@ -0,0 +1,20 @@ +wecui.options.title=Options WorldEditCUI + +wecui.keys.toggle=Bascule Visibilité du CUI +wecui.keys.clear=Effacer la sélection WorldEdit +wecui.keys.category=WorldEditCUI + +gui.ok=OK + +colour.cuboidedge=Couleur des bordures du Cuboïde +colour.cuboidgrid=Couleur de la grille du Cuboïde +colour.cuboidpoint1=Couleur du premier point du Cuboïde +colour.cuboidpoint2=Couleur du second point du Cuboïde +colour.polygrid=Couleur de la grille du Polygone +colour.polyedge=Couleur des bordures du Polygone +colour.polypoint=Couleur du point du Polygone +colour.ellipsoidgrid=Couleur de la grille de l'Ellipsoïde +colour.ellipsoidpoint=Couleur du centre de l'Ellipsoïde +colour.cylindergrid=Couleur de la grille du Cylindre +colour.cylinderedge=Couleur des bordures du Cylindre +colour.cylinderpoint=Couleur du centre du Cylindre From 54583ebf88544fb2a36574b13a5e401e61ee2cdf Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Sun, 14 Dec 2014 19:06:22 +0000 Subject: [PATCH 15/51] Updated to 1.8, added promiscuous mode switch, improved handshake logic --- .../worldeditcui/LiteModWorldEditCUI.java | 70 ++++++-- .../mumfrey/worldeditcui/WorldEditCUI.java | 3 +- .../worldeditcui/config/CUIConfiguration.java | 16 +- .../listeners/CUIListenerWorldRender.java | 27 ++- .../worldeditcui/gui/CUIConfigPanel.java | 61 ++++--- .../gui/controls/GuiColourButton.java | 2 +- .../gui/controls/GuiColourPicker.java | 10 +- .../worldeditcui/gui/controls/GuiControl.java | 154 +++++++++--------- .../worldeditcui/render/LineColour.java | 2 +- .../mumfrey/worldeditcui/render/LineInfo.java | 2 +- .../render/shapes/Render2DBox.java | 14 +- .../render/shapes/Render2DGrid.java | 12 +- .../render/shapes/Render3DBox.java | 50 +++--- .../render/shapes/Render3DGrid.java | 58 +++---- .../render/shapes/Render3DPolygon.java | 12 +- .../render/shapes/RenderCylinderBox.java | 13 +- .../render/shapes/RenderCylinderCircles.java | 13 +- .../render/shapes/RenderCylinderGrid.java | 31 ++-- .../render/shapes/RenderEllipsoid.java | 51 +++--- res/assets/wecui/lang/en_US.lang | 5 + 20 files changed, 344 insertions(+), 262 deletions(-) diff --git a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java index e9843247..71a5e38f 100644 --- a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java @@ -1,21 +1,27 @@ package com.mumfrey.worldeditcui; +import io.netty.buffer.Unpooled; + import java.io.File; -import java.nio.charset.Charset; import java.util.Arrays; import java.util.List; -import org.lwjgl.input.Keyboard; - import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.multiplayer.ServerData; import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.client.settings.KeyBinding; import net.minecraft.network.INetHandler; +import net.minecraft.network.PacketBuffer; import net.minecraft.network.play.server.S01PacketJoinGame; +import org.lwjgl.input.Keyboard; + +import com.google.common.base.Charsets; +import com.mojang.realmsclient.dto.RealmsServer; import com.mumfrey.liteloader.Configurable; import com.mumfrey.liteloader.InitCompleteListener; +import com.mumfrey.liteloader.JoinGameListener; import com.mumfrey.liteloader.PluginChannelListener; import com.mumfrey.liteloader.PostRenderListener; import com.mumfrey.liteloader.core.ClientPluginChannels; @@ -27,10 +33,11 @@ import com.mumfrey.worldeditcui.gui.CUIConfigPanel; import com.mumfrey.worldeditcui.render.region.CuboidRegion; -public class LiteModWorldEditCUI implements InitCompleteListener, PluginChannelListener, PostRenderListener, Configurable +public class LiteModWorldEditCUI implements InitCompleteListener, PluginChannelListener, PostRenderListener, Configurable, JoinGameListener { + private static final int DELAYED_HELO_TICKS = 10; + private static final String CHANNEL_WECUI = "WECUI"; - private final static Charset UTF_8_CHARSET = Charset.forName("UTF-8"); private WorldEditCUI controller; private WorldClient lastWorld; @@ -44,6 +51,8 @@ public class LiteModWorldEditCUI implements InitCompleteListener, PluginChannelL private CUIListenerWorldRender worldRenderListener; private CUIListenerChannel channelListener; + private int delayedHelo = 0; + @Override public void init(File configPath) { @@ -70,7 +79,7 @@ public void onInitCompleted(Minecraft minecraft, LiteLoader loader) } @Override - public void onJoinGame(INetHandler netHandler, S01PacketJoinGame loginPacket) + public void onJoinGame(INetHandler netHandler, S01PacketJoinGame loginPacket, ServerData serverData, RealmsServer realmsServer) { this.visible = true; this.controller.getDebugger().debug("Joined game, sending initial handshake"); @@ -82,7 +91,8 @@ public void onJoinGame(INetHandler netHandler, S01PacketJoinGame loginPacket) */ private void helo() { - byte[] buffer = ("v|" + WorldEditCUI.protocolVersion).getBytes(UTF_8_CHARSET); + PacketBuffer buffer = new PacketBuffer(Unpooled.buffer()); + buffer.writeString("v|" + WorldEditCUI.PROTOCOL_VERSION); ClientPluginChannels.sendMessage(CHANNEL_WECUI, buffer, ChannelPolicy.DISPATCH_ALWAYS); } @@ -93,12 +103,21 @@ public List getChannels() } @Override - public void onCustomPayload(String channel, int length, byte[] data) + public void onCustomPayload(String channel, PacketBuffer data) { try { - String payload = new String(data, LiteModWorldEditCUI.UTF_8_CHARSET); - this.channelListener.onMessage(payload); + int readableBytes = data.readableBytes(); + if (readableBytes > 0) + { + byte[] payload = new byte[readableBytes]; + data.readBytes(payload); + this.channelListener.onMessage(new String(payload, Charsets.UTF_8)); + } + else + { + this.controller.getDebugger().debug("Warning, invalid (zero length) payload received from server"); + } } catch (Exception ex) {} } @@ -130,7 +149,24 @@ public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clo this.controller.getDebugger().debug("World change detected, sending new handshake"); this.controller.setSelection(new CuboidRegion(this.controller)); this.helo(); - if (mc.thePlayer != null) mc.thePlayer.sendChatMessage("/we cui"); //Tricks WE to send the current selection + this.delayedHelo = LiteModWorldEditCUI.DELAYED_HELO_TICKS; + if (mc.thePlayer != null && this.controller.getConfiguration().isPromiscuous()) + { + mc.thePlayer.sendChatMessage("/we cui"); //Tricks WE to send the current selection + } + } + + if (this.delayedHelo > 0) + { + this.delayedHelo--; + if (this.delayedHelo == 0) + { + this.helo(); + if (LiteLoader.getClientPluginChannels().isRemoteChannelRegistered(CHANNEL_WECUI) && mc.thePlayer != null) + { + mc.thePlayer.sendChatMessage("/we cui"); + } + } } } } @@ -144,7 +180,7 @@ public String getName() @Override public String getVersion() { - return "1.7.10_00"; + return "1.8.0_00"; } @Override @@ -155,6 +191,11 @@ public Class getConfigPanelClass() @Override public void onPostRenderEntities(float partialTicks) + { + } + + @Override + public void onPostRender(float partialTicks) { if (this.visible) { @@ -166,11 +207,6 @@ public void onPostRenderEntities(float partialTicks) } } - @Override - public void onPostRender(float partialTicks) - { - } - public WorldEditCUI getController() { return this.controller; diff --git a/java/com/mumfrey/worldeditcui/WorldEditCUI.java b/java/com/mumfrey/worldeditcui/WorldEditCUI.java index 8252bbe1..dc2d2374 100644 --- a/java/com/mumfrey/worldeditcui/WorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/WorldEditCUI.java @@ -20,7 +20,8 @@ */ public class WorldEditCUI { - public static final int protocolVersion = 3; + public static final int PROTOCOL_VERSION = 3; + private BaseRegion selection; private CUIDebug debugger; private CUIConfiguration configuration; diff --git a/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java b/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java index 6b7b61af..2560c7b1 100644 --- a/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java +++ b/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java @@ -26,6 +26,8 @@ public class CUIConfiguration implements InitializationFactory private boolean debugMode = false; private boolean ignoreUpdates = false; + private boolean promiscuous = false; + private Colour cuboidGridColor = new Colour("#CC3333CC"); private Colour cuboidEdgeColor = new Colour("#CC4C4CCC"); private Colour cuboidFirstPointColor = new Colour("#33CC33CC"); @@ -85,6 +87,16 @@ public boolean ignoreUpdates() return this.ignoreUpdates; } + public boolean isPromiscuous() + { + return this.promiscuous; + } + + public void setPromiscuous(boolean promiscuous) + { + this.promiscuous = promiscuous; + } + public static CUIConfiguration create() { File jsonFile = new File(LiteLoader.getCommonConfigFolder(), CUIConfiguration.CONFIG_FILE_NAME); @@ -99,7 +111,7 @@ public static CUIConfiguration create() CUIConfiguration config = CUIConfiguration.gson.fromJson(fileReader, CUIConfiguration.class); return config; } - catch (IOException ex) + catch (Exception ex) { ex.printStackTrace(); } @@ -127,7 +139,7 @@ public void save() fileWriter = new FileWriter(jsonFile); CUIConfiguration.gson.toJson(this, fileWriter); } - catch (IOException ex) + catch (Exception ex) { ex.printStackTrace(); } diff --git a/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerWorldRender.java b/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerWorldRender.java index 2b46d691..44fe28cb 100644 --- a/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerWorldRender.java +++ b/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerWorldRender.java @@ -1,14 +1,13 @@ package com.mumfrey.worldeditcui.event.listeners; -import static org.lwjgl.opengl.GL11.*; - -import com.mumfrey.worldeditcui.WorldEditCUI; - +import static com.mumfrey.liteloader.gl.GL.*; import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityClientPlayerMP; +import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; +import com.mumfrey.worldeditcui.WorldEditCUI; + /** * Listener for WorldRenderEvent * @@ -34,16 +33,16 @@ public void onRender(float partialTicks) OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_BLEND); - glEnable(GL_ALPHA_TEST); + glEnableBlend(); + glEnableAlphaTest(); glAlphaFunc(GL_GREATER, 0.0F); - glDisable(GL_TEXTURE_2D); + glDisableTexture2D(); glDepthMask(false); glPushMatrix(); try { - EntityClientPlayerMP thePlayer = this.minecraft.thePlayer; + EntityPlayerSP thePlayer = this.minecraft.thePlayer; glTranslated(-this.getPlayerXGuess(thePlayer, partialTicks), -this.getPlayerYGuess(thePlayer, partialTicks), -this.getPlayerZGuess(thePlayer, partialTicks)); glColor3f(1.0f, 1.0f, 1.0f); if (this.controller.getSelection() != null) @@ -59,24 +58,24 @@ public void onRender(float partialTicks) glPopMatrix(); glDepthMask(true); - glEnable(GL_TEXTURE_2D); - glDisable(GL_BLEND); + glEnableTexture2D(); + glDisableBlend(); glAlphaFunc(GL_GREATER, 0.1F); RenderHelper.enableStandardItemLighting(); } - private double getPlayerXGuess(EntityClientPlayerMP thePlayer, float renderTick) + private double getPlayerXGuess(EntityPlayerSP thePlayer, float renderTick) { return thePlayer.prevPosX + ((thePlayer.posX - thePlayer.prevPosX) * renderTick); } - private double getPlayerYGuess(EntityClientPlayerMP thePlayer, float renderTick) + private double getPlayerYGuess(EntityPlayerSP thePlayer, float renderTick) { return thePlayer.prevPosY + ((thePlayer.posY - thePlayer.prevPosY) * renderTick); } - private double getPlayerZGuess(EntityClientPlayerMP thePlayer, float renderTick) + private double getPlayerZGuess(EntityPlayerSP thePlayer, float renderTick) { return thePlayer.prevPosZ + ((thePlayer.posZ - thePlayer.prevPosZ) * renderTick); } diff --git a/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java b/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java index eb090c99..343183e9 100644 --- a/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java +++ b/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java @@ -1,7 +1,5 @@ package com.mumfrey.worldeditcui.gui; -import static org.lwjgl.opengl.GL11.*; - import java.util.ArrayList; import java.util.List; @@ -9,12 +7,15 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.resources.I18n; +import com.mumfrey.liteloader.client.gui.GuiCheckbox; import com.mumfrey.liteloader.modconfig.ConfigPanel; import com.mumfrey.liteloader.modconfig.ConfigPanelHost; import com.mumfrey.worldeditcui.LiteModWorldEditCUI; +import com.mumfrey.worldeditcui.config.CUIConfiguration; import com.mumfrey.worldeditcui.gui.controls.GuiColourButton; import com.mumfrey.worldeditcui.gui.controls.GuiControl; import com.mumfrey.worldeditcui.render.LineColour; @@ -27,11 +28,13 @@ public class CUIConfigPanel extends Gui implements ConfigPanel private LiteModWorldEditCUI mod; - private List controlList = new ArrayList(); + private List controlList = new ArrayList(); private List colourButtonList = new ArrayList(); - private GuiControl activeControl; + private GuiButton activeControl; + + private GuiCheckbox chkPromiscuous; public CUIConfigPanel() { @@ -60,15 +63,18 @@ public void onPanelShown(ConfigPanelHost host) this.controlList.clear(); int nextId = 0; + int top = 64; for (LineColour colour : LineColour.values()) { - this.controlList.add(new GuiColourButton(this.mc, nextId, 10, nextId * CUIConfigPanel.CONTROL_SPACING, 40, 20, colour)); - this.controlList.add(new GuiControl(this.mc, 100 + nextId, 220, nextId * CUIConfigPanel.CONTROL_SPACING, 60, 20, "Reset")); + this.controlList.add(new GuiColourButton(this.mc, nextId, 24, top + nextId * CUIConfigPanel.CONTROL_SPACING, 40, 20, colour)); + this.controlList.add(new GuiControl(this.mc, 100 + nextId, 234, top + nextId * CUIConfigPanel.CONTROL_SPACING, 60, 20, "Reset")); nextId++; } - for (GuiControl control : this.controlList) + this.controlList.add(this.chkPromiscuous = new GuiCheckbox(nextId, 24, 26, I18n.format("gui.options.compat.spammy"))); + + for (GuiButton control : this.controlList) { if (control instanceof GuiColourButton) this.colourButtonList.add((GuiColourButton)control); @@ -88,7 +94,9 @@ public void onPanelHidden() colourButton.save(); } - this.mod.getController().getConfiguration().save(); + CUIConfiguration config = this.mod.getController().getConfiguration(); + config.setPromiscuous(this.chkPromiscuous.checked); + config.save(); } @Override @@ -99,7 +107,10 @@ public void onTick(ConfigPanelHost host) @Override public void drawPanel(ConfigPanelHost host, int mouseX, int mouseY, float partialTicks) { - for (GuiControl control : this.controlList) + this.drawString(this.mc.fontRendererObj, I18n.format("gui.options.compat.title"), 10, 10, 0xFFFFFF55); + this.drawString(this.mc.fontRendererObj, I18n.format("gui.options.colours.title"), 10, 48, 0xFFFFFF55); + + for (GuiButton control : this.controlList) { control.drawButton(this.mc, mouseX, mouseY); } @@ -115,7 +126,7 @@ public void mousePressed(ConfigPanelHost host, int mouseX, int mouseY, int mouse { boolean makeActive = true; - for (GuiControl control : this.controlList) + for (GuiButton control : this.controlList) { if (control.mousePressed(this.mc, mouseX, mouseY)) { @@ -129,8 +140,14 @@ public void mousePressed(ConfigPanelHost host, int mouseX, int mouseY, int mouse } } - private void actionPerformed(GuiControl control) + private void actionPerformed(GuiButton control) { + if (control instanceof GuiCheckbox) + { + GuiCheckbox chk = (GuiCheckbox)control; + chk.checked = !chk.checked; + } + if (control.id >= 100) { LineColour lineColour = LineColour.values()[control.id - 100]; @@ -170,26 +187,4 @@ public void keyPressed(ConfigPanelHost host, char keyChar, int keyCode) colourButton.keyTyped(keyChar, keyCode); } } - - /** - * Enable OpenGL clipping planes (uses planes 2, 3, 4 and 5) - */ - protected final void enableClipping() - { - glEnable(GL_CLIP_PLANE2); - glEnable(GL_CLIP_PLANE3); - glEnable(GL_CLIP_PLANE4); - glEnable(GL_CLIP_PLANE5); - } - - /** - * Disable OpenGL clipping planes (uses planes 2, 3, 4 and 5) - */ - protected final void disableClipping() - { - glDisable(GL_CLIP_PLANE5); - glDisable(GL_CLIP_PLANE4); - glDisable(GL_CLIP_PLANE3); - glDisable(GL_CLIP_PLANE2); - } } diff --git a/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java index 43be52c3..6243a669 100644 --- a/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java +++ b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java @@ -1,6 +1,6 @@ package com.mumfrey.worldeditcui.gui.controls; -import static org.lwjgl.opengl.GL11.*; +import static com.mumfrey.liteloader.gl.GL.*; import com.mumfrey.worldeditcui.render.LineColour; diff --git a/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java index ce1bc676..36217f0a 100644 --- a/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java +++ b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java @@ -1,6 +1,6 @@ package com.mumfrey.worldeditcui.gui.controls; -import static org.lwjgl.opengl.GL11.*; +import static com.mumfrey.liteloader.gl.GL.*; import java.awt.Color; import java.awt.Rectangle; @@ -82,10 +82,10 @@ public GuiColourPicker(Minecraft minecraft, int controlId, int xPos, int yPos, i this.opacity = 0; this.fontRenderer = minecraft.fontRendererObj; - this.txtRed = new GuiTextField(this.fontRenderer, this.xPosition + 188, this.yPosition + 10, 32, 16); - this.txtGreen = new GuiTextField(this.fontRenderer, this.xPosition + 188, this.yPosition + 30, 32, 16); - this.txtBlue = new GuiTextField(this.fontRenderer, this.xPosition + 188, this.yPosition + 50, 32, 16); - this.txtAlpha = new GuiTextField(this.fontRenderer, this.xPosition + 188, this.yPosition + 70, 32, 16); + this.txtRed = new GuiTextField(0, this.fontRenderer, this.xPosition + 188, this.yPosition + 10, 32, 16); + this.txtGreen = new GuiTextField(1, this.fontRenderer, this.xPosition + 188, this.yPosition + 30, 32, 16); + this.txtBlue = new GuiTextField(2, this.fontRenderer, this.xPosition + 188, this.yPosition + 50, 32, 16); + this.txtAlpha = new GuiTextField(3, this.fontRenderer, this.xPosition + 188, this.yPosition + 70, 32, 16); this.txtRed.setMaxStringLength(3); this.txtGreen.setMaxStringLength(3); diff --git a/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java b/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java index ada19ec3..d5f17196 100644 --- a/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java +++ b/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java @@ -4,8 +4,8 @@ import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.renderer.Tessellator; - -import static org.lwjgl.opengl.GL11.*; +import net.minecraft.client.renderer.WorldRenderer; +import static com.mumfrey.liteloader.gl.GL.*; /** * GuiControlEx is the base class for additional controls. It includes some advanced drawing methods @@ -194,20 +194,21 @@ public static void drawNativeLine(float x1, float y1, float x2, float y2, float float f2 = (float)(colour >> 8 & 0xff) / 255F; float f3 = (float)(colour & 0xff) / 255F; - glEnable(GL_BLEND); - glDisable(GL_TEXTURE_2D); + glEnableBlend(); + glDisableTexture2D(); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(f1, f2, f3, f); glLineWidth(width); - Tessellator tessellator = Tessellator.instance; - tessellator.startDrawing(GL_LINES); - tessellator.addVertex(x1, y1, 0); - tessellator.addVertex(x2, y2, 0); + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + worldRenderer.startDrawing(GL_LINES); + worldRenderer.addVertex(x1, y1, 0); + worldRenderer.addVertex(x2, y2, 0); tessellator.draw(); - glEnable(GL_TEXTURE_2D); - glDisable(GL_BLEND); + glEnableTexture2D(); + glDisableBlend(); } /** @@ -262,32 +263,33 @@ public static void drawArrow(int x1, int y1, int x2, int y2, int z, int width, i float f2 = (float)(colour >> 8 & 0xff) / 255F; float f3 = (float)(colour & 0xff) / 255F; - glEnable(GL_BLEND); - glDisable(GL_TEXTURE_2D); + glEnableBlend(); + glDisableTexture2D(); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(f1, f2, f3, f); // Draw the line - Tessellator tessellator = Tessellator.instance; - tessellator.startDrawingQuads(); - tessellator.addVertex(x1, y2, z); - tessellator.addVertex(x2, y2, z); - tessellator.addVertex(x2, y1, z); - tessellator.addVertex(x1, y1, z); + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + worldRenderer.startDrawingQuads(); + worldRenderer.addVertex(x1, y2, z); + worldRenderer.addVertex(x2, y2, z); + worldRenderer.addVertex(x2, y1, z); + worldRenderer.addVertex(x1, y1, z); tessellator.draw(); // If an arrow then draw the arrow head if (arrowHead && arrowHeadSize > 0) { - tessellator.startDrawing(4); - tessellator.addVertex(x2, 0 - arrowHeadSize / 2, z); - tessellator.addVertex(x2, arrowHeadSize / 2, z); - tessellator.addVertex(length, 0, z); + worldRenderer.startDrawing(4); + worldRenderer.addVertex(x2, 0 - arrowHeadSize / 2, z); + worldRenderer.addVertex(x2, arrowHeadSize / 2, z); + worldRenderer.addVertex(length, 0, z); tessellator.draw(); } - glEnable(GL_TEXTURE_2D); - glDisable(GL_BLEND); + glEnableTexture2D(); + glDisableBlend(); glPopMatrix(); } @@ -318,12 +320,13 @@ public void setTexMapSize(int textureSize) @SuppressWarnings("cast") public void drawTexturedModalRectRot(int x, int y, int x2, int y2, int u, int v, int u2, int v2) { - Tessellator tessellator = Tessellator.instance; - tessellator.startDrawingQuads(); - tessellator.addVertexWithUV(x2, y2, this.zLevel, (float)(u) * texMapScale, (float)(v2) * texMapScale); - tessellator.addVertexWithUV(x2, y, this.zLevel, (float)(u2) * texMapScale, (float)(v2) * texMapScale); - tessellator.addVertexWithUV(x, y, this.zLevel, (float)(u2) * texMapScale, (float)(v) * texMapScale); - tessellator.addVertexWithUV(x, y2, this.zLevel, (float)(u) * texMapScale, (float)(v) * texMapScale); + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + worldRenderer.startDrawingQuads(); + worldRenderer.addVertexWithUV(x2, y2, this.zLevel, (float)(u) * texMapScale, (float)(v2) * texMapScale); + worldRenderer.addVertexWithUV(x2, y, this.zLevel, (float)(u2) * texMapScale, (float)(v2) * texMapScale); + worldRenderer.addVertexWithUV(x, y, this.zLevel, (float)(u2) * texMapScale, (float)(v) * texMapScale); + worldRenderer.addVertexWithUV(x, y2, this.zLevel, (float)(u) * texMapScale, (float)(v) * texMapScale); tessellator.draw(); } @@ -340,12 +343,13 @@ public void drawTexturedModalRectRot(int x, int y, int x2, int y2, int u, int v, @SuppressWarnings("cast") public void drawTexturedModalRectRot(int x, int y, int u, int v, int width, int height) { - Tessellator tessellator = Tessellator.instance; - tessellator.startDrawingQuads(); - tessellator.addVertexWithUV(x + height, y + width, this.zLevel, (float)(u) * texMapScale, (float)(v + height) * texMapScale); - tessellator.addVertexWithUV(x + height, y, this.zLevel, (float)(u + width) * texMapScale, (float)(v + height) * texMapScale); - tessellator.addVertexWithUV(x, y, this.zLevel, (float)(u + width) * texMapScale, (float)(v) * texMapScale); - tessellator.addVertexWithUV(x, y + width, this.zLevel, (float)(u) * texMapScale, (float)(v) * texMapScale); + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + worldRenderer.startDrawingQuads(); + worldRenderer.addVertexWithUV(x + height, y + width, this.zLevel, (float)(u) * texMapScale, (float)(v + height) * texMapScale); + worldRenderer.addVertexWithUV(x + height, y, this.zLevel, (float)(u + width) * texMapScale, (float)(v + height) * texMapScale); + worldRenderer.addVertexWithUV(x, y, this.zLevel, (float)(u + width) * texMapScale, (float)(v) * texMapScale); + worldRenderer.addVertexWithUV(x, y + width, this.zLevel, (float)(u) * texMapScale, (float)(v) * texMapScale); tessellator.draw(); } @@ -462,11 +466,11 @@ public static void drawStringWithEllipsis(FontRenderer fontrenderer, String s, i { if (fontrenderer.getStringWidth(s) <= width) { - fontrenderer.drawStringWithShadow(s, x, y, colour); + fontrenderer.drawStringWithShadow(s, x, y, colour); // func_175063_a drawStringWithShadow } else if (width < 8) { - fontrenderer.drawStringWithShadow("..", x, y, colour); + fontrenderer.drawStringWithShadow("..", x, y, colour); // func_175063_a drawStringWithShadow } else { @@ -475,7 +479,7 @@ else if (width < 8) while (fontrenderer.getStringWidth(trimmedText) > width - 8 && trimmedText.length() > 0) trimmedText = trimmedText.substring(0, trimmedText.length() - 1); - fontrenderer.drawStringWithShadow(trimmedText + "...", x, y, colour); + fontrenderer.drawStringWithShadow(trimmedText + "...", x, y, colour); // func_175063_a drawStringWithShadow } } @@ -492,35 +496,36 @@ protected void drawCrossHair(int x, int y, int size, int width, int colour) glLineWidth(GuiControl.guiScaleFactor * width); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_BLEND); - glDisable(GL_TEXTURE_2D); - glDisable(GL_LIGHTING); + glEnableBlend(); + glDisableTexture2D(); + glDisableLighting(); glColor4f(red, green, blue, alpha); - glEnable(GL_COLOR_LOGIC_OP); + glEnableColorLogic(); glLogicOp(GL_OR_REVERSE); // Draw the frame - Tessellator tessellator = Tessellator.instance; + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldRenderer = tessellator.getWorldRenderer(); - tessellator.startDrawing(GL_LINES); - tessellator.addVertex(x - size, y, 0); - tessellator.addVertex(x + size, y, 0); + worldRenderer.startDrawing(GL_LINES); + worldRenderer.addVertex(x - size, y, 0); + worldRenderer.addVertex(x + size, y, 0); tessellator.draw(); - tessellator.startDrawing(GL_LINES); - tessellator.addVertex(x, y - size, 0); - tessellator.addVertex(x, y + size, 0); + worldRenderer.startDrawing(GL_LINES); + worldRenderer.addVertex(x, y - size, 0); + worldRenderer.addVertex(x, y + size, 0); tessellator.draw(); - glDisable(GL_COLOR_LOGIC_OP); - glEnable(GL_TEXTURE_2D); + glDisableColorLogic(); + glEnableTexture2D(); } protected void drawRotText(FontRenderer fontRenderer, String text, int xPosition, int yPosition, int colour, boolean colourOrOp) { if (colourOrOp) { - glEnable(GL_COLOR_LOGIC_OP); + glEnableColorLogic(); glLogicOp(GL_OR_REVERSE); } @@ -537,8 +542,8 @@ protected void drawRotText(FontRenderer fontRenderer, String text, int xPosition if (colourOrOp) { - glDisable(GL_COLOR_LOGIC_OP); - glEnable(GL_TEXTURE_2D); + glDisableColorLogic(); + glEnableTexture2D(); } } @@ -579,12 +584,13 @@ protected void drawTooltip(FontRenderer fontRenderer, String tooltipText, int mo @SuppressWarnings("cast") public void drawTexturedModalRect(int x, int y, int x2, int y2, int u, int v, int u2, int v2) { - Tessellator tessellator = Tessellator.instance; - tessellator.startDrawingQuads(); - tessellator.addVertexWithUV(x, y2, this.zLevel, (float)(u) * texMapScale, (float)(v2) * texMapScale); - tessellator.addVertexWithUV(x2, y2, this.zLevel, (float)(u2) * texMapScale, (float)(v2) * texMapScale); - tessellator.addVertexWithUV(x2, y, this.zLevel, (float)(u2) * texMapScale, (float)(v) * texMapScale); - tessellator.addVertexWithUV(x, y, this.zLevel, (float)(u) * texMapScale, (float)(v) * texMapScale); + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + worldRenderer.startDrawingQuads(); + worldRenderer.addVertexWithUV(x, y2, this.zLevel, (float)(u) * texMapScale, (float)(v2) * texMapScale); + worldRenderer.addVertexWithUV(x2, y2, this.zLevel, (float)(u2) * texMapScale, (float)(v2) * texMapScale); + worldRenderer.addVertexWithUV(x2, y, this.zLevel, (float)(u2) * texMapScale, (float)(v) * texMapScale); + worldRenderer.addVertexWithUV(x, y, this.zLevel, (float)(u) * texMapScale, (float)(v) * texMapScale); tessellator.draw(); } @@ -602,12 +608,13 @@ public void drawTexturedModalRect(int x, int y, int x2, int y2, int u, int v, in */ public void drawTexturedModalRectF(int x, int y, int x2, int y2, float u, float v, float u2, float v2) { - Tessellator tessellator = Tessellator.instance; - tessellator.startDrawingQuads(); - tessellator.addVertexWithUV(x, y2, this.zLevel, u, v2); - tessellator.addVertexWithUV(x2, y2, this.zLevel, u2, v2); - tessellator.addVertexWithUV(x2, y, this.zLevel, u2, v); - tessellator.addVertexWithUV(x, y, this.zLevel, u, v); + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + worldRenderer.startDrawingQuads(); + worldRenderer.addVertexWithUV(x, y2, this.zLevel, u, v2); + worldRenderer.addVertexWithUV(x2, y2, this.zLevel, u2, v2); + worldRenderer.addVertexWithUV(x2, y, this.zLevel, u2, v); + worldRenderer.addVertexWithUV(x, y, this.zLevel, u, v); tessellator.draw(); } @@ -625,12 +632,13 @@ public void drawTexturedModalRectF(int x, int y, int x2, int y2, float u, float @SuppressWarnings("cast") public void drawTexturedModalRect(int x, int y, int u, int v, int width, int height, float texMapScale) { - Tessellator tessellator = Tessellator.instance; - tessellator.startDrawingQuads(); - tessellator.addVertexWithUV(x + 0, y + height, this.zLevel, (float)(u + 0) * texMapScale, (float)(v + height) * texMapScale); - tessellator.addVertexWithUV(x + width, y + height, this.zLevel, (float)(u + width) * texMapScale, (float)(v + height) * texMapScale); - tessellator.addVertexWithUV(x + width, y + 0, this.zLevel, (float)(u + width) * texMapScale, (float)(v + 0) * texMapScale); - tessellator.addVertexWithUV(x + 0, y + 0, this.zLevel, (float)(u + 0) * texMapScale, (float)(v + 0) * texMapScale); + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + worldRenderer.startDrawingQuads(); + worldRenderer.addVertexWithUV(x + 0, y + height, this.zLevel, (float)(u + 0) * texMapScale, (float)(v + height) * texMapScale); + worldRenderer.addVertexWithUV(x + width, y + height, this.zLevel, (float)(u + width) * texMapScale, (float)(v + height) * texMapScale); + worldRenderer.addVertexWithUV(x + width, y + 0, this.zLevel, (float)(u + width) * texMapScale, (float)(v + 0) * texMapScale); + worldRenderer.addVertexWithUV(x + 0, y + 0, this.zLevel, (float)(u + 0) * texMapScale, (float)(v + 0) * texMapScale); tessellator.draw(); } diff --git a/java/com/mumfrey/worldeditcui/render/LineColour.java b/java/com/mumfrey/worldeditcui/render/LineColour.java index da442cdc..e73a36da 100644 --- a/java/com/mumfrey/worldeditcui/render/LineColour.java +++ b/java/com/mumfrey/worldeditcui/render/LineColour.java @@ -3,7 +3,7 @@ import com.mumfrey.worldeditcui.config.Colour; import net.minecraft.client.resources.I18n; -import static org.lwjgl.opengl.GL11.*; +import static com.mumfrey.liteloader.gl.GL.*; /** * Stores colour data for each type of line. diff --git a/java/com/mumfrey/worldeditcui/render/LineInfo.java b/java/com/mumfrey/worldeditcui/render/LineInfo.java index 888875c8..0ff5e7d7 100644 --- a/java/com/mumfrey/worldeditcui/render/LineInfo.java +++ b/java/com/mumfrey/worldeditcui/render/LineInfo.java @@ -1,6 +1,6 @@ package com.mumfrey.worldeditcui.render; -import static org.lwjgl.opengl.GL11.*; +import static com.mumfrey.liteloader.gl.GL.*; /** * Stores data about a line that can be rendered diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java b/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java index 5e6367f1..e6e1914c 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java @@ -7,7 +7,8 @@ import com.mumfrey.worldeditcui.render.points.PointRectangle; import net.minecraft.client.renderer.Tessellator; -import static org.lwjgl.opengl.GL11.*; +import net.minecraft.client.renderer.WorldRenderer; +import static com.mumfrey.liteloader.gl.GL.*; /** * Draws the top and bottom rings of a polygon region @@ -33,24 +34,25 @@ public Render2DBox(LineColour colour, List points, int min, int public void render() { - Tessellator tess = Tessellator.instance; + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldRenderer = tessellator.getWorldRenderer(); double off = 0.03; for (LineInfo tempColour : this.colour.getColours()) { tempColour.prepareRender(); - tess.startDrawing(GL_LINES); + worldRenderer.startDrawing(GL_LINES); tempColour.prepareColour(); for (PointRectangle point : this.points) { if (point != null) { - tess.addVertex(point.getPoint().getX() + 0.5, this.min + off, point.getPoint().getY() + 0.5); - tess.addVertex(point.getPoint().getX() + 0.5, this.max + 1 + off, point.getPoint().getY() + 0.5); + worldRenderer.addVertex(point.getPoint().getX() + 0.5, this.min + off, point.getPoint().getY() + 0.5); + worldRenderer.addVertex(point.getPoint().getX() + 0.5, this.max + 1 + off, point.getPoint().getY() + 0.5); } } - tess.draw(); + tessellator.draw(); } } } diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java b/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java index c68c4113..05ffd12f 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java @@ -7,7 +7,8 @@ import com.mumfrey.worldeditcui.render.points.PointRectangle; import net.minecraft.client.renderer.Tessellator; -import static org.lwjgl.opengl.GL11.*; +import net.minecraft.client.renderer.WorldRenderer; +import static com.mumfrey.liteloader.gl.GL.*; /** * Draws the grid for a polygon region @@ -41,21 +42,22 @@ public void render() protected void drawPoly(double height) { - Tessellator tess = Tessellator.instance; + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldRenderer = tessellator.getWorldRenderer(); for (LineInfo tempColour : this.colour.getColours()) { tempColour.prepareRender(); - tess.startDrawing(GL_LINE_LOOP); + worldRenderer.startDrawing(GL_LINE_LOOP); tempColour.prepareColour(); for (PointRectangle point : this.points) { if (point != null) { - tess.addVertex(point.getPoint().getX() + 0.5, height, point.getPoint().getY() + 0.5); + worldRenderer.addVertex(point.getPoint().getX() + 0.5, height, point.getPoint().getY() + 0.5); } } - tess.draw(); + tessellator.draw(); } } } diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java index 20eea9ac..48c141bb 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java @@ -5,7 +5,8 @@ import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; -import static org.lwjgl.opengl.GL11.*; +import net.minecraft.client.renderer.WorldRenderer; +import static com.mumfrey.liteloader.gl.GL.*; /** * Draws a rectangular prism around 2 corners @@ -29,7 +30,8 @@ public Render3DBox(LineColour colour, Vector3 first, Vector3 second) public void render() { - Tessellator tess = Tessellator.instance; + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldRenderer = tessellator.getWorldRenderer(); double x1 = this.first.getX(); double y1 = this.first.getY(); double z1 = this.first.getZ(); @@ -42,40 +44,40 @@ public void render() tempColour.prepareRender(); // Draw bottom face - tess.startDrawing(GL_LINE_LOOP); + worldRenderer.startDrawing(GL_LINE_LOOP); tempColour.prepareColour(); - tess.addVertex(x1, y1, z1); - tess.addVertex(x2, y1, z1); - tess.addVertex(x2, y1, z2); - tess.addVertex(x1, y1, z2); - tess.draw(); + worldRenderer.addVertex(x1, y1, z1); + worldRenderer.addVertex(x2, y1, z1); + worldRenderer.addVertex(x2, y1, z2); + worldRenderer.addVertex(x1, y1, z2); + tessellator.draw(); // Draw top face - tess.startDrawing(GL_LINE_LOOP); + worldRenderer.startDrawing(GL_LINE_LOOP); tempColour.prepareColour(); - tess.addVertex(x1, y2, z1); - tess.addVertex(x2, y2, z1); - tess.addVertex(x2, y2, z2); - tess.addVertex(x1, y2, z2); - tess.draw(); + worldRenderer.addVertex(x1, y2, z1); + worldRenderer.addVertex(x2, y2, z1); + worldRenderer.addVertex(x2, y2, z2); + worldRenderer.addVertex(x1, y2, z2); + tessellator.draw(); // Draw join top and bottom faces - tess.startDrawing(GL_LINES); + worldRenderer.startDrawing(GL_LINES); tempColour.prepareColour(); - tess.addVertex(x1, y1, z1); - tess.addVertex(x1, y2, z1); + worldRenderer.addVertex(x1, y1, z1); + worldRenderer.addVertex(x1, y2, z1); - tess.addVertex(x2, y1, z1); - tess.addVertex(x2, y2, z1); + worldRenderer.addVertex(x2, y1, z1); + worldRenderer.addVertex(x2, y2, z1); - tess.addVertex(x2, y1, z2); - tess.addVertex(x2, y2, z2); + worldRenderer.addVertex(x2, y1, z2); + worldRenderer.addVertex(x2, y2, z2); - tess.addVertex(x1, y1, z2); - tess.addVertex(x1, y2, z2); + worldRenderer.addVertex(x1, y1, z2); + worldRenderer.addVertex(x1, y2, z2); - tess.draw(); + tessellator.draw(); } } } diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java index 6668c5a6..d0f4576e 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java @@ -5,7 +5,8 @@ import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; -import static org.lwjgl.opengl.GL11.*; +import net.minecraft.client.renderer.WorldRenderer; +import static com.mumfrey.liteloader.gl.GL.*; /** * Draws the grid for a region between @@ -29,7 +30,8 @@ public Render3DGrid(LineColour colour, Vector3 first, Vector3 second) public void render() { - Tessellator tess = Tessellator.instance; + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldRenderer = tessellator.getWorldRenderer(); double x1 = this.first.getX(); double y1 = this.first.getY(); double z1 = this.first.getZ(); @@ -41,7 +43,7 @@ public void render() { tempColour.prepareRender(); - tess.startDrawing(GL_LINES); + worldRenderer.startDrawing(GL_LINES); tempColour.prepareColour(); double x, y, z; @@ -55,8 +57,8 @@ public void render() { for (double yoff = 0; yoff + y <= y2; yoff += offsetSize) { - tess.addVertex(x1, y + yoff, z); - tess.addVertex(x2, y + yoff, z); + worldRenderer.addVertex(x1, y + yoff, z); + worldRenderer.addVertex(x2, y + yoff, z); } } @@ -66,8 +68,8 @@ public void render() { for (double yoff = 0; yoff + y <= y2; yoff += offsetSize) { - tess.addVertex(x1, y + yoff, z); - tess.addVertex(x2, y + yoff, z); + worldRenderer.addVertex(x1, y + yoff, z); + worldRenderer.addVertex(x2, y + yoff, z); } } @@ -77,8 +79,8 @@ public void render() { for (double yoff = 0; yoff + y <= y2; yoff += offsetSize) { - tess.addVertex(x, y + yoff, z1); - tess.addVertex(x, y + yoff, z2); + worldRenderer.addVertex(x, y + yoff, z1); + worldRenderer.addVertex(x, y + yoff, z2); } } @@ -88,8 +90,8 @@ public void render() { for (double yoff = 0; yoff + y <= y2; yoff += offsetSize) { - tess.addVertex(x, y + yoff, z1); - tess.addVertex(x, y + yoff, z2); + worldRenderer.addVertex(x, y + yoff, z1); + worldRenderer.addVertex(x, y + yoff, z2); } } @@ -100,8 +102,8 @@ public void render() { for (double xoff = 0; xoff + x <= x2; xoff += offsetSize) { - tess.addVertex(x + xoff, y1, z); - tess.addVertex(x + xoff, y2, z); + worldRenderer.addVertex(x + xoff, y1, z); + worldRenderer.addVertex(x + xoff, y2, z); } } // Zmax XY plane, x axis @@ -110,8 +112,8 @@ public void render() { for (double xoff = 0; xoff + x <= x2; xoff += offsetSize) { - tess.addVertex(x + xoff, y1, z); - tess.addVertex(x + xoff, y2, z); + worldRenderer.addVertex(x + xoff, y1, z); + worldRenderer.addVertex(x + xoff, y2, z); } } // Ymin XZ plane, x axis @@ -120,8 +122,8 @@ public void render() { for (double xoff = 0; xoff + x <= x2; xoff += offsetSize) { - tess.addVertex(x + xoff, y, z1); - tess.addVertex(x + xoff, y, z2); + worldRenderer.addVertex(x + xoff, y, z1); + worldRenderer.addVertex(x + xoff, y, z2); } } // Ymax XZ plane, x axis @@ -130,8 +132,8 @@ public void render() { for (double xoff = 0; xoff + x <= x2; xoff += offsetSize) { - tess.addVertex(x + xoff, y, z1); - tess.addVertex(x + xoff, y, z2); + worldRenderer.addVertex(x + xoff, y, z1); + worldRenderer.addVertex(x + xoff, y, z2); } } @@ -142,8 +144,8 @@ public void render() { for (double zoff = 0; zoff + z <= z2; zoff += offsetSize) { - tess.addVertex(x1, y, z + zoff); - tess.addVertex(x2, y, z + zoff); + worldRenderer.addVertex(x1, y, z + zoff); + worldRenderer.addVertex(x2, y, z + zoff); } } // Ymax XZ plane, z axis @@ -152,8 +154,8 @@ public void render() { for (double zoff = 0; zoff + z <= z2; zoff += offsetSize) { - tess.addVertex(x1, y, z + zoff); - tess.addVertex(x2, y, z + zoff); + worldRenderer.addVertex(x1, y, z + zoff); + worldRenderer.addVertex(x2, y, z + zoff); } } // Xmin YZ plane, z axis @@ -162,8 +164,8 @@ public void render() { for (double zoff = 0; zoff + z <= z2; zoff += offsetSize) { - tess.addVertex(x, y1, z + zoff); - tess.addVertex(x, y2, z + zoff); + worldRenderer.addVertex(x, y1, z + zoff); + worldRenderer.addVertex(x, y2, z + zoff); } } // Xmax YZ plane, z axis @@ -172,12 +174,12 @@ public void render() { for (double zoff = 0; zoff + z <= z2; zoff += offsetSize) { - tess.addVertex(x, y1, z + zoff); - tess.addVertex(x, y2, z + zoff); + worldRenderer.addVertex(x, y1, z + zoff); + worldRenderer.addVertex(x, y2, z + zoff); } } - tess.draw(); + tessellator.draw(); } } } diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java index 7d7d3963..e6fd42af 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java @@ -5,7 +5,8 @@ import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; -import static org.lwjgl.opengl.GL11.*; +import net.minecraft.client.renderer.WorldRenderer; +import static com.mumfrey.liteloader.gl.GL.*; /** * Draws a polygon @@ -27,19 +28,20 @@ public Render3DPolygon(LineColour colour, Vector3... vertices) public void render() { - Tessellator tess = Tessellator.instance; + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldRenderer = tessellator.getWorldRenderer(); for (LineInfo tempColour : this.colour.getColours()) { tempColour.prepareRender(); - tess.startDrawing(GL_LINE_LOOP); + worldRenderer.startDrawing(GL_LINE_LOOP); tempColour.prepareColour(); for (Vector3 vertex : this.vertices) { - tess.addVertex(vertex.getX(), vertex.getY(), vertex.getZ()); + worldRenderer.addVertex(vertex.getX(), vertex.getY(), vertex.getZ()); } - tess.draw(); + tessellator.draw(); } } } diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java index 6f222671..67d37adf 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java @@ -5,7 +5,8 @@ import com.mumfrey.worldeditcui.render.points.PointCube; import net.minecraft.client.renderer.Tessellator; -import static org.lwjgl.opengl.GL11.*; +import net.minecraft.client.renderer.WorldRenderer; +import static com.mumfrey.liteloader.gl.GL.*; /** * Draws the top and bottom circles around a cylindrical region @@ -36,7 +37,9 @@ public RenderCylinderBox(LineColour colour, PointCube center, double radX, doubl public void render() { - Tessellator tess = Tessellator.instance; + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + for (LineInfo tempColour : this.colour.getColours()) { tempColour.prepareRender(); @@ -44,7 +47,7 @@ public void render() double twoPi = Math.PI * 2; for (int yBlock : new int[] { this.minY, this.maxY + 1 }) { - tess.startDrawing(GL_LINE_LOOP); + worldRenderer.startDrawing(GL_LINE_LOOP); tempColour.prepareColour(); for (int i = 0; i <= 75; i++) @@ -53,9 +56,9 @@ public void render() double tempX = this.radX * Math.cos(tempTheta); double tempZ = this.radZ * Math.sin(tempTheta); - tess.addVertex(this.centerX + tempX, yBlock, this.centerZ + tempZ); + worldRenderer.addVertex(this.centerX + tempX, yBlock, this.centerZ + tempZ); } - tess.draw(); + tessellator.draw(); } } } diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java index 3aeca6ca..1320d6fa 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java @@ -5,7 +5,8 @@ import com.mumfrey.worldeditcui.render.points.PointCube; import net.minecraft.client.renderer.Tessellator; -import static org.lwjgl.opengl.GL11.*; +import net.minecraft.client.renderer.WorldRenderer; +import static com.mumfrey.liteloader.gl.GL.*; /** * Draws the circles around a cylindrical region @@ -36,7 +37,9 @@ public RenderCylinderCircles(LineColour colour, PointCube center, double radX, d public void render() { - Tessellator tess = Tessellator.instance; + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + for (LineInfo tempColour : this.colour.getColours()) { tempColour.prepareRender(); @@ -44,7 +47,7 @@ public void render() double twoPi = Math.PI * 2; for (int yBlock = this.minY + 1; yBlock <= this.maxY; yBlock++) { - tess.startDrawing(GL_LINE_LOOP); + worldRenderer.startDrawing(GL_LINE_LOOP); tempColour.prepareColour(); for (int i = 0; i <= 75; i++) @@ -53,9 +56,9 @@ public void render() double tempX = this.radX * Math.cos(tempTheta); double tempZ = this.radZ * Math.sin(tempTheta); - tess.addVertex(this.centerX + tempX, yBlock, this.centerZ + tempZ); + worldRenderer.addVertex(this.centerX + tempX, yBlock, this.centerZ + tempZ); } - tess.draw(); + tessellator.draw(); } } } diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java index de34a0da..e0c9c937 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java @@ -5,7 +5,8 @@ import com.mumfrey.worldeditcui.render.points.PointCube; import net.minecraft.client.renderer.Tessellator; -import static org.lwjgl.opengl.GL11.*; +import net.minecraft.client.renderer.WorldRenderer; +import static com.mumfrey.liteloader.gl.GL.*; /** * Draws the grid lines around a cylindrical region @@ -36,7 +37,9 @@ public RenderCylinderGrid(LineColour colour, PointCube center, double radX, doub public void render() { - Tessellator tess = Tessellator.instance; + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + for (LineInfo tempColour : this.colour.getColours()) { tempColour.prepareRender(); @@ -51,29 +54,29 @@ public void render() for (double tempX = negRadiusX; tempX <= posRadiusX; ++tempX) { double tempZ = this.radZ * Math.cos(Math.asin(tempX / this.radX)); - tess.startDrawing(GL_LINE_LOOP); + worldRenderer.startDrawing(GL_LINE_LOOP); tempColour.prepareColour(); - tess.addVertex(this.centerX + tempX, tmaxY, this.centerZ + tempZ); - tess.addVertex(this.centerX + tempX, tmaxY, this.centerZ - tempZ); - tess.addVertex(this.centerX + tempX, tminY, this.centerZ - tempZ); - tess.addVertex(this.centerX + tempX, tminY, this.centerZ + tempZ); + worldRenderer.addVertex(this.centerX + tempX, tmaxY, this.centerZ + tempZ); + worldRenderer.addVertex(this.centerX + tempX, tmaxY, this.centerZ - tempZ); + worldRenderer.addVertex(this.centerX + tempX, tminY, this.centerZ - tempZ); + worldRenderer.addVertex(this.centerX + tempX, tminY, this.centerZ + tempZ); - tess.draw(); + tessellator.draw(); } for (double tempZ = negRadiusZ; tempZ <= posRadiusZ; ++tempZ) { double tempX = this.radX * Math.sin(Math.acos(tempZ / this.radZ)); - tess.startDrawing(GL_LINE_LOOP); + worldRenderer.startDrawing(GL_LINE_LOOP); tempColour.prepareColour(); - tess.addVertex(this.centerX + tempX, tmaxY, this.centerZ + tempZ); - tess.addVertex(this.centerX - tempX, tmaxY, this.centerZ + tempZ); - tess.addVertex(this.centerX - tempX, tminY, this.centerZ + tempZ); - tess.addVertex(this.centerX + tempX, tminY, this.centerZ + tempZ); + worldRenderer.addVertex(this.centerX + tempX, tmaxY, this.centerZ + tempZ); + worldRenderer.addVertex(this.centerX - tempX, tmaxY, this.centerZ + tempZ); + worldRenderer.addVertex(this.centerX - tempX, tminY, this.centerZ + tempZ); + worldRenderer.addVertex(this.centerX + tempX, tminY, this.centerZ + tempZ); - tess.draw(); + tessellator.draw(); } } } diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java index 59586a08..ccf31992 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java @@ -6,7 +6,8 @@ import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; -import static org.lwjgl.opengl.GL11.*; +import net.minecraft.client.renderer.WorldRenderer; +import static com.mumfrey.liteloader.gl.GL.*; /** * Draws an ellipsoid shape around a center point. @@ -47,11 +48,13 @@ public void render() protected void drawXZPlane(LineInfo colour) { - Tessellator tess = Tessellator.instance; + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + int yRad = (int)Math.floor(this.radii.getY()); for (int yBlock = -yRad; yBlock < yRad; yBlock++) { - tess.startDrawing(GL_LINE_LOOP); + worldRenderer.startDrawing(GL_LINE_LOOP); colour.prepareColour(); for (int i = 0; i <= 40; i++) @@ -60,12 +63,12 @@ protected void drawXZPlane(LineInfo colour) double tempX = this.radii.getX() * Math.cos(tempTheta) * Math.cos(Math.asin(yBlock / this.radii.getY())); double tempZ = this.radii.getZ() * Math.sin(tempTheta) * Math.cos(Math.asin(yBlock / this.radii.getY())); - tess.addVertex(this.centerX + tempX, this.centerY + yBlock, this.centerZ + tempZ); + worldRenderer.addVertex(this.centerX + tempX, this.centerY + yBlock, this.centerZ + tempZ); } - tess.draw(); + tessellator.draw(); } - tess.startDrawing(GL_LINE_LOOP); + worldRenderer.startDrawing(GL_LINE_LOOP); colour.prepareColour(); for (int i = 0; i <= 40; i++) @@ -74,18 +77,20 @@ protected void drawXZPlane(LineInfo colour) double tempX = this.radii.getX() * Math.cos(tempTheta); double tempZ = this.radii.getZ() * Math.sin(tempTheta); - tess.addVertex(this.centerX + tempX, this.centerY, this.centerZ + tempZ); + worldRenderer.addVertex(this.centerX + tempX, this.centerY, this.centerZ + tempZ); } - tess.draw(); + tessellator.draw(); } protected void drawYZPlane(LineInfo colour) { - Tessellator tess = Tessellator.instance; + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + int xRad = (int)Math.floor(this.radii.getX()); for (int xBlock = -xRad; xBlock < xRad; xBlock++) { - tess.startDrawing(GL_LINE_LOOP); + worldRenderer.startDrawing(GL_LINE_LOOP); colour.prepareColour(); for (int i = 0; i <= 40; i++) @@ -94,12 +99,12 @@ protected void drawYZPlane(LineInfo colour) double tempY = this.radii.getY() * Math.cos(tempTheta) * Math.sin(Math.acos(xBlock / this.radii.getX())); double tempZ = this.radii.getZ() * Math.sin(tempTheta) * Math.sin(Math.acos(xBlock / this.radii.getX())); - tess.addVertex(this.centerX + xBlock, this.centerY + tempY, this.centerZ + tempZ); + worldRenderer.addVertex(this.centerX + xBlock, this.centerY + tempY, this.centerZ + tempZ); } - tess.draw(); + tessellator.draw(); } - tess.startDrawing(GL_LINE_LOOP); + worldRenderer.startDrawing(GL_LINE_LOOP); colour.prepareColour(); for (int i = 0; i <= 40; i++) @@ -108,18 +113,20 @@ protected void drawYZPlane(LineInfo colour) double tempY = this.radii.getY() * Math.cos(tempTheta); double tempZ = this.radii.getZ() * Math.sin(tempTheta); - tess.addVertex(this.centerX, this.centerY + tempY, this.centerZ + tempZ); + worldRenderer.addVertex(this.centerX, this.centerY + tempY, this.centerZ + tempZ); } - tess.draw(); + tessellator.draw(); } protected void drawXYPlane(LineInfo colour) { - Tessellator tess = Tessellator.instance; + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + int zRad = (int)Math.floor(this.radii.getZ()); for (int zBlock = -zRad; zBlock < zRad; zBlock++) { - tess.startDrawing(GL_LINE_LOOP); + worldRenderer.startDrawing(GL_LINE_LOOP); colour.prepareColour(); for (int i = 0; i <= 40; i++) @@ -128,12 +135,12 @@ protected void drawXYPlane(LineInfo colour) double tempX = this.radii.getX() * Math.sin(tempTheta) * Math.sin(Math.acos(zBlock / this.radii.getZ())); double tempY = this.radii.getY() * Math.cos(tempTheta) * Math.sin(Math.acos(zBlock / this.radii.getZ())); - tess.addVertex(this.centerX + tempX, this.centerY + tempY, this.centerZ + zBlock); + worldRenderer.addVertex(this.centerX + tempX, this.centerY + tempY, this.centerZ + zBlock); } - tess.draw(); + tessellator.draw(); } - tess.startDrawing(GL_LINE_LOOP); + worldRenderer.startDrawing(GL_LINE_LOOP); colour.prepareColour(); for (int i = 0; i <= 40; i++) @@ -142,8 +149,8 @@ protected void drawXYPlane(LineInfo colour) double tempX = this.radii.getX() * Math.cos(tempTheta); double tempY = this.radii.getY() * Math.sin(tempTheta); - tess.addVertex(this.centerX + tempX, this.centerY + tempY, this.centerZ); + worldRenderer.addVertex(this.centerX + tempX, this.centerY + tempY, this.centerZ); } - tess.draw(); + tessellator.draw(); } } diff --git a/res/assets/wecui/lang/en_US.lang b/res/assets/wecui/lang/en_US.lang index 4d61571a..4bddd8f1 100644 --- a/res/assets/wecui/lang/en_US.lang +++ b/res/assets/wecui/lang/en_US.lang @@ -18,3 +18,8 @@ colour.ellipsoidpoint=Ellipsoid Centre Point Colour colour.cylindergrid=Cylinder Grid Colour colour.cylinderedge=Cylinder Edge Colour colour.cylinderpoint=Cylinder Centre Point Colour + +gui.options.compat.title=Compatibility Options +gui.options.compat.spammy=Promiscuous Mode (send /we cui all the time) +gui.options.colours.title=Display Colours + From d2a69fe899245c3ba24b181c6a6d084b461c2a55 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Sun, 14 Dec 2014 23:19:27 +0000 Subject: [PATCH 16/51] Send the handshake in the right format --- build/build_wecui.xml | 6 +++--- build/buildnumber.txt | 4 ++-- java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/build/build_wecui.xml b/build/build_wecui.xml index 3a19a6e5..27535b6e 100644 --- a/build/build_wecui.xml +++ b/build/build_wecui.xml @@ -4,9 +4,9 @@ - - - + + + diff --git a/build/buildnumber.txt b/build/buildnumber.txt index f47b007a..011b048f 100644 --- a/build/buildnumber.txt +++ b/build/buildnumber.txt @@ -1,3 +1,3 @@ #Build Number for ANT. Do not edit! -#Sun Jul 06 01:04:36 BST 2014 -build.number=1728 +#Sun Dec 14 19:33:22 GMT 2014 +build.number=1801 diff --git a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java index 71a5e38f..fcd5cc74 100644 --- a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java @@ -92,7 +92,8 @@ public void onJoinGame(INetHandler netHandler, S01PacketJoinGame loginPacket, Se private void helo() { PacketBuffer buffer = new PacketBuffer(Unpooled.buffer()); - buffer.writeString("v|" + WorldEditCUI.PROTOCOL_VERSION); + String message = "v|" + WorldEditCUI.PROTOCOL_VERSION; + buffer.writeBytes(message.getBytes(Charsets.UTF_8)); ClientPluginChannels.sendMessage(CHANNEL_WECUI, buffer, ChannelPolicy.DISPATCH_ALWAYS); } @@ -180,7 +181,7 @@ public String getName() @Override public String getVersion() { - return "1.8.0_00"; + return "1.8.0_01"; } @Override From 69f236ebcf8ee39b6d051332c675fcbfa92ba972 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Thu, 5 Feb 2015 11:50:55 +0000 Subject: [PATCH 17/51] Fix jitter at high coords and better rendering of large grids, closes #5 --- build/build_wecui.xml | 2 +- .../worldeditcui/LiteModWorldEditCUI.java | 31 +- .../worldeditcui/config/CUIConfiguration.java | 12 +- .../listeners/CUIListenerWorldRender.java | 76 +- .../worldeditcui/gui/CUIConfigPanel.java | 15 +- .../worldeditcui/render/LineColour.java | 2 +- .../worldeditcui/render/points/PointCube.java | 34 +- .../render/points/PointRectangle.java | 5 +- .../render/region/BaseRegion.java | 3 +- .../render/region/CuboidRegion.java | 29 +- .../render/region/CylinderRegion.java | 47 +- .../render/region/EllipsoidRegion.java | 32 +- .../render/region/PolygonRegion.java | 26 +- .../render/region/PolyhedronRegion.java | 23 +- .../render/shapes/Render2DBox.java | 13 +- .../render/shapes/Render2DGrid.java | 13 +- .../render/shapes/Render3DBox.java | 14 +- .../render/shapes/Render3DGrid.java | 173 +-- .../render/shapes/Render3DPolygon.java | 4 +- .../render/shapes/RenderCylinderBox.java | 18 +- .../render/shapes/RenderCylinderCircles.java | 18 +- .../render/shapes/RenderCylinderGrid.java | 32 +- .../render/shapes/RenderEllipsoid.java | 35 +- .../mumfrey/worldeditcui/util/Vector2.java | 1228 ++++++++-------- .../mumfrey/worldeditcui/util/Vector2m.java | 292 ++-- .../mumfrey/worldeditcui/util/Vector3.java | 1295 +++++++++-------- .../mumfrey/worldeditcui/util/Vector3m.java | 370 ++--- res/assets/wecui/lang/en_US.lang | 1 + 28 files changed, 1942 insertions(+), 1901 deletions(-) diff --git a/build/build_wecui.xml b/build/build_wecui.xml index 27535b6e..78b91143 100644 --- a/build/build_wecui.xml +++ b/build/build_wecui.xml @@ -4,7 +4,7 @@ - + diff --git a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java index fcd5cc74..3451d03d 100644 --- a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java @@ -28,6 +28,7 @@ import com.mumfrey.liteloader.core.LiteLoader; import com.mumfrey.liteloader.core.PluginChannels.ChannelPolicy; import com.mumfrey.liteloader.modconfig.ConfigPanel; +import com.mumfrey.worldeditcui.config.CUIConfiguration; import com.mumfrey.worldeditcui.event.listeners.CUIListenerChannel; import com.mumfrey.worldeditcui.event.listeners.CUIListenerWorldRender; import com.mumfrey.worldeditcui.gui.CUIConfigPanel; @@ -47,6 +48,7 @@ public class LiteModWorldEditCUI implements InitCompleteListener, PluginChannelL private KeyBinding keyBindClearSel = new KeyBinding("wecui.keys.clear", Keyboard.KEY_NONE, "wecui.keys.category"); private boolean visible = true; + private boolean alwaysOnTop = false; private CUIListenerWorldRender worldRenderListener; private CUIListenerChannel channelListener; @@ -130,7 +132,15 @@ public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clo { if (this.keyBindToggleUI.isPressed()) { - this.visible = !this.visible; + if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) + { + CUIConfiguration config = this.controller.getConfiguration(); + config.setAlwaysOnTop(!config.isAlwaysOnTop()); + } + else + { + this.visible = !this.visible; + } } if (this.keyBindClearSel.isPressed()) @@ -142,6 +152,9 @@ public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clo if (inGame && clock && this.controller != null) { + CUIConfiguration config = this.controller.getConfiguration(); + this.alwaysOnTop = config.isAlwaysOnTop(); + if (mc.theWorld != this.lastWorld || mc.thePlayer != this.lastPlayer) { this.lastWorld = mc.theWorld; @@ -151,7 +164,7 @@ public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clo this.controller.setSelection(new CuboidRegion(this.controller)); this.helo(); this.delayedHelo = LiteModWorldEditCUI.DELAYED_HELO_TICKS; - if (mc.thePlayer != null && this.controller.getConfiguration().isPromiscuous()) + if (mc.thePlayer != null && config.isPromiscuous()) { mc.thePlayer.sendChatMessage("/we cui"); //Tricks WE to send the current selection } @@ -181,7 +194,7 @@ public String getName() @Override public String getVersion() { - return "1.8.0_01"; + return "1.8.0_02"; } @Override @@ -193,18 +206,18 @@ public Class getConfigPanelClass() @Override public void onPostRenderEntities(float partialTicks) { + if (this.visible && !this.alwaysOnTop) + { + this.worldRenderListener.onRender(partialTicks); + } } @Override public void onPostRender(float partialTicks) { - if (this.visible) + if (this.visible && this.alwaysOnTop) { - try - { - this.worldRenderListener.onRender(partialTicks); - } - catch (Exception ex) {} + this.worldRenderListener.onRender(partialTicks); } } diff --git a/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java b/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java index 2560c7b1..732f77b3 100644 --- a/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java +++ b/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java @@ -25,8 +25,8 @@ public class CUIConfiguration implements InitializationFactory private boolean debugMode = false; private boolean ignoreUpdates = false; - private boolean promiscuous = false; + private boolean alwaysOnTop = false; private Colour cuboidGridColor = new Colour("#CC3333CC"); private Colour cuboidEdgeColor = new Colour("#CC4C4CCC"); @@ -97,6 +97,16 @@ public void setPromiscuous(boolean promiscuous) this.promiscuous = promiscuous; } + public boolean isAlwaysOnTop() + { + return this.alwaysOnTop; + } + + public void setAlwaysOnTop(boolean alwaysOnTop) + { + this.alwaysOnTop = alwaysOnTop; + } + public static CUIConfiguration create() { File jsonFile = new File(LiteLoader.getCommonConfigFolder(), CUIConfiguration.CONFIG_FILE_NAME); diff --git a/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerWorldRender.java b/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerWorldRender.java index 44fe28cb..1cbc477a 100644 --- a/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerWorldRender.java +++ b/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerWorldRender.java @@ -2,11 +2,11 @@ import static com.mumfrey.liteloader.gl.GL.*; import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; import com.mumfrey.worldeditcui.WorldEditCUI; +import com.mumfrey.worldeditcui.util.Vector3; /** * Listener for WorldRenderEvent @@ -29,54 +29,44 @@ public CUIListenerWorldRender(WorldEditCUI controller, Minecraft minecraft) public void onRender(float partialTicks) { - RenderHelper.disableStandardItemLighting(); - OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnableBlend(); - glEnableAlphaTest(); - glAlphaFunc(GL_GREATER, 0.0F); - glDisableTexture2D(); - glDepthMask(false); - glPushMatrix(); - try { - EntityPlayerSP thePlayer = this.minecraft.thePlayer; - glTranslated(-this.getPlayerXGuess(thePlayer, partialTicks), -this.getPlayerYGuess(thePlayer, partialTicks), -this.getPlayerZGuess(thePlayer, partialTicks)); - glColor3f(1.0f, 1.0f, 1.0f); - if (this.controller.getSelection() != null) + RenderHelper.disableStandardItemLighting(); + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnableBlend(); + glEnableAlphaTest(); + glAlphaFunc(GL_GREATER, 0.0F); + glDisableTexture2D(); + glEnableDepthTest(); + glDepthMask(false); + glPushMatrix(); + glDisableFog(); + + try { - this.controller.getSelection().render(); + Vector3 cameraPos = new Vector3(this.minecraft.getRenderViewEntity(), partialTicks); + glColor4f(1.0F, 1.0F, 1.0F, 0.5F); + if (this.controller.getSelection() != null) + { + this.controller.getSelection().render(cameraPos); + } } + catch (Exception e) + { + } + + glDepthFunc(GL_LEQUAL); + glPopMatrix(); + + glDepthMask(true); + glEnableTexture2D(); + glDisableBlend(); + glAlphaFunc(GL_GREATER, 0.1F); } - catch (Exception e) - { - } - - glDepthFunc(GL_LEQUAL); - glPopMatrix(); - - glDepthMask(true); - glEnableTexture2D(); - glDisableBlend(); - glAlphaFunc(GL_GREATER, 0.1F); + catch (Exception ex) {} RenderHelper.enableStandardItemLighting(); } - - private double getPlayerXGuess(EntityPlayerSP thePlayer, float renderTick) - { - return thePlayer.prevPosX + ((thePlayer.posX - thePlayer.prevPosX) * renderTick); - } - - private double getPlayerYGuess(EntityPlayerSP thePlayer, float renderTick) - { - return thePlayer.prevPosY + ((thePlayer.posY - thePlayer.prevPosY) * renderTick); - } - - private double getPlayerZGuess(EntityPlayerSP thePlayer, float renderTick) - { - return thePlayer.prevPosZ + ((thePlayer.posZ - thePlayer.prevPosZ) * renderTick); - } } diff --git a/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java b/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java index 343183e9..79fb7e02 100644 --- a/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java +++ b/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java @@ -23,6 +23,7 @@ public class CUIConfigPanel extends Gui implements ConfigPanel { private static final int CONTROL_SPACING = 24; + private static final int CONTROL_TOP = 80; private Minecraft mc; @@ -34,7 +35,7 @@ public class CUIConfigPanel extends Gui implements ConfigPanel private GuiButton activeControl; - private GuiCheckbox chkPromiscuous; + private GuiCheckbox chkPromiscuous, chkAlwaysOnTop; public CUIConfigPanel() { @@ -50,7 +51,7 @@ public String getPanelTitle() @Override public int getContentHeight() { - return LineColour.values().length * CUIConfigPanel.CONTROL_SPACING; + return LineColour.values().length * CUIConfigPanel.CONTROL_SPACING + CUIConfigPanel.CONTROL_TOP; } @Override @@ -63,7 +64,7 @@ public void onPanelShown(ConfigPanelHost host) this.controlList.clear(); int nextId = 0; - int top = 64; + int top = CUIConfigPanel.CONTROL_TOP; for (LineColour colour : LineColour.values()) { @@ -73,12 +74,17 @@ public void onPanelShown(ConfigPanelHost host) } this.controlList.add(this.chkPromiscuous = new GuiCheckbox(nextId, 24, 26, I18n.format("gui.options.compat.spammy"))); + this.controlList.add(this.chkAlwaysOnTop = new GuiCheckbox(nextId, 24, 42, I18n.format("gui.options.compat.ontop"))); for (GuiButton control : this.controlList) { if (control instanceof GuiColourButton) this.colourButtonList.add((GuiColourButton)control); } + + CUIConfiguration config = this.mod.getController().getConfiguration(); + this.chkPromiscuous.checked = config.isPromiscuous(); + this.chkAlwaysOnTop.checked = config.isAlwaysOnTop(); } @Override @@ -96,6 +102,7 @@ public void onPanelHidden() CUIConfiguration config = this.mod.getController().getConfiguration(); config.setPromiscuous(this.chkPromiscuous.checked); + config.setAlwaysOnTop(this.chkAlwaysOnTop.checked); config.save(); } @@ -108,7 +115,7 @@ public void onTick(ConfigPanelHost host) public void drawPanel(ConfigPanelHost host, int mouseX, int mouseY, float partialTicks) { this.drawString(this.mc.fontRendererObj, I18n.format("gui.options.compat.title"), 10, 10, 0xFFFFFF55); - this.drawString(this.mc.fontRendererObj, I18n.format("gui.options.colours.title"), 10, 48, 0xFFFFFF55); + this.drawString(this.mc.fontRendererObj, I18n.format("gui.options.colours.title"), 10, 64, 0xFFFFFF55); for (GuiButton control : this.controlList) { diff --git a/java/com/mumfrey/worldeditcui/render/LineColour.java b/java/com/mumfrey/worldeditcui/render/LineColour.java index e73a36da..ccd7c3bf 100644 --- a/java/com/mumfrey/worldeditcui/render/LineColour.java +++ b/java/com/mumfrey/worldeditcui/render/LineColour.java @@ -80,7 +80,7 @@ public void setColour(Colour colour) public void updateColour() { this.normal = new LineInfo(3.0f, this.colour.red(), this.colour.green(), this.colour.blue(), this.colour.alpha(), GL_LESS); - this.hidden = new LineInfo(3.0f, this.colour.red(), this.colour.green(), this.colour.blue(), this.colour.alpha() * 0.25F, GL_GEQUAL); + this.hidden = new LineInfo(3.0f, this.colour.red() * 0.75F, this.colour.green() * 0.75F, this.colour.blue() * 0.75F, this.colour.alpha() * 0.25F, GL_GEQUAL); } public void setDefaultColour() diff --git a/java/com/mumfrey/worldeditcui/render/points/PointCube.java b/java/com/mumfrey/worldeditcui/render/points/PointCube.java index ac2a38cb..d68b9da6 100644 --- a/java/com/mumfrey/worldeditcui/render/points/PointCube.java +++ b/java/com/mumfrey/worldeditcui/render/points/PointCube.java @@ -15,32 +15,29 @@ */ public class PointCube { + private static final double OFF = 0.03f; + private static final Vector3 MIN_VEC = new Vector3(PointCube.OFF, PointCube.OFF, PointCube.OFF); + private static final Vector3 MAX_VEC = new Vector3(PointCube.OFF + 1, PointCube.OFF + 1, PointCube.OFF + 1); + protected Vector3 point; protected LineColour colour = LineColour.CUBOIDPOINT1; - public PointCube(Vector3 point) - { - this.point = point; - } + private Render3DBox box; - public PointCube(int x, int y, int z) + public PointCube(double x, double y, double z) { - this.point = new Vector3(x, y, z); + this(new Vector3(x, y, z)); } - public PointCube(double x, double y, double z) + public PointCube(Vector3 point) { - this.point = new Vector3(x, y, z); + this.setPoint(point); } - public void render() + public void render(Vector3 cameraPos) { - double off = 0.03f; - Vector3 minVec = new Vector3(off, off, off); - Vector3 maxVec = new Vector3(off + 1, off + 1, off + 1); - - new Render3DBox(this.colour, this.point.subtract(minVec), this.point.add(maxVec)).render(); + this.box.render(cameraPos); } public Vector3 getPoint() @@ -51,8 +48,9 @@ public Vector3 getPoint() public void setPoint(Vector3 point) { this.point = point; + this.update(); } - + public LineColour getColour() { return this.colour; @@ -61,5 +59,11 @@ public LineColour getColour() public void setColour(LineColour colour) { this.colour = colour; + this.update(); + } + + private void update() + { + this.box = new Render3DBox(this.colour, this.point.subtract(MIN_VEC), this.point.add(MAX_VEC)); } } diff --git a/java/com/mumfrey/worldeditcui/render/points/PointRectangle.java b/java/com/mumfrey/worldeditcui/render/points/PointRectangle.java index be576c33..6d4147fc 100644 --- a/java/com/mumfrey/worldeditcui/render/points/PointRectangle.java +++ b/java/com/mumfrey/worldeditcui/render/points/PointRectangle.java @@ -3,6 +3,7 @@ import com.mumfrey.worldeditcui.render.LineColour; import com.mumfrey.worldeditcui.render.shapes.Render3DBox; import com.mumfrey.worldeditcui.util.Vector2; +import com.mumfrey.worldeditcui.util.Vector3; /** * Stores data about a prism surrounding two @@ -29,13 +30,13 @@ public PointRectangle(int x, int z) this.point = new Vector2(x, z); } - public void render(int min, int max) + public void render(Vector3 cameraPos, int min, int max) { float off = 0.03f; Vector2 minVec = new Vector2(off, off); Vector2 maxVec = new Vector2(off + 1, off + 1); - new Render3DBox(this.colour, this.point.subtract(minVec).toVector3(min - off), this.point.add(maxVec).toVector3(max + 1 + off)).render(); + new Render3DBox(this.colour, this.point.subtract(minVec).toVector3(min - off), this.point.add(maxVec).toVector3(max + 1 + off)).render(cameraPos); } public Vector2 getPoint() diff --git a/java/com/mumfrey/worldeditcui/render/region/BaseRegion.java b/java/com/mumfrey/worldeditcui/render/region/BaseRegion.java index 9234927e..7a5d5600 100644 --- a/java/com/mumfrey/worldeditcui/render/region/BaseRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/BaseRegion.java @@ -3,6 +3,7 @@ import com.mumfrey.worldeditcui.InitializationFactory; import com.mumfrey.worldeditcui.WorldEditCUI; import com.mumfrey.worldeditcui.exceptions.InvalidSelectionTypeException; +import com.mumfrey.worldeditcui.util.Vector3; /** * Base region storage class. Provides @@ -27,7 +28,7 @@ public void initialize() { } - public abstract void render(); + public abstract void render(Vector3 cameraPos); public void setCuboidPoint(int id, double x, double y, double z) { diff --git a/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java b/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java index e3a347a6..2c969ce3 100644 --- a/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java @@ -16,36 +16,34 @@ */ public class CuboidRegion extends BaseRegion { - protected PointCube firstPoint; protected PointCube secondPoint; + private Render3DGrid grid; + private Render3DBox box; + public CuboidRegion(WorldEditCUI controller) { super(controller); } @Override - public void render() + public void render(Vector3 cameraPos) { if (this.firstPoint != null && this.secondPoint != null) { - - Vector3[] bounds = this.calcBounds(); - new Render3DGrid(LineColour.CUBOIDGRID, bounds[0], bounds[1]).render(); - new Render3DBox(LineColour.CUBOIDBOX, bounds[0], bounds[1]).render(); - - this.firstPoint.render(); - this.secondPoint.render(); - + this.grid.render(cameraPos); + this.box.render(cameraPos); + this.firstPoint.render(cameraPos); + this.secondPoint.render(cameraPos); } else if (this.firstPoint != null) { - this.firstPoint.render(); + this.firstPoint.render(cameraPos); } else if (this.secondPoint != null) { - this.secondPoint.render(); + this.secondPoint.render(cameraPos); } } @@ -62,6 +60,13 @@ else if (id == 1) this.secondPoint = new PointCube(x, y, z); this.secondPoint.setColour(LineColour.CUBOIDPOINT2); } + + if (this.firstPoint != null && this.secondPoint != null) + { + Vector3[] bounds = this.calcBounds(); + this.grid = new Render3DGrid(LineColour.CUBOIDGRID, bounds[0], bounds[1]); + this.box = new Render3DBox(LineColour.CUBOIDBOX, bounds[0], bounds[1]); + } } /** diff --git a/java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java b/java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java index a6818af5..303ad980 100644 --- a/java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java @@ -6,6 +6,7 @@ import com.mumfrey.worldeditcui.render.shapes.RenderCylinderBox; import com.mumfrey.worldeditcui.render.shapes.RenderCylinderCircles; import com.mumfrey.worldeditcui.render.shapes.RenderCylinderGrid; +import com.mumfrey.worldeditcui.util.Vector3; /** * Main controller for a cylinder-type region @@ -21,39 +22,33 @@ public class CylinderRegion extends BaseRegion protected int minY = 0; protected int maxY = 0; + private RenderCylinderCircles circles; + private RenderCylinderGrid grid; + private RenderCylinderBox box; + public CylinderRegion(WorldEditCUI controller) { super(controller); } @Override - public void render() + public void render(Vector3 cameraPos) { if (this.center != null) { - this.center.render(); - - int tMin = this.minY; - int tMax = this.maxY; - - if (this.minY == 0 || this.maxY == 0) - { - tMin = (int)this.center.getPoint().getY(); - tMax = (int)this.center.getPoint().getY(); - } - - new RenderCylinderCircles(LineColour.CYLINDERGRID, this.center, this.radX, this.radZ, tMin, tMax).render(); - new RenderCylinderGrid(LineColour.CYLINDERGRID, this.center, this.radX, this.radZ, tMin, tMax).render(); - new RenderCylinderBox(LineColour.CYLINDERBOX, this.center, this.radX, this.radZ, tMin, tMax).render(); - + this.center.render(cameraPos); + this.circles.render(cameraPos); + this.grid.render(cameraPos); + this.box.render(cameraPos); } } - + @Override public void setCylinderCenter(int x, int y, int z) { this.center = new PointCube(x, y, z); this.center.setColour(LineColour.CYLINDERCENTER); + this.update(); } @Override @@ -61,6 +56,7 @@ public void setCylinderRadius(double x, double z) { this.radX = x; this.radZ = z; + this.update(); } @Override @@ -68,6 +64,23 @@ public void setMinMax(int min, int max) { this.minY = min; this.maxY = max; + this.update(); + } + + private void update() + { + int tMin = this.minY; + int tMax = this.maxY; + + if (this.minY == 0 || this.maxY == 0) + { + tMin = (int)this.center.getPoint().getY(); + tMax = (int)this.center.getPoint().getY(); + } + + this.circles = new RenderCylinderCircles(LineColour.CYLINDERGRID, this.center, this.radX, this.radZ, tMin, tMax); + this.grid = new RenderCylinderGrid(LineColour.CYLINDERGRID, this.center, this.radX, this.radZ, tMin, tMax); + this.box = new RenderCylinderBox(LineColour.CYLINDERBOX, this.center, this.radX, this.radZ, tMin, tMax); } @Override diff --git a/java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java b/java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java index b849fa79..798f14ae 100644 --- a/java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java @@ -15,41 +15,51 @@ public class EllipsoidRegion extends BaseRegion { - protected PointCube center; + protected PointCube centre; protected Vector3 radii; + private RenderEllipsoid ellipsoid; + public EllipsoidRegion(WorldEditCUI controller) { super(controller); } @Override - public void render() + public void render(Vector3 cameraPos) { - if (this.center != null && this.radii != null) + if (this.centre != null && this.radii != null) { - this.center.render(); - - new RenderEllipsoid(LineColour.ELLIPSOIDGRID, this.center, this.radii).render(); - + this.centre.render(cameraPos); + this.ellipsoid.render(cameraPos); } - else if (this.center != null) + else if (this.centre != null) { - this.center.render(); + this.centre.render(cameraPos); } } @Override public void setEllipsoidCenter(int x, int y, int z) { - this.center = new PointCube(x, y, z); - this.center.setColour(LineColour.ELLIPSOIDCENTER); + this.centre = new PointCube(x, y, z); + this.centre.setColour(LineColour.ELLIPSOIDCENTER); + this.update(); } @Override public void setEllipsoidRadii(double x, double y, double z) { this.radii = new Vector3(x, y, z); + this.update(); + } + + private void update() + { + if (this.centre != null && this.radii != null) + { + this.ellipsoid = new RenderEllipsoid(LineColour.ELLIPSOIDGRID, this.centre, this.radii); + } } @Override diff --git a/java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java b/java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java index b79b9b0d..dc2ce525 100644 --- a/java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java @@ -8,6 +8,7 @@ import com.mumfrey.worldeditcui.render.points.PointRectangle; import com.mumfrey.worldeditcui.render.shapes.Render2DBox; import com.mumfrey.worldeditcui.render.shapes.Render2DGrid; +import com.mumfrey.worldeditcui.util.Vector3; /** * Main controller for a polygon-type region @@ -22,27 +23,29 @@ public class PolygonRegion extends BaseRegion protected int min; protected int max; + private Render2DBox box; + private Render2DGrid grid; + public PolygonRegion(WorldEditCUI controller) { super(controller); } @Override - public void render() + public void render(Vector3 cameraPos) { - if (this.points == null) + if (this.points.size() < 1) { return; } for (PointRectangle point : this.points) { - point.render(this.min, this.max); + point.render(cameraPos, this.min, this.max); } - new Render2DBox(LineColour.POLYBOX, this.points, this.min, this.max).render(); - new Render2DGrid(LineColour.POLYGRID, this.points, this.min, this.max).render(); - + this.box.render(cameraPos); + this.grid.render(cameraPos); } @Override @@ -50,6 +53,7 @@ public void setMinMax(int min, int max) { this.min = min; this.max = max; + this.update(); } @Override @@ -70,6 +74,16 @@ public void setPolygonPoint(int id, int x, int z) } this.points.add(point); } + this.update(); + } + + private void update() + { + if (this.points.size() > 0) + { + this.box = new Render2DBox(LineColour.POLYBOX, this.points, this.min, this.max); + this.grid = new Render2DGrid(LineColour.POLYGRID, this.points, this.min, this.max); + } } @Override diff --git a/java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java b/java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java index ba5e1cd0..9dea681d 100644 --- a/java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java @@ -20,25 +20,27 @@ public class PolyhedronRegion extends BaseRegion protected List vertices = new ArrayList(); protected List faces = new ArrayList(); + private List faceRenders = new ArrayList(); + public PolyhedronRegion(WorldEditCUI controller) { super(controller); } @Override - public void render() + public void render(Vector3 cameraPos) { for (PointCube vertex : this.vertices) { - vertex.render(); + vertex.render(cameraPos); } - for (Vector3[] face : this.faces) + for (Render3DPolygon face : this.faceRenders) { - new Render3DPolygon(LineColour.POLYBOX, face).render(); + face.render(cameraPos); } } - + @Override public void setCuboidPoint(int id, double x, double y, double z) { @@ -77,6 +79,17 @@ public void addPolygon(int[] vertexIds) face[i] = vertex.getPoint().add(half); } this.faces.add(face); + this.update(); + } + + private void update() + { + this.faceRenders.clear(); + + for (Vector3[] face : this.faces) + { + this.faceRenders.add(new Render3DPolygon(LineColour.POLYBOX, face)); + } } @Override diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java b/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java index e6e1914c..6de8872b 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java @@ -5,6 +5,8 @@ import com.mumfrey.worldeditcui.render.LineColour; import com.mumfrey.worldeditcui.render.LineInfo; import com.mumfrey.worldeditcui.render.points.PointRectangle; +import com.mumfrey.worldeditcui.util.Vector2; +import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.WorldRenderer; @@ -32,11 +34,11 @@ public Render2DBox(LineColour colour, List points, int min, int this.max = max; } - public void render() + public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); WorldRenderer worldRenderer = tessellator.getWorldRenderer(); - double off = 0.03; + double off = 0.03 - cameraPos.getY(); for (LineInfo tempColour : this.colour.getColours()) { tempColour.prepareRender(); @@ -48,8 +50,11 @@ public void render() { if (point != null) { - worldRenderer.addVertex(point.getPoint().getX() + 0.5, this.min + off, point.getPoint().getY() + 0.5); - worldRenderer.addVertex(point.getPoint().getX() + 0.5, this.max + 1 + off, point.getPoint().getY() + 0.5); + Vector2 pos = point.getPoint(); + double x = pos.getX() - cameraPos.getX(); + double z = pos.getY() - cameraPos.getZ(); + worldRenderer.addVertex(x + 0.5, this.min + off, z + 0.5); + worldRenderer.addVertex(x + 0.5, this.max + 1 + off, z + 0.5); } } tessellator.draw(); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java b/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java index 05ffd12f..4a1ff50c 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java @@ -5,6 +5,8 @@ import com.mumfrey.worldeditcui.render.LineColour; import com.mumfrey.worldeditcui.render.LineInfo; import com.mumfrey.worldeditcui.render.points.PointRectangle; +import com.mumfrey.worldeditcui.util.Vector2; +import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.WorldRenderer; @@ -31,16 +33,16 @@ public Render2DGrid(LineColour colour, List points, int min, int this.max = max; } - public void render() + public void render(Vector3 cameraPos) { double off = 0.03; for (double height = this.min; height <= this.max + 1; height++) { - this.drawPoly(height + off); + this.drawPoly(cameraPos, height + off); } } - protected void drawPoly(double height) + protected void drawPoly(Vector3 cameraPos, double height) { Tessellator tessellator = Tessellator.getInstance(); WorldRenderer worldRenderer = tessellator.getWorldRenderer(); @@ -54,7 +56,10 @@ protected void drawPoly(double height) { if (point != null) { - worldRenderer.addVertex(point.getPoint().getX() + 0.5, height, point.getPoint().getY() + 0.5); + Vector2 pos = point.getPoint(); + double x = pos.getX() - cameraPos.getX(); + double z = pos.getY() - cameraPos.getZ(); + worldRenderer.addVertex(x + 0.5, height - cameraPos.getY(), z + 0.5); } } tessellator.draw(); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java index 48c141bb..546c307f 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java @@ -28,16 +28,16 @@ public Render3DBox(LineColour colour, Vector3 first, Vector3 second) this.second = second; } - public void render() + public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); WorldRenderer worldRenderer = tessellator.getWorldRenderer(); - double x1 = this.first.getX(); - double y1 = this.first.getY(); - double z1 = this.first.getZ(); - double x2 = this.second.getX(); - double y2 = this.second.getY(); - double z2 = this.second.getZ(); + double x1 = this.first.getX() - cameraPos.getX(); + double y1 = this.first.getY() - cameraPos.getY(); + double z1 = this.first.getZ() - cameraPos.getZ(); + double x2 = this.second.getX() - cameraPos.getX(); + double y2 = this.second.getY() - cameraPos.getY(); + double z2 = this.second.getZ() - cameraPos.getZ(); for (LineInfo tempColour : this.colour.getColours()) { diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java index d0f4576e..0ee60111 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java @@ -28,17 +28,18 @@ public Render3DGrid(LineColour colour, Vector3 first, Vector3 second) this.second = second; } - public void render() + public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); WorldRenderer worldRenderer = tessellator.getWorldRenderer(); - double x1 = this.first.getX(); - double y1 = this.first.getY(); - double z1 = this.first.getZ(); - double x2 = this.second.getX(); - double y2 = this.second.getY(); - double z2 = this.second.getZ(); + double x1 = this.first.getX() - cameraPos.getX(); + double y1 = this.first.getY() - cameraPos.getY(); + double z1 = this.first.getZ() - cameraPos.getZ(); + double x2 = this.second.getX() - cameraPos.getX(); + double y2 = this.second.getY() - cameraPos.getY(); + double z2 = this.second.getZ() - cameraPos.getZ(); + double cullAt = 128.0F; for (LineInfo tempColour : this.colour.getColours()) { tempColour.prepareRender(); @@ -46,137 +47,51 @@ public void render() worldRenderer.startDrawing(GL_LINES); tempColour.prepareColour(); - double x, y, z; double offsetSize = 1.0; - // Zmax XY plane, y axis - z = z2; - y = y1; - int msize = 150; - if ((y2 - y / offsetSize) < msize) + for (double yoff = 0; yoff + y1 <= y2; yoff += offsetSize) { - for (double yoff = 0; yoff + y <= y2; yoff += offsetSize) - { - worldRenderer.addVertex(x1, y + yoff, z); - worldRenderer.addVertex(x2, y + yoff, z); - } + double y = y1 + yoff; + worldRenderer.addVertex(x1, y, z2); + worldRenderer.addVertex(x2, y, z2); + worldRenderer.addVertex(x1, y, z1); + worldRenderer.addVertex(x2, y, z1); + worldRenderer.addVertex(x1, y, z1); + worldRenderer.addVertex(x1, y, z2); + worldRenderer.addVertex(x2, y, z1); + worldRenderer.addVertex(x2, y, z2); } - // Zmin XY plane, y axis - z = z1; - if ((y2 - y / offsetSize) < msize) + for (double xoff = 0; xoff + x1 <= x2; xoff += offsetSize) { - for (double yoff = 0; yoff + y <= y2; yoff += offsetSize) - { - worldRenderer.addVertex(x1, y + yoff, z); - worldRenderer.addVertex(x2, y + yoff, z); - } + double x = x1 + xoff; +// boolean major = xoff % 10 == 0; + if (x < -cullAt) continue; + if (x > cullAt) break; + worldRenderer.addVertex(x, y1, z1); + worldRenderer.addVertex(x, y2, z1); + worldRenderer.addVertex(x, y1, z2); + worldRenderer.addVertex(x, y2, z2); + worldRenderer.addVertex(x, y2, z1); + worldRenderer.addVertex(x, y2, z2); + worldRenderer.addVertex(x, y1, z1); + worldRenderer.addVertex(x, y1, z2); } - // Xmin YZ plane, y axis - x = x1; - if ((y2 - y / offsetSize) < msize) + for (double zoff = 0; zoff + z1 <= z2; zoff += offsetSize) { - for (double yoff = 0; yoff + y <= y2; yoff += offsetSize) - { - worldRenderer.addVertex(x, y + yoff, z1); - worldRenderer.addVertex(x, y + yoff, z2); - } - } - - // Xmax YZ plane, y axis - x = x2; - if ((y2 - y / offsetSize) < msize) - { - for (double yoff = 0; yoff + y <= y2; yoff += offsetSize) - { - worldRenderer.addVertex(x, y + yoff, z1); - worldRenderer.addVertex(x, y + yoff, z2); - } - } - - // Zmin XY plane, x axis - x = x1; - z = z1; - if ((x2 - x / offsetSize) < msize) - { - for (double xoff = 0; xoff + x <= x2; xoff += offsetSize) - { - worldRenderer.addVertex(x + xoff, y1, z); - worldRenderer.addVertex(x + xoff, y2, z); - } - } - // Zmax XY plane, x axis - z = z2; - if ((x2 - x / offsetSize) < msize) - { - for (double xoff = 0; xoff + x <= x2; xoff += offsetSize) - { - worldRenderer.addVertex(x + xoff, y1, z); - worldRenderer.addVertex(x + xoff, y2, z); - } - } - // Ymin XZ plane, x axis - y = y2; - if ((x2 - x / offsetSize) < msize) - { - for (double xoff = 0; xoff + x <= x2; xoff += offsetSize) - { - worldRenderer.addVertex(x + xoff, y, z1); - worldRenderer.addVertex(x + xoff, y, z2); - } - } - // Ymax XZ plane, x axis - y = y1; - if ((x2 - x / offsetSize) < msize) - { - for (double xoff = 0; xoff + x <= x2; xoff += offsetSize) - { - worldRenderer.addVertex(x + xoff, y, z1); - worldRenderer.addVertex(x + xoff, y, z2); - } - } - - // Ymin XZ plane, z axis - z = z1; - y = y1; - if ((z2 - z / offsetSize) < msize) - { - for (double zoff = 0; zoff + z <= z2; zoff += offsetSize) - { - worldRenderer.addVertex(x1, y, z + zoff); - worldRenderer.addVertex(x2, y, z + zoff); - } - } - // Ymax XZ plane, z axis - y = y2; - if ((z2 - z / offsetSize) < msize) - { - for (double zoff = 0; zoff + z <= z2; zoff += offsetSize) - { - worldRenderer.addVertex(x1, y, z + zoff); - worldRenderer.addVertex(x2, y, z + zoff); - } - } - // Xmin YZ plane, z axis - x = x2; - if ((z2 - z / offsetSize) < msize) - { - for (double zoff = 0; zoff + z <= z2; zoff += offsetSize) - { - worldRenderer.addVertex(x, y1, z + zoff); - worldRenderer.addVertex(x, y2, z + zoff); - } - } - // Xmax YZ plane, z axis - x = x1; - if ((z2 - z / offsetSize) < msize) - { - for (double zoff = 0; zoff + z <= z2; zoff += offsetSize) - { - worldRenderer.addVertex(x, y1, z + zoff); - worldRenderer.addVertex(x, y2, z + zoff); - } + double z = z1 + zoff; +// boolean major = zoff % 10 == 0; + if (z < -cullAt) continue; + if (z > cullAt) break; + worldRenderer.addVertex(x1, y1, z); + worldRenderer.addVertex(x2, y1, z); + worldRenderer.addVertex(x1, y2, z); + worldRenderer.addVertex(x2, y2, z); + worldRenderer.addVertex(x2, y1, z); + worldRenderer.addVertex(x2, y2, z); + worldRenderer.addVertex(x1, y1, z); + worldRenderer.addVertex(x1, y2, z); } tessellator.draw(); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java index e6fd42af..508ce75c 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java @@ -26,7 +26,7 @@ public Render3DPolygon(LineColour colour, Vector3... vertices) this.vertices = vertices; } - public void render() + public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); WorldRenderer worldRenderer = tessellator.getWorldRenderer(); @@ -39,7 +39,7 @@ public void render() tempColour.prepareColour(); for (Vector3 vertex : this.vertices) { - worldRenderer.addVertex(vertex.getX(), vertex.getY(), vertex.getZ()); + worldRenderer.addVertex(vertex.getX() - cameraPos.getX(), vertex.getY() - cameraPos.getY(), vertex.getZ() - cameraPos.getZ()); } tessellator.draw(); } diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java index 67d37adf..cece5004 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java @@ -3,6 +3,7 @@ import com.mumfrey.worldeditcui.render.LineColour; import com.mumfrey.worldeditcui.render.LineInfo; import com.mumfrey.worldeditcui.render.points.PointCube; +import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.WorldRenderer; @@ -21,25 +22,28 @@ public class RenderCylinderBox protected double radZ = 0; protected int minY; protected int maxY; - protected double centerX; - protected double centerZ; + protected double centreX; + protected double centreZ; - public RenderCylinderBox(LineColour colour, PointCube center, double radX, double radZ, int minY, int maxY) + public RenderCylinderBox(LineColour colour, PointCube centre, double radX, double radZ, int minY, int maxY) { this.colour = colour; this.radX = radX; this.radZ = radZ; this.minY = minY; this.maxY = maxY; - this.centerX = center.getPoint().getX() + 0.5; - this.centerZ = center.getPoint().getZ() + 0.5; + this.centreX = centre.getPoint().getX() + 0.5; + this.centreZ = centre.getPoint().getZ() + 0.5; } - public void render() + public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + double xPos = this.centreX - cameraPos.getX(); + double zPos = this.centreZ - cameraPos.getZ(); + for (LineInfo tempColour : this.colour.getColours()) { tempColour.prepareRender(); @@ -56,7 +60,7 @@ public void render() double tempX = this.radX * Math.cos(tempTheta); double tempZ = this.radZ * Math.sin(tempTheta); - worldRenderer.addVertex(this.centerX + tempX, yBlock, this.centerZ + tempZ); + worldRenderer.addVertex(xPos + tempX, yBlock - cameraPos.getY(), zPos + tempZ); } tessellator.draw(); } diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java index 1320d6fa..6c509942 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java @@ -3,6 +3,7 @@ import com.mumfrey.worldeditcui.render.LineColour; import com.mumfrey.worldeditcui.render.LineInfo; import com.mumfrey.worldeditcui.render.points.PointCube; +import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.WorldRenderer; @@ -21,25 +22,28 @@ public class RenderCylinderCircles protected double radZ = 0; protected int minY; protected int maxY; - protected double centerX; - protected double centerZ; + protected double centreX; + protected double centreZ; - public RenderCylinderCircles(LineColour colour, PointCube center, double radX, double radZ, int minY, int maxY) + public RenderCylinderCircles(LineColour colour, PointCube centre, double radX, double radZ, int minY, int maxY) { this.colour = colour; this.radX = radX; this.radZ = radZ; this.minY = minY; this.maxY = maxY; - this.centerX = center.getPoint().getX() + 0.5; - this.centerZ = center.getPoint().getZ() + 0.5; + this.centreX = centre.getPoint().getX() + 0.5; + this.centreZ = centre.getPoint().getZ() + 0.5; } - public void render() + public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + double xPos = this.centreX - cameraPos.getX(); + double zPos = this.centreZ - cameraPos.getZ(); + for (LineInfo tempColour : this.colour.getColours()) { tempColour.prepareRender(); @@ -56,7 +60,7 @@ public void render() double tempX = this.radX * Math.cos(tempTheta); double tempZ = this.radZ * Math.sin(tempTheta); - worldRenderer.addVertex(this.centerX + tempX, yBlock, this.centerZ + tempZ); + worldRenderer.addVertex(xPos + tempX, yBlock - cameraPos.getY(), zPos + tempZ); } tessellator.draw(); } diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java index e0c9c937..95544122 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java @@ -3,6 +3,7 @@ import com.mumfrey.worldeditcui.render.LineColour; import com.mumfrey.worldeditcui.render.LineInfo; import com.mumfrey.worldeditcui.render.points.PointCube; +import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.WorldRenderer; @@ -21,25 +22,28 @@ public class RenderCylinderGrid protected double radZ = 0; protected int minY; protected int maxY; - protected double centerX; - protected double centerZ; + protected double centreX; + protected double centreZ; - public RenderCylinderGrid(LineColour colour, PointCube center, double radX, double radZ, int minY, int maxY) + public RenderCylinderGrid(LineColour colour, PointCube centre, double radX, double radZ, int minY, int maxY) { this.colour = colour; this.radX = radX; this.radZ = radZ; this.minY = minY; this.maxY = maxY; - this.centerX = center.getPoint().getX() + 0.5; - this.centerZ = center.getPoint().getZ() + 0.5; + this.centreX = centre.getPoint().getX() + 0.5; + this.centreZ = centre.getPoint().getZ() + 0.5; } - public void render() + public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + double xPos = this.centreX - cameraPos.getX(); + double zPos = this.centreZ - cameraPos.getZ(); + for (LineInfo tempColour : this.colour.getColours()) { tempColour.prepareRender(); @@ -57,10 +61,10 @@ public void render() worldRenderer.startDrawing(GL_LINE_LOOP); tempColour.prepareColour(); - worldRenderer.addVertex(this.centerX + tempX, tmaxY, this.centerZ + tempZ); - worldRenderer.addVertex(this.centerX + tempX, tmaxY, this.centerZ - tempZ); - worldRenderer.addVertex(this.centerX + tempX, tminY, this.centerZ - tempZ); - worldRenderer.addVertex(this.centerX + tempX, tminY, this.centerZ + tempZ); + worldRenderer.addVertex(xPos + tempX, tmaxY - cameraPos.getY(), zPos + tempZ); + worldRenderer.addVertex(xPos + tempX, tmaxY - cameraPos.getY(), zPos - tempZ); + worldRenderer.addVertex(xPos + tempX, tminY - cameraPos.getY(), zPos - tempZ); + worldRenderer.addVertex(xPos + tempX, tminY - cameraPos.getY(), zPos + tempZ); tessellator.draw(); } @@ -71,10 +75,10 @@ public void render() worldRenderer.startDrawing(GL_LINE_LOOP); tempColour.prepareColour(); - worldRenderer.addVertex(this.centerX + tempX, tmaxY, this.centerZ + tempZ); - worldRenderer.addVertex(this.centerX - tempX, tmaxY, this.centerZ + tempZ); - worldRenderer.addVertex(this.centerX - tempX, tminY, this.centerZ + tempZ); - worldRenderer.addVertex(this.centerX + tempX, tminY, this.centerZ + tempZ); + worldRenderer.addVertex(xPos + tempX, tmaxY - cameraPos.getY(), zPos + tempZ); + worldRenderer.addVertex(xPos - tempX, tmaxY - cameraPos.getY(), zPos + tempZ); + worldRenderer.addVertex(xPos - tempX, tminY - cameraPos.getY(), zPos + tempZ); + worldRenderer.addVertex(xPos + tempX, tminY - cameraPos.getY(), zPos + tempZ); tessellator.draw(); } diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java index ccf31992..4475aff3 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java @@ -21,22 +21,25 @@ public class RenderEllipsoid protected PointCube center; protected Vector3 radii; protected final static double twoPi = Math.PI * 2; - protected double centerX; - protected double centerY; - protected double centerZ; + protected double centreX; + protected double centreY; + protected double centreZ; - public RenderEllipsoid(LineColour colour, PointCube center, Vector3 radii) + public RenderEllipsoid(LineColour colour, PointCube centre, Vector3 radii) { this.colour = colour; - this.center = center; + this.center = centre; this.radii = radii; - this.centerX = center.getPoint().getX() + 0.5; - this.centerY = center.getPoint().getY() + 0.5; - this.centerZ = center.getPoint().getZ() + 0.5; + this.centreX = centre.getPoint().getX() + 0.5; + this.centreY = centre.getPoint().getY() + 0.5; + this.centreZ = centre.getPoint().getZ() + 0.5; } - public void render() + public void render(Vector3 cameraPos) { + glPushMatrix(); + glTranslated(this.centreX - cameraPos.getX(), this.centreY - cameraPos.getY(), this.centreZ - cameraPos.getZ()); + for (LineInfo tempColour : this.colour.getColours()) { tempColour.prepareRender(); @@ -44,6 +47,8 @@ public void render() this.drawYZPlane(tempColour); this.drawXYPlane(tempColour); } + + glPopMatrix(); } protected void drawXZPlane(LineInfo colour) @@ -63,7 +68,7 @@ protected void drawXZPlane(LineInfo colour) double tempX = this.radii.getX() * Math.cos(tempTheta) * Math.cos(Math.asin(yBlock / this.radii.getY())); double tempZ = this.radii.getZ() * Math.sin(tempTheta) * Math.cos(Math.asin(yBlock / this.radii.getY())); - worldRenderer.addVertex(this.centerX + tempX, this.centerY + yBlock, this.centerZ + tempZ); + worldRenderer.addVertex(tempX, yBlock, tempZ); } tessellator.draw(); } @@ -77,7 +82,7 @@ protected void drawXZPlane(LineInfo colour) double tempX = this.radii.getX() * Math.cos(tempTheta); double tempZ = this.radii.getZ() * Math.sin(tempTheta); - worldRenderer.addVertex(this.centerX + tempX, this.centerY, this.centerZ + tempZ); + worldRenderer.addVertex(tempX, 0.0, tempZ); } tessellator.draw(); } @@ -99,7 +104,7 @@ protected void drawYZPlane(LineInfo colour) double tempY = this.radii.getY() * Math.cos(tempTheta) * Math.sin(Math.acos(xBlock / this.radii.getX())); double tempZ = this.radii.getZ() * Math.sin(tempTheta) * Math.sin(Math.acos(xBlock / this.radii.getX())); - worldRenderer.addVertex(this.centerX + xBlock, this.centerY + tempY, this.centerZ + tempZ); + worldRenderer.addVertex(xBlock, tempY, tempZ); } tessellator.draw(); } @@ -113,7 +118,7 @@ protected void drawYZPlane(LineInfo colour) double tempY = this.radii.getY() * Math.cos(tempTheta); double tempZ = this.radii.getZ() * Math.sin(tempTheta); - worldRenderer.addVertex(this.centerX, this.centerY + tempY, this.centerZ + tempZ); + worldRenderer.addVertex(0.0, tempY, tempZ); } tessellator.draw(); } @@ -135,7 +140,7 @@ protected void drawXYPlane(LineInfo colour) double tempX = this.radii.getX() * Math.sin(tempTheta) * Math.sin(Math.acos(zBlock / this.radii.getZ())); double tempY = this.radii.getY() * Math.cos(tempTheta) * Math.sin(Math.acos(zBlock / this.radii.getZ())); - worldRenderer.addVertex(this.centerX + tempX, this.centerY + tempY, this.centerZ + zBlock); + worldRenderer.addVertex(tempX, tempY, zBlock); } tessellator.draw(); } @@ -149,7 +154,7 @@ protected void drawXYPlane(LineInfo colour) double tempX = this.radii.getX() * Math.cos(tempTheta); double tempY = this.radii.getY() * Math.sin(tempTheta); - worldRenderer.addVertex(this.centerX + tempX, this.centerY + tempY, this.centerZ); + worldRenderer.addVertex(tempX, tempY, 0.0); } tessellator.draw(); } diff --git a/java/com/mumfrey/worldeditcui/util/Vector2.java b/java/com/mumfrey/worldeditcui/util/Vector2.java index dda531d0..629c1f76 100644 --- a/java/com/mumfrey/worldeditcui/util/Vector2.java +++ b/java/com/mumfrey/worldeditcui/util/Vector2.java @@ -1,614 +1,614 @@ -package com.mumfrey.worldeditcui.util; - -/** - * A 2-dimensional vector represented by float-precision x,y coordinates - * - * Note, this is the Immutable form of Vector2. All operations will construct a - * new Vector2. - */ -public class Vector2 implements Comparable -{ - - /** - * Represents the Zero vector (0,0) - */ - public final static Vector2 ZERO = new Vector2(0, 0); - /** - * Represents a unit vector in the X direction (1,0) - */ - public final static Vector2 UNIT_X = new Vector2(1, 0); - /** - * Represents a unit vector in the Y direction (0,1) - */ - public final static Vector2 UNIT_Y = new Vector2(0, 1); - /** - * Represents a unit vector (1,1) - */ - public static Vector2 ONE = new Vector2(1, 1); - protected float x, z; - - /** - * Construct and Initialized a Vector2 from the given x, y - * - * @param x the x coordinate - * @param y the y coordinate - */ - public Vector2(float x, float y) - { - this.x = x; - this.z = y; - } - - /** - * Construct and Initialized a Vector2 from the given x, y - * - * @param x the x coordinate - * @param y the y coordinate - */ - public Vector2(Double x, Double y) - { - this(x.floatValue(), y.floatValue()); - } - - /** - * Construct and Initialized a Vector2 to (0,0) - */ - public Vector2() - { - this(0, 0); - } - - /** - * Construct and Initialized a Vector2 from an old Vector2 - * - * @param original - */ - public Vector2(Vector2 original) - { - this(original.x, original.z); - } - - /** - * Gets the X coordiante - * - * @return The X coordinate - */ - public float getX() - { - return this.x; - } - - /** - * Gets the Y coordiante - * - * @return The Y coordinate - */ - public float getY() - { - return this.z; - } - - /** - * Adds this Vector2 to the value of the Vector2 argument - * - * @param that The Vector2 to add - * @return the new Vector2 - */ - public Vector2 add(Vector2 that) - { - return Vector2.add(this, that); - } - - /** - * Subtracts this Vector2 to the value of the Vector2 argument - * - * @param that The Vector2 to subtract - * @return the new Vector2 - */ - public Vector2 subtract(Vector2 that) - { - return Vector2.subtract(this, that); - } - - /** - * Scales this Vector2 by the value of the argument - * - * @param scale The amount to scale by - * @return A new Vector2 scaled by the amount. - */ - public Vector2 scale(float scale) - { - return Vector2.scale(this, scale); - } - - /** - * Returns this Vector2 dot the Vector2 argument. Dot Product is defined as - * a.x*b.x + a.y*b.y - * - * @param that The Vector2 to dot with this. - * @return The dot product - */ - public float dot(Vector2 that) - { - return Vector2.dot(this, that); - } - - /** - * Returns a Vector3 object with a y-value of 0. - * The x of this Vector2 becomes the x of the Vector3, - * the y of this Vector2 becomes the z of the Vector3. - * - * @return - */ - public Vector3 toVector3() - { - return Vector2.toVector3(this); - } - - /** - * Returns a Vector3m object with a y-value of 0. - * The x of this Vector2 becomes the x of the Vector3m, - * the y of this Vector2 becomes the z of the Vector3m. - * - * @return - */ - public Vector3m toVector3m() - { - return Vector2.toVector3m(this); - } - - /** - * Returns a Vector3 object with the given y value. - * The x of this Vector2 becomes the x of the Vector3, - * the y of this Vector2 becomes the z of the Vector3. - * - * @param y Y value to use in the new Vector3. - * @return - */ - public Vector3 toVector3(float y) - { - return Vector2.toVector3(this, y); - } - - /** - * Returns a Vector3m object with the given y value. - * The x of this Vector2 becomes the x of the Vector3m, - * the y of this Vector2 becomes the z of the Vector3m. - * - * @param y Y value to use in the new Vector3m. - * @return - */ - public Vector3m toVector3m(float y) - { - return Vector2.toVector3m(this, y); - } - - /** - * Returns the Cross Product of this Vector2 Note: Cross Product is - * undefined in 2d space. This returns the orthogonal vector to this vector - * - * @return The orthogonal vector to this vector. - */ - public Vector2 cross() - { - return new Vector2(this.z, -this.x); - } - - /** - * Rounds the X and Y values of this Vector2 up to - * the nearest integer value. - * - * @return - */ - public Vector2 ceil() - { - return new Vector2(Math.ceil(this.x), Math.ceil(this.z)); - } - - /** - * Rounds the X and Y values of this Vector2 down to - * the nearest integer value. - * - * @return - */ - public Vector2 floor() - { - return new Vector2(Math.floor(this.x), Math.floor(this.z)); - } - - /** - * Rounds the X and Y values of this Vector2 to - * the nearest integer value. - * - * @return - */ - public Vector2 round() - { - return new Vector2(Math.round(this.x), Math.round(this.z)); - } - - /** - * Sets the X and Y values of this Vector2 to their - * absolute value. - * - * @return - */ - public Vector2 abs() - { - return new Vector2(Math.abs(this.x), Math.abs(this.z)); - } - - /** - * Gets the distance between this Vector2 and a given Vector2. - * - * @param a - * @return - */ - public double distance(Vector2 a) - { - return Vector2.distance(a, this); - } - - /** - * Raises the X and Y values of this Vector2 to the given power. - * - * @param power - * @return - */ - public Vector2 pow(double power) - { - return Vector2.pow(this, power); - } - - /** - * Calculates the length of this Vector2 squared. - * - * @return the squared length - */ - public float lengthSquared() - { - return Vector2.lengthSquared(this); - } - - /** - * Calculates the length of this Vector2 Note: This makes use of the sqrt - * function, and is not cached. That could affect performance - * - * @return the length of this vector2 - */ - public float length() - { - return Vector2.length(this); - } - - /** - * Returns this Vector2 where the length is equal to 1 - * - * @return This Vector2 with length 1 - */ - public Vector2 normalize() - { - return Vector2.normalize(this); - } - - /** - * Returns this Vector2 in an array. Element 0 contains x Element 1 contains - * y - * - * @return The array containing this Vector2 - */ - public float[] toArray() - { - return Vector2.toArray(this); - } - - /** - * Compares two Vector3s - */ - @Override - public int compareTo(Vector2 o) - { - return Vector2.compareTo(this, o); - } - - /** - * Checks if two Vector2s are equal - */ - @Override - public boolean equals(Object o) - { - return Vector2.equals(this, o); - } - - /** - * Returns the length of the provided Vector2 Note: This makes use of the - * sqrt function, and is not cached. This could affect performance. - * - * @param a The Vector2 to calculate the length of - * @return The length of the Vector2 - */ - public static float length(Vector2 a) - { - return (float)Math.sqrt(lengthSquared(a)); - } - - /** - * Returns the length squared of the provided Vector2 - * - * @param a the Vector2 to calculate the length squared - * @return the length squared of the Vector2 - */ - public static float lengthSquared(Vector2 a) - { - return Vector2.dot(a, a); - } - - /** - * Returns a Vector2 that is the unit form of the provided Vector2 - * - * @param a - * @return - */ - public static Vector2 normalize(Vector2 a) - { - return Vector2.scale(a, (1.f / a.length())); - } - - /** - * Subtracts one Vector2 from the other Vector2 - * - * @param a - * @param b - * @return - */ - public static Vector2 subtract(Vector2 a, Vector2 b) - { - return new Vector2(a.getX() - b.getX(), a.getY() - b.getY()); - } - - /** - * Adds one Vector2 to the other Vector2 - * - * @param a - * @param b - * @return - */ - public static Vector2 add(Vector2 a, Vector2 b) - { - return new Vector2(a.getX() + b.getX(), a.getY() + b.getY()); - } - - /** - * Scales the Vector2 by the ammount - * - * @param a - * @param b - * @return - */ - public static Vector2 scale(Vector2 a, float b) - { - return new Vector2(a.getX() * b, a.getY() * b); - } - - /** - * Calculates the Dot Product of two Vector2s Dot Product is defined as - * a.x*b.x + a.y*b.y - * - * @param a - * @param b - * @return - */ - public static float dot(Vector2 a, Vector2 b) - { - return a.getX() * b.getX() + a.getY() * b.getY(); - } - - /** - * Returns a Vector3 object with a y-value of 0. - * The x of the Vector2 becomes the x of the Vector3, - * the y of the Vector2 becomes the z of the Vector3. - * - * @param o Vector2 to use as the x/z values - * @return - */ - public static Vector3 toVector3(Vector2 o) - { - return new Vector3(o.x, 0, o.z); - } - - /** - * Returns a Vector3m object with a y-value of 0. - * The x of the Vector2 becomes the x of the Vector3m, - * the y of the Vector2 becomes the z of the Vector3m. - * - * @param o Vector2 to use as the x/z values - * @return - */ - public static Vector3m toVector3m(Vector2 o) - { - return new Vector3m(o.x, 0, o.z); - } - - /** - * Returns a Vector3 object with the given y-value. - * The x of the Vector2 becomes the x of the Vector3, - * the y of the Vector2 becomes the z of the Vector3. - * - * @param o Vector2 to use as the x/z values - * @param y Y value of the new Vector3 - * @return - */ - public static Vector3 toVector3(Vector2 o, float y) - { - return new Vector3(o.x, y, o.z); - } - - /** - * Returns a Vector3m object with the given y-value. - * The x of the Vector2 becomes the x of the Vector3m, - * the y of the Vector2 becomes the z of the Vector3m. - * - * @param o Vector2 to use as the x/z values - * @param y Y value of the new Vector3 - * @return - */ - public static Vector3m toVector3m(Vector2 o, float y) - { - return new Vector3m(o.x, y, o.z); - } - - /** - * Rounds the X and Y values of the given Vector2 up to - * the nearest integer value. - * - * @param o Vector2 to use - * @return - */ - public static Vector2 ceil(Vector2 o) - { - return new Vector2(Math.ceil(o.x), Math.ceil(o.z)); - } - - /** - * Rounds the X and Y values of the given Vector2 down to - * the nearest integer value. - * - * @param o Vector2 to use - * @return - */ - public static Vector2 floor(Vector2 o) - { - return new Vector2(Math.floor(o.x), Math.floor(o.z)); - } - - /** - * Rounds the X and Y values of the given Vector2 to - * the nearest integer value. - * - * @param o Vector2 to use - * @return - */ - public static Vector2 round(Vector2 o) - { - return new Vector2(Math.round(o.x), Math.round(o.z)); - } - - /** - * Sets the X and Y values of the given Vector2 to their - * absolute value. - * - * @param o Vector2 to use - * @return - */ - public static Vector2 abs(Vector2 o) - { - return new Vector2(Math.abs(o.x), Math.abs(o.z)); - } - - /** - * Returns a Vector2 containing the smallest X and Y values. - * - * @param o1 - * @param o2 - * @return - */ - public static Vector2 min(Vector2 o1, Vector2 o2) - { - return new Vector2(Math.min(o1.x, o2.x), Math.min(o1.z, o2.z)); - } - - /** - * Returns a Vector2 containing the largest X and Y values. - * - * @param o1 - * @param o2 - * @return - */ - public static Vector2 max(Vector2 o1, Vector2 o2) - { - return new Vector2(Math.max(o1.x, o2.x), Math.max(o1.z, o2.z)); - } - - /** - * Returns a Vector2 with random X and Y values (between 0 and 1) - * - * @param o - * @return - */ - public static Vector2 rand() - { - return new Vector2(Math.random(), Math.random()); - } - - /** - * Returns the provided Vector2 in an array. Element 0 contains x Element 1 - * contains y - * - * @return The array containing the Vector2 - */ - public static float[] toArray(Vector2 a) - { - return new float[] { a.getX(), a.getY() }; - } - - /** - * Compares two Vector3s - */ - public static int compareTo(Vector2 a, Vector2 b) - { - return (int)a.lengthSquared() - (int)b.lengthSquared(); - } - - /** - * Gets the distance between two Vector2. - * - * @param a - * @param b - * @return - */ - public static double distance(Vector2 a, Vector2 b) - { - Vector2 tempVector = Vector2.pow(Vector2.subtract(a, b), 2); - return Math.sqrt(tempVector.x + tempVector.z); - } - - /** - * Raises the X and Y values of a Vector2 to the given power. - * - * @param o - * @param power - * @return - */ - public static Vector2 pow(Vector2 o, double power) - { - return new Vector2(Math.pow(o.x, power), Math.pow(o.z, power)); - } - - /** - * Checks if two Vector2s are equal - */ - public static boolean equals(Object a, Object b) - { - if (!(a instanceof Vector2) || !(b instanceof Vector2)) - { - return false; - } - if (a == b) - { - return true; - } - return compareTo((Vector2)a, (Vector2)b) == 0; - } - - @Override - public String toString() - { - return "(" + this.x + ", " + this.z + ")"; - } - - @Override - public int hashCode() - { - return (int)(this.x % this.z); - } -} +package com.mumfrey.worldeditcui.util; + +/** + * A 2-dimensional vector represented by float-precision x,y coordinates + * + * Note, this is the Immutable form of Vector2. All operations will construct a + * new Vector2. + */ +public class Vector2 implements Comparable +{ + + /** + * Represents the Zero vector (0,0) + */ + public final static Vector2 ZERO = new Vector2(0, 0); + /** + * Represents a unit vector in the X direction (1,0) + */ + public final static Vector2 UNIT_X = new Vector2(1, 0); + /** + * Represents a unit vector in the Y direction (0,1) + */ + public final static Vector2 UNIT_Y = new Vector2(0, 1); + /** + * Represents a unit vector (1,1) + */ + public static Vector2 ONE = new Vector2(1, 1); + protected double x, z; + + /** + * Construct and Initialized a Vector2 from the given x, y + * + * @param x the x coordinate + * @param y the y coordinate + */ + public Vector2(double x, double y) + { + this.x = x; + this.z = y; + } + + /** + * Construct and Initialized a Vector2 from the given x, y + * + * @param x the x coordinate + * @param y the y coordinate + */ + public Vector2(Double x, Double y) + { + this(x.doubleValue(), y.doubleValue()); + } + + /** + * Construct and Initialized a Vector2 to (0,0) + */ + public Vector2() + { + this(0, 0); + } + + /** + * Construct and Initialized a Vector2 from an old Vector2 + * + * @param original + */ + public Vector2(Vector2 original) + { + this(original.x, original.z); + } + + /** + * Gets the X coordiante + * + * @return The X coordinate + */ + public double getX() + { + return this.x; + } + + /** + * Gets the Y coordiante + * + * @return The Y coordinate + */ + public double getY() + { + return this.z; + } + + /** + * Adds this Vector2 to the value of the Vector2 argument + * + * @param that The Vector2 to add + * @return the new Vector2 + */ + public Vector2 add(Vector2 that) + { + return Vector2.add(this, that); + } + + /** + * Subtracts this Vector2 to the value of the Vector2 argument + * + * @param that The Vector2 to subtract + * @return the new Vector2 + */ + public Vector2 subtract(Vector2 that) + { + return Vector2.subtract(this, that); + } + + /** + * Scales this Vector2 by the value of the argument + * + * @param scale The amount to scale by + * @return A new Vector2 scaled by the amount. + */ + public Vector2 scale(double scale) + { + return Vector2.scale(this, scale); + } + + /** + * Returns this Vector2 dot the Vector2 argument. Dot Product is defined as + * a.x*b.x + a.y*b.y + * + * @param that The Vector2 to dot with this. + * @return The dot product + */ + public double dot(Vector2 that) + { + return Vector2.dot(this, that); + } + + /** + * Returns a Vector3 object with a y-value of 0. + * The x of this Vector2 becomes the x of the Vector3, + * the y of this Vector2 becomes the z of the Vector3. + * + * @return + */ + public Vector3 toVector3() + { + return Vector2.toVector3(this); + } + + /** + * Returns a Vector3m object with a y-value of 0. + * The x of this Vector2 becomes the x of the Vector3m, + * the y of this Vector2 becomes the z of the Vector3m. + * + * @return + */ + public Vector3m toVector3m() + { + return Vector2.toVector3m(this); + } + + /** + * Returns a Vector3 object with the given y value. + * The x of this Vector2 becomes the x of the Vector3, + * the y of this Vector2 becomes the z of the Vector3. + * + * @param y Y value to use in the new Vector3. + * @return + */ + public Vector3 toVector3(double y) + { + return Vector2.toVector3(this, y); + } + + /** + * Returns a Vector3m object with the given y value. + * The x of this Vector2 becomes the x of the Vector3m, + * the y of this Vector2 becomes the z of the Vector3m. + * + * @param y Y value to use in the new Vector3m. + * @return + */ + public Vector3m toVector3m(double y) + { + return Vector2.toVector3m(this, y); + } + + /** + * Returns the Cross Product of this Vector2 Note: Cross Product is + * undefined in 2d space. This returns the orthogonal vector to this vector + * + * @return The orthogonal vector to this vector. + */ + public Vector2 cross() + { + return new Vector2(this.z, -this.x); + } + + /** + * Rounds the X and Y values of this Vector2 up to + * the nearest integer value. + * + * @return + */ + public Vector2 ceil() + { + return new Vector2(Math.ceil(this.x), Math.ceil(this.z)); + } + + /** + * Rounds the X and Y values of this Vector2 down to + * the nearest integer value. + * + * @return + */ + public Vector2 floor() + { + return new Vector2(Math.floor(this.x), Math.floor(this.z)); + } + + /** + * Rounds the X and Y values of this Vector2 to + * the nearest integer value. + * + * @return + */ + public Vector2 round() + { + return new Vector2(Math.round(this.x), Math.round(this.z)); + } + + /** + * Sets the X and Y values of this Vector2 to their + * absolute value. + * + * @return + */ + public Vector2 abs() + { + return new Vector2(Math.abs(this.x), Math.abs(this.z)); + } + + /** + * Gets the distance between this Vector2 and a given Vector2. + * + * @param a + * @return + */ + public double distance(Vector2 a) + { + return Vector2.distance(a, this); + } + + /** + * Raises the X and Y values of this Vector2 to the given power. + * + * @param power + * @return + */ + public Vector2 pow(double power) + { + return Vector2.pow(this, power); + } + + /** + * Calculates the length of this Vector2 squared. + * + * @return the squared length + */ + public double lengthSquared() + { + return Vector2.lengthSquared(this); + } + + /** + * Calculates the length of this Vector2 Note: This makes use of the sqrt + * function, and is not cached. That could affect performance + * + * @return the length of this vector2 + */ + public double length() + { + return Vector2.length(this); + } + + /** + * Returns this Vector2 where the length is equal to 1 + * + * @return This Vector2 with length 1 + */ + public Vector2 normalize() + { + return Vector2.normalize(this); + } + + /** + * Returns this Vector2 in an array. Element 0 contains x Element 1 contains + * y + * + * @return The array containing this Vector2 + */ + public double[] toArray() + { + return Vector2.toArray(this); + } + + /** + * Compares two Vector3s + */ + @Override + public int compareTo(Vector2 o) + { + return Vector2.compareTo(this, o); + } + + /** + * Checks if two Vector2s are equal + */ + @Override + public boolean equals(Object o) + { + return Vector2.equals(this, o); + } + + /** + * Returns the length of the provided Vector2 Note: This makes use of the + * sqrt function, and is not cached. This could affect performance. + * + * @param a The Vector2 to calculate the length of + * @return The length of the Vector2 + */ + public static double length(Vector2 a) + { + return Math.sqrt(lengthSquared(a)); + } + + /** + * Returns the length squared of the provided Vector2 + * + * @param a the Vector2 to calculate the length squared + * @return the length squared of the Vector2 + */ + public static double lengthSquared(Vector2 a) + { + return Vector2.dot(a, a); + } + + /** + * Returns a Vector2 that is the unit form of the provided Vector2 + * + * @param a + * @return + */ + public static Vector2 normalize(Vector2 a) + { + return Vector2.scale(a, (1.f / a.length())); + } + + /** + * Subtracts one Vector2 from the other Vector2 + * + * @param a + * @param b + * @return + */ + public static Vector2 subtract(Vector2 a, Vector2 b) + { + return new Vector2(a.getX() - b.getX(), a.getY() - b.getY()); + } + + /** + * Adds one Vector2 to the other Vector2 + * + * @param a + * @param b + * @return + */ + public static Vector2 add(Vector2 a, Vector2 b) + { + return new Vector2(a.getX() + b.getX(), a.getY() + b.getY()); + } + + /** + * Scales the Vector2 by the ammount + * + * @param a + * @param b + * @return + */ + public static Vector2 scale(Vector2 a, double b) + { + return new Vector2(a.getX() * b, a.getY() * b); + } + + /** + * Calculates the Dot Product of two Vector2s Dot Product is defined as + * a.x*b.x + a.y*b.y + * + * @param a + * @param b + * @return + */ + public static double dot(Vector2 a, Vector2 b) + { + return a.getX() * b.getX() + a.getY() * b.getY(); + } + + /** + * Returns a Vector3 object with a y-value of 0. + * The x of the Vector2 becomes the x of the Vector3, + * the y of the Vector2 becomes the z of the Vector3. + * + * @param o Vector2 to use as the x/z values + * @return + */ + public static Vector3 toVector3(Vector2 o) + { + return new Vector3(o.x, 0, o.z); + } + + /** + * Returns a Vector3m object with a y-value of 0. + * The x of the Vector2 becomes the x of the Vector3m, + * the y of the Vector2 becomes the z of the Vector3m. + * + * @param o Vector2 to use as the x/z values + * @return + */ + public static Vector3m toVector3m(Vector2 o) + { + return new Vector3m(o.x, 0, o.z); + } + + /** + * Returns a Vector3 object with the given y-value. + * The x of the Vector2 becomes the x of the Vector3, + * the y of the Vector2 becomes the z of the Vector3. + * + * @param o Vector2 to use as the x/z values + * @param y Y value of the new Vector3 + * @return + */ + public static Vector3 toVector3(Vector2 o, double y) + { + return new Vector3(o.x, y, o.z); + } + + /** + * Returns a Vector3m object with the given y-value. + * The x of the Vector2 becomes the x of the Vector3m, + * the y of the Vector2 becomes the z of the Vector3m. + * + * @param o Vector2 to use as the x/z values + * @param y Y value of the new Vector3 + * @return + */ + public static Vector3m toVector3m(Vector2 o, double y) + { + return new Vector3m(o.x, y, o.z); + } + + /** + * Rounds the X and Y values of the given Vector2 up to + * the nearest integer value. + * + * @param o Vector2 to use + * @return + */ + public static Vector2 ceil(Vector2 o) + { + return new Vector2(Math.ceil(o.x), Math.ceil(o.z)); + } + + /** + * Rounds the X and Y values of the given Vector2 down to + * the nearest integer value. + * + * @param o Vector2 to use + * @return + */ + public static Vector2 floor(Vector2 o) + { + return new Vector2(Math.floor(o.x), Math.floor(o.z)); + } + + /** + * Rounds the X and Y values of the given Vector2 to + * the nearest integer value. + * + * @param o Vector2 to use + * @return + */ + public static Vector2 round(Vector2 o) + { + return new Vector2(Math.round(o.x), Math.round(o.z)); + } + + /** + * Sets the X and Y values of the given Vector2 to their + * absolute value. + * + * @param o Vector2 to use + * @return + */ + public static Vector2 abs(Vector2 o) + { + return new Vector2(Math.abs(o.x), Math.abs(o.z)); + } + + /** + * Returns a Vector2 containing the smallest X and Y values. + * + * @param o1 + * @param o2 + * @return + */ + public static Vector2 min(Vector2 o1, Vector2 o2) + { + return new Vector2(Math.min(o1.x, o2.x), Math.min(o1.z, o2.z)); + } + + /** + * Returns a Vector2 containing the largest X and Y values. + * + * @param o1 + * @param o2 + * @return + */ + public static Vector2 max(Vector2 o1, Vector2 o2) + { + return new Vector2(Math.max(o1.x, o2.x), Math.max(o1.z, o2.z)); + } + + /** + * Returns a Vector2 with random X and Y values (between 0 and 1) + * + * @param o + * @return + */ + public static Vector2 rand() + { + return new Vector2(Math.random(), Math.random()); + } + + /** + * Returns the provided Vector2 in an array. Element 0 contains x Element 1 + * contains y + * + * @return The array containing the Vector2 + */ + public static double[] toArray(Vector2 a) + { + return new double[] { a.getX(), a.getY() }; + } + + /** + * Compares two Vector3s + */ + public static int compareTo(Vector2 a, Vector2 b) + { + return (int)a.lengthSquared() - (int)b.lengthSquared(); + } + + /** + * Gets the distance between two Vector2. + * + * @param a + * @param b + * @return + */ + public static double distance(Vector2 a, Vector2 b) + { + Vector2 tempVector = Vector2.pow(Vector2.subtract(a, b), 2); + return Math.sqrt(tempVector.x + tempVector.z); + } + + /** + * Raises the X and Y values of a Vector2 to the given power. + * + * @param o + * @param power + * @return + */ + public static Vector2 pow(Vector2 o, double power) + { + return new Vector2(Math.pow(o.x, power), Math.pow(o.z, power)); + } + + /** + * Checks if two Vector2s are equal + */ + public static boolean equals(Object a, Object b) + { + if (!(a instanceof Vector2) || !(b instanceof Vector2)) + { + return false; + } + if (a == b) + { + return true; + } + return compareTo((Vector2)a, (Vector2)b) == 0; + } + + @Override + public String toString() + { + return "(" + this.x + ", " + this.z + ")"; + } + + @Override + public int hashCode() + { + return (int)(this.x % this.z); + } +} diff --git a/java/com/mumfrey/worldeditcui/util/Vector2m.java b/java/com/mumfrey/worldeditcui/util/Vector2m.java index c0b21987..e3dd0e31 100644 --- a/java/com/mumfrey/worldeditcui/util/Vector2m.java +++ b/java/com/mumfrey/worldeditcui/util/Vector2m.java @@ -1,146 +1,146 @@ -package com.mumfrey.worldeditcui.util; - -/** - * A version of Vector2 that can be modified. - * - * @author yetanotherx - */ -public class Vector2m extends Vector2 -{ - - public Vector2m() - { - } - - public Vector2m(Double x, Double y) - { - super(x, y); - } - - public Vector2m(float x, float y) - { - super(x, y); - } - - public Vector2m(Vector2 original) - { - super(original); - } - - /** - * Sets the X coordinate - * - * @param x The x coordinate - */ - public void setX(float x) - { - this.x = x; - } - - /** - * Sets the Y coordinate - * - * @param y The Y coordinate - */ - public void setY(float y) - { - this.z = y; - } - - @Override - public Vector2 add(Vector2 that) - { - this.x += that.x; - this.z += that.z; - return this; - } - - @Override - public Vector2 subtract(Vector2 that) - { - this.x -= that.x; - this.z -= that.z; - return this; - } - - @Override - public Vector2 scale(float scale) - { - this.x *= scale; - this.z *= scale; - return this; - } - - public Vector2 cross(Vector2 that) - { - float tmp = this.z; - this.z = -this.x; - this.x = tmp; - return this; - } - - /** - * Rounds the X and Y values of this Vector2 up to - * the nearest integer value. - * - * @return - */ - @Override - public Vector2 ceil() - { - this.x = (float)Math.ceil(this.x); - this.z = (float)Math.ceil(this.z); - return this; - } - - /** - * Rounds the X and Y values of this Vector2 down to - * the nearest integer value. - * - * @return - */ - @Override - public Vector2 floor() - { - this.x = (float)Math.floor(this.x); - this.z = (float)Math.floor(this.z); - return this; - } - - /** - * Rounds the X and Y values of this Vector2 to - * the nearest integer value. - * - * @return - */ - @Override - public Vector2 round() - { - this.x = Math.round(this.x); - this.z = Math.round(this.z); - return this; - } - - /** - * Sets the X and Y values of this Vector2 to their - * absolute value. - * - * @return - */ - @Override - public Vector2 abs() - { - this.x = Math.abs(this.x); - this.z = Math.abs(this.z); - return this; - } - - @Override - public Vector2 normalize() - { - float length = this.length(); - this.x *= 1 / length; - this.z *= 1 / length; - return this; - } -} +package com.mumfrey.worldeditcui.util; + +/** + * A version of Vector2 that can be modified. + * + * @author yetanotherx + */ +public class Vector2m extends Vector2 +{ + + public Vector2m() + { + } + + public Vector2m(Double x, Double y) + { + super(x, y); + } + + public Vector2m(float x, float y) + { + super(x, y); + } + + public Vector2m(Vector2 original) + { + super(original); + } + + /** + * Sets the X coordinate + * + * @param x The x coordinate + */ + public void setX(float x) + { + this.x = x; + } + + /** + * Sets the Y coordinate + * + * @param y The Y coordinate + */ + public void setY(float y) + { + this.z = y; + } + + @Override + public Vector2 add(Vector2 that) + { + this.x += that.x; + this.z += that.z; + return this; + } + + @Override + public Vector2 subtract(Vector2 that) + { + this.x -= that.x; + this.z -= that.z; + return this; + } + + @Override + public Vector2 scale(double scale) + { + this.x *= scale; + this.z *= scale; + return this; + } + + public Vector2 cross(Vector2 that) + { + double tmp = this.z; + this.z = -this.x; + this.x = tmp; + return this; + } + + /** + * Rounds the X and Y values of this Vector2 up to + * the nearest integer value. + * + * @return + */ + @Override + public Vector2 ceil() + { + this.x = (float)Math.ceil(this.x); + this.z = (float)Math.ceil(this.z); + return this; + } + + /** + * Rounds the X and Y values of this Vector2 down to + * the nearest integer value. + * + * @return + */ + @Override + public Vector2 floor() + { + this.x = (float)Math.floor(this.x); + this.z = (float)Math.floor(this.z); + return this; + } + + /** + * Rounds the X and Y values of this Vector2 to + * the nearest integer value. + * + * @return + */ + @Override + public Vector2 round() + { + this.x = Math.round(this.x); + this.z = Math.round(this.z); + return this; + } + + /** + * Sets the X and Y values of this Vector2 to their + * absolute value. + * + * @return + */ + @Override + public Vector2 abs() + { + this.x = Math.abs(this.x); + this.z = Math.abs(this.z); + return this; + } + + @Override + public Vector2 normalize() + { + double length = this.length(); + this.x *= 1 / length; + this.z *= 1 / length; + return this; + } +} diff --git a/java/com/mumfrey/worldeditcui/util/Vector3.java b/java/com/mumfrey/worldeditcui/util/Vector3.java index 2fdf0122..1e7b80f7 100644 --- a/java/com/mumfrey/worldeditcui/util/Vector3.java +++ b/java/com/mumfrey/worldeditcui/util/Vector3.java @@ -1,639 +1,656 @@ -package com.mumfrey.worldeditcui.util; - -/** - * Represents a 3d vector. - */ -public class Vector3 implements Comparable -{ - - /** - * Vector with all elements set to 0. (0, 0, 0) - */ - public final static Vector3 ZERO = new Vector3(0, 0, 0); - /** - * Unit Vector in the X direction. (1, 0, 0) - */ - public final static Vector3 UNIT_X = new Vector3(1, 0, 0); - /** - * Unit Vector facing Forward. (1, 0, 0) - */ - public final static Vector3 Forward = UNIT_X; - /** - * Unit Vector in the Y direction. (0, 1, 0) - */ - public final static Vector3 UNIT_Y = new Vector3(0, 1, 0); - /** - * Unit Vector pointing Up. (0, 1, 0) - */ - public final static Vector3 Up = UNIT_Y; - /** - * Unit Vector in the Z direction. (0, 0, 1) - */ - public final static Vector3 UNIT_Z = new Vector3(0, 0, 1); - /** - * Unit Vector pointing Right. (0, 0, 1) - */ - public final static Vector3 Right = UNIT_Z; - /** - * Unit Vector with all elements set to 1. (1, 1, 1) - */ - public final static Vector3 ONE = new Vector3(1, 1, 1); - protected float x, y, z; - - /** - * Constructs a new Vector3 with the given x, y, z - * - * @param x - * @param y - * @param z - */ - public Vector3(float x, float y, float z) - { - this.x = x; - this.y = y; - this.z = z; - } - - /** - * Constructs a new Vector3 with the given x, y, z - * - * @param x - * @param y - * @param z - */ - public Vector3(Double x, Double y, Double z) - { - this(x.floatValue(), y.floatValue(), z.floatValue()); - } - - /** - * Constructs a new Vector3 with all elements set to 0 - */ - public Vector3() - { - this(0, 0, 0); - } - - /** - * Constructs a new Vector3 that is a clone of the given vector3 - * - * @param clone - */ - public Vector3(Vector3 clone) - { - this(clone.getX(), clone.getY(), clone.getZ()); - } - - /** - * Constructs a new Vector3 from the given Vector2 and z - * - * @param vector - * @param z - */ - public Vector3(Vector2 vector, float z) - { - this(vector.getX(), vector.getY(), z); - } - - /** - * Constructs a new Vector3 from the given Vector2 and z set to 0 - * - * @param vector - */ - public Vector3(Vector2 vector) - { - this(vector, 0); - } - - public float getX() - { - return this.x; - } - - public float getY() - { - return this.y; - } - - public float getZ() - { - return this.z; - } - - /** - * Adds two vectors - * - * @param that - * @return - */ - public Vector3 add(Vector3 that) - { - return Vector3.add(this, that); - } - - /** - * Subtracts two vectors - * - * @param that - * @return - */ - public Vector3 subtract(Vector3 that) - { - return Vector3.subtract(this, that); - } - - /** - * Scales by the scalar value - * - * @param scale - * @return - */ - public Vector3 scale(float scale) - { - return Vector3.scale(this, scale); - } - - /** - * Takes the dot product of two vectors - * - * @param that - * @return - */ - public float dot(Vector3 that) - { - return Vector3.dot(this, that); - } - - /** - * Takes the cross product of two vectors - * - * @param that - * @return - */ - public Vector3 cross(Vector3 that) - { - return Vector3.cross(this, that); - } - - /** - * Returns a Vector2 object using the X and Z values of - * this Vector3. The x of this Vector3 becomes the x - * of the Vector2, and the z of this Vector3 becomes the - * y of the Vector2. - * - * @return - */ - public Vector2 toVector2() - { - return Vector3.toVector2(this); - } - - /** - * Returns a Vector2m object using the X and Z values of - * this Vector3. The x of this Vector3 becomes the x - * of the Vector2, and the z of this Vector3 becomes the - * y of the Vector2m. - * - * @return - */ - public Vector2m toVector2m() - { - return Vector3.toVector2m(this); - } - - /** - * Rounds the X, Y, and Z values of this Vector3 up to - * the nearest integer value. - * - * @return - */ - public Vector3 ceil() - { - return new Vector3(Math.ceil(this.x), Math.ceil(this.y), Math.ceil(this.z)); - } - - /** - * Rounds the X, Y, and Z values of this Vector3 down to - * the nearest integer value. - * - * @return - */ - public Vector3 floor() - { - return new Vector3(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z)); - } - - /** - * Rounds the X, Y, and Z values of this Vector3 to - * the nearest integer value. - * - * @return - */ - public Vector3 round() - { - return new Vector3(Math.round(this.x), Math.round(this.y), Math.round(this.z)); - } - - /** - * Sets the X, Y, and Z values of this Vector3 to their - * absolute value. - * - * @return - */ - public Vector3 abs() - { - return new Vector3(Math.abs(this.x), Math.abs(this.y), Math.abs(this.z)); - } - - /** - * Gets the distance between this Vector3 and a given Vector3. - * - * @param a - * @return - */ - public double distance(Vector3 a) - { - return Vector3.distance(a, this); - } - - /** - * Raises the X, Y, and Z values of this Vector3 to the given power. - * - * @param power - * @return - */ - public Vector3 pow(double power) - { - return Vector3.pow(this, power); - } - - /** - * returns the squared length of the vector - * - * @return - */ - public float lengthSquared() - { - return Vector3.lengthSquared(this); - } - - /** - * returns the length of this vector. Note: makes use of Math.sqrt and is - * not cached. - * - * @return - */ - public float length() - { - return Vector3.length(this); - } - - /** - * Returns a fast approximation of this vector's length. - * - * @return - */ - public float fastLength() - { - return Vector3.fastLength(this); - } - - /** - * returns the vector with a length of 1 - * - * @return - */ - public Vector3 normalize() - { - return Vector3.normalize(this); - } - - /** - * returns the vector as [x,y,z] - * - * @return - */ - public float[] toArray() - { - return Vector3.toArray(this); - } - - /** - * Compares two Vector3s - */ - @Override - public int compareTo(Vector3 o) - { - return Vector3.compareTo(this, o); - } - - /** - * Checks if two Vector3s are equal - */ - @Override - public boolean equals(Object o) - { - return Vector3.equals(this, o); - } - - /** - * toString Override - */ - @Override - public String toString() - { - return String.format("{ %f, %f, %f }", this.x, this.y, this.z); - } - - /** - * Returns the length of the given vector. - * - * Note: Makes use of Math.sqrt and - * is not cached, so can be slow - * - * Also known as norm. ||a|| - * - * @param a - * @return - */ - public static float length(Vector3 a) - { - return (float)Math.sqrt(lengthSquared(a)); - } - - /** - * Returns an approximate length of the given vector. - * - * @param a - * @return - */ - public static float fastLength(Vector3 a) - { - return (float)Math.sqrt(lengthSquared(a)); - } - - /** - * returns the length squared to the given vector - * - * @param a - * @return - */ - public static float lengthSquared(Vector3 a) - { - return Vector3.dot(a, a); - } - - /** - * Returns a new vector that is the given vector but length 1 - * - * @param a - * @return - */ - public static Vector3 normalize(Vector3 a) - { - return Vector3.scale(a, (1.f / a.length())); - } - - /** - * Creates a new vector that is A - B - * - * @param a - * @param b - * @return - */ - public static Vector3 subtract(Vector3 a, Vector3 b) - { - return new Vector3(a.getX() - b.getX(), a.getY() - b.getY(), a.getZ() - b.getZ()); - } - - /** - * Creates a new Vector that is A + B - * - * @param a - * @param b - * @return - */ - public static Vector3 add(Vector3 a, Vector3 b) - { - return new Vector3(a.getX() + b.getX(), a.getY() + b.getY(), a.getZ() + b.getZ()); - } - - /** - * Creates a new vector that is A multiplied by the uniform scalar B - * - * @param a - * @param b - * @return - */ - public static Vector3 scale(Vector3 a, float b) - { - return new Vector3(a.getX() * b, a.getY() * b, a.getZ() * b); - } - - /** - * Returns the dot product of A and B - * - * @param a - * @param b - * @return - */ - public static float dot(Vector3 a, Vector3 b) - { - return a.getX() * b.getX() + a.getY() * b.getY() + a.getZ() * b.getZ(); - } - - /** - * Creates a new Vector that is the A x B The Cross Product is the vector - * orthogonal to both A and B - * - * @param a - * @param b - * @return - */ - public static Vector3 cross(Vector3 a, Vector3 b) - { - return new Vector3(a.getY() * b.getZ() - a.getZ() * b.getY(), a.getZ() * b.getX() - a.getX() * b.getZ(), a.getX() * b.getY() - a.getY() * b.getX()); - } - - /** - * Rounds the X, Y, and Z values of the given Vector3 up to - * the nearest integer value. - * - * @param o Vector3 to use - * @return - */ - public static Vector3 ceil(Vector3 o) - { - return new Vector3(Math.ceil(o.x), Math.ceil(o.y), Math.ceil(o.z)); - } - - /** - * Rounds the X, Y, and Z values of the given Vector3 down to - * the nearest integer value. - * - * @param o Vector3 to use - * @return - */ - public static Vector3 floor(Vector3 o) - { - return new Vector3(Math.floor(o.x), Math.floor(o.y), Math.floor(o.z)); - } - - /** - * Rounds the X, Y, and Z values of the given Vector3 to - * the nearest integer value. - * - * @param o Vector3 to use - * @return - */ - public static Vector3 round(Vector3 o) - { - return new Vector3(Math.round(o.x), Math.round(o.y), Math.round(o.z)); - } - - /** - * Sets the X, Y, and Z values of the given Vector3 to their - * absolute value. - * - * @param o Vector3 to use - * @return - */ - public static Vector3 abs(Vector3 o) - { - return new Vector3(Math.abs(o.x), Math.abs(o.y), Math.abs(o.z)); - } - - /** - * Returns a Vector3 containing the smallest X, Y, and Z values. - * - * @param o1 - * @param o2 - * @return - */ - public static Vector3 min(Vector3 o1, Vector3 o2) - { - return new Vector3(Math.min(o1.x, o2.x), Math.min(o1.y, o2.y), Math.min(o1.z, o2.z)); - } - - /** - * Returns a Vector3 containing the largest X, Y, and Z values. - * - * @param o1 - * @param o2 - * @return - */ - public static Vector3 max(Vector3 o1, Vector3 o2) - { - return new Vector3(Math.max(o1.x, o2.x), Math.max(o1.y, o2.y), Math.max(o1.z, o2.z)); - } - - /** - * Returns a Vector3 with random X, Y, and Z values (between 0 and 1) - * - * @return - */ - public static Vector3 rand() - { - return new Vector3(Math.random(), Math.random(), Math.random()); - } - - /** - * Gets the distance between two Vector3. - * - * @param a - * @param b - * @return - */ - public static double distance(Vector3 a, Vector3 b) - { - double xzDist = Vector2.distance(a.toVector2(), b.toVector2()); - return Math.sqrt(Math.pow(xzDist, 2) + Math.pow(Math.abs(Vector3.subtract(a, b).getY()), 2)); - } - - /** - * Raises the X, Y, and Z values of a Vector3 to the given power. - * - * @param o - * @param power - * @return - */ - public static Vector3 pow(Vector3 o, double power) - { - return new Vector3(Math.pow(o.x, power), Math.pow(o.y, power), Math.pow(o.z, power)); - } - - /** - * Returns a Vector2 object using the X and Z values of - * the given Vector3. The x of the Vector3 becomes the x - * of the Vector2, and the z of this Vector3 becomes the - * y of the Vector2m. - * - * @param o Vector3 object to use - * @return - */ - public static Vector2 toVector2(Vector3 o) - { - return new Vector2(o.x, o.z); - } - - /** - * Returns a Vector2m object using the X and Z values of - * the given Vector3. The x of the Vector3 becomes the x - * of the Vector2m, and the z of this Vector3 becomes the - * y of the Vector2m. - * - * @param o Vector3 object to use - * @return - */ - public static Vector2m toVector2m(Vector3 o) - { - return new Vector2m(o.x, o.z); - } - - /** - * Returns a new float array that is {x, y, z} - * - * @param a - * @return - */ - public static float[] toArray(Vector3 a) - { - return new float[] { a.getX(), a.getY(), a.getZ() }; - } - - /** - * Compares two Vector3s - */ - public static int compareTo(Vector3 a, Vector3 b) - { - return (int)a.lengthSquared() - (int)b.lengthSquared(); - } - - /** - * Checks if two Vector3s are equal - */ - public static boolean equals(Object a, Object b) - { - if (!(a instanceof Vector3) || !(b instanceof Vector3)) - { - return false; - } - if (a == b) - { - return true; - } - Vector3 x = (Vector3)a; - Vector3 y = (Vector3)b; - if (x.getX() == y.getX() && x.getY() == y.getY() && x.getZ() == y.getZ()) - { - return true; - } - return false; - } - - @Override - public int hashCode() - { - return (int)(this.x * this.y % this.z); - } -} +package com.mumfrey.worldeditcui.util; + +import net.minecraft.entity.Entity; + +/** + * Represents a 3d vector. + */ +public class Vector3 implements Comparable +{ + + /** + * Vector with all elements set to 0. (0, 0, 0) + */ + public final static Vector3 ZERO = new Vector3(0, 0, 0); + /** + * Unit Vector in the X direction. (1, 0, 0) + */ + public final static Vector3 UNIT_X = new Vector3(1, 0, 0); + /** + * Unit Vector facing Forward. (1, 0, 0) + */ + public final static Vector3 Forward = UNIT_X; + /** + * Unit Vector in the Y direction. (0, 1, 0) + */ + public final static Vector3 UNIT_Y = new Vector3(0, 1, 0); + /** + * Unit Vector pointing Up. (0, 1, 0) + */ + public final static Vector3 Up = UNIT_Y; + /** + * Unit Vector in the Z direction. (0, 0, 1) + */ + public final static Vector3 UNIT_Z = new Vector3(0, 0, 1); + /** + * Unit Vector pointing Right. (0, 0, 1) + */ + public final static Vector3 Right = UNIT_Z; + /** + * Unit Vector with all elements set to 1. (1, 1, 1) + */ + public final static Vector3 ONE = new Vector3(1, 1, 1); + protected double x, y, z; + + /** + * Constructs a new Vector3 for the specified entity's position + * + * @param entity + * @param partialTicks + */ + public Vector3(Entity entity, double partialTicks) + { + this( + entity.prevPosX + ((entity.posX - entity.prevPosX) * partialTicks), + entity.prevPosY + ((entity.posY - entity.prevPosY) * partialTicks), + entity.prevPosZ + ((entity.posZ - entity.prevPosZ) * partialTicks) + ); + } + + /** + * Constructs a new Vector3 with the given x, y, z + * + * @param x + * @param y + * @param z + */ + public Vector3(double x, double y, double z) + { + this.x = x; + this.y = y; + this.z = z; + } + + /** + * Constructs a new Vector3 with the given x, y, z + * + * @param x + * @param y + * @param z + */ + public Vector3(Double x, Double y, Double z) + { + this(x.doubleValue(), y.doubleValue(), z.doubleValue()); + } + + /** + * Constructs a new Vector3 with all elements set to 0 + */ + public Vector3() + { + this(0, 0, 0); + } + + /** + * Constructs a new Vector3 that is a clone of the given vector3 + * + * @param clone + */ + public Vector3(Vector3 clone) + { + this(clone.getX(), clone.getY(), clone.getZ()); + } + + /** + * Constructs a new Vector3 from the given Vector2 and z + * + * @param vector + * @param z + */ + public Vector3(Vector2 vector, double z) + { + this(vector.getX(), vector.getY(), z); + } + + /** + * Constructs a new Vector3 from the given Vector2 and z set to 0 + * + * @param vector + */ + public Vector3(Vector2 vector) + { + this(vector, 0); + } + + public double getX() + { + return this.x; + } + + public double getY() + { + return this.y; + } + + public double getZ() + { + return this.z; + } + + /** + * Adds two vectors + * + * @param that + * @return + */ + public Vector3 add(Vector3 that) + { + return Vector3.add(this, that); + } + + /** + * Subtracts two vectors + * + * @param that + * @return + */ + public Vector3 subtract(Vector3 that) + { + return Vector3.subtract(this, that); + } + + /** + * Scales by the scalar value + * + * @param scale + * @return + */ + public Vector3 scale(double scale) + { + return Vector3.scale(this, scale); + } + + /** + * Takes the dot product of two vectors + * + * @param that + * @return + */ + public double dot(Vector3 that) + { + return Vector3.dot(this, that); + } + + /** + * Takes the cross product of two vectors + * + * @param that + * @return + */ + public Vector3 cross(Vector3 that) + { + return Vector3.cross(this, that); + } + + /** + * Returns a Vector2 object using the X and Z values of + * this Vector3. The x of this Vector3 becomes the x + * of the Vector2, and the z of this Vector3 becomes the + * y of the Vector2. + * + * @return + */ + public Vector2 toVector2() + { + return Vector3.toVector2(this); + } + + /** + * Returns a Vector2m object using the X and Z values of + * this Vector3. The x of this Vector3 becomes the x + * of the Vector2, and the z of this Vector3 becomes the + * y of the Vector2m. + * + * @return + */ + public Vector2m toVector2m() + { + return Vector3.toVector2m(this); + } + + /** + * Rounds the X, Y, and Z values of this Vector3 up to + * the nearest integer value. + * + * @return + */ + public Vector3 ceil() + { + return new Vector3(Math.ceil(this.x), Math.ceil(this.y), Math.ceil(this.z)); + } + + /** + * Rounds the X, Y, and Z values of this Vector3 down to + * the nearest integer value. + * + * @return + */ + public Vector3 floor() + { + return new Vector3(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z)); + } + + /** + * Rounds the X, Y, and Z values of this Vector3 to + * the nearest integer value. + * + * @return + */ + public Vector3 round() + { + return new Vector3(Math.round(this.x), Math.round(this.y), Math.round(this.z)); + } + + /** + * Sets the X, Y, and Z values of this Vector3 to their + * absolute value. + * + * @return + */ + public Vector3 abs() + { + return new Vector3(Math.abs(this.x), Math.abs(this.y), Math.abs(this.z)); + } + + /** + * Gets the distance between this Vector3 and a given Vector3. + * + * @param a + * @return + */ + public double distance(Vector3 a) + { + return Vector3.distance(a, this); + } + + /** + * Raises the X, Y, and Z values of this Vector3 to the given power. + * + * @param power + * @return + */ + public Vector3 pow(double power) + { + return Vector3.pow(this, power); + } + + /** + * returns the squared length of the vector + * + * @return + */ + public double lengthSquared() + { + return Vector3.lengthSquared(this); + } + + /** + * returns the length of this vector. Note: makes use of Math.sqrt and is + * not cached. + * + * @return + */ + public double length() + { + return Vector3.length(this); + } + + /** + * Returns a fast approximation of this vector's length. + * + * @return + */ + public double fastLength() + { + return Vector3.fastLength(this); + } + + /** + * returns the vector with a length of 1 + * + * @return + */ + public Vector3 normalize() + { + return Vector3.normalize(this); + } + + /** + * returns the vector as [x,y,z] + * + * @return + */ + public double[] toArray() + { + return Vector3.toArray(this); + } + + /** + * Compares two Vector3s + */ + @Override + public int compareTo(Vector3 o) + { + return Vector3.compareTo(this, o); + } + + /** + * Checks if two Vector3s are equal + */ + @Override + public boolean equals(Object o) + { + return Vector3.equals(this, o); + } + + /** + * toString Override + */ + @Override + public String toString() + { + return String.format("{ %f, %f, %f }", this.x, this.y, this.z); + } + + /** + * Returns the length of the given vector. + * + * Note: Makes use of Math.sqrt and + * is not cached, so can be slow + * + * Also known as norm. ||a|| + * + * @param a + * @return + */ + public static double length(Vector3 a) + { + return Math.sqrt(lengthSquared(a)); + } + + /** + * Returns an approximate length of the given vector. + * + * @param a + * @return + */ + public static double fastLength(Vector3 a) + { + return Math.sqrt(lengthSquared(a)); + } + + /** + * returns the length squared to the given vector + * + * @param a + * @return + */ + public static double lengthSquared(Vector3 a) + { + return Vector3.dot(a, a); + } + + /** + * Returns a new vector that is the given vector but length 1 + * + * @param a + * @return + */ + public static Vector3 normalize(Vector3 a) + { + return Vector3.scale(a, (1.f / a.length())); + } + + /** + * Creates a new vector that is A - B + * + * @param a + * @param b + * @return + */ + public static Vector3 subtract(Vector3 a, Vector3 b) + { + return new Vector3(a.getX() - b.getX(), a.getY() - b.getY(), a.getZ() - b.getZ()); + } + + /** + * Creates a new Vector that is A + B + * + * @param a + * @param b + * @return + */ + public static Vector3 add(Vector3 a, Vector3 b) + { + return new Vector3(a.getX() + b.getX(), a.getY() + b.getY(), a.getZ() + b.getZ()); + } + + /** + * Creates a new vector that is A multiplied by the uniform scalar B + * + * @param a + * @param b + * @return + */ + public static Vector3 scale(Vector3 a, double b) + { + return new Vector3(a.getX() * b, a.getY() * b, a.getZ() * b); + } + + /** + * Returns the dot product of A and B + * + * @param a + * @param b + * @return + */ + public static double dot(Vector3 a, Vector3 b) + { + return a.getX() * b.getX() + a.getY() * b.getY() + a.getZ() * b.getZ(); + } + + /** + * Creates a new Vector that is the A x B The Cross Product is the vector + * orthogonal to both A and B + * + * @param a + * @param b + * @return + */ + public static Vector3 cross(Vector3 a, Vector3 b) + { + return new Vector3(a.getY() * b.getZ() - a.getZ() * b.getY(), a.getZ() * b.getX() - a.getX() * b.getZ(), a.getX() * b.getY() - a.getY() * b.getX()); + } + + /** + * Rounds the X, Y, and Z values of the given Vector3 up to + * the nearest integer value. + * + * @param o Vector3 to use + * @return + */ + public static Vector3 ceil(Vector3 o) + { + return new Vector3(Math.ceil(o.x), Math.ceil(o.y), Math.ceil(o.z)); + } + + /** + * Rounds the X, Y, and Z values of the given Vector3 down to + * the nearest integer value. + * + * @param o Vector3 to use + * @return + */ + public static Vector3 floor(Vector3 o) + { + return new Vector3(Math.floor(o.x), Math.floor(o.y), Math.floor(o.z)); + } + + /** + * Rounds the X, Y, and Z values of the given Vector3 to + * the nearest integer value. + * + * @param o Vector3 to use + * @return + */ + public static Vector3 round(Vector3 o) + { + return new Vector3(Math.round(o.x), Math.round(o.y), Math.round(o.z)); + } + + /** + * Sets the X, Y, and Z values of the given Vector3 to their + * absolute value. + * + * @param o Vector3 to use + * @return + */ + public static Vector3 abs(Vector3 o) + { + return new Vector3(Math.abs(o.x), Math.abs(o.y), Math.abs(o.z)); + } + + /** + * Returns a Vector3 containing the smallest X, Y, and Z values. + * + * @param o1 + * @param o2 + * @return + */ + public static Vector3 min(Vector3 o1, Vector3 o2) + { + return new Vector3(Math.min(o1.x, o2.x), Math.min(o1.y, o2.y), Math.min(o1.z, o2.z)); + } + + /** + * Returns a Vector3 containing the largest X, Y, and Z values. + * + * @param o1 + * @param o2 + * @return + */ + public static Vector3 max(Vector3 o1, Vector3 o2) + { + return new Vector3(Math.max(o1.x, o2.x), Math.max(o1.y, o2.y), Math.max(o1.z, o2.z)); + } + + /** + * Returns a Vector3 with random X, Y, and Z values (between 0 and 1) + * + * @return + */ + public static Vector3 rand() + { + return new Vector3(Math.random(), Math.random(), Math.random()); + } + + /** + * Gets the distance between two Vector3. + * + * @param a + * @param b + * @return + */ + public static double distance(Vector3 a, Vector3 b) + { + double xzDist = Vector2.distance(a.toVector2(), b.toVector2()); + return Math.sqrt(Math.pow(xzDist, 2) + Math.pow(Math.abs(Vector3.subtract(a, b).getY()), 2)); + } + + /** + * Raises the X, Y, and Z values of a Vector3 to the given power. + * + * @param o + * @param power + * @return + */ + public static Vector3 pow(Vector3 o, double power) + { + return new Vector3(Math.pow(o.x, power), Math.pow(o.y, power), Math.pow(o.z, power)); + } + + /** + * Returns a Vector2 object using the X and Z values of + * the given Vector3. The x of the Vector3 becomes the x + * of the Vector2, and the z of this Vector3 becomes the + * y of the Vector2m. + * + * @param o Vector3 object to use + * @return + */ + public static Vector2 toVector2(Vector3 o) + { + return new Vector2(o.x, o.z); + } + + /** + * Returns a Vector2m object using the X and Z values of + * the given Vector3. The x of the Vector3 becomes the x + * of the Vector2m, and the z of this Vector3 becomes the + * y of the Vector2m. + * + * @param o Vector3 object to use + * @return + */ + public static Vector2m toVector2m(Vector3 o) + { + return new Vector2m(o.x, o.z); + } + + /** + * Returns a new double array that is {x, y, z} + * + * @param a + * @return + */ + public static double[] toArray(Vector3 a) + { + return new double[] { a.getX(), a.getY(), a.getZ() }; + } + + /** + * Compares two Vector3s + */ + public static int compareTo(Vector3 a, Vector3 b) + { + return (int)a.lengthSquared() - (int)b.lengthSquared(); + } + + /** + * Checks if two Vector3s are equal + */ + public static boolean equals(Object a, Object b) + { + if (!(a instanceof Vector3) || !(b instanceof Vector3)) + { + return false; + } + if (a == b) + { + return true; + } + Vector3 x = (Vector3)a; + Vector3 y = (Vector3)b; + if (x.getX() == y.getX() && x.getY() == y.getY() && x.getZ() == y.getZ()) + { + return true; + } + return false; + } + + @Override + public int hashCode() + { + return (int)(this.x * this.y % this.z); + } +} diff --git a/java/com/mumfrey/worldeditcui/util/Vector3m.java b/java/com/mumfrey/worldeditcui/util/Vector3m.java index 7bd5b080..ea1f840b 100644 --- a/java/com/mumfrey/worldeditcui/util/Vector3m.java +++ b/java/com/mumfrey/worldeditcui/util/Vector3m.java @@ -1,185 +1,185 @@ -package com.mumfrey.worldeditcui.util; - -/** - * A version of Vector3 that can be modified. - * - * @author yetanotherx - */ -public class Vector3m extends Vector3 -{ - - public Vector3m(float x, float y, float z) - { - super(x, y, z); - } - - public Vector3m(Double x, Double y, Double z) - { - super(x, y, z); - } - - public Vector3m(Vector3 vector) - { - super(vector); - } - - public Vector3m() - { - } - - public void setZ(float z) - { - this.z = z; - } - - public void setY(float y) - { - this.y = y; - } - - public void setX(float x) - { - this.x = x; - } - - /** - * Adds two vectors - * - * @param that - * @return - */ - - @Override - public Vector3 add(Vector3 that) - { - this.x += that.x; - this.y += that.y; - this.z += that.z; - return this; - } - - /** - * Subtracts two vectors - * - * @param that - * @return - */ - - @Override - public Vector3 subtract(Vector3 that) - { - this.x -= that.x; - this.y -= that.y; - this.z -= that.z; - return this; - } - - /** - * Scales by the scalar value - * - * @param scale - * @return - */ - - @Override - public Vector3 scale(float scale) - { - this.x *= scale; - this.y *= scale; - this.z *= scale; - return this; - } - - /** - * Takes the cross product of two vectors - * - * @param that - * @return - */ - - @Override - public Vector3 cross(Vector3 that) - { - this.x = this.getY() * that.getZ() - this.getZ() * that.getY(); - this.y = this.getZ() * that.getX() - this.getX() * that.getZ(); - this.z = this.getX() * that.getY() - this.getY() * that.getX(); - - return this; - } - - /** - * Rounds the X, Y, and Z values of this Vector3 up to - * the nearest integer value. - * - * @return - */ - @Override - public Vector3 ceil() - { - this.x = (float)Math.ceil(this.x); - this.y = (float)Math.ceil(this.y); - this.z = (float)Math.ceil(this.z); - return this; - } - - /** - * Rounds the X, Y, and Z values of this Vector3 down to - * the nearest integer value. - * - * @return - */ - @Override - public Vector3 floor() - { - this.x = (float)Math.floor(this.x); - this.y = (float)Math.floor(this.y); - this.z = (float)Math.floor(this.z); - return this; - } - - /** - * Rounds the X, Y, and Z values of this Vector3 to - * the nearest integer value. - * - * @return - */ - @Override - public Vector3 round() - { - this.x = Math.round(this.x); - this.y = Math.round(this.y); - this.z = Math.round(this.z); - return this; - } - - /** - * Sets the X, Y, and Z values of this Vector3 to their - * absolute value. - * - * @return - */ - @Override - public Vector3 abs() - { - this.x = Math.abs(this.x); - this.y = Math.abs(this.y); - this.z = Math.abs(this.z); - return this; - } - - /** - * returns the vector with a length of 1 - * - * @return - */ - - @Override - public Vector3 normalize() - { - float length = this.length(); - this.x *= 1 / length; - this.y *= 1 / length; - this.z *= 1 / length; - return this; - } -} +package com.mumfrey.worldeditcui.util; + +/** + * A version of Vector3 that can be modified. + * + * @author yetanotherx + */ +public class Vector3m extends Vector3 +{ + + public Vector3m(double x, double y, double z) + { + super(x, y, z); + } + + public Vector3m(Double x, Double y, Double z) + { + super(x, y, z); + } + + public Vector3m(Vector3 vector) + { + super(vector); + } + + public Vector3m() + { + } + + public void setZ(double z) + { + this.z = z; + } + + public void setY(double y) + { + this.y = y; + } + + public void setX(double x) + { + this.x = x; + } + + /** + * Adds two vectors + * + * @param that + * @return + */ + + @Override + public Vector3 add(Vector3 that) + { + this.x += that.x; + this.y += that.y; + this.z += that.z; + return this; + } + + /** + * Subtracts two vectors + * + * @param that + * @return + */ + + @Override + public Vector3 subtract(Vector3 that) + { + this.x -= that.x; + this.y -= that.y; + this.z -= that.z; + return this; + } + + /** + * Scales by the scalar value + * + * @param scale + * @return + */ + + @Override + public Vector3 scale(double scale) + { + this.x *= scale; + this.y *= scale; + this.z *= scale; + return this; + } + + /** + * Takes the cross product of two vectors + * + * @param that + * @return + */ + + @Override + public Vector3 cross(Vector3 that) + { + this.x = this.getY() * that.getZ() - this.getZ() * that.getY(); + this.y = this.getZ() * that.getX() - this.getX() * that.getZ(); + this.z = this.getX() * that.getY() - this.getY() * that.getX(); + + return this; + } + + /** + * Rounds the X, Y, and Z values of this Vector3 up to + * the nearest integer value. + * + * @return + */ + @Override + public Vector3 ceil() + { + this.x = Math.ceil(this.x); + this.y = Math.ceil(this.y); + this.z = Math.ceil(this.z); + return this; + } + + /** + * Rounds the X, Y, and Z values of this Vector3 down to + * the nearest integer value. + * + * @return + */ + @Override + public Vector3 floor() + { + this.x = Math.floor(this.x); + this.y = Math.floor(this.y); + this.z = Math.floor(this.z); + return this; + } + + /** + * Rounds the X, Y, and Z values of this Vector3 to + * the nearest integer value. + * + * @return + */ + @Override + public Vector3 round() + { + this.x = Math.round(this.x); + this.y = Math.round(this.y); + this.z = Math.round(this.z); + return this; + } + + /** + * Sets the X, Y, and Z values of this Vector3 to their + * absolute value. + * + * @return + */ + @Override + public Vector3 abs() + { + this.x = Math.abs(this.x); + this.y = Math.abs(this.y); + this.z = Math.abs(this.z); + return this; + } + + /** + * returns the vector with a length of 1 + * + * @return + */ + + @Override + public Vector3 normalize() + { + double lengthReciprocal = 1.0 / this.length(); + this.x *= lengthReciprocal; + this.y *= lengthReciprocal; + this.z *= lengthReciprocal; + return this; + } +} diff --git a/res/assets/wecui/lang/en_US.lang b/res/assets/wecui/lang/en_US.lang index 4bddd8f1..c162a650 100644 --- a/res/assets/wecui/lang/en_US.lang +++ b/res/assets/wecui/lang/en_US.lang @@ -21,5 +21,6 @@ colour.cylinderpoint=Cylinder Centre Point Colour gui.options.compat.title=Compatibility Options gui.options.compat.spammy=Promiscuous Mode (send /we cui all the time) +gui.options.compat.ontop=Always on top (mod compatibility) gui.options.colours.title=Display Colours From 4465061933b4bfc3f1714236704dc1b40db41d0c Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Thu, 5 Feb 2015 12:03:25 +0000 Subject: [PATCH 18/51] Refactor PointRectangle --- .../render/points/PointRectangle.java | 45 ++++++++++++++----- .../render/region/PolygonRegion.java | 15 ++++++- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/java/com/mumfrey/worldeditcui/render/points/PointRectangle.java b/java/com/mumfrey/worldeditcui/render/points/PointRectangle.java index 6d4147fc..121d5da2 100644 --- a/java/com/mumfrey/worldeditcui/render/points/PointRectangle.java +++ b/java/com/mumfrey/worldeditcui/render/points/PointRectangle.java @@ -16,27 +16,30 @@ */ public class PointRectangle { + private static final double OFF = 0.03; + private static final Vector2 MIN_VEC = new Vector2(PointRectangle.OFF, PointRectangle.OFF); + private static final Vector2 MAX_VEC = new Vector2(PointRectangle.OFF + 1, PointRectangle.OFF + 1); protected Vector2 point; protected LineColour colour = LineColour.POLYPOINT; - public PointRectangle(Vector2 point) + private int min, max; + + private Render3DBox box; + + public PointRectangle(int x, int z) { - this.point = point; + this(new Vector2(x, z)); } - public PointRectangle(int x, int z) + public PointRectangle(Vector2 point) { - this.point = new Vector2(x, z); + this.setPoint(point); } - public void render(Vector3 cameraPos, int min, int max) + public void render(Vector3 cameraPos) { - float off = 0.03f; - Vector2 minVec = new Vector2(off, off); - Vector2 maxVec = new Vector2(off + 1, off + 1); - - new Render3DBox(this.colour, this.point.subtract(minVec).toVector3(min - off), this.point.add(maxVec).toVector3(max + 1 + off)).render(cameraPos); + this.box.render(cameraPos); } public Vector2 getPoint() @@ -58,4 +61,26 @@ public void setColour(LineColour colour) { this.colour = colour; } + + public void setMinMax(int min, int max) + { + this.min = min; + this.max = max; + this.update(); + } + + public int getMin() + { + return this.min; + } + + public int getMax() + { + return this.max; + } + + private void update() + { + this.box = new Render3DBox(this.colour, this.point.subtract(PointRectangle.MIN_VEC).toVector3(this.min - 0.03f), this.point.add(PointRectangle.MAX_VEC).toVector3(this.max + 1 + 0.03f)); + } } diff --git a/java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java b/java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java index dc2ce525..897e27ee 100644 --- a/java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java @@ -41,7 +41,10 @@ public void render(Vector3 cameraPos) for (PointRectangle point : this.points) { - point.render(cameraPos, this.min, this.max); + if (point != null) + { + point.render(cameraPos); + } } this.box.render(cameraPos); @@ -61,6 +64,7 @@ public void setPolygonPoint(int id, int x, int z) { PointRectangle point = new PointRectangle(x, z); point.setColour(LineColour.POLYPOINT); + point.setMinMax(this.min, this.max); if (id < this.points.size()) { @@ -81,6 +85,14 @@ private void update() { if (this.points.size() > 0) { + for (PointRectangle point : this.points) + { + if (point != null) + { + point.setMinMax(this.min, this.max); + } + } + this.box = new Render2DBox(LineColour.POLYBOX, this.points, this.min, this.max); this.grid = new Render2DGrid(LineColour.POLYGRID, this.points, this.min, this.max); } @@ -92,3 +104,4 @@ public RegionType getType() return RegionType.POLYGON; } } + From 6a5acc968bd028c3c2488ddc2e26fa2b2b3cd966 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Thu, 5 Feb 2015 12:06:14 +0000 Subject: [PATCH 19/51] Purge the last of the american spellings --- .../worldeditcui/InitialisationFactory.java | 15 ++++++++++++++ .../worldeditcui/InitializationFactory.java | 15 -------------- .../worldeditcui/LiteModWorldEditCUI.java | 2 +- .../mumfrey/worldeditcui/WorldEditCUI.java | 16 +++++++-------- .../worldeditcui/config/CUIConfiguration.java | 10 +++++----- .../mumfrey/worldeditcui/debug/CUIDebug.java | 10 +++++----- .../event/CUIEventDispatcher.java | 8 ++++---- .../event/cui/CUIEventCylinder.java | 2 +- .../event/cui/CUIEventEllipsoid.java | 2 +- .../event/cui/CUIEventSelection.java | 2 +- ...tion.java => InitialisationException.java} | 8 ++++---- .../render/CUISelectionProvider.java | 8 ++++---- .../worldeditcui/render/LineColour.java | 4 ++-- .../render/region/BaseRegion.java | 6 +++--- .../render/region/CylinderRegion.java | 20 +++++++++---------- .../render/region/EllipsoidRegion.java | 2 +- .../render/shapes/RenderEllipsoid.java | 6 +++--- .../mumfrey/worldeditcui/util/Vector2.java | 8 ++++---- 18 files changed, 72 insertions(+), 72 deletions(-) create mode 100644 java/com/mumfrey/worldeditcui/InitialisationFactory.java delete mode 100644 java/com/mumfrey/worldeditcui/InitializationFactory.java rename java/com/mumfrey/worldeditcui/exceptions/{InitializationException.java => InitialisationException.java} (52%) diff --git a/java/com/mumfrey/worldeditcui/InitialisationFactory.java b/java/com/mumfrey/worldeditcui/InitialisationFactory.java new file mode 100644 index 00000000..6008c9c9 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/InitialisationFactory.java @@ -0,0 +1,15 @@ +package com.mumfrey.worldeditcui; + +import com.mumfrey.worldeditcui.exceptions.InitialisationException; + +/** + * Simple interface to trace what needs to be initialised at mod loading. + * Uses a unique exception to know when to halt initialisation and stop mod loading. + * + * @author yetanotherx + */ +public interface InitialisationFactory +{ + + public void initialise() throws InitialisationException; +} diff --git a/java/com/mumfrey/worldeditcui/InitializationFactory.java b/java/com/mumfrey/worldeditcui/InitializationFactory.java deleted file mode 100644 index 8eb14a52..00000000 --- a/java/com/mumfrey/worldeditcui/InitializationFactory.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.mumfrey.worldeditcui; - -import com.mumfrey.worldeditcui.exceptions.InitializationException; - -/** - * Simple interface to trace what needs to be initialized at mod loading. - * Uses a unique exception to know when to halt initialization and stop mod loading. - * - * @author yetanotherx - */ -public interface InitializationFactory -{ - - public void initialize() throws InitializationException; -} diff --git a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java index 3451d03d..829e6c00 100644 --- a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java @@ -74,7 +74,7 @@ public void upgradeSettings(String version, File configPath, File oldConfigPath) public void onInitCompleted(Minecraft minecraft, LiteLoader loader) { this.controller = new WorldEditCUI(); - this.controller.initialize(); + this.controller.initialise(); this.worldRenderListener = new CUIListenerWorldRender(this.controller, minecraft); this.channelListener = new CUIListenerChannel(this.controller); diff --git a/java/com/mumfrey/worldeditcui/WorldEditCUI.java b/java/com/mumfrey/worldeditcui/WorldEditCUI.java index dc2d2374..cf5be8fd 100644 --- a/java/com/mumfrey/worldeditcui/WorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/WorldEditCUI.java @@ -3,7 +3,7 @@ import com.mumfrey.worldeditcui.config.CUIConfiguration; import com.mumfrey.worldeditcui.debug.CUIDebug; import com.mumfrey.worldeditcui.event.CUIEventDispatcher; -import com.mumfrey.worldeditcui.exceptions.InitializationException; +import com.mumfrey.worldeditcui.exceptions.InitialisationException; import com.mumfrey.worldeditcui.render.CUISelectionProvider; import com.mumfrey.worldeditcui.render.region.BaseRegion; import com.mumfrey.worldeditcui.render.region.CuboidRegion; @@ -28,7 +28,7 @@ public class WorldEditCUI private CUIEventDispatcher dispatcher; private CUISelectionProvider selectionProvider; - public void initialize() + public void initialise() { this.selection = new CuboidRegion(this); this.configuration = CUIConfiguration.create(); @@ -38,13 +38,13 @@ public void initialize() try { - this.selection.initialize(); - this.configuration.initialize(); - this.debugger.initialize(); - this.dispatcher.initialize(); - this.selectionProvider.initialize(); + this.selection.initialise(); + this.configuration.initialise(); + this.debugger.initialise(); + this.dispatcher.initialise(); + this.selectionProvider.initialise(); } - catch (InitializationException e) + catch (InitialisationException e) { e.printStackTrace(); return; diff --git a/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java b/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java index 732f77b3..583004ec 100644 --- a/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java +++ b/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java @@ -8,7 +8,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mumfrey.liteloader.core.LiteLoader; -import com.mumfrey.worldeditcui.InitializationFactory; +import com.mumfrey.worldeditcui.InitialisationFactory; import com.mumfrey.worldeditcui.render.LineColour; /** @@ -17,7 +17,7 @@ * @author yetanotherx * */ -public class CUIConfiguration implements InitializationFactory +public class CUIConfiguration implements InitialisationFactory { private static final String CONFIG_FILE_NAME = "worldeditcui.config.json"; @@ -46,7 +46,7 @@ public class CUIConfiguration implements InitializationFactory * exist. It then reads the file and sets each variable to the proper value. */ @Override - public void initialize() + public void initialise() { this.cuboidGridColor = Colour.setDefault(this.cuboidGridColor, "#CC3333CC"); this.cuboidEdgeColor = Colour.setDefault(this.cuboidEdgeColor, "#CC4C4CCC"); @@ -69,10 +69,10 @@ public void initialize() LineColour.POLYBOX.setColour(this.polyEdgeColor); LineColour.POLYPOINT.setColour(this.polyPointColor); LineColour.ELLIPSOIDGRID.setColour(this.ellipsoidGridColor); - LineColour.ELLIPSOIDCENTER.setColour(this.ellipsoidPointColor); + LineColour.ELLIPSOIDCENTRE.setColour(this.ellipsoidPointColor); LineColour.CYLINDERGRID.setColour(this.cylinderGridColor); LineColour.CYLINDERBOX.setColour(this.cylinderEdgeColor); - LineColour.CYLINDERCENTER.setColour(this.cylinderPointColor); + LineColour.CYLINDERCENTRE.setColour(this.cylinderPointColor); this.save(); } diff --git a/java/com/mumfrey/worldeditcui/debug/CUIDebug.java b/java/com/mumfrey/worldeditcui/debug/CUIDebug.java index fc18fcad..27a3e5c6 100644 --- a/java/com/mumfrey/worldeditcui/debug/CUIDebug.java +++ b/java/com/mumfrey/worldeditcui/debug/CUIDebug.java @@ -8,9 +8,9 @@ import java.util.logging.Logger; import com.mumfrey.liteloader.core.LiteLoader; -import com.mumfrey.worldeditcui.InitializationFactory; +import com.mumfrey.worldeditcui.InitialisationFactory; import com.mumfrey.worldeditcui.WorldEditCUI; -import com.mumfrey.worldeditcui.exceptions.InitializationException; +import com.mumfrey.worldeditcui.exceptions.InitialisationException; import com.mumfrey.worldeditcui.util.ConsoleLogFormatter; /** @@ -19,7 +19,7 @@ * @author yetanotherx * */ -public class CUIDebug implements InitializationFactory +public class CUIDebug implements InitialisationFactory { protected WorldEditCUI controller; @@ -33,7 +33,7 @@ public CUIDebug(WorldEditCUI controller) } @Override - public void initialize() throws InitializationException + public void initialise() throws InitialisationException { ConsoleLogFormatter formatter = new ConsoleLogFormatter(); @@ -59,7 +59,7 @@ public void initialize() throws InitializationException catch (IOException e) { e.printStackTrace(System.err); - throw new InitializationException(); + throw new InitialisationException(); } } diff --git a/java/com/mumfrey/worldeditcui/event/CUIEventDispatcher.java b/java/com/mumfrey/worldeditcui/event/CUIEventDispatcher.java index 0502a058..461de8d8 100644 --- a/java/com/mumfrey/worldeditcui/event/CUIEventDispatcher.java +++ b/java/com/mumfrey/worldeditcui/event/CUIEventDispatcher.java @@ -4,15 +4,15 @@ import java.util.HashMap; import java.util.Map; -import com.mumfrey.worldeditcui.InitializationFactory; +import com.mumfrey.worldeditcui.InitialisationFactory; import com.mumfrey.worldeditcui.WorldEditCUI; -import com.mumfrey.worldeditcui.exceptions.InitializationException; +import com.mumfrey.worldeditcui.exceptions.InitialisationException; /** * * @author Adam Mummery-Smith */ -public class CUIEventDispatcher implements InitializationFactory +public class CUIEventDispatcher implements InitialisationFactory { private WorldEditCUI controller; @@ -24,7 +24,7 @@ public CUIEventDispatcher(WorldEditCUI controller) } @Override - public void initialize() throws InitializationException + public void initialise() throws InitialisationException { for (CUIEventType eventType : CUIEventType.values()) { diff --git a/java/com/mumfrey/worldeditcui/event/cui/CUIEventCylinder.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventCylinder.java index ebc8d1dd..2c20ba68 100644 --- a/java/com/mumfrey/worldeditcui/event/cui/CUIEventCylinder.java +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventCylinder.java @@ -37,7 +37,7 @@ public String raise() this.controller.getSelection().setCylinderCenter(x, y, z); this.controller.getSelection().setCylinderRadius(radX, radZ); - this.controller.getDebugger().debug("Setting center/radius"); + this.controller.getDebugger().debug("Setting centre/radius"); return null; } diff --git a/java/com/mumfrey/worldeditcui/event/cui/CUIEventEllipsoid.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventEllipsoid.java index 1506a3af..a1bbdc4f 100644 --- a/java/com/mumfrey/worldeditcui/event/cui/CUIEventEllipsoid.java +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventEllipsoid.java @@ -45,7 +45,7 @@ else if (id == 1) this.controller.getSelection().setEllipsoidRadii(x, y, z); } - this.controller.getDebugger().debug("Setting center/radius"); + this.controller.getDebugger().debug("Setting centre/radius"); return null; } diff --git a/java/com/mumfrey/worldeditcui/event/cui/CUIEventSelection.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventSelection.java index faacfb57..0e3546ff 100644 --- a/java/com/mumfrey/worldeditcui/event/cui/CUIEventSelection.java +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventSelection.java @@ -32,7 +32,7 @@ public String raise() if (selection != null) { - selection.initialize(); + selection.initialise(); } this.controller.setSelection(selection); diff --git a/java/com/mumfrey/worldeditcui/exceptions/InitializationException.java b/java/com/mumfrey/worldeditcui/exceptions/InitialisationException.java similarity index 52% rename from java/com/mumfrey/worldeditcui/exceptions/InitializationException.java rename to java/com/mumfrey/worldeditcui/exceptions/InitialisationException.java index f55fa9eb..93b7d215 100644 --- a/java/com/mumfrey/worldeditcui/exceptions/InitializationException.java +++ b/java/com/mumfrey/worldeditcui/exceptions/InitialisationException.java @@ -1,23 +1,23 @@ package com.mumfrey.worldeditcui.exceptions; /** - * Special exception that only gets called during initialization + * Special exception that only gets called during initialisation * Throwing this halts the loading of the mod * * @author yetanotherx * */ -public class InitializationException extends Exception +public class InitialisationException extends Exception { private static final long serialVersionUID = 1L; - public InitializationException(String string) + public InitialisationException(String string) { super(string); } - public InitializationException() + public InitialisationException() { } } diff --git a/java/com/mumfrey/worldeditcui/render/CUISelectionProvider.java b/java/com/mumfrey/worldeditcui/render/CUISelectionProvider.java index 03d9194b..090b33ec 100644 --- a/java/com/mumfrey/worldeditcui/render/CUISelectionProvider.java +++ b/java/com/mumfrey/worldeditcui/render/CUISelectionProvider.java @@ -4,9 +4,9 @@ import java.util.HashMap; import java.util.Map; -import com.mumfrey.worldeditcui.InitializationFactory; +import com.mumfrey.worldeditcui.InitialisationFactory; import com.mumfrey.worldeditcui.WorldEditCUI; -import com.mumfrey.worldeditcui.exceptions.InitializationException; +import com.mumfrey.worldeditcui.exceptions.InitialisationException; import com.mumfrey.worldeditcui.render.region.BaseRegion; import com.mumfrey.worldeditcui.render.region.RegionType; @@ -14,7 +14,7 @@ * * @author Adam Mummery-Smith */ -public class CUISelectionProvider implements InitializationFactory +public class CUISelectionProvider implements InitialisationFactory { private Map> regionConstructors = new HashMap>(); @@ -26,7 +26,7 @@ public CUISelectionProvider(WorldEditCUI controller) } @Override - public void initialize() throws InitializationException + public void initialise() throws InitialisationException { for (RegionType regionType : RegionType.values()) { diff --git a/java/com/mumfrey/worldeditcui/render/LineColour.java b/java/com/mumfrey/worldeditcui/render/LineColour.java index ccd7c3bf..7da10628 100644 --- a/java/com/mumfrey/worldeditcui/render/LineColour.java +++ b/java/com/mumfrey/worldeditcui/render/LineColour.java @@ -26,10 +26,10 @@ public enum LineColour POLYBOX ("colour.polyedge", new Colour("#CC4C4CCC")), POLYPOINT ("colour.polypoint", new Colour("#33CCCCCC")), ELLIPSOIDGRID ("colour.ellipsoidgrid", new Colour("#CC4C4CCC")), - ELLIPSOIDCENTER("colour.ellipsoidpoint", new Colour("#CCCC33CC")), + ELLIPSOIDCENTRE("colour.ellipsoidpoint", new Colour("#CCCC33CC")), CYLINDERGRID ("colour.cylindergrid", new Colour("#CC3333CC")), CYLINDERBOX ("colour.cylinderedge", new Colour("#CC4C4CCC")), - CYLINDERCENTER ("colour.cylinderpoint", new Colour("#CC33CCCC")); + CYLINDERCENTRE ("colour.cylinderpoint", new Colour("#CC33CCCC")); private String displayName; diff --git a/java/com/mumfrey/worldeditcui/render/region/BaseRegion.java b/java/com/mumfrey/worldeditcui/render/region/BaseRegion.java index 7a5d5600..948970d9 100644 --- a/java/com/mumfrey/worldeditcui/render/region/BaseRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/BaseRegion.java @@ -1,6 +1,6 @@ package com.mumfrey.worldeditcui.render.region; -import com.mumfrey.worldeditcui.InitializationFactory; +import com.mumfrey.worldeditcui.InitialisationFactory; import com.mumfrey.worldeditcui.WorldEditCUI; import com.mumfrey.worldeditcui.exceptions.InvalidSelectionTypeException; import com.mumfrey.worldeditcui.util.Vector3; @@ -13,7 +13,7 @@ * @author yetanotherx * @author lahwran */ -public abstract class BaseRegion implements InitializationFactory +public abstract class BaseRegion implements InitialisationFactory { protected WorldEditCUI controller; @@ -24,7 +24,7 @@ public BaseRegion(WorldEditCUI controller) } @Override - public void initialize() + public void initialise() { } diff --git a/java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java b/java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java index 303ad980..64be8f4e 100644 --- a/java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java @@ -16,7 +16,7 @@ public class CylinderRegion extends BaseRegion { - protected PointCube center; + protected PointCube centre; protected double radX = 0; protected double radZ = 0; protected int minY = 0; @@ -34,9 +34,9 @@ public CylinderRegion(WorldEditCUI controller) @Override public void render(Vector3 cameraPos) { - if (this.center != null) + if (this.centre != null) { - this.center.render(cameraPos); + this.centre.render(cameraPos); this.circles.render(cameraPos); this.grid.render(cameraPos); this.box.render(cameraPos); @@ -46,8 +46,8 @@ public void render(Vector3 cameraPos) @Override public void setCylinderCenter(int x, int y, int z) { - this.center = new PointCube(x, y, z); - this.center.setColour(LineColour.CYLINDERCENTER); + this.centre = new PointCube(x, y, z); + this.centre.setColour(LineColour.CYLINDERCENTRE); this.update(); } @@ -74,13 +74,13 @@ private void update() if (this.minY == 0 || this.maxY == 0) { - tMin = (int)this.center.getPoint().getY(); - tMax = (int)this.center.getPoint().getY(); + tMin = (int)this.centre.getPoint().getY(); + tMax = (int)this.centre.getPoint().getY(); } - this.circles = new RenderCylinderCircles(LineColour.CYLINDERGRID, this.center, this.radX, this.radZ, tMin, tMax); - this.grid = new RenderCylinderGrid(LineColour.CYLINDERGRID, this.center, this.radX, this.radZ, tMin, tMax); - this.box = new RenderCylinderBox(LineColour.CYLINDERBOX, this.center, this.radX, this.radZ, tMin, tMax); + this.circles = new RenderCylinderCircles(LineColour.CYLINDERGRID, this.centre, this.radX, this.radZ, tMin, tMax); + this.grid = new RenderCylinderGrid(LineColour.CYLINDERGRID, this.centre, this.radX, this.radZ, tMin, tMax); + this.box = new RenderCylinderBox(LineColour.CYLINDERBOX, this.centre, this.radX, this.radZ, tMin, tMax); } @Override diff --git a/java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java b/java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java index 798f14ae..bf027f61 100644 --- a/java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java @@ -43,7 +43,7 @@ else if (this.centre != null) public void setEllipsoidCenter(int x, int y, int z) { this.centre = new PointCube(x, y, z); - this.centre.setColour(LineColour.ELLIPSOIDCENTER); + this.centre.setColour(LineColour.ELLIPSOIDCENTRE); this.update(); } diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java index 4475aff3..0044db60 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java @@ -10,7 +10,7 @@ import static com.mumfrey.liteloader.gl.GL.*; /** - * Draws an ellipsoid shape around a center point. + * Draws an ellipsoid shape around a centre point. * * @author yetanotherx */ @@ -18,7 +18,7 @@ public class RenderEllipsoid { protected LineColour colour; - protected PointCube center; + protected PointCube centre; protected Vector3 radii; protected final static double twoPi = Math.PI * 2; protected double centreX; @@ -28,7 +28,7 @@ public class RenderEllipsoid public RenderEllipsoid(LineColour colour, PointCube centre, Vector3 radii) { this.colour = colour; - this.center = centre; + this.centre = centre; this.radii = radii; this.centreX = centre.getPoint().getX() + 0.5; this.centreY = centre.getPoint().getY() + 0.5; diff --git a/java/com/mumfrey/worldeditcui/util/Vector2.java b/java/com/mumfrey/worldeditcui/util/Vector2.java index 629c1f76..366bb8d7 100644 --- a/java/com/mumfrey/worldeditcui/util/Vector2.java +++ b/java/com/mumfrey/worldeditcui/util/Vector2.java @@ -28,7 +28,7 @@ public class Vector2 implements Comparable protected double x, z; /** - * Construct and Initialized a Vector2 from the given x, y + * Construct and Initialised a Vector2 from the given x, y * * @param x the x coordinate * @param y the y coordinate @@ -40,7 +40,7 @@ public Vector2(double x, double y) } /** - * Construct and Initialized a Vector2 from the given x, y + * Construct and Initialised a Vector2 from the given x, y * * @param x the x coordinate * @param y the y coordinate @@ -51,7 +51,7 @@ public Vector2(Double x, Double y) } /** - * Construct and Initialized a Vector2 to (0,0) + * Construct and Initialised a Vector2 to (0,0) */ public Vector2() { @@ -59,7 +59,7 @@ public Vector2() } /** - * Construct and Initialized a Vector2 from an old Vector2 + * Construct and Initialised a Vector2 from an old Vector2 * * @param original */ From 663bef959c5452c89fe5119010a48a3e98375ad4 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Thu, 5 Feb 2015 12:34:38 +0000 Subject: [PATCH 20/51] Refactor BoundingBox calculation for cuboid region --- .../render/region/CuboidRegion.java | 58 +----- .../render/shapes/Render3DBox.java | 6 + .../render/shapes/Render3DGrid.java | 6 + .../worldeditcui/util/BoundingBox.java | 35 ++++ .../mumfrey/worldeditcui/util/Vector2.java | 52 ----- .../mumfrey/worldeditcui/util/Vector3m.java | 185 ------------------ 6 files changed, 51 insertions(+), 291 deletions(-) create mode 100644 java/com/mumfrey/worldeditcui/util/BoundingBox.java delete mode 100644 java/com/mumfrey/worldeditcui/util/Vector3m.java diff --git a/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java b/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java index 2c969ce3..9e01ecc6 100644 --- a/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java @@ -5,8 +5,8 @@ import com.mumfrey.worldeditcui.render.points.PointCube; import com.mumfrey.worldeditcui.render.shapes.Render3DBox; import com.mumfrey.worldeditcui.render.shapes.Render3DGrid; +import com.mumfrey.worldeditcui.util.BoundingBox; import com.mumfrey.worldeditcui.util.Vector3; -import com.mumfrey.worldeditcui.util.Vector3m; /** * Main controller for a cuboid-type region @@ -63,62 +63,12 @@ else if (id == 1) if (this.firstPoint != null && this.secondPoint != null) { - Vector3[] bounds = this.calcBounds(); - this.grid = new Render3DGrid(LineColour.CUBOIDGRID, bounds[0], bounds[1]); - this.box = new Render3DBox(LineColour.CUBOIDBOX, bounds[0], bounds[1]); + BoundingBox bounds = new BoundingBox(this.firstPoint, this.secondPoint); + this.grid = new Render3DGrid(LineColour.CUBOIDGRID, bounds); + this.box = new Render3DBox(LineColour.CUBOIDBOX, bounds); } } - /** - * Calculates the boundary points of the actual box. - * I have no idea what I'm doing. - * @return - */ - protected Vector3m[] calcBounds() - { - float off = 0.02f; - float off1 = 1 + off; - - Vector3m[] out = new Vector3m[2]; - out[0] = new Vector3m(Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE); - out[1] = new Vector3m(-Double.MAX_VALUE, -Double.MAX_VALUE, -Double.MAX_VALUE); - - for (PointCube point : new PointCube[] { this.firstPoint, this.secondPoint }) - { - if (point.getPoint().getX() + off1 > out[1].getX()) - { - out[1].setX(point.getPoint().getX() + off1); - } - - if (point.getPoint().getX() - off < out[0].getX()) - { - out[0].setX(point.getPoint().getX() - off); - } - - if (point.getPoint().getY() + off1 > out[1].getY()) - { - out[1].setY(point.getPoint().getY() + off1); - } - - if (point.getPoint().getY() - off < out[0].getY()) - { - out[0].setY(point.getPoint().getY() - off); - } - - if (point.getPoint().getZ() + off1 > out[1].getZ()) - { - out[1].setZ(point.getPoint().getZ() + off1); - } - - if (point.getPoint().getZ() - off < out[0].getZ()) - { - out[0].setZ(point.getPoint().getZ() - off); - } - } - - return out; - } - @Override public RegionType getType() { diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java index 546c307f..8e32f8ce 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java @@ -2,6 +2,7 @@ import com.mumfrey.worldeditcui.render.LineColour; import com.mumfrey.worldeditcui.render.LineInfo; +import com.mumfrey.worldeditcui.util.BoundingBox; import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; @@ -21,6 +22,11 @@ public class Render3DBox protected Vector3 first; protected Vector3 second; + public Render3DBox(LineColour colour, BoundingBox region) + { + this(colour, region.getMin(), region.getMax()); + } + public Render3DBox(LineColour colour, Vector3 first, Vector3 second) { this.colour = colour; diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java index 0ee60111..319e263b 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java @@ -2,6 +2,7 @@ import com.mumfrey.worldeditcui.render.LineColour; import com.mumfrey.worldeditcui.render.LineInfo; +import com.mumfrey.worldeditcui.util.BoundingBox; import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; @@ -21,6 +22,11 @@ public class Render3DGrid protected Vector3 first; protected Vector3 second; + public Render3DGrid(LineColour colour, BoundingBox region) + { + this(colour, region.getMin(), region.getMax()); + } + public Render3DGrid(LineColour colour, Vector3 first, Vector3 second) { this.colour = colour; diff --git a/java/com/mumfrey/worldeditcui/util/BoundingBox.java b/java/com/mumfrey/worldeditcui/util/BoundingBox.java new file mode 100644 index 00000000..eb42c3dc --- /dev/null +++ b/java/com/mumfrey/worldeditcui/util/BoundingBox.java @@ -0,0 +1,35 @@ +package com.mumfrey.worldeditcui.util; + +import com.mumfrey.worldeditcui.render.points.PointCube; + + +public class BoundingBox +{ + private static final double OFF = 0.02; + + private static final Vector3 MIN_VEC = new Vector3(BoundingBox.OFF, BoundingBox.OFF, BoundingBox.OFF); + private static final Vector3 MAX_VEC = new Vector3(BoundingBox.OFF + 1, BoundingBox.OFF + 1, BoundingBox.OFF + 1); + + private final Vector3 min, max; + + public BoundingBox(PointCube p1, PointCube p2) + { + this(p1.getPoint(), p2.getPoint()); + } + + public BoundingBox(Vector3 p1, Vector3 p2) + { + this.min = new Vector3(Math.min(p1.getX(), p2.getX()), Math.min(p1.getY(), p2.getY()), Math.min(p1.getZ(), p2.getZ())).subtract(BoundingBox.MIN_VEC); + this.max = new Vector3(Math.max(p1.getX(), p2.getX()), Math.max(p1.getY(), p2.getY()), Math.max(p1.getZ(), p2.getZ())).add(BoundingBox.MAX_VEC); + } + + public Vector3 getMin() + { + return this.min; + } + + public Vector3 getMax() + { + return this.max; + } +} diff --git a/java/com/mumfrey/worldeditcui/util/Vector2.java b/java/com/mumfrey/worldeditcui/util/Vector2.java index 366bb8d7..3ba93ad3 100644 --- a/java/com/mumfrey/worldeditcui/util/Vector2.java +++ b/java/com/mumfrey/worldeditcui/util/Vector2.java @@ -145,18 +145,6 @@ public Vector3 toVector3() return Vector2.toVector3(this); } - /** - * Returns a Vector3m object with a y-value of 0. - * The x of this Vector2 becomes the x of the Vector3m, - * the y of this Vector2 becomes the z of the Vector3m. - * - * @return - */ - public Vector3m toVector3m() - { - return Vector2.toVector3m(this); - } - /** * Returns a Vector3 object with the given y value. * The x of this Vector2 becomes the x of the Vector3, @@ -170,19 +158,6 @@ public Vector3 toVector3(double y) return Vector2.toVector3(this, y); } - /** - * Returns a Vector3m object with the given y value. - * The x of this Vector2 becomes the x of the Vector3m, - * the y of this Vector2 becomes the z of the Vector3m. - * - * @param y Y value to use in the new Vector3m. - * @return - */ - public Vector3m toVector3m(double y) - { - return Vector2.toVector3m(this, y); - } - /** * Returns the Cross Product of this Vector2 Note: Cross Product is * undefined in 2d space. This returns the orthogonal vector to this vector @@ -416,19 +391,6 @@ public static Vector3 toVector3(Vector2 o) return new Vector3(o.x, 0, o.z); } - /** - * Returns a Vector3m object with a y-value of 0. - * The x of the Vector2 becomes the x of the Vector3m, - * the y of the Vector2 becomes the z of the Vector3m. - * - * @param o Vector2 to use as the x/z values - * @return - */ - public static Vector3m toVector3m(Vector2 o) - { - return new Vector3m(o.x, 0, o.z); - } - /** * Returns a Vector3 object with the given y-value. * The x of the Vector2 becomes the x of the Vector3, @@ -443,20 +405,6 @@ public static Vector3 toVector3(Vector2 o, double y) return new Vector3(o.x, y, o.z); } - /** - * Returns a Vector3m object with the given y-value. - * The x of the Vector2 becomes the x of the Vector3m, - * the y of the Vector2 becomes the z of the Vector3m. - * - * @param o Vector2 to use as the x/z values - * @param y Y value of the new Vector3 - * @return - */ - public static Vector3m toVector3m(Vector2 o, double y) - { - return new Vector3m(o.x, y, o.z); - } - /** * Rounds the X and Y values of the given Vector2 up to * the nearest integer value. diff --git a/java/com/mumfrey/worldeditcui/util/Vector3m.java b/java/com/mumfrey/worldeditcui/util/Vector3m.java deleted file mode 100644 index ea1f840b..00000000 --- a/java/com/mumfrey/worldeditcui/util/Vector3m.java +++ /dev/null @@ -1,185 +0,0 @@ -package com.mumfrey.worldeditcui.util; - -/** - * A version of Vector3 that can be modified. - * - * @author yetanotherx - */ -public class Vector3m extends Vector3 -{ - - public Vector3m(double x, double y, double z) - { - super(x, y, z); - } - - public Vector3m(Double x, Double y, Double z) - { - super(x, y, z); - } - - public Vector3m(Vector3 vector) - { - super(vector); - } - - public Vector3m() - { - } - - public void setZ(double z) - { - this.z = z; - } - - public void setY(double y) - { - this.y = y; - } - - public void setX(double x) - { - this.x = x; - } - - /** - * Adds two vectors - * - * @param that - * @return - */ - - @Override - public Vector3 add(Vector3 that) - { - this.x += that.x; - this.y += that.y; - this.z += that.z; - return this; - } - - /** - * Subtracts two vectors - * - * @param that - * @return - */ - - @Override - public Vector3 subtract(Vector3 that) - { - this.x -= that.x; - this.y -= that.y; - this.z -= that.z; - return this; - } - - /** - * Scales by the scalar value - * - * @param scale - * @return - */ - - @Override - public Vector3 scale(double scale) - { - this.x *= scale; - this.y *= scale; - this.z *= scale; - return this; - } - - /** - * Takes the cross product of two vectors - * - * @param that - * @return - */ - - @Override - public Vector3 cross(Vector3 that) - { - this.x = this.getY() * that.getZ() - this.getZ() * that.getY(); - this.y = this.getZ() * that.getX() - this.getX() * that.getZ(); - this.z = this.getX() * that.getY() - this.getY() * that.getX(); - - return this; - } - - /** - * Rounds the X, Y, and Z values of this Vector3 up to - * the nearest integer value. - * - * @return - */ - @Override - public Vector3 ceil() - { - this.x = Math.ceil(this.x); - this.y = Math.ceil(this.y); - this.z = Math.ceil(this.z); - return this; - } - - /** - * Rounds the X, Y, and Z values of this Vector3 down to - * the nearest integer value. - * - * @return - */ - @Override - public Vector3 floor() - { - this.x = Math.floor(this.x); - this.y = Math.floor(this.y); - this.z = Math.floor(this.z); - return this; - } - - /** - * Rounds the X, Y, and Z values of this Vector3 to - * the nearest integer value. - * - * @return - */ - @Override - public Vector3 round() - { - this.x = Math.round(this.x); - this.y = Math.round(this.y); - this.z = Math.round(this.z); - return this; - } - - /** - * Sets the X, Y, and Z values of this Vector3 to their - * absolute value. - * - * @return - */ - @Override - public Vector3 abs() - { - this.x = Math.abs(this.x); - this.y = Math.abs(this.y); - this.z = Math.abs(this.z); - return this; - } - - /** - * returns the vector with a length of 1 - * - * @return - */ - - @Override - public Vector3 normalize() - { - double lengthReciprocal = 1.0 / this.length(); - this.x *= lengthReciprocal; - this.y *= lengthReciprocal; - this.z *= lengthReciprocal; - return this; - } -} From e9000ec13158b45510b1baf58ffe26da6b3fbdf3 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Thu, 5 Feb 2015 14:45:22 +0000 Subject: [PATCH 21/51] Fix issue with hotbar rendering oddly when in always-on-top mode --- build/buildnumber.txt | 4 ++-- java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java | 3 +++ .../worldeditcui/event/listeners/CUIListenerWorldRender.java | 4 ---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/build/buildnumber.txt b/build/buildnumber.txt index 011b048f..087b0323 100644 --- a/build/buildnumber.txt +++ b/build/buildnumber.txt @@ -1,3 +1,3 @@ #Build Number for ANT. Do not edit! -#Sun Dec 14 19:33:22 GMT 2014 -build.number=1801 +#Thu Feb 05 14:35:03 GMT 2015 +build.number=1802 diff --git a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java index 829e6c00..a7e4eb0f 100644 --- a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java @@ -10,6 +10,7 @@ import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.multiplayer.ServerData; import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.settings.KeyBinding; import net.minecraft.network.INetHandler; import net.minecraft.network.PacketBuffer; @@ -208,7 +209,9 @@ public void onPostRenderEntities(float partialTicks) { if (this.visible && !this.alwaysOnTop) { + RenderHelper.disableStandardItemLighting(); this.worldRenderListener.onRender(partialTicks); + RenderHelper.enableStandardItemLighting(); } } diff --git a/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerWorldRender.java b/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerWorldRender.java index 1cbc477a..15c6a222 100644 --- a/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerWorldRender.java +++ b/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerWorldRender.java @@ -3,7 +3,6 @@ import static com.mumfrey.liteloader.gl.GL.*; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.client.renderer.RenderHelper; import com.mumfrey.worldeditcui.WorldEditCUI; import com.mumfrey.worldeditcui.util.Vector3; @@ -31,7 +30,6 @@ public void onRender(float partialTicks) { try { - RenderHelper.disableStandardItemLighting(); OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -66,7 +64,5 @@ public void onRender(float partialTicks) glAlphaFunc(GL_GREATER, 0.1F); } catch (Exception ex) {} - - RenderHelper.enableStandardItemLighting(); } } From 7872ff704015fb33289d13d3e903974c6642aa1a Mon Sep 17 00:00:00 2001 From: Jochem Broekhoff Date: Fri, 17 Jul 2015 13:49:06 +0200 Subject: [PATCH 22/51] Added Dutch language (nl_NL) --- res/assets/wecui/lang/nl_NL.lang | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 res/assets/wecui/lang/nl_NL.lang diff --git a/res/assets/wecui/lang/nl_NL.lang b/res/assets/wecui/lang/nl_NL.lang new file mode 100644 index 00000000..d9481e19 --- /dev/null +++ b/res/assets/wecui/lang/nl_NL.lang @@ -0,0 +1,26 @@ +wecui.options.title=WorldEditCUI Opties + +wecui.keys.toggle=CUI zichtbaarheid omschakelen +wecui.keys.clear=WorldEdit selectie verwijderen +wecui.keys.category=WorldEditCUI + +gui.ok=OK + +colour.cuboidedge=Randkleur Balk +colour.cuboidgrid=Roosterkleur Balk +colour.cuboidpoint1=Eerste punt kleur Balk +colour.cuboidpoint2=Tweede punt kleur Balk +colour.polygrid=Roosterkleur Veelhoek +colour.polyedge=Randkleur Veelhoek +colour.polypoint=Puntkleur Veelhoek +colour.ellipsoidgrid=Roosterkleur Ellipsoïde +colour.ellipsoidpoint=Centrumpuntkleur Ellipsoïde +colour.cylindergrid=Roosterkleur Cilinder +colour.cylinderedge=Randkleur Cilinder +colour.cylinderpoint=Centrumpuntkleur Cilinder + +gui.options.compat.title=Compatibiliteitsopties +gui.options.compat.spammy=Veel-modus (heel de tijd /we cui verzenden) +gui.options.compat.ontop=Altijd bovenaan (mod-compatibiliteit) +gui.options.colours.title=Opties voor kleuren + From 8db61a686b6ba05d0c5eac0e7832bf9b5522c3f2 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Fri, 17 Jul 2015 13:06:11 +0100 Subject: [PATCH 23/51] Version bump to 1.8.0_03 for dutch language addition --- build/build_wecui.xml | 2 +- java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/build_wecui.xml b/build/build_wecui.xml index 78b91143..cb3eb8b8 100644 --- a/build/build_wecui.xml +++ b/build/build_wecui.xml @@ -4,7 +4,7 @@ - + diff --git a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java index a7e4eb0f..5bd10855 100644 --- a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java @@ -195,7 +195,7 @@ public String getName() @Override public String getVersion() { - return "1.8.0_02"; + return "1.8.0_03"; } @Override From 840346aacd9d702dd9ebc384040124d0e3fc6d25 Mon Sep 17 00:00:00 2001 From: cyilin Date: Wed, 12 Aug 2015 12:05:15 +0800 Subject: [PATCH 24/51] Added Simplified Chinese language --- res/assets/wecui/lang/zh_CN.lang | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 res/assets/wecui/lang/zh_CN.lang diff --git a/res/assets/wecui/lang/zh_CN.lang b/res/assets/wecui/lang/zh_CN.lang new file mode 100644 index 00000000..c6475e96 --- /dev/null +++ b/res/assets/wecui/lang/zh_CN.lang @@ -0,0 +1,26 @@ +wecui.options.title=WorldEditCUI选项 + +wecui.keys.toggle=显示/隐藏 WECUI +wecui.keys.clear=取消WorldEdit选择区域 +wecui.keys.category=WorldEditCUI按键设置 + +gui.ok=OK + +colour.cuboidedge=长方体边缘颜色 +colour.cuboidgrid=长方体网格颜色 +colour.cuboidpoint1=长方体第一点颜色 +colour.cuboidpoint2=长方体第二点颜色 +colour.polygrid=多边形网格颜色 +colour.polyedge=多边形边缘颜色 +colour.polypoint=多边形点颜色 +colour.ellipsoidgrid=椭球形网格颜色 +colour.ellipsoidpoint=椭球形中心点颜色 +colour.cylindergrid=圆柱形网格颜色 +colour.cylinderedge=圆柱形边缘颜色 +colour.cylinderpoint=圆柱形中心点颜色 + +gui.options.compat.title=兼容性选项 +gui.options.compat.spammy=混杂模式(始终发送/we cui命令) +gui.options.compat.ontop=始终在前面(mod兼容选项) +gui.options.colours.title=显示颜色 + From 2d242d7422013246522badca2aa66f4da72513ad Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Mon, 18 Apr 2016 13:44:57 +0100 Subject: [PATCH 25/51] Initial update to 1.9, convert to gradle --- .classpath | 9 - .gitignore | 78 ++++++++- .project | 23 --- build.gradle | 48 +++++ build/build_wecui.xml | 165 ------------------ build/buildnumber.txt | 3 - build/litemod.template.json | 8 - .../worldeditcui/LiteModWorldEditCUI.java | 6 +- .../worldeditcui/gui/CUIConfigPanel.java | 2 +- .../worldeditcui/gui/controls/GuiControl.java | 104 +++++------ .../render/shapes/Render2DBox.java | 10 +- .../render/shapes/Render2DGrid.java | 8 +- .../render/shapes/Render3DBox.java | 42 ++--- .../render/shapes/Render3DGrid.java | 54 +++--- .../render/shapes/Render3DPolygon.java | 8 +- .../render/shapes/RenderCylinderBox.java | 8 +- .../render/shapes/RenderCylinderCircles.java | 8 +- .../render/shapes/RenderCylinderGrid.java | 24 +-- .../render/shapes/RenderEllipsoid.java | 32 ++-- 19 files changed, 278 insertions(+), 362 deletions(-) delete mode 100644 .classpath delete mode 100644 .project create mode 100644 build.gradle delete mode 100644 build/build_wecui.xml delete mode 100644 build/buildnumber.txt delete mode 100644 build/litemod.template.json diff --git a/.classpath b/.classpath deleted file mode 100644 index 21b4c252..00000000 --- a/.classpath +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/.gitignore b/.gitignore index d8bab97f..96854677 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,78 @@ +# Build # +######### +MANIFEST.MF +dependency-reduced-pom.xml + +# Compiled # +############ bin -.settings \ No newline at end of file +build +dist +lib +out +run +target +*.com +*.class +*.dll +*.exe +*.o +*.so + +# Databases # +############# +*.db +*.sql +*.sqlite + +# Packages # +############ +*.7z +*.dmg +*.gz +*.iso +*.rar +*.tar +*.zip + +# Repository # +############## +.git + +# Logging # +########### +/logs +*.log + +# Misc # +######## +*.bak + +# System # +########## +.DS_Store +ehthumbs.db +Thumbs.db +*.bat +*.sh + +# Project # +########### +.checkstyle +.classpath +.externalToolBuilders +.gradle +.nb-gradle +.idea +.project +.settings +eclipse +nbproject +atlassian-ide-plugin.xml +build.xml +nb-configuration.xml +*.iml +*.ipr +*.iws +*.launch +*.number \ No newline at end of file diff --git a/.project b/.project deleted file mode 100644 index 2b062ce5..00000000 --- a/.project +++ /dev/null @@ -1,23 +0,0 @@ - - - WorldEditCUI - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - - - MCP_LOC - $%7BPARENT-2-PROJECT_LOC%7D - - - diff --git a/build.gradle b/build.gradle new file mode 100644 index 00000000..01d3b15f --- /dev/null +++ b/build.gradle @@ -0,0 +1,48 @@ +buildscript { + repositories { + mavenLocal() + mavenCentral() + maven { + name = "sonatype" + url = "https://oss.sonatype.org/content/repositories/snapshots/" + } + maven { + name = "forge" + url = "http://files.minecraftforge.net/maven" + } + } + dependencies { + classpath 'net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT' + } +} + +apply plugin: 'net.minecraftforge.gradle.liteloader' + +version = "1.9.0_00" +group = "com.mumfrey.worldeditcui" +archivesBaseName = "worldeditcui" + +minecraft { + version = "1.9" + mappings = "snapshot_20160410" + runDir = "run" +} + +sourceSets { + main { + java.srcDir 'java' + resources.srcDir 'res' + } +} + +litemod { + json { + author = "yetanotherx, Mumfrey, TomyLobo" + mcversion = "1.9" + description = "Client-side user interface for WorldEdit" + } +} + +jar { + from litemod.outputs +} diff --git a/build/build_wecui.xml b/build/build_wecui.xml deleted file mode 100644 index cb3eb8b8..00000000 --- a/build/build_wecui.xml +++ /dev/null @@ -1,165 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/build/buildnumber.txt b/build/buildnumber.txt deleted file mode 100644 index 087b0323..00000000 --- a/build/buildnumber.txt +++ /dev/null @@ -1,3 +0,0 @@ -#Build Number for ANT. Do not edit! -#Thu Feb 05 14:35:03 GMT 2015 -build.number=1802 diff --git a/build/litemod.template.json b/build/litemod.template.json deleted file mode 100644 index 0da0a4d9..00000000 --- a/build/litemod.template.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "wecui", - "mcversion": "${litemodversion}", - "version": "${version}", - "revision": "${build.number}", - "author": "${author}", - "description": "Client-side user interface for WorldEdit" -} diff --git a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java index 5bd10855..c5a9694c 100644 --- a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java @@ -14,7 +14,7 @@ import net.minecraft.client.settings.KeyBinding; import net.minecraft.network.INetHandler; import net.minecraft.network.PacketBuffer; -import net.minecraft.network.play.server.S01PacketJoinGame; +import net.minecraft.network.play.server.SPacketJoinGame; import org.lwjgl.input.Keyboard; @@ -82,7 +82,7 @@ public void onInitCompleted(Minecraft minecraft, LiteLoader loader) } @Override - public void onJoinGame(INetHandler netHandler, S01PacketJoinGame loginPacket, ServerData serverData, RealmsServer realmsServer) + public void onJoinGame(INetHandler netHandler, SPacketJoinGame loginPacket, ServerData serverData, RealmsServer realmsServer) { this.visible = true; this.controller.getDebugger().debug("Joined game, sending initial handshake"); @@ -195,7 +195,7 @@ public String getName() @Override public String getVersion() { - return "1.8.0_03"; + return "1.9.0_00"; } @Override diff --git a/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java b/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java index 79fb7e02..3c8dbf2c 100644 --- a/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java +++ b/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java @@ -59,7 +59,7 @@ public void onPanelShown(ConfigPanelHost host) { this.mod = host.getMod(); - ScaledResolution scaledresolution = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight); + ScaledResolution scaledresolution = new ScaledResolution(this.mc); GuiControl.setScreenSizeAndScale(host.getWidth(), this.getContentHeight(), scaledresolution.getScaleFactor()); this.controlList.clear(); diff --git a/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java b/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java index d5f17196..eb337b74 100644 --- a/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java +++ b/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java @@ -4,7 +4,7 @@ import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.VertexBuffer; import static com.mumfrey.liteloader.gl.GL.*; /** @@ -201,10 +201,10 @@ public static void drawNativeLine(float x1, float y1, float x2, float y2, float glLineWidth(width); Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldRenderer = tessellator.getWorldRenderer(); - worldRenderer.startDrawing(GL_LINES); - worldRenderer.addVertex(x1, y1, 0); - worldRenderer.addVertex(x2, y2, 0); + VertexBuffer buf = tessellator.getBuffer(); + buf.begin(GL_LINES, VF_POSITION); + buf.pos(x1, y1, 0).endVertex(); + buf.pos(x2, y2, 0).endVertex(); tessellator.draw(); glEnableTexture2D(); @@ -270,21 +270,21 @@ public static void drawArrow(int x1, int y1, int x2, int y2, int z, int width, i // Draw the line Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldRenderer = tessellator.getWorldRenderer(); - worldRenderer.startDrawingQuads(); - worldRenderer.addVertex(x1, y2, z); - worldRenderer.addVertex(x2, y2, z); - worldRenderer.addVertex(x2, y1, z); - worldRenderer.addVertex(x1, y1, z); + VertexBuffer buf = tessellator.getBuffer(); + buf.begin(GL_QUADS, VF_POSITION); + buf.pos(x1, y2, z).endVertex(); + buf.pos(x2, y2, z).endVertex(); + buf.pos(x2, y1, z).endVertex(); + buf.pos(x1, y1, z).endVertex(); tessellator.draw(); // If an arrow then draw the arrow head if (arrowHead && arrowHeadSize > 0) { - worldRenderer.startDrawing(4); - worldRenderer.addVertex(x2, 0 - arrowHeadSize / 2, z); - worldRenderer.addVertex(x2, arrowHeadSize / 2, z); - worldRenderer.addVertex(length, 0, z); + buf.begin(GL_TRIANGLES, VF_POSITION); + buf.pos(x2, 0 - arrowHeadSize / 2, z).endVertex(); + buf.pos(x2, arrowHeadSize / 2, z).endVertex(); + buf.pos(length, 0, z).endVertex(); tessellator.draw(); } @@ -321,12 +321,12 @@ public void setTexMapSize(int textureSize) public void drawTexturedModalRectRot(int x, int y, int x2, int y2, int u, int v, int u2, int v2) { Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldRenderer = tessellator.getWorldRenderer(); - worldRenderer.startDrawingQuads(); - worldRenderer.addVertexWithUV(x2, y2, this.zLevel, (float)(u) * texMapScale, (float)(v2) * texMapScale); - worldRenderer.addVertexWithUV(x2, y, this.zLevel, (float)(u2) * texMapScale, (float)(v2) * texMapScale); - worldRenderer.addVertexWithUV(x, y, this.zLevel, (float)(u2) * texMapScale, (float)(v) * texMapScale); - worldRenderer.addVertexWithUV(x, y2, this.zLevel, (float)(u) * texMapScale, (float)(v) * texMapScale); + VertexBuffer buf = tessellator.getBuffer(); + buf.begin(GL_QUADS, VF_POSITION_TEX); + buf.pos(x2, y2, this.zLevel).tex((float)(u) * texMapScale, (float)(v2) * texMapScale).endVertex(); + buf.pos(x2, y, this.zLevel).tex((float)(u2) * texMapScale, (float)(v2) * texMapScale).endVertex(); + buf.pos(x, y, this.zLevel).tex((float)(u2) * texMapScale, (float)(v) * texMapScale).endVertex(); + buf.pos(x, y2, this.zLevel).tex((float)(u) * texMapScale, (float)(v) * texMapScale).endVertex(); tessellator.draw(); } @@ -344,12 +344,12 @@ public void drawTexturedModalRectRot(int x, int y, int x2, int y2, int u, int v, public void drawTexturedModalRectRot(int x, int y, int u, int v, int width, int height) { Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldRenderer = tessellator.getWorldRenderer(); - worldRenderer.startDrawingQuads(); - worldRenderer.addVertexWithUV(x + height, y + width, this.zLevel, (float)(u) * texMapScale, (float)(v + height) * texMapScale); - worldRenderer.addVertexWithUV(x + height, y, this.zLevel, (float)(u + width) * texMapScale, (float)(v + height) * texMapScale); - worldRenderer.addVertexWithUV(x, y, this.zLevel, (float)(u + width) * texMapScale, (float)(v) * texMapScale); - worldRenderer.addVertexWithUV(x, y + width, this.zLevel, (float)(u) * texMapScale, (float)(v) * texMapScale); + VertexBuffer buf = tessellator.getBuffer(); + buf.begin(GL_QUADS, VF_POSITION_TEX); + buf.pos(x + height, y + width, this.zLevel).tex((float)(u) * texMapScale, (float)(v + height) * texMapScale).endVertex(); + buf.pos(x + height, y, this.zLevel).tex((float)(u + width) * texMapScale, (float)(v + height) * texMapScale).endVertex(); + buf.pos(x, y, this.zLevel).tex((float)(u + width) * texMapScale, (float)(v) * texMapScale).endVertex(); + buf.pos(x, y + width, this.zLevel).tex((float)(u) * texMapScale, (float)(v) * texMapScale).endVertex(); tessellator.draw(); } @@ -505,16 +505,16 @@ protected void drawCrossHair(int x, int y, int size, int width, int colour) // Draw the frame Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + VertexBuffer buf = tessellator.getBuffer(); - worldRenderer.startDrawing(GL_LINES); - worldRenderer.addVertex(x - size, y, 0); - worldRenderer.addVertex(x + size, y, 0); + buf.begin(GL_LINES, VF_POSITION); + buf.pos(x - size, y, 0).endVertex(); + buf.pos(x + size, y, 0).endVertex(); tessellator.draw(); - worldRenderer.startDrawing(GL_LINES); - worldRenderer.addVertex(x, y - size, 0); - worldRenderer.addVertex(x, y + size, 0); + buf.begin(GL_LINES, VF_POSITION); + buf.pos(x, y - size, 0).endVertex(); + buf.pos(x, y + size, 0).endVertex(); tessellator.draw(); glDisableColorLogic(); @@ -585,12 +585,12 @@ protected void drawTooltip(FontRenderer fontRenderer, String tooltipText, int mo public void drawTexturedModalRect(int x, int y, int x2, int y2, int u, int v, int u2, int v2) { Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldRenderer = tessellator.getWorldRenderer(); - worldRenderer.startDrawingQuads(); - worldRenderer.addVertexWithUV(x, y2, this.zLevel, (float)(u) * texMapScale, (float)(v2) * texMapScale); - worldRenderer.addVertexWithUV(x2, y2, this.zLevel, (float)(u2) * texMapScale, (float)(v2) * texMapScale); - worldRenderer.addVertexWithUV(x2, y, this.zLevel, (float)(u2) * texMapScale, (float)(v) * texMapScale); - worldRenderer.addVertexWithUV(x, y, this.zLevel, (float)(u) * texMapScale, (float)(v) * texMapScale); + VertexBuffer buf = tessellator.getBuffer(); + buf.begin(GL_QUADS, VF_POSITION_TEX); + buf.pos(x, y2, this.zLevel).tex((float)(u) * texMapScale, (float)(v2) * texMapScale).endVertex(); + buf.pos(x2, y2, this.zLevel).tex((float)(u2) * texMapScale, (float)(v2) * texMapScale).endVertex(); + buf.pos(x2, y, this.zLevel).tex((float)(u2) * texMapScale, (float)(v) * texMapScale).endVertex(); + buf.pos(x, y, this.zLevel).tex((float)(u) * texMapScale, (float)(v) * texMapScale).endVertex(); tessellator.draw(); } @@ -609,12 +609,12 @@ public void drawTexturedModalRect(int x, int y, int x2, int y2, int u, int v, in public void drawTexturedModalRectF(int x, int y, int x2, int y2, float u, float v, float u2, float v2) { Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldRenderer = tessellator.getWorldRenderer(); - worldRenderer.startDrawingQuads(); - worldRenderer.addVertexWithUV(x, y2, this.zLevel, u, v2); - worldRenderer.addVertexWithUV(x2, y2, this.zLevel, u2, v2); - worldRenderer.addVertexWithUV(x2, y, this.zLevel, u2, v); - worldRenderer.addVertexWithUV(x, y, this.zLevel, u, v); + VertexBuffer buf = tessellator.getBuffer(); + buf.begin(GL_QUADS, VF_POSITION_TEX); + buf.pos(x, y2, this.zLevel).tex(u, v2).endVertex(); + buf.pos(x2, y2, this.zLevel).tex(u2, v2).endVertex(); + buf.pos(x2, y, this.zLevel).tex(u2, v).endVertex(); + buf.pos(x, y, this.zLevel).tex(u, v).endVertex(); tessellator.draw(); } @@ -633,12 +633,12 @@ public void drawTexturedModalRectF(int x, int y, int x2, int y2, float u, float public void drawTexturedModalRect(int x, int y, int u, int v, int width, int height, float texMapScale) { Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldRenderer = tessellator.getWorldRenderer(); - worldRenderer.startDrawingQuads(); - worldRenderer.addVertexWithUV(x + 0, y + height, this.zLevel, (float)(u + 0) * texMapScale, (float)(v + height) * texMapScale); - worldRenderer.addVertexWithUV(x + width, y + height, this.zLevel, (float)(u + width) * texMapScale, (float)(v + height) * texMapScale); - worldRenderer.addVertexWithUV(x + width, y + 0, this.zLevel, (float)(u + width) * texMapScale, (float)(v + 0) * texMapScale); - worldRenderer.addVertexWithUV(x + 0, y + 0, this.zLevel, (float)(u + 0) * texMapScale, (float)(v + 0) * texMapScale); + VertexBuffer buf = tessellator.getBuffer(); + buf.begin(GL_QUADS, VF_POSITION_TEX); + buf.pos(x + 0, y + height, this.zLevel).tex((float)(u + 0) * texMapScale, (float)(v + height) * texMapScale).endVertex(); + buf.pos(x + width, y + height, this.zLevel).tex((float)(u + width) * texMapScale, (float)(v + height) * texMapScale).endVertex(); + buf.pos(x + width, y + 0, this.zLevel).tex((float)(u + width) * texMapScale, (float)(v + 0) * texMapScale).endVertex(); + buf.pos(x + 0, y + 0, this.zLevel).tex((float)(u + 0) * texMapScale, (float)(v + 0) * texMapScale).endVertex(); tessellator.draw(); } diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java b/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java index 6de8872b..b07c3f24 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java @@ -9,7 +9,7 @@ import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.VertexBuffer; import static com.mumfrey.liteloader.gl.GL.*; /** @@ -37,13 +37,13 @@ public Render2DBox(LineColour colour, List points, int min, int public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + VertexBuffer buf = tessellator.getBuffer(); double off = 0.03 - cameraPos.getY(); for (LineInfo tempColour : this.colour.getColours()) { tempColour.prepareRender(); - worldRenderer.startDrawing(GL_LINES); + buf.begin(GL_LINES, VF_POSITION); tempColour.prepareColour(); for (PointRectangle point : this.points) @@ -53,8 +53,8 @@ public void render(Vector3 cameraPos) Vector2 pos = point.getPoint(); double x = pos.getX() - cameraPos.getX(); double z = pos.getY() - cameraPos.getZ(); - worldRenderer.addVertex(x + 0.5, this.min + off, z + 0.5); - worldRenderer.addVertex(x + 0.5, this.max + 1 + off, z + 0.5); + buf.pos(x + 0.5, this.min + off, z + 0.5).endVertex(); + buf.pos(x + 0.5, this.max + 1 + off, z + 0.5).endVertex(); } } tessellator.draw(); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java b/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java index 4a1ff50c..849bceb5 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java @@ -9,7 +9,7 @@ import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.VertexBuffer; import static com.mumfrey.liteloader.gl.GL.*; /** @@ -45,12 +45,12 @@ public void render(Vector3 cameraPos) protected void drawPoly(Vector3 cameraPos, double height) { Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + VertexBuffer buf = tessellator.getBuffer(); for (LineInfo tempColour : this.colour.getColours()) { tempColour.prepareRender(); - worldRenderer.startDrawing(GL_LINE_LOOP); + buf.begin(GL_LINE_LOOP, VF_POSITION); tempColour.prepareColour(); for (PointRectangle point : this.points) { @@ -59,7 +59,7 @@ protected void drawPoly(Vector3 cameraPos, double height) Vector2 pos = point.getPoint(); double x = pos.getX() - cameraPos.getX(); double z = pos.getY() - cameraPos.getZ(); - worldRenderer.addVertex(x + 0.5, height - cameraPos.getY(), z + 0.5); + buf.pos(x + 0.5, height - cameraPos.getY(), z + 0.5).endVertex(); } } tessellator.draw(); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java index 8e32f8ce..9dc0aa40 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java @@ -6,7 +6,7 @@ import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.VertexBuffer; import static com.mumfrey.liteloader.gl.GL.*; /** @@ -37,7 +37,7 @@ public Render3DBox(LineColour colour, Vector3 first, Vector3 second) public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + VertexBuffer buf = tessellator.getBuffer(); double x1 = this.first.getX() - cameraPos.getX(); double y1 = this.first.getY() - cameraPos.getY(); double z1 = this.first.getZ() - cameraPos.getZ(); @@ -50,38 +50,38 @@ public void render(Vector3 cameraPos) tempColour.prepareRender(); // Draw bottom face - worldRenderer.startDrawing(GL_LINE_LOOP); + buf.begin(GL_LINE_LOOP, VF_POSITION); tempColour.prepareColour(); - worldRenderer.addVertex(x1, y1, z1); - worldRenderer.addVertex(x2, y1, z1); - worldRenderer.addVertex(x2, y1, z2); - worldRenderer.addVertex(x1, y1, z2); + buf.pos(x1, y1, z1).endVertex(); + buf.pos(x2, y1, z1).endVertex(); + buf.pos(x2, y1, z2).endVertex(); + buf.pos(x1, y1, z2).endVertex(); tessellator.draw(); // Draw top face - worldRenderer.startDrawing(GL_LINE_LOOP); + buf.begin(GL_LINE_LOOP, VF_POSITION); tempColour.prepareColour(); - worldRenderer.addVertex(x1, y2, z1); - worldRenderer.addVertex(x2, y2, z1); - worldRenderer.addVertex(x2, y2, z2); - worldRenderer.addVertex(x1, y2, z2); + buf.pos(x1, y2, z1).endVertex(); + buf.pos(x2, y2, z1).endVertex(); + buf.pos(x2, y2, z2).endVertex(); + buf.pos(x1, y2, z2).endVertex(); tessellator.draw(); // Draw join top and bottom faces - worldRenderer.startDrawing(GL_LINES); + buf.begin(GL_LINES, VF_POSITION); tempColour.prepareColour(); - worldRenderer.addVertex(x1, y1, z1); - worldRenderer.addVertex(x1, y2, z1); + buf.pos(x1, y1, z1).endVertex(); + buf.pos(x1, y2, z1).endVertex(); - worldRenderer.addVertex(x2, y1, z1); - worldRenderer.addVertex(x2, y2, z1); + buf.pos(x2, y1, z1).endVertex(); + buf.pos(x2, y2, z1).endVertex(); - worldRenderer.addVertex(x2, y1, z2); - worldRenderer.addVertex(x2, y2, z2); + buf.pos(x2, y1, z2).endVertex(); + buf.pos(x2, y2, z2).endVertex(); - worldRenderer.addVertex(x1, y1, z2); - worldRenderer.addVertex(x1, y2, z2); + buf.pos(x1, y1, z2).endVertex(); + buf.pos(x1, y2, z2).endVertex(); tessellator.draw(); } diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java index 319e263b..570de0eb 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java @@ -6,7 +6,7 @@ import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.VertexBuffer; import static com.mumfrey.liteloader.gl.GL.*; /** @@ -37,7 +37,7 @@ public Render3DGrid(LineColour colour, Vector3 first, Vector3 second) public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + VertexBuffer buf = tessellator.getBuffer(); double x1 = this.first.getX() - cameraPos.getX(); double y1 = this.first.getY() - cameraPos.getY(); double z1 = this.first.getZ() - cameraPos.getZ(); @@ -50,7 +50,7 @@ public void render(Vector3 cameraPos) { tempColour.prepareRender(); - worldRenderer.startDrawing(GL_LINES); + buf.begin(GL_LINES, VF_POSITION); tempColour.prepareColour(); double offsetSize = 1.0; @@ -58,14 +58,14 @@ public void render(Vector3 cameraPos) for (double yoff = 0; yoff + y1 <= y2; yoff += offsetSize) { double y = y1 + yoff; - worldRenderer.addVertex(x1, y, z2); - worldRenderer.addVertex(x2, y, z2); - worldRenderer.addVertex(x1, y, z1); - worldRenderer.addVertex(x2, y, z1); - worldRenderer.addVertex(x1, y, z1); - worldRenderer.addVertex(x1, y, z2); - worldRenderer.addVertex(x2, y, z1); - worldRenderer.addVertex(x2, y, z2); + buf.pos(x1, y, z2).endVertex(); + buf.pos(x2, y, z2).endVertex(); + buf.pos(x1, y, z1).endVertex(); + buf.pos(x2, y, z1).endVertex(); + buf.pos(x1, y, z1).endVertex(); + buf.pos(x1, y, z2).endVertex(); + buf.pos(x2, y, z1).endVertex(); + buf.pos(x2, y, z2).endVertex(); } for (double xoff = 0; xoff + x1 <= x2; xoff += offsetSize) @@ -74,14 +74,14 @@ public void render(Vector3 cameraPos) // boolean major = xoff % 10 == 0; if (x < -cullAt) continue; if (x > cullAt) break; - worldRenderer.addVertex(x, y1, z1); - worldRenderer.addVertex(x, y2, z1); - worldRenderer.addVertex(x, y1, z2); - worldRenderer.addVertex(x, y2, z2); - worldRenderer.addVertex(x, y2, z1); - worldRenderer.addVertex(x, y2, z2); - worldRenderer.addVertex(x, y1, z1); - worldRenderer.addVertex(x, y1, z2); + buf.pos(x, y1, z1).endVertex(); + buf.pos(x, y2, z1).endVertex(); + buf.pos(x, y1, z2).endVertex(); + buf.pos(x, y2, z2).endVertex(); + buf.pos(x, y2, z1).endVertex(); + buf.pos(x, y2, z2).endVertex(); + buf.pos(x, y1, z1).endVertex(); + buf.pos(x, y1, z2).endVertex(); } for (double zoff = 0; zoff + z1 <= z2; zoff += offsetSize) @@ -90,14 +90,14 @@ public void render(Vector3 cameraPos) // boolean major = zoff % 10 == 0; if (z < -cullAt) continue; if (z > cullAt) break; - worldRenderer.addVertex(x1, y1, z); - worldRenderer.addVertex(x2, y1, z); - worldRenderer.addVertex(x1, y2, z); - worldRenderer.addVertex(x2, y2, z); - worldRenderer.addVertex(x2, y1, z); - worldRenderer.addVertex(x2, y2, z); - worldRenderer.addVertex(x1, y1, z); - worldRenderer.addVertex(x1, y2, z); + buf.pos(x1, y1, z).endVertex(); + buf.pos(x2, y1, z).endVertex(); + buf.pos(x1, y2, z).endVertex(); + buf.pos(x2, y2, z).endVertex(); + buf.pos(x2, y1, z).endVertex(); + buf.pos(x2, y2, z).endVertex(); + buf.pos(x1, y1, z).endVertex(); + buf.pos(x1, y2, z).endVertex(); } tessellator.draw(); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java index 508ce75c..debba922 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java @@ -5,7 +5,7 @@ import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.VertexBuffer; import static com.mumfrey.liteloader.gl.GL.*; /** @@ -29,17 +29,17 @@ public Render3DPolygon(LineColour colour, Vector3... vertices) public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + VertexBuffer buf = tessellator.getBuffer(); for (LineInfo tempColour : this.colour.getColours()) { tempColour.prepareRender(); - worldRenderer.startDrawing(GL_LINE_LOOP); + buf.begin(GL_LINE_LOOP, VF_POSITION); tempColour.prepareColour(); for (Vector3 vertex : this.vertices) { - worldRenderer.addVertex(vertex.getX() - cameraPos.getX(), vertex.getY() - cameraPos.getY(), vertex.getZ() - cameraPos.getZ()); + buf.pos(vertex.getX() - cameraPos.getX(), vertex.getY() - cameraPos.getY(), vertex.getZ() - cameraPos.getZ()).endVertex(); } tessellator.draw(); } diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java index cece5004..268e2d3b 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java @@ -6,7 +6,7 @@ import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.VertexBuffer; import static com.mumfrey.liteloader.gl.GL.*; /** @@ -39,7 +39,7 @@ public RenderCylinderBox(LineColour colour, PointCube centre, double radX, doubl public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + VertexBuffer buf = tessellator.getBuffer(); double xPos = this.centreX - cameraPos.getX(); double zPos = this.centreZ - cameraPos.getZ(); @@ -51,7 +51,7 @@ public void render(Vector3 cameraPos) double twoPi = Math.PI * 2; for (int yBlock : new int[] { this.minY, this.maxY + 1 }) { - worldRenderer.startDrawing(GL_LINE_LOOP); + buf.begin(GL_LINE_LOOP, VF_POSITION); tempColour.prepareColour(); for (int i = 0; i <= 75; i++) @@ -60,7 +60,7 @@ public void render(Vector3 cameraPos) double tempX = this.radX * Math.cos(tempTheta); double tempZ = this.radZ * Math.sin(tempTheta); - worldRenderer.addVertex(xPos + tempX, yBlock - cameraPos.getY(), zPos + tempZ); + buf.pos(xPos + tempX, yBlock - cameraPos.getY(), zPos + tempZ).endVertex(); } tessellator.draw(); } diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java index 6c509942..e2820cf3 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java @@ -6,7 +6,7 @@ import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.VertexBuffer; import static com.mumfrey.liteloader.gl.GL.*; /** @@ -39,7 +39,7 @@ public RenderCylinderCircles(LineColour colour, PointCube centre, double radX, d public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + VertexBuffer buf = tessellator.getBuffer(); double xPos = this.centreX - cameraPos.getX(); double zPos = this.centreZ - cameraPos.getZ(); @@ -51,7 +51,7 @@ public void render(Vector3 cameraPos) double twoPi = Math.PI * 2; for (int yBlock = this.minY + 1; yBlock <= this.maxY; yBlock++) { - worldRenderer.startDrawing(GL_LINE_LOOP); + buf.begin(GL_LINE_LOOP, VF_POSITION); tempColour.prepareColour(); for (int i = 0; i <= 75; i++) @@ -60,7 +60,7 @@ public void render(Vector3 cameraPos) double tempX = this.radX * Math.cos(tempTheta); double tempZ = this.radZ * Math.sin(tempTheta); - worldRenderer.addVertex(xPos + tempX, yBlock - cameraPos.getY(), zPos + tempZ); + buf.pos(xPos + tempX, yBlock - cameraPos.getY(), zPos + tempZ).endVertex(); } tessellator.draw(); } diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java index 95544122..fca0d625 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java @@ -6,7 +6,7 @@ import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.VertexBuffer; import static com.mumfrey.liteloader.gl.GL.*; /** @@ -39,7 +39,7 @@ public RenderCylinderGrid(LineColour colour, PointCube centre, double radX, doub public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + VertexBuffer buf = tessellator.getBuffer(); double xPos = this.centreX - cameraPos.getX(); double zPos = this.centreZ - cameraPos.getZ(); @@ -58,13 +58,13 @@ public void render(Vector3 cameraPos) for (double tempX = negRadiusX; tempX <= posRadiusX; ++tempX) { double tempZ = this.radZ * Math.cos(Math.asin(tempX / this.radX)); - worldRenderer.startDrawing(GL_LINE_LOOP); + buf.begin(GL_LINE_LOOP, VF_POSITION); tempColour.prepareColour(); - worldRenderer.addVertex(xPos + tempX, tmaxY - cameraPos.getY(), zPos + tempZ); - worldRenderer.addVertex(xPos + tempX, tmaxY - cameraPos.getY(), zPos - tempZ); - worldRenderer.addVertex(xPos + tempX, tminY - cameraPos.getY(), zPos - tempZ); - worldRenderer.addVertex(xPos + tempX, tminY - cameraPos.getY(), zPos + tempZ); + buf.pos(xPos + tempX, tmaxY - cameraPos.getY(), zPos + tempZ).endVertex(); + buf.pos(xPos + tempX, tmaxY - cameraPos.getY(), zPos - tempZ).endVertex(); + buf.pos(xPos + tempX, tminY - cameraPos.getY(), zPos - tempZ).endVertex(); + buf.pos(xPos + tempX, tminY - cameraPos.getY(), zPos + tempZ).endVertex(); tessellator.draw(); } @@ -72,13 +72,13 @@ public void render(Vector3 cameraPos) for (double tempZ = negRadiusZ; tempZ <= posRadiusZ; ++tempZ) { double tempX = this.radX * Math.sin(Math.acos(tempZ / this.radZ)); - worldRenderer.startDrawing(GL_LINE_LOOP); + buf.begin(GL_LINE_LOOP, VF_POSITION); tempColour.prepareColour(); - worldRenderer.addVertex(xPos + tempX, tmaxY - cameraPos.getY(), zPos + tempZ); - worldRenderer.addVertex(xPos - tempX, tmaxY - cameraPos.getY(), zPos + tempZ); - worldRenderer.addVertex(xPos - tempX, tminY - cameraPos.getY(), zPos + tempZ); - worldRenderer.addVertex(xPos + tempX, tminY - cameraPos.getY(), zPos + tempZ); + buf.pos(xPos + tempX, tmaxY - cameraPos.getY(), zPos + tempZ).endVertex(); + buf.pos(xPos - tempX, tmaxY - cameraPos.getY(), zPos + tempZ).endVertex(); + buf.pos(xPos - tempX, tminY - cameraPos.getY(), zPos + tempZ).endVertex(); + buf.pos(xPos + tempX, tminY - cameraPos.getY(), zPos + tempZ).endVertex(); tessellator.draw(); } diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java index 0044db60..1c752355 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java @@ -6,7 +6,7 @@ import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.VertexBuffer; import static com.mumfrey.liteloader.gl.GL.*; /** @@ -54,12 +54,12 @@ public void render(Vector3 cameraPos) protected void drawXZPlane(LineInfo colour) { Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + VertexBuffer buf = tessellator.getBuffer(); int yRad = (int)Math.floor(this.radii.getY()); for (int yBlock = -yRad; yBlock < yRad; yBlock++) { - worldRenderer.startDrawing(GL_LINE_LOOP); + buf.begin(GL_LINE_LOOP, VF_POSITION); colour.prepareColour(); for (int i = 0; i <= 40; i++) @@ -68,12 +68,12 @@ protected void drawXZPlane(LineInfo colour) double tempX = this.radii.getX() * Math.cos(tempTheta) * Math.cos(Math.asin(yBlock / this.radii.getY())); double tempZ = this.radii.getZ() * Math.sin(tempTheta) * Math.cos(Math.asin(yBlock / this.radii.getY())); - worldRenderer.addVertex(tempX, yBlock, tempZ); + buf.pos(tempX, yBlock, tempZ).endVertex(); } tessellator.draw(); } - worldRenderer.startDrawing(GL_LINE_LOOP); + buf.begin(GL_LINE_LOOP, VF_POSITION); colour.prepareColour(); for (int i = 0; i <= 40; i++) @@ -82,7 +82,7 @@ protected void drawXZPlane(LineInfo colour) double tempX = this.radii.getX() * Math.cos(tempTheta); double tempZ = this.radii.getZ() * Math.sin(tempTheta); - worldRenderer.addVertex(tempX, 0.0, tempZ); + buf.pos(tempX, 0.0, tempZ).endVertex(); } tessellator.draw(); } @@ -90,12 +90,12 @@ protected void drawXZPlane(LineInfo colour) protected void drawYZPlane(LineInfo colour) { Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + VertexBuffer buf = tessellator.getBuffer(); int xRad = (int)Math.floor(this.radii.getX()); for (int xBlock = -xRad; xBlock < xRad; xBlock++) { - worldRenderer.startDrawing(GL_LINE_LOOP); + buf.begin(GL_LINE_LOOP, VF_POSITION); colour.prepareColour(); for (int i = 0; i <= 40; i++) @@ -104,12 +104,12 @@ protected void drawYZPlane(LineInfo colour) double tempY = this.radii.getY() * Math.cos(tempTheta) * Math.sin(Math.acos(xBlock / this.radii.getX())); double tempZ = this.radii.getZ() * Math.sin(tempTheta) * Math.sin(Math.acos(xBlock / this.radii.getX())); - worldRenderer.addVertex(xBlock, tempY, tempZ); + buf.pos(xBlock, tempY, tempZ).endVertex(); } tessellator.draw(); } - worldRenderer.startDrawing(GL_LINE_LOOP); + buf.begin(GL_LINE_LOOP, VF_POSITION); colour.prepareColour(); for (int i = 0; i <= 40; i++) @@ -118,7 +118,7 @@ protected void drawYZPlane(LineInfo colour) double tempY = this.radii.getY() * Math.cos(tempTheta); double tempZ = this.radii.getZ() * Math.sin(tempTheta); - worldRenderer.addVertex(0.0, tempY, tempZ); + buf.pos(0.0, tempY, tempZ).endVertex(); } tessellator.draw(); } @@ -126,12 +126,12 @@ protected void drawYZPlane(LineInfo colour) protected void drawXYPlane(LineInfo colour) { Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + VertexBuffer buf = tessellator.getBuffer(); int zRad = (int)Math.floor(this.radii.getZ()); for (int zBlock = -zRad; zBlock < zRad; zBlock++) { - worldRenderer.startDrawing(GL_LINE_LOOP); + buf.begin(GL_LINE_LOOP, VF_POSITION); colour.prepareColour(); for (int i = 0; i <= 40; i++) @@ -140,12 +140,12 @@ protected void drawXYPlane(LineInfo colour) double tempX = this.radii.getX() * Math.sin(tempTheta) * Math.sin(Math.acos(zBlock / this.radii.getZ())); double tempY = this.radii.getY() * Math.cos(tempTheta) * Math.sin(Math.acos(zBlock / this.radii.getZ())); - worldRenderer.addVertex(tempX, tempY, zBlock); + buf.pos(tempX, tempY, zBlock).endVertex(); } tessellator.draw(); } - worldRenderer.startDrawing(GL_LINE_LOOP); + buf.begin(GL_LINE_LOOP, VF_POSITION); colour.prepareColour(); for (int i = 0; i <= 40; i++) @@ -154,7 +154,7 @@ protected void drawXYPlane(LineInfo colour) double tempX = this.radii.getX() * Math.cos(tempTheta); double tempY = this.radii.getY() * Math.sin(tempTheta); - worldRenderer.addVertex(tempX, tempY, 0.0); + buf.pos(tempX, tempY, 0.0).endVertex(); } tessellator.draw(); } From 2e5fc85b0befafdba5dbb6461447cf8d9dd8fc52 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Tue, 17 May 2016 16:16:42 +0100 Subject: [PATCH 26/51] Update to 1.9.4 --- build.gradle | 8 ++++---- java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 01d3b15f..9a4670d6 100644 --- a/build.gradle +++ b/build.gradle @@ -18,13 +18,13 @@ buildscript { apply plugin: 'net.minecraftforge.gradle.liteloader' -version = "1.9.0_00" +version = "1.9.4_00" group = "com.mumfrey.worldeditcui" archivesBaseName = "worldeditcui" minecraft { - version = "1.9" - mappings = "snapshot_20160410" + version = "1.9.4" + mappings = "snapshot_20160517" runDir = "run" } @@ -38,7 +38,7 @@ sourceSets { litemod { json { author = "yetanotherx, Mumfrey, TomyLobo" - mcversion = "1.9" + mcversion = "1.9.4" description = "Client-side user interface for WorldEdit" } } diff --git a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java index c5a9694c..cc8e8a1d 100644 --- a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java @@ -195,7 +195,7 @@ public String getName() @Override public String getVersion() { - return "1.9.0_00"; + return "1.9.4_00"; } @Override From f7891c0840e3aae4fd8eca76352fadeb25f496e1 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Thu, 19 May 2016 15:57:44 +0100 Subject: [PATCH 27/51] Update to most recent liteloader snapshot --- build.gradle | 2 +- java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 9a4670d6..76c6c762 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,7 @@ buildscript { apply plugin: 'net.minecraftforge.gradle.liteloader' -version = "1.9.4_00" +version = "1.9.4_01" group = "com.mumfrey.worldeditcui" archivesBaseName = "worldeditcui" diff --git a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java index cc8e8a1d..d07ac84a 100644 --- a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java @@ -25,6 +25,7 @@ import com.mumfrey.liteloader.JoinGameListener; import com.mumfrey.liteloader.PluginChannelListener; import com.mumfrey.liteloader.PostRenderListener; +import com.mumfrey.liteloader.Tickable; import com.mumfrey.liteloader.core.ClientPluginChannels; import com.mumfrey.liteloader.core.LiteLoader; import com.mumfrey.liteloader.core.PluginChannels.ChannelPolicy; @@ -35,7 +36,7 @@ import com.mumfrey.worldeditcui.gui.CUIConfigPanel; import com.mumfrey.worldeditcui.render.region.CuboidRegion; -public class LiteModWorldEditCUI implements InitCompleteListener, PluginChannelListener, PostRenderListener, Configurable, JoinGameListener +public class LiteModWorldEditCUI implements Tickable, InitCompleteListener, PluginChannelListener, PostRenderListener, Configurable, JoinGameListener { private static final int DELAYED_HELO_TICKS = 10; @@ -195,7 +196,7 @@ public String getName() @Override public String getVersion() { - return "1.9.4_00"; + return "1.9.4_01"; } @Override From e5915331be71c896df3a10ba873015039ac98896 Mon Sep 17 00:00:00 2001 From: Coolboy21 Date: Wed, 1 Jun 2016 17:55:37 +0300 Subject: [PATCH 28/51] Ukrainian translation Add ukrainian translation for this mod. --- res/assets/wecui/lang/uk_UA | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 res/assets/wecui/lang/uk_UA diff --git a/res/assets/wecui/lang/uk_UA b/res/assets/wecui/lang/uk_UA new file mode 100644 index 00000000..f6c65e89 --- /dev/null +++ b/res/assets/wecui/lang/uk_UA @@ -0,0 +1,25 @@ +wecui.options.title=Налаштування WorldEditCUI + +wecui.keys.toggle=Перемкнути видимість CUI +wecui.keys.clear=Очистити виділення +wecui.keys.category=WorldEditCUI + +gui.ok=OK + +colour.cuboidedge=Колір границі кубоїда +colour.cuboidgrid=Колір сітки кубоїда +colour.cuboidpoint1=Колір першої точки кубоїда +colour.cuboidpoint2=Колір другої точки кубоїда +colour.polygrid=Колір сітки полігона +colour.polyedge=Колір границі полігона +colour.polypoint=Колір точки полігона +colour.ellipsoidgrid=Колір сітки еліпсоїда +colour.ellipsoidpoint=Колір центральної точки еліпсоїда +colour.cylindergrid=Колір сітки циліндра +colour.cylinderedge=Колір границі циліндра +colour.cylinderpoint=Колір центральної точки циліндра + +gui.options.compat.title=Параметри сумісності +gui.options.compat.spammy=Нерозбірливий режим (надсилає /we cui весь час) +gui.options.compat.ontop=Завжди зверху (сумісність модів) +gui.options.colours.title=Кольори виділення From b8fdc6b359b1d0d7bac52ccf3f597e7644d6b4c6 Mon Sep 17 00:00:00 2001 From: Timofey Date: Fri, 3 Jun 2016 14:17:35 +0300 Subject: [PATCH 29/51] Create ru_RU.lang --- res/assets/wecui/lang/ru_RU.lang | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 res/assets/wecui/lang/ru_RU.lang diff --git a/res/assets/wecui/lang/ru_RU.lang b/res/assets/wecui/lang/ru_RU.lang new file mode 100644 index 00000000..e801d81e --- /dev/null +++ b/res/assets/wecui/lang/ru_RU.lang @@ -0,0 +1,26 @@ +wecui.options.title=Настройки WorldEditCUI + +wecui.keys.toggle=Переключить видимость CUI +wecui.keys.clear=Очистить выделение WorldEdit +wecui.keys.category=WorldEditCUI + +gui.ok=ОК + +colour.cuboidedge=Цвет границ кубоида +colour.cuboidgrid=Цвет сетки кубоида +colour.cuboidpoint1=Цвет первой точки кубоида +colour.cuboidpoint2=Цвет второй точки кубоида +colour.polygrid=Цвет сетки многоугольника +colour.polyedge=Цвет границ многоугольника +colour.polypoint=Цвет точки многоугольника +colour.ellipsoidgrid=Цвет сетки эллипсоида +colour.ellipsoidpoint=Цвет центральной точки эллипсоида +colour.cylindergrid=Цвет сетки цилиндра +colour.cylinderedge=Цвет границ цилиндра +colour.cylinderpoint=Цвет центральной точки цилиндра + +gui.options.compat.title=Настройки совместимости +gui.options.compat.spammy=Неразборчивый режим (отправлять /we cui всё время) +gui.options.compat.ontop=Всегда сверху (совместимость модов) +gui.options.colours.title=Отображение цветов + From 294e405c7fc7a8a7a68b3055d6e7232575720096 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Sun, 19 Jun 2016 23:42:38 +0100 Subject: [PATCH 30/51] 1.10 update --- build.gradle | 10 +++++----- java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 76c6c762..a3c2562c 100644 --- a/build.gradle +++ b/build.gradle @@ -12,19 +12,19 @@ buildscript { } } dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT' + classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT' } } apply plugin: 'net.minecraftforge.gradle.liteloader' -version = "1.9.4_01" +version = "1.10_00" group = "com.mumfrey.worldeditcui" archivesBaseName = "worldeditcui" minecraft { - version = "1.9.4" - mappings = "snapshot_20160517" + version = "1.10" + mappings = "snapshot_20160619" runDir = "run" } @@ -38,7 +38,7 @@ sourceSets { litemod { json { author = "yetanotherx, Mumfrey, TomyLobo" - mcversion = "1.9.4" + mcversion = "1.10" description = "Client-side user interface for WorldEdit" } } diff --git a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java index d07ac84a..14517ce1 100644 --- a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java @@ -196,7 +196,7 @@ public String getName() @Override public String getVersion() { - return "1.9.4_01"; + return "1.10_00"; } @Override From e67611184c4005e3ade293e26200740955252f34 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Wed, 16 Nov 2016 16:30:44 +0000 Subject: [PATCH 31/51] 1.11 update --- build.gradle | 8 ++++---- .../worldeditcui/LiteModWorldEditCUI.java | 20 +++++++++---------- .../wecui/lang/{en_US.lang => en_us.lang} | 0 .../wecui/lang/{fr_FR.lang => fr_fr.lang} | 0 .../wecui/lang/{nl_NL.lang => nl_nl.lang} | 0 5 files changed, 14 insertions(+), 14 deletions(-) rename res/assets/wecui/lang/{en_US.lang => en_us.lang} (100%) rename res/assets/wecui/lang/{fr_FR.lang => fr_fr.lang} (100%) rename res/assets/wecui/lang/{nl_NL.lang => nl_nl.lang} (100%) diff --git a/build.gradle b/build.gradle index a3c2562c..eef3ee47 100644 --- a/build.gradle +++ b/build.gradle @@ -18,13 +18,13 @@ buildscript { apply plugin: 'net.minecraftforge.gradle.liteloader' -version = "1.10_00" +version = "1.11_00" group = "com.mumfrey.worldeditcui" archivesBaseName = "worldeditcui" minecraft { - version = "1.10" - mappings = "snapshot_20160619" + version = "1.11" + mappings = "snapshot_custom" runDir = "run" } @@ -38,7 +38,7 @@ sourceSets { litemod { json { author = "yetanotherx, Mumfrey, TomyLobo" - mcversion = "1.10" + mcversion = "1.11" description = "Client-side user interface for WorldEdit" } } diff --git a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java index 14517ce1..b8403aab 100644 --- a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java @@ -147,8 +147,8 @@ public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clo if (this.keyBindClearSel.isPressed()) { - if (mc.thePlayer != null) - mc.thePlayer.sendChatMessage("//sel"); + if (mc.player != null) + mc.player.sendChatMessage("//sel"); } } @@ -157,18 +157,18 @@ public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clo CUIConfiguration config = this.controller.getConfiguration(); this.alwaysOnTop = config.isAlwaysOnTop(); - if (mc.theWorld != this.lastWorld || mc.thePlayer != this.lastPlayer) + if (mc.world != this.lastWorld || mc.player != this.lastPlayer) { - this.lastWorld = mc.theWorld; - this.lastPlayer = mc.thePlayer; + this.lastWorld = mc.world; + this.lastPlayer = mc.player; this.controller.getDebugger().debug("World change detected, sending new handshake"); this.controller.setSelection(new CuboidRegion(this.controller)); this.helo(); this.delayedHelo = LiteModWorldEditCUI.DELAYED_HELO_TICKS; - if (mc.thePlayer != null && config.isPromiscuous()) + if (mc.player != null && config.isPromiscuous()) { - mc.thePlayer.sendChatMessage("/we cui"); //Tricks WE to send the current selection + mc.player.sendChatMessage("/we cui"); //Tricks WE to send the current selection } } @@ -178,9 +178,9 @@ public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clo if (this.delayedHelo == 0) { this.helo(); - if (LiteLoader.getClientPluginChannels().isRemoteChannelRegistered(CHANNEL_WECUI) && mc.thePlayer != null) + if (LiteLoader.getClientPluginChannels().isRemoteChannelRegistered(CHANNEL_WECUI) && mc.player != null) { - mc.thePlayer.sendChatMessage("/we cui"); + mc.player.sendChatMessage("/we cui"); } } } @@ -196,7 +196,7 @@ public String getName() @Override public String getVersion() { - return "1.10_00"; + return "1.11_00"; } @Override diff --git a/res/assets/wecui/lang/en_US.lang b/res/assets/wecui/lang/en_us.lang similarity index 100% rename from res/assets/wecui/lang/en_US.lang rename to res/assets/wecui/lang/en_us.lang diff --git a/res/assets/wecui/lang/fr_FR.lang b/res/assets/wecui/lang/fr_fr.lang similarity index 100% rename from res/assets/wecui/lang/fr_FR.lang rename to res/assets/wecui/lang/fr_fr.lang diff --git a/res/assets/wecui/lang/nl_NL.lang b/res/assets/wecui/lang/nl_nl.lang similarity index 100% rename from res/assets/wecui/lang/nl_NL.lang rename to res/assets/wecui/lang/nl_nl.lang From 395d1d5cf409775b560a0060bbca6420346770ed Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Tue, 6 Dec 2016 16:24:54 +0000 Subject: [PATCH 32/51] Update to production mappings --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index eef3ee47..a5f6c269 100644 --- a/build.gradle +++ b/build.gradle @@ -24,7 +24,7 @@ archivesBaseName = "worldeditcui" minecraft { version = "1.11" - mappings = "snapshot_custom" + mappings = "snapshot_20161124" runDir = "run" } @@ -38,7 +38,7 @@ sourceSets { litemod { json { author = "yetanotherx, Mumfrey, TomyLobo" - mcversion = "1.11" + mcversion = "1.11.r1" description = "Client-side user interface for WorldEdit" } } From ccec77ea3f025466d731b15d31c6d80e91872a87 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Sat, 24 Dec 2016 22:32:32 +0000 Subject: [PATCH 33/51] 1.11.2 update --- build.gradle | 6 +++--- java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index a5f6c269..bd6ed20f 100644 --- a/build.gradle +++ b/build.gradle @@ -18,12 +18,12 @@ buildscript { apply plugin: 'net.minecraftforge.gradle.liteloader' -version = "1.11_00" +version = "1.11.2_00" group = "com.mumfrey.worldeditcui" archivesBaseName = "worldeditcui" minecraft { - version = "1.11" + version = "1.11.2" mappings = "snapshot_20161124" runDir = "run" } @@ -38,7 +38,7 @@ sourceSets { litemod { json { author = "yetanotherx, Mumfrey, TomyLobo" - mcversion = "1.11.r1" + mcversion = "1.11.r2" description = "Client-side user interface for WorldEdit" } } diff --git a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java index b8403aab..b471635e 100644 --- a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java @@ -196,7 +196,7 @@ public String getName() @Override public String getVersion() { - return "1.11_00"; + return "1.11.2_00"; } @Override From 38acf0f8227dffcf9ec19c971aa3a8ad002aca92 Mon Sep 17 00:00:00 2001 From: X00LA Date: Sat, 14 Jan 2017 02:56:36 +0100 Subject: [PATCH 34/51] Created de_de.lang Added german translation. --- res/assets/wecui/lang/de.de.lang | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 res/assets/wecui/lang/de.de.lang diff --git a/res/assets/wecui/lang/de.de.lang b/res/assets/wecui/lang/de.de.lang new file mode 100644 index 00000000..612d6e18 --- /dev/null +++ b/res/assets/wecui/lang/de.de.lang @@ -0,0 +1,25 @@ +wecui.options.title=WorldEditCUI Optionen + +wecui.keys.toggle=CUI Sichtbarkeit An/Aus +wecui.keys.clear=WorldEdit Auswahl aufheben +wecui.keys.category=WorldEditCUI + +gui.ok=OK + +colour.cuboidedge=Quader Randfarbe +colour.cuboidgrid=Quader Rasterfarbe +colour.cuboidpoint1=1. Quader Auswahlpunkt Farbe +colour.cuboidpoint2=2. Quader Auswahlpunkt Farbe +colour.polygrid=Polygon Rasterfarbe +colour.polyedge=Polygon Randfarbe +colour.polypoint=Polygon Punktfarbe +colour.ellipsoidgrid=Ellipsoid Rasterfarbe +colour.ellipsoidpoint=Ellipsoid Mittelpunktfarbe +colour.cylindergrid=Zylinder Rasterfarbe +colour.cylinderedge=Zylinder Randfarbe +colour.cylinderpoint=Zylinder Mittelpunktfarbe + +gui.options.compat.title=Kompatibilitätsoptionen +gui.options.compat.spammy=Promiskuitiver Modus (sende /we cui die ganze Zeit) +gui.options.compat.ontop=Immer im Vordergrund (Mod Kompatibilität) +gui.options.colours.title=Anzeigefarben From e0450192fbe843eb1a342f0f4130029ea40c6c9c Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Tue, 13 Jun 2017 15:58:21 +0100 Subject: [PATCH 35/51] 1.12 Update --- build.gradle | 9 ++- gradle.properties | 5 ++ .../worldeditcui/LiteModWorldEditCUI.java | 2 +- .../worldeditcui/gui/CUIConfigPanel.java | 8 +-- .../gui/controls/GuiColourButton.java | 20 +++--- .../gui/controls/GuiColourPicker.java | 70 +++++++++---------- .../worldeditcui/gui/controls/GuiControl.java | 26 +++---- .../render/shapes/Render2DBox.java | 4 +- .../render/shapes/Render2DGrid.java | 4 +- .../render/shapes/Render3DBox.java | 4 +- .../render/shapes/Render3DGrid.java | 4 +- .../render/shapes/Render3DPolygon.java | 4 +- .../render/shapes/RenderCylinderBox.java | 4 +- .../render/shapes/RenderCylinderCircles.java | 4 +- .../render/shapes/RenderCylinderGrid.java | 4 +- .../render/shapes/RenderEllipsoid.java | 8 +-- 16 files changed, 92 insertions(+), 88 deletions(-) create mode 100644 gradle.properties diff --git a/build.gradle b/build.gradle index bd6ed20f..34c07226 100644 --- a/build.gradle +++ b/build.gradle @@ -12,19 +12,18 @@ buildscript { } } dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT' + classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' } } apply plugin: 'net.minecraftforge.gradle.liteloader' -version = "1.11.2_00" group = "com.mumfrey.worldeditcui" archivesBaseName = "worldeditcui" minecraft { - version = "1.11.2" - mappings = "snapshot_20161124" + version = project.mcVersion + mappings = project.mcMappings runDir = "run" } @@ -38,7 +37,7 @@ sourceSets { litemod { json { author = "yetanotherx, Mumfrey, TomyLobo" - mcversion = "1.11.r2" + mcversion = project.targetVersion description = "Client-side user interface for WorldEdit" } } diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 00000000..f50996e6 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,5 @@ +name=WorldEditCUI +version=1.12 +mcVersion=1.12 +mcMappings=snapshot_20170609 +targetVersion=1.12.r1 \ No newline at end of file diff --git a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java index b471635e..89d960da 100644 --- a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java @@ -196,7 +196,7 @@ public String getName() @Override public String getVersion() { - return "1.11.2_00"; + return "1.12_00"; } @Override diff --git a/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java b/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java index 3c8dbf2c..0868dcde 100644 --- a/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java +++ b/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java @@ -114,17 +114,17 @@ public void onTick(ConfigPanelHost host) @Override public void drawPanel(ConfigPanelHost host, int mouseX, int mouseY, float partialTicks) { - this.drawString(this.mc.fontRendererObj, I18n.format("gui.options.compat.title"), 10, 10, 0xFFFFFF55); - this.drawString(this.mc.fontRendererObj, I18n.format("gui.options.colours.title"), 10, 64, 0xFFFFFF55); + this.drawString(this.mc.fontRenderer, I18n.format("gui.options.compat.title"), 10, 10, 0xFFFFFF55); + this.drawString(this.mc.fontRenderer, I18n.format("gui.options.colours.title"), 10, 64, 0xFFFFFF55); for (GuiButton control : this.controlList) { - control.drawButton(this.mc, mouseX, mouseY); + control.func_191745_a(this.mc, mouseX, mouseY, partialTicks); // drawButton } for (GuiColourButton colourButton : this.colourButtonList) { - colourButton.drawPicker(this.mc, mouseX, mouseY); + colourButton.drawPicker(this.mc, mouseX, mouseY, partialTicks); } } diff --git a/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java index 6243a669..a7df2720 100644 --- a/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java +++ b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java @@ -53,37 +53,37 @@ public void save() } @Override - public void drawControl(Minecraft minecraft, int mouseX, int mouseY) + public void drawControl(Minecraft minecraft, int mouseX, int mouseY, float partialTicks) { if (this.visible) { - boolean mouseOver = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; + boolean mouseOver = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height; int borderColour = mouseOver || this.picker != null ? 0xFFFFFFFF : 0xFFA0A0A0; - drawRect(this.xPosition, this.yPosition, this.xPosition + this.width, this.yPosition + this.height, borderColour); + drawRect(this.x, this.y, this.x + this.width, this.y + this.height, borderColour); int v = Math.min(Math.max((int)(((float)this.height / (float)this.width) * 1024F), 256), 1024); minecraft.getTextureManager().bindTexture(GuiColourPicker.COLOURPICKER_CHECKER); glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - this.drawTexturedModalRect(this.xPosition + 1, this.yPosition + 1, this.xPosition + this.width - 1, this.yPosition + this.height - 1, 0, 0, 1024, v); + this.drawTexturedModalRect(this.x + 1, this.y + 1, this.x + this.width - 1, this.y + this.height - 1, 0, 0, 1024, v); - drawRect(this.xPosition + 1, this.yPosition + 1, this.xPosition + this.width - 1, this.yPosition + this.height - 1, this.colour); + drawRect(this.x + 1, this.y + 1, this.x + this.width - 1, this.y + this.height - 1, this.colour); this.mouseDragged(minecraft, mouseX, mouseY); if (this.displayString != null && this.displayString.length() > 0) { - this.drawString(minecraft.fontRendererObj, this.displayString, this.xPosition + this.width + 8, this.yPosition + (this.height - 8) / 2, 0xFFFFFFFF); + this.drawString(minecraft.fontRenderer, this.displayString, this.x + this.width + 8, this.y + (this.height - 8) / 2, 0xFFFFFFFF); } } } - public void drawPicker(Minecraft minecraft, int mouseX, int mouseY) + public void drawPicker(Minecraft minecraft, int mouseX, int mouseY, float partialTicks) { if (this.visible && this.picker != null) { - this.picker.drawButton(minecraft, mouseX, mouseY); + this.picker.func_191745_a(minecraft, mouseX, mouseY, partialTicks); // drawButton if (this.picker.getDialogResult() == DialogResult.OK) { @@ -132,8 +132,8 @@ public boolean mousePressed(Minecraft minecraft, int mouseX, int mouseY) { if (pressed) { - int xPos = Math.min(this.xPosition + this.width, GuiControl.lastScreenWidth - 233); - int yPos = Math.min(this.yPosition, GuiControl.lastScreenHeight - 175); + int xPos = Math.min(this.x + this.width, GuiControl.lastScreenWidth - 233); + int yPos = Math.min(this.y, GuiControl.lastScreenHeight - 175); this.picker = new GuiColourPicker(minecraft, 1, xPos, yPos, this.colour, "Choose colour"); this.pickerClicked = false; diff --git a/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java index 36217f0a..313ba80a 100644 --- a/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java +++ b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java @@ -81,23 +81,23 @@ public GuiColourPicker(Minecraft minecraft, int controlId, int xPos, int yPos, i if (this.opacity == 0x01000000) this.opacity = 0; - this.fontRenderer = minecraft.fontRendererObj; - this.txtRed = new GuiTextField(0, this.fontRenderer, this.xPosition + 188, this.yPosition + 10, 32, 16); - this.txtGreen = new GuiTextField(1, this.fontRenderer, this.xPosition + 188, this.yPosition + 30, 32, 16); - this.txtBlue = new GuiTextField(2, this.fontRenderer, this.xPosition + 188, this.yPosition + 50, 32, 16); - this.txtAlpha = new GuiTextField(3, this.fontRenderer, this.xPosition + 188, this.yPosition + 70, 32, 16); + this.fontRenderer = minecraft.fontRenderer; + this.txtRed = new GuiTextField(0, this.fontRenderer, this.x + 188, this.y + 10, 32, 16); + this.txtGreen = new GuiTextField(1, this.fontRenderer, this.x + 188, this.y + 30, 32, 16); + this.txtBlue = new GuiTextField(2, this.fontRenderer, this.x + 188, this.y + 50, 32, 16); + this.txtAlpha = new GuiTextField(3, this.fontRenderer, this.x + 188, this.y + 70, 32, 16); this.txtRed.setMaxStringLength(3); this.txtGreen.setMaxStringLength(3); this.txtBlue.setMaxStringLength(3); this.txtAlpha.setMaxStringLength(3); - this.rectHSArea = new Rectangle(this.xPosition + 10, this.yPosition + 10, 128, 128); - this.rectBArea = new Rectangle(this.xPosition + 143, this.yPosition + 10, 15, 128); - this.rectAArea = new Rectangle(this.xPosition + 163, this.yPosition + 10, 15, 128); + this.rectHSArea = new Rectangle(this.x + 10, this.y + 10, 128, 128); + this.rectBArea = new Rectangle(this.x + 143, this.y + 10, 15, 128); + this.rectAArea = new Rectangle(this.x + 163, this.y + 10, 15, 128); - this.btnOk = new GuiControl(minecraft, 0, this.xPosition + 9, this.yPosition + 145, 55, 20, I18n.format("gui.ok")); - this.btnCancel = new GuiControl(minecraft, 1, this.xPosition + 70, this.yPosition + 145, 65, 20, I18n.format("gui.cancel")); + this.btnOk = new GuiControl(minecraft, 0, this.x + 9, this.y + 145, 55, 20, I18n.format("gui.ok")); + this.btnCancel = new GuiControl(minecraft, 1, this.x + 70, this.y + 145, 65, 20, I18n.format("gui.cancel")); this.updateColour(); } @@ -115,47 +115,47 @@ public int getColour() } @Override - protected void drawControl(Minecraft minecraft, int mouseX, int mouseY) + protected void drawControl(Minecraft minecraft, int mouseX, int mouseY, float partialTicks) { this.mouseDragged(minecraft, mouseX, mouseY); // Calculate coordinates for the selectors - int hPos = this.xPosition + 10 + (int)(128F * this.hsb[H]); - int sPos = this.yPosition + 10 + (128 - (int)(128F * this.hsb[S])); - int bPos = this.yPosition + 10 + (128 - (int)(128F * this.hsb[B])); - int aPos = this.yPosition + 10 + ((256 - ((this.opacity >> 24) & 0xFF)) / 2); + int hPos = this.x + 10 + (int)(128F * this.hsb[H]); + int sPos = this.y + 10 + (128 - (int)(128F * this.hsb[S])); + int bPos = this.y + 10 + (128 - (int)(128F * this.hsb[B])); + int aPos = this.y + 10 + ((256 - ((this.opacity >> 24) & 0xFF)) / 2); // Calculate B colour int brightness = Color.HSBtoRGB(this.hsb[H], this.hsb[S], 1.0F) | 0xFF000000; // Draw backgrounds - drawRect(this.xPosition, this.yPosition, this.xPosition + this.width, this.yPosition + this.height, 0xAA000000); // Background - drawRect(this.xPosition + 9, this.yPosition + 9, this.xPosition + 139, this.yPosition + 139, 0xFFA0A0A0); // HS background - drawRect(this.xPosition + 142, this.yPosition + 9, this.xPosition + 159, this.yPosition + 139, 0xFFA0A0A0); // B background - drawRect(this.xPosition + 162, this.yPosition + 9, this.xPosition + 179, this.yPosition + 139, 0xFFA0A0A0); // A background - drawRect(this.xPosition + 187, this.yPosition + 105, this.xPosition + 221, this.yPosition + 139, 0xFFA0A0A0); // Preview background + drawRect(this.x, this.y, this.x + this.width, this.y + this.height, 0xAA000000); // Background + drawRect(this.x + 9, this.y + 9, this.x + 139, this.y + 139, 0xFFA0A0A0); // HS background + drawRect(this.x + 142, this.y + 9, this.x + 159, this.y + 139, 0xFFA0A0A0); // B background + drawRect(this.x + 162, this.y + 9, this.x + 179, this.y + 139, 0xFFA0A0A0); // A background + drawRect(this.x + 187, this.y + 105, this.x + 221, this.y + 139, 0xFFA0A0A0); // Preview background // Draw colour picker this.mc.getTextureManager().bindTexture(GuiColourPicker.COLOURPICKER_PICKER); glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - this.drawTexturedModalRect(this.xPosition + 10, this.yPosition + 10, this.xPosition + 138, this.yPosition + 138, 0, 0, 256, 256); + this.drawTexturedModalRect(this.x + 10, this.y + 10, this.x + 138, this.y + 138, 0, 0, 256, 256); this.drawCrossHair(hPos, sPos, 5, 1, 0xFF000000); // Draw brightness bar - this.drawGradientRect(this.xPosition + 143, this.yPosition + 10, this.xPosition + 158, this.yPosition + 138, brightness, 0xFF000000); - this.drawRotText(this.fontRenderer, "Luminosity", this.xPosition + 150, this.yPosition + 74, 0xFF000000, false); - drawRect(this.xPosition + 142, bPos - 1, this.xPosition + 159, bPos + 1, 0xFFFFFFFF); + this.drawGradientRect(this.x + 143, this.y + 10, this.x + 158, this.y + 138, brightness, 0xFF000000); + this.drawRotText(this.fontRenderer, "Luminosity", this.x + 150, this.y + 74, 0xFF000000, false); + drawRect(this.x + 142, bPos - 1, this.x + 159, bPos + 1, 0xFFFFFFFF); // Draw opacity bar - this.drawGradientRect(this.xPosition + 163, this.yPosition + 10, this.xPosition + 178, this.yPosition + 138, 0xFFFFFFFF, 0xFF000000); - this.drawRotText(this.fontRenderer, "Opacity", this.xPosition + 170, this.yPosition + 74, 0xFF000000, false); - drawRect(this.xPosition + 162, aPos - 1, this.xPosition + 179, aPos + 1, 0xFFFFFFFF); + this.drawGradientRect(this.x + 163, this.y + 10, this.x + 178, this.y + 138, 0xFFFFFFFF, 0xFF000000); + this.drawRotText(this.fontRenderer, "Opacity", this.x + 170, this.y + 74, 0xFF000000, false); + drawRect(this.x + 162, aPos - 1, this.x + 179, aPos + 1, 0xFFFFFFFF); // Draw preview this.mc.getTextureManager().bindTexture(GuiColourPicker.COLOURPICKER_CHECKER); glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - this.drawTexturedModalRect(this.xPosition + 188, this.yPosition + 106, this.xPosition + 220, this.yPosition + 138, 0, 0, 1024, 1024); - drawRect(this.xPosition + 188, this.yPosition + 106, this.xPosition + 220, this.yPosition + 138, this.rgb); + this.drawTexturedModalRect(this.x + 188, this.y + 106, this.x + 220, this.y + 138, 0, 0, 1024, 1024); + drawRect(this.x + 188, this.y + 106, this.x + 220, this.y + 138, this.rgb); // Draw text boxes this.txtRed.drawTextBox(); @@ -163,8 +163,8 @@ protected void drawControl(Minecraft minecraft, int mouseX, int mouseY) this.txtBlue.drawTextBox(); this.txtAlpha.drawTextBox(); - this.btnOk.drawButton(minecraft, mouseX, mouseY); - this.btnCancel.drawButton(minecraft, mouseX, mouseY); + this.btnOk.func_191745_a(minecraft, mouseX, mouseY, partialTicks); // drawButton + this.btnCancel.func_191745_a(minecraft, mouseX, mouseY, partialTicks); // drawButton } public void updateCursorCounter() @@ -223,20 +223,20 @@ protected void mouseDragged(Minecraft minecraft, int mouseX, int mouseY) if (this.draggingHS) { - this.hsb[H] = clamp(mouseX - this.xPosition - 10, 0, 128) / 128F; - this.hsb[S] = (128F - clamp(mouseY - this.yPosition - 10, 0, 128)) / 128F; + this.hsb[H] = clamp(mouseX - this.x - 10, 0, 128) / 128F; + this.hsb[S] = (128F - clamp(mouseY - this.y - 10, 0, 128)) / 128F; this.updateColour(); } if (this.draggingB) { - this.hsb[B] = (128F - clamp(mouseY - this.yPosition - 10, 0, 128)) / 128F; + this.hsb[B] = (128F - clamp(mouseY - this.y - 10, 0, 128)) / 128F; this.updateColour(); } if (this.draggingA) { - this.opacity = (mouseY - this.yPosition < 11) ? 0xFF000000 : (((128 - (int)clamp(mouseY - this.yPosition - 10, 0, 128)) << 25) & 0xFF000000); + this.opacity = (mouseY - this.y < 11) ? 0xFF000000 : (((128 - (int)clamp(mouseY - this.y - 10, 0, 128)) << 25) & 0xFF000000); this.updateColour(); } } diff --git a/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java b/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java index eb337b74..4848a1f1 100644 --- a/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java +++ b/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java @@ -4,7 +4,7 @@ import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.VertexBuffer; +import net.minecraft.client.renderer.BufferBuilder; import static com.mumfrey.liteloader.gl.GL.*; /** @@ -97,9 +97,9 @@ public enum DialogResult * @param mouseY Mouse Y coordinate */ @Override - public final void drawButton(Minecraft minecraft, int mouseX, int mouseY) + public final void func_191745_a(Minecraft minecraft, int mouseX, int mouseY, float partialTicks) // drawButton { - this.drawControl(minecraft, mouseX, mouseY); + this.drawControl(minecraft, mouseX, mouseY, partialTicks); } /** @@ -109,9 +109,9 @@ public final void drawButton(Minecraft minecraft, int mouseX, int mouseY) * @param mouseX Mouse X coordinate * @param mouseY Mouse Y coordinate */ - protected void drawControl(Minecraft minecraft, int mouseX, int mouseY) + protected void drawControl(Minecraft minecraft, int mouseX, int mouseY, float partialTicks) { - super.drawButton(minecraft, mouseX, mouseY); + super.func_191745_a(minecraft, mouseX, mouseY, partialTicks); } /** @@ -201,7 +201,7 @@ public static void drawNativeLine(float x1, float y1, float x2, float y2, float glLineWidth(width); Tessellator tessellator = Tessellator.getInstance(); - VertexBuffer buf = tessellator.getBuffer(); + BufferBuilder buf = tessellator.getBuffer(); buf.begin(GL_LINES, VF_POSITION); buf.pos(x1, y1, 0).endVertex(); buf.pos(x2, y2, 0).endVertex(); @@ -270,7 +270,7 @@ public static void drawArrow(int x1, int y1, int x2, int y2, int z, int width, i // Draw the line Tessellator tessellator = Tessellator.getInstance(); - VertexBuffer buf = tessellator.getBuffer(); + BufferBuilder buf = tessellator.getBuffer(); buf.begin(GL_QUADS, VF_POSITION); buf.pos(x1, y2, z).endVertex(); buf.pos(x2, y2, z).endVertex(); @@ -321,7 +321,7 @@ public void setTexMapSize(int textureSize) public void drawTexturedModalRectRot(int x, int y, int x2, int y2, int u, int v, int u2, int v2) { Tessellator tessellator = Tessellator.getInstance(); - VertexBuffer buf = tessellator.getBuffer(); + BufferBuilder buf = tessellator.getBuffer(); buf.begin(GL_QUADS, VF_POSITION_TEX); buf.pos(x2, y2, this.zLevel).tex((float)(u) * texMapScale, (float)(v2) * texMapScale).endVertex(); buf.pos(x2, y, this.zLevel).tex((float)(u2) * texMapScale, (float)(v2) * texMapScale).endVertex(); @@ -344,7 +344,7 @@ public void drawTexturedModalRectRot(int x, int y, int x2, int y2, int u, int v, public void drawTexturedModalRectRot(int x, int y, int u, int v, int width, int height) { Tessellator tessellator = Tessellator.getInstance(); - VertexBuffer buf = tessellator.getBuffer(); + BufferBuilder buf = tessellator.getBuffer(); buf.begin(GL_QUADS, VF_POSITION_TEX); buf.pos(x + height, y + width, this.zLevel).tex((float)(u) * texMapScale, (float)(v + height) * texMapScale).endVertex(); buf.pos(x + height, y, this.zLevel).tex((float)(u + width) * texMapScale, (float)(v + height) * texMapScale).endVertex(); @@ -505,7 +505,7 @@ protected void drawCrossHair(int x, int y, int size, int width, int colour) // Draw the frame Tessellator tessellator = Tessellator.getInstance(); - VertexBuffer buf = tessellator.getBuffer(); + BufferBuilder buf = tessellator.getBuffer(); buf.begin(GL_LINES, VF_POSITION); buf.pos(x - size, y, 0).endVertex(); @@ -585,7 +585,7 @@ protected void drawTooltip(FontRenderer fontRenderer, String tooltipText, int mo public void drawTexturedModalRect(int x, int y, int x2, int y2, int u, int v, int u2, int v2) { Tessellator tessellator = Tessellator.getInstance(); - VertexBuffer buf = tessellator.getBuffer(); + BufferBuilder buf = tessellator.getBuffer(); buf.begin(GL_QUADS, VF_POSITION_TEX); buf.pos(x, y2, this.zLevel).tex((float)(u) * texMapScale, (float)(v2) * texMapScale).endVertex(); buf.pos(x2, y2, this.zLevel).tex((float)(u2) * texMapScale, (float)(v2) * texMapScale).endVertex(); @@ -609,7 +609,7 @@ public void drawTexturedModalRect(int x, int y, int x2, int y2, int u, int v, in public void drawTexturedModalRectF(int x, int y, int x2, int y2, float u, float v, float u2, float v2) { Tessellator tessellator = Tessellator.getInstance(); - VertexBuffer buf = tessellator.getBuffer(); + BufferBuilder buf = tessellator.getBuffer(); buf.begin(GL_QUADS, VF_POSITION_TEX); buf.pos(x, y2, this.zLevel).tex(u, v2).endVertex(); buf.pos(x2, y2, this.zLevel).tex(u2, v2).endVertex(); @@ -633,7 +633,7 @@ public void drawTexturedModalRectF(int x, int y, int x2, int y2, float u, float public void drawTexturedModalRect(int x, int y, int u, int v, int width, int height, float texMapScale) { Tessellator tessellator = Tessellator.getInstance(); - VertexBuffer buf = tessellator.getBuffer(); + BufferBuilder buf = tessellator.getBuffer(); buf.begin(GL_QUADS, VF_POSITION_TEX); buf.pos(x + 0, y + height, this.zLevel).tex((float)(u + 0) * texMapScale, (float)(v + height) * texMapScale).endVertex(); buf.pos(x + width, y + height, this.zLevel).tex((float)(u + width) * texMapScale, (float)(v + height) * texMapScale).endVertex(); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java b/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java index b07c3f24..b604a336 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java @@ -9,7 +9,7 @@ import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.VertexBuffer; +import net.minecraft.client.renderer.BufferBuilder; import static com.mumfrey.liteloader.gl.GL.*; /** @@ -37,7 +37,7 @@ public Render2DBox(LineColour colour, List points, int min, int public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); - VertexBuffer buf = tessellator.getBuffer(); + BufferBuilder buf = tessellator.getBuffer(); double off = 0.03 - cameraPos.getY(); for (LineInfo tempColour : this.colour.getColours()) { diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java b/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java index 849bceb5..4e595809 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java @@ -9,7 +9,7 @@ import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.VertexBuffer; +import net.minecraft.client.renderer.BufferBuilder; import static com.mumfrey.liteloader.gl.GL.*; /** @@ -45,7 +45,7 @@ public void render(Vector3 cameraPos) protected void drawPoly(Vector3 cameraPos, double height) { Tessellator tessellator = Tessellator.getInstance(); - VertexBuffer buf = tessellator.getBuffer(); + BufferBuilder buf = tessellator.getBuffer(); for (LineInfo tempColour : this.colour.getColours()) { tempColour.prepareRender(); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java index 9dc0aa40..290f6ef0 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java @@ -6,7 +6,7 @@ import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.VertexBuffer; +import net.minecraft.client.renderer.BufferBuilder; import static com.mumfrey.liteloader.gl.GL.*; /** @@ -37,7 +37,7 @@ public Render3DBox(LineColour colour, Vector3 first, Vector3 second) public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); - VertexBuffer buf = tessellator.getBuffer(); + BufferBuilder buf = tessellator.getBuffer(); double x1 = this.first.getX() - cameraPos.getX(); double y1 = this.first.getY() - cameraPos.getY(); double z1 = this.first.getZ() - cameraPos.getZ(); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java index 570de0eb..c230bc9c 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java @@ -6,7 +6,7 @@ import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.VertexBuffer; +import net.minecraft.client.renderer.BufferBuilder; import static com.mumfrey.liteloader.gl.GL.*; /** @@ -37,7 +37,7 @@ public Render3DGrid(LineColour colour, Vector3 first, Vector3 second) public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); - VertexBuffer buf = tessellator.getBuffer(); + BufferBuilder buf = tessellator.getBuffer(); double x1 = this.first.getX() - cameraPos.getX(); double y1 = this.first.getY() - cameraPos.getY(); double z1 = this.first.getZ() - cameraPos.getZ(); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java index debba922..fa662afb 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java @@ -5,7 +5,7 @@ import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.VertexBuffer; +import net.minecraft.client.renderer.BufferBuilder; import static com.mumfrey.liteloader.gl.GL.*; /** @@ -29,7 +29,7 @@ public Render3DPolygon(LineColour colour, Vector3... vertices) public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); - VertexBuffer buf = tessellator.getBuffer(); + BufferBuilder buf = tessellator.getBuffer(); for (LineInfo tempColour : this.colour.getColours()) { diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java index 268e2d3b..92c1f86a 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java @@ -6,7 +6,7 @@ import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.VertexBuffer; +import net.minecraft.client.renderer.BufferBuilder; import static com.mumfrey.liteloader.gl.GL.*; /** @@ -39,7 +39,7 @@ public RenderCylinderBox(LineColour colour, PointCube centre, double radX, doubl public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); - VertexBuffer buf = tessellator.getBuffer(); + BufferBuilder buf = tessellator.getBuffer(); double xPos = this.centreX - cameraPos.getX(); double zPos = this.centreZ - cameraPos.getZ(); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java index e2820cf3..228abcf4 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java @@ -6,7 +6,7 @@ import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.VertexBuffer; +import net.minecraft.client.renderer.BufferBuilder; import static com.mumfrey.liteloader.gl.GL.*; /** @@ -39,7 +39,7 @@ public RenderCylinderCircles(LineColour colour, PointCube centre, double radX, d public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); - VertexBuffer buf = tessellator.getBuffer(); + BufferBuilder buf = tessellator.getBuffer(); double xPos = this.centreX - cameraPos.getX(); double zPos = this.centreZ - cameraPos.getZ(); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java index fca0d625..f914b6a6 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java @@ -6,7 +6,7 @@ import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.VertexBuffer; +import net.minecraft.client.renderer.BufferBuilder; import static com.mumfrey.liteloader.gl.GL.*; /** @@ -39,7 +39,7 @@ public RenderCylinderGrid(LineColour colour, PointCube centre, double radX, doub public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); - VertexBuffer buf = tessellator.getBuffer(); + BufferBuilder buf = tessellator.getBuffer(); double xPos = this.centreX - cameraPos.getX(); double zPos = this.centreZ - cameraPos.getZ(); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java index 1c752355..8ee94cc5 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java @@ -6,7 +6,7 @@ import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.VertexBuffer; +import net.minecraft.client.renderer.BufferBuilder; import static com.mumfrey.liteloader.gl.GL.*; /** @@ -54,7 +54,7 @@ public void render(Vector3 cameraPos) protected void drawXZPlane(LineInfo colour) { Tessellator tessellator = Tessellator.getInstance(); - VertexBuffer buf = tessellator.getBuffer(); + BufferBuilder buf = tessellator.getBuffer(); int yRad = (int)Math.floor(this.radii.getY()); for (int yBlock = -yRad; yBlock < yRad; yBlock++) @@ -90,7 +90,7 @@ protected void drawXZPlane(LineInfo colour) protected void drawYZPlane(LineInfo colour) { Tessellator tessellator = Tessellator.getInstance(); - VertexBuffer buf = tessellator.getBuffer(); + BufferBuilder buf = tessellator.getBuffer(); int xRad = (int)Math.floor(this.radii.getX()); for (int xBlock = -xRad; xBlock < xRad; xBlock++) @@ -126,7 +126,7 @@ protected void drawYZPlane(LineInfo colour) protected void drawXYPlane(LineInfo colour) { Tessellator tessellator = Tessellator.getInstance(); - VertexBuffer buf = tessellator.getBuffer(); + BufferBuilder buf = tessellator.getBuffer(); int zRad = (int)Math.floor(this.radii.getZ()); for (int zBlock = -zRad; zBlock < zRad; zBlock++) From 2e1e7b236e719445e17c07051ec22c3725610664 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Tue, 25 Jul 2017 18:32:35 +0100 Subject: [PATCH 36/51] Multi-region WIP, updates #16 --- gradle.properties | 4 +- .../worldeditcui/LiteModWorldEditCUI.java | 50 +++++++-- .../mumfrey/worldeditcui/WorldEditCUI.java | 65 +++++++++-- .../worldeditcui/config/CUIConfiguration.java | 52 ++++----- .../mumfrey/worldeditcui/config/Colour.java | 81 +++++++++++--- .../mumfrey/worldeditcui/debug/CUIDebug.java | 24 ++--- .../mumfrey/worldeditcui/event/CUIEvent.java | 31 +++--- .../worldeditcui/event/CUIEventArgs.java | 22 ++-- .../event/CUIEventDispatcher.java | 16 +-- .../worldeditcui/event/CUIEventType.java | 10 +- .../event/cui/CUIEventBounds.java | 19 ++-- .../event/cui/CUIEventColour.java | 67 ++++++++++++ .../event/cui/CUIEventCylinder.java | 19 ++-- .../event/cui/CUIEventEllipsoid.java | 20 ++-- .../worldeditcui/event/cui/CUIEventGrid.java | 50 +++++++++ .../event/cui/CUIEventPoint2D.java | 19 ++-- .../event/cui/CUIEventPoint3D.java | 25 ++++- .../event/cui/CUIEventPolygon.java | 22 ++-- .../event/cui/CUIEventSelection.java | 28 +++-- .../event/cui/CUIEventUpdate.java | 8 +- .../event/listeners/CUIListenerChannel.java | 12 ++- .../listeners/CUIListenerWorldRender.java | 7 +- .../worldeditcui/gui/CUIConfigPanel.java | 13 ++- .../gui/controls/GuiColourButton.java | 10 +- .../gui/controls/GuiColourPicker.java | 4 +- .../worldeditcui/gui/controls/GuiControl.java | 5 +- .../render/CUISelectionProvider.java | 22 ++-- ...{LineColour.java => ConfiguredColour.java} | 39 +++---- .../worldeditcui/render/CustomColour.java | 41 +++++++ .../mumfrey/worldeditcui/render/LineInfo.java | 5 + .../worldeditcui/render/RenderColour.java | 18 ++++ .../worldeditcui/render/points/PointCube.java | 48 +++++++-- .../render/points/PointCubeTracking.java | 54 ++++++++++ .../render/points/PointRectangle.java | 17 +-- .../render/region/CuboidRegion.java | 101 ++++++++++++++---- .../render/region/CylinderRegion.java | 48 ++++++--- .../render/region/EllipsoidRegion.java | 30 ++++-- .../render/region/PolygonRegion.java | 54 +++++++--- .../render/region/PolyhedronRegion.java | 36 +++++-- .../region/{BaseRegion.java => Region.java} | 40 ++++++- .../render/region/RegionType.java | 6 +- .../render/shapes/Render2DBox.java | 17 ++- .../render/shapes/Render2DGrid.java | 25 ++--- .../render/shapes/Render3DBox.java | 48 ++++++--- .../render/shapes/Render3DGrid.java | 96 ++++++++++++++--- .../render/shapes/Render3DPolygon.java | 23 ++-- .../render/shapes/RenderCylinderBox.java | 30 +++--- .../render/shapes/RenderCylinderCircles.java | 23 ++-- .../render/shapes/RenderCylinderGrid.java | 21 ++-- .../render/shapes/RenderEllipsoid.java | 21 ++-- .../render/shapes/RenderRegion.java | 34 ++++++ .../worldeditcui/util/BoundingBox.java | 56 ++++++++-- .../mumfrey/worldeditcui/util/Observable.java | 36 +++++++ .../mumfrey/worldeditcui/util/Observer.java | 11 ++ 54 files changed, 1265 insertions(+), 418 deletions(-) create mode 100644 java/com/mumfrey/worldeditcui/event/cui/CUIEventColour.java create mode 100644 java/com/mumfrey/worldeditcui/event/cui/CUIEventGrid.java rename java/com/mumfrey/worldeditcui/render/{LineColour.java => ConfiguredColour.java} (83%) create mode 100644 java/com/mumfrey/worldeditcui/render/CustomColour.java create mode 100644 java/com/mumfrey/worldeditcui/render/RenderColour.java create mode 100644 java/com/mumfrey/worldeditcui/render/points/PointCubeTracking.java rename java/com/mumfrey/worldeditcui/render/region/{BaseRegion.java => Region.java} (62%) create mode 100644 java/com/mumfrey/worldeditcui/render/shapes/RenderRegion.java create mode 100644 java/com/mumfrey/worldeditcui/util/Observable.java create mode 100644 java/com/mumfrey/worldeditcui/util/Observer.java diff --git a/gradle.properties b/gradle.properties index f50996e6..a33f8906 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ name=WorldEditCUI -version=1.12 +version=1.12_01 mcVersion=1.12 -mcMappings=snapshot_20170609 +mcMappings=snapshot_20170627 targetVersion=1.12.r1 \ No newline at end of file diff --git a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java index 89d960da..f8dc461c 100644 --- a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java @@ -3,7 +3,6 @@ import io.netty.buffer.Unpooled; import java.io.File; -import java.util.Arrays; import java.util.List; import net.minecraft.client.Minecraft; @@ -19,6 +18,8 @@ import org.lwjgl.input.Keyboard; import com.google.common.base.Charsets; +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableList; import com.mojang.realmsclient.dto.RealmsServer; import com.mumfrey.liteloader.Configurable; import com.mumfrey.liteloader.InitCompleteListener; @@ -29,14 +30,20 @@ import com.mumfrey.liteloader.core.ClientPluginChannels; import com.mumfrey.liteloader.core.LiteLoader; import com.mumfrey.liteloader.core.PluginChannels.ChannelPolicy; +import com.mumfrey.liteloader.messaging.Message; +import com.mumfrey.liteloader.messaging.Messenger; import com.mumfrey.liteloader.modconfig.ConfigPanel; import com.mumfrey.worldeditcui.config.CUIConfiguration; import com.mumfrey.worldeditcui.event.listeners.CUIListenerChannel; import com.mumfrey.worldeditcui.event.listeners.CUIListenerWorldRender; import com.mumfrey.worldeditcui.gui.CUIConfigPanel; -import com.mumfrey.worldeditcui.render.region.CuboidRegion; -public class LiteModWorldEditCUI implements Tickable, InitCompleteListener, PluginChannelListener, PostRenderListener, Configurable, JoinGameListener +/** + * Main litemod entry point + * + * @author Adam Mummery-Smith + */ +public class LiteModWorldEditCUI implements Tickable, InitCompleteListener, PluginChannelListener, PostRenderListener, Configurable, JoinGameListener, Messenger { private static final int DELAYED_HELO_TICKS = 10; @@ -101,10 +108,39 @@ private void helo() ClientPluginChannels.sendMessage(CHANNEL_WECUI, buffer, ChannelPolicy.DISPATCH_ALWAYS); } + @Override + public List getMessageChannels() + { + return ImmutableList.of("wecui:wecui"); + } + + @Override + public void receiveMessage(Message message) + { + if (message.isChannel("wecui:wecui")) + { + try + { + Object value = message.getValue(); + if (value instanceof String) + { + this.channelListener.onMessage((String)value); + } + else if (value instanceof List) + { + @SuppressWarnings("unchecked") + List list = (List)value; + this.channelListener.onMessage(Joiner.on('|').join(list)); + } + } + catch (Exception ex) {} + } + } + @Override public List getChannels() { - return Arrays.asList(new String[] { CHANNEL_WECUI }); + return ImmutableList.of(LiteModWorldEditCUI.CHANNEL_WECUI); } @Override @@ -148,7 +184,9 @@ public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clo if (this.keyBindClearSel.isPressed()) { if (mc.player != null) + { mc.player.sendChatMessage("//sel"); + } } } @@ -163,7 +201,7 @@ public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clo this.lastPlayer = mc.player; this.controller.getDebugger().debug("World change detected, sending new handshake"); - this.controller.setSelection(new CuboidRegion(this.controller)); + this.controller.clear(); this.helo(); this.delayedHelo = LiteModWorldEditCUI.DELAYED_HELO_TICKS; if (mc.player != null && config.isPromiscuous()) @@ -196,7 +234,7 @@ public String getName() @Override public String getVersion() { - return "1.12_00"; + return "1.12_01"; } @Override diff --git a/java/com/mumfrey/worldeditcui/WorldEditCUI.java b/java/com/mumfrey/worldeditcui/WorldEditCUI.java index cf5be8fd..5482f1f1 100644 --- a/java/com/mumfrey/worldeditcui/WorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/WorldEditCUI.java @@ -1,12 +1,17 @@ package com.mumfrey.worldeditcui; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.UUID; + import com.mumfrey.worldeditcui.config.CUIConfiguration; import com.mumfrey.worldeditcui.debug.CUIDebug; import com.mumfrey.worldeditcui.event.CUIEventDispatcher; import com.mumfrey.worldeditcui.exceptions.InitialisationException; import com.mumfrey.worldeditcui.render.CUISelectionProvider; -import com.mumfrey.worldeditcui.render.region.BaseRegion; import com.mumfrey.worldeditcui.render.region.CuboidRegion; +import com.mumfrey.worldeditcui.render.region.Region; +import com.mumfrey.worldeditcui.util.Vector3; /** * Main controller class. Uses a pseudo-JavaBeans paradigm. The only real @@ -17,12 +22,14 @@ * TODO: Add ability to flash selection * * @author yetanotherx + * @author Adam Mummery-Smith */ public class WorldEditCUI { - public static final int PROTOCOL_VERSION = 3; + public static final int PROTOCOL_VERSION = 4; - private BaseRegion selection; + private final Map regions = new LinkedHashMap(); + private Region selection, activeRegion; private CUIDebug debugger; private CUIConfiguration configuration; private CUIEventDispatcher dispatcher; @@ -71,13 +78,57 @@ public CUIDebug getDebugger() return this.debugger; } - public BaseRegion getSelection() + public void clear() + { + this.clearSelection(); + this.clearRegions(); + } + + public void clearSelection() + { + this.selection = new CuboidRegion(this); + } + + public void clearRegions() + { + this.activeRegion = null; + this.regions.clear(); + } + + public Region getSelection(boolean multi) { - return this.selection; + return multi ? this.activeRegion : this.selection; } - public void setSelection(BaseRegion selection) + public void setSelection(UUID id, Region region) { - this.selection = selection; + if (id == null) + { + this.selection = region; + return; + } + + if (region == null) + { + this.regions.remove(id); + this.activeRegion = null; + return; + } + + this.regions.put(id, region); + this.activeRegion = region; + } + + public void renderSelections(Vector3 cameraPos) + { + if (this.selection != null) + { + this.selection.render(cameraPos); + } + + for (Region region : this.regions.values()) + { + region.render(cameraPos); + } } } diff --git a/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java b/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java index 583004ec..4f2ee9df 100644 --- a/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java +++ b/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java @@ -9,13 +9,13 @@ import com.google.gson.GsonBuilder; import com.mumfrey.liteloader.core.LiteLoader; import com.mumfrey.worldeditcui.InitialisationFactory; -import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.ConfiguredColour; /** * Stores and reads WorldEditCUI settings * * @author yetanotherx - * + * @author Adam Mummery-Smith */ public class CUIConfiguration implements InitialisationFactory { @@ -48,31 +48,31 @@ public class CUIConfiguration implements InitialisationFactory @Override public void initialise() { - this.cuboidGridColor = Colour.setDefault(this.cuboidGridColor, "#CC3333CC"); - this.cuboidEdgeColor = Colour.setDefault(this.cuboidEdgeColor, "#CC4C4CCC"); - this.cuboidFirstPointColor = Colour.setDefault(this.cuboidFirstPointColor, "#33CC33CC"); - this.cuboidSecondPointColor = Colour.setDefault(this.cuboidSecondPointColor, "#3333CCCC"); - this.polyGridColor = Colour.setDefault(this.polyGridColor, "#CC3333CC"); - this.polyEdgeColor = Colour.setDefault(this.polyEdgeColor, "#CC4C4CCC"); - this.polyPointColor = Colour.setDefault(this.polyPointColor, "#33CCCCCC"); - this.ellipsoidGridColor = Colour.setDefault(this.ellipsoidGridColor, "#CC4C4CCC"); - this.ellipsoidPointColor = Colour.setDefault(this.ellipsoidPointColor, "#CCCC33CC"); - this.cylinderGridColor = Colour.setDefault(this.cylinderGridColor, "#CC3333CC"); - this.cylinderEdgeColor = Colour.setDefault(this.cylinderEdgeColor, "#CC4C4CCC"); - this.cylinderPointColor = Colour.setDefault(this.cylinderPointColor, "#CC33CCCC"); + this.cuboidGridColor = Colour.firstOrDefault(this.cuboidGridColor, "#CC3333CC"); + this.cuboidEdgeColor = Colour.firstOrDefault(this.cuboidEdgeColor, "#CC4C4CCC"); + this.cuboidFirstPointColor = Colour.firstOrDefault(this.cuboidFirstPointColor, "#33CC33CC"); + this.cuboidSecondPointColor = Colour.firstOrDefault(this.cuboidSecondPointColor, "#3333CCCC"); + this.polyGridColor = Colour.firstOrDefault(this.polyGridColor, "#CC3333CC"); + this.polyEdgeColor = Colour.firstOrDefault(this.polyEdgeColor, "#CC4C4CCC"); + this.polyPointColor = Colour.firstOrDefault(this.polyPointColor, "#33CCCCCC"); + this.ellipsoidGridColor = Colour.firstOrDefault(this.ellipsoidGridColor, "#CC4C4CCC"); + this.ellipsoidPointColor = Colour.firstOrDefault(this.ellipsoidPointColor, "#CCCC33CC"); + this.cylinderGridColor = Colour.firstOrDefault(this.cylinderGridColor, "#CC3333CC"); + this.cylinderEdgeColor = Colour.firstOrDefault(this.cylinderEdgeColor, "#CC4C4CCC"); + this.cylinderPointColor = Colour.firstOrDefault(this.cylinderPointColor, "#CC33CCCC"); - LineColour.CUBOIDBOX.setColour(this.cuboidEdgeColor); - LineColour.CUBOIDGRID.setColour(this.cuboidGridColor); - LineColour.CUBOIDPOINT1.setColour(this.cuboidFirstPointColor); - LineColour.CUBOIDPOINT2.setColour(this.cuboidSecondPointColor); - LineColour.POLYGRID.setColour(this.polyGridColor); - LineColour.POLYBOX.setColour(this.polyEdgeColor); - LineColour.POLYPOINT.setColour(this.polyPointColor); - LineColour.ELLIPSOIDGRID.setColour(this.ellipsoidGridColor); - LineColour.ELLIPSOIDCENTRE.setColour(this.ellipsoidPointColor); - LineColour.CYLINDERGRID.setColour(this.cylinderGridColor); - LineColour.CYLINDERBOX.setColour(this.cylinderEdgeColor); - LineColour.CYLINDERCENTRE.setColour(this.cylinderPointColor); + ConfiguredColour.CUBOIDBOX.setColour(this.cuboidEdgeColor); + ConfiguredColour.CUBOIDGRID.setColour(this.cuboidGridColor); + ConfiguredColour.CUBOIDPOINT1.setColour(this.cuboidFirstPointColor); + ConfiguredColour.CUBOIDPOINT2.setColour(this.cuboidSecondPointColor); + ConfiguredColour.POLYGRID.setColour(this.polyGridColor); + ConfiguredColour.POLYBOX.setColour(this.polyEdgeColor); + ConfiguredColour.POLYPOINT.setColour(this.polyPointColor); + ConfiguredColour.ELLIPSOIDGRID.setColour(this.ellipsoidGridColor); + ConfiguredColour.ELLIPSOIDCENTRE.setColour(this.ellipsoidPointColor); + ConfiguredColour.CYLINDERGRID.setColour(this.cylinderGridColor); + ConfiguredColour.CYLINDERBOX.setColour(this.cylinderEdgeColor); + ConfiguredColour.CYLINDERCENTRE.setColour(this.cylinderPointColor); this.save(); } diff --git a/java/com/mumfrey/worldeditcui/config/Colour.java b/java/com/mumfrey/worldeditcui/config/Colour.java index 7bbab516..a5008bcf 100644 --- a/java/com/mumfrey/worldeditcui/config/Colour.java +++ b/java/com/mumfrey/worldeditcui/config/Colour.java @@ -1,21 +1,32 @@ package com.mumfrey.worldeditcui.config; +/** + * @author Adam Mummery-Smith + */ public class Colour { private String hex; + private int argb; + private float a, r, g, b; private transient String defaultColour; + private transient boolean woken; - public Colour(String defaultColour) + public Colour(String colour) { - this.hex = defaultColour; - this.defaultColour = defaultColour; + this.hex = this.defaultColour = colour; + this.update(); } public Colour() { } - public static Colour setDefault(Colour colour, String defaultColour) + public static Colour parse(String colour, Colour defaultColour) + { + return ((colour = Colour.sanitiseColour(colour, null)) == null) ? defaultColour : new Colour(colour); + } + + public static Colour firstOrDefault(Colour colour, String defaultColour) { if (colour == null) { @@ -29,7 +40,7 @@ public static Colour setDefault(Colour colour, String defaultColour) } else { - colour.hex = Colour.parseColour(colour.hex, defaultColour); + colour.hex = Colour.sanitiseColour(colour.hex, defaultColour); } return colour; @@ -43,7 +54,7 @@ public static Colour setDefault(Colour colour, String defaultColour) * @param def * @return */ - private static String parseColour(String colour, String def) + private static String sanitiseColour(String colour, String def) { if (colour == null) { @@ -64,47 +75,85 @@ else if (colour.length() != 7 && colour.length() != 9) public void setHex(String hex) { if (hex.length() < 8) + { hex = "00000000".substring(0, 8 - hex.length()) + hex; + } + this.hex = "#" + hex; + this.update(); } public String getHex() { if (this.hex == null) + { this.hex = this.defaultColour; + this.update(); + } + if (this.hex.length() == 7) + { this.hex = this.hex + "CC"; + this.update(); + } + return this.hex; } - public int getIntARGB() + private void update() { String hex = this.getHex(); - return (int)Long.parseLong(hex.substring(7, 9) + hex.substring(1, 7), 16); + this.argb = (int)Long.parseLong(hex.substring(7, 9) + hex.substring(1, 7), 16); + this.r = ((Integer.parseInt(hex.substring(1, 3), 16)) / 256.0F); + this.g = ((Integer.parseInt(hex.substring(3, 5), 16)) / 256.0F); + this.b = ((Integer.parseInt(hex.substring(5, 7), 16)) / 256.0F); + this.a = ((Integer.parseInt(hex.substring(7, 9), 16)) / 256.0F); + this.woken = true; + } + + public int getIntARGB() + { + return this.argb; } public float red() { - String hex = this.getHex(); - return (((Integer)Integer.parseInt(hex.substring(1, 3), 16)).floatValue() / 256.0F); + if (!this.woken) + { + this.update(); + } + + return this.r; } public float green() { - String hex = this.getHex(); - return (((Integer)Integer.parseInt(hex.substring(3, 5), 16)).floatValue() / 256.0F); + if (!this.woken) + { + this.update(); + } + + return this.g; } public float blue() { - String hex = this.getHex(); - return (((Integer)Integer.parseInt(hex.substring(5, 7), 16)).floatValue() / 256.0F); + if (!this.woken) + { + this.update(); + } + + return this.b; } public float alpha() { - String hex = this.getHex(); - return (((Integer)Integer.parseInt(hex.substring(7, 9), 16)).floatValue() / 256.0F); + if (!this.woken) + { + this.update(); + } + + return this.a; } public Colour copyFrom(Colour other) diff --git a/java/com/mumfrey/worldeditcui/debug/CUIDebug.java b/java/com/mumfrey/worldeditcui/debug/CUIDebug.java index 27a3e5c6..b690c7a8 100644 --- a/java/com/mumfrey/worldeditcui/debug/CUIDebug.java +++ b/java/com/mumfrey/worldeditcui/debug/CUIDebug.java @@ -17,15 +17,15 @@ * Debugging helper class * * @author yetanotherx - * + * @author Adam Mummery-Smith */ -public class CUIDebug implements InitialisationFactory +public final class CUIDebug implements InitialisationFactory { + private static final Logger logger = Logger.getLogger("WorldEditCUI"); - protected WorldEditCUI controller; - protected File debugFile; - protected boolean debugMode = false; - protected final static Logger logger = Logger.getLogger("WorldEditCUI"); + private final WorldEditCUI controller; + private File debugFile; + private boolean debugMode = false; public CUIDebug(WorldEditCUI controller) { @@ -40,8 +40,8 @@ public void initialise() throws InitialisationException ConsoleHandler handler = new ConsoleHandler(); handler.setFormatter(formatter); - logger.setUseParentHandlers(false); - logger.addHandler(handler); + CUIDebug.logger.setUseParentHandlers(false); + CUIDebug.logger.addHandler(handler); try { @@ -52,7 +52,7 @@ public void initialise() throws InitialisationException { FileHandler newHandler = new FileHandler(this.debugFile.getAbsolutePath()); newHandler.setFormatter(formatter); - logger.addHandler(newHandler); + CUIDebug.logger.addHandler(newHandler); } } @@ -72,17 +72,17 @@ public void debug(String message) { if (this.debugMode) { - logger.info("WorldEditCUI Debug - " + message); + CUIDebug.logger.info("WorldEditCUI Debug - " + message); } } public void info(String message) { - logger.info(message); + CUIDebug.logger.info(message); } public void info(String message, Throwable e) { - logger.log(Level.INFO, message, e); + CUIDebug.logger.log(Level.INFO, message, e); } } diff --git a/java/com/mumfrey/worldeditcui/event/CUIEvent.java b/java/com/mumfrey/worldeditcui/event/CUIEvent.java index 7f42a38f..e7412605 100644 --- a/java/com/mumfrey/worldeditcui/event/CUIEvent.java +++ b/java/com/mumfrey/worldeditcui/event/CUIEvent.java @@ -7,18 +7,19 @@ * Base event for CUI events, handles parameter validation and running the logic * * @author yetanotherx - * + * @author Adam Mummery-Smith */ public abstract class CUIEvent { + protected final WorldEditCUI controller; + protected final String[] params; + protected final boolean multi; - protected WorldEditCUI controller; - protected String[] args; - - public CUIEvent(WorldEditCUI controller, String[] args) + public CUIEvent(CUIEventArgs args) { - this.controller = controller; - this.args = args; + this.controller = args.getController(); + this.params = args.getParams(); + this.multi = args.isMulti(); } public abstract String raise(); @@ -41,14 +42,14 @@ public boolean isValid() if (max == min) { - if (this.args.length != max) + if (this.params.length != max) { return false; } } else { - if (this.args.length > max || this.args.length < min) + if (this.params.length > max || this.params.length < min) { return false; } @@ -58,16 +59,16 @@ public boolean isValid() } - public final void prepare() + public void prepare() { - if (this.controller == null || this.args == null) + if (this.controller == null || this.params == null) { throw new IllegalStateException("Controller and parameters must both be set."); } if (!this.isValid()) { - String message = String.format("Invalid number of parameters. %s event requires %s parameters but received %s [%s]", this.getEventName(), this.getRequiredParameterString(), this.args.length, Joiner.on(", ").join(this.args)); + String message = String.format("Invalid number of parameters. %s event requires %s parameters but received %s [%s]", this.getEventName(), this.getRequiredParameterString(), this.params.length, Joiner.on(", ").join(this.params)); throw new IllegalArgumentException(message); } } @@ -84,16 +85,16 @@ private String getRequiredParameterString() public int getInt(int index) { - return (int)Float.parseFloat(this.args[index]); + return (int)Float.parseFloat(this.params[index]); } public double getDouble(int index) { - return Double.parseDouble(this.args[index]); + return Double.parseDouble(this.params[index]); } public String getString(int index) { - return this.args[index]; + return this.params[index]; } } diff --git a/java/com/mumfrey/worldeditcui/event/CUIEventArgs.java b/java/com/mumfrey/worldeditcui/event/CUIEventArgs.java index 7d146b2e..631cc25a 100644 --- a/java/com/mumfrey/worldeditcui/event/CUIEventArgs.java +++ b/java/com/mumfrey/worldeditcui/event/CUIEventArgs.java @@ -9,17 +9,19 @@ * * @author lahwran * @author yetanotherx - * + * @author Adam Mummery-Smith */ -public class CUIEventArgs +public final class CUIEventArgs { private WorldEditCUI controller; + private boolean multi; private String type; private String[] params; - public CUIEventArgs(WorldEditCUI controller, String type, String[] params) + public CUIEventArgs(WorldEditCUI controller, boolean multi, String type, String[] params) { this.controller = controller; + this.multi = multi; this.type = type; if (params.length == 1 && params[0].length() == 0) @@ -31,14 +33,9 @@ public CUIEventArgs(WorldEditCUI controller, String type, String[] params) this.controller.getDebugger().debug("CUI Event (" + type + ") - Params: " + Joiner.on(", ").join(params)); } - public int getInt(int index) + public WorldEditCUI getController() { - return (int)Float.parseFloat(this.params[index]); - } - - public String getString(int index) - { - return this.params[index]; + return this.controller; } public String[] getParams() @@ -50,4 +47,9 @@ public String getType() { return this.type; } + + public boolean isMulti() + { + return this.multi; + } } diff --git a/java/com/mumfrey/worldeditcui/event/CUIEventDispatcher.java b/java/com/mumfrey/worldeditcui/event/CUIEventDispatcher.java index 461de8d8..f26b6929 100644 --- a/java/com/mumfrey/worldeditcui/event/CUIEventDispatcher.java +++ b/java/com/mumfrey/worldeditcui/event/CUIEventDispatcher.java @@ -9,7 +9,6 @@ import com.mumfrey.worldeditcui.exceptions.InitialisationException; /** - * * @author Adam Mummery-Smith */ public class CUIEventDispatcher implements InitialisationFactory @@ -31,12 +30,13 @@ public void initialise() throws InitialisationException try { Class eventClass = eventType.getEventClass(); - Constructor ctor = eventClass.getDeclaredConstructor(WorldEditCUI.class, String[].class); + Constructor ctor = eventClass.getDeclaredConstructor(CUIEventArgs.class); this.eventConstructors.put(eventType.getKey(), ctor); } catch (NoSuchMethodException ex) { + ex.printStackTrace(); this.controller.getDebugger().debug("Error getting constructor for event " + eventType.getKey()); } } @@ -47,7 +47,13 @@ public void raiseEvent(CUIEventArgs eventArgs) try { Constructor eventCtor = this.eventConstructors.get(eventArgs.getType()); - CUIEvent event = eventCtor.newInstance(this.controller, eventArgs.getParams()); + if (eventCtor == null) + { + this.controller.getDebugger().debug("No such event " + eventArgs.getType()); + return; + } + + CUIEvent event = eventCtor.newInstance(eventArgs); event.prepare(); String response = event.raise(); @@ -56,10 +62,6 @@ public void raiseEvent(CUIEventArgs eventArgs) this.handleEventResponse(response); } } - catch (NullPointerException ex) - { - this.controller.getDebugger().debug("No such event " + eventArgs.getType()); - } catch (Exception ex) { ex.printStackTrace(); diff --git a/java/com/mumfrey/worldeditcui/event/CUIEventType.java b/java/com/mumfrey/worldeditcui/event/CUIEventType.java index b3116102..c70ba398 100644 --- a/java/com/mumfrey/worldeditcui/event/CUIEventType.java +++ b/java/com/mumfrey/worldeditcui/event/CUIEventType.java @@ -1,8 +1,10 @@ package com.mumfrey.worldeditcui.event; import com.mumfrey.worldeditcui.event.cui.CUIEventBounds; +import com.mumfrey.worldeditcui.event.cui.CUIEventColour; import com.mumfrey.worldeditcui.event.cui.CUIEventCylinder; import com.mumfrey.worldeditcui.event.cui.CUIEventEllipsoid; +import com.mumfrey.worldeditcui.event.cui.CUIEventGrid; import com.mumfrey.worldeditcui.event.cui.CUIEventPoint2D; import com.mumfrey.worldeditcui.event.cui.CUIEventPoint3D; import com.mumfrey.worldeditcui.event.cui.CUIEventPolygon; @@ -13,18 +15,20 @@ * Event type enum for CUI events. Also stores class, arguments, and key for each value. * * @author yetanotherx - * + * @author Adam Mummery-Smith */ public enum CUIEventType { - SELECTION(CUIEventSelection.class, "s", 1 ), + SELECTION(CUIEventSelection.class, "s", 1, 2 ), POINT (CUIEventPoint3D.class, "p", 5, 6 ), POINT2D (CUIEventPoint2D.class, "p2", 4, 5 ), ELLIPSOID(CUIEventEllipsoid.class, "e", 4 ), CYLINDER (CUIEventCylinder.class, "cyl", 5 ), MINMAX (CUIEventBounds.class, "mm", 2 ), UPDATE (CUIEventUpdate.class, "u", 1 ), - POLYGON (CUIEventPolygon.class, "poly", 3, 99); + POLYGON (CUIEventPolygon.class, "poly", 3, 99), + COLOUR (CUIEventColour.class, "col", 4 ), + GRID (CUIEventGrid.class, "grid", 1 ); private final Class eventClass; private final String key; diff --git a/java/com/mumfrey/worldeditcui/event/cui/CUIEventBounds.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventBounds.java index 25057982..06def89d 100644 --- a/java/com/mumfrey/worldeditcui/event/cui/CUIEventBounds.java +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventBounds.java @@ -1,21 +1,22 @@ package com.mumfrey.worldeditcui.event.cui; -import com.mumfrey.worldeditcui.WorldEditCUI; import com.mumfrey.worldeditcui.event.CUIEvent; +import com.mumfrey.worldeditcui.event.CUIEventArgs; import com.mumfrey.worldeditcui.event.CUIEventType; +import com.mumfrey.worldeditcui.render.region.Region; /** * Called when resize event is received * * @author lahwran * @author yetanotherx + * @author Adam Mummery-Smith */ public class CUIEventBounds extends CUIEvent { - - public CUIEventBounds(WorldEditCUI controller, String[] args) + public CUIEventBounds(CUIEventArgs args) { - super(controller, args); + super(args); } @Override @@ -27,10 +28,16 @@ public CUIEventType getEventType() @Override public String raise() { + Region selection = this.controller.getSelection(this.multi); + if (selection == null) + { + this.controller.getDebugger().debug("No active multi selection."); + return null; + } + int min = this.getInt(0); int max = this.getInt(1); - this.controller.getSelection().setMinMax(min, max); - + selection.setMinMax(min, max); this.controller.getDebugger().debug("Expanding/contracting selection."); return null; diff --git a/java/com/mumfrey/worldeditcui/event/cui/CUIEventColour.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventColour.java new file mode 100644 index 00000000..e06fb58d --- /dev/null +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventColour.java @@ -0,0 +1,67 @@ +package com.mumfrey.worldeditcui.event.cui; + +import com.mumfrey.worldeditcui.config.Colour; +import com.mumfrey.worldeditcui.event.CUIEvent; +import com.mumfrey.worldeditcui.event.CUIEventArgs; +import com.mumfrey.worldeditcui.event.CUIEventType; +import com.mumfrey.worldeditcui.render.CustomColour; +import com.mumfrey.worldeditcui.render.RenderColour; +import com.mumfrey.worldeditcui.render.region.Region; + +/** + * Called when colour event is received + * + * @author Adam Mummery-Smith + */ +public class CUIEventColour extends CUIEvent +{ + public CUIEventColour(CUIEventArgs args) + { + super(args); + } + + @Override + public CUIEventType getEventType() + { + return CUIEventType.COLOUR; + } + + @Override + public void prepare() + { + if (!this.multi) + { + throw new IllegalStateException("COLOUR event is not valid for non-multi selections"); + } + + super.prepare(); + } + + @Override + public String raise() + { + Region selection = this.controller.getSelection(true); + if (selection == null) + { + this.controller.getDebugger().debug("No active multi selection."); + return null; + } + + RenderColour[] defaultColours = selection.getDefaultColours(); + RenderColour[] colours = new RenderColour[defaultColours.length]; + + for (int i = 0; i < defaultColours.length; i++) + { + String str = this.getString(i); + if (!str.startsWith("#")) + { + str = "#" + str; + } + colours[i] = new CustomColour(Colour.parse(str, defaultColours[i].getColour())); + + } + + selection.setColours(colours); + return null; + } +} diff --git a/java/com/mumfrey/worldeditcui/event/cui/CUIEventCylinder.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventCylinder.java index 2c20ba68..008d9876 100644 --- a/java/com/mumfrey/worldeditcui/event/cui/CUIEventCylinder.java +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventCylinder.java @@ -1,21 +1,22 @@ package com.mumfrey.worldeditcui.event.cui; -import com.mumfrey.worldeditcui.WorldEditCUI; import com.mumfrey.worldeditcui.event.CUIEvent; +import com.mumfrey.worldeditcui.event.CUIEventArgs; import com.mumfrey.worldeditcui.event.CUIEventType; +import com.mumfrey.worldeditcui.render.region.Region; /** * Called when cylinder event is received * * @author lahwran * @author yetanotherx + * @author Adam Mummery-Smith */ public class CUIEventCylinder extends CUIEvent { - - public CUIEventCylinder(WorldEditCUI controller, String[] args) + public CUIEventCylinder(CUIEventArgs args) { - super(controller, args); + super(args); } @Override @@ -27,6 +28,12 @@ public CUIEventType getEventType() @Override public String raise() { + Region selection = this.controller.getSelection(this.multi); + if (selection == null) + { + this.controller.getDebugger().debug("No active multi selection."); + return null; + } int x = this.getInt(0); int y = this.getInt(1); @@ -34,8 +41,8 @@ public String raise() double radX = this.getDouble(3); double radZ = this.getDouble(4); - this.controller.getSelection().setCylinderCenter(x, y, z); - this.controller.getSelection().setCylinderRadius(radX, radZ); + selection.setCylinderCenter(x, y, z); + selection.setCylinderRadius(radX, radZ); this.controller.getDebugger().debug("Setting centre/radius"); diff --git a/java/com/mumfrey/worldeditcui/event/cui/CUIEventEllipsoid.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventEllipsoid.java index a1bbdc4f..e07d2824 100644 --- a/java/com/mumfrey/worldeditcui/event/cui/CUIEventEllipsoid.java +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventEllipsoid.java @@ -1,21 +1,22 @@ package com.mumfrey.worldeditcui.event.cui; -import com.mumfrey.worldeditcui.WorldEditCUI; import com.mumfrey.worldeditcui.event.CUIEvent; +import com.mumfrey.worldeditcui.event.CUIEventArgs; import com.mumfrey.worldeditcui.event.CUIEventType; +import com.mumfrey.worldeditcui.render.region.Region; /** * Called when ellipsoid event is received * * @author lahwran * @author yetanotherx + * @author Adam Mummery-Smith */ public class CUIEventEllipsoid extends CUIEvent { - - public CUIEventEllipsoid(WorldEditCUI controller, String[] args) + public CUIEventEllipsoid(CUIEventArgs args) { - super(controller, args); + super(args); } @Override @@ -27,6 +28,13 @@ public CUIEventType getEventType() @Override public String raise() { + Region selection = this.controller.getSelection(this.multi); + if (selection == null) + { + this.controller.getDebugger().debug("No active multi selection."); + return null; + } + int id = this.getInt(0); @@ -35,14 +43,14 @@ public String raise() int x = this.getInt(1); int y = this.getInt(2); int z = this.getInt(3); - this.controller.getSelection().setEllipsoidCenter(x, y, z); + selection.setEllipsoidCenter(x, y, z); } else if (id == 1) { double x = this.getDouble(1); double y = this.getDouble(2); double z = this.getDouble(3); - this.controller.getSelection().setEllipsoidRadii(x, y, z); + selection.setEllipsoidRadii(x, y, z); } this.controller.getDebugger().debug("Setting centre/radius"); diff --git a/java/com/mumfrey/worldeditcui/event/cui/CUIEventGrid.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventGrid.java new file mode 100644 index 00000000..40e0a6c0 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventGrid.java @@ -0,0 +1,50 @@ +package com.mumfrey.worldeditcui.event.cui; + +import com.mumfrey.worldeditcui.event.CUIEvent; +import com.mumfrey.worldeditcui.event.CUIEventArgs; +import com.mumfrey.worldeditcui.event.CUIEventType; +import com.mumfrey.worldeditcui.render.region.Region; + +/** + * Called when grid spacing event is received + * + * @author Adam Mummery-Smith + */ +public class CUIEventGrid extends CUIEvent +{ + public CUIEventGrid(CUIEventArgs args) + { + super(args); + } + + @Override + public CUIEventType getEventType() + { + return CUIEventType.GRID; + } + + @Override + public void prepare() + { + if (!this.multi) + { + throw new IllegalStateException("GRID event is not valid for non-multi selections"); + } + + super.prepare(); + } + + @Override + public String raise() + { + Region selection = this.controller.getSelection(true); + if (selection == null) + { + this.controller.getDebugger().debug("No active multi selection."); + return null; + } + + selection.setGridSpacing(this.getDouble(0)); + return null; + } +} diff --git a/java/com/mumfrey/worldeditcui/event/cui/CUIEventPoint2D.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventPoint2D.java index e6ed57d6..39a39ff0 100644 --- a/java/com/mumfrey/worldeditcui/event/cui/CUIEventPoint2D.java +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventPoint2D.java @@ -1,20 +1,21 @@ package com.mumfrey.worldeditcui.event.cui; -import com.mumfrey.worldeditcui.WorldEditCUI; +import com.mumfrey.worldeditcui.event.CUIEventArgs; import com.mumfrey.worldeditcui.event.CUIEventType; +import com.mumfrey.worldeditcui.render.region.Region; /** * Called when poly point event is received * * @author lahwran * @author yetanotherx + * @author Adam Mummery-Smith */ public class CUIEventPoint2D extends CUIEventPoint3D { - - public CUIEventPoint2D(WorldEditCUI controller, String[] args) + public CUIEventPoint2D(CUIEventArgs args) { - super(controller, args); + super(args); } @Override @@ -26,13 +27,19 @@ public CUIEventType getEventType() @Override public String raise() { - + Region selection = this.controller.getSelection(this.multi); + if (selection == null) + { + this.controller.getDebugger().debug("No active multi selection."); + return null; + } + int id = this.getInt(0); int x = this.getInt(1); int z = this.getInt(2); @SuppressWarnings("unused") int regionSize = this.getInt(3); - this.controller.getSelection().setPolygonPoint(id, x, z); + selection.setPolygonPoint(id, x, z); this.controller.getDebugger().debug("Setting point2d #" + id); diff --git a/java/com/mumfrey/worldeditcui/event/cui/CUIEventPoint3D.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventPoint3D.java index 7b12ae6c..e9c776cb 100644 --- a/java/com/mumfrey/worldeditcui/event/cui/CUIEventPoint3D.java +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventPoint3D.java @@ -1,20 +1,22 @@ package com.mumfrey.worldeditcui.event.cui; -import com.mumfrey.worldeditcui.WorldEditCUI; import com.mumfrey.worldeditcui.event.CUIEvent; +import com.mumfrey.worldeditcui.event.CUIEventArgs; import com.mumfrey.worldeditcui.event.CUIEventType; +import com.mumfrey.worldeditcui.render.region.Region; /** * Called when point event is received * * @author lahwran * @author yetanotherx + * @author Adam Mummery-Smith */ public class CUIEventPoint3D extends CUIEvent { - public CUIEventPoint3D(WorldEditCUI controller, String[] args) + public CUIEventPoint3D(CUIEventArgs args) { - super(controller, args); + super(args); } @Override @@ -26,12 +28,27 @@ public CUIEventType getEventType() @Override public String raise() { + Region selection = this.controller.getSelection(this.multi); + if (selection == null) + { + this.controller.getDebugger().debug("No active multi selection."); + return null; + } + int id = this.getInt(0); + + if (this.multi && "~".equals(this.getString(1)) && "~".equals(this.getString(2)) && "~".equals(this.getString(3))) + { + selection.setCuboidVertexLatch(id); + this.controller.getDebugger().debug("Setting vertex latch #" + id); + return null; + } + double x = this.getDouble(1); double y = this.getDouble(2); double z = this.getDouble(3); - this.controller.getSelection().setCuboidPoint(id, x, y, z); + selection.setCuboidPoint(id, x, y, z); this.controller.getDebugger().debug("Setting point #" + id); return null; diff --git a/java/com/mumfrey/worldeditcui/event/cui/CUIEventPolygon.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventPolygon.java index 114d5020..6ca7d863 100644 --- a/java/com/mumfrey/worldeditcui/event/cui/CUIEventPolygon.java +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventPolygon.java @@ -1,21 +1,22 @@ package com.mumfrey.worldeditcui.event.cui; -import com.mumfrey.worldeditcui.WorldEditCUI; import com.mumfrey.worldeditcui.event.CUIEvent; +import com.mumfrey.worldeditcui.event.CUIEventArgs; import com.mumfrey.worldeditcui.event.CUIEventType; +import com.mumfrey.worldeditcui.render.region.Region; /** * Called when polygon event is received * * @author lahwran * @author yetanotherx + * @author Adam Mummery-Smith */ public class CUIEventPolygon extends CUIEvent { - - public CUIEventPolygon(WorldEditCUI controller, String[] args) + public CUIEventPolygon(CUIEventArgs args) { - super(controller, args); + super(args); } @Override @@ -27,13 +28,20 @@ public CUIEventType getEventType() @Override public String raise() { - final int[] vertexIds = new int[this.args.length]; - for (int i = 0; i < this.args.length; ++i) + Region selection = this.controller.getSelection(this.multi); + if (selection == null) + { + this.controller.getDebugger().debug("No active multi selection."); + return null; + } + + final int[] vertexIds = new int[this.params.length]; + for (int i = 0; i < this.params.length; ++i) { vertexIds[i] = this.getInt(i); } - this.controller.getSelection().addPolygon(vertexIds); + selection.addPolygon(vertexIds); //this.controller.getDebugger().debug("Setting point #" + id); return null; diff --git a/java/com/mumfrey/worldeditcui/event/cui/CUIEventSelection.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventSelection.java index 0e3546ff..56291398 100644 --- a/java/com/mumfrey/worldeditcui/event/cui/CUIEventSelection.java +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventSelection.java @@ -1,21 +1,24 @@ package com.mumfrey.worldeditcui.event.cui; -import com.mumfrey.worldeditcui.WorldEditCUI; +import java.util.UUID; + import com.mumfrey.worldeditcui.event.CUIEvent; +import com.mumfrey.worldeditcui.event.CUIEventArgs; import com.mumfrey.worldeditcui.event.CUIEventType; -import com.mumfrey.worldeditcui.render.region.BaseRegion; +import com.mumfrey.worldeditcui.render.region.Region; /** * Called when selection event is received * * @author lahwran * @author yetanotherx + * @author Adam Mummery-Smith */ public class CUIEventSelection extends CUIEvent { - public CUIEventSelection(WorldEditCUI controller, String[] args) + public CUIEventSelection(CUIEventArgs args) { - super(controller, args); + super(args); } @Override @@ -28,14 +31,27 @@ public CUIEventType getEventType() public String raise() { String key = this.getString(0); - BaseRegion selection = this.controller.getSelectionProvider().createSelection(key); + Region selection = this.controller.getSelectionProvider().createSelection(key); if (selection != null) { selection.initialise(); } - this.controller.setSelection(selection); + UUID id = null; + if (this.multi) + { + if (selection == null && this.params.length < 2) + { + this.controller.getDebugger().debug("Received clear selection event."); + this.controller.clearRegions(); + return null; + } + + id = UUID.fromString(this.getString(1)); + } + + this.controller.setSelection(id, selection); this.controller.getDebugger().debug("Received selection event, initalizing new region instance."); return null; diff --git a/java/com/mumfrey/worldeditcui/event/cui/CUIEventUpdate.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventUpdate.java index c6384d42..d37665e5 100644 --- a/java/com/mumfrey/worldeditcui/event/cui/CUIEventUpdate.java +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventUpdate.java @@ -1,7 +1,7 @@ package com.mumfrey.worldeditcui.event.cui; -import com.mumfrey.worldeditcui.WorldEditCUI; import com.mumfrey.worldeditcui.event.CUIEvent; +import com.mumfrey.worldeditcui.event.CUIEventArgs; import com.mumfrey.worldeditcui.event.CUIEventType; /** @@ -9,13 +9,13 @@ * * @author lahwran * @author yetanotherx + * @author Adam Mummery-Smith */ public class CUIEventUpdate extends CUIEvent { - - public CUIEventUpdate(WorldEditCUI controller, String[] args) + public CUIEventUpdate(CUIEventArgs args) { - super(controller, args); + super(args); } @Override diff --git a/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerChannel.java b/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerChannel.java index 15d2f5d6..ab926709 100644 --- a/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerChannel.java +++ b/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerChannel.java @@ -8,7 +8,7 @@ * * @author lahwran * @author yetanotherx - * + * @author Adam Mummery-Smith */ public class CUIListenerChannel { @@ -21,19 +21,21 @@ public CUIListenerChannel(WorldEditCUI controller) public void onMessage(String message) { - String[] split = message.split("[|]"); - String type = split[0]; - String args = message.substring(type.length() + 1); + String[] split = message.split("\\|", -1); + boolean multi = split[0].startsWith("+"); + String type = split[0].substring(multi ? 1 : 0); + String args = message.substring(type.length() + (multi ? 2 : 1)); this.controller.getDebugger().debug("Received CUI event from server: " + message); try { - CUIEventArgs eventArgs = new CUIEventArgs(this.controller, type, args.split("[|]")); + CUIEventArgs eventArgs = new CUIEventArgs(this.controller, multi, type, args.split("\\|", -1)); this.controller.getDispatcher().raiseEvent(eventArgs); } catch (Exception ex) { +// ex.printStackTrace(); } } } diff --git a/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerWorldRender.java b/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerWorldRender.java index 15c6a222..d984e267 100644 --- a/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerWorldRender.java +++ b/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerWorldRender.java @@ -12,7 +12,7 @@ * * @author lahwran * @author yetanotherx - * + * @author Adam Mummery-Smith */ public class CUIListenerWorldRender { @@ -46,10 +46,7 @@ public void onRender(float partialTicks) { Vector3 cameraPos = new Vector3(this.minecraft.getRenderViewEntity(), partialTicks); glColor4f(1.0F, 1.0F, 1.0F, 0.5F); - if (this.controller.getSelection() != null) - { - this.controller.getSelection().render(cameraPos); - } + this.controller.renderSelections(cameraPos); } catch (Exception e) { diff --git a/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java b/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java index 0868dcde..e1d71e84 100644 --- a/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java +++ b/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java @@ -18,8 +18,11 @@ import com.mumfrey.worldeditcui.config.CUIConfiguration; import com.mumfrey.worldeditcui.gui.controls.GuiColourButton; import com.mumfrey.worldeditcui.gui.controls.GuiControl; -import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.ConfiguredColour; +/** + * @author Adam Mummery-Smith + */ public class CUIConfigPanel extends Gui implements ConfigPanel { private static final int CONTROL_SPACING = 24; @@ -51,7 +54,7 @@ public String getPanelTitle() @Override public int getContentHeight() { - return LineColour.values().length * CUIConfigPanel.CONTROL_SPACING + CUIConfigPanel.CONTROL_TOP; + return ConfiguredColour.values().length * CUIConfigPanel.CONTROL_SPACING + CUIConfigPanel.CONTROL_TOP; } @Override @@ -66,7 +69,7 @@ public void onPanelShown(ConfigPanelHost host) int nextId = 0; int top = CUIConfigPanel.CONTROL_TOP; - for (LineColour colour : LineColour.values()) + for (ConfiguredColour colour : ConfiguredColour.values()) { this.controlList.add(new GuiColourButton(this.mc, nextId, 24, top + nextId * CUIConfigPanel.CONTROL_SPACING, 40, 20, colour)); this.controlList.add(new GuiControl(this.mc, 100 + nextId, 234, top + nextId * CUIConfigPanel.CONTROL_SPACING, 60, 20, "Reset")); @@ -119,7 +122,7 @@ public void drawPanel(ConfigPanelHost host, int mouseX, int mouseY, float partia for (GuiButton control : this.controlList) { - control.func_191745_a(this.mc, mouseX, mouseY, partialTicks); // drawButton + control.drawButton(this.mc, mouseX, mouseY, partialTicks); } for (GuiColourButton colourButton : this.colourButtonList) @@ -157,7 +160,7 @@ private void actionPerformed(GuiButton control) if (control.id >= 100) { - LineColour lineColour = LineColour.values()[control.id - 100]; + ConfiguredColour lineColour = ConfiguredColour.values()[control.id - 100]; lineColour.setDefaultColour(); for (GuiColourButton colourButton : this.colourButtonList) diff --git a/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java index a7df2720..c6b67770 100644 --- a/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java +++ b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java @@ -2,7 +2,7 @@ import static com.mumfrey.liteloader.gl.GL.*; -import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.ConfiguredColour; import net.minecraft.client.Minecraft; @@ -18,13 +18,13 @@ public class GuiColourButton extends GuiControl */ private int colour = 0xFF000000; - private LineColour lineColour; + private ConfiguredColour lineColour; private GuiColourPicker picker; private boolean pickerClicked = false; - public GuiColourButton(Minecraft minecraft, int id, int xPosition, int yPosition, int controlWidth, int controlHeight, LineColour lineColour) + public GuiColourButton(Minecraft minecraft, int id, int xPosition, int yPosition, int controlWidth, int controlHeight, ConfiguredColour lineColour) { super(minecraft, id, xPosition, yPosition, controlWidth, controlHeight, lineColour.getDisplayName()); this.lineColour = lineColour; @@ -34,7 +34,7 @@ public GuiColourButton(Minecraft minecraft, int id, int xPosition, int yPosition /** * @param lineColour */ - public void updateColour(LineColour lineColour) + public void updateColour(ConfiguredColour lineColour) { if (lineColour == this.lineColour) { @@ -83,7 +83,7 @@ public void drawPicker(Minecraft minecraft, int mouseX, int mouseY, float partia { if (this.visible && this.picker != null) { - this.picker.func_191745_a(minecraft, mouseX, mouseY, partialTicks); // drawButton + this.picker.drawButton(minecraft, mouseX, mouseY, partialTicks); if (this.picker.getDialogResult() == DialogResult.OK) { diff --git a/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java index 313ba80a..f040298a 100644 --- a/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java +++ b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java @@ -163,8 +163,8 @@ protected void drawControl(Minecraft minecraft, int mouseX, int mouseY, float pa this.txtBlue.drawTextBox(); this.txtAlpha.drawTextBox(); - this.btnOk.func_191745_a(minecraft, mouseX, mouseY, partialTicks); // drawButton - this.btnCancel.func_191745_a(minecraft, mouseX, mouseY, partialTicks); // drawButton + this.btnOk.drawButton(minecraft, mouseX, mouseY, partialTicks); + this.btnCancel.drawButton(minecraft, mouseX, mouseY, partialTicks); } public void updateCursorCounter() diff --git a/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java b/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java index 4848a1f1..2bb07215 100644 --- a/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java +++ b/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java @@ -12,7 +12,6 @@ * which are used by several derived classes * * @author Adam Mummery-Smith - * */ public class GuiControl extends GuiButton { @@ -97,7 +96,7 @@ public enum DialogResult * @param mouseY Mouse Y coordinate */ @Override - public final void func_191745_a(Minecraft minecraft, int mouseX, int mouseY, float partialTicks) // drawButton + public final void drawButton(Minecraft minecraft, int mouseX, int mouseY, float partialTicks) { this.drawControl(minecraft, mouseX, mouseY, partialTicks); } @@ -111,7 +110,7 @@ public final void func_191745_a(Minecraft minecraft, int mouseX, int mouseY, flo */ protected void drawControl(Minecraft minecraft, int mouseX, int mouseY, float partialTicks) { - super.func_191745_a(minecraft, mouseX, mouseY, partialTicks); + super.drawButton(minecraft, mouseX, mouseY, partialTicks); } /** diff --git a/java/com/mumfrey/worldeditcui/render/CUISelectionProvider.java b/java/com/mumfrey/worldeditcui/render/CUISelectionProvider.java index 090b33ec..47126b70 100644 --- a/java/com/mumfrey/worldeditcui/render/CUISelectionProvider.java +++ b/java/com/mumfrey/worldeditcui/render/CUISelectionProvider.java @@ -7,16 +7,15 @@ import com.mumfrey.worldeditcui.InitialisationFactory; import com.mumfrey.worldeditcui.WorldEditCUI; import com.mumfrey.worldeditcui.exceptions.InitialisationException; -import com.mumfrey.worldeditcui.render.region.BaseRegion; +import com.mumfrey.worldeditcui.render.region.Region; import com.mumfrey.worldeditcui.render.region.RegionType; /** - * * @author Adam Mummery-Smith */ public class CUISelectionProvider implements InitialisationFactory { - private Map> regionConstructors = new HashMap>(); + private Map> regionConstructors = new HashMap>(); private WorldEditCUI controller; @@ -32,8 +31,8 @@ public void initialise() throws InitialisationException { try { - Class eventClass = regionType.getRegionClass(); - Constructor ctor = eventClass.getDeclaredConstructor(WorldEditCUI.class); + Class eventClass = regionType.getRegionClass(); + Constructor ctor = eventClass.getDeclaredConstructor(WorldEditCUI.class); this.regionConstructors.put(regionType.getKey(), ctor); } @@ -44,12 +43,17 @@ public void initialise() throws InitialisationException } } - public BaseRegion createSelection(String key) + public Region createSelection(String key) { + if ("clear".equals(key)) + { + return null; + } + try { - Constructor regionCtor = this.regionConstructors.get(key); - BaseRegion region = regionCtor.newInstance(this.controller); + Constructor regionCtor = this.regionConstructors.get(key); + Region region = regionCtor.newInstance(this.controller); return region; } catch (NullPointerException ex) @@ -58,7 +62,7 @@ public BaseRegion createSelection(String key) } catch (Exception ex) { - this.controller.getDebugger().debug("Error creation " + key + " selection: " + ex.getClass().getSimpleName() + " " + ex.getMessage()); + this.controller.getDebugger().debug("Error creating " + key + " selection: " + ex.getClass().getSimpleName() + " " + ex.getMessage()); } return null; diff --git a/java/com/mumfrey/worldeditcui/render/LineColour.java b/java/com/mumfrey/worldeditcui/render/ConfiguredColour.java similarity index 83% rename from java/com/mumfrey/worldeditcui/render/LineColour.java rename to java/com/mumfrey/worldeditcui/render/ConfiguredColour.java index 7da10628..373f6d2f 100644 --- a/java/com/mumfrey/worldeditcui/render/LineColour.java +++ b/java/com/mumfrey/worldeditcui/render/ConfiguredColour.java @@ -15,8 +15,9 @@ * * @author yetanotherx * @author lahwran + * @author Adam Mummery-Smith */ -public enum LineColour +public enum ConfiguredColour implements RenderColour { CUBOIDBOX ("colour.cuboidedge", new Colour("#CC3333CC")), CUBOIDGRID ("colour.cuboidgrid", new Colour("#CC4C4CCC")), @@ -32,18 +33,16 @@ public enum LineColour CYLINDERCENTRE ("colour.cylinderpoint", new Colour("#CC33CCCC")); private String displayName; + private Colour defaultColour, colour; + private LineInfo normal, hidden; + private LineInfo[] lines; - private Colour defaultColour; - private Colour colour; - - private LineInfo normal; - private LineInfo hidden; - - private LineColour(String displayName, Colour colour) + private ConfiguredColour(String displayName, Colour colour) { this.displayName = displayName; this.colour = colour; this.defaultColour = new Colour().copyFrom(colour); + this.updateLines(); } public String getDisplayName() @@ -51,6 +50,7 @@ public String getDisplayName() return I18n.format(this.displayName); } + @Override public Colour getColour() { return this.colour; @@ -66,38 +66,41 @@ public LineInfo getNormal() return this.normal; } + @Override public LineInfo[] getColours() { - return new LineInfo[] { this.hidden, this.normal }; + return this.lines; } + @Override public void setColour(Colour colour) { this.colour = colour; - this.updateColour(); - } - - public void updateColour() - { - this.normal = new LineInfo(3.0f, this.colour.red(), this.colour.green(), this.colour.blue(), this.colour.alpha(), GL_LESS); - this.hidden = new LineInfo(3.0f, this.colour.red() * 0.75F, this.colour.green() * 0.75F, this.colour.blue() * 0.75F, this.colour.alpha() * 0.25F, GL_GEQUAL); + this.updateLines(); } public void setDefaultColour() { this.colour.copyFrom(this.defaultColour); - this.updateColour(); + this.updateLines(); } public void setColourIntRGBA(int argb) { int rgba = ((argb << 8) & 0xFFFFFF00) | (((argb & 0xFF000000) >> 24) & 0xFF); this.colour.setHex(Integer.toHexString(rgba)); - this.updateColour(); + this.updateLines(); } public int getColourIntARGB() { return this.colour.getIntARGB(); } + + private void updateLines() + { + this.normal = new LineInfo(3.0f, this.colour.red(), this.colour.green(), this.colour.blue(), this.colour.alpha(), GL_LESS); + this.hidden = new LineInfo(3.0f, this.colour.red() * 0.75F, this.colour.green() * 0.75F, this.colour.blue() * 0.75F, this.colour.alpha() * 0.25F, GL_GEQUAL); + this.lines = new LineInfo[] { this.hidden, this.normal }; + } } diff --git a/java/com/mumfrey/worldeditcui/render/CustomColour.java b/java/com/mumfrey/worldeditcui/render/CustomColour.java new file mode 100644 index 00000000..8a908817 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/CustomColour.java @@ -0,0 +1,41 @@ +package com.mumfrey.worldeditcui.render; + +import static com.mumfrey.liteloader.gl.GL.*; + +import com.mumfrey.worldeditcui.config.Colour; + +/** + * Server-defined colour for multi selections + * + * @author Adam Mummery-Smith + */ +public class CustomColour implements RenderColour +{ + private Colour colour; + private final LineInfo[] lines = new LineInfo[2]; + + public CustomColour(Colour colour) + { + this.setColour(colour); + } + + @Override + public void setColour(Colour colour) + { + this.colour = colour; + this.lines[0] = new LineInfo(3.0f, colour.red() * 0.75F, colour.green() * 0.75F, colour.blue() * 0.75F, colour.alpha() * 0.25F, GL_GEQUAL); + this.lines[1] = new LineInfo(3.0f, colour.red(), colour.green(), colour.blue(), colour.alpha(), GL_LESS); + } + + @Override + public Colour getColour() + { + return this.colour; + } + + @Override + public LineInfo[] getColours() + { + return this.lines; + } +} diff --git a/java/com/mumfrey/worldeditcui/render/LineInfo.java b/java/com/mumfrey/worldeditcui/render/LineInfo.java index 0ff5e7d7..a0e6e98e 100644 --- a/java/com/mumfrey/worldeditcui/render/LineInfo.java +++ b/java/com/mumfrey/worldeditcui/render/LineInfo.java @@ -57,4 +57,9 @@ public void prepareColour() { glColor4f(this.red, this.green, this.blue, this.alpha); } + + public void prepareColour(float tint) + { + glColor4f(this.red, this.green, this.blue, this.alpha * tint); + } } diff --git a/java/com/mumfrey/worldeditcui/render/RenderColour.java b/java/com/mumfrey/worldeditcui/render/RenderColour.java new file mode 100644 index 00000000..5350971c --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/RenderColour.java @@ -0,0 +1,18 @@ +package com.mumfrey.worldeditcui.render; + +import com.mumfrey.worldeditcui.config.Colour; + +/** + * Render colour adapter, can be one of the built-in {@link ConfiguredColour}s or a + * user-defined colour from a custom payload + * + * @author Adam Mummery-Smith + */ +public interface RenderColour +{ + public abstract void setColour(Colour colour); + + public abstract Colour getColour(); + + public abstract LineInfo[] getColours(); +} \ No newline at end of file diff --git a/java/com/mumfrey/worldeditcui/render/points/PointCube.java b/java/com/mumfrey/worldeditcui/render/points/PointCube.java index d68b9da6..862bf35b 100644 --- a/java/com/mumfrey/worldeditcui/render/points/PointCube.java +++ b/java/com/mumfrey/worldeditcui/render/points/PointCube.java @@ -1,7 +1,10 @@ package com.mumfrey.worldeditcui.render.points; -import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.ConfiguredColour; +import com.mumfrey.worldeditcui.render.RenderColour; import com.mumfrey.worldeditcui.render.shapes.Render3DBox; +import com.mumfrey.worldeditcui.util.BoundingBox; +import com.mumfrey.worldeditcui.util.Observable; import com.mumfrey.worldeditcui.util.Vector3; /** @@ -12,18 +15,20 @@ * * @author yetanotherx * @author lahwran + * @author Adam Mummery-Smith */ -public class PointCube +public class PointCube extends Observable { - private static final double OFF = 0.03f; + private static final double PADDING = 0.03; - private static final Vector3 MIN_VEC = new Vector3(PointCube.OFF, PointCube.OFF, PointCube.OFF); - private static final Vector3 MAX_VEC = new Vector3(PointCube.OFF + 1, PointCube.OFF + 1, PointCube.OFF + 1); + protected static final Vector3 MIN_VEC = new Vector3(PointCube.PADDING, PointCube.PADDING, PointCube.PADDING); + protected static final Vector3 MAX_VEC = new Vector3(PointCube.PADDING + 1, PointCube.PADDING + 1, PointCube.PADDING + 1); + protected int id; protected Vector3 point; - protected LineColour colour = LineColour.CUBOIDPOINT1; + protected RenderColour colour = ConfiguredColour.CUBOIDPOINT1; - private Render3DBox box; + protected Render3DBox box; public PointCube(double x, double y, double z) { @@ -35,11 +40,31 @@ public PointCube(Vector3 point) this.setPoint(point); } + public boolean isDynamic() + { + return false; + } + + public PointCube setId(int id) + { + this.id = id; + return this; + } + + public int getId() + { + return this.id; + } + public void render(Vector3 cameraPos) { this.box.render(cameraPos); } - + + public void updatePoint() + { + } + public Vector3 getPoint() { return this.point; @@ -51,19 +76,20 @@ public void setPoint(Vector3 point) this.update(); } - public LineColour getColour() + public RenderColour getColour() { return this.colour; } - public void setColour(LineColour colour) + public PointCube setColour(RenderColour colour) { this.colour = colour; this.update(); + return this; } private void update() { - this.box = new Render3DBox(this.colour, this.point.subtract(MIN_VEC), this.point.add(MAX_VEC)); + this.box = new Render3DBox(this.colour, this.point.subtract(PointCube.MIN_VEC), this.point.add(PointCube.MAX_VEC)); } } diff --git a/java/com/mumfrey/worldeditcui/render/points/PointCubeTracking.java b/java/com/mumfrey/worldeditcui/render/points/PointCubeTracking.java new file mode 100644 index 00000000..a0df672e --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/points/PointCubeTracking.java @@ -0,0 +1,54 @@ +package com.mumfrey.worldeditcui.render.points; + +import net.minecraft.entity.Entity; +import net.minecraft.util.math.MathHelper; + +import com.mumfrey.worldeditcui.util.Vector3; + +/** + * A PointCube which tracks the specified entity location + * + * @author Adam Mummery-Smith + */ +public class PointCubeTracking extends PointCube +{ + private final Entity entity; + private int lastX, lastY, lastZ; + + public PointCubeTracking(Entity entity) + { + super(0, 0, 0); + this.entity = entity; + } + + @Override + public boolean isDynamic() + { + return true; + } + + @Override + public Vector3 getPoint() + { + this.updatePoint(); + return this.point; + } + + @Override + public void updatePoint() + { + int x = MathHelper.floor(this.entity.posX); + int y = MathHelper.floor(this.entity.posY + this.entity.getEyeHeight()); + int z = MathHelper.floor(this.entity.posZ); + + if (this.lastX != x || this.lastY != y || this.lastZ != z) + { + this.lastX = x; + this.lastY = y; + this.lastZ = z; + this.point = new Vector3(x, y, z); + this.box.setPosition(this.point.subtract(PointCube.MIN_VEC), this.point.add(PointCube.MAX_VEC)); + this.notifyObservers(); + } + } +} diff --git a/java/com/mumfrey/worldeditcui/render/points/PointRectangle.java b/java/com/mumfrey/worldeditcui/render/points/PointRectangle.java index 121d5da2..c30de1ff 100644 --- a/java/com/mumfrey/worldeditcui/render/points/PointRectangle.java +++ b/java/com/mumfrey/worldeditcui/render/points/PointRectangle.java @@ -1,18 +1,19 @@ package com.mumfrey.worldeditcui.render.points; -import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.RenderColour; +import com.mumfrey.worldeditcui.render.ConfiguredColour; import com.mumfrey.worldeditcui.render.shapes.Render3DBox; import com.mumfrey.worldeditcui.util.Vector2; import com.mumfrey.worldeditcui.util.Vector3; /** - * Stores data about a prism surrounding two - * blocks in the world. Used to store info - * about the selector blocks for polys. Keeps - * track of colour, x/y/z values, and rendering. + * Stores data about a prism surrounding two blocks in the world. Used to store + * info about the selector blocks for polys. Keeps track of colour, x/y/z + * values, and rendering. * * @author yetanotherx * @author lahwran + * @author Adam Mummery-Smith */ public class PointRectangle { @@ -21,7 +22,7 @@ public class PointRectangle private static final Vector2 MAX_VEC = new Vector2(PointRectangle.OFF + 1, PointRectangle.OFF + 1); protected Vector2 point; - protected LineColour colour = LineColour.POLYPOINT; + protected RenderColour colour = ConfiguredColour.POLYPOINT; private int min, max; @@ -52,12 +53,12 @@ public void setPoint(Vector2 point) this.point = point; } - public LineColour getColour() + public RenderColour getColour() { return this.colour; } - public void setColour(LineColour colour) + public void setColour(RenderColour colour) { this.colour = colour; } diff --git a/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java b/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java index 9e01ecc6..119156d0 100644 --- a/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java @@ -1,8 +1,12 @@ package com.mumfrey.worldeditcui.render.region; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.Entity; + import com.mumfrey.worldeditcui.WorldEditCUI; -import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.ConfiguredColour; import com.mumfrey.worldeditcui.render.points.PointCube; +import com.mumfrey.worldeditcui.render.points.PointCubeTracking; import com.mumfrey.worldeditcui.render.shapes.Render3DBox; import com.mumfrey.worldeditcui.render.shapes.Render3DGrid; import com.mumfrey.worldeditcui.util.BoundingBox; @@ -13,59 +17,112 @@ * * @author yetanotherx * @author lahwran + * @author Adam Mummery-Smith */ -public class CuboidRegion extends BaseRegion +public class CuboidRegion extends Region { - protected PointCube firstPoint; - protected PointCube secondPoint; + private PointCube[] points = new PointCube[2]; private Render3DGrid grid; private Render3DBox box; + private double spacing = 1.0; + public CuboidRegion(WorldEditCUI controller) { - super(controller); + super(controller, ConfiguredColour.CUBOIDBOX, ConfiguredColour.CUBOIDGRID, ConfiguredColour.CUBOIDPOINT1, ConfiguredColour.CUBOIDPOINT2); } @Override public void render(Vector3 cameraPos) { - if (this.firstPoint != null && this.secondPoint != null) + if (this.points[0] != null && this.points[1] != null) { + this.points[0].updatePoint(); + this.points[1].updatePoint(); + this.grid.render(cameraPos); this.box.render(cameraPos); - this.firstPoint.render(cameraPos); - this.secondPoint.render(cameraPos); + + this.points[0].render(cameraPos); + this.points[1].render(cameraPos); + } + else if (this.points[0] != null) + { + this.points[0].updatePoint(); + this.points[0].render(cameraPos); } - else if (this.firstPoint != null) + else if (this.points[1] != null) { - this.firstPoint.render(cameraPos); + this.points[1].updatePoint(); + this.points[1].render(cameraPos); } - else if (this.secondPoint != null) + } + + @Override + public void setGridSpacing(double spacing) + { + this.spacing = spacing; + if (this.grid != null) { - this.secondPoint.render(cameraPos); + this.grid.setSpacing(spacing); } } @Override public void setCuboidPoint(int id, double x, double y, double z) { - if (id == 0) + if (id < 2) { - this.firstPoint = new PointCube(x, y, z); - this.firstPoint.setColour(LineColour.CUBOIDPOINT1); + this.points[id] = new PointCube(x, y, z).setColour(this.colours[2]); } - else if (id == 1) + + this.updateBounds(); + } + + @Override + public void setCuboidVertexLatch(int id) + { + if (id < 2) + { + Entity renderViewEntity = Minecraft.getMinecraft().getRenderViewEntity(); + this.points[id] = new PointCubeTracking(renderViewEntity).setColour(this.colours[2]); + } + + this.updateBounds(); + } + + private void updateBounds() + { + if (this.points[0] != null && this.points[1] != null) + { + BoundingBox bounds = new BoundingBox(this.points[0], this.points[1]); + this.grid = new Render3DGrid(this.colours[1], bounds).setSpacing(this.spacing); + this.box = new Render3DBox(this.colours[0], bounds); + } + } + + @Override + protected void updateColours() + { + if (this.box != null) + { + this.box.setColour(this.colours[0]); + } + + if (this.grid != null) + { + this.grid.setColour(this.colours[1]); + } + + if (this.points[0] != null) { - this.secondPoint = new PointCube(x, y, z); - this.secondPoint.setColour(LineColour.CUBOIDPOINT2); + this.points[0].setColour(this.colours[2]); } - if (this.firstPoint != null && this.secondPoint != null) + if (this.points[1] != null) { - BoundingBox bounds = new BoundingBox(this.firstPoint, this.secondPoint); - this.grid = new Render3DGrid(LineColour.CUBOIDGRID, bounds); - this.box = new Render3DBox(LineColour.CUBOIDBOX, bounds); + this.points[1].setColour(this.colours[3]); } } diff --git a/java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java b/java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java index 64be8f4e..8ff5dd2a 100644 --- a/java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java @@ -1,7 +1,7 @@ package com.mumfrey.worldeditcui.render.region; import com.mumfrey.worldeditcui.WorldEditCUI; -import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.ConfiguredColour; import com.mumfrey.worldeditcui.render.points.PointCube; import com.mumfrey.worldeditcui.render.shapes.RenderCylinderBox; import com.mumfrey.worldeditcui.render.shapes.RenderCylinderCircles; @@ -12,15 +12,13 @@ * Main controller for a cylinder-type region * * @author yetanotherx + * @author Adam Mummery-Smith */ -public class CylinderRegion extends BaseRegion +public class CylinderRegion extends Region { - - protected PointCube centre; - protected double radX = 0; - protected double radZ = 0; - protected int minY = 0; - protected int maxY = 0; + private PointCube centre; + private double radX = 0, radZ = 0; + private int minY = 0, maxY = 0; private RenderCylinderCircles circles; private RenderCylinderGrid grid; @@ -28,7 +26,7 @@ public class CylinderRegion extends BaseRegion public CylinderRegion(WorldEditCUI controller) { - super(controller); + super(controller, ConfiguredColour.CYLINDERBOX, ConfiguredColour.CYLINDERGRID, ConfiguredColour.CYLINDERCENTRE); } @Override @@ -47,7 +45,7 @@ public void render(Vector3 cameraPos) public void setCylinderCenter(int x, int y, int z) { this.centre = new PointCube(x, y, z); - this.centre.setColour(LineColour.CYLINDERCENTRE); + this.centre.setColour(this.colours[2]); this.update(); } @@ -78,11 +76,35 @@ private void update() tMax = (int)this.centre.getPoint().getY(); } - this.circles = new RenderCylinderCircles(LineColour.CYLINDERGRID, this.centre, this.radX, this.radZ, tMin, tMax); - this.grid = new RenderCylinderGrid(LineColour.CYLINDERGRID, this.centre, this.radX, this.radZ, tMin, tMax); - this.box = new RenderCylinderBox(LineColour.CYLINDERBOX, this.centre, this.radX, this.radZ, tMin, tMax); + this.circles = new RenderCylinderCircles(this.colours[1], this.centre, this.radX, this.radZ, tMin, tMax); + this.grid = new RenderCylinderGrid(this.colours[1], this.centre, this.radX, this.radZ, tMin, tMax); + this.box = new RenderCylinderBox(this.colours[0], this.centre, this.radX, this.radZ, tMin, tMax); } + @Override + protected void updateColours() + { + if (this.box != null) + { + this.box.setColour(this.colours[0]); + } + + if (this.grid != null) + { + this.grid.setColour(this.colours[1]); + } + + if (this.circles != null) + { + this.circles.setColour(this.colours[1]); + } + + if (this.centre != null) + { + this.centre.setColour(this.colours[2]); + } + } + @Override public RegionType getType() { diff --git a/java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java b/java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java index bf027f61..da9ef816 100644 --- a/java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java @@ -1,7 +1,7 @@ package com.mumfrey.worldeditcui.render.region; import com.mumfrey.worldeditcui.WorldEditCUI; -import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.ConfiguredColour; import com.mumfrey.worldeditcui.render.points.PointCube; import com.mumfrey.worldeditcui.render.shapes.RenderEllipsoid; import com.mumfrey.worldeditcui.util.Vector3; @@ -11,18 +11,18 @@ * * @author yetanotherx * @author lahwran + * @author Adam Mummery-Smith */ -public class EllipsoidRegion extends BaseRegion +public class EllipsoidRegion extends Region { - - protected PointCube centre; - protected Vector3 radii; + private PointCube centre; + private Vector3 radii; private RenderEllipsoid ellipsoid; public EllipsoidRegion(WorldEditCUI controller) { - super(controller); + super(controller, ConfiguredColour.ELLIPSOIDGRID, ConfiguredColour.ELLIPSOIDCENTRE); } @Override @@ -43,7 +43,7 @@ else if (this.centre != null) public void setEllipsoidCenter(int x, int y, int z) { this.centre = new PointCube(x, y, z); - this.centre.setColour(LineColour.ELLIPSOIDCENTRE); + this.centre.setColour(this.colours[1]); this.update(); } @@ -58,10 +58,24 @@ private void update() { if (this.centre != null && this.radii != null) { - this.ellipsoid = new RenderEllipsoid(LineColour.ELLIPSOIDGRID, this.centre, this.radii); + this.ellipsoid = new RenderEllipsoid(this.colours[0], this.centre, this.radii); } } + @Override + protected void updateColours() + { + if (this.ellipsoid != null) + { + this.ellipsoid.setColour(this.colours[0]); + } + + if (this.centre != null) + { + this.centre.setColour(this.colours[1]); + } + } + @Override public RegionType getType() { diff --git a/java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java b/java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java index 897e27ee..dcf92518 100644 --- a/java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java @@ -4,7 +4,7 @@ import java.util.List; import com.mumfrey.worldeditcui.WorldEditCUI; -import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.ConfiguredColour; import com.mumfrey.worldeditcui.render.points.PointRectangle; import com.mumfrey.worldeditcui.render.shapes.Render2DBox; import com.mumfrey.worldeditcui.render.shapes.Render2DGrid; @@ -15,20 +15,19 @@ * * @author yetanotherx * @author lahwran + * @author Adam Mummery-Smith */ -public class PolygonRegion extends BaseRegion +public class PolygonRegion extends Region { - - protected List points = new ArrayList(); - protected int min; - protected int max; + private final List points = new ArrayList(); + private int min, max; private Render2DBox box; private Render2DGrid grid; public PolygonRegion(WorldEditCUI controller) { - super(controller); + super(controller, ConfiguredColour.POLYBOX, ConfiguredColour.POLYGRID, ConfiguredColour.POLYPOINT); } @Override @@ -63,7 +62,7 @@ public void setMinMax(int min, int max) public void setPolygonPoint(int id, int x, int z) { PointRectangle point = new PointRectangle(x, z); - point.setColour(LineColour.POLYPOINT); + point.setColour(this.colours[0]); point.setMinMax(this.min, this.max); if (id < this.points.size()) @@ -83,21 +82,42 @@ public void setPolygonPoint(int id, int x, int z) private void update() { - if (this.points.size() > 0) + if (this.points.size() <= 0) + { + return; + } + + for (PointRectangle point : this.points) { - for (PointRectangle point : this.points) + if (point != null) { - if (point != null) - { - point.setMinMax(this.min, this.max); - } + point.setMinMax(this.min, this.max); } - - this.box = new Render2DBox(LineColour.POLYBOX, this.points, this.min, this.max); - this.grid = new Render2DGrid(LineColour.POLYGRID, this.points, this.min, this.max); } + + this.box = new Render2DBox(this.colours[0], this.points, this.min, this.max); + this.grid = new Render2DGrid(this.colours[1], this.points, this.min, this.max); } + @Override + protected void updateColours() + { + if (this.box != null) + { + this.box.setColour(this.colours[0]); + } + + if (this.grid != null) + { + this.grid.setColour(this.colours[1]); + } + + for (PointRectangle point : this.points) + { + point.setColour(this.colours[0]); + } + } + @Override public RegionType getType() { diff --git a/java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java b/java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java index 9dea681d..76136592 100644 --- a/java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java @@ -4,7 +4,7 @@ import java.util.List; import com.mumfrey.worldeditcui.WorldEditCUI; -import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.ConfiguredColour; import com.mumfrey.worldeditcui.render.points.PointCube; import com.mumfrey.worldeditcui.render.shapes.Render3DPolygon; import com.mumfrey.worldeditcui.util.Vector3; @@ -13,18 +13,20 @@ * Main controller for a polygon-type region * * @author TomyLobo + * @author Adam Mummery-Smith */ -public class PolyhedronRegion extends BaseRegion +public class PolyhedronRegion extends Region { + private static final Vector3 HALF = new Vector3(0.5, 0.5, 0.5); - protected List vertices = new ArrayList(); - protected List faces = new ArrayList(); + private List vertices = new ArrayList(); + private List faces = new ArrayList(); private List faceRenders = new ArrayList(); public PolyhedronRegion(WorldEditCUI controller) { - super(controller); + super(controller, ConfiguredColour.POLYBOX, ConfiguredColour.POLYPOINT, ConfiguredColour.CUBOIDPOINT1); } @Override @@ -44,8 +46,8 @@ public void render(Vector3 cameraPos) @Override public void setCuboidPoint(int id, double x, double y, double z) { - final PointCube vertex = new PointCube(x, y, z); - vertex.setColour(id == 0 ? LineColour.CUBOIDPOINT1 : LineColour.POLYPOINT); + final PointCube vertex = new PointCube(x, y, z).setId(id); + vertex.setColour(id == 0 ? this.colours[2] : this.colours[1]); if (id < this.vertices.size()) { @@ -61,8 +63,6 @@ public void setCuboidPoint(int id, double x, double y, double z) } } - private static final Vector3 half = new Vector3(0.5, 0.5, 0.5); - @Override public void addPolygon(int[] vertexIds) { @@ -76,7 +76,7 @@ public void addPolygon(int[] vertexIds) return; } - face[i] = vertex.getPoint().add(half); + face[i] = vertex.getPoint().add(HALF); } this.faces.add(face); this.update(); @@ -88,10 +88,24 @@ private void update() for (Vector3[] face : this.faces) { - this.faceRenders.add(new Render3DPolygon(LineColour.POLYBOX, face)); + this.faceRenders.add(new Render3DPolygon(this.colours[0], face)); } } + @Override + protected void updateColours() + { + for (PointCube vertex : this.vertices) + { + vertex.setColour(vertex.getId() == 0 ? this.colours[2] : this.colours[1]); + } + + for (Render3DPolygon face : this.faceRenders) + { + face.setColour(this.colours[0]); + } + } + @Override public RegionType getType() { diff --git a/java/com/mumfrey/worldeditcui/render/region/BaseRegion.java b/java/com/mumfrey/worldeditcui/render/region/Region.java similarity index 62% rename from java/com/mumfrey/worldeditcui/render/region/BaseRegion.java rename to java/com/mumfrey/worldeditcui/render/region/Region.java index 948970d9..9a5bbeaa 100644 --- a/java/com/mumfrey/worldeditcui/render/region/BaseRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/Region.java @@ -3,6 +3,7 @@ import com.mumfrey.worldeditcui.InitialisationFactory; import com.mumfrey.worldeditcui.WorldEditCUI; import com.mumfrey.worldeditcui.exceptions.InvalidSelectionTypeException; +import com.mumfrey.worldeditcui.render.RenderColour; import com.mumfrey.worldeditcui.util.Vector3; /** @@ -12,15 +13,18 @@ * * @author yetanotherx * @author lahwran + * @author Adam Mummery-Smith */ -public abstract class BaseRegion implements InitialisationFactory +public abstract class Region implements InitialisationFactory { + protected final WorldEditCUI controller; + protected final RenderColour[] defaultColours; + protected RenderColour[] colours; - protected WorldEditCUI controller; - - public BaseRegion(WorldEditCUI controller) + protected Region(WorldEditCUI controller, RenderColour... colours) { this.controller = controller; + this.colours = this.defaultColours = colours; } @Override @@ -30,11 +34,39 @@ public void initialise() public abstract void render(Vector3 cameraPos); + public RenderColour[] getDefaultColours() + { + return this.defaultColours; + } + + public void setColours(RenderColour... colours) + { + if (colours.length < this.defaultColours.length) + { + throw new IllegalArgumentException("Invalid colour palette supplied for " + this.getType().getName() + " region"); + } + + this.colours = colours; + this.updateColours(); + } + + protected abstract void updateColours(); + + public void setGridSpacing(double spacing) + { + throw new InvalidSelectionTypeException(this.getType().getName(), "setGridSpacing"); + } + public void setCuboidPoint(int id, double x, double y, double z) { throw new InvalidSelectionTypeException(this.getType().getName(), "setCuboidPoint"); } + public void setCuboidVertexLatch(int id) + { + throw new InvalidSelectionTypeException(this.getType().getName(), "setCuboidVertexLatch"); + } + public void setPolygonPoint(int id, int x, int z) { throw new InvalidSelectionTypeException(this.getType().getName(), "setPolygonPoint"); diff --git a/java/com/mumfrey/worldeditcui/render/region/RegionType.java b/java/com/mumfrey/worldeditcui/render/region/RegionType.java index 11ecde37..a349ac71 100644 --- a/java/com/mumfrey/worldeditcui/render/region/RegionType.java +++ b/java/com/mumfrey/worldeditcui/render/region/RegionType.java @@ -17,9 +17,9 @@ public enum RegionType private final String name; - private final Class regionClass; + private final Class regionClass; - private RegionType(String key, String name, Class regionClass) + private RegionType(String key, String name, Class regionClass) { this.key = key; this.name = name; @@ -36,7 +36,7 @@ public String getName() return this.name; } - public Class getRegionClass() + public Class getRegionClass() { return this.regionClass; } diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java b/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java index b604a336..d63de941 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java @@ -2,7 +2,7 @@ import java.util.List; -import com.mumfrey.worldeditcui.render.LineColour; +import com.mumfrey.worldeditcui.render.RenderColour; import com.mumfrey.worldeditcui.render.LineInfo; import com.mumfrey.worldeditcui.render.points.PointRectangle; import com.mumfrey.worldeditcui.util.Vector2; @@ -17,23 +17,22 @@ * * @author yetanotherx * @author lahwran + * @author Adam Mummery-Smith */ -public class Render2DBox +public class Render2DBox extends RenderRegion { + private List points; + private int min, max; - protected LineColour colour; - protected List points; - protected int min; - protected int max; - - public Render2DBox(LineColour colour, List points, int min, int max) + public Render2DBox(RenderColour colour, List points, int min, int max) { - this.colour = colour; + super(colour); this.points = points; this.min = min; this.max = max; } + @Override public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java b/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java index 4e595809..f75e51d1 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java @@ -1,38 +1,39 @@ package com.mumfrey.worldeditcui.render.shapes; +import static com.mumfrey.liteloader.gl.GL.*; + import java.util.List; -import com.mumfrey.worldeditcui.render.LineColour; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Tessellator; + +import com.mumfrey.worldeditcui.render.RenderColour; import com.mumfrey.worldeditcui.render.LineInfo; import com.mumfrey.worldeditcui.render.points.PointRectangle; import com.mumfrey.worldeditcui.util.Vector2; import com.mumfrey.worldeditcui.util.Vector3; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.BufferBuilder; -import static com.mumfrey.liteloader.gl.GL.*; - /** * Draws the grid for a polygon region * * @author yetanotherx * @author lahwran + * @author Adam Mummery-Smith */ -public class Render2DGrid +public class Render2DGrid extends RenderRegion { - protected LineColour colour; - protected List points; - protected int min; - protected int max; + private List points; + private int min, max; - public Render2DGrid(LineColour colour, List points, int min, int max) + public Render2DGrid(RenderColour colour, List points, int min, int max) { - this.colour = colour; + super(colour); this.points = points; this.min = min; this.max = max; } + @Override public void render(Vector3 cameraPos) { double off = 0.03; diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java index 290f6ef0..0de59471 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java @@ -1,39 +1,61 @@ package com.mumfrey.worldeditcui.render.shapes; -import com.mumfrey.worldeditcui.render.LineColour; +import static com.mumfrey.liteloader.gl.GL.*; + +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Tessellator; + +import com.mumfrey.worldeditcui.render.RenderColour; import com.mumfrey.worldeditcui.render.LineInfo; import com.mumfrey.worldeditcui.util.BoundingBox; +import com.mumfrey.worldeditcui.util.Observable; import com.mumfrey.worldeditcui.util.Vector3; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.BufferBuilder; -import static com.mumfrey.liteloader.gl.GL.*; - /** * Draws a rectangular prism around 2 corners * * @author yetanotherx * @author lahwran + * @author Adam Mummery-Smith */ -public class Render3DBox +public class Render3DBox extends RenderRegion { + private Vector3 first, second; - protected LineColour colour; - protected Vector3 first; - protected Vector3 second; - - public Render3DBox(LineColour colour, BoundingBox region) + public Render3DBox(RenderColour colour, BoundingBox region) { this(colour, region.getMin(), region.getMax()); + if (region.isDynamic()) + { + region.addObserver(this); + } + } + + public Render3DBox(RenderColour colour, Vector3 first, Vector3 second) + { + super(colour); + this.first = first; + this.second = second; + } + + @Override + public void notifyChanged(Observable source) + { + this.setPosition((BoundingBox)source); + } + + public void setPosition(BoundingBox region) + { + this.setPosition(region.getMin(), region.getMax()); } - public Render3DBox(LineColour colour, Vector3 first, Vector3 second) + public void setPosition(Vector3 first, Vector3 second) { - this.colour = colour; this.first = first; this.second = second; } + @Override public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java index c230bc9c..7f969ba3 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java @@ -1,39 +1,70 @@ package com.mumfrey.worldeditcui.render.shapes; -import com.mumfrey.worldeditcui.render.LineColour; +import static com.mumfrey.liteloader.gl.GL.*; + +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Tessellator; + import com.mumfrey.worldeditcui.render.LineInfo; +import com.mumfrey.worldeditcui.render.RenderColour; import com.mumfrey.worldeditcui.util.BoundingBox; +import com.mumfrey.worldeditcui.util.Observable; import com.mumfrey.worldeditcui.util.Vector3; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.BufferBuilder; -import static com.mumfrey.liteloader.gl.GL.*; - /** * Draws the grid for a region between * two corners in a cuboid region. * * @author yetanotherx + * @author Adam Mummery-Smith */ -public class Render3DGrid +public class Render3DGrid extends RenderRegion { + public static final double MIN_SPACING = 1.0; - protected LineColour colour; - protected Vector3 first; - protected Vector3 second; + private Vector3 first, second; + private double spacing = 1.0; - public Render3DGrid(LineColour colour, BoundingBox region) + public Render3DGrid(RenderColour colour, BoundingBox region) { this(colour, region.getMin(), region.getMax()); + if (region.isDynamic()) + { + region.addObserver(this); + } } - public Render3DGrid(LineColour colour, Vector3 first, Vector3 second) + public Render3DGrid(RenderColour colour, Vector3 first, Vector3 second) { - this.colour = colour; + super(colour); this.first = first; this.second = second; } + @Override + public void notifyChanged(Observable source) + { + this.setPosition((BoundingBox)source); + } + + public void setPosition(BoundingBox region) + { + this.setPosition(region.getMin(), region.getMax()); + } + + public void setPosition(Vector3 first, Vector3 second) + { + this.first = first; + this.second = second; + } + + public Render3DGrid setSpacing(double spacing) + { + this.spacing = spacing; + return this; + } + + @Override public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); @@ -45,6 +76,39 @@ public void render(Vector3 cameraPos) double y2 = this.second.getY() - cameraPos.getY(); double z2 = this.second.getZ() - cameraPos.getZ(); + if (this.spacing != 1.0) + { + glDisableCulling(); + + double[] vertices = { + x1, y1, z1, x2, y1, z1, x2, y1, z2, x1, y1, z2, // bottom + x1, y2, z1, x2, y2, z1, x2, y2, z2, x1, y2, z2, // top + x1, y1, z1, x1, y1, z2, x1, y2, z2, x1, y2, z1, // west + x2, y1, z1, x2, y2, z1, x2, y2, z2, x2, y1, z2, // east + x1, y1, z1, x1, y2, z1, x2, y2, z1, x2, y1, z1, // north + x1, y1, z2, x2, y1, z2, x2, y2, z2, x1, y2, z2 // south + }; + + for (LineInfo tempColour : this.colour.getColours()) + { + buf.begin(GL_QUADS, VF_POSITION); + tempColour.prepareRender(); + tempColour.prepareColour(0.25F); + for (int i = 0; i < vertices.length; i += 3) + { + buf.pos(vertices[i], vertices[i + 1], vertices[i + 2]).endVertex(); + } + tessellator.draw(); + } + + glEnableCulling(); + } + + if (this.spacing < Render3DGrid.MIN_SPACING) + { + return; + } + double cullAt = 128.0F; for (LineInfo tempColour : this.colour.getColours()) { @@ -53,9 +117,7 @@ public void render(Vector3 cameraPos) buf.begin(GL_LINES, VF_POSITION); tempColour.prepareColour(); - double offsetSize = 1.0; - - for (double yoff = 0; yoff + y1 <= y2; yoff += offsetSize) + for (double yoff = 0; yoff + y1 <= y2; yoff += this.spacing) { double y = y1 + yoff; buf.pos(x1, y, z2).endVertex(); @@ -68,7 +130,7 @@ public void render(Vector3 cameraPos) buf.pos(x2, y, z2).endVertex(); } - for (double xoff = 0; xoff + x1 <= x2; xoff += offsetSize) + for (double xoff = 0; xoff + x1 <= x2; xoff += this.spacing) { double x = x1 + xoff; // boolean major = xoff % 10 == 0; @@ -84,7 +146,7 @@ public void render(Vector3 cameraPos) buf.pos(x, y1, z2).endVertex(); } - for (double zoff = 0; zoff + z1 <= z2; zoff += offsetSize) + for (double zoff = 0; zoff + z1 <= z2; zoff += this.spacing) { double z = z1 + zoff; // boolean major = zoff % 10 == 0; diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java index fa662afb..f9d32397 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java @@ -1,31 +1,32 @@ package com.mumfrey.worldeditcui.render.shapes; -import com.mumfrey.worldeditcui.render.LineColour; -import com.mumfrey.worldeditcui.render.LineInfo; -import com.mumfrey.worldeditcui.util.Vector3; +import static com.mumfrey.liteloader.gl.GL.*; -import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.BufferBuilder; -import static com.mumfrey.liteloader.gl.GL.*; +import net.minecraft.client.renderer.Tessellator; + +import com.mumfrey.worldeditcui.render.RenderColour; +import com.mumfrey.worldeditcui.render.LineInfo; +import com.mumfrey.worldeditcui.util.Vector3; /** * Draws a polygon * * @author yetanotherx * @author lahwran + * @author Adam Mummery-Smith */ -public class Render3DPolygon +public class Render3DPolygon extends RenderRegion { + private Vector3[] vertices; - protected LineColour colour; - protected Vector3[] vertices; - - public Render3DPolygon(LineColour colour, Vector3... vertices) + public Render3DPolygon(RenderColour colour, Vector3... vertices) { - this.colour = colour; + super(colour); this.vertices = vertices; } + @Override public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java index 92c1f86a..ce631b33 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java @@ -1,33 +1,30 @@ package com.mumfrey.worldeditcui.render.shapes; -import com.mumfrey.worldeditcui.render.LineColour; +import static com.mumfrey.liteloader.gl.GL.*; + +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Tessellator; + +import com.mumfrey.worldeditcui.render.RenderColour; import com.mumfrey.worldeditcui.render.LineInfo; import com.mumfrey.worldeditcui.render.points.PointCube; import com.mumfrey.worldeditcui.util.Vector3; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.BufferBuilder; -import static com.mumfrey.liteloader.gl.GL.*; - /** * Draws the top and bottom circles around a cylindrical region * * @author yetanotherx + * @author Adam Mummery-Smith */ -public class RenderCylinderBox +public class RenderCylinderBox extends RenderRegion { + private double radX, radZ; + private int minY, maxY; + private double centreX, centreZ; - protected LineColour colour; - protected double radX = 0; - protected double radZ = 0; - protected int minY; - protected int maxY; - protected double centreX; - protected double centreZ; - - public RenderCylinderBox(LineColour colour, PointCube centre, double radX, double radZ, int minY, int maxY) + public RenderCylinderBox(RenderColour colour, PointCube centre, double radX, double radZ, int minY, int maxY) { - this.colour = colour; + super(colour); this.radX = radX; this.radZ = radZ; this.minY = minY; @@ -36,6 +33,7 @@ public RenderCylinderBox(LineColour colour, PointCube centre, double radX, doubl this.centreZ = centre.getPoint().getZ() + 0.5; } + @Override public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java index 228abcf4..79b29d9c 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java @@ -1,23 +1,23 @@ package com.mumfrey.worldeditcui.render.shapes; -import com.mumfrey.worldeditcui.render.LineColour; +import static com.mumfrey.liteloader.gl.GL.*; + +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Tessellator; + +import com.mumfrey.worldeditcui.render.RenderColour; import com.mumfrey.worldeditcui.render.LineInfo; import com.mumfrey.worldeditcui.render.points.PointCube; import com.mumfrey.worldeditcui.util.Vector3; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.BufferBuilder; -import static com.mumfrey.liteloader.gl.GL.*; - /** * Draws the circles around a cylindrical region * * @author yetanotherx + * @author Adam Mummery-Smith */ -public class RenderCylinderCircles +public class RenderCylinderCircles extends RenderRegion { - - protected LineColour colour; protected double radX = 0; protected double radZ = 0; protected int minY; @@ -25,9 +25,9 @@ public class RenderCylinderCircles protected double centreX; protected double centreZ; - public RenderCylinderCircles(LineColour colour, PointCube centre, double radX, double radZ, int minY, int maxY) + public RenderCylinderCircles(RenderColour colour, PointCube centre, double radX, double radZ, int minY, int maxY) { - this.colour = colour; + super(colour); this.radX = radX; this.radZ = radZ; this.minY = minY; @@ -35,7 +35,8 @@ public RenderCylinderCircles(LineColour colour, PointCube centre, double radX, d this.centreX = centre.getPoint().getX() + 0.5; this.centreZ = centre.getPoint().getZ() + 0.5; } - + + @Override public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java index f914b6a6..dbc30d63 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java @@ -1,23 +1,23 @@ package com.mumfrey.worldeditcui.render.shapes; -import com.mumfrey.worldeditcui.render.LineColour; +import static com.mumfrey.liteloader.gl.GL.*; + +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Tessellator; + +import com.mumfrey.worldeditcui.render.RenderColour; import com.mumfrey.worldeditcui.render.LineInfo; import com.mumfrey.worldeditcui.render.points.PointCube; import com.mumfrey.worldeditcui.util.Vector3; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.BufferBuilder; -import static com.mumfrey.liteloader.gl.GL.*; - /** * Draws the grid lines around a cylindrical region * * @author yetanotherx + * @author Adam Mummery-Smith */ -public class RenderCylinderGrid +public class RenderCylinderGrid extends RenderRegion { - - protected LineColour colour; protected double radX = 0; protected double radZ = 0; protected int minY; @@ -25,9 +25,9 @@ public class RenderCylinderGrid protected double centreX; protected double centreZ; - public RenderCylinderGrid(LineColour colour, PointCube centre, double radX, double radZ, int minY, int maxY) + public RenderCylinderGrid(RenderColour colour, PointCube centre, double radX, double radZ, int minY, int maxY) { - this.colour = colour; + super(colour); this.radX = radX; this.radZ = radZ; this.minY = minY; @@ -36,6 +36,7 @@ public RenderCylinderGrid(LineColour colour, PointCube centre, double radX, doub this.centreZ = centre.getPoint().getZ() + 0.5; } + @Override public void render(Vector3 cameraPos) { Tessellator tessellator = Tessellator.getInstance(); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java index 8ee94cc5..eef073d8 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java @@ -1,23 +1,23 @@ package com.mumfrey.worldeditcui.render.shapes; -import com.mumfrey.worldeditcui.render.LineColour; +import static com.mumfrey.liteloader.gl.GL.*; + +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Tessellator; + +import com.mumfrey.worldeditcui.render.RenderColour; import com.mumfrey.worldeditcui.render.LineInfo; import com.mumfrey.worldeditcui.render.points.PointCube; import com.mumfrey.worldeditcui.util.Vector3; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.BufferBuilder; -import static com.mumfrey.liteloader.gl.GL.*; - /** * Draws an ellipsoid shape around a centre point. * * @author yetanotherx + * @author Adam Mummery-Smith */ -public class RenderEllipsoid +public class RenderEllipsoid extends RenderRegion { - - protected LineColour colour; protected PointCube centre; protected Vector3 radii; protected final static double twoPi = Math.PI * 2; @@ -25,9 +25,9 @@ public class RenderEllipsoid protected double centreY; protected double centreZ; - public RenderEllipsoid(LineColour colour, PointCube centre, Vector3 radii) + public RenderEllipsoid(RenderColour colour, PointCube centre, Vector3 radii) { - this.colour = colour; + super(colour); this.centre = centre; this.radii = radii; this.centreX = centre.getPoint().getX() + 0.5; @@ -35,6 +35,7 @@ public RenderEllipsoid(LineColour colour, PointCube centre, Vector3 radii) this.centreZ = centre.getPoint().getZ() + 0.5; } + @Override public void render(Vector3 cameraPos) { glPushMatrix(); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderRegion.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderRegion.java new file mode 100644 index 00000000..7fa835de --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderRegion.java @@ -0,0 +1,34 @@ +package com.mumfrey.worldeditcui.render.shapes; + +import com.mumfrey.worldeditcui.render.RenderColour; +import com.mumfrey.worldeditcui.util.Observable; +import com.mumfrey.worldeditcui.util.Observer; +import com.mumfrey.worldeditcui.util.Vector3; + +/** + * Base class for region renderers + * + * @author Adam Mummery-Smith + */ +public abstract class RenderRegion implements Observer +{ + protected RenderColour colour; + + protected RenderRegion(RenderColour colour) + { + this.colour = colour; + } + + public final void setColour(RenderColour colour) + { + this.colour = colour; + } + + public abstract void render(Vector3 cameraPos); + + @Override + public void notifyChanged(Observable source) + { + + } +} diff --git a/java/com/mumfrey/worldeditcui/util/BoundingBox.java b/java/com/mumfrey/worldeditcui/util/BoundingBox.java index eb42c3dc..36f99123 100644 --- a/java/com/mumfrey/worldeditcui/util/BoundingBox.java +++ b/java/com/mumfrey/worldeditcui/util/BoundingBox.java @@ -1,26 +1,37 @@ package com.mumfrey.worldeditcui.util; import com.mumfrey.worldeditcui.render.points.PointCube; +import com.mumfrey.worldeditcui.render.shapes.RenderRegion; - -public class BoundingBox +/** + * @author Adam Mummery-Smith + */ +public class BoundingBox extends Observable implements Observer { private static final double OFF = 0.02; private static final Vector3 MIN_VEC = new Vector3(BoundingBox.OFF, BoundingBox.OFF, BoundingBox.OFF); private static final Vector3 MAX_VEC = new Vector3(BoundingBox.OFF + 1, BoundingBox.OFF + 1, BoundingBox.OFF + 1); - private final Vector3 min, max; + private final PointCube pc1, pc2; + private Vector3 min, max; - public BoundingBox(PointCube p1, PointCube p2) + public BoundingBox(PointCube pc1, PointCube pc2) { - this(p1.getPoint(), p2.getPoint()); - } - - public BoundingBox(Vector3 p1, Vector3 p2) - { - this.min = new Vector3(Math.min(p1.getX(), p2.getX()), Math.min(p1.getY(), p2.getY()), Math.min(p1.getZ(), p2.getZ())).subtract(BoundingBox.MIN_VEC); - this.max = new Vector3(Math.max(p1.getX(), p2.getX()), Math.max(p1.getY(), p2.getY()), Math.max(p1.getZ(), p2.getZ())).add(BoundingBox.MAX_VEC); + this.pc1 = pc1; + this.pc2 = pc2; + + this.update(); + + if (this.pc1.isDynamic()) + { + this.pc1.addObserver(this); + } + + if (this.pc2.isDynamic()) + { + this.pc2.addObserver(this); + } } public Vector3 getMin() @@ -32,4 +43,27 @@ public Vector3 getMax() { return this.max; } + + public boolean isDynamic() + { + return this.pc1.isDynamic() || this.pc2.isDynamic(); + } + + @Override + public void notifyChanged(Observable source) + { + if (source == this.pc1 || source == this.pc2) + { + this.update(); + this.notifyObservers(); + } + } + + private void update() + { + Vector3 p1 = this.pc1.getPoint(); + Vector3 p2 = this.pc2.getPoint(); + this.min = new Vector3(Math.min(p1.getX(), p2.getX()), Math.min(p1.getY(), p2.getY()), Math.min(p1.getZ(), p2.getZ())).subtract(BoundingBox.MIN_VEC); + this.max = new Vector3(Math.max(p1.getX(), p2.getX()), Math.max(p1.getY(), p2.getY()), Math.max(p1.getZ(), p2.getZ())).add(BoundingBox.MAX_VEC); + } } diff --git a/java/com/mumfrey/worldeditcui/util/Observable.java b/java/com/mumfrey/worldeditcui/util/Observable.java new file mode 100644 index 00000000..88b8659d --- /dev/null +++ b/java/com/mumfrey/worldeditcui/util/Observable.java @@ -0,0 +1,36 @@ +package com.mumfrey.worldeditcui.util; + +import java.util.ArrayList; +import java.util.List; + +/** + * Observable object + * + * @param observer type + * @author Adam Mummery-Smith + */ +public abstract class Observable +{ + protected List observers; + + public void addObserver(TObserver observer) + { + if (this.observers == null) + { + this.observers = new ArrayList(); + } + + this.observers.add(observer); + } + + protected void notifyObservers() + { + if (this.observers != null) + { + for (TObserver observer : this.observers) + { + observer.notifyChanged(this); + } + } + } +} diff --git a/java/com/mumfrey/worldeditcui/util/Observer.java b/java/com/mumfrey/worldeditcui/util/Observer.java new file mode 100644 index 00000000..68f00b39 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/util/Observer.java @@ -0,0 +1,11 @@ +package com.mumfrey.worldeditcui.util; + +/** + * Observer for {@link Observable} + * + * @author Adam Mummery-Smith + */ +public interface Observer +{ + public abstract void notifyChanged(Observable source); +} From c42c94e9c5b907fa8ecd2071968a7d63bb2b18f8 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Tue, 25 Jul 2017 22:43:50 +0100 Subject: [PATCH 37/51] Do version as SNAPSHOT --- gradle.properties | 2 +- java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index a33f8906..df05573d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ name=WorldEditCUI -version=1.12_01 +version=1.12.1-SNAPSHOT mcVersion=1.12 mcMappings=snapshot_20170627 targetVersion=1.12.r1 \ No newline at end of file diff --git a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java index f8dc461c..00e6fc0e 100644 --- a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java @@ -234,7 +234,7 @@ public String getName() @Override public String getVersion() { - return "1.12_01"; + return "1.12.1-SNAPSHOT"; } @Override From 9db195667006207b6e34c536581971544203d8a8 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Wed, 26 Jul 2017 02:46:15 +0100 Subject: [PATCH 38/51] Change "interactive" position setting behaviour to raytrace --- .../mumfrey/worldeditcui/WorldEditCUI.java | 6 +-- .../event/cui/CUIEventPoint3D.java | 8 +++- .../listeners/CUIListenerWorldRender.java | 2 +- .../worldeditcui/render/points/PointCube.java | 2 +- .../render/points/PointCubeTracking.java | 40 ++++++++++--------- .../render/region/CuboidRegion.java | 19 ++++----- .../render/region/CylinderRegion.java | 2 +- .../render/region/EllipsoidRegion.java | 2 +- .../render/region/PolygonRegion.java | 2 +- .../render/region/PolyhedronRegion.java | 2 +- .../worldeditcui/render/region/Region.java | 5 ++- 11 files changed, 48 insertions(+), 42 deletions(-) diff --git a/java/com/mumfrey/worldeditcui/WorldEditCUI.java b/java/com/mumfrey/worldeditcui/WorldEditCUI.java index 5482f1f1..27d1f7b4 100644 --- a/java/com/mumfrey/worldeditcui/WorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/WorldEditCUI.java @@ -119,16 +119,16 @@ public void setSelection(UUID id, Region region) this.activeRegion = region; } - public void renderSelections(Vector3 cameraPos) + public void renderSelections(Vector3 cameraPos, float partialTicks) { if (this.selection != null) { - this.selection.render(cameraPos); + this.selection.render(cameraPos, partialTicks); } for (Region region : this.regions.values()) { - region.render(cameraPos); + region.render(cameraPos, partialTicks); } } } diff --git a/java/com/mumfrey/worldeditcui/event/cui/CUIEventPoint3D.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventPoint3D.java index e9c776cb..a69c5870 100644 --- a/java/com/mumfrey/worldeditcui/event/cui/CUIEventPoint3D.java +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventPoint3D.java @@ -4,6 +4,8 @@ import com.mumfrey.worldeditcui.event.CUIEventArgs; import com.mumfrey.worldeditcui.event.CUIEventType; import com.mumfrey.worldeditcui.render.region.Region; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.Entity; /** * Called when point event is received @@ -39,7 +41,11 @@ public String raise() if (this.multi && "~".equals(this.getString(1)) && "~".equals(this.getString(2)) && "~".equals(this.getString(3))) { - selection.setCuboidVertexLatch(id); + Minecraft mc = Minecraft.getMinecraft(); + Entity entity = mc.getRenderViewEntity(); + double hitDistance = mc.playerController.getBlockReachDistance(); + + selection.setCuboidVertexLatch(id, entity, Math.min(Math.max(this.getDouble(4), hitDistance), 256.0)); this.controller.getDebugger().debug("Setting vertex latch #" + id); return null; } diff --git a/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerWorldRender.java b/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerWorldRender.java index d984e267..1e1f3b44 100644 --- a/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerWorldRender.java +++ b/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerWorldRender.java @@ -46,7 +46,7 @@ public void onRender(float partialTicks) { Vector3 cameraPos = new Vector3(this.minecraft.getRenderViewEntity(), partialTicks); glColor4f(1.0F, 1.0F, 1.0F, 0.5F); - this.controller.renderSelections(cameraPos); + this.controller.renderSelections(cameraPos, partialTicks); } catch (Exception e) { diff --git a/java/com/mumfrey/worldeditcui/render/points/PointCube.java b/java/com/mumfrey/worldeditcui/render/points/PointCube.java index 862bf35b..0191381b 100644 --- a/java/com/mumfrey/worldeditcui/render/points/PointCube.java +++ b/java/com/mumfrey/worldeditcui/render/points/PointCube.java @@ -61,7 +61,7 @@ public void render(Vector3 cameraPos) this.box.render(cameraPos); } - public void updatePoint() + public void updatePoint(float partialTicks) { } diff --git a/java/com/mumfrey/worldeditcui/render/points/PointCubeTracking.java b/java/com/mumfrey/worldeditcui/render/points/PointCubeTracking.java index a0df672e..07a6c609 100644 --- a/java/com/mumfrey/worldeditcui/render/points/PointCubeTracking.java +++ b/java/com/mumfrey/worldeditcui/render/points/PointCubeTracking.java @@ -1,9 +1,9 @@ package com.mumfrey.worldeditcui.render.points; -import net.minecraft.entity.Entity; -import net.minecraft.util.math.MathHelper; - +import com.mumfrey.liteloader.util.EntityUtilities; import com.mumfrey.worldeditcui.util.Vector3; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.BlockPos; /** * A PointCube which tracks the specified entity location @@ -13,12 +13,14 @@ public class PointCubeTracking extends PointCube { private final Entity entity; + private final double traceDistance; private int lastX, lastY, lastZ; - public PointCubeTracking(Entity entity) + public PointCubeTracking(Entity entity, double traceDistance) { super(0, 0, 0); this.entity = entity; + this.traceDistance = traceDistance; } @Override @@ -30,25 +32,25 @@ public boolean isDynamic() @Override public Vector3 getPoint() { - this.updatePoint(); return this.point; } @Override - public void updatePoint() + public void updatePoint(float partialTicks) { - int x = MathHelper.floor(this.entity.posX); - int y = MathHelper.floor(this.entity.posY + this.entity.getEyeHeight()); - int z = MathHelper.floor(this.entity.posZ); - - if (this.lastX != x || this.lastY != y || this.lastZ != z) - { - this.lastX = x; - this.lastY = y; - this.lastZ = z; - this.point = new Vector3(x, y, z); - this.box.setPosition(this.point.subtract(PointCube.MIN_VEC), this.point.add(PointCube.MAX_VEC)); - this.notifyObservers(); - } + BlockPos pos = EntityUtilities.rayTraceFromEntity(this.entity, this.traceDistance, partialTicks, false).getBlockPos(); + int x = pos.getX(); + int y = pos.getY(); + int z = pos.getZ(); + + if (this.lastX != x || this.lastY != y || this.lastZ != z) + { + this.lastX = x; + this.lastY = y; + this.lastZ = z; + this.point = new Vector3(x, y, z); + this.box.setPosition(this.point.subtract(PointCube.MIN_VEC), this.point.add(PointCube.MAX_VEC)); + this.notifyObservers(); + } } } diff --git a/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java b/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java index 119156d0..efe88a41 100644 --- a/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java @@ -1,8 +1,5 @@ package com.mumfrey.worldeditcui.render.region; -import net.minecraft.client.Minecraft; -import net.minecraft.entity.Entity; - import com.mumfrey.worldeditcui.WorldEditCUI; import com.mumfrey.worldeditcui.render.ConfiguredColour; import com.mumfrey.worldeditcui.render.points.PointCube; @@ -11,6 +8,7 @@ import com.mumfrey.worldeditcui.render.shapes.Render3DGrid; import com.mumfrey.worldeditcui.util.BoundingBox; import com.mumfrey.worldeditcui.util.Vector3; +import net.minecraft.entity.Entity; /** * Main controller for a cuboid-type region @@ -34,12 +32,12 @@ public CuboidRegion(WorldEditCUI controller) } @Override - public void render(Vector3 cameraPos) + public void render(Vector3 cameraPos, float partialTicks) { if (this.points[0] != null && this.points[1] != null) { - this.points[0].updatePoint(); - this.points[1].updatePoint(); + this.points[0].updatePoint(partialTicks); + this.points[1].updatePoint(partialTicks); this.grid.render(cameraPos); this.box.render(cameraPos); @@ -49,12 +47,12 @@ public void render(Vector3 cameraPos) } else if (this.points[0] != null) { - this.points[0].updatePoint(); + this.points[0].updatePoint(partialTicks); this.points[0].render(cameraPos); } else if (this.points[1] != null) { - this.points[1].updatePoint(); + this.points[1].updatePoint(partialTicks); this.points[1].render(cameraPos); } } @@ -81,12 +79,11 @@ public void setCuboidPoint(int id, double x, double y, double z) } @Override - public void setCuboidVertexLatch(int id) + public void setCuboidVertexLatch(int id, Entity entity, double traceDistance) { if (id < 2) { - Entity renderViewEntity = Minecraft.getMinecraft().getRenderViewEntity(); - this.points[id] = new PointCubeTracking(renderViewEntity).setColour(this.colours[2]); + this.points[id] = new PointCubeTracking(entity, traceDistance).setColour(this.colours[2]); } this.updateBounds(); diff --git a/java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java b/java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java index 8ff5dd2a..9deaefe4 100644 --- a/java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java @@ -30,7 +30,7 @@ public CylinderRegion(WorldEditCUI controller) } @Override - public void render(Vector3 cameraPos) + public void render(Vector3 cameraPos, float partialTicks) { if (this.centre != null) { diff --git a/java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java b/java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java index da9ef816..8b4a0f10 100644 --- a/java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java @@ -26,7 +26,7 @@ public EllipsoidRegion(WorldEditCUI controller) } @Override - public void render(Vector3 cameraPos) + public void render(Vector3 cameraPos, float partialTicks) { if (this.centre != null && this.radii != null) { diff --git a/java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java b/java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java index dcf92518..4d4813cc 100644 --- a/java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java @@ -31,7 +31,7 @@ public PolygonRegion(WorldEditCUI controller) } @Override - public void render(Vector3 cameraPos) + public void render(Vector3 cameraPos, float partialTicks) { if (this.points.size() < 1) { diff --git a/java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java b/java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java index 76136592..348fe18f 100644 --- a/java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java @@ -30,7 +30,7 @@ public PolyhedronRegion(WorldEditCUI controller) } @Override - public void render(Vector3 cameraPos) + public void render(Vector3 cameraPos, float partialTicks) { for (PointCube vertex : this.vertices) { diff --git a/java/com/mumfrey/worldeditcui/render/region/Region.java b/java/com/mumfrey/worldeditcui/render/region/Region.java index 9a5bbeaa..9e41c3a0 100644 --- a/java/com/mumfrey/worldeditcui/render/region/Region.java +++ b/java/com/mumfrey/worldeditcui/render/region/Region.java @@ -5,6 +5,7 @@ import com.mumfrey.worldeditcui.exceptions.InvalidSelectionTypeException; import com.mumfrey.worldeditcui.render.RenderColour; import com.mumfrey.worldeditcui.util.Vector3; +import net.minecraft.entity.Entity; /** * Base region storage class. Provides @@ -32,7 +33,7 @@ public void initialise() { } - public abstract void render(Vector3 cameraPos); + public abstract void render(Vector3 cameraPos, float partialTicks); public RenderColour[] getDefaultColours() { @@ -62,7 +63,7 @@ public void setCuboidPoint(int id, double x, double y, double z) throw new InvalidSelectionTypeException(this.getType().getName(), "setCuboidPoint"); } - public void setCuboidVertexLatch(int id) + public void setCuboidVertexLatch(int id, Entity entity, double traceDistance) { throw new InvalidSelectionTypeException(this.getType().getName(), "setCuboidVertexLatch"); } From a2a5e9382fe4603c7fc1857228b6dd353943bb2d Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Thu, 27 Jul 2017 01:33:02 +0100 Subject: [PATCH 39/51] Cull grid on all axes, closes #17 --- .../worldeditcui/render/shapes/Render3DGrid.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java index 7f969ba3..9a7bd6cf 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java @@ -117,9 +117,8 @@ public void render(Vector3 cameraPos) buf.begin(GL_LINES, VF_POSITION); tempColour.prepareColour(); - for (double yoff = 0; yoff + y1 <= y2; yoff += this.spacing) + for (double y = Math.max(y1, -cullAt); y <= y2 && y <= cullAt; y += this.spacing) { - double y = y1 + yoff; buf.pos(x1, y, z2).endVertex(); buf.pos(x2, y, z2).endVertex(); buf.pos(x1, y, z1).endVertex(); @@ -130,12 +129,9 @@ public void render(Vector3 cameraPos) buf.pos(x2, y, z2).endVertex(); } - for (double xoff = 0; xoff + x1 <= x2; xoff += this.spacing) + for (double x = Math.max(x1, -cullAt); x <= x2 && x <= cullAt; x += this.spacing) { - double x = x1 + xoff; // boolean major = xoff % 10 == 0; - if (x < -cullAt) continue; - if (x > cullAt) break; buf.pos(x, y1, z1).endVertex(); buf.pos(x, y2, z1).endVertex(); buf.pos(x, y1, z2).endVertex(); @@ -146,12 +142,9 @@ public void render(Vector3 cameraPos) buf.pos(x, y1, z2).endVertex(); } - for (double zoff = 0; zoff + z1 <= z2; zoff += this.spacing) + for (double z = Math.max(z1, -cullAt); z <= z2 && z <= cullAt; z += this.spacing) { - double z = z1 + zoff; // boolean major = zoff % 10 == 0; - if (z < -cullAt) continue; - if (z > cullAt) break; buf.pos(x1, y1, z).endVertex(); buf.pos(x2, y1, z).endVertex(); buf.pos(x1, y2, z).endVertex(); From 6476b13bfe39a07da219e38da7498ea9920029c2 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Mon, 31 Jul 2017 15:42:46 +0100 Subject: [PATCH 40/51] Add draw style support and "cull" option to grid message, updates #16 --- .../mumfrey/worldeditcui/config/Colour.java | 4 +- .../worldeditcui/event/CUIEventType.java | 2 +- .../event/cui/CUIEventColour.java | 16 +-- .../worldeditcui/event/cui/CUIEventGrid.java | 9 ++ .../gui/controls/GuiColourButton.java | 6 +- .../gui/controls/GuiColourPicker.java | 6 +- .../worldeditcui/gui/controls/GuiControl.java | 18 +-- .../worldeditcui/render/ConfiguredColour.java | 104 ++++++++++++------ .../worldeditcui/render/CustomColour.java | 41 ------- .../worldeditcui/render/CustomStyle.java | 52 +++++++++ .../mumfrey/worldeditcui/render/LineInfo.java | 65 ----------- .../worldeditcui/render/LineStyle.java | 58 ++++++++++ .../worldeditcui/render/RenderColour.java | 18 --- .../worldeditcui/render/RenderStyle.java | 57 ++++++++++ .../worldeditcui/render/points/PointCube.java | 16 +-- .../render/points/PointRectangle.java | 16 +-- .../render/region/CuboidRegion.java | 24 ++-- .../render/region/CylinderRegion.java | 20 ++-- .../render/region/EllipsoidRegion.java | 12 +- .../render/region/PolygonRegion.java | 16 +-- .../render/region/PolyhedronRegion.java | 12 +- .../worldeditcui/render/region/Region.java | 46 +++++--- .../render/shapes/Render2DBox.java | 17 +-- .../render/shapes/Render2DGrid.java | 17 +-- .../render/shapes/Render3DBox.java | 25 +++-- .../render/shapes/Render3DGrid.java | 39 ++++--- .../render/shapes/Render3DPolygon.java | 17 +-- .../render/shapes/RenderCylinderBox.java | 17 +-- .../render/shapes/RenderCylinderCircles.java | 17 +-- .../render/shapes/RenderCylinderGrid.java | 19 ++-- .../render/shapes/RenderEllipsoid.java | 58 +++++----- .../render/shapes/RenderRegion.java | 12 +- 32 files changed, 495 insertions(+), 361 deletions(-) delete mode 100644 java/com/mumfrey/worldeditcui/render/CustomColour.java create mode 100644 java/com/mumfrey/worldeditcui/render/CustomStyle.java delete mode 100644 java/com/mumfrey/worldeditcui/render/LineInfo.java create mode 100644 java/com/mumfrey/worldeditcui/render/LineStyle.java delete mode 100644 java/com/mumfrey/worldeditcui/render/RenderColour.java create mode 100644 java/com/mumfrey/worldeditcui/render/RenderStyle.java diff --git a/java/com/mumfrey/worldeditcui/config/Colour.java b/java/com/mumfrey/worldeditcui/config/Colour.java index a5008bcf..9e56d8e0 100644 --- a/java/com/mumfrey/worldeditcui/config/Colour.java +++ b/java/com/mumfrey/worldeditcui/config/Colour.java @@ -47,10 +47,10 @@ public static Colour firstOrDefault(Colour colour, String defaultColour) } /** - * Validates a user-entered colour code. Ensures that colour is not null, it + * Validates a user-entered style code. Ensures that style is not null, it * starts with #, that it has all 6 digits, and that each hex code is valid. * - * @param colour + * @param style * @param def * @return */ diff --git a/java/com/mumfrey/worldeditcui/event/CUIEventType.java b/java/com/mumfrey/worldeditcui/event/CUIEventType.java index c70ba398..c0d114b1 100644 --- a/java/com/mumfrey/worldeditcui/event/CUIEventType.java +++ b/java/com/mumfrey/worldeditcui/event/CUIEventType.java @@ -28,7 +28,7 @@ public enum CUIEventType UPDATE (CUIEventUpdate.class, "u", 1 ), POLYGON (CUIEventPolygon.class, "poly", 3, 99), COLOUR (CUIEventColour.class, "col", 4 ), - GRID (CUIEventGrid.class, "grid", 1 ); + GRID (CUIEventGrid.class, "grid", 1, 2 ); private final Class eventClass; private final String key; diff --git a/java/com/mumfrey/worldeditcui/event/cui/CUIEventColour.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventColour.java index e06fb58d..025f7b02 100644 --- a/java/com/mumfrey/worldeditcui/event/cui/CUIEventColour.java +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventColour.java @@ -4,12 +4,12 @@ import com.mumfrey.worldeditcui.event.CUIEvent; import com.mumfrey.worldeditcui.event.CUIEventArgs; import com.mumfrey.worldeditcui.event.CUIEventType; -import com.mumfrey.worldeditcui.render.CustomColour; -import com.mumfrey.worldeditcui.render.RenderColour; +import com.mumfrey.worldeditcui.render.CustomStyle; +import com.mumfrey.worldeditcui.render.RenderStyle; import com.mumfrey.worldeditcui.render.region.Region; /** - * Called when colour event is received + * Called when style event is received * * @author Adam Mummery-Smith */ @@ -47,21 +47,21 @@ public String raise() return null; } - RenderColour[] defaultColours = selection.getDefaultColours(); - RenderColour[] colours = new RenderColour[defaultColours.length]; + RenderStyle[] defaultStyles = selection.getDefaultStyles(); + RenderStyle[] styles = new RenderStyle[defaultStyles.length]; - for (int i = 0; i < defaultColours.length; i++) + for (int i = 0; i < defaultStyles.length; i++) { String str = this.getString(i); if (!str.startsWith("#")) { str = "#" + str; } - colours[i] = new CustomColour(Colour.parse(str, defaultColours[i].getColour())); + styles[i] = new CustomStyle(Colour.parse(str, defaultStyles[i].getColour())); } - selection.setColours(colours); + selection.setStyles(styles); return null; } } diff --git a/java/com/mumfrey/worldeditcui/event/cui/CUIEventGrid.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventGrid.java index 40e0a6c0..8abe9b47 100644 --- a/java/com/mumfrey/worldeditcui/event/cui/CUIEventGrid.java +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventGrid.java @@ -3,6 +3,7 @@ import com.mumfrey.worldeditcui.event.CUIEvent; import com.mumfrey.worldeditcui.event.CUIEventArgs; import com.mumfrey.worldeditcui.event.CUIEventType; +import com.mumfrey.worldeditcui.render.RenderStyle.RenderType; import com.mumfrey.worldeditcui.render.region.Region; /** @@ -45,6 +46,14 @@ public String raise() } selection.setGridSpacing(this.getDouble(0)); + + RenderType renderType = RenderType.ANY; + if (this.params.length > 1 && "cull".equalsIgnoreCase(this.getString(1))) + { + renderType = RenderType.VISIBLE; + } + + selection.setRenderType(renderType); return null; } } diff --git a/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java index c6b67770..1fe84a7d 100644 --- a/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java +++ b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java @@ -7,14 +7,14 @@ import net.minecraft.client.Minecraft; /** - * Colour picker button control, spawns a colour picker when clicked + * Colour picker button control, spawns a style picker when clicked * * @author Adam Mummery-Smith */ public class GuiColourButton extends GuiControl { /** - * Picker active colour + * Picker active style */ private int colour = 0xFF000000; @@ -135,7 +135,7 @@ public boolean mousePressed(Minecraft minecraft, int mouseX, int mouseY) int xPos = Math.min(this.x + this.width, GuiControl.lastScreenWidth - 233); int yPos = Math.min(this.y, GuiControl.lastScreenHeight - 175); - this.picker = new GuiColourPicker(minecraft, 1, xPos, yPos, this.colour, "Choose colour"); + this.picker = new GuiColourPicker(minecraft, 1, xPos, yPos, this.colour, "Choose style"); this.pickerClicked = false; } diff --git a/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java index f040298a..8fdd4d3e 100644 --- a/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java +++ b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java @@ -30,7 +30,7 @@ public class GuiColourPicker extends GuiControl /** * HSB values from Colour.RGBtoHSB, combined with opacity this is the authoritative version of the - * colour we are editing + * style we are editing */ private float[] hsb; @@ -125,7 +125,7 @@ protected void drawControl(Minecraft minecraft, int mouseX, int mouseY, float pa int bPos = this.y + 10 + (128 - (int)(128F * this.hsb[B])); int aPos = this.y + 10 + ((256 - ((this.opacity >> 24) & 0xFF)) / 2); - // Calculate B colour + // Calculate B style int brightness = Color.HSBtoRGB(this.hsb[H], this.hsb[S], 1.0F) | 0xFF000000; // Draw backgrounds @@ -135,7 +135,7 @@ protected void drawControl(Minecraft minecraft, int mouseX, int mouseY, float pa drawRect(this.x + 162, this.y + 9, this.x + 179, this.y + 139, 0xFFA0A0A0); // A background drawRect(this.x + 187, this.y + 105, this.x + 221, this.y + 139, 0xFFA0A0A0); // Preview background - // Draw colour picker + // Draw style picker this.mc.getTextureManager().bindTexture(GuiColourPicker.COLOURPICKER_PICKER); glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.drawTexturedModalRect(this.x + 10, this.y + 10, this.x + 138, this.y + 138, 0, 0, 256, 256); diff --git a/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java b/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java index 2bb07215..a6fbf9a5 100644 --- a/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java +++ b/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java @@ -161,14 +161,14 @@ public boolean isDoubleClicked(boolean resetDoubleClicked) } /** - * Draws a line between two points with the specified width and colour + * Draws a line between two points with the specified width and style * * @param x1 Origin x coordinate * @param y1 Origin y coordinate * @param x2 End x coordinate * @param y2 End y coordinate * @param width Line width in pixels - * @param colour Line colour + * @param style Line style */ public static void drawLine(int x1, int y1, int x2, int y2, int width, int colour) { @@ -183,7 +183,7 @@ public static void drawLine(int x1, int y1, int x2, int y2, int width, int colou * @param x2 End x position * @param y2 End y position * @param width Line width - * @param colour Line colour + * @param style Line style */ @SuppressWarnings("cast") public static void drawNativeLine(float x1, float y1, float x2, float y2, float width, int colour) @@ -211,7 +211,7 @@ public static void drawNativeLine(float x1, float y1, float x2, float y2, float } /** - * Draws an arrow between two points with the specified width and colour + * Draws an arrow between two points with the specified width and style * * @param x1 Origin x coordinate * @param y1 Origin y coordinate @@ -219,7 +219,7 @@ public static void drawNativeLine(float x1, float y1, float x2, float y2, float * @param y2 End y coordinate * @param width Line width in pixels * @param arrowHeadSize Size of the arrow head - * @param colour Colour + * @param style Colour */ public static void drawArrow(int x1, int y1, int x2, int y2, int z, int width, int arrowHeadSize, int colour) { @@ -234,7 +234,7 @@ public static void drawArrow(int x1, int y1, int x2, int y2, int z, int width, i * @param x2 End x coordinate * @param y2 End y coordinate * @param width Line width in pixels - * @param colour Colour + * @param style Colour * @param arrowHead True to draw an arrow, otherwise draws a line * @param arrowHeadSize Size of the arrow head */ @@ -256,7 +256,7 @@ public static void drawArrow(int x1, int y1, int x2, int y2, int z, int width, i y1 = (int)(width * -0.5); y2 = y1 + width; - // Calc colour components + // Calc style components float f = (float)(colour >> 24 & 0xff) / 255F; float f1 = (float)(colour >> 16 & 0xff) / 255F; float f2 = (float)(colour >> 8 & 0xff) / 255F; @@ -459,7 +459,7 @@ public void drawTessellatedModalBorderRect(int x, int y, int x2, int y2, int u, * @param x * @param y * @param width - * @param colour + * @param style */ public static void drawStringWithEllipsis(FontRenderer fontrenderer, String s, int x, int y, int width, int colour) { @@ -555,7 +555,7 @@ protected void drawRotText(FontRenderer fontRenderer, String text, int xPosition * @param mouseY * @param screenWidth * @param screenHeight - * @param colour + * @param style * @param backgroundColour */ protected void drawTooltip(FontRenderer fontRenderer, String tooltipText, int mouseX, int mouseY, int screenWidth, int screenHeight, int colour, int backgroundColour) diff --git a/java/com/mumfrey/worldeditcui/render/ConfiguredColour.java b/java/com/mumfrey/worldeditcui/render/ConfiguredColour.java index 373f6d2f..c06ba233 100644 --- a/java/com/mumfrey/worldeditcui/render/ConfiguredColour.java +++ b/java/com/mumfrey/worldeditcui/render/ConfiguredColour.java @@ -1,12 +1,12 @@ package com.mumfrey.worldeditcui.render; -import com.mumfrey.worldeditcui.config.Colour; - import net.minecraft.client.resources.I18n; -import static com.mumfrey.liteloader.gl.GL.*; + +import com.mumfrey.worldeditcui.config.Colour; +import com.mumfrey.worldeditcui.render.RenderStyle.RenderType; /** - * Stores colour data for each type of line. + * Stores style data for each type of line. * * Each line has a normal line, and a hidden line. * The normal line has an alpha value of 0.8f, and @@ -17,25 +17,59 @@ * @author lahwran * @author Adam Mummery-Smith */ -public enum ConfiguredColour implements RenderColour +public enum ConfiguredColour // implements RenderStyle { - CUBOIDBOX ("colour.cuboidedge", new Colour("#CC3333CC")), - CUBOIDGRID ("colour.cuboidgrid", new Colour("#CC4C4CCC")), - CUBOIDPOINT1 ("colour.cuboidpoint1", new Colour("#33CC33CC")), - CUBOIDPOINT2 ("colour.cuboidpoint2", new Colour("#3333CCCC")), - POLYGRID ("colour.polygrid", new Colour("#CC3333CC")), - POLYBOX ("colour.polyedge", new Colour("#CC4C4CCC")), - POLYPOINT ("colour.polypoint", new Colour("#33CCCCCC")), - ELLIPSOIDGRID ("colour.ellipsoidgrid", new Colour("#CC4C4CCC")), - ELLIPSOIDCENTRE("colour.ellipsoidpoint", new Colour("#CCCC33CC")), - CYLINDERGRID ("colour.cylindergrid", new Colour("#CC3333CC")), - CYLINDERBOX ("colour.cylinderedge", new Colour("#CC4C4CCC")), - CYLINDERCENTRE ("colour.cylinderpoint", new Colour("#CC33CCCC")); + CUBOIDBOX ("style.cuboidedge", new Colour("#CC3333CC")), + CUBOIDGRID ("style.cuboidgrid", new Colour("#CC4C4CCC")), + CUBOIDPOINT1 ("style.cuboidpoint1", new Colour("#33CC33CC")), + CUBOIDPOINT2 ("style.cuboidpoint2", new Colour("#3333CCCC")), + POLYGRID ("style.polygrid", new Colour("#CC3333CC")), + POLYBOX ("style.polyedge", new Colour("#CC4C4CCC")), + POLYPOINT ("style.polypoint", new Colour("#33CCCCCC")), + ELLIPSOIDGRID ("style.ellipsoidgrid", new Colour("#CC4C4CCC")), + ELLIPSOIDCENTRE("style.ellipsoidpoint", new Colour("#CCCC33CC")), + CYLINDERGRID ("style.cylindergrid", new Colour("#CC3333CC")), + CYLINDERBOX ("style.cylinderedge", new Colour("#CC4C4CCC")), + CYLINDERCENTRE ("style.cylinderpoint", new Colour("#CC33CCCC")); + + class Style implements RenderStyle + { + private RenderType renderType = RenderType.ANY; + + @Override + public void setRenderType(RenderType renderType) + { + this.renderType = renderType; + } + + @Override + public RenderType getRenderType() + { + return this.renderType; + } + + @Override + public void setColour(Colour colour) + { + } + + @Override + public Colour getColour() + { + return ConfiguredColour.this.getColour(); + } + + @Override + public LineStyle[] getLines() + { + return ConfiguredColour.this.getLines(); + } + } private String displayName; private Colour defaultColour, colour; - private LineInfo normal, hidden; - private LineInfo[] lines; + private LineStyle normal, hidden; + private LineStyle[] lines; private ConfiguredColour(String displayName, Colour colour) { @@ -50,35 +84,37 @@ public String getDisplayName() return I18n.format(this.displayName); } - @Override + public RenderStyle style() + { + return new Style(); + } + + public void setColour(Colour colour) + { + this.colour = colour; + this.updateLines(); + } + public Colour getColour() { return this.colour; } - public LineInfo getHidden() + public LineStyle getHidden() { return this.hidden; } - public LineInfo getNormal() + public LineStyle getNormal() { return this.normal; } - @Override - public LineInfo[] getColours() + public LineStyle[] getLines() { return this.lines; } - @Override - public void setColour(Colour colour) - { - this.colour = colour; - this.updateLines(); - } - public void setDefaultColour() { this.colour.copyFrom(this.defaultColour); @@ -99,8 +135,8 @@ public int getColourIntARGB() private void updateLines() { - this.normal = new LineInfo(3.0f, this.colour.red(), this.colour.green(), this.colour.blue(), this.colour.alpha(), GL_LESS); - this.hidden = new LineInfo(3.0f, this.colour.red() * 0.75F, this.colour.green() * 0.75F, this.colour.blue() * 0.75F, this.colour.alpha() * 0.25F, GL_GEQUAL); - this.lines = new LineInfo[] { this.hidden, this.normal }; + this.normal = new LineStyle(RenderType.VISIBLE, 3.0f, this.colour.red(), this.colour.green(), this.colour.blue(), this.colour.alpha()); + this.hidden = new LineStyle(RenderType.HIDDEN, 3.0f, this.colour.red() * 0.75F, this.colour.green() * 0.75F, this.colour.blue() * 0.75F, this.colour.alpha() * 0.25F); + this.lines = new LineStyle[] { this.hidden, this.normal }; } } diff --git a/java/com/mumfrey/worldeditcui/render/CustomColour.java b/java/com/mumfrey/worldeditcui/render/CustomColour.java deleted file mode 100644 index 8a908817..00000000 --- a/java/com/mumfrey/worldeditcui/render/CustomColour.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.mumfrey.worldeditcui.render; - -import static com.mumfrey.liteloader.gl.GL.*; - -import com.mumfrey.worldeditcui.config.Colour; - -/** - * Server-defined colour for multi selections - * - * @author Adam Mummery-Smith - */ -public class CustomColour implements RenderColour -{ - private Colour colour; - private final LineInfo[] lines = new LineInfo[2]; - - public CustomColour(Colour colour) - { - this.setColour(colour); - } - - @Override - public void setColour(Colour colour) - { - this.colour = colour; - this.lines[0] = new LineInfo(3.0f, colour.red() * 0.75F, colour.green() * 0.75F, colour.blue() * 0.75F, colour.alpha() * 0.25F, GL_GEQUAL); - this.lines[1] = new LineInfo(3.0f, colour.red(), colour.green(), colour.blue(), colour.alpha(), GL_LESS); - } - - @Override - public Colour getColour() - { - return this.colour; - } - - @Override - public LineInfo[] getColours() - { - return this.lines; - } -} diff --git a/java/com/mumfrey/worldeditcui/render/CustomStyle.java b/java/com/mumfrey/worldeditcui/render/CustomStyle.java new file mode 100644 index 00000000..d3a4b55d --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/CustomStyle.java @@ -0,0 +1,52 @@ +package com.mumfrey.worldeditcui.render; + +import com.mumfrey.worldeditcui.config.Colour; + +/** + * Server-defined style for multi selections + * + * @author Adam Mummery-Smith + */ +public class CustomStyle implements RenderStyle +{ + private Colour colour; + private RenderType renderType = RenderType.ANY; + private final LineStyle[] lines = new LineStyle[2]; + + public CustomStyle(Colour colour) + { + this.setColour(colour); + } + + @Override + public void setRenderType(RenderType renderType) + { + this.renderType = renderType; + } + + @Override + public RenderType getRenderType() + { + return this.renderType; + } + + @Override + public void setColour(Colour colour) + { + this.colour = colour; + this.lines[0] = new LineStyle(RenderType.HIDDEN, 3.0f, colour.red() * 0.75F, colour.green() * 0.75F, colour.blue() * 0.75F, colour.alpha() * 0.25F); + this.lines[1] = new LineStyle(RenderType.VISIBLE, 3.0f, colour.red(), colour.green(), colour.blue(), colour.alpha()); + } + + @Override + public Colour getColour() + { + return this.colour; + } + + @Override + public LineStyle[] getLines() + { + return this.lines; + } +} diff --git a/java/com/mumfrey/worldeditcui/render/LineInfo.java b/java/com/mumfrey/worldeditcui/render/LineInfo.java deleted file mode 100644 index a0e6e98e..00000000 --- a/java/com/mumfrey/worldeditcui/render/LineInfo.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.mumfrey.worldeditcui.render; - -import static com.mumfrey.liteloader.gl.GL.*; - -/** - * Stores data about a line that can be rendered - * - * @author lahwran - * @author yetanotherx - * - */ -public class LineInfo -{ - - public float lineWidth; - public float red; - public float green; - public float blue; - public float alpha; - public int depthfunc; - - public LineInfo(float lineWidth, float r, float g, float b, float a, int depthfunc) - { - this.lineWidth = lineWidth; - this.red = r; - this.green = g; - this.blue = b; - this.alpha = a; - this.depthfunc = depthfunc; - } - - public LineInfo(float lineWidth, float r, float g, float b) - { - this(lineWidth, r, g, b, 1.0f, GL_LEQUAL); - } - - public LineInfo(LineInfo orig) - { - this.lineWidth = orig.lineWidth; - this.red = orig.red; - this.green = orig.green; - this.blue = orig.blue; - this.alpha = orig.alpha; - this.depthfunc = orig.depthfunc; - } - - /** - * Sets the lineWidth and depthFunction based on this colour - */ - public void prepareRender() - { - glLineWidth(this.lineWidth); - glDepthFunc(this.depthfunc); - } - - public void prepareColour() - { - glColor4f(this.red, this.green, this.blue, this.alpha); - } - - public void prepareColour(float tint) - { - glColor4f(this.red, this.green, this.blue, this.alpha * tint); - } -} diff --git a/java/com/mumfrey/worldeditcui/render/LineStyle.java b/java/com/mumfrey/worldeditcui/render/LineStyle.java new file mode 100644 index 00000000..b3a21b1a --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/LineStyle.java @@ -0,0 +1,58 @@ +package com.mumfrey.worldeditcui.render; + +import static com.mumfrey.liteloader.gl.GL.*; + +import com.mumfrey.worldeditcui.render.RenderStyle.RenderType; + +/** + * Stores data about a line that can be rendered + * + * @author lahwran + * @author yetanotherx + * @author Adam Mummery-Smith + */ +public class LineStyle +{ + public final float lineWidth, red, green, blue, alpha; + public final RenderType renderType; + + public LineStyle(RenderType renderType, float lineWidth, float red, float green, float blue) + { + this(renderType, lineWidth, red, green, blue, 1.0f); + } + + public LineStyle(RenderType renderType, float lineWidth, float red, float green, float blue, float alpha) + { + this.lineWidth = lineWidth; + this.red = red; + this.green = green; + this.blue = blue; + this.alpha = alpha; + this.renderType = renderType; + } + + /** + * Sets the lineWidth and depthFunction based on this style + */ + public boolean prepare(RenderType renderType) + { + if (this.renderType.matches(renderType)) + { + glLineWidth(this.lineWidth); + glDepthFunc(this.renderType.depthFunc); + return true; + } + + return false; + } + + public void applyColour() + { + glColor4f(this.red, this.green, this.blue, this.alpha); + } + + public void applyColour(float tint) + { + glColor4f(this.red, this.green, this.blue, this.alpha * tint); + } +} diff --git a/java/com/mumfrey/worldeditcui/render/RenderColour.java b/java/com/mumfrey/worldeditcui/render/RenderColour.java deleted file mode 100644 index 5350971c..00000000 --- a/java/com/mumfrey/worldeditcui/render/RenderColour.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.mumfrey.worldeditcui.render; - -import com.mumfrey.worldeditcui.config.Colour; - -/** - * Render colour adapter, can be one of the built-in {@link ConfiguredColour}s or a - * user-defined colour from a custom payload - * - * @author Adam Mummery-Smith - */ -public interface RenderColour -{ - public abstract void setColour(Colour colour); - - public abstract Colour getColour(); - - public abstract LineInfo[] getColours(); -} \ No newline at end of file diff --git a/java/com/mumfrey/worldeditcui/render/RenderStyle.java b/java/com/mumfrey/worldeditcui/render/RenderStyle.java new file mode 100644 index 00000000..e9420daa --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/RenderStyle.java @@ -0,0 +1,57 @@ +package com.mumfrey.worldeditcui.render; + +import static com.mumfrey.liteloader.gl.GL.*; + +import com.mumfrey.worldeditcui.config.Colour; + +/** + * Render style adapter, can be one of the built-in {@link ConfiguredColour}s + * or a user-defined style from a custom payload + * + * @author Adam Mummery-Smith + */ +public interface RenderStyle +{ + /** + * Rendering type for this line + */ + public enum RenderType + { + /** + * Render type to draw lines regardless of depth + */ + ANY(GL_ALWAYS), + + /** + * Render type for "hidden" lines (under world geometry) + */ + HIDDEN(GL_GEQUAL), + + /** + * Render type for visible lines (over world geometry) + */ + VISIBLE(GL_LESS); + + final int depthFunc; + + private RenderType(int depthFunc) + { + this.depthFunc = depthFunc; + } + + public boolean matches(RenderType other) + { + return other == RenderType.ANY ? true : other == this; + } + } + + public abstract void setRenderType(RenderType renderType); + + public abstract RenderType getRenderType(); + + public abstract void setColour(Colour colour); + + public abstract Colour getColour(); + + public abstract LineStyle[] getLines(); +} \ No newline at end of file diff --git a/java/com/mumfrey/worldeditcui/render/points/PointCube.java b/java/com/mumfrey/worldeditcui/render/points/PointCube.java index 0191381b..7d30c23c 100644 --- a/java/com/mumfrey/worldeditcui/render/points/PointCube.java +++ b/java/com/mumfrey/worldeditcui/render/points/PointCube.java @@ -1,7 +1,7 @@ package com.mumfrey.worldeditcui.render.points; import com.mumfrey.worldeditcui.render.ConfiguredColour; -import com.mumfrey.worldeditcui.render.RenderColour; +import com.mumfrey.worldeditcui.render.RenderStyle; import com.mumfrey.worldeditcui.render.shapes.Render3DBox; import com.mumfrey.worldeditcui.util.BoundingBox; import com.mumfrey.worldeditcui.util.Observable; @@ -11,7 +11,7 @@ * Stores data about a cube surrounding a * block in the world. Used to store info * about the selector blocks. Keeps track - * of colour, x/y/z values, and rendering. + * of style, x/y/z values, and rendering. * * @author yetanotherx * @author lahwran @@ -26,7 +26,7 @@ public class PointCube extends Observable protected int id; protected Vector3 point; - protected RenderColour colour = ConfiguredColour.CUBOIDPOINT1; + protected RenderStyle style = ConfiguredColour.CUBOIDPOINT1.style(); protected Render3DBox box; @@ -76,20 +76,20 @@ public void setPoint(Vector3 point) this.update(); } - public RenderColour getColour() + public RenderStyle getStyle() { - return this.colour; + return this.style; } - public PointCube setColour(RenderColour colour) + public PointCube setStyle(RenderStyle style) { - this.colour = colour; + this.style = style; this.update(); return this; } private void update() { - this.box = new Render3DBox(this.colour, this.point.subtract(PointCube.MIN_VEC), this.point.add(PointCube.MAX_VEC)); + this.box = new Render3DBox(this.style, this.point.subtract(PointCube.MIN_VEC), this.point.add(PointCube.MAX_VEC)); } } diff --git a/java/com/mumfrey/worldeditcui/render/points/PointRectangle.java b/java/com/mumfrey/worldeditcui/render/points/PointRectangle.java index c30de1ff..47542b1f 100644 --- a/java/com/mumfrey/worldeditcui/render/points/PointRectangle.java +++ b/java/com/mumfrey/worldeditcui/render/points/PointRectangle.java @@ -1,6 +1,6 @@ package com.mumfrey.worldeditcui.render.points; -import com.mumfrey.worldeditcui.render.RenderColour; +import com.mumfrey.worldeditcui.render.RenderStyle; import com.mumfrey.worldeditcui.render.ConfiguredColour; import com.mumfrey.worldeditcui.render.shapes.Render3DBox; import com.mumfrey.worldeditcui.util.Vector2; @@ -8,7 +8,7 @@ /** * Stores data about a prism surrounding two blocks in the world. Used to store - * info about the selector blocks for polys. Keeps track of colour, x/y/z + * info about the selector blocks for polys. Keeps track of style, x/y/z * values, and rendering. * * @author yetanotherx @@ -22,7 +22,7 @@ public class PointRectangle private static final Vector2 MAX_VEC = new Vector2(PointRectangle.OFF + 1, PointRectangle.OFF + 1); protected Vector2 point; - protected RenderColour colour = ConfiguredColour.POLYPOINT; + protected RenderStyle style = ConfiguredColour.POLYPOINT.style(); private int min, max; @@ -53,14 +53,14 @@ public void setPoint(Vector2 point) this.point = point; } - public RenderColour getColour() + public RenderStyle getStyle() { - return this.colour; + return this.style; } - public void setColour(RenderColour colour) + public void setStyle(RenderStyle style) { - this.colour = colour; + this.style = style; } public void setMinMax(int min, int max) @@ -82,6 +82,6 @@ public int getMax() private void update() { - this.box = new Render3DBox(this.colour, this.point.subtract(PointRectangle.MIN_VEC).toVector3(this.min - 0.03f), this.point.add(PointRectangle.MAX_VEC).toVector3(this.max + 1 + 0.03f)); + this.box = new Render3DBox(this.style, this.point.subtract(PointRectangle.MIN_VEC).toVector3(this.min - 0.03f), this.point.add(PointRectangle.MAX_VEC).toVector3(this.max + 1 + 0.03f)); } } diff --git a/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java b/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java index efe88a41..09c1a67b 100644 --- a/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java @@ -28,7 +28,7 @@ public class CuboidRegion extends Region public CuboidRegion(WorldEditCUI controller) { - super(controller, ConfiguredColour.CUBOIDBOX, ConfiguredColour.CUBOIDGRID, ConfiguredColour.CUBOIDPOINT1, ConfiguredColour.CUBOIDPOINT2); + super(controller, ConfiguredColour.CUBOIDBOX.style(), ConfiguredColour.CUBOIDGRID.style(), ConfiguredColour.CUBOIDPOINT1.style(), ConfiguredColour.CUBOIDPOINT2.style()); } @Override @@ -47,12 +47,12 @@ public void render(Vector3 cameraPos, float partialTicks) } else if (this.points[0] != null) { - this.points[0].updatePoint(partialTicks); + this.points[0].updatePoint(partialTicks); this.points[0].render(cameraPos); } else if (this.points[1] != null) { - this.points[1].updatePoint(partialTicks); + this.points[1].updatePoint(partialTicks); this.points[1].render(cameraPos); } } @@ -72,7 +72,7 @@ public void setCuboidPoint(int id, double x, double y, double z) { if (id < 2) { - this.points[id] = new PointCube(x, y, z).setColour(this.colours[2]); + this.points[id] = new PointCube(x, y, z).setStyle(this.styles[2]); } this.updateBounds(); @@ -83,7 +83,7 @@ public void setCuboidVertexLatch(int id, Entity entity, double traceDistance) { if (id < 2) { - this.points[id] = new PointCubeTracking(entity, traceDistance).setColour(this.colours[2]); + this.points[id] = new PointCubeTracking(entity, traceDistance).setStyle(this.styles[2]); } this.updateBounds(); @@ -94,32 +94,32 @@ private void updateBounds() if (this.points[0] != null && this.points[1] != null) { BoundingBox bounds = new BoundingBox(this.points[0], this.points[1]); - this.grid = new Render3DGrid(this.colours[1], bounds).setSpacing(this.spacing); - this.box = new Render3DBox(this.colours[0], bounds); + this.grid = new Render3DGrid(this.styles[1], bounds).setSpacing(this.spacing); + this.box = new Render3DBox(this.styles[0], bounds); } } @Override - protected void updateColours() + protected void updateStyles() { if (this.box != null) { - this.box.setColour(this.colours[0]); + this.box.setStyle(this.styles[0]); } if (this.grid != null) { - this.grid.setColour(this.colours[1]); + this.grid.setStyle(this.styles[1]); } if (this.points[0] != null) { - this.points[0].setColour(this.colours[2]); + this.points[0].setStyle(this.styles[2]); } if (this.points[1] != null) { - this.points[1].setColour(this.colours[3]); + this.points[1].setStyle(this.styles[3]); } } diff --git a/java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java b/java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java index 9deaefe4..242957b1 100644 --- a/java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java @@ -26,7 +26,7 @@ public class CylinderRegion extends Region public CylinderRegion(WorldEditCUI controller) { - super(controller, ConfiguredColour.CYLINDERBOX, ConfiguredColour.CYLINDERGRID, ConfiguredColour.CYLINDERCENTRE); + super(controller, ConfiguredColour.CYLINDERBOX.style(), ConfiguredColour.CYLINDERGRID.style(), ConfiguredColour.CYLINDERCENTRE.style()); } @Override @@ -45,7 +45,7 @@ public void render(Vector3 cameraPos, float partialTicks) public void setCylinderCenter(int x, int y, int z) { this.centre = new PointCube(x, y, z); - this.centre.setColour(this.colours[2]); + this.centre.setStyle(this.styles[2]); this.update(); } @@ -76,32 +76,32 @@ private void update() tMax = (int)this.centre.getPoint().getY(); } - this.circles = new RenderCylinderCircles(this.colours[1], this.centre, this.radX, this.radZ, tMin, tMax); - this.grid = new RenderCylinderGrid(this.colours[1], this.centre, this.radX, this.radZ, tMin, tMax); - this.box = new RenderCylinderBox(this.colours[0], this.centre, this.radX, this.radZ, tMin, tMax); + this.circles = new RenderCylinderCircles(this.styles[1], this.centre, this.radX, this.radZ, tMin, tMax); + this.grid = new RenderCylinderGrid(this.styles[1], this.centre, this.radX, this.radZ, tMin, tMax); + this.box = new RenderCylinderBox(this.styles[0], this.centre, this.radX, this.radZ, tMin, tMax); } @Override - protected void updateColours() + protected void updateStyles() { if (this.box != null) { - this.box.setColour(this.colours[0]); + this.box.setStyle(this.styles[0]); } if (this.grid != null) { - this.grid.setColour(this.colours[1]); + this.grid.setStyle(this.styles[1]); } if (this.circles != null) { - this.circles.setColour(this.colours[1]); + this.circles.setStyle(this.styles[1]); } if (this.centre != null) { - this.centre.setColour(this.colours[2]); + this.centre.setStyle(this.styles[2]); } } diff --git a/java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java b/java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java index 8b4a0f10..48a4c0b9 100644 --- a/java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java @@ -22,7 +22,7 @@ public class EllipsoidRegion extends Region public EllipsoidRegion(WorldEditCUI controller) { - super(controller, ConfiguredColour.ELLIPSOIDGRID, ConfiguredColour.ELLIPSOIDCENTRE); + super(controller, ConfiguredColour.ELLIPSOIDGRID.style(), ConfiguredColour.ELLIPSOIDCENTRE.style()); } @Override @@ -43,7 +43,7 @@ else if (this.centre != null) public void setEllipsoidCenter(int x, int y, int z) { this.centre = new PointCube(x, y, z); - this.centre.setColour(this.colours[1]); + this.centre.setStyle(this.styles[1]); this.update(); } @@ -58,21 +58,21 @@ private void update() { if (this.centre != null && this.radii != null) { - this.ellipsoid = new RenderEllipsoid(this.colours[0], this.centre, this.radii); + this.ellipsoid = new RenderEllipsoid(this.styles[0], this.centre, this.radii); } } @Override - protected void updateColours() + protected void updateStyles() { if (this.ellipsoid != null) { - this.ellipsoid.setColour(this.colours[0]); + this.ellipsoid.setStyle(this.styles[0]); } if (this.centre != null) { - this.centre.setColour(this.colours[1]); + this.centre.setStyle(this.styles[1]); } } diff --git a/java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java b/java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java index 4d4813cc..90d2e7a1 100644 --- a/java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java @@ -27,7 +27,7 @@ public class PolygonRegion extends Region public PolygonRegion(WorldEditCUI controller) { - super(controller, ConfiguredColour.POLYBOX, ConfiguredColour.POLYGRID, ConfiguredColour.POLYPOINT); + super(controller, ConfiguredColour.POLYBOX.style(), ConfiguredColour.POLYGRID.style(), ConfiguredColour.POLYPOINT.style()); } @Override @@ -62,7 +62,7 @@ public void setMinMax(int min, int max) public void setPolygonPoint(int id, int x, int z) { PointRectangle point = new PointRectangle(x, z); - point.setColour(this.colours[0]); + point.setStyle(this.styles[0]); point.setMinMax(this.min, this.max); if (id < this.points.size()) @@ -95,26 +95,26 @@ private void update() } } - this.box = new Render2DBox(this.colours[0], this.points, this.min, this.max); - this.grid = new Render2DGrid(this.colours[1], this.points, this.min, this.max); + this.box = new Render2DBox(this.styles[0], this.points, this.min, this.max); + this.grid = new Render2DGrid(this.styles[1], this.points, this.min, this.max); } @Override - protected void updateColours() + protected void updateStyles() { if (this.box != null) { - this.box.setColour(this.colours[0]); + this.box.setStyle(this.styles[0]); } if (this.grid != null) { - this.grid.setColour(this.colours[1]); + this.grid.setStyle(this.styles[1]); } for (PointRectangle point : this.points) { - point.setColour(this.colours[0]); + point.setStyle(this.styles[0]); } } diff --git a/java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java b/java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java index 348fe18f..46af9665 100644 --- a/java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java @@ -26,7 +26,7 @@ public class PolyhedronRegion extends Region public PolyhedronRegion(WorldEditCUI controller) { - super(controller, ConfiguredColour.POLYBOX, ConfiguredColour.POLYPOINT, ConfiguredColour.CUBOIDPOINT1); + super(controller, ConfiguredColour.POLYBOX.style(), ConfiguredColour.POLYPOINT.style(), ConfiguredColour.CUBOIDPOINT1.style()); } @Override @@ -47,7 +47,7 @@ public void render(Vector3 cameraPos, float partialTicks) public void setCuboidPoint(int id, double x, double y, double z) { final PointCube vertex = new PointCube(x, y, z).setId(id); - vertex.setColour(id == 0 ? this.colours[2] : this.colours[1]); + vertex.setStyle(id == 0 ? this.styles[2] : this.styles[1]); if (id < this.vertices.size()) { @@ -88,21 +88,21 @@ private void update() for (Vector3[] face : this.faces) { - this.faceRenders.add(new Render3DPolygon(this.colours[0], face)); + this.faceRenders.add(new Render3DPolygon(this.styles[0], face)); } } @Override - protected void updateColours() + protected void updateStyles() { for (PointCube vertex : this.vertices) { - vertex.setColour(vertex.getId() == 0 ? this.colours[2] : this.colours[1]); + vertex.setStyle(vertex.getId() == 0 ? this.styles[2] : this.styles[1]); } for (Render3DPolygon face : this.faceRenders) { - face.setColour(this.colours[0]); + face.setStyle(this.styles[0]); } } diff --git a/java/com/mumfrey/worldeditcui/render/region/Region.java b/java/com/mumfrey/worldeditcui/render/region/Region.java index 9e41c3a0..549fbd31 100644 --- a/java/com/mumfrey/worldeditcui/render/region/Region.java +++ b/java/com/mumfrey/worldeditcui/render/region/Region.java @@ -3,7 +3,8 @@ import com.mumfrey.worldeditcui.InitialisationFactory; import com.mumfrey.worldeditcui.WorldEditCUI; import com.mumfrey.worldeditcui.exceptions.InvalidSelectionTypeException; -import com.mumfrey.worldeditcui.render.RenderColour; +import com.mumfrey.worldeditcui.render.RenderStyle; +import com.mumfrey.worldeditcui.render.RenderStyle.RenderType; import com.mumfrey.worldeditcui.util.Vector3; import net.minecraft.entity.Entity; @@ -19,13 +20,14 @@ public abstract class Region implements InitialisationFactory { protected final WorldEditCUI controller; - protected final RenderColour[] defaultColours; - protected RenderColour[] colours; + protected final RenderStyle[] defaultStyles; + protected RenderStyle[] styles; + protected RenderType renderType = RenderType.ANY; - protected Region(WorldEditCUI controller, RenderColour... colours) + protected Region(WorldEditCUI controller, RenderStyle... styles) { this.controller = controller; - this.colours = this.defaultColours = colours; + this.styles = this.defaultStyles = styles; } @Override @@ -35,23 +37,41 @@ public void initialise() public abstract void render(Vector3 cameraPos, float partialTicks); - public RenderColour[] getDefaultColours() + public RenderStyle[] getDefaultStyles() { - return this.defaultColours; + return this.defaultStyles; } - public void setColours(RenderColour... colours) + public void setRenderType(RenderType renderType) { - if (colours.length < this.defaultColours.length) + this.renderType = renderType; + this.updateRenderStyle(); + } + + public void setStyles(RenderStyle... styles) + { + if (styles.length < this.defaultStyles.length) { - throw new IllegalArgumentException("Invalid colour palette supplied for " + this.getType().getName() + " region"); + throw new IllegalArgumentException("Invalid style palette supplied for " + this.getType().getName() + " region"); } - this.colours = colours; - this.updateColours(); + this.styles = styles; + this.updateRenderStyle(); + this.updateStyles(); } - protected abstract void updateColours(); + protected void updateRenderStyle() + { + for (RenderStyle style : this.styles) + { + if (style != null) + { + style.setRenderType(this.renderType); + } + } + } + + protected abstract void updateStyles(); public void setGridSpacing(double spacing) { diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java b/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java index d63de941..e11b4159 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java @@ -2,8 +2,8 @@ import java.util.List; -import com.mumfrey.worldeditcui.render.RenderColour; -import com.mumfrey.worldeditcui.render.LineInfo; +import com.mumfrey.worldeditcui.render.RenderStyle; +import com.mumfrey.worldeditcui.render.LineStyle; import com.mumfrey.worldeditcui.render.points.PointRectangle; import com.mumfrey.worldeditcui.util.Vector2; import com.mumfrey.worldeditcui.util.Vector3; @@ -24,9 +24,9 @@ public class Render2DBox extends RenderRegion private List points; private int min, max; - public Render2DBox(RenderColour colour, List points, int min, int max) + public Render2DBox(RenderStyle style, List points, int min, int max) { - super(colour); + super(style); this.points = points; this.min = min; this.max = max; @@ -38,12 +38,15 @@ public void render(Vector3 cameraPos) Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buf = tessellator.getBuffer(); double off = 0.03 - cameraPos.getY(); - for (LineInfo tempColour : this.colour.getColours()) + for (LineStyle line : this.style.getLines()) { - tempColour.prepareRender(); + if (!line.prepare(this.style.getRenderType())) + { + continue; + } buf.begin(GL_LINES, VF_POSITION); - tempColour.prepareColour(); + line.applyColour(); for (PointRectangle point : this.points) { diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java b/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java index f75e51d1..ead55db6 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java @@ -7,8 +7,8 @@ import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.Tessellator; -import com.mumfrey.worldeditcui.render.RenderColour; -import com.mumfrey.worldeditcui.render.LineInfo; +import com.mumfrey.worldeditcui.render.RenderStyle; +import com.mumfrey.worldeditcui.render.LineStyle; import com.mumfrey.worldeditcui.render.points.PointRectangle; import com.mumfrey.worldeditcui.util.Vector2; import com.mumfrey.worldeditcui.util.Vector3; @@ -25,9 +25,9 @@ public class Render2DGrid extends RenderRegion private List points; private int min, max; - public Render2DGrid(RenderColour colour, List points, int min, int max) + public Render2DGrid(RenderStyle style, List points, int min, int max) { - super(colour); + super(style); this.points = points; this.min = min; this.max = max; @@ -47,12 +47,15 @@ protected void drawPoly(Vector3 cameraPos, double height) { Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buf = tessellator.getBuffer(); - for (LineInfo tempColour : this.colour.getColours()) + for (LineStyle line : this.style.getLines()) { - tempColour.prepareRender(); + if (!line.prepare(this.style.getRenderType())) + { + continue; + } buf.begin(GL_LINE_LOOP, VF_POSITION); - tempColour.prepareColour(); + line.applyColour(); for (PointRectangle point : this.points) { if (point != null) diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java index 0de59471..fdd20eb6 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java @@ -5,8 +5,8 @@ import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.Tessellator; -import com.mumfrey.worldeditcui.render.RenderColour; -import com.mumfrey.worldeditcui.render.LineInfo; +import com.mumfrey.worldeditcui.render.RenderStyle; +import com.mumfrey.worldeditcui.render.LineStyle; import com.mumfrey.worldeditcui.util.BoundingBox; import com.mumfrey.worldeditcui.util.Observable; import com.mumfrey.worldeditcui.util.Vector3; @@ -22,18 +22,18 @@ public class Render3DBox extends RenderRegion { private Vector3 first, second; - public Render3DBox(RenderColour colour, BoundingBox region) + public Render3DBox(RenderStyle style, BoundingBox region) { - this(colour, region.getMin(), region.getMax()); + this(style, region.getMin(), region.getMax()); if (region.isDynamic()) { region.addObserver(this); } } - public Render3DBox(RenderColour colour, Vector3 first, Vector3 second) + public Render3DBox(RenderStyle style, Vector3 first, Vector3 second) { - super(colour); + super(style); this.first = first; this.second = second; } @@ -67,13 +67,16 @@ public void render(Vector3 cameraPos) double y2 = this.second.getY() - cameraPos.getY(); double z2 = this.second.getZ() - cameraPos.getZ(); - for (LineInfo tempColour : this.colour.getColours()) + for (LineStyle line : this.style.getLines()) { - tempColour.prepareRender(); + if (!line.prepare(this.style.getRenderType())) + { + continue; + } // Draw bottom face buf.begin(GL_LINE_LOOP, VF_POSITION); - tempColour.prepareColour(); + line.applyColour(); buf.pos(x1, y1, z1).endVertex(); buf.pos(x2, y1, z1).endVertex(); buf.pos(x2, y1, z2).endVertex(); @@ -82,7 +85,7 @@ public void render(Vector3 cameraPos) // Draw top face buf.begin(GL_LINE_LOOP, VF_POSITION); - tempColour.prepareColour(); + line.applyColour(); buf.pos(x1, y2, z1).endVertex(); buf.pos(x2, y2, z1).endVertex(); buf.pos(x2, y2, z2).endVertex(); @@ -91,7 +94,7 @@ public void render(Vector3 cameraPos) // Draw join top and bottom faces buf.begin(GL_LINES, VF_POSITION); - tempColour.prepareColour(); + line.applyColour(); buf.pos(x1, y1, z1).endVertex(); buf.pos(x1, y2, z1).endVertex(); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java index 9a7bd6cf..7ef5ed42 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java @@ -5,8 +5,8 @@ import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.Tessellator; -import com.mumfrey.worldeditcui.render.LineInfo; -import com.mumfrey.worldeditcui.render.RenderColour; +import com.mumfrey.worldeditcui.render.LineStyle; +import com.mumfrey.worldeditcui.render.RenderStyle; import com.mumfrey.worldeditcui.util.BoundingBox; import com.mumfrey.worldeditcui.util.Observable; import com.mumfrey.worldeditcui.util.Vector3; @@ -25,18 +25,18 @@ public class Render3DGrid extends RenderRegion private Vector3 first, second; private double spacing = 1.0; - public Render3DGrid(RenderColour colour, BoundingBox region) + public Render3DGrid(RenderStyle style, BoundingBox region) { - this(colour, region.getMin(), region.getMax()); + this(style, region.getMin(), region.getMax()); if (region.isDynamic()) { region.addObserver(this); } } - public Render3DGrid(RenderColour colour, Vector3 first, Vector3 second) + public Render3DGrid(RenderStyle style, Vector3 first, Vector3 second) { - super(colour); + super(style); this.first = first; this.second = second; } @@ -89,16 +89,18 @@ public void render(Vector3 cameraPos) x1, y1, z2, x2, y1, z2, x2, y2, z2, x1, y2, z2 // south }; - for (LineInfo tempColour : this.colour.getColours()) + for (LineStyle line : this.style.getLines()) { - buf.begin(GL_QUADS, VF_POSITION); - tempColour.prepareRender(); - tempColour.prepareColour(0.25F); - for (int i = 0; i < vertices.length; i += 3) + if (line.prepare(this.style.getRenderType())) { - buf.pos(vertices[i], vertices[i + 1], vertices[i + 2]).endVertex(); + buf.begin(GL_QUADS, VF_POSITION); + line.applyColour(0.25F); + for (int i = 0; i < vertices.length; i += 3) + { + buf.pos(vertices[i], vertices[i + 1], vertices[i + 2]).endVertex(); + } + tessellator.draw(); } - tessellator.draw(); } glEnableCulling(); @@ -110,12 +112,15 @@ public void render(Vector3 cameraPos) } double cullAt = 128.0F; - for (LineInfo tempColour : this.colour.getColours()) + for (LineStyle line : this.style.getLines()) { - tempColour.prepareRender(); + if (!line.prepare(this.style.getRenderType())) + { + continue; + } buf.begin(GL_LINES, VF_POSITION); - tempColour.prepareColour(); + line.applyColour(); for (double y = Math.max(y1, -cullAt); y <= y2 && y <= cullAt; y += this.spacing) { @@ -131,7 +136,6 @@ public void render(Vector3 cameraPos) for (double x = Math.max(x1, -cullAt); x <= x2 && x <= cullAt; x += this.spacing) { -// boolean major = xoff % 10 == 0; buf.pos(x, y1, z1).endVertex(); buf.pos(x, y2, z1).endVertex(); buf.pos(x, y1, z2).endVertex(); @@ -144,7 +148,6 @@ public void render(Vector3 cameraPos) for (double z = Math.max(z1, -cullAt); z <= z2 && z <= cullAt; z += this.spacing) { -// boolean major = zoff % 10 == 0; buf.pos(x1, y1, z).endVertex(); buf.pos(x2, y1, z).endVertex(); buf.pos(x1, y2, z).endVertex(); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java index f9d32397..457c92d2 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java @@ -5,8 +5,8 @@ import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.Tessellator; -import com.mumfrey.worldeditcui.render.RenderColour; -import com.mumfrey.worldeditcui.render.LineInfo; +import com.mumfrey.worldeditcui.render.RenderStyle; +import com.mumfrey.worldeditcui.render.LineStyle; import com.mumfrey.worldeditcui.util.Vector3; /** @@ -20,9 +20,9 @@ public class Render3DPolygon extends RenderRegion { private Vector3[] vertices; - public Render3DPolygon(RenderColour colour, Vector3... vertices) + public Render3DPolygon(RenderStyle style, Vector3... vertices) { - super(colour); + super(style); this.vertices = vertices; } @@ -32,12 +32,15 @@ public void render(Vector3 cameraPos) Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buf = tessellator.getBuffer(); - for (LineInfo tempColour : this.colour.getColours()) + for (LineStyle line : this.style.getLines()) { - tempColour.prepareRender(); + if (!line.prepare(this.style.getRenderType())) + { + continue; + } buf.begin(GL_LINE_LOOP, VF_POSITION); - tempColour.prepareColour(); + line.applyColour(); for (Vector3 vertex : this.vertices) { buf.pos(vertex.getX() - cameraPos.getX(), vertex.getY() - cameraPos.getY(), vertex.getZ() - cameraPos.getZ()).endVertex(); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java index ce631b33..cbdfc0f7 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java @@ -5,8 +5,8 @@ import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.Tessellator; -import com.mumfrey.worldeditcui.render.RenderColour; -import com.mumfrey.worldeditcui.render.LineInfo; +import com.mumfrey.worldeditcui.render.RenderStyle; +import com.mumfrey.worldeditcui.render.LineStyle; import com.mumfrey.worldeditcui.render.points.PointCube; import com.mumfrey.worldeditcui.util.Vector3; @@ -22,9 +22,9 @@ public class RenderCylinderBox extends RenderRegion private int minY, maxY; private double centreX, centreZ; - public RenderCylinderBox(RenderColour colour, PointCube centre, double radX, double radZ, int minY, int maxY) + public RenderCylinderBox(RenderStyle style, PointCube centre, double radX, double radZ, int minY, int maxY) { - super(colour); + super(style); this.radX = radX; this.radZ = radZ; this.minY = minY; @@ -42,15 +42,18 @@ public void render(Vector3 cameraPos) double xPos = this.centreX - cameraPos.getX(); double zPos = this.centreZ - cameraPos.getZ(); - for (LineInfo tempColour : this.colour.getColours()) + for (LineStyle line : this.style.getLines()) { - tempColour.prepareRender(); + if (!line.prepare(this.style.getRenderType())) + { + continue; + } double twoPi = Math.PI * 2; for (int yBlock : new int[] { this.minY, this.maxY + 1 }) { buf.begin(GL_LINE_LOOP, VF_POSITION); - tempColour.prepareColour(); + line.applyColour(); for (int i = 0; i <= 75; i++) { diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java index 79b29d9c..7e3ff071 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java @@ -5,8 +5,8 @@ import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.Tessellator; -import com.mumfrey.worldeditcui.render.RenderColour; -import com.mumfrey.worldeditcui.render.LineInfo; +import com.mumfrey.worldeditcui.render.RenderStyle; +import com.mumfrey.worldeditcui.render.LineStyle; import com.mumfrey.worldeditcui.render.points.PointCube; import com.mumfrey.worldeditcui.util.Vector3; @@ -25,9 +25,9 @@ public class RenderCylinderCircles extends RenderRegion protected double centreX; protected double centreZ; - public RenderCylinderCircles(RenderColour colour, PointCube centre, double radX, double radZ, int minY, int maxY) + public RenderCylinderCircles(RenderStyle style, PointCube centre, double radX, double radZ, int minY, int maxY) { - super(colour); + super(style); this.radX = radX; this.radZ = radZ; this.minY = minY; @@ -45,15 +45,18 @@ public void render(Vector3 cameraPos) double xPos = this.centreX - cameraPos.getX(); double zPos = this.centreZ - cameraPos.getZ(); - for (LineInfo tempColour : this.colour.getColours()) + for (LineStyle line : this.style.getLines()) { - tempColour.prepareRender(); + if (!line.prepare(this.style.getRenderType())) + { + continue; + } double twoPi = Math.PI * 2; for (int yBlock = this.minY + 1; yBlock <= this.maxY; yBlock++) { buf.begin(GL_LINE_LOOP, VF_POSITION); - tempColour.prepareColour(); + line.applyColour(); for (int i = 0; i <= 75; i++) { diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java index dbc30d63..26a91b70 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java @@ -5,8 +5,8 @@ import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.Tessellator; -import com.mumfrey.worldeditcui.render.RenderColour; -import com.mumfrey.worldeditcui.render.LineInfo; +import com.mumfrey.worldeditcui.render.RenderStyle; +import com.mumfrey.worldeditcui.render.LineStyle; import com.mumfrey.worldeditcui.render.points.PointCube; import com.mumfrey.worldeditcui.util.Vector3; @@ -25,9 +25,9 @@ public class RenderCylinderGrid extends RenderRegion protected double centreX; protected double centreZ; - public RenderCylinderGrid(RenderColour colour, PointCube centre, double radX, double radZ, int minY, int maxY) + public RenderCylinderGrid(RenderStyle style, PointCube centre, double radX, double radZ, int minY, int maxY) { - super(colour); + super(style); this.radX = radX; this.radZ = radZ; this.minY = minY; @@ -45,9 +45,12 @@ public void render(Vector3 cameraPos) double xPos = this.centreX - cameraPos.getX(); double zPos = this.centreZ - cameraPos.getZ(); - for (LineInfo tempColour : this.colour.getColours()) + for (LineStyle line : this.style.getLines()) { - tempColour.prepareRender(); + if (!line.prepare(this.style.getRenderType())) + { + continue; + } int tmaxY = this.maxY + 1; int tminY = this.minY; @@ -60,7 +63,7 @@ public void render(Vector3 cameraPos) { double tempZ = this.radZ * Math.cos(Math.asin(tempX / this.radX)); buf.begin(GL_LINE_LOOP, VF_POSITION); - tempColour.prepareColour(); + line.applyColour(); buf.pos(xPos + tempX, tmaxY - cameraPos.getY(), zPos + tempZ).endVertex(); buf.pos(xPos + tempX, tmaxY - cameraPos.getY(), zPos - tempZ).endVertex(); @@ -74,7 +77,7 @@ public void render(Vector3 cameraPos) { double tempX = this.radX * Math.sin(Math.acos(tempZ / this.radZ)); buf.begin(GL_LINE_LOOP, VF_POSITION); - tempColour.prepareColour(); + line.applyColour(); buf.pos(xPos + tempX, tmaxY - cameraPos.getY(), zPos + tempZ).endVertex(); buf.pos(xPos - tempX, tmaxY - cameraPos.getY(), zPos + tempZ).endVertex(); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java index eef073d8..78825873 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java @@ -5,8 +5,8 @@ import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.Tessellator; -import com.mumfrey.worldeditcui.render.RenderColour; -import com.mumfrey.worldeditcui.render.LineInfo; +import com.mumfrey.worldeditcui.render.RenderStyle; +import com.mumfrey.worldeditcui.render.LineStyle; import com.mumfrey.worldeditcui.render.points.PointCube; import com.mumfrey.worldeditcui.util.Vector3; @@ -18,16 +18,16 @@ */ public class RenderEllipsoid extends RenderRegion { + protected final static double TAU = Math.PI * 2.0; + protected PointCube centre; protected Vector3 radii; - protected final static double twoPi = Math.PI * 2; - protected double centreX; - protected double centreY; - protected double centreZ; - public RenderEllipsoid(RenderColour colour, PointCube centre, Vector3 radii) + protected double centreX, centreY, centreZ; + + public RenderEllipsoid(RenderStyle style, PointCube centre, Vector3 radii) { - super(colour); + super(style); this.centre = centre; this.radii = radii; this.centreX = centre.getPoint().getX() + 0.5; @@ -41,18 +41,20 @@ public void render(Vector3 cameraPos) glPushMatrix(); glTranslated(this.centreX - cameraPos.getX(), this.centreY - cameraPos.getY(), this.centreZ - cameraPos.getZ()); - for (LineInfo tempColour : this.colour.getColours()) + for (LineStyle line : this.style.getLines()) { - tempColour.prepareRender(); - this.drawXZPlane(tempColour); - this.drawYZPlane(tempColour); - this.drawXYPlane(tempColour); + if (line.prepare(this.style.getRenderType())) + { + this.drawXZPlane(line); + this.drawYZPlane(line); + this.drawXYPlane(line); + } } glPopMatrix(); } - protected void drawXZPlane(LineInfo colour) + protected void drawXZPlane(LineStyle line) { Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buf = tessellator.getBuffer(); @@ -61,11 +63,11 @@ protected void drawXZPlane(LineInfo colour) for (int yBlock = -yRad; yBlock < yRad; yBlock++) { buf.begin(GL_LINE_LOOP, VF_POSITION); - colour.prepareColour(); + line.applyColour(); for (int i = 0; i <= 40; i++) { - double tempTheta = i * twoPi / 40; + double tempTheta = i * TAU / 40; double tempX = this.radii.getX() * Math.cos(tempTheta) * Math.cos(Math.asin(yBlock / this.radii.getY())); double tempZ = this.radii.getZ() * Math.sin(tempTheta) * Math.cos(Math.asin(yBlock / this.radii.getY())); @@ -75,11 +77,11 @@ protected void drawXZPlane(LineInfo colour) } buf.begin(GL_LINE_LOOP, VF_POSITION); - colour.prepareColour(); + line.applyColour(); for (int i = 0; i <= 40; i++) { - double tempTheta = i * twoPi / 40; + double tempTheta = i * TAU / 40; double tempX = this.radii.getX() * Math.cos(tempTheta); double tempZ = this.radii.getZ() * Math.sin(tempTheta); @@ -88,7 +90,7 @@ protected void drawXZPlane(LineInfo colour) tessellator.draw(); } - protected void drawYZPlane(LineInfo colour) + protected void drawYZPlane(LineStyle line) { Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buf = tessellator.getBuffer(); @@ -97,11 +99,11 @@ protected void drawYZPlane(LineInfo colour) for (int xBlock = -xRad; xBlock < xRad; xBlock++) { buf.begin(GL_LINE_LOOP, VF_POSITION); - colour.prepareColour(); + line.applyColour(); for (int i = 0; i <= 40; i++) { - double tempTheta = i * twoPi / 40; + double tempTheta = i * TAU / 40; double tempY = this.radii.getY() * Math.cos(tempTheta) * Math.sin(Math.acos(xBlock / this.radii.getX())); double tempZ = this.radii.getZ() * Math.sin(tempTheta) * Math.sin(Math.acos(xBlock / this.radii.getX())); @@ -111,11 +113,11 @@ protected void drawYZPlane(LineInfo colour) } buf.begin(GL_LINE_LOOP, VF_POSITION); - colour.prepareColour(); + line.applyColour(); for (int i = 0; i <= 40; i++) { - double tempTheta = i * twoPi / 40; + double tempTheta = i * TAU / 40; double tempY = this.radii.getY() * Math.cos(tempTheta); double tempZ = this.radii.getZ() * Math.sin(tempTheta); @@ -124,7 +126,7 @@ protected void drawYZPlane(LineInfo colour) tessellator.draw(); } - protected void drawXYPlane(LineInfo colour) + protected void drawXYPlane(LineStyle line) { Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buf = tessellator.getBuffer(); @@ -133,11 +135,11 @@ protected void drawXYPlane(LineInfo colour) for (int zBlock = -zRad; zBlock < zRad; zBlock++) { buf.begin(GL_LINE_LOOP, VF_POSITION); - colour.prepareColour(); + line.applyColour(); for (int i = 0; i <= 40; i++) { - double tempTheta = i * twoPi / 40; + double tempTheta = i * TAU / 40; double tempX = this.radii.getX() * Math.sin(tempTheta) * Math.sin(Math.acos(zBlock / this.radii.getZ())); double tempY = this.radii.getY() * Math.cos(tempTheta) * Math.sin(Math.acos(zBlock / this.radii.getZ())); @@ -147,11 +149,11 @@ protected void drawXYPlane(LineInfo colour) } buf.begin(GL_LINE_LOOP, VF_POSITION); - colour.prepareColour(); + line.applyColour(); for (int i = 0; i <= 40; i++) { - double tempTheta = i * twoPi / 40; + double tempTheta = i * TAU / 40; double tempX = this.radii.getX() * Math.cos(tempTheta); double tempY = this.radii.getY() * Math.sin(tempTheta); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderRegion.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderRegion.java index 7fa835de..b89bfdbc 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/RenderRegion.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderRegion.java @@ -1,6 +1,6 @@ package com.mumfrey.worldeditcui.render.shapes; -import com.mumfrey.worldeditcui.render.RenderColour; +import com.mumfrey.worldeditcui.render.RenderStyle; import com.mumfrey.worldeditcui.util.Observable; import com.mumfrey.worldeditcui.util.Observer; import com.mumfrey.worldeditcui.util.Vector3; @@ -12,16 +12,16 @@ */ public abstract class RenderRegion implements Observer { - protected RenderColour colour; + protected RenderStyle style; - protected RenderRegion(RenderColour colour) + protected RenderRegion(RenderStyle style) { - this.colour = colour; + this.style = style; } - public final void setColour(RenderColour colour) + public final void setStyle(RenderStyle style) { - this.colour = colour; + this.style = style; } public abstract void render(Vector3 cameraPos); From beb58db5a61f55ebc22dc74fd404a1ed64c517da Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Mon, 31 Jul 2017 16:18:09 +0100 Subject: [PATCH 41/51] Fix some comments and string literals which accidentally got refactored --- .../mumfrey/worldeditcui/config/Colour.java | 4 +-- .../gui/controls/GuiColourButton.java | 4 +-- .../gui/controls/GuiColourPicker.java | 11 ++++---- .../worldeditcui/gui/controls/GuiControl.java | 18 ++++++------- .../worldeditcui/render/ConfiguredColour.java | 26 +++++++++---------- .../worldeditcui/render/points/PointCube.java | 6 ++--- .../render/points/PointRectangle.java | 2 +- .../worldeditcui/render/region/Region.java | 2 +- 8 files changed, 36 insertions(+), 37 deletions(-) diff --git a/java/com/mumfrey/worldeditcui/config/Colour.java b/java/com/mumfrey/worldeditcui/config/Colour.java index 9e56d8e0..70195201 100644 --- a/java/com/mumfrey/worldeditcui/config/Colour.java +++ b/java/com/mumfrey/worldeditcui/config/Colour.java @@ -47,10 +47,10 @@ public static Colour firstOrDefault(Colour colour, String defaultColour) } /** - * Validates a user-entered style code. Ensures that style is not null, it + * Validates a user-entered colour code. Ensures that style is not null, it * starts with #, that it has all 6 digits, and that each hex code is valid. * - * @param style + * @param colour * @param def * @return */ diff --git a/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java index 1fe84a7d..d31cb242 100644 --- a/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java +++ b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java @@ -14,7 +14,7 @@ public class GuiColourButton extends GuiControl { /** - * Picker active style + * Picker active colour */ private int colour = 0xFF000000; @@ -135,7 +135,7 @@ public boolean mousePressed(Minecraft minecraft, int mouseX, int mouseY) int xPos = Math.min(this.x + this.width, GuiControl.lastScreenWidth - 233); int yPos = Math.min(this.y, GuiControl.lastScreenHeight - 175); - this.picker = new GuiColourPicker(minecraft, 1, xPos, yPos, this.colour, "Choose style"); + this.picker = new GuiColourPicker(minecraft, 1, xPos, yPos, this.colour, "Choose colour"); this.pickerClicked = false; } diff --git a/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java index 8fdd4d3e..aff311fe 100644 --- a/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java +++ b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java @@ -29,8 +29,8 @@ public class GuiColourPicker extends GuiControl private static final int H = 0, S = 1, B = 2; /** - * HSB values from Colour.RGBtoHSB, combined with opacity this is the authoritative version of the - * style we are editing + * HSB values from Colour.RGBtoHSB, combined with opacity this is the + * authoritative version of the colour we are editing */ private float[] hsb; @@ -40,7 +40,8 @@ public class GuiColourPicker extends GuiControl private int rgb; /** - * Current opacity, stored as an offset byte in the usual position, eg. 0xFF << 24 + * Current opacity, stored as an offset byte in the usual position, + * eg. 0xFF << 24 */ private int opacity; @@ -125,7 +126,7 @@ protected void drawControl(Minecraft minecraft, int mouseX, int mouseY, float pa int bPos = this.y + 10 + (128 - (int)(128F * this.hsb[B])); int aPos = this.y + 10 + ((256 - ((this.opacity >> 24) & 0xFF)) / 2); - // Calculate B style + // Calculate B colour int brightness = Color.HSBtoRGB(this.hsb[H], this.hsb[S], 1.0F) | 0xFF000000; // Draw backgrounds @@ -135,7 +136,7 @@ protected void drawControl(Minecraft minecraft, int mouseX, int mouseY, float pa drawRect(this.x + 162, this.y + 9, this.x + 179, this.y + 139, 0xFFA0A0A0); // A background drawRect(this.x + 187, this.y + 105, this.x + 221, this.y + 139, 0xFFA0A0A0); // Preview background - // Draw style picker + // Draw colour picker this.mc.getTextureManager().bindTexture(GuiColourPicker.COLOURPICKER_PICKER); glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.drawTexturedModalRect(this.x + 10, this.y + 10, this.x + 138, this.y + 138, 0, 0, 256, 256); diff --git a/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java b/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java index a6fbf9a5..2bb07215 100644 --- a/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java +++ b/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java @@ -161,14 +161,14 @@ public boolean isDoubleClicked(boolean resetDoubleClicked) } /** - * Draws a line between two points with the specified width and style + * Draws a line between two points with the specified width and colour * * @param x1 Origin x coordinate * @param y1 Origin y coordinate * @param x2 End x coordinate * @param y2 End y coordinate * @param width Line width in pixels - * @param style Line style + * @param colour Line colour */ public static void drawLine(int x1, int y1, int x2, int y2, int width, int colour) { @@ -183,7 +183,7 @@ public static void drawLine(int x1, int y1, int x2, int y2, int width, int colou * @param x2 End x position * @param y2 End y position * @param width Line width - * @param style Line style + * @param colour Line colour */ @SuppressWarnings("cast") public static void drawNativeLine(float x1, float y1, float x2, float y2, float width, int colour) @@ -211,7 +211,7 @@ public static void drawNativeLine(float x1, float y1, float x2, float y2, float } /** - * Draws an arrow between two points with the specified width and style + * Draws an arrow between two points with the specified width and colour * * @param x1 Origin x coordinate * @param y1 Origin y coordinate @@ -219,7 +219,7 @@ public static void drawNativeLine(float x1, float y1, float x2, float y2, float * @param y2 End y coordinate * @param width Line width in pixels * @param arrowHeadSize Size of the arrow head - * @param style Colour + * @param colour Colour */ public static void drawArrow(int x1, int y1, int x2, int y2, int z, int width, int arrowHeadSize, int colour) { @@ -234,7 +234,7 @@ public static void drawArrow(int x1, int y1, int x2, int y2, int z, int width, i * @param x2 End x coordinate * @param y2 End y coordinate * @param width Line width in pixels - * @param style Colour + * @param colour Colour * @param arrowHead True to draw an arrow, otherwise draws a line * @param arrowHeadSize Size of the arrow head */ @@ -256,7 +256,7 @@ public static void drawArrow(int x1, int y1, int x2, int y2, int z, int width, i y1 = (int)(width * -0.5); y2 = y1 + width; - // Calc style components + // Calc colour components float f = (float)(colour >> 24 & 0xff) / 255F; float f1 = (float)(colour >> 16 & 0xff) / 255F; float f2 = (float)(colour >> 8 & 0xff) / 255F; @@ -459,7 +459,7 @@ public void drawTessellatedModalBorderRect(int x, int y, int x2, int y2, int u, * @param x * @param y * @param width - * @param style + * @param colour */ public static void drawStringWithEllipsis(FontRenderer fontrenderer, String s, int x, int y, int width, int colour) { @@ -555,7 +555,7 @@ protected void drawRotText(FontRenderer fontRenderer, String text, int xPosition * @param mouseY * @param screenWidth * @param screenHeight - * @param style + * @param colour * @param backgroundColour */ protected void drawTooltip(FontRenderer fontRenderer, String tooltipText, int mouseX, int mouseY, int screenWidth, int screenHeight, int colour, int backgroundColour) diff --git a/java/com/mumfrey/worldeditcui/render/ConfiguredColour.java b/java/com/mumfrey/worldeditcui/render/ConfiguredColour.java index c06ba233..658800ee 100644 --- a/java/com/mumfrey/worldeditcui/render/ConfiguredColour.java +++ b/java/com/mumfrey/worldeditcui/render/ConfiguredColour.java @@ -17,20 +17,20 @@ * @author lahwran * @author Adam Mummery-Smith */ -public enum ConfiguredColour // implements RenderStyle +public enum ConfiguredColour { - CUBOIDBOX ("style.cuboidedge", new Colour("#CC3333CC")), - CUBOIDGRID ("style.cuboidgrid", new Colour("#CC4C4CCC")), - CUBOIDPOINT1 ("style.cuboidpoint1", new Colour("#33CC33CC")), - CUBOIDPOINT2 ("style.cuboidpoint2", new Colour("#3333CCCC")), - POLYGRID ("style.polygrid", new Colour("#CC3333CC")), - POLYBOX ("style.polyedge", new Colour("#CC4C4CCC")), - POLYPOINT ("style.polypoint", new Colour("#33CCCCCC")), - ELLIPSOIDGRID ("style.ellipsoidgrid", new Colour("#CC4C4CCC")), - ELLIPSOIDCENTRE("style.ellipsoidpoint", new Colour("#CCCC33CC")), - CYLINDERGRID ("style.cylindergrid", new Colour("#CC3333CC")), - CYLINDERBOX ("style.cylinderedge", new Colour("#CC4C4CCC")), - CYLINDERCENTRE ("style.cylinderpoint", new Colour("#CC33CCCC")); + CUBOIDBOX ("colour.cuboidedge", new Colour("#CC3333CC")), + CUBOIDGRID ("colour.cuboidgrid", new Colour("#CC4C4CCC")), + CUBOIDPOINT1 ("colour.cuboidpoint1", new Colour("#33CC33CC")), + CUBOIDPOINT2 ("colour.cuboidpoint2", new Colour("#3333CCCC")), + POLYGRID ("colour.polygrid", new Colour("#CC3333CC")), + POLYBOX ("colour.polyedge", new Colour("#CC4C4CCC")), + POLYPOINT ("colour.polypoint", new Colour("#33CCCCCC")), + ELLIPSOIDGRID ("colour.ellipsoidgrid", new Colour("#CC4C4CCC")), + ELLIPSOIDCENTRE("colour.ellipsoidpoint", new Colour("#CCCC33CC")), + CYLINDERGRID ("colour.cylindergrid", new Colour("#CC3333CC")), + CYLINDERBOX ("colour.cylinderedge", new Colour("#CC4C4CCC")), + CYLINDERCENTRE ("colour.cylinderpoint", new Colour("#CC33CCCC")); class Style implements RenderStyle { diff --git a/java/com/mumfrey/worldeditcui/render/points/PointCube.java b/java/com/mumfrey/worldeditcui/render/points/PointCube.java index 7d30c23c..f34812af 100644 --- a/java/com/mumfrey/worldeditcui/render/points/PointCube.java +++ b/java/com/mumfrey/worldeditcui/render/points/PointCube.java @@ -8,10 +8,8 @@ import com.mumfrey.worldeditcui.util.Vector3; /** - * Stores data about a cube surrounding a - * block in the world. Used to store info - * about the selector blocks. Keeps track - * of style, x/y/z values, and rendering. + * Stores data about a cube surrounding a block in the world. Used to store info + * about the selector blocks. Keeps track of colour, x/y/z values, and rendering * * @author yetanotherx * @author lahwran diff --git a/java/com/mumfrey/worldeditcui/render/points/PointRectangle.java b/java/com/mumfrey/worldeditcui/render/points/PointRectangle.java index 47542b1f..8b4c174c 100644 --- a/java/com/mumfrey/worldeditcui/render/points/PointRectangle.java +++ b/java/com/mumfrey/worldeditcui/render/points/PointRectangle.java @@ -8,7 +8,7 @@ /** * Stores data about a prism surrounding two blocks in the world. Used to store - * info about the selector blocks for polys. Keeps track of style, x/y/z + * info about the selector blocks for polys. Keeps track of colour, x/y/z * values, and rendering. * * @author yetanotherx diff --git a/java/com/mumfrey/worldeditcui/render/region/Region.java b/java/com/mumfrey/worldeditcui/render/region/Region.java index 549fbd31..ff3bb759 100644 --- a/java/com/mumfrey/worldeditcui/render/region/Region.java +++ b/java/com/mumfrey/worldeditcui/render/region/Region.java @@ -52,7 +52,7 @@ public void setStyles(RenderStyle... styles) { if (styles.length < this.defaultStyles.length) { - throw new IllegalArgumentException("Invalid style palette supplied for " + this.getType().getName() + " region"); + throw new IllegalArgumentException("Invalid colour palette supplied for " + this.getType().getName() + " region"); } this.styles = styles; From 7136f2f3bc9075a9ae7e04882de09ea7911466ff Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Tue, 1 Aug 2017 13:31:18 +0100 Subject: [PATCH 42/51] Cull gridlines further away based on grid spacing, updates #16 --- java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java b/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java index 7ef5ed42..fe0a0dd4 100644 --- a/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java @@ -20,6 +20,7 @@ */ public class Render3DGrid extends RenderRegion { + private static final float CULL_RANGE = 128.0F; public static final double MIN_SPACING = 1.0; private Vector3 first, second; @@ -111,7 +112,7 @@ public void render(Vector3 cameraPos) return; } - double cullAt = 128.0F; + double cullAt = Render3DGrid.CULL_RANGE * this.spacing; for (LineStyle line : this.style.getLines()) { if (!line.prepare(this.style.getRenderType())) From 21cfcaf709a6e45e1cca69cdf677e53646abbf08 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Tue, 1 Aug 2017 17:52:31 +0100 Subject: [PATCH 43/51] Update build scripts for release version _01 --- build.gradle | 3 ++- gradle.properties | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 34c07226..9eb7fb38 100644 --- a/build.gradle +++ b/build.gradle @@ -38,7 +38,8 @@ litemod { json { author = "yetanotherx, Mumfrey, TomyLobo" mcversion = project.targetVersion - description = "Client-side user interface for WorldEdit" + description = "Client-side user interface for WorldEdit", + revision = project.revision } } diff --git a/gradle.properties b/gradle.properties index df05573d..df5d792a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,6 @@ name=WorldEditCUI -version=1.12.1-SNAPSHOT +version=1.12_00 +revision=11201 mcVersion=1.12 mcMappings=snapshot_20170627 targetVersion=1.12.r1 \ No newline at end of file From 78bd685e0dedfdf368967980c15ccd87e5d26c40 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Tue, 1 Aug 2017 17:54:08 +0100 Subject: [PATCH 44/51] Add chunk boundary rendering option, closes #15 --- .../worldeditcui/LiteModWorldEditCUI.java | 17 ++- .../mumfrey/worldeditcui/WorldEditCUI.java | 22 ++- .../worldeditcui/config/CUIConfiguration.java | 87 +++++------ .../mumfrey/worldeditcui/config/Colour.java | 4 +- .../worldeditcui/gui/CUIConfigPanel.java | 4 +- .../worldeditcui/render/ConfiguredColour.java | 11 +- .../render/shapes/RenderChunkBoundary.java | 143 ++++++++++++++++++ res/assets/wecui/lang/en_us.lang | 3 + 8 files changed, 235 insertions(+), 56 deletions(-) create mode 100644 java/com/mumfrey/worldeditcui/render/shapes/RenderChunkBoundary.java diff --git a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java index 00e6fc0e..0268d2e4 100644 --- a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java @@ -33,6 +33,7 @@ import com.mumfrey.liteloader.messaging.Message; import com.mumfrey.liteloader.messaging.Messenger; import com.mumfrey.liteloader.modconfig.ConfigPanel; +import com.mumfrey.liteloader.util.Input; import com.mumfrey.worldeditcui.config.CUIConfiguration; import com.mumfrey.worldeditcui.event.listeners.CUIListenerChannel; import com.mumfrey.worldeditcui.event.listeners.CUIListenerWorldRender; @@ -55,6 +56,7 @@ public class LiteModWorldEditCUI implements Tickable, InitCompleteListener, Plug private KeyBinding keyBindToggleUI = new KeyBinding("wecui.keys.toggle", Keyboard.KEY_NONE, "wecui.keys.category"); private KeyBinding keyBindClearSel = new KeyBinding("wecui.keys.clear", Keyboard.KEY_NONE, "wecui.keys.category"); + private KeyBinding keyBindChunkBorder = new KeyBinding("wecui.keys.chunk", Keyboard.KEY_NONE, "wecui.keys.category"); private boolean visible = true; private boolean alwaysOnTop = false; @@ -67,8 +69,10 @@ public class LiteModWorldEditCUI implements Tickable, InitCompleteListener, Plug @Override public void init(File configPath) { - LiteLoader.getInput().registerKeyBinding(this.keyBindToggleUI); - LiteLoader.getInput().registerKeyBinding(this.keyBindClearSel); + Input input = LiteLoader.getInput(); + input.registerKeyBinding(this.keyBindToggleUI); + input.registerKeyBinding(this.keyBindClearSel); + input.registerKeyBinding(this.keyBindChunkBorder); } @Override @@ -83,7 +87,7 @@ public void upgradeSettings(String version, File configPath, File oldConfigPath) public void onInitCompleted(Minecraft minecraft, LiteLoader loader) { this.controller = new WorldEditCUI(); - this.controller.initialise(); + this.controller.initialise(minecraft); this.worldRenderListener = new CUIListenerWorldRender(this.controller, minecraft); this.channelListener = new CUIListenerChannel(this.controller); @@ -188,6 +192,11 @@ public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clo mc.player.sendChatMessage("//sel"); } } + + if (this.keyBindChunkBorder.isPressed()) + { + this.controller.toggleChunkBorders(); + } } if (inGame && clock && this.controller != null) @@ -234,7 +243,7 @@ public String getName() @Override public String getVersion() { - return "1.12.1-SNAPSHOT"; + return "1.12_01"; } @Override diff --git a/java/com/mumfrey/worldeditcui/WorldEditCUI.java b/java/com/mumfrey/worldeditcui/WorldEditCUI.java index 27d1f7b4..971e9ae1 100644 --- a/java/com/mumfrey/worldeditcui/WorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/WorldEditCUI.java @@ -4,13 +4,17 @@ import java.util.Map; import java.util.UUID; +import net.minecraft.client.Minecraft; + import com.mumfrey.worldeditcui.config.CUIConfiguration; import com.mumfrey.worldeditcui.debug.CUIDebug; import com.mumfrey.worldeditcui.event.CUIEventDispatcher; import com.mumfrey.worldeditcui.exceptions.InitialisationException; import com.mumfrey.worldeditcui.render.CUISelectionProvider; +import com.mumfrey.worldeditcui.render.ConfiguredColour; import com.mumfrey.worldeditcui.render.region.CuboidRegion; import com.mumfrey.worldeditcui.render.region.Region; +import com.mumfrey.worldeditcui.render.shapes.RenderChunkBoundary; import com.mumfrey.worldeditcui.util.Vector3; /** @@ -34,15 +38,17 @@ public class WorldEditCUI private CUIConfiguration configuration; private CUIEventDispatcher dispatcher; private CUISelectionProvider selectionProvider; + private RenderChunkBoundary chunkBorderRenderer; + private boolean chunkBorders; - public void initialise() + public void initialise(Minecraft minecraft) { this.selection = new CuboidRegion(this); this.configuration = CUIConfiguration.create(); this.debugger = new CUIDebug(this); this.dispatcher = new CUIEventDispatcher(this); this.selectionProvider = new CUISelectionProvider(this); - + try { this.selection.initialise(); @@ -56,6 +62,8 @@ public void initialise() e.printStackTrace(); return; } + + this.chunkBorderRenderer = new RenderChunkBoundary(ConfiguredColour.CHUNKBOUNDARY.style(), ConfiguredColour.CHUNKGRID.style(), minecraft); } public CUIEventDispatcher getDispatcher() @@ -130,5 +138,15 @@ public void renderSelections(Vector3 cameraPos, float partialTicks) { region.render(cameraPos, partialTicks); } + + if (this.chunkBorders) + { + this.chunkBorderRenderer.render(cameraPos); + } + } + + public void toggleChunkBorders() + { + this.chunkBorders = !this.chunkBorders; } } diff --git a/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java b/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java index 4f2ee9df..10b540e3 100644 --- a/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java +++ b/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java @@ -4,9 +4,11 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.lang.reflect.Field; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.annotations.Expose; import com.mumfrey.liteloader.core.LiteLoader; import com.mumfrey.worldeditcui.InitialisationFactory; import com.mumfrey.worldeditcui.render.ConfiguredColour; @@ -17,29 +19,31 @@ * @author yetanotherx * @author Adam Mummery-Smith */ -public class CUIConfiguration implements InitialisationFactory +public final class CUIConfiguration implements InitialisationFactory { private static final String CONFIG_FILE_NAME = "worldeditcui.config.json"; - private static Gson gson = new GsonBuilder().setPrettyPrinting().create(); + private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); - private boolean debugMode = false; - private boolean ignoreUpdates = false; - private boolean promiscuous = false; - private boolean alwaysOnTop = false; + @Expose private boolean debugMode = false; + @Expose private boolean ignoreUpdates = false; + @Expose private boolean promiscuous = false; + @Expose private boolean alwaysOnTop = false; - private Colour cuboidGridColor = new Colour("#CC3333CC"); - private Colour cuboidEdgeColor = new Colour("#CC4C4CCC"); - private Colour cuboidFirstPointColor = new Colour("#33CC33CC"); - private Colour cuboidSecondPointColor = new Colour("#3333CCCC"); - private Colour polyGridColor = new Colour("#CC3333CC"); - private Colour polyEdgeColor = new Colour("#CC4C4CCC"); - private Colour polyPointColor = new Colour("#33CCCCCC"); - private Colour ellipsoidGridColor = new Colour("#CC4C4CCC"); - private Colour ellipsoidPointColor = new Colour("#CCCC33CC"); - private Colour cylinderGridColor = new Colour("#CC3333CC"); - private Colour cylinderEdgeColor = new Colour("#CC4C4CCC"); - private Colour cylinderPointColor = new Colour("#CC33CCCC"); + @Expose private Colour cuboidGridColor = ConfiguredColour.CUBOIDBOX.getDefault(); + @Expose private Colour cuboidEdgeColor = ConfiguredColour.CUBOIDGRID.getDefault(); + @Expose private Colour cuboidFirstPointColor = ConfiguredColour.CUBOIDPOINT1.getDefault(); + @Expose private Colour cuboidSecondPointColor = ConfiguredColour.CUBOIDPOINT2.getDefault(); + @Expose private Colour polyGridColor = ConfiguredColour.POLYGRID.getDefault(); + @Expose private Colour polyEdgeColor = ConfiguredColour.POLYBOX.getDefault(); + @Expose private Colour polyPointColor = ConfiguredColour.POLYPOINT.getDefault(); + @Expose private Colour ellipsoidGridColor = ConfiguredColour.ELLIPSOIDGRID.getDefault(); + @Expose private Colour ellipsoidPointColor = ConfiguredColour.ELLIPSOIDCENTRE.getDefault(); + @Expose private Colour cylinderGridColor = ConfiguredColour.CYLINDERGRID.getDefault(); + @Expose private Colour cylinderEdgeColor = ConfiguredColour.CYLINDERBOX.getDefault(); + @Expose private Colour cylinderPointColor = ConfiguredColour.CYLINDERCENTRE.getDefault(); + @Expose private Colour chunkBoundaryColour = ConfiguredColour.CHUNKBOUNDARY.getDefault(); + @Expose private Colour chunkGridColour = ConfiguredColour.CHUNKGRID.getDefault(); /** * Copies the default config file to the proper directory if it does not @@ -48,31 +52,24 @@ public class CUIConfiguration implements InitialisationFactory @Override public void initialise() { - this.cuboidGridColor = Colour.firstOrDefault(this.cuboidGridColor, "#CC3333CC"); - this.cuboidEdgeColor = Colour.firstOrDefault(this.cuboidEdgeColor, "#CC4C4CCC"); - this.cuboidFirstPointColor = Colour.firstOrDefault(this.cuboidFirstPointColor, "#33CC33CC"); - this.cuboidSecondPointColor = Colour.firstOrDefault(this.cuboidSecondPointColor, "#3333CCCC"); - this.polyGridColor = Colour.firstOrDefault(this.polyGridColor, "#CC3333CC"); - this.polyEdgeColor = Colour.firstOrDefault(this.polyEdgeColor, "#CC4C4CCC"); - this.polyPointColor = Colour.firstOrDefault(this.polyPointColor, "#33CCCCCC"); - this.ellipsoidGridColor = Colour.firstOrDefault(this.ellipsoidGridColor, "#CC4C4CCC"); - this.ellipsoidPointColor = Colour.firstOrDefault(this.ellipsoidPointColor, "#CCCC33CC"); - this.cylinderGridColor = Colour.firstOrDefault(this.cylinderGridColor, "#CC3333CC"); - this.cylinderEdgeColor = Colour.firstOrDefault(this.cylinderEdgeColor, "#CC4C4CCC"); - this.cylinderPointColor = Colour.firstOrDefault(this.cylinderPointColor, "#CC33CCCC"); - - ConfiguredColour.CUBOIDBOX.setColour(this.cuboidEdgeColor); - ConfiguredColour.CUBOIDGRID.setColour(this.cuboidGridColor); - ConfiguredColour.CUBOIDPOINT1.setColour(this.cuboidFirstPointColor); - ConfiguredColour.CUBOIDPOINT2.setColour(this.cuboidSecondPointColor); - ConfiguredColour.POLYGRID.setColour(this.polyGridColor); - ConfiguredColour.POLYBOX.setColour(this.polyEdgeColor); - ConfiguredColour.POLYPOINT.setColour(this.polyPointColor); - ConfiguredColour.ELLIPSOIDGRID.setColour(this.ellipsoidGridColor); - ConfiguredColour.ELLIPSOIDCENTRE.setColour(this.ellipsoidPointColor); - ConfiguredColour.CYLINDERGRID.setColour(this.cylinderGridColor); - ConfiguredColour.CYLINDERBOX.setColour(this.cylinderEdgeColor); - ConfiguredColour.CYLINDERCENTRE.setColour(this.cylinderPointColor); + int index = 0; + try + { + for (Field field : this.getClass().getDeclaredFields()) + { + if (field.getType() == Colour.class) + { + ConfiguredColour configuredColour = ConfiguredColour.values()[index++]; + Colour colour = Colour.firstOrDefault((Colour)field.get(this), configuredColour.getColour().getHex()); + field.set(this, colour); + configuredColour.setColour(colour); + } + } + } + catch (Exception ex) + { + ex.printStackTrace(); + } this.save(); } @@ -118,7 +115,7 @@ public static CUIConfiguration create() try { fileReader = new FileReader(jsonFile); - CUIConfiguration config = CUIConfiguration.gson.fromJson(fileReader, CUIConfiguration.class); + CUIConfiguration config = CUIConfiguration.GSON.fromJson(fileReader, CUIConfiguration.class); return config; } catch (Exception ex) @@ -147,7 +144,7 @@ public void save() try { fileWriter = new FileWriter(jsonFile); - CUIConfiguration.gson.toJson(this, fileWriter); + CUIConfiguration.GSON.toJson(this, fileWriter); } catch (Exception ex) { diff --git a/java/com/mumfrey/worldeditcui/config/Colour.java b/java/com/mumfrey/worldeditcui/config/Colour.java index 70195201..a85109a3 100644 --- a/java/com/mumfrey/worldeditcui/config/Colour.java +++ b/java/com/mumfrey/worldeditcui/config/Colour.java @@ -6,8 +6,8 @@ public class Colour { private String hex; - private int argb; - private float a, r, g, b; + private transient int argb; + private transient float a, r, g, b; private transient String defaultColour; private transient boolean woken; diff --git a/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java b/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java index e1d71e84..1ad9af87 100644 --- a/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java +++ b/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java @@ -161,10 +161,12 @@ private void actionPerformed(GuiButton control) if (control.id >= 100) { ConfiguredColour lineColour = ConfiguredColour.values()[control.id - 100]; - lineColour.setDefaultColour(); + lineColour.setDefault(); for (GuiColourButton colourButton : this.colourButtonList) + { colourButton.updateColour(lineColour); + } } } diff --git a/java/com/mumfrey/worldeditcui/render/ConfiguredColour.java b/java/com/mumfrey/worldeditcui/render/ConfiguredColour.java index 658800ee..e929b4be 100644 --- a/java/com/mumfrey/worldeditcui/render/ConfiguredColour.java +++ b/java/com/mumfrey/worldeditcui/render/ConfiguredColour.java @@ -30,7 +30,9 @@ public enum ConfiguredColour ELLIPSOIDCENTRE("colour.ellipsoidpoint", new Colour("#CCCC33CC")), CYLINDERGRID ("colour.cylindergrid", new Colour("#CC3333CC")), CYLINDERBOX ("colour.cylinderedge", new Colour("#CC4C4CCC")), - CYLINDERCENTRE ("colour.cylinderpoint", new Colour("#CC33CCCC")); + CYLINDERCENTRE ("colour.cylinderpoint", new Colour("#CC33CCCC")), + CHUNKBOUNDARY ("colour.chunkboundary", new Colour("#33CC33CC")), + CHUNKGRID ("colour.chunkgrid", new Colour("#4CCCAA99")); class Style implements RenderStyle { @@ -115,12 +117,17 @@ public LineStyle[] getLines() return this.lines; } - public void setDefaultColour() + public void setDefault() { this.colour.copyFrom(this.defaultColour); this.updateLines(); } + public Colour getDefault() + { + return this.defaultColour; + } + public void setColourIntRGBA(int argb) { int rgba = ((argb << 8) & 0xFFFFFF00) | (((argb & 0xFF000000) >> 24) & 0xFF); diff --git a/java/com/mumfrey/worldeditcui/render/shapes/RenderChunkBoundary.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderChunkBoundary.java new file mode 100644 index 00000000..89316d37 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderChunkBoundary.java @@ -0,0 +1,143 @@ +package com.mumfrey.worldeditcui.render.shapes; + +import static com.mumfrey.liteloader.gl.GL.*; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.chunk.Chunk; + +import com.mumfrey.worldeditcui.render.LineStyle; +import com.mumfrey.worldeditcui.render.RenderStyle; +import com.mumfrey.worldeditcui.util.Vector3; + +public class RenderChunkBoundary extends RenderRegion +{ + private final Minecraft mc; + private Render3DGrid grid; + + public RenderChunkBoundary(RenderStyle boundaryStyle, RenderStyle gridStyle, Minecraft minecraft) + { + super(boundaryStyle); + + this.mc = minecraft; + + this.grid = new Render3DGrid(gridStyle, Vector3.ZERO, Vector3.ZERO); + this.grid.setSpacing(4.0); + } + + @Override + public void render(Vector3 cameraPos) + { + double yMax = this.mc.world != null ? this.mc.world.getHeight() : 256.0; + double yMin = 0.0; + + long xBlock = MathHelper.floor(cameraPos.getX()); + long zBlock = MathHelper.floor(cameraPos.getZ()); + + int xChunk = (int)(xBlock >> 4); + int zChunk = (int)(zBlock >> 4); + + double xBase = 0 - (xBlock - (xChunk * 16)) - (cameraPos.getX() - xBlock); + double zBase = (0 - (zBlock - (zChunk * 16)) - (cameraPos.getZ() - zBlock)) + 16; + + this.grid.setPosition(new Vector3(xBase, yMin, zBase - 16), new Vector3(xBase + 16, yMax, zBase)); + + glPushMatrix(); + glTranslated(0.0, -cameraPos.getY(), 0.0); + + this.grid.render(Vector3.ZERO); + + this.renderChunkBorder(yMin, yMax, xBase, zBase); + + if (this.mc.world != null) + { + this.renderChunkBoundary(xChunk, zChunk, xBase, zBase); + } + + glPopMatrix(); + } + + private void renderChunkBorder(double yMin, double yMax, double xBase, double zBase) + { + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buf = tessellator.getBuffer(); + + int spacing = 16; + + for (LineStyle line : this.style.getLines()) + { + if (line.prepare(this.style.getRenderType())) + { + buf.begin(GL_LINES, VF_POSITION); + line.applyColour(); + + for (int x = -16; x <= 32; x += spacing) + { + for (int z = -16; z <= 32; z += spacing) + { + buf.pos(xBase + x, yMin, zBase - z).endVertex(); + buf.pos(xBase + x, yMax, zBase - z).endVertex(); + } + } + + for (double y = yMin; y <= yMax; y += yMax) + { + buf.pos(xBase, y, zBase).endVertex(); + buf.pos(xBase, y, zBase - 16).endVertex(); + buf.pos(xBase, y, zBase - 16).endVertex(); + buf.pos(xBase + 16, y, zBase - 16).endVertex(); + buf.pos(xBase + 16, y, zBase - 16).endVertex(); + buf.pos(xBase + 16, y, zBase).endVertex(); + buf.pos(xBase + 16, y, zBase).endVertex(); + buf.pos(xBase, y, zBase).endVertex(); + } + + tessellator.draw(); + } + } + } + + private void renderChunkBoundary(int xChunk, int zChunk, double xBase, double zBase) + { + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buf = tessellator.getBuffer(); + + Chunk chunk = this.mc.world.getChunkFromChunkCoords(xChunk, zChunk); + + for (LineStyle line : this.style.getLines()) + { + if (line.prepare(this.style.getRenderType())) + { + buf.begin(GL_LINES, VF_POSITION); + line.applyColour(); + + int[][] lastHeight = { { -1, -1 }, { -1, -1 } }; + for (int i = 0, height = 0; i < 16; i++) + { + for (int j = 0; j < 2; j++) + { + for (int axis = 0; axis < 2; axis++) + { + height = axis == 0 ? chunk.getHeightValue(j * 15, i) : chunk.getHeightValue(i, j * 15); + double xPos = axis == 0 ? xBase + (j * 16) : xBase + i; + double zPos = axis == 0 ? zBase - 16 + i : zBase - 16 + (j * 16); + if (lastHeight[axis][j] > -1 && height != lastHeight[axis][j]) + { + buf.pos(xPos, lastHeight[axis][j], zPos).endVertex(); + buf.pos(xPos, height, zPos).endVertex(); + } + buf.pos(xPos, height, zPos).endVertex(); + buf.pos(xPos + axis, height, zPos + (1 - axis)).endVertex(); + lastHeight[axis][j] = height; + } + } + } + + tessellator.draw(); + } + } + } + +} diff --git a/res/assets/wecui/lang/en_us.lang b/res/assets/wecui/lang/en_us.lang index c162a650..664aeb0b 100644 --- a/res/assets/wecui/lang/en_us.lang +++ b/res/assets/wecui/lang/en_us.lang @@ -2,6 +2,7 @@ wecui.options.title=WorldEditCUI Options wecui.keys.toggle=Toggle CUI visibility wecui.keys.clear=Clear WorldEdit selection +wecui.keys.chunk=Toggle Chunk Border wecui.keys.category=WorldEditCUI gui.ok=OK @@ -18,6 +19,8 @@ colour.ellipsoidpoint=Ellipsoid Centre Point Colour colour.cylindergrid=Cylinder Grid Colour colour.cylinderedge=Cylinder Edge Colour colour.cylinderpoint=Cylinder Centre Point Colour +colour.chunkboundary=Chunk Boundary +colour.chunkgrid=Chunk Grid gui.options.compat.title=Compatibility Options gui.options.compat.spammy=Promiscuous Mode (send /we cui all the time) From b973b0e1dc94d9df6a868eb94ab5d7dd548455c2 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Tue, 1 Aug 2017 18:15:03 +0100 Subject: [PATCH 45/51] Lower-case resource file names for post-1.11 compatibility --- res/assets/wecui/lang/{ru_RU.lang => ru_ru.lang} | 0 res/assets/wecui/lang/{uk_UA => uk_ua} | 0 res/assets/wecui/lang/{zh_CN.lang => zh_cn.lang} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename res/assets/wecui/lang/{ru_RU.lang => ru_ru.lang} (100%) rename res/assets/wecui/lang/{uk_UA => uk_ua} (100%) rename res/assets/wecui/lang/{zh_CN.lang => zh_cn.lang} (100%) diff --git a/res/assets/wecui/lang/ru_RU.lang b/res/assets/wecui/lang/ru_ru.lang similarity index 100% rename from res/assets/wecui/lang/ru_RU.lang rename to res/assets/wecui/lang/ru_ru.lang diff --git a/res/assets/wecui/lang/uk_UA b/res/assets/wecui/lang/uk_ua similarity index 100% rename from res/assets/wecui/lang/uk_UA rename to res/assets/wecui/lang/uk_ua diff --git a/res/assets/wecui/lang/zh_CN.lang b/res/assets/wecui/lang/zh_cn.lang similarity index 100% rename from res/assets/wecui/lang/zh_CN.lang rename to res/assets/wecui/lang/zh_cn.lang From 45af92ff9bd09bcbe6e32601cd84f996a85c4670 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Tue, 1 Aug 2017 20:04:27 +0100 Subject: [PATCH 46/51] Fix minor issues for release build --- build.gradle | 2 +- gradle.properties | 2 +- res/assets/wecui/lang/{uk_ua => uk_ua.lang} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename res/assets/wecui/lang/{uk_ua => uk_ua.lang} (100%) diff --git a/build.gradle b/build.gradle index 9eb7fb38..38a812fd 100644 --- a/build.gradle +++ b/build.gradle @@ -38,7 +38,7 @@ litemod { json { author = "yetanotherx, Mumfrey, TomyLobo" mcversion = project.targetVersion - description = "Client-side user interface for WorldEdit", + description = "Client-side user interface for WorldEdit" revision = project.revision } } diff --git a/gradle.properties b/gradle.properties index df5d792a..76e8b965 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ name=WorldEditCUI -version=1.12_00 +version=1.12_01 revision=11201 mcVersion=1.12 mcMappings=snapshot_20170627 diff --git a/res/assets/wecui/lang/uk_ua b/res/assets/wecui/lang/uk_ua.lang similarity index 100% rename from res/assets/wecui/lang/uk_ua rename to res/assets/wecui/lang/uk_ua.lang From b3983bd9b7ad0a3d830e07c02de765dbc06007a0 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Fri, 4 Aug 2017 12:55:39 +0100 Subject: [PATCH 47/51] Fix "reset" button for colours --- java/com/mumfrey/worldeditcui/config/Colour.java | 1 + 1 file changed, 1 insertion(+) diff --git a/java/com/mumfrey/worldeditcui/config/Colour.java b/java/com/mumfrey/worldeditcui/config/Colour.java index a85109a3..a1fb679c 100644 --- a/java/com/mumfrey/worldeditcui/config/Colour.java +++ b/java/com/mumfrey/worldeditcui/config/Colour.java @@ -159,6 +159,7 @@ public float alpha() public Colour copyFrom(Colour other) { this.hex = other.getHex(); + this.update(); return this; } } From db6777ac59e81af62035ba3c46c209f4a9b7140d Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Fri, 4 Aug 2017 13:24:20 +0100 Subject: [PATCH 48/51] 1.12.1 update --- gradle.properties | 10 +++++----- java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gradle.properties b/gradle.properties index 76e8b965..cac05de8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ name=WorldEditCUI -version=1.12_01 -revision=11201 -mcVersion=1.12 -mcMappings=snapshot_20170627 -targetVersion=1.12.r1 \ No newline at end of file +version=1.12.1_00 +revision=11210 +mcVersion=1.12.1 +mcMappings=snapshot_20170804 +targetVersion=1.12.r2 \ No newline at end of file diff --git a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java index 0268d2e4..0624dc09 100644 --- a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java @@ -243,7 +243,7 @@ public String getName() @Override public String getVersion() { - return "1.12_01"; + return "1.12.1_00"; } @Override From e5abb2e1c5671e35c84369b4ad0cad5e05e2ad71 Mon Sep 17 00:00:00 2001 From: Ecconia Date: Fri, 9 Feb 2018 18:55:43 +0100 Subject: [PATCH 49/51] Fixed using wrong color for second corner in CuboidRegion For corners the style[2] has always been used. Both corners got the color of the first corner. Fix: - Use "id" (is 0 or 1) plus an offset of 2 to get the corner styles. The corner styles are located in the style array at: 2 and 3. --- java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java b/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java index 09c1a67b..15d171e0 100644 --- a/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java +++ b/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java @@ -72,7 +72,7 @@ public void setCuboidPoint(int id, double x, double y, double z) { if (id < 2) { - this.points[id] = new PointCube(x, y, z).setStyle(this.styles[2]); + this.points[id] = new PointCube(x, y, z).setStyle(this.styles[id+2]); } this.updateBounds(); @@ -83,7 +83,7 @@ public void setCuboidVertexLatch(int id, Entity entity, double traceDistance) { if (id < 2) { - this.points[id] = new PointCubeTracking(entity, traceDistance).setStyle(this.styles[2]); + this.points[id] = new PointCubeTracking(entity, traceDistance).setStyle(this.styles[id+2]); } this.updateBounds(); From bdb3f5b5ea50c785467f07207c2b65d97761f3e5 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Thu, 22 Mar 2018 11:53:43 +0000 Subject: [PATCH 50/51] Bump version for cuboid colour fixes --- gradle.properties | 2 +- java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index cac05de8..a3615f18 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ name=WorldEditCUI -version=1.12.1_00 +version=1.12.1_01 revision=11210 mcVersion=1.12.1 mcMappings=snapshot_20170804 diff --git a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java index 0624dc09..21131161 100644 --- a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java @@ -243,7 +243,7 @@ public String getName() @Override public String getVersion() { - return "1.12.1_00"; + return "1.12.1_01"; } @Override From 04aeacfac992b6b10082b171881f1e7eade24322 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Thu, 22 Mar 2018 14:53:04 +0000 Subject: [PATCH 51/51] Add option to clear server-defined regions locally using key, closes #21 --- .../worldeditcui/LiteModWorldEditCUI.java | 10 ++++- .../worldeditcui/config/CUIConfiguration.java | 11 ++++++ .../worldeditcui/gui/CUIConfigPanel.java | 37 +++++++++++++------ res/assets/wecui/lang/en_us.lang | 4 ++ 4 files changed, 48 insertions(+), 14 deletions(-) diff --git a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java index 21131161..3d26144f 100644 --- a/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java +++ b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java @@ -170,13 +170,15 @@ public void onCustomPayload(String channel, PacketBuffer data) @Override public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clock) { + CUIConfiguration config = this.controller.getConfiguration(); + if (inGame && mc.currentScreen == null) { + if (this.keyBindToggleUI.isPressed()) { if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) { - CUIConfiguration config = this.controller.getConfiguration(); config.setAlwaysOnTop(!config.isAlwaysOnTop()); } else @@ -191,6 +193,11 @@ public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clo { mc.player.sendChatMessage("//sel"); } + + if (config.isClearAllOnKey()) + { + this.controller.clearRegions(); + } } if (this.keyBindChunkBorder.isPressed()) @@ -201,7 +208,6 @@ public void onTick(Minecraft mc, float partialTicks, boolean inGame, boolean clo if (inGame && clock && this.controller != null) { - CUIConfiguration config = this.controller.getConfiguration(); this.alwaysOnTop = config.isAlwaysOnTop(); if (mc.world != this.lastWorld || mc.player != this.lastPlayer) diff --git a/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java b/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java index 10b540e3..d7ea0103 100644 --- a/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java +++ b/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java @@ -29,6 +29,7 @@ public final class CUIConfiguration implements InitialisationFactory @Expose private boolean ignoreUpdates = false; @Expose private boolean promiscuous = false; @Expose private boolean alwaysOnTop = false; + @Expose private boolean clearAllOnKey = false; @Expose private Colour cuboidGridColor = ConfiguredColour.CUBOIDBOX.getDefault(); @Expose private Colour cuboidEdgeColor = ConfiguredColour.CUBOIDGRID.getDefault(); @@ -104,6 +105,16 @@ public void setAlwaysOnTop(boolean alwaysOnTop) this.alwaysOnTop = alwaysOnTop; } + public boolean isClearAllOnKey() + { + return this.clearAllOnKey; + } + + public void setClearAllOnKey(boolean clearAllOnKey) + { + this.clearAllOnKey = clearAllOnKey; + } + public static CUIConfiguration create() { File jsonFile = new File(LiteLoader.getCommonConfigFolder(), CUIConfiguration.CONFIG_FILE_NAME); diff --git a/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java b/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java index 1ad9af87..49b6434a 100644 --- a/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java +++ b/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java @@ -25,8 +25,14 @@ */ public class CUIConfigPanel extends Gui implements ConfigPanel { + + private static final int COLOUR_OPTION_BASE_ID = 100; + private static final int CONTROL_SPACING = 24; private static final int CONTROL_TOP = 80; + private static final int CONTROLS_PADDING = 10; + private static final int EXTRA_CONTROLS_SPACING = 16; + private static final int EXTRA_CONTROLS_HEIGHT = CUIConfigPanel.EXTRA_CONTROLS_SPACING * 2; private Minecraft mc; @@ -38,7 +44,9 @@ public class CUIConfigPanel extends Gui implements ConfigPanel private GuiButton activeControl; - private GuiCheckbox chkPromiscuous, chkAlwaysOnTop; + private GuiCheckbox chkPromiscuous, chkAlwaysOnTop, chkClearAll; + + private int colourButtonsBottom; public CUIConfigPanel() { @@ -54,7 +62,7 @@ public String getPanelTitle() @Override public int getContentHeight() { - return ConfiguredColour.values().length * CUIConfigPanel.CONTROL_SPACING + CUIConfigPanel.CONTROL_TOP; + return this.colourButtonsBottom + CUIConfigPanel.EXTRA_CONTROLS_HEIGHT + CUIConfigPanel.CONTROLS_PADDING; } @Override @@ -62,32 +70,35 @@ public void onPanelShown(ConfigPanelHost host) { this.mod = host.getMod(); - ScaledResolution scaledresolution = new ScaledResolution(this.mc); - GuiControl.setScreenSizeAndScale(host.getWidth(), this.getContentHeight(), scaledresolution.getScaleFactor()); - this.controlList.clear(); int nextId = 0; - int top = CUIConfigPanel.CONTROL_TOP; - for (ConfiguredColour colour : ConfiguredColour.values()) { - this.controlList.add(new GuiColourButton(this.mc, nextId, 24, top + nextId * CUIConfigPanel.CONTROL_SPACING, 40, 20, colour)); - this.controlList.add(new GuiControl(this.mc, 100 + nextId, 234, top + nextId * CUIConfigPanel.CONTROL_SPACING, 60, 20, "Reset")); + this.controlList.add(new GuiColourButton(this.mc, nextId, 24, CUIConfigPanel.CONTROL_TOP + nextId * CUIConfigPanel.CONTROL_SPACING, 40, 20, colour)); + this.controlList.add(new GuiControl(this.mc, CUIConfigPanel.COLOUR_OPTION_BASE_ID + nextId, 234, CUIConfigPanel.CONTROL_TOP + nextId * CUIConfigPanel.CONTROL_SPACING, 60, 20, "Reset")); nextId++; } + this.colourButtonsBottom = CUIConfigPanel.CONTROL_TOP + nextId * CUIConfigPanel.CONTROL_SPACING + CUIConfigPanel.EXTRA_CONTROLS_SPACING; this.controlList.add(this.chkPromiscuous = new GuiCheckbox(nextId, 24, 26, I18n.format("gui.options.compat.spammy"))); this.controlList.add(this.chkAlwaysOnTop = new GuiCheckbox(nextId, 24, 42, I18n.format("gui.options.compat.ontop"))); + this.controlList.add(this.chkClearAll = new GuiCheckbox(nextId, 24, this.colourButtonsBottom + CUIConfigPanel.EXTRA_CONTROLS_SPACING, I18n.format("gui.options.extra.clearall"))); for (GuiButton control : this.controlList) { if (control instanceof GuiColourButton) + { this.colourButtonList.add((GuiColourButton)control); + } } CUIConfiguration config = this.mod.getController().getConfiguration(); this.chkPromiscuous.checked = config.isPromiscuous(); this.chkAlwaysOnTop.checked = config.isAlwaysOnTop(); + this.chkClearAll.checked = config.isClearAllOnKey(); + + ScaledResolution scaledresolution = new ScaledResolution(this.mc); + GuiControl.setScreenSizeAndScale(host.getWidth(), this.getContentHeight(), scaledresolution.getScaleFactor()); } @Override @@ -106,6 +117,7 @@ public void onPanelHidden() CUIConfiguration config = this.mod.getController().getConfiguration(); config.setPromiscuous(this.chkPromiscuous.checked); config.setAlwaysOnTop(this.chkAlwaysOnTop.checked); + config.setClearAllOnKey(this.chkClearAll.checked); config.save(); } @@ -117,8 +129,9 @@ public void onTick(ConfigPanelHost host) @Override public void drawPanel(ConfigPanelHost host, int mouseX, int mouseY, float partialTicks) { - this.drawString(this.mc.fontRenderer, I18n.format("gui.options.compat.title"), 10, 10, 0xFFFFFF55); + this.drawString(this.mc.fontRenderer, I18n.format("gui.options.compat.title"), 10, CUIConfigPanel.CONTROLS_PADDING, 0xFFFFFF55); this.drawString(this.mc.fontRenderer, I18n.format("gui.options.colours.title"), 10, 64, 0xFFFFFF55); + this.drawString(this.mc.fontRenderer, I18n.format("gui.options.extra.title"), 10, this.colourButtonsBottom, 0xFFFFFF55); for (GuiButton control : this.controlList) { @@ -158,9 +171,9 @@ private void actionPerformed(GuiButton control) chk.checked = !chk.checked; } - if (control.id >= 100) + if (control.id >= CUIConfigPanel.COLOUR_OPTION_BASE_ID) { - ConfiguredColour lineColour = ConfiguredColour.values()[control.id - 100]; + ConfiguredColour lineColour = ConfiguredColour.values()[control.id - CUIConfigPanel.COLOUR_OPTION_BASE_ID]; lineColour.setDefault(); for (GuiColourButton colourButton : this.colourButtonList) diff --git a/res/assets/wecui/lang/en_us.lang b/res/assets/wecui/lang/en_us.lang index 664aeb0b..63b6d0c9 100644 --- a/res/assets/wecui/lang/en_us.lang +++ b/res/assets/wecui/lang/en_us.lang @@ -25,5 +25,9 @@ colour.chunkgrid=Chunk Grid gui.options.compat.title=Compatibility Options gui.options.compat.spammy=Promiscuous Mode (send /we cui all the time) gui.options.compat.ontop=Always on top (mod compatibility) + gui.options.colours.title=Display Colours +gui.options.extra.title=Advanced Options +gui.options.extra.clearall=Clear displayed regions when <§aClear§r> is pressed +