diff --git a/.gitignore b/.gitignore index 740dbd77..96854677 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,17 @@ -/target -/run* -/build.sh -/minecraft.jar -/repackaging/ - -# Compiled source # -################### +# Build # +######### +MANIFEST.MF +dependency-reduced-pom.xml + +# Compiled # +############ +bin +build +dist +lib +out +run +target *.com *.class *.dll @@ -13,30 +19,60 @@ *.o *.so +# Databases # +############# +*.db +*.sql +*.sqlite + # 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 # -###################### +# Repository # +############## +.git + +# Logging # +########### +/logs *.log -*.sql -*.sqlite -# OS generated files # -###################### -.DS_Store* +# Misc # +######## +*.bak + +# System # +########## +.DS_Store ehthumbs.db -Icon? Thumbs.db +*.bat +*.sh -*.howto +# 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/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..11666a40 100644 --- a/README.md +++ b/README.md @@ -1,93 +1,31 @@ -WorldEditCUI ------------- - -A graphical user interface for WorldEdit. WorldEditCUI is designed -to assist in using WorldEdit, as well as preventing accidental errors. - -Please note that this is not WorldEdit, which allows you to make changes -to your world, but WorldEditCUI, a frontend for WorldEdit. You must have -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. - -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 -------- - - * [lahwran](https://github.com/lahwran) - Creator of the original WorldEdit CUI! - * [sk89q](http://sk89q.com) for writing the WorldEdit plugin! - * TomyLobo and zml2008 for maintaining WorldEdit! - * [Apache Commons](http://commons.apache.org/) for the join() methods! - * [Mojang](http://mojang.com) - for making such an awesome game! - - -Legal stuff ------------ - +WorldEditCUI +------------ + +A graphical user interface for WorldEdit. WorldEditCUI is designed +to assist in using WorldEdit, as well as preventing accidental errors. + +Please note that this is not WorldEdit, which allows you to make changes +to your world, but WorldEditCUI, a frontend for WorldEdit. You must have +WorldEdit installed on your server or in SinglePlayerCommands to use this mod. + + +Compiling +--------- + +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. + + +Credits +------- + + * [lahwran](https://github.com/lahwran) - Creator of the original WorldEdit CUI! + * [sk89q](http://sk89q.com) for writing the WorldEdit plugin! + * TomyLobo and zml2008 for maintaining WorldEdit! + * [Apache Commons](http://commons.apache.org/) for the join() methods! + * [Mojang](http://mojang.com) - for making such an awesome game! + + +Legal stuff +----------- + This code is licensed under the Eclipse Public License. \ No newline at end of file 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.gradle b/build.gradle new file mode 100644 index 00000000..38a812fd --- /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.3-SNAPSHOT' + } +} + +apply plugin: 'net.minecraftforge.gradle.liteloader' + +group = "com.mumfrey.worldeditcui" +archivesBaseName = "worldeditcui" + +minecraft { + version = project.mcVersion + mappings = project.mcMappings + runDir = "run" +} + +sourceSets { + main { + java.srcDir 'java' + resources.srcDir 'res' + } +} + +litemod { + json { + author = "yetanotherx, Mumfrey, TomyLobo" + mcversion = project.targetVersion + description = "Client-side user interface for WorldEdit" + revision = project.revision + } +} + +jar { + from litemod.outputs +} 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/gradle.properties b/gradle.properties new file mode 100644 index 00000000..a3615f18 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,6 @@ +name=WorldEditCUI +version=1.12.1_01 +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/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/LiteModWorldEditCUI.java b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java new file mode 100644 index 00000000..3d26144f --- /dev/null +++ b/java/com/mumfrey/worldeditcui/LiteModWorldEditCUI.java @@ -0,0 +1,285 @@ +package com.mumfrey.worldeditcui; + +import io.netty.buffer.Unpooled; + +import java.io.File; +import java.util.List; + +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.renderer.RenderHelper; +import net.minecraft.client.settings.KeyBinding; +import net.minecraft.network.INetHandler; +import net.minecraft.network.PacketBuffer; +import net.minecraft.network.play.server.SPacketJoinGame; + +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; +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; +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; +import com.mumfrey.worldeditcui.gui.CUIConfigPanel; + +/** + * 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; + + private static final String CHANNEL_WECUI = "WECUI"; + + 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 KeyBinding keyBindChunkBorder = new KeyBinding("wecui.keys.chunk", Keyboard.KEY_NONE, "wecui.keys.category"); + + private boolean visible = true; + private boolean alwaysOnTop = false; + + private CUIListenerWorldRender worldRenderListener; + private CUIListenerChannel channelListener; + + private int delayedHelo = 0; + + @Override + public void init(File configPath) + { + Input input = LiteLoader.getInput(); + input.registerKeyBinding(this.keyBindToggleUI); + input.registerKeyBinding(this.keyBindClearSel); + input.registerKeyBinding(this.keyBindChunkBorder); + } + + @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.initialise(minecraft); + + this.worldRenderListener = new CUIListenerWorldRender(this.controller, minecraft); + this.channelListener = new CUIListenerChannel(this.controller); + } + + @Override + public void onJoinGame(INetHandler netHandler, SPacketJoinGame loginPacket, ServerData serverData, RealmsServer realmsServer) + { + this.visible = true; + this.controller.getDebugger().debug("Joined game, sending initial handshake"); + this.helo(); + } + + /** + * + */ + private void helo() + { + PacketBuffer buffer = new PacketBuffer(Unpooled.buffer()); + String message = "v|" + WorldEditCUI.PROTOCOL_VERSION; + buffer.writeBytes(message.getBytes(Charsets.UTF_8)); + 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 ImmutableList.of(LiteModWorldEditCUI.CHANNEL_WECUI); + } + + @Override + public void onCustomPayload(String channel, PacketBuffer data) + { + try + { + 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) {} + } + + @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)) + { + config.setAlwaysOnTop(!config.isAlwaysOnTop()); + } + else + { + this.visible = !this.visible; + } + } + + if (this.keyBindClearSel.isPressed()) + { + if (mc.player != null) + { + mc.player.sendChatMessage("//sel"); + } + + if (config.isClearAllOnKey()) + { + this.controller.clearRegions(); + } + } + + if (this.keyBindChunkBorder.isPressed()) + { + this.controller.toggleChunkBorders(); + } + } + + if (inGame && clock && this.controller != null) + { + this.alwaysOnTop = config.isAlwaysOnTop(); + + if (mc.world != this.lastWorld || mc.player != this.lastPlayer) + { + this.lastWorld = mc.world; + this.lastPlayer = mc.player; + + this.controller.getDebugger().debug("World change detected, sending new handshake"); + this.controller.clear(); + this.helo(); + this.delayedHelo = LiteModWorldEditCUI.DELAYED_HELO_TICKS; + if (mc.player != null && config.isPromiscuous()) + { + mc.player.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.player != null) + { + mc.player.sendChatMessage("/we cui"); + } + } + } + } + } + + @Override + public String getName() + { + return "WorldEditCUI"; + } + + @Override + public String getVersion() + { + return "1.12.1_01"; + } + + @Override + public Class getConfigPanelClass() + { + return CUIConfigPanel.class; + } + + @Override + public void onPostRenderEntities(float partialTicks) + { + if (this.visible && !this.alwaysOnTop) + { + RenderHelper.disableStandardItemLighting(); + this.worldRenderListener.onRender(partialTicks); + RenderHelper.enableStandardItemLighting(); + } + } + + @Override + public void onPostRender(float partialTicks) + { + if (this.visible && this.alwaysOnTop) + { + this.worldRenderListener.onRender(partialTicks); + } + } + + public WorldEditCUI getController() + { + return this.controller; + } +} diff --git a/java/com/mumfrey/worldeditcui/WorldEditCUI.java b/java/com/mumfrey/worldeditcui/WorldEditCUI.java new file mode 100644 index 00000000..971e9ae1 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/WorldEditCUI.java @@ -0,0 +1,152 @@ +package com.mumfrey.worldeditcui; + +import java.util.LinkedHashMap; +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; + +/** + * Main controller class. Uses a pseudo-JavaBeans paradigm. The only real + * logic here is listener registration. + * + * TODO: Preview mode + * TODO: Command transactions + * TODO: Add ability to flash selection + * + * @author yetanotherx + * @author Adam Mummery-Smith + */ +public class WorldEditCUI +{ + public static final int PROTOCOL_VERSION = 4; + + private final Map regions = new LinkedHashMap(); + private Region selection, activeRegion; + private CUIDebug debugger; + private CUIConfiguration configuration; + private CUIEventDispatcher dispatcher; + private CUISelectionProvider selectionProvider; + private RenderChunkBoundary chunkBorderRenderer; + private boolean chunkBorders; + + 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(); + this.configuration.initialise(); + this.debugger.initialise(); + this.dispatcher.initialise(); + this.selectionProvider.initialise(); + } + catch (InitialisationException e) + { + e.printStackTrace(); + return; + } + + this.chunkBorderRenderer = new RenderChunkBoundary(ConfiguredColour.CHUNKBOUNDARY.style(), ConfiguredColour.CHUNKGRID.style(), minecraft); + } + + public CUIEventDispatcher getDispatcher() + { + return this.dispatcher; + } + + public CUISelectionProvider getSelectionProvider() + { + return this.selectionProvider; + } + + public CUIConfiguration getConfiguration() + { + return this.configuration; + } + + public CUIDebug getDebugger() + { + return this.debugger; + } + + 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 multi ? this.activeRegion : this.selection; + } + + public void setSelection(UUID id, Region region) + { + 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, float partialTicks) + { + if (this.selection != null) + { + this.selection.render(cameraPos, partialTicks); + } + + for (Region region : this.regions.values()) + { + 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 new file mode 100644 index 00000000..d7ea0103 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/config/CUIConfiguration.java @@ -0,0 +1,176 @@ +package com.mumfrey.worldeditcui.config; + +import java.io.File; +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; + +/** + * Stores and reads WorldEditCUI settings + * + * @author yetanotherx + * @author Adam Mummery-Smith + */ +public final class CUIConfiguration implements InitialisationFactory +{ + private static final String CONFIG_FILE_NAME = "worldeditcui.config.json"; + + private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + + @Expose private boolean debugMode = false; + @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(); + @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 + * exist. It then reads the file and sets each variable to the proper value. + */ + @Override + public void initialise() + { + 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(); + } + + public boolean isDebugMode() + { + return this.debugMode; + } + + public boolean ignoreUpdates() + { + return this.ignoreUpdates; + } + + public boolean isPromiscuous() + { + return this.promiscuous; + } + + public void setPromiscuous(boolean promiscuous) + { + this.promiscuous = promiscuous; + } + + public boolean isAlwaysOnTop() + { + return this.alwaysOnTop; + } + + 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); + + if (jsonFile.exists()) + { + FileReader fileReader = null; + + try + { + fileReader = new FileReader(jsonFile); + CUIConfiguration config = CUIConfiguration.GSON.fromJson(fileReader, CUIConfiguration.class); + return config; + } + catch (Exception 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 (Exception ex) + { + ex.printStackTrace(); + } + finally + { + try + { + if (fileWriter != null) fileWriter.close(); + } + catch (IOException ex) + { + ex.printStackTrace(); + } + } + } +} diff --git a/java/com/mumfrey/worldeditcui/config/Colour.java b/java/com/mumfrey/worldeditcui/config/Colour.java new file mode 100644 index 00000000..a1fb679c --- /dev/null +++ b/java/com/mumfrey/worldeditcui/config/Colour.java @@ -0,0 +1,165 @@ +package com.mumfrey.worldeditcui.config; + +/** + * @author Adam Mummery-Smith + */ +public class Colour +{ + private String hex; + private transient int argb; + private transient float a, r, g, b; + private transient String defaultColour; + private transient boolean woken; + + public Colour(String colour) + { + this.hex = this.defaultColour = colour; + this.update(); + } + + public Colour() + { + } + + 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) + { + return new Colour(defaultColour); + } + + if (colour.hex == null) + { + colour.hex = defaultColour; + colour.defaultColour = defaultColour; + } + else + { + colour.hex = Colour.sanitiseColour(colour.hex, defaultColour); + } + + return colour; + } + + /** + * 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 colour + * @param def + * @return + */ + private static String sanitiseColour(String colour, String def) + { + if (colour == null) + { + return def; + } + else if (!colour.startsWith("#")) + { + return def; + } + else if (colour.length() != 7 && colour.length() != 9) + { + return def; + } + + 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; + } + + 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; + } + + private void update() + { + String hex = this.getHex(); + 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() + { + if (!this.woken) + { + this.update(); + } + + return this.r; + } + + public float green() + { + if (!this.woken) + { + this.update(); + } + + return this.g; + } + + public float blue() + { + if (!this.woken) + { + this.update(); + } + + return this.b; + } + + public float alpha() + { + if (!this.woken) + { + this.update(); + } + + return this.a; + } + + public Colour copyFrom(Colour other) + { + this.hex = other.getHex(); + this.update(); + return this; + } +} diff --git a/java/com/mumfrey/worldeditcui/debug/CUIDebug.java b/java/com/mumfrey/worldeditcui/debug/CUIDebug.java new file mode 100644 index 00000000..b690c7a8 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/debug/CUIDebug.java @@ -0,0 +1,88 @@ +package com.mumfrey.worldeditcui.debug; + +import java.io.File; +import java.io.IOException; +import java.util.logging.ConsoleHandler; +import java.util.logging.FileHandler; +import java.util.logging.Level; +import java.util.logging.Logger; + +import com.mumfrey.liteloader.core.LiteLoader; +import com.mumfrey.worldeditcui.InitialisationFactory; +import com.mumfrey.worldeditcui.WorldEditCUI; +import com.mumfrey.worldeditcui.exceptions.InitialisationException; +import com.mumfrey.worldeditcui.util.ConsoleLogFormatter; + +/** + * Debugging helper class + * + * @author yetanotherx + * @author Adam Mummery-Smith + */ +public final class CUIDebug implements InitialisationFactory +{ + private static final Logger logger = Logger.getLogger("WorldEditCUI"); + + private final WorldEditCUI controller; + private File debugFile; + private boolean debugMode = false; + + public CUIDebug(WorldEditCUI controller) + { + this.controller = controller; + } + + @Override + public void initialise() throws InitialisationException + { + + ConsoleLogFormatter formatter = new ConsoleLogFormatter(); + ConsoleHandler handler = new ConsoleHandler(); + handler.setFormatter(formatter); + + CUIDebug.logger.setUseParentHandlers(false); + CUIDebug.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); + CUIDebug.logger.addHandler(newHandler); + } + + } + catch (IOException e) + { + e.printStackTrace(System.err); + throw new InitialisationException(); + } + + } + + /** + * Shows a message if debug mode is true + * @param message + */ + public void debug(String message) + { + if (this.debugMode) + { + CUIDebug.logger.info("WorldEditCUI Debug - " + message); + } + } + + public void info(String message) + { + CUIDebug.logger.info(message); + } + + public void info(String message, Throwable 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 new file mode 100644 index 00000000..e7412605 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/event/CUIEvent.java @@ -0,0 +1,100 @@ +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 + * @author Adam Mummery-Smith + */ +public abstract class CUIEvent +{ + protected final WorldEditCUI controller; + protected final String[] params; + protected final boolean multi; + + public CUIEvent(CUIEventArgs args) + { + this.controller = args.getController(); + this.params = args.getParams(); + this.multi = args.isMulti(); + } + + 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.params.length != max) + { + return false; + } + } + else + { + if (this.params.length > max || this.params.length < min) + { + return false; + } + } + + return true; + + } + + public void prepare() + { + 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.params.length, Joiner.on(", ").join(this.params)); + 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.params[index]); + } + + public double getDouble(int index) + { + return Double.parseDouble(this.params[index]); + } + + public String getString(int index) + { + return this.params[index]; + } +} diff --git a/java/com/mumfrey/worldeditcui/event/CUIEventArgs.java b/java/com/mumfrey/worldeditcui/event/CUIEventArgs.java new file mode 100644 index 00000000..631cc25a --- /dev/null +++ b/java/com/mumfrey/worldeditcui/event/CUIEventArgs.java @@ -0,0 +1,55 @@ +package com.mumfrey.worldeditcui.event; + +import com.google.common.base.Joiner; +import com.mumfrey.worldeditcui.WorldEditCUI; + +/** + * CUI communication event + * Called when a CUI event is sent from the server. + * + * @author lahwran + * @author yetanotherx + * @author Adam Mummery-Smith + */ +public final class CUIEventArgs +{ + private WorldEditCUI controller; + private boolean multi; + private String type; + private 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) + { + params = new String[] {}; + } + + this.params = params; + this.controller.getDebugger().debug("CUI Event (" + type + ") - Params: " + Joiner.on(", ").join(params)); + } + + public WorldEditCUI getController() + { + return this.controller; + } + + public String[] getParams() + { + return this.params; + } + + 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 new file mode 100644 index 00000000..f26b6929 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/event/CUIEventDispatcher.java @@ -0,0 +1,75 @@ +package com.mumfrey.worldeditcui.event; + +import java.lang.reflect.Constructor; +import java.util.HashMap; +import java.util.Map; + +import com.mumfrey.worldeditcui.InitialisationFactory; +import com.mumfrey.worldeditcui.WorldEditCUI; +import com.mumfrey.worldeditcui.exceptions.InitialisationException; + +/** + * @author Adam Mummery-Smith + */ +public class CUIEventDispatcher implements InitialisationFactory +{ + private WorldEditCUI controller; + + private Map> eventConstructors = new HashMap>(); + + public CUIEventDispatcher(WorldEditCUI controller) + { + this.controller = controller; + } + + @Override + public void initialise() throws InitialisationException + { + for (CUIEventType eventType : CUIEventType.values()) + { + try + { + Class eventClass = eventType.getEventClass(); + 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()); + } + } + } + + public void raiseEvent(CUIEventArgs eventArgs) + { + try + { + Constructor eventCtor = this.eventConstructors.get(eventArgs.getType()); + if (eventCtor == null) + { + this.controller.getDebugger().debug("No such event " + eventArgs.getType()); + return; + } + + CUIEvent event = eventCtor.newInstance(eventArgs); + event.prepare(); + + String response = event.raise(); + if (response != null) + { + this.handleEventResponse(response); + } + } + 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..c0d114b1 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/event/CUIEventType.java @@ -0,0 +1,81 @@ +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; +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 + * @author Adam Mummery-Smith + */ +public enum CUIEventType +{ + 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), + COLOUR (CUIEventColour.class, "col", 4 ), + GRID (CUIEventGrid.class, "grid", 1, 2 ); + + 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/com/mumfrey/worldeditcui/event/cui/CUIEventBounds.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventBounds.java new file mode 100644 index 00000000..06def89d --- /dev/null +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventBounds.java @@ -0,0 +1,45 @@ +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 resize event is received + * + * @author lahwran + * @author yetanotherx + * @author Adam Mummery-Smith + */ +public class CUIEventBounds extends CUIEvent +{ + public CUIEventBounds(CUIEventArgs args) + { + super(args); + } + + @Override + public CUIEventType getEventType() + { + return CUIEventType.MINMAX; + } + + @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); + 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..025f7b02 --- /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.CustomStyle; +import com.mumfrey.worldeditcui.render.RenderStyle; +import com.mumfrey.worldeditcui.render.region.Region; + +/** + * Called when style 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; + } + + RenderStyle[] defaultStyles = selection.getDefaultStyles(); + RenderStyle[] styles = new RenderStyle[defaultStyles.length]; + + for (int i = 0; i < defaultStyles.length; i++) + { + String str = this.getString(i); + if (!str.startsWith("#")) + { + str = "#" + str; + } + styles[i] = new CustomStyle(Colour.parse(str, defaultStyles[i].getColour())); + + } + + selection.setStyles(styles); + return null; + } +} diff --git a/java/com/mumfrey/worldeditcui/event/cui/CUIEventCylinder.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventCylinder.java new file mode 100644 index 00000000..008d9876 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventCylinder.java @@ -0,0 +1,51 @@ +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 cylinder event is received + * + * @author lahwran + * @author yetanotherx + * @author Adam Mummery-Smith + */ +public class CUIEventCylinder extends CUIEvent +{ + public CUIEventCylinder(CUIEventArgs args) + { + super(args); + } + + @Override + public CUIEventType getEventType() + { + return CUIEventType.CYLINDER; + } + + @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); + int z = this.getInt(2); + double radX = this.getDouble(3); + double radZ = this.getDouble(4); + + selection.setCylinderCenter(x, y, z); + selection.setCylinderRadius(radX, radZ); + + 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 new file mode 100644 index 00000000..e07d2824 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventEllipsoid.java @@ -0,0 +1,60 @@ +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 ellipsoid event is received + * + * @author lahwran + * @author yetanotherx + * @author Adam Mummery-Smith + */ +public class CUIEventEllipsoid extends CUIEvent +{ + public CUIEventEllipsoid(CUIEventArgs args) + { + super(args); + } + + @Override + public CUIEventType getEventType() + { + return CUIEventType.ELLIPSOID; + } + + @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 (id == 0) + { + int x = this.getInt(1); + int y = this.getInt(2); + int z = this.getInt(3); + selection.setEllipsoidCenter(x, y, z); + } + else if (id == 1) + { + double x = this.getDouble(1); + double y = this.getDouble(2); + double z = this.getDouble(3); + selection.setEllipsoidRadii(x, y, z); + } + + this.controller.getDebugger().debug("Setting centre/radius"); + + return null; + } +} 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..8abe9b47 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventGrid.java @@ -0,0 +1,59 @@ +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.RenderStyle.RenderType; +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)); + + 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/event/cui/CUIEventPoint2D.java b/java/com/mumfrey/worldeditcui/event/cui/CUIEventPoint2D.java new file mode 100644 index 00000000..39a39ff0 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventPoint2D.java @@ -0,0 +1,48 @@ +package com.mumfrey.worldeditcui.event.cui; + +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(CUIEventArgs args) + { + super(args); + } + + @Override + public CUIEventType getEventType() + { + return CUIEventType.POINT2D; + } + + @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); + selection.setPolygonPoint(id, x, z); + + this.controller.getDebugger().debug("Setting point2d #" + id); + + return null; + } +} 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..a69c5870 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventPoint3D.java @@ -0,0 +1,62 @@ +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; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.Entity; + +/** + * Called when point event is received + * + * @author lahwran + * @author yetanotherx + * @author Adam Mummery-Smith + */ +public class CUIEventPoint3D extends CUIEvent +{ + public CUIEventPoint3D(CUIEventArgs args) + { + super(args); + } + + @Override + public CUIEventType getEventType() + { + return CUIEventType.POINT; + } + + @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))) + { + 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; + } + + double x = this.getDouble(1); + double y = this.getDouble(2); + double z = this.getDouble(3); + + 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 new file mode 100644 index 00000000..6ca7d863 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventPolygon.java @@ -0,0 +1,49 @@ +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 polygon event is received + * + * @author lahwran + * @author yetanotherx + * @author Adam Mummery-Smith + */ +public class CUIEventPolygon extends CUIEvent +{ + public CUIEventPolygon(CUIEventArgs args) + { + super(args); + } + + @Override + public CUIEventType getEventType() + { + return CUIEventType.POLYGON; + } + + @Override + public String raise() + { + 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); + } + + 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 new file mode 100644 index 00000000..56291398 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/event/cui/CUIEventSelection.java @@ -0,0 +1,59 @@ +package com.mumfrey.worldeditcui.event.cui; + +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.Region; + +/** + * Called when selection event is received + * + * @author lahwran + * @author yetanotherx + * @author Adam Mummery-Smith + */ +public class CUIEventSelection extends CUIEvent +{ + public CUIEventSelection(CUIEventArgs args) + { + super(args); + } + + @Override + public CUIEventType getEventType() + { + return CUIEventType.SELECTION; + } + + @Override + public String raise() + { + String key = this.getString(0); + Region selection = this.controller.getSelectionProvider().createSelection(key); + + if (selection != null) + { + selection.initialise(); + } + + 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 new file mode 100644 index 00000000..d37665e5 --- /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.event.CUIEvent; +import com.mumfrey.worldeditcui.event.CUIEventArgs; +import com.mumfrey.worldeditcui.event.CUIEventType; + +/** + * Called when update event is received + * + * @author lahwran + * @author yetanotherx + * @author Adam Mummery-Smith + */ +public class CUIEventUpdate extends CUIEvent +{ + public CUIEventUpdate(CUIEventArgs args) + { + super(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..ab926709 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerChannel.java @@ -0,0 +1,41 @@ +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 + * @author Adam Mummery-Smith + */ +public class CUIListenerChannel +{ + private WorldEditCUI controller; + + public CUIListenerChannel(WorldEditCUI controller) + { + this.controller = controller; + } + + public void onMessage(String message) + { + 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, 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 new file mode 100644 index 00000000..1e1f3b44 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/event/listeners/CUIListenerWorldRender.java @@ -0,0 +1,65 @@ +package com.mumfrey.worldeditcui.event.listeners; + +import static com.mumfrey.liteloader.gl.GL.*; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.OpenGlHelper; + +import com.mumfrey.worldeditcui.WorldEditCUI; +import com.mumfrey.worldeditcui.util.Vector3; + +/** + * Listener for WorldRenderEvent + * + * @author lahwran + * @author yetanotherx + * @author Adam Mummery-Smith + */ +public class CUIListenerWorldRender +{ + private WorldEditCUI controller; + + private Minecraft minecraft; + + public CUIListenerWorldRender(WorldEditCUI controller, Minecraft minecraft) + { + this.controller = controller; + this.minecraft = minecraft; + } + + public void onRender(float partialTicks) + { + try + { + 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 + { + Vector3 cameraPos = new Vector3(this.minecraft.getRenderViewEntity(), partialTicks); + glColor4f(1.0F, 1.0F, 1.0F, 0.5F); + this.controller.renderSelections(cameraPos, partialTicks); + } + catch (Exception e) + { + } + + glDepthFunc(GL_LEQUAL); + glPopMatrix(); + + glDepthMask(true); + glEnableTexture2D(); + glDisableBlend(); + glAlphaFunc(GL_GREATER, 0.1F); + } + catch (Exception ex) {} + } +} diff --git a/java/com/mumfrey/worldeditcui/exceptions/InitialisationException.java b/java/com/mumfrey/worldeditcui/exceptions/InitialisationException.java new file mode 100644 index 00000000..93b7d215 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/exceptions/InitialisationException.java @@ -0,0 +1,23 @@ +package com.mumfrey.worldeditcui.exceptions; + +/** + * Special exception that only gets called during initialisation + * Throwing this halts the loading of the mod + * + * @author yetanotherx + * + */ +public class InitialisationException extends Exception +{ + + private static final long serialVersionUID = 1L; + + public InitialisationException(String string) + { + super(string); + } + + public InitialisationException() + { + } +} 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/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java b/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java new file mode 100644 index 00000000..49b6434a --- /dev/null +++ b/java/com/mumfrey/worldeditcui/gui/CUIConfigPanel.java @@ -0,0 +1,215 @@ +package com.mumfrey.worldeditcui.gui; + +import java.util.ArrayList; +import java.util.List; + +import org.lwjgl.input.Keyboard; + +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.ConfiguredColour; + +/** + * @author Adam Mummery-Smith + */ +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; + + private LiteModWorldEditCUI mod; + + private List controlList = new ArrayList(); + + private List colourButtonList = new ArrayList(); + + private GuiButton activeControl; + + private GuiCheckbox chkPromiscuous, chkAlwaysOnTop, chkClearAll; + + private int colourButtonsBottom; + + public CUIConfigPanel() + { + this.mc = Minecraft.getMinecraft(); + } + + @Override + public String getPanelTitle() + { + return I18n.format("wecui.options.title"); + } + + @Override + public int getContentHeight() + { + return this.colourButtonsBottom + CUIConfigPanel.EXTRA_CONTROLS_HEIGHT + CUIConfigPanel.CONTROLS_PADDING; + } + + @Override + public void onPanelShown(ConfigPanelHost host) + { + this.mod = host.getMod(); + + this.controlList.clear(); + int nextId = 0; + for (ConfiguredColour colour : ConfiguredColour.values()) + { + 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 + public void onPanelResize(ConfigPanelHost host) + { + } + + @Override + public void onPanelHidden() + { + for (GuiColourButton colourButton : this.colourButtonList) + { + colourButton.save(); + } + + CUIConfiguration config = this.mod.getController().getConfiguration(); + config.setPromiscuous(this.chkPromiscuous.checked); + config.setAlwaysOnTop(this.chkAlwaysOnTop.checked); + config.setClearAllOnKey(this.chkClearAll.checked); + config.save(); + } + + @Override + 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, 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) + { + control.drawButton(this.mc, mouseX, mouseY, partialTicks); + } + + for (GuiColourButton colourButton : this.colourButtonList) + { + colourButton.drawPicker(this.mc, mouseX, mouseY, partialTicks); + } + } + + @Override + public void mousePressed(ConfigPanelHost host, int mouseX, int mouseY, int mouseButton) + { + boolean makeActive = true; + + for (GuiButton control : this.controlList) + { + if (control.mousePressed(this.mc, mouseX, mouseY)) + { + if (makeActive) + { + makeActive = false; + this.activeControl = control; + this.actionPerformed(control); + } + } + } + } + + private void actionPerformed(GuiButton control) + { + if (control instanceof GuiCheckbox) + { + GuiCheckbox chk = (GuiCheckbox)control; + chk.checked = !chk.checked; + } + + if (control.id >= CUIConfigPanel.COLOUR_OPTION_BASE_ID) + { + ConfiguredColour lineColour = ConfiguredColour.values()[control.id - CUIConfigPanel.COLOUR_OPTION_BASE_ID]; + lineColour.setDefault(); + + 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); + } + } +} diff --git a/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java new file mode 100644 index 00000000..d31cb242 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourButton.java @@ -0,0 +1,159 @@ +package com.mumfrey.worldeditcui.gui.controls; + +import static com.mumfrey.liteloader.gl.GL.*; + +import com.mumfrey.worldeditcui.render.ConfiguredColour; + +import net.minecraft.client.Minecraft; + +/** + * Colour picker button control, spawns a style picker when clicked + * + * @author Adam Mummery-Smith + */ +public class GuiColourButton extends GuiControl +{ + /** + * Picker active colour + */ + private int colour = 0xFF000000; + + private ConfiguredColour lineColour; + + private GuiColourPicker picker; + + private boolean pickerClicked = false; + + 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; + this.updateColour(lineColour); + } + + /** + * @param lineColour + */ + public void updateColour(ConfiguredColour 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, float partialTicks) + { + if (this.visible) + { + 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.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.x + 1, this.y + 1, this.x + this.width - 1, this.y + this.height - 1, 0, 0, 1024, v); + + 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.fontRenderer, this.displayString, this.x + this.width + 8, this.y + (this.height - 8) / 2, 0xFFFFFFFF); + } + } + } + + public void drawPicker(Minecraft minecraft, int mouseX, int mouseY, float partialTicks) + { + if (this.visible && this.picker != null) + { + this.picker.drawButton(minecraft, mouseX, mouseY, partialTicks); + + 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.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; + } + + 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/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java new file mode 100644 index 00000000..aff311fe --- /dev/null +++ b/java/com/mumfrey/worldeditcui/gui/controls/GuiColourPicker.java @@ -0,0 +1,342 @@ +package com.mumfrey.worldeditcui.gui.controls; + +import static com.mumfrey.liteloader.gl.GL.*; + +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(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.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.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(); + } + + 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, float partialTicks) + { + this.mouseDragged(minecraft, mouseX, mouseY); + + // Calculate coordinates for the selectors + 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.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.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.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.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.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(); + this.txtGreen.drawTextBox(); + this.txtBlue.drawTextBox(); + this.txtAlpha.drawTextBox(); + + this.btnOk.drawButton(minecraft, mouseX, mouseY, partialTicks); + this.btnCancel.drawButton(minecraft, mouseX, mouseY, partialTicks); + } + + 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.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.y - 10, 0, 128)) / 128F; + this.updateColour(); + } + + if (this.draggingA) + { + this.opacity = (mouseY - this.y < 11) ? 0xFF000000 : (((128 - (int)clamp(mouseY - this.y - 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/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java b/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java new file mode 100644 index 00000000..2bb07215 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/gui/controls/GuiControl.java @@ -0,0 +1,650 @@ +package com.mumfrey.worldeditcui.gui.controls; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.BufferBuilder; +import static com.mumfrey.liteloader.gl.GL.*; + +/** + * 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, float partialTicks) + { + this.drawControl(minecraft, mouseX, mouseY, partialTicks); + } + + /** + * 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, float partialTicks) + { + super.drawButton(minecraft, mouseX, mouseY, partialTicks); + } + + /** + * 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; + + glEnableBlend(); + glDisableTexture2D(); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4f(f1, f2, f3, f); + glLineWidth(width); + + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buf = tessellator.getBuffer(); + buf.begin(GL_LINES, VF_POSITION); + buf.pos(x1, y1, 0).endVertex(); + buf.pos(x2, y2, 0).endVertex(); + tessellator.draw(); + + glEnableTexture2D(); + glDisableBlend(); + } + + /** + * 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; + + glEnableBlend(); + glDisableTexture2D(); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4f(f1, f2, f3, f); + + // Draw the line + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder 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) + { + 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(); + } + + glEnableTexture2D(); + glDisableBlend(); + + 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.getInstance(); + 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(); + 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(); + } + + /** + * 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.getInstance(); + 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(); + 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(); + } + + /** + * 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); // func_175063_a drawStringWithShadow + } + else if (width < 8) + { + fontrenderer.drawStringWithShadow("..", x, y, colour); // func_175063_a drawStringWithShadow + } + 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); // func_175063_a drawStringWithShadow + } + } + + /** + * @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); + glEnableBlend(); + glDisableTexture2D(); + glDisableLighting(); + glColor4f(red, green, blue, alpha); + glEnableColorLogic(); + glLogicOp(GL_OR_REVERSE); + + // Draw the frame + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buf = tessellator.getBuffer(); + + buf.begin(GL_LINES, VF_POSITION); + buf.pos(x - size, y, 0).endVertex(); + buf.pos(x + size, y, 0).endVertex(); + tessellator.draw(); + + buf.begin(GL_LINES, VF_POSITION); + buf.pos(x, y - size, 0).endVertex(); + buf.pos(x, y + size, 0).endVertex(); + tessellator.draw(); + + glDisableColorLogic(); + glEnableTexture2D(); + } + + protected void drawRotText(FontRenderer fontRenderer, String text, int xPosition, int yPosition, int colour, boolean colourOrOp) + { + if (colourOrOp) + { + glEnableColorLogic(); + 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) + { + glDisableColorLogic(); + glEnableTexture2D(); + } + } + + /** + * 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.getInstance(); + 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(); + 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(); + } + + /** + * 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.getInstance(); + 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(); + buf.pos(x2, y, this.zLevel).tex(u2, v).endVertex(); + buf.pos(x, y, this.zLevel).tex(u, v).endVertex(); + 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.getInstance(); + 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(); + 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(); + } + + public static void setScreenSizeAndScale(int width, int height, int scaleFactor) + { + GuiControl.lastScreenWidth = width; + GuiControl.lastScreenHeight = height; + GuiControl.guiScaleFactor = scaleFactor; + } +} diff --git a/java/com/mumfrey/worldeditcui/render/CUISelectionProvider.java b/java/com/mumfrey/worldeditcui/render/CUISelectionProvider.java new file mode 100644 index 00000000..47126b70 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/CUISelectionProvider.java @@ -0,0 +1,70 @@ +package com.mumfrey.worldeditcui.render; + +import java.lang.reflect.Constructor; +import java.util.HashMap; +import java.util.Map; + +import com.mumfrey.worldeditcui.InitialisationFactory; +import com.mumfrey.worldeditcui.WorldEditCUI; +import com.mumfrey.worldeditcui.exceptions.InitialisationException; +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 WorldEditCUI controller; + + public CUISelectionProvider(WorldEditCUI controller) + { + this.controller = controller; + } + + @Override + public void initialise() throws InitialisationException + { + 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 Region createSelection(String key) + { + if ("clear".equals(key)) + { + return null; + } + + try + { + Constructor regionCtor = this.regionConstructors.get(key); + Region 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 creating " + key + " selection: " + ex.getClass().getSimpleName() + " " + ex.getMessage()); + } + + return null; + } +} diff --git a/java/com/mumfrey/worldeditcui/render/ConfiguredColour.java b/java/com/mumfrey/worldeditcui/render/ConfiguredColour.java new file mode 100644 index 00000000..e929b4be --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/ConfiguredColour.java @@ -0,0 +1,149 @@ +package com.mumfrey.worldeditcui.render; + +import net.minecraft.client.resources.I18n; + +import com.mumfrey.worldeditcui.config.Colour; +import com.mumfrey.worldeditcui.render.RenderStyle.RenderType; + +/** + * 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 + * the hidden line has an alpha value of 0.2f. They + * both have a thickness of 3.0f. + * + * @author yetanotherx + * @author lahwran + * @author Adam Mummery-Smith + */ +public enum ConfiguredColour +{ + 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")), + CHUNKBOUNDARY ("colour.chunkboundary", new Colour("#33CC33CC")), + CHUNKGRID ("colour.chunkgrid", new Colour("#4CCCAA99")); + + 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 LineStyle normal, hidden; + private LineStyle[] lines; + + private ConfiguredColour(String displayName, Colour colour) + { + this.displayName = displayName; + this.colour = colour; + this.defaultColour = new Colour().copyFrom(colour); + this.updateLines(); + } + + public String getDisplayName() + { + return I18n.format(this.displayName); + } + + public RenderStyle style() + { + return new Style(); + } + + public void setColour(Colour colour) + { + this.colour = colour; + this.updateLines(); + } + + public Colour getColour() + { + return this.colour; + } + + public LineStyle getHidden() + { + return this.hidden; + } + + public LineStyle getNormal() + { + return this.normal; + } + + public LineStyle[] getLines() + { + return this.lines; + } + + 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); + this.colour.setHex(Integer.toHexString(rgba)); + this.updateLines(); + } + + public int getColourIntARGB() + { + return this.colour.getIntARGB(); + } + + private void updateLines() + { + 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/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/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/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 new file mode 100644 index 00000000..f34812af --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/points/PointCube.java @@ -0,0 +1,93 @@ +package com.mumfrey.worldeditcui.render.points; + +import com.mumfrey.worldeditcui.render.ConfiguredColour; +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; +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 colour, x/y/z values, and rendering + * + * @author yetanotherx + * @author lahwran + * @author Adam Mummery-Smith + */ +public class PointCube extends Observable +{ + private static final double PADDING = 0.03; + + 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 RenderStyle style = ConfiguredColour.CUBOIDPOINT1.style(); + + protected Render3DBox box; + + public PointCube(double x, double y, double z) + { + this(new Vector3(x, y, z)); + } + + 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(float partialTicks) + { + } + + public Vector3 getPoint() + { + return this.point; + } + + public void setPoint(Vector3 point) + { + this.point = point; + this.update(); + } + + public RenderStyle getStyle() + { + return this.style; + } + + public PointCube setStyle(RenderStyle style) + { + this.style = style; + this.update(); + return this; + } + + private void update() + { + 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/PointCubeTracking.java b/java/com/mumfrey/worldeditcui/render/points/PointCubeTracking.java new file mode 100644 index 00000000..07a6c609 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/points/PointCubeTracking.java @@ -0,0 +1,56 @@ +package com.mumfrey.worldeditcui.render.points; + +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 + * + * @author Adam Mummery-Smith + */ +public class PointCubeTracking extends PointCube +{ + private final Entity entity; + private final double traceDistance; + private int lastX, lastY, lastZ; + + public PointCubeTracking(Entity entity, double traceDistance) + { + super(0, 0, 0); + this.entity = entity; + this.traceDistance = traceDistance; + } + + @Override + public boolean isDynamic() + { + return true; + } + + @Override + public Vector3 getPoint() + { + return this.point; + } + + @Override + public void updatePoint(float partialTicks) + { + 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/points/PointRectangle.java b/java/com/mumfrey/worldeditcui/render/points/PointRectangle.java new file mode 100644 index 00000000..8b4c174c --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/points/PointRectangle.java @@ -0,0 +1,87 @@ +package com.mumfrey.worldeditcui.render.points; + +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; +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. + * + * @author yetanotherx + * @author lahwran + * @author Adam Mummery-Smith + */ +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 RenderStyle style = ConfiguredColour.POLYPOINT.style(); + + private int min, max; + + private Render3DBox box; + + public PointRectangle(int x, int z) + { + this(new Vector2(x, z)); + } + + public PointRectangle(Vector2 point) + { + this.setPoint(point); + } + + public void render(Vector3 cameraPos) + { + this.box.render(cameraPos); + } + + public Vector2 getPoint() + { + return this.point; + } + + public void setPoint(Vector2 point) + { + this.point = point; + } + + public RenderStyle getStyle() + { + return this.style; + } + + public void setStyle(RenderStyle style) + { + this.style = style; + } + + 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.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 new file mode 100644 index 00000000..15d171e0 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/region/CuboidRegion.java @@ -0,0 +1,131 @@ +package com.mumfrey.worldeditcui.render.region; + +import com.mumfrey.worldeditcui.WorldEditCUI; +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; +import com.mumfrey.worldeditcui.util.Vector3; +import net.minecraft.entity.Entity; + +/** + * Main controller for a cuboid-type region + * + * @author yetanotherx + * @author lahwran + * @author Adam Mummery-Smith + */ +public class CuboidRegion extends Region +{ + private PointCube[] points = new PointCube[2]; + + private Render3DGrid grid; + private Render3DBox box; + + private double spacing = 1.0; + + public CuboidRegion(WorldEditCUI controller) + { + super(controller, ConfiguredColour.CUBOIDBOX.style(), ConfiguredColour.CUBOIDGRID.style(), ConfiguredColour.CUBOIDPOINT1.style(), ConfiguredColour.CUBOIDPOINT2.style()); + } + + @Override + public void render(Vector3 cameraPos, float partialTicks) + { + if (this.points[0] != null && this.points[1] != null) + { + this.points[0].updatePoint(partialTicks); + this.points[1].updatePoint(partialTicks); + + this.grid.render(cameraPos); + this.box.render(cameraPos); + + this.points[0].render(cameraPos); + this.points[1].render(cameraPos); + } + else if (this.points[0] != null) + { + this.points[0].updatePoint(partialTicks); + this.points[0].render(cameraPos); + } + else if (this.points[1] != null) + { + this.points[1].updatePoint(partialTicks); + this.points[1].render(cameraPos); + } + } + + @Override + public void setGridSpacing(double spacing) + { + this.spacing = spacing; + if (this.grid != null) + { + this.grid.setSpacing(spacing); + } + } + + @Override + 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[id+2]); + } + + this.updateBounds(); + } + + @Override + public void setCuboidVertexLatch(int id, Entity entity, double traceDistance) + { + if (id < 2) + { + this.points[id] = new PointCubeTracking(entity, traceDistance).setStyle(this.styles[id+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.styles[1], bounds).setSpacing(this.spacing); + this.box = new Render3DBox(this.styles[0], bounds); + } + } + + @Override + protected void updateStyles() + { + if (this.box != null) + { + this.box.setStyle(this.styles[0]); + } + + if (this.grid != null) + { + this.grid.setStyle(this.styles[1]); + } + + if (this.points[0] != null) + { + this.points[0].setStyle(this.styles[2]); + } + + if (this.points[1] != null) + { + this.points[1].setStyle(this.styles[3]); + } + } + + @Override + public RegionType getType() + { + return RegionType.CUBOID; + } +} diff --git a/java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java b/java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java new file mode 100644 index 00000000..242957b1 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/region/CylinderRegion.java @@ -0,0 +1,113 @@ +package com.mumfrey.worldeditcui.render.region; + +import com.mumfrey.worldeditcui.WorldEditCUI; +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; +import com.mumfrey.worldeditcui.render.shapes.RenderCylinderGrid; +import com.mumfrey.worldeditcui.util.Vector3; + +/** + * Main controller for a cylinder-type region + * + * @author yetanotherx + * @author Adam Mummery-Smith + */ +public class CylinderRegion extends Region +{ + private PointCube centre; + private double radX = 0, radZ = 0; + private int minY = 0, maxY = 0; + + private RenderCylinderCircles circles; + private RenderCylinderGrid grid; + private RenderCylinderBox box; + + public CylinderRegion(WorldEditCUI controller) + { + super(controller, ConfiguredColour.CYLINDERBOX.style(), ConfiguredColour.CYLINDERGRID.style(), ConfiguredColour.CYLINDERCENTRE.style()); + } + + @Override + public void render(Vector3 cameraPos, float partialTicks) + { + if (this.centre != null) + { + this.centre.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.centre = new PointCube(x, y, z); + this.centre.setStyle(this.styles[2]); + this.update(); + } + + @Override + public void setCylinderRadius(double x, double z) + { + this.radX = x; + this.radZ = z; + this.update(); + } + + @Override + 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.centre.getPoint().getY(); + tMax = (int)this.centre.getPoint().getY(); + } + + 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 updateStyles() + { + if (this.box != null) + { + this.box.setStyle(this.styles[0]); + } + + if (this.grid != null) + { + this.grid.setStyle(this.styles[1]); + } + + if (this.circles != null) + { + this.circles.setStyle(this.styles[1]); + } + + if (this.centre != null) + { + this.centre.setStyle(this.styles[2]); + } + } + + @Override + public RegionType getType() + { + return RegionType.CYLINDER; + } +} diff --git a/java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java b/java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java new file mode 100644 index 00000000..48a4c0b9 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/region/EllipsoidRegion.java @@ -0,0 +1,85 @@ +package com.mumfrey.worldeditcui.render.region; + +import com.mumfrey.worldeditcui.WorldEditCUI; +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; + +/** + * Main controller for a ellipsoid-type region + * + * @author yetanotherx + * @author lahwran + * @author Adam Mummery-Smith + */ +public class EllipsoidRegion extends Region +{ + private PointCube centre; + private Vector3 radii; + + private RenderEllipsoid ellipsoid; + + public EllipsoidRegion(WorldEditCUI controller) + { + super(controller, ConfiguredColour.ELLIPSOIDGRID.style(), ConfiguredColour.ELLIPSOIDCENTRE.style()); + } + + @Override + public void render(Vector3 cameraPos, float partialTicks) + { + if (this.centre != null && this.radii != null) + { + this.centre.render(cameraPos); + this.ellipsoid.render(cameraPos); + } + else if (this.centre != null) + { + this.centre.render(cameraPos); + } + } + + @Override + public void setEllipsoidCenter(int x, int y, int z) + { + this.centre = new PointCube(x, y, z); + this.centre.setStyle(this.styles[1]); + 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(this.styles[0], this.centre, this.radii); + } + } + + @Override + protected void updateStyles() + { + if (this.ellipsoid != null) + { + this.ellipsoid.setStyle(this.styles[0]); + } + + if (this.centre != null) + { + this.centre.setStyle(this.styles[1]); + } + } + + @Override + public RegionType getType() + { + return RegionType.ELLIPSOID; + } + +} diff --git a/java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java b/java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java new file mode 100644 index 00000000..90d2e7a1 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/region/PolygonRegion.java @@ -0,0 +1,127 @@ +package com.mumfrey.worldeditcui.render.region; + +import java.util.ArrayList; +import java.util.List; + +import com.mumfrey.worldeditcui.WorldEditCUI; +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; +import com.mumfrey.worldeditcui.util.Vector3; + +/** + * Main controller for a polygon-type region + * + * @author yetanotherx + * @author lahwran + * @author Adam Mummery-Smith + */ +public class PolygonRegion extends Region +{ + private final List points = new ArrayList(); + private int min, max; + + private Render2DBox box; + private Render2DGrid grid; + + public PolygonRegion(WorldEditCUI controller) + { + super(controller, ConfiguredColour.POLYBOX.style(), ConfiguredColour.POLYGRID.style(), ConfiguredColour.POLYPOINT.style()); + } + + @Override + public void render(Vector3 cameraPos, float partialTicks) + { + if (this.points.size() < 1) + { + return; + } + + for (PointRectangle point : this.points) + { + if (point != null) + { + point.render(cameraPos); + } + } + + this.box.render(cameraPos); + this.grid.render(cameraPos); + } + + @Override + public void setMinMax(int min, int max) + { + this.min = min; + this.max = max; + this.update(); + } + + @Override + public void setPolygonPoint(int id, int x, int z) + { + PointRectangle point = new PointRectangle(x, z); + point.setStyle(this.styles[0]); + point.setMinMax(this.min, this.max); + + 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); + } + this.update(); + } + + private void update() + { + if (this.points.size() <= 0) + { + return; + } + + for (PointRectangle point : this.points) + { + if (point != null) + { + point.setMinMax(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 updateStyles() + { + if (this.box != null) + { + this.box.setStyle(this.styles[0]); + } + + if (this.grid != null) + { + this.grid.setStyle(this.styles[1]); + } + + for (PointRectangle point : this.points) + { + point.setStyle(this.styles[0]); + } + } + + @Override + public RegionType getType() + { + return RegionType.POLYGON; + } +} + diff --git a/java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java b/java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java new file mode 100644 index 00000000..46af9665 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/region/PolyhedronRegion.java @@ -0,0 +1,114 @@ +package com.mumfrey.worldeditcui.render.region; + +import java.util.ArrayList; +import java.util.List; + +import com.mumfrey.worldeditcui.WorldEditCUI; +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; + +/** + * Main controller for a polygon-type region + * + * @author TomyLobo + * @author Adam Mummery-Smith + */ +public class PolyhedronRegion extends Region +{ + private static final Vector3 HALF = new Vector3(0.5, 0.5, 0.5); + + private List vertices = new ArrayList(); + private List faces = new ArrayList(); + + private List faceRenders = new ArrayList(); + + public PolyhedronRegion(WorldEditCUI controller) + { + super(controller, ConfiguredColour.POLYBOX.style(), ConfiguredColour.POLYPOINT.style(), ConfiguredColour.CUBOIDPOINT1.style()); + } + + @Override + public void render(Vector3 cameraPos, float partialTicks) + { + for (PointCube vertex : this.vertices) + { + vertex.render(cameraPos); + } + + for (Render3DPolygon face : this.faceRenders) + { + face.render(cameraPos); + } + } + + @Override + public void setCuboidPoint(int id, double x, double y, double z) + { + final PointCube vertex = new PointCube(x, y, z).setId(id); + vertex.setStyle(id == 0 ? this.styles[2] : this.styles[1]); + + 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); + } + } + + @Override + public void addPolygon(int[] vertexIds) + { + final Vector3[] face = new Vector3[vertexIds.length]; + for (int i = 0; i < vertexIds.length; ++i) + { + final PointCube vertex = this.vertices.get(vertexIds[i]); + if (vertex == null) + { + // This should never happen + return; + } + + 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(this.styles[0], face)); + } + } + + @Override + protected void updateStyles() + { + for (PointCube vertex : this.vertices) + { + vertex.setStyle(vertex.getId() == 0 ? this.styles[2] : this.styles[1]); + } + + for (Render3DPolygon face : this.faceRenders) + { + face.setStyle(this.styles[0]); + } + } + + @Override + public RegionType getType() + { + return RegionType.POLYHEDRON; + } +} diff --git a/java/com/mumfrey/worldeditcui/render/region/Region.java b/java/com/mumfrey/worldeditcui/render/region/Region.java new file mode 100644 index 00000000..ff3bb759 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/region/Region.java @@ -0,0 +1,127 @@ +package com.mumfrey.worldeditcui.render.region; + +import com.mumfrey.worldeditcui.InitialisationFactory; +import com.mumfrey.worldeditcui.WorldEditCUI; +import com.mumfrey.worldeditcui.exceptions.InvalidSelectionTypeException; +import com.mumfrey.worldeditcui.render.RenderStyle; +import com.mumfrey.worldeditcui.render.RenderStyle.RenderType; +import com.mumfrey.worldeditcui.util.Vector3; +import net.minecraft.entity.Entity; + +/** + * Base region storage class. Provides + * abstract methods for setting various + * points in the region. + * + * @author yetanotherx + * @author lahwran + * @author Adam Mummery-Smith + */ +public abstract class Region implements InitialisationFactory +{ + protected final WorldEditCUI controller; + protected final RenderStyle[] defaultStyles; + protected RenderStyle[] styles; + protected RenderType renderType = RenderType.ANY; + + protected Region(WorldEditCUI controller, RenderStyle... styles) + { + this.controller = controller; + this.styles = this.defaultStyles = styles; + } + + @Override + public void initialise() + { + } + + public abstract void render(Vector3 cameraPos, float partialTicks); + + public RenderStyle[] getDefaultStyles() + { + return this.defaultStyles; + } + + public void setRenderType(RenderType renderType) + { + 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"); + } + + this.styles = styles; + this.updateRenderStyle(); + this.updateStyles(); + } + + protected void updateRenderStyle() + { + for (RenderStyle style : this.styles) + { + if (style != null) + { + style.setRenderType(this.renderType); + } + } + } + + protected abstract void updateStyles(); + + 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, Entity entity, double traceDistance) + { + throw new InvalidSelectionTypeException(this.getType().getName(), "setCuboidVertexLatch"); + } + + 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/com/mumfrey/worldeditcui/render/region/RegionType.java b/java/com/mumfrey/worldeditcui/render/region/RegionType.java new file mode 100644 index 00000000..a349ac71 --- /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/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java b/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java new file mode 100644 index 00000000..e11b4159 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render2DBox.java @@ -0,0 +1,65 @@ +package com.mumfrey.worldeditcui.render.shapes; + +import java.util.List; + +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; + +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.BufferBuilder; +import static com.mumfrey.liteloader.gl.GL.*; + +/** + * Draws the top and bottom rings of a polygon region + * + * @author yetanotherx + * @author lahwran + * @author Adam Mummery-Smith + */ +public class Render2DBox extends RenderRegion +{ + private List points; + private int min, max; + + public Render2DBox(RenderStyle style, List points, int min, int max) + { + super(style); + this.points = points; + this.min = min; + this.max = max; + } + + @Override + public void render(Vector3 cameraPos) + { + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buf = tessellator.getBuffer(); + double off = 0.03 - cameraPos.getY(); + for (LineStyle line : this.style.getLines()) + { + if (!line.prepare(this.style.getRenderType())) + { + continue; + } + + buf.begin(GL_LINES, VF_POSITION); + line.applyColour(); + + for (PointRectangle point : this.points) + { + if (point != null) + { + Vector2 pos = point.getPoint(); + double x = pos.getX() - cameraPos.getX(); + double z = pos.getY() - cameraPos.getZ(); + 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 new file mode 100644 index 00000000..ead55db6 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render2DGrid.java @@ -0,0 +1,72 @@ +package com.mumfrey.worldeditcui.render.shapes; + +import static com.mumfrey.liteloader.gl.GL.*; + +import java.util.List; + +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Tessellator; + +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; + +/** + * Draws the grid for a polygon region + * + * @author yetanotherx + * @author lahwran + * @author Adam Mummery-Smith + */ +public class Render2DGrid extends RenderRegion +{ + private List points; + private int min, max; + + public Render2DGrid(RenderStyle style, List points, int min, int max) + { + super(style); + this.points = points; + this.min = min; + this.max = max; + } + + @Override + public void render(Vector3 cameraPos) + { + double off = 0.03; + for (double height = this.min; height <= this.max + 1; height++) + { + this.drawPoly(cameraPos, height + off); + } + } + + protected void drawPoly(Vector3 cameraPos, double height) + { + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buf = tessellator.getBuffer(); + for (LineStyle line : this.style.getLines()) + { + if (!line.prepare(this.style.getRenderType())) + { + continue; + } + + buf.begin(GL_LINE_LOOP, VF_POSITION); + line.applyColour(); + for (PointRectangle point : this.points) + { + if (point != null) + { + Vector2 pos = point.getPoint(); + double x = pos.getX() - cameraPos.getX(); + double z = pos.getY() - cameraPos.getZ(); + 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 new file mode 100644 index 00000000..fdd20eb6 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DBox.java @@ -0,0 +1,114 @@ +package com.mumfrey.worldeditcui.render.shapes; + +import static com.mumfrey.liteloader.gl.GL.*; + +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Tessellator; + +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; + +/** + * Draws a rectangular prism around 2 corners + * + * @author yetanotherx + * @author lahwran + * @author Adam Mummery-Smith + */ +public class Render3DBox extends RenderRegion +{ + private Vector3 first, second; + + public Render3DBox(RenderStyle style, BoundingBox region) + { + this(style, region.getMin(), region.getMax()); + if (region.isDynamic()) + { + region.addObserver(this); + } + } + + public Render3DBox(RenderStyle style, Vector3 first, Vector3 second) + { + super(style); + 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; + } + + @Override + public void render(Vector3 cameraPos) + { + Tessellator tessellator = Tessellator.getInstance(); + 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(); + double x2 = this.second.getX() - cameraPos.getX(); + double y2 = this.second.getY() - cameraPos.getY(); + double z2 = this.second.getZ() - cameraPos.getZ(); + + for (LineStyle line : this.style.getLines()) + { + if (!line.prepare(this.style.getRenderType())) + { + continue; + } + + // Draw bottom face + buf.begin(GL_LINE_LOOP, VF_POSITION); + line.applyColour(); + 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 + buf.begin(GL_LINE_LOOP, VF_POSITION); + line.applyColour(); + 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 + buf.begin(GL_LINES, VF_POSITION); + line.applyColour(); + + buf.pos(x1, y1, z1).endVertex(); + buf.pos(x1, y2, z1).endVertex(); + + buf.pos(x2, y1, z1).endVertex(); + buf.pos(x2, y2, z1).endVertex(); + + buf.pos(x2, y1, z2).endVertex(); + buf.pos(x2, y2, z2).endVertex(); + + 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 new file mode 100644 index 00000000..fe0a0dd4 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DGrid.java @@ -0,0 +1,165 @@ +package com.mumfrey.worldeditcui.render.shapes; + +import static com.mumfrey.liteloader.gl.GL.*; + +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Tessellator; + +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; + +/** + * Draws the grid for a region between + * two corners in a cuboid region. + * + * @author yetanotherx + * @author Adam Mummery-Smith + */ +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; + private double spacing = 1.0; + + public Render3DGrid(RenderStyle style, BoundingBox region) + { + this(style, region.getMin(), region.getMax()); + if (region.isDynamic()) + { + region.addObserver(this); + } + } + + public Render3DGrid(RenderStyle style, Vector3 first, Vector3 second) + { + super(style); + 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(); + 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(); + double x2 = this.second.getX() - cameraPos.getX(); + 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 (LineStyle line : this.style.getLines()) + { + if (line.prepare(this.style.getRenderType())) + { + 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(); + } + } + + glEnableCulling(); + } + + if (this.spacing < Render3DGrid.MIN_SPACING) + { + return; + } + + double cullAt = Render3DGrid.CULL_RANGE * this.spacing; + for (LineStyle line : this.style.getLines()) + { + if (!line.prepare(this.style.getRenderType())) + { + continue; + } + + buf.begin(GL_LINES, VF_POSITION); + line.applyColour(); + + for (double y = Math.max(y1, -cullAt); y <= y2 && y <= cullAt; y += this.spacing) + { + 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 x = Math.max(x1, -cullAt); x <= x2 && x <= cullAt; x += this.spacing) + { + 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 z = Math.max(z1, -cullAt); z <= z2 && z <= cullAt; z += this.spacing) + { + 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 new file mode 100644 index 00000000..457c92d2 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/shapes/Render3DPolygon.java @@ -0,0 +1,51 @@ +package com.mumfrey.worldeditcui.render.shapes; + +import static com.mumfrey.liteloader.gl.GL.*; + +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Tessellator; + +import com.mumfrey.worldeditcui.render.RenderStyle; +import com.mumfrey.worldeditcui.render.LineStyle; +import com.mumfrey.worldeditcui.util.Vector3; + +/** + * Draws a polygon + * + * @author yetanotherx + * @author lahwran + * @author Adam Mummery-Smith + */ +public class Render3DPolygon extends RenderRegion +{ + private Vector3[] vertices; + + public Render3DPolygon(RenderStyle style, Vector3... vertices) + { + super(style); + this.vertices = vertices; + } + + @Override + public void render(Vector3 cameraPos) + { + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buf = tessellator.getBuffer(); + + for (LineStyle line : this.style.getLines()) + { + if (!line.prepare(this.style.getRenderType())) + { + continue; + } + + buf.begin(GL_LINE_LOOP, VF_POSITION); + line.applyColour(); + for (Vector3 vertex : this.vertices) + { + 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/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/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java new file mode 100644 index 00000000..cbdfc0f7 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderBox.java @@ -0,0 +1,70 @@ +package com.mumfrey.worldeditcui.render.shapes; + +import static com.mumfrey.liteloader.gl.GL.*; + +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Tessellator; + +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; + +/** + * Draws the top and bottom circles around a cylindrical region + * + * @author yetanotherx + * @author Adam Mummery-Smith + */ +public class RenderCylinderBox extends RenderRegion +{ + private double radX, radZ; + private int minY, maxY; + private double centreX, centreZ; + + public RenderCylinderBox(RenderStyle style, PointCube centre, double radX, double radZ, int minY, int maxY) + { + super(style); + this.radX = radX; + this.radZ = radZ; + this.minY = minY; + this.maxY = maxY; + this.centreX = centre.getPoint().getX() + 0.5; + this.centreZ = centre.getPoint().getZ() + 0.5; + } + + @Override + public void render(Vector3 cameraPos) + { + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buf = tessellator.getBuffer(); + + double xPos = this.centreX - cameraPos.getX(); + double zPos = this.centreZ - cameraPos.getZ(); + + for (LineStyle line : this.style.getLines()) + { + 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); + line.applyColour(); + + 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); + + 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 new file mode 100644 index 00000000..7e3ff071 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderCircles.java @@ -0,0 +1,73 @@ +package com.mumfrey.worldeditcui.render.shapes; + +import static com.mumfrey.liteloader.gl.GL.*; + +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Tessellator; + +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; + +/** + * Draws the circles around a cylindrical region + * + * @author yetanotherx + * @author Adam Mummery-Smith + */ +public class RenderCylinderCircles extends RenderRegion +{ + protected double radX = 0; + protected double radZ = 0; + protected int minY; + protected int maxY; + protected double centreX; + protected double centreZ; + + public RenderCylinderCircles(RenderStyle style, PointCube centre, double radX, double radZ, int minY, int maxY) + { + super(style); + this.radX = radX; + this.radZ = radZ; + this.minY = minY; + this.maxY = maxY; + this.centreX = centre.getPoint().getX() + 0.5; + this.centreZ = centre.getPoint().getZ() + 0.5; + } + + @Override + public void render(Vector3 cameraPos) + { + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buf = tessellator.getBuffer(); + + double xPos = this.centreX - cameraPos.getX(); + double zPos = this.centreZ - cameraPos.getZ(); + + for (LineStyle line : this.style.getLines()) + { + 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); + line.applyColour(); + + 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); + + 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 new file mode 100644 index 00000000..26a91b70 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderCylinderGrid.java @@ -0,0 +1,91 @@ +package com.mumfrey.worldeditcui.render.shapes; + +import static com.mumfrey.liteloader.gl.GL.*; + +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Tessellator; + +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; + +/** + * Draws the grid lines around a cylindrical region + * + * @author yetanotherx + * @author Adam Mummery-Smith + */ +public class RenderCylinderGrid extends RenderRegion +{ + protected double radX = 0; + protected double radZ = 0; + protected int minY; + protected int maxY; + protected double centreX; + protected double centreZ; + + public RenderCylinderGrid(RenderStyle style, PointCube centre, double radX, double radZ, int minY, int maxY) + { + super(style); + this.radX = radX; + this.radZ = radZ; + this.minY = minY; + this.maxY = maxY; + this.centreX = centre.getPoint().getX() + 0.5; + this.centreZ = centre.getPoint().getZ() + 0.5; + } + + @Override + public void render(Vector3 cameraPos) + { + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buf = tessellator.getBuffer(); + + double xPos = this.centreX - cameraPos.getX(); + double zPos = this.centreZ - cameraPos.getZ(); + + for (LineStyle line : this.style.getLines()) + { + if (!line.prepare(this.style.getRenderType())) + { + continue; + } + + 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)); + buf.begin(GL_LINE_LOOP, VF_POSITION); + line.applyColour(); + + 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(); + } + + for (double tempZ = negRadiusZ; tempZ <= posRadiusZ; ++tempZ) + { + double tempX = this.radX * Math.sin(Math.acos(tempZ / this.radZ)); + buf.begin(GL_LINE_LOOP, VF_POSITION); + line.applyColour(); + + 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 new file mode 100644 index 00000000..78825873 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/render/shapes/RenderEllipsoid.java @@ -0,0 +1,164 @@ +package com.mumfrey.worldeditcui.render.shapes; + +import static com.mumfrey.liteloader.gl.GL.*; + +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Tessellator; + +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; + +/** + * Draws an ellipsoid shape around a centre point. + * + * @author yetanotherx + * @author Adam Mummery-Smith + */ +public class RenderEllipsoid extends RenderRegion +{ + protected final static double TAU = Math.PI * 2.0; + + protected PointCube centre; + protected Vector3 radii; + + protected double centreX, centreY, centreZ; + + public RenderEllipsoid(RenderStyle style, PointCube centre, Vector3 radii) + { + super(style); + this.centre = centre; + this.radii = radii; + this.centreX = centre.getPoint().getX() + 0.5; + this.centreY = centre.getPoint().getY() + 0.5; + this.centreZ = centre.getPoint().getZ() + 0.5; + } + + @Override + public void render(Vector3 cameraPos) + { + glPushMatrix(); + glTranslated(this.centreX - cameraPos.getX(), this.centreY - cameraPos.getY(), this.centreZ - cameraPos.getZ()); + + for (LineStyle line : this.style.getLines()) + { + if (line.prepare(this.style.getRenderType())) + { + this.drawXZPlane(line); + this.drawYZPlane(line); + this.drawXYPlane(line); + } + } + + glPopMatrix(); + } + + protected void drawXZPlane(LineStyle line) + { + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buf = tessellator.getBuffer(); + + int yRad = (int)Math.floor(this.radii.getY()); + for (int yBlock = -yRad; yBlock < yRad; yBlock++) + { + buf.begin(GL_LINE_LOOP, VF_POSITION); + line.applyColour(); + + for (int i = 0; i <= 40; i++) + { + 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())); + + buf.pos(tempX, yBlock, tempZ).endVertex(); + } + tessellator.draw(); + } + + buf.begin(GL_LINE_LOOP, VF_POSITION); + line.applyColour(); + + for (int i = 0; i <= 40; i++) + { + double tempTheta = i * TAU / 40; + double tempX = this.radii.getX() * Math.cos(tempTheta); + double tempZ = this.radii.getZ() * Math.sin(tempTheta); + + buf.pos(tempX, 0.0, tempZ).endVertex(); + } + tessellator.draw(); + } + + protected void drawYZPlane(LineStyle line) + { + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buf = tessellator.getBuffer(); + + int xRad = (int)Math.floor(this.radii.getX()); + for (int xBlock = -xRad; xBlock < xRad; xBlock++) + { + buf.begin(GL_LINE_LOOP, VF_POSITION); + line.applyColour(); + + for (int i = 0; i <= 40; i++) + { + 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())); + + buf.pos(xBlock, tempY, tempZ).endVertex(); + } + tessellator.draw(); + } + + buf.begin(GL_LINE_LOOP, VF_POSITION); + line.applyColour(); + + for (int i = 0; i <= 40; i++) + { + double tempTheta = i * TAU / 40; + double tempY = this.radii.getY() * Math.cos(tempTheta); + double tempZ = this.radii.getZ() * Math.sin(tempTheta); + + buf.pos(0.0, tempY, tempZ).endVertex(); + } + tessellator.draw(); + } + + protected void drawXYPlane(LineStyle line) + { + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buf = tessellator.getBuffer(); + + int zRad = (int)Math.floor(this.radii.getZ()); + for (int zBlock = -zRad; zBlock < zRad; zBlock++) + { + buf.begin(GL_LINE_LOOP, VF_POSITION); + line.applyColour(); + + for (int i = 0; i <= 40; i++) + { + 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())); + + buf.pos(tempX, tempY, zBlock).endVertex(); + } + tessellator.draw(); + } + + buf.begin(GL_LINE_LOOP, VF_POSITION); + line.applyColour(); + + for (int i = 0; i <= 40; i++) + { + double tempTheta = i * TAU / 40; + double tempX = this.radii.getX() * Math.cos(tempTheta); + double tempY = this.radii.getY() * Math.sin(tempTheta); + + buf.pos(tempX, tempY, 0.0).endVertex(); + } + tessellator.draw(); + } +} 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..b89bfdbc --- /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.RenderStyle; +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 RenderStyle style; + + protected RenderRegion(RenderStyle style) + { + this.style = style; + } + + public final void setStyle(RenderStyle style) + { + this.style = style; + } + + 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 new file mode 100644 index 00000000..36f99123 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/util/BoundingBox.java @@ -0,0 +1,69 @@ +package com.mumfrey.worldeditcui.util; + +import com.mumfrey.worldeditcui.render.points.PointCube; +import com.mumfrey.worldeditcui.render.shapes.RenderRegion; + +/** + * @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 PointCube pc1, pc2; + private Vector3 min, max; + + public BoundingBox(PointCube pc1, PointCube pc2) + { + 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() + { + return this.min; + } + + 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/ConsoleLogFormatter.java b/java/com/mumfrey/worldeditcui/util/ConsoleLogFormatter.java new file mode 100644 index 00000000..34106415 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/util/ConsoleLogFormatter.java @@ -0,0 +1,73 @@ +package com.mumfrey.worldeditcui.util; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.text.SimpleDateFormat; +import java.util.logging.Formatter; +import java.util.logging.Level; +import java.util.logging.LogRecord; + +/** + * Console log formatter, from Minecraft Server. + * Brought into Minecraft Client. + * + * 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(); + } +} 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); +} diff --git a/java/com/mumfrey/worldeditcui/util/Vector2.java b/java/com/mumfrey/worldeditcui/util/Vector2.java new file mode 100644 index 00000000..3ba93ad3 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/util/Vector2.java @@ -0,0 +1,562 @@ +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 Initialised 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 Initialised 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 Initialised a Vector2 to (0,0) + */ + public Vector2() + { + this(0, 0); + } + + /** + * Construct and Initialised 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 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 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 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); + } + + /** + * 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 new file mode 100644 index 00000000..e3dd0e31 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/util/Vector2m.java @@ -0,0 +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(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 new file mode 100644 index 00000000..1e7b80f7 --- /dev/null +++ b/java/com/mumfrey/worldeditcui/util/Vector3.java @@ -0,0 +1,656 @@ +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/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/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/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 diff --git a/res/assets/wecui/lang/en_us.lang b/res/assets/wecui/lang/en_us.lang new file mode 100644 index 00000000..63b6d0c9 --- /dev/null +++ b/res/assets/wecui/lang/en_us.lang @@ -0,0 +1,33 @@ +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 + +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 +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) +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 + 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 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 + 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=Отображение цветов + diff --git a/res/assets/wecui/lang/uk_ua.lang b/res/assets/wecui/lang/uk_ua.lang new file mode 100644 index 00000000..f6c65e89 --- /dev/null +++ b/res/assets/wecui/lang/uk_ua.lang @@ -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=Кольори виділення 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=显示颜色 + diff --git a/res/assets/wecui/textures/gui/checker.png b/res/assets/wecui/textures/gui/checker.png new file mode 100644 index 00000000..d7ca6a32 Binary files /dev/null and b/res/assets/wecui/textures/gui/checker.png differ diff --git a/res/assets/wecui/textures/gui/picker.png b/res/assets/wecui/textures/gui/picker.png new file mode 100644 index 00000000..18e1c9dd Binary files /dev/null and b/res/assets/wecui/textures/gui/picker.png differ 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/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 deleted file mode 100644 index cf852cf7..00000000 --- a/src/main/java/wecui/CUIDebug.java +++ /dev/null @@ -1,74 +0,0 @@ -package wecui; - -import java.io.File; -import java.io.IOException; -import java.util.logging.ConsoleHandler; -import java.util.logging.FileHandler; -import java.util.logging.Level; -import java.util.logging.Logger; -import wecui.exception.InitializationException; -import wecui.obfuscation.Obfuscation; -import wecui.util.ConsoleLogFormatter; - -/** - * Debugging helper class - * - * @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(Obfuscation.getWorldEditCUIDir(), "WorldEditCUI-debug.txt"); - this.debugMode = 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 (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 deleted file mode 100644 index 436ba90b..00000000 --- a/src/main/java/wecui/InitializationFactory.java +++ /dev/null @@ -1,14 +0,0 @@ -package wecui; - -import wecui.exception.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/src/main/java/wecui/Updater.java b/src/main/java/wecui/Updater.java deleted file mode 100644 index 915883a7..00000000 --- a/src/main/java/wecui/Updater.java +++ /dev/null @@ -1,78 +0,0 @@ -package wecui; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -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; - - 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 - @SuppressWarnings("unchecked") - public void run() { - if (controller.configuration.ignoreUpdates()) { - return; - } - - InputStream is = null; - ConfigurationNode node = new ConfigurationNode(new HashMap()); - - try { - URL url = new URL(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()); - - 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"); - - } - } - - } catch (Exception e) { - controller.getDebugger().info("Error in fetching update file!", e); - } finally { - if (is != null) { - try { - is.close(); - } catch (IOException e) { - } - } - } - } -} diff --git a/src/main/java/wecui/WorldEditCUI.java b/src/main/java/wecui/WorldEditCUI.java deleted file mode 100644 index b46f973a..00000000 --- a/src/main/java/wecui/WorldEditCUI.java +++ /dev/null @@ -1,140 +0,0 @@ -package wecui; - -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; -import wecui.event.listeners.CUIListener; -import wecui.event.WorldRenderEvent; -import wecui.event.listeners.ChannelListener; -import wecui.event.listeners.WorldEditCommandListener; -import wecui.event.listeners.WorldRenderListener; -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; - -/** - * Main controller class. Uses a pseudo-JavaBeans paradigm. The only real - * logic here is listener registration. - * - * TODO: Preview mode - * TODO: Command transactions - * TODO: Add ability to flash selection - * - * @author yetanotherx - */ -public class WorldEditCUI { - - public static final String VERSION = "1.4.5"; - public static final String MCVERSION = "1.4.5"; - public static final int protocolVersion = 2; - protected Minecraft minecraft; - protected EventManager eventManager; - protected Obfuscation obfuscation; - protected BaseRegion selection; - protected CUIDebug debugger; - protected CUIConfiguration configuration; - //protected LocalPlugin localPlugin; - - public WorldEditCUI(Minecraft minecraft) { - this.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); - //this.localPlugin = new LocalPlugin(this); - - try { - this.eventManager.initialize(); - this.obfuscation.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); - - WorldEditCommandListener commListener = new WorldEditCommandListener(this); - ChatCommandEvent.getHandlers("worldedit").register(commListener, Order.Default); - ChatCommandEvent.getHandlers("we").register(commListener, Order.Default); - } - - public CUIConfiguration getConfiguration() { - return configuration; - } - - public void setConfiguration(CUIConfiguration configuration) { - this.configuration = configuration; - } - - public CUIDebug getDebugger() { - return debugger; - } - - public void setDebugger(CUIDebug debugger) { - this.debugger = debugger; - } - - public EventManager getEventManager() { - return eventManager; - } - - 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 minecraft; - } - - 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; - } - - public void setSelection(BaseRegion selection) { - this.selection = selection; - } - - public static String getVersion() { - return VERSION + " for Minecraft version " + MCVERSION; - } -} diff --git a/src/main/java/wecui/config/CUIConfiguration.java b/src/main/java/wecui/config/CUIConfiguration.java deleted file mode 100644 index ac5278a1..00000000 --- a/src/main/java/wecui/config/CUIConfiguration.java +++ /dev/null @@ -1,163 +0,0 @@ -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; - -/** - * 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 = "https://raw.github.com/yetanotherx/WorldEditCUI/master/updates.yml"; - 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(Obfuscation.getWorldEditCUIDir(), "Configuration.yml"); - file.getParentFile().mkdirs(); - - if (!file.exists()) { - InputStream input = mod_WorldEditCUI.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 { - if (input != null) { - input.close(); - } - } catch (IOException e) { - } - - try { - if (output != null) { - output.close(); - } - } catch (IOException e) { - } - } - } - } - - 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); - - 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 = 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; - } - - 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; - } - } - - public boolean isDebugMode() { - return debugMode; - } - - public boolean ignoreUpdates() { - return ignoreUpdates; - } - - public String getUpdateFile() { - return updateFile; - } -} diff --git a/src/main/java/wecui/config/Configuration.java b/src/main/java/wecui/config/Configuration.java deleted file mode 100644 index 260e5958..00000000 --- a/src/main/java/wecui/config/Configuration.java +++ /dev/null @@ -1,188 +0,0 @@ -package wecui.config; - -import wecui.exception.ConfigurationException; -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; - -/** - * 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); - - 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(file); - read(yaml.load(new UnicodeReader(stream))); - } catch (IOException e) { - root = new HashMap(); - } catch (ConfigurationException e) { - 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); - } - - 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 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 = file.getParentFile(); - - if (parent != null) { - parent.mkdirs(); - } - - try { - stream = new FileOutputStream(file); - OutputStreamWriter writer = new OutputStreamWriter(stream, "UTF-8"); - if (header != null) { - writer.append(header); - writer.append("\r\n"); - } - yaml.dump(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) { - root = new HashMap(); - } else { - 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 27b410d9..00000000 --- a/src/main/java/wecui/config/ConfigurationNode.java +++ /dev/null @@ -1,546 +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 = root.get(path); - - if (val == null) { - return null; - } - return val; - } - - String[] parts = path.split("\\."); - Map node = 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(".")) { - root.put(path, value); - return; - } - - String[] parts = path.split("\\."); - Map node = 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 = 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 = 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(getProperty(path)); - - if (o == null) { - //setProperty(path, def); - return def; - } else { - 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(getProperty(path)); - - if (o == null) { - //setProperty(path, def); - return def; - } else { - 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(getProperty(path)); - - if (o == null) { - //setProperty(path, def); - return def; - } else { - 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(root.keySet()); - } - Object o = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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(".")) { - root.remove(path); - return; - } - - String[] parts = path.split("\\."); - Map node = 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 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 0928b147..00000000 --- a/src/main/java/wecui/config/EmptyNullRepresenter.java +++ /dev/null @@ -1,50 +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 { - - public Node representData(Object data) { - return 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/CUIEvent.java b/src/main/java/wecui/event/CUIEvent.java deleted file mode 100644 index 09e43663..00000000 --- a/src/main/java/wecui/event/CUIEvent.java +++ /dev/null @@ -1,86 +0,0 @@ -package wecui.event; - -import wecui.util.Utilities; -import wecui.fevents.Event; -import wecui.fevents.HandlerList; -import wecui.WorldEditCUI; - -/** - * CUI communication event - * Called when a CUI event is sent from the server. - * - * @author lahwran - * @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 " + type + " - " + Utilities.join(params, "|") + " - Reason: " + reason); - setHandled(true); - } - - public int getInt(int index) { - return (int) Float.parseFloat(params[index]); - } - - public String getString(int index) { - return params[index]; - } - - public boolean isHandled() { - return handled; - } - - public boolean isCancelled() { - return isHandled(); - } - - public String[] getParams() { - return params; - } - - public String getType() { - return type; - } -} diff --git a/src/main/java/wecui/event/ChannelEvent.java b/src/main/java/wecui/event/ChannelEvent.java deleted file mode 100644 index 273a74b7..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 message; - } -} diff --git a/src/main/java/wecui/event/ChatCommandEvent.java b/src/main/java/wecui/event/ChatCommandEvent.java deleted file mode 100644 index 69fecf79..00000000 --- a/src/main/java/wecui/event/ChatCommandEvent.java +++ /dev/null @@ -1,99 +0,0 @@ -package wecui.event; - -import wecui.fevents.Event; -import wecui.fevents.HandlerList; -import java.util.HashMap; -import wecui.WorldEditCUI; -import wecui.fevents.Cancellable; - -/** - * 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(command); - if (handlers == null) { - handlers = defaulthandlers; - } - return handlers; - } - - public void markHandled() { - handled = true; - } - - public boolean isHandled() { - return handled; - } - - public String[] getArgs() { - return args; - } - - public String getCommand() { - return command; - } - - public String getRawMessage() { - return rawMessage; - } - - @Override - public boolean isCancelled() { - return cancelled; - } - - 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 633f4d61..00000000 --- a/src/main/java/wecui/event/OutgoingChatEvent.java +++ /dev/null @@ -1,43 +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 message; - } - - 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 aee3661f..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 partialTick; - } - - public Vector3 getPosition() { - return pos; - } - - @Override - protected String getEventName() { - return "WorldRenderEvent"; - } - - @Override - protected HandlerList getHandlers() { - return handlers; - } -} 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 fe29edf7..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 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 d9bdb4b3..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 eventClass; - } - - public List getAliases() { - return 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 b8deee01..00000000 --- a/src/main/java/wecui/event/command/VersionCommandEvent.java +++ /dev/null @@ -1,27 +0,0 @@ -package wecui.event.command; - -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() { - this.controller.getObfuscation().showChatMessage(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 deleted file mode 100644 index 9a483c37..00000000 --- a/src/main/java/wecui/event/cui/CUIBaseEvent.java +++ /dev/null @@ -1,90 +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 (controller == null || 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 " + args.length + " parameters instead. "; - for (String arg : args) { - message += arg + " "; - } - - throw new RuntimeException(message); - } else { - return this.run(); - } - - } - - public int getInt(int index) { - return (int) Float.parseFloat(args[index]); - } - - public double getDouble(int index) { - return Double.parseDouble(args[index]); - } - - public String getString(int index) { - return args[index]; - } -} diff --git a/src/main/java/wecui/event/cui/CUICylinderEvent.java b/src/main/java/wecui/event/cui/CUICylinderEvent.java deleted file mode 100644 index 0f008716..00000000 --- a/src/main/java/wecui/event/cui/CUICylinderEvent.java +++ /dev/null @@ -1,38 +0,0 @@ -package wecui.event.cui; - -import wecui.WorldEditCUI; - -/** - * Called when cylinder event is received - * - * @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); - - controller.getSelection().setCylinderCenter(x, y, z); - controller.getSelection().setCylinderRadius(radX, radZ); - - 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 deleted file mode 100644 index 311c2a88..00000000 --- a/src/main/java/wecui/event/cui/CUIEllipsoidEvent.java +++ /dev/null @@ -1,43 +0,0 @@ -package wecui.event.cui; - -import wecui.WorldEditCUI; - -/** - * Called when ellipsoid event is received - * - * @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); - 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); - } - - 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 deleted file mode 100644 index 889e4579..00000000 --- a/src/main/java/wecui/event/cui/CUIEventType.java +++ /dev/null @@ -1,62 +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); - - 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 eventClass; - } - - public String getKey() { - return key; - } - - public int getMaxParameters() { - return max; - } - - public int getMinParameters() { - return 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 deleted file mode 100644 index 92d1f124..00000000 --- a/src/main/java/wecui/event/cui/CUIMinMaxEvent.java +++ /dev/null @@ -1,32 +0,0 @@ -package wecui.event.cui; - -import wecui.WorldEditCUI; - -/** - * Called when resize event is received - * - * @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); - controller.getSelection().setMinMax(min, max); - - 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 deleted file mode 100644 index 20b8b734..00000000 --- a/src/main/java/wecui/event/cui/CUIPoint2DEvent.java +++ /dev/null @@ -1,35 +0,0 @@ -package wecui.event.cui; - -import wecui.WorldEditCUI; - -/** - * Called when poly point event is received - * - * @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); - int regionSize = this.getInt(3); - controller.getSelection().setPolygonPoint(id, x, z); - - 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 deleted file mode 100644 index 712473f6..00000000 --- a/src/main/java/wecui/event/cui/CUIPointEvent.java +++ /dev/null @@ -1,58 +0,0 @@ -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 - * - * @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); - int x = this.getInt(1); - int y = this.getInt(2); - int z = this.getInt(3); - - controller.getSelection().setCuboidPoint(id, x, y, z); - this.setLocalPoint(id, x, y, z); - controller.getDebugger().debug("Setting point #" + id); - - return null; - } - - protected void setLocalPoint(int id, int x, int y, int 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/CUISelectionEvent.java b/src/main/java/wecui/event/cui/CUISelectionEvent.java deleted file mode 100644 index 8d560fe5..00000000 --- a/src/main/java/wecui/event/cui/CUISelectionEvent.java +++ /dev/null @@ -1,49 +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; - -/** - * 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(controller); - } else if (this.getString(0).equals("polygon2d")) { - newRegion = new PolygonRegion(controller); - } else if (this.getString(0).equals("ellipsoid")) { - newRegion = new EllipsoidRegion(controller); - } else if (this.getString(0).equals("cylinder")) { - newRegion = new CylinderRegion(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."); - - return null; - } -} diff --git a/src/main/java/wecui/event/cui/CUIUpdateEvent.java b/src/main/java/wecui/event/cui/CUIUpdateEvent.java deleted file mode 100644 index 5cc62a3f..00000000 --- a/src/main/java/wecui/event/cui/CUIUpdateEvent.java +++ /dev/null @@ -1,26 +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/src/main/java/wecui/event/listeners/CUIListener.java b/src/main/java/wecui/event/listeners/CUIListener.java deleted file mode 100644 index f8103e93..00000000 --- a/src/main/java/wecui/event/listeners/CUIListener.java +++ /dev/null @@ -1,49 +0,0 @@ -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; - -/** - * Listener class for CUIEvent - * - * @author lahwran - * @author yetanotherx - * - */ -public class CUIListener implements Listener { - - protected WorldEditCUI controller; - - public CUIListener(WorldEditCUI controller) { - this.controller = controller; - } - - 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."); - } - - 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 deleted file mode 100644 index 363c5c67..00000000 --- a/src/main/java/wecui/event/listeners/ChannelListener.java +++ /dev/null @@ -1,38 +0,0 @@ -package wecui.event.listeners; - -import wecui.fevents.Listener; -import wecui.WorldEditCUI; -import wecui.event.CUIEvent; -import wecui.event.ChannelEvent; - -/** - * Listener class for incoming plugin channel messages - * - * @author lahwran - * @author yetanotherx - * - */ -public class ChannelListener implements Listener { - - 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."); - } - } -} 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 fcb5ca72..00000000 --- a/src/main/java/wecui/event/listeners/WorldEditCommandListener.java +++ /dev/null @@ -1,48 +0,0 @@ -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; - -/** - * 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 deleted file mode 100644 index f2ef8d89..00000000 --- a/src/main/java/wecui/event/listeners/WorldRenderListener.java +++ /dev/null @@ -1,58 +0,0 @@ -package wecui.event.listeners; - -import wecui.fevents.Listener; -import wecui.obfuscation.Obfuscation; -import wecui.WorldEditCUI; -import org.lwjgl.opengl.GL11; -import wecui.event.WorldRenderEvent; - -/** - * Listener for WorldRenderEvent - * - * @author lahwran - * @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.glDisable(GL11.GL_ALPHA_TEST); - GL11.glDisable(GL11.GL_TEXTURE_2D); - GL11.glDepthMask(false); - GL11.glPushMatrix(); - - try { - Obfuscation obf = controller.getObfuscation(); - - GL11.glTranslated(-obf.getPlayerXGuess(event.getPartialTick()), - -obf.getPlayerYGuess(event.getPartialTick()), - -obf.getPlayerZGuess(event.getPartialTick())); - GL11.glColor3f(1.0f, 1.0f, 1.0f); - if (controller.getSelection() != null) { - 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.glEnable(GL11.GL_ALPHA_TEST); - } -} 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 deleted file mode 100644 index 68ff8a82..00000000 --- a/src/main/java/wecui/exception/InitializationException.java +++ /dev/null @@ -1,20 +0,0 @@ -package wecui.exception; - -/** - * Special exception that only gets called during initialization - * Throwing this halts the loading of the mod - * - * @author yetanotherx - * - */ -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 deleted file mode 100644 index 8a3671ff..00000000 --- a/src/main/java/wecui/exception/ReflectException.java +++ /dev/null @@ -1,79 +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); - } -} \ No newline at end of file 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 05a2b9be..00000000 --- a/src/main/java/wecui/fevents/Event.java +++ /dev/null @@ -1,75 +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(); - - public String toString() { - return 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 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 f19db186..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() { - handlerslots = new EnumMap>>(Order.class); - for (Order o : Order.values()) { - 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 (handlerslots.get(order).contains(listener)) { - throw new IllegalStateException("This listener is already registered to order " + order.toString()); - } - baked = false; - 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()) { - 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 (handlerslots.get(order).contains(listener)) { - baked = false; - handlerslots.get(order).remove(listener); - } - } - - /** - * Bake HashMap and ArrayLists to 2d array - does nothing if not necessary - */ - void bake() { - if (baked) { - return; // don't re-bake when still valid - } - ArrayList handlerslist = new ArrayList(); - ArrayList handleridslist = new ArrayList(); - for (Entry>> entry : 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); - } - handlers = handlerslist.toArray(new Listener[handlerslist.size()][]); - handlerids = new int[handleridslist.size()]; - for (int i = 0; i < handleridslist.size(); i++) { - handlerids[i] = handleridslist.get(i); - } - 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 cea718f6..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 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 deleted file mode 100644 index d90d22a3..00000000 --- a/src/main/java/wecui/obfuscation/DataPacketList.java +++ /dev/null @@ -1,118 +0,0 @@ -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 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 - */ - public boolean add(T packet) { - if (packet instanceof Packet3Chat) { - - boolean cancelled = false; - String s = Obfuscation.getChatFromPacket((Packet3Chat) packet); - - OutgoingChatEvent chatevent = new OutgoingChatEvent(controller, s); - controller.getEventManager().callEvent(chatevent); - if (!chatevent.isCancelled() && s.startsWith("/") && s.length() > 1) { - ChatCommandEvent commandevent = new ChatCommandEvent(controller, s); - 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); - Obfuscation obf = controller.getObfuscation(); - - //Checks if it's a multiplayer world - if (!obf.isMultiplayerWorld()) { - return; - } - - EntityClientPlayerMP player = (EntityClientPlayerMP) obf.getPlayer(); - - 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; - } - - 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); - } - - 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 900c22d4..00000000 --- a/src/main/java/wecui/obfuscation/FieldObfuscation.java +++ /dev/null @@ -1,43 +0,0 @@ -package wecui.obfuscation; - -/** - * Method name obfuscation, used whenever we use reflection. - * This lets us keep reflected obfuscated methods in a central - * class to ease updating. - * - * @author yetanotherx - * - * @obfuscated 1.4.5 - */ -public enum FieldObfuscation { - - /** - * NetworkManager instance in NetClientHandler.class - */ - NETWORKMANAGER("g"), - /** - * Packet stream list in NetworkManager.class - */ - PACKETLIST("p"), - /** - * ID->Class hashmap for packets in Packet.class - */ - IDSTOCLASSES("l"), - /** - * Class->ID hashmap for packets in Packet.class - */ - CLASSESTOIDS("a"); - protected String variable; - - private FieldObfuscation(String variable) { - this.variable = variable; - } - - public String getVariable() { - return variable; - } - - public static String getVariable(FieldObfuscation type) { - return type.getVariable(); - } -} 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/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 deleted file mode 100644 index 410d84a6..00000000 --- a/src/main/java/wecui/render/LineColor.java +++ /dev/null @@ -1,70 +0,0 @@ -package wecui.render; - -import org.lwjgl.opengl.GL11; - -/** - * Stores color 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 - * the hidden line has an alpha value of 0.2f. They - * both have a thickness of 3.0f. - * - * @author yetanotherx - * @author lahwran - */ -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; - - 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); - } - - private LineColor(String hex) { - setColor(hex); - } - - public LineInfo getHidden() { - return hidden; - } - - public LineInfo getNormal() { - return normal; - } - - public LineInfo[] getColors() { - return new LineInfo[]{hidden, normal}; - } - - /** - * 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; - - 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); - } -} diff --git a/src/main/java/wecui/render/LineInfo.java b/src/main/java/wecui/render/LineInfo.java deleted file mode 100644 index 862a4b6a..00000000 --- a/src/main/java/wecui/render/LineInfo.java +++ /dev/null @@ -1,54 +0,0 @@ -package wecui.render; - -import org.lwjgl.opengl.GL11; - -/** - * 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, 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(lineWidth); - GL11.glDepthFunc(depthfunc); - } - - public void prepareColor() { - GL11.glColor4f(red, green, blue, alpha); - } -} 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/points/PointCube.java b/src/main/java/wecui/render/points/PointCube.java deleted file mode 100644 index a4e782a1..00000000 --- a/src/main/java/wecui/render/points/PointCube.java +++ /dev/null @@ -1,56 +0,0 @@ -package wecui.render.points; - -import wecui.render.LineColor; -import wecui.render.shapes.Render3DBox; -import wecui.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. - * - * @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(color, point.subtract(minVec), point.add(maxVec)).render(); - } - - public Vector3 getPoint() { - return point; - } - - public void setPoint(Vector3 point) { - this.point = point; - } - - public LineColor getColor() { - return 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 deleted file mode 100644 index fe192ff2..00000000 --- a/src/main/java/wecui/render/points/PointRectangle.java +++ /dev/null @@ -1,52 +0,0 @@ -package wecui.render.points; - -import wecui.render.LineColor; -import wecui.render.shapes.Render3DBox; -import wecui.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. - * - * @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(color, point.subtract(minVec).toVector3(min - off), point.add(maxVec).toVector3(max + 1 + off)).render(); - } - - public Vector2 getPoint() { - return point; - } - - public void setPoint(Vector2 point) { - this.point = point; - } - - public LineColor getColor() { - return 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 deleted file mode 100644 index 6a37a444..00000000 --- a/src/main/java/wecui/render/region/BaseRegion.java +++ /dev/null @@ -1,50 +0,0 @@ -package wecui.render.region; - -import wecui.InitializationFactory; -import wecui.WorldEditCUI; - -/** - * Base region storage class. Provides - * abstract methods for setting various - * points in the region. - * - * @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, int x, int y, int 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 abstract RegionType getType(); -} diff --git a/src/main/java/wecui/render/region/CuboidRegion.java b/src/main/java/wecui/render/region/CuboidRegion.java deleted file mode 100644 index f673d928..00000000 --- a/src/main/java/wecui/render/region/CuboidRegion.java +++ /dev/null @@ -1,100 +0,0 @@ -package wecui.render.region; - -import wecui.WorldEditCUI; -import wecui.render.LineColor; -import wecui.render.shapes.Render3DBox; -import wecui.render.points.PointCube; -import wecui.render.shapes.Render3DGrid; -import wecui.util.Vector3; -import wecui.util.Vector3m; - -/** - * Main controller for a cuboid-type region - * - * @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 (firstPoint != null && secondPoint != null) { - firstPoint.render(); - 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(); - } - } - - @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); - } else if (id == 1) { - secondPoint = new PointCube(x, y, z); - 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[]{firstPoint, 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 deleted file mode 100644 index 226e4bd0..00000000 --- a/src/main/java/wecui/render/region/CylinderRegion.java +++ /dev/null @@ -1,69 +0,0 @@ -package wecui.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; - -/** - * Main controller for a cylinder-type region - * - * @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 (center != null) { - center.render(); - - int tMin = minY; - int tMax = maxY; - - if (minY == 0 || maxY == 0) { - tMin = (int) center.getPoint().getY(); - tMax = (int) 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(); - - } - } - - @Override - public void setCylinderCenter(int x, int y, int z) { - center = new PointCube(x, y, z); - 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) { - minY = min; - 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 deleted file mode 100644 index 6ad99aa7..00000000 --- a/src/main/java/wecui/render/region/EllipsoidRegion.java +++ /dev/null @@ -1,53 +0,0 @@ -package wecui.render.region; - -import wecui.WorldEditCUI; -import wecui.render.LineColor; -import wecui.render.shapes.RenderEllipsoid; -import wecui.render.points.PointCube; -import wecui.util.Vector3; - -/** - * Main controller for a ellipsoid-type region - * - * @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( center != null && radii != null ) { - center.render(); - - new RenderEllipsoid(LineColor.ELLIPSOIDGRID, center, radii).render(); - - } - else if( center != null ) { - center.render(); - } - } - - @Override - public void setEllipsoidCenter(int x, int y, int z) { - center = new PointCube(x, y, z); - center.setColor(LineColor.ELLIPSOIDCENTER); - } - - @Override - public void setEllipsoidRadii(double x, double y, double z) { - 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 deleted file mode 100644 index 269e07cb..00000000 --- a/src/main/java/wecui/render/region/PolygonRegion.java +++ /dev/null @@ -1,67 +0,0 @@ -package wecui.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; - -/** - * Main controller for a polygon-type region - * - * @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 (points == null) { - return; - } - - for (PointRectangle point : points) { - point.render(min, max); - } - - new Render2DBox(LineColor.POLYBOX, points, min, max).render(); - new Render2DGrid(LineColor.POLYGRID, points, min, 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 < points.size()) { - points.set(id, point); - } else { - for (int i = 0; i < id - points.size(); i++) { - points.add(null); - } - points.add(point); - } - } - - @Override - public RegionType getType() { - return RegionType.POLYGON; - } -} diff --git a/src/main/java/wecui/render/region/RegionType.java b/src/main/java/wecui/render/region/RegionType.java deleted file mode 100644 index a24ab3c0..00000000 --- a/src/main/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 - -} diff --git a/src/main/java/wecui/render/shapes/Render2DBox.java b/src/main/java/wecui/render/shapes/Render2DBox.java deleted file mode 100644 index a0168a6e..00000000 --- a/src/main/java/wecui/render/shapes/Render2DBox.java +++ /dev/null @@ -1,48 +0,0 @@ -package wecui.render.shapes; - -import java.util.List; -import org.lwjgl.opengl.GL11; -import wecui.obfuscation.RenderObfuscation; -import wecui.render.LineColor; -import wecui.render.LineInfo; -import wecui.render.points.PointRectangle; - -/** - * Draws the top and bottom rings of a polygon region - * - * @author yetanotherx - * @author lahwran - */ -public class Render2DBox { - - protected RenderObfuscation obf = RenderObfuscation.getInstance(); - 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() { - double off = 0.03; - for (LineInfo tempColor : color.getColors()) { - tempColor.prepareRender(); - - obf.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); - } - } - obf.finishDrawing(); - } - } -} diff --git a/src/main/java/wecui/render/shapes/Render2DGrid.java b/src/main/java/wecui/render/shapes/Render2DGrid.java deleted file mode 100644 index 489dc029..00000000 --- a/src/main/java/wecui/render/shapes/Render2DGrid.java +++ /dev/null @@ -1,52 +0,0 @@ -package wecui.render.shapes; - -import java.util.List; -import org.lwjgl.opengl.GL11; -import wecui.obfuscation.RenderObfuscation; -import wecui.render.LineColor; -import wecui.render.LineInfo; -import wecui.render.points.PointRectangle; - -/** - * Draws the grid for a polygon region - * - * @author yetanotherx - * @author lahwran - */ -public class Render2DGrid { - - protected RenderObfuscation obf = RenderObfuscation.getInstance(); - 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 = min; height <= max + 1; height++) { - drawPoly(height + off); - } - } - - protected void drawPoly(double height) { - for (LineInfo tempColor : color.getColors()) { - tempColor.prepareRender(); - - obf.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); - } - } - obf.finishDrawing(); - } - } -} diff --git a/src/main/java/wecui/render/shapes/Render3DBox.java b/src/main/java/wecui/render/shapes/Render3DBox.java deleted file mode 100644 index e2d37eb0..00000000 --- a/src/main/java/wecui/render/shapes/Render3DBox.java +++ /dev/null @@ -1,76 +0,0 @@ -package wecui.render.shapes; - -import org.lwjgl.opengl.GL11; -import wecui.obfuscation.RenderObfuscation; -import wecui.render.LineColor; -import wecui.render.LineInfo; -import wecui.util.Vector3; - -/** - * Draws a rectangular prism around 2 corners - * - * @author yetanotherx - * @author lahwran - */ -public class Render3DBox { - - protected RenderObfuscation obf = RenderObfuscation.getInstance(); - 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() { - 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()) { - tempColor.prepareRender(); - - // Draw bottom face - obf.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(); - - // Draw top face - obf.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(); - - // Draw join top and bottom faces - obf.startDrawing(GL11.GL_LINES); - tempColor.prepareColor(); - - obf.addVertex(x1, y1, z1); - obf.addVertex(x1, y2, z1); - - obf.addVertex(x2, y1, z1); - obf.addVertex(x2, y2, z1); - - obf.addVertex(x2, y1, z2); - obf.addVertex(x2, y2, z2); - - obf.addVertex(x1, y1, z2); - obf.addVertex(x1, y2, z2); - - obf.finishDrawing(); - } - } -} diff --git a/src/main/java/wecui/render/shapes/Render3DGrid.java b/src/main/java/wecui/render/shapes/Render3DGrid.java deleted file mode 100644 index 74063f3a..00000000 --- a/src/main/java/wecui/render/shapes/Render3DGrid.java +++ /dev/null @@ -1,155 +0,0 @@ -package wecui.render.shapes; - -import org.lwjgl.opengl.GL11; -import wecui.obfuscation.RenderObfuscation; -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. - * - * @author yetanotherx - */ -public class Render3DGrid { - - protected RenderObfuscation obf = RenderObfuscation.getInstance(); - 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() { - 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()) { - tempColor.prepareRender(); - - RenderObfuscation o = RenderObfuscation.getInstance(); - o.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) { - o.addVertex(x1, y + yoff, z); - o.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) { - o.addVertex(x1, y + yoff, z); - o.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) { - o.addVertex(x, y + yoff, z1); - o.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) { - o.addVertex(x, y + yoff, z1); - o.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) { - o.addVertex(x + xoff, y1, z); - o.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); - } - } - // 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); - } - } - // 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); - } - } - - // Ymin XZ plane, z axis - z = z1; - 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); - } - } - // 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); - } - } - // 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); - } - } - // 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); - } - } - - o.finishDrawing(); - } - } -} diff --git a/src/main/java/wecui/render/shapes/RenderCylinderBox.java b/src/main/java/wecui/render/shapes/RenderCylinderBox.java deleted file mode 100644 index 7d50f178..00000000 --- a/src/main/java/wecui/render/shapes/RenderCylinderBox.java +++ /dev/null @@ -1,55 +0,0 @@ -package wecui.render.shapes; - -import org.lwjgl.opengl.GL11; -import wecui.obfuscation.RenderObfuscation; -import wecui.render.LineColor; -import wecui.render.LineInfo; -import wecui.render.points.PointCube; - -/** - * Draws the top and bottom circles around a cylindrical region - * - * @author yetanotherx - */ -public class RenderCylinderBox { - - protected LineColor color; - protected double radX = 0; - protected double radZ = 0; - protected int minY; - protected int maxY; - protected RenderObfuscation obf = RenderObfuscation.getInstance(); - 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() { - 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); - 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); - - obf.addVertex(centerX + tempX, yBlock, centerZ + tempZ); - } - obf.finishDrawing(); - } - } - } -} diff --git a/src/main/java/wecui/render/shapes/RenderCylinderCircles.java b/src/main/java/wecui/render/shapes/RenderCylinderCircles.java deleted file mode 100644 index 63077fe8..00000000 --- a/src/main/java/wecui/render/shapes/RenderCylinderCircles.java +++ /dev/null @@ -1,55 +0,0 @@ -package wecui.render.shapes; - -import org.lwjgl.opengl.GL11; -import wecui.obfuscation.RenderObfuscation; -import wecui.render.LineColor; -import wecui.render.LineInfo; -import wecui.render.points.PointCube; - -/** - * Draws the circles around a cylindrical region - * - * @author yetanotherx - */ -public class RenderCylinderCircles { - - protected LineColor color; - protected double radX = 0; - protected double radZ = 0; - protected int minY; - protected int maxY; - protected RenderObfuscation obf = RenderObfuscation.getInstance(); - 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() { - 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); - 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); - - obf.addVertex(centerX + tempX, yBlock, centerZ + tempZ); - } - obf.finishDrawing(); - } - } - } -} diff --git a/src/main/java/wecui/render/shapes/RenderCylinderGrid.java b/src/main/java/wecui/render/shapes/RenderCylinderGrid.java deleted file mode 100644 index 741aab3f..00000000 --- a/src/main/java/wecui/render/shapes/RenderCylinderGrid.java +++ /dev/null @@ -1,73 +0,0 @@ -package wecui.render.shapes; - -import org.lwjgl.opengl.GL11; -import wecui.obfuscation.RenderObfuscation; -import wecui.render.LineColor; -import wecui.render.LineInfo; -import wecui.render.points.PointCube; - -/** - * Draws the grid lines around a cylindrical region - * - * @author yetanotherx - */ -public class RenderCylinderGrid { - - protected LineColor color; - protected double radX = 0; - protected double radZ = 0; - protected int minY; - protected int maxY; - protected RenderObfuscation obf = RenderObfuscation.getInstance(); - 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() { - for (LineInfo tempColor : 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); - - for (double tempX = negRadiusX; tempX <= posRadiusX; ++tempX) { - double tempZ = radZ * Math.cos(Math.asin(tempX / radX)); - obf.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); - - obf.finishDrawing(); - } - - for (double tempZ = negRadiusZ; tempZ <= posRadiusZ; ++tempZ) { - double tempX = radX * Math.sin(Math.acos(tempZ / radZ)); - obf.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); - - obf.finishDrawing(); - } - } - } -} diff --git a/src/main/java/wecui/render/shapes/RenderEllipsoid.java b/src/main/java/wecui/render/shapes/RenderEllipsoid.java deleted file mode 100644 index 1ba053d4..00000000 --- a/src/main/java/wecui/render/shapes/RenderEllipsoid.java +++ /dev/null @@ -1,130 +0,0 @@ -package wecui.render.shapes; - -import org.lwjgl.opengl.GL11; -import wecui.obfuscation.RenderObfuscation; -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. - * - * @author yetanotherx - */ -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; - 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 : color.getColors()) { - tempColor.prepareRender(); - drawXZPlane(tempColor); - drawYZPlane(tempColor); - drawXYPlane(tempColor); - } - } - - protected void drawXZPlane(LineInfo color) { - int yRad = (int) Math.floor(radii.getY()); - for (int yBlock = -yRad; yBlock < yRad; yBlock++) { - obf.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())); - - obf.addVertex(centerX + tempX, centerY + yBlock, centerZ + tempZ); - } - obf.finishDrawing(); - } - - obf.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); - double tempZ = radii.getZ() * Math.sin(tempTheta); - - obf.addVertex(centerX + tempX, centerY, centerZ + tempZ); - } - obf.finishDrawing(); - } - - protected void drawYZPlane(LineInfo color) { - int xRad = (int) Math.floor(radii.getX()); - for (int xBlock = -xRad; xBlock < xRad; xBlock++) { - obf.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())); - - obf.addVertex(centerX + xBlock, centerY + tempY, centerZ + tempZ); - } - obf.finishDrawing(); - } - - obf.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); - double tempZ = radii.getZ() * Math.sin(tempTheta); - - obf.addVertex(centerX, centerY + tempY, centerZ + tempZ); - } - obf.finishDrawing(); - } - - protected void drawXYPlane(LineInfo color) { - int zRad = (int) Math.floor(radii.getZ()); - for (int zBlock = -zRad; zBlock < zRad; zBlock++) { - obf.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())); - - obf.addVertex(centerX + tempX, centerY + tempY, centerZ + zBlock); - } - obf.finishDrawing(); - } - - obf.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); - double tempY = radii.getY() * Math.sin(tempTheta); - - obf.addVertex(centerX + tempX, centerY + tempY, centerZ); - } - obf.finishDrawing(); - } -} diff --git a/src/main/java/wecui/util/ChatColor.java b/src/main/java/wecui/util/ChatColor.java deleted file mode 100644 index a3e2797f..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 code; - } - - @Override - public String toString() { - return String.format("\u00A7%x", 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 deleted file mode 100644 index e334c2ac..00000000 --- a/src/main/java/wecui/util/ConsoleLogFormatter.java +++ /dev/null @@ -1,56 +0,0 @@ -package wecui.util; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.text.SimpleDateFormat; -import java.util.logging.Formatter; -import java.util.logging.Level; -import java.util.logging.LogRecord; - -/** - * Console log formatter, from Minecraft Server. - * Brought into Minecraft Client. - * - * TODO: Necessary anymore? - * @author Mojang - */ -public class ConsoleLogFormatter extends Formatter { - - private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - - 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 diff --git a/src/main/java/wecui/util/Utilities.java b/src/main/java/wecui/util/Utilities.java deleted file mode 100644 index 1e64a7de..00000000 --- a/src/main/java/wecui/util/Utilities.java +++ /dev/null @@ -1,140 +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/src/main/java/wecui/util/Vector2.java b/src/main/java/wecui/util/Vector2.java deleted file mode 100644 index 033f30aa..00000000 --- a/src/main/java/wecui/util/Vector2.java +++ /dev/null @@ -1,553 +0,0 @@ -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 + ")"; - } -} diff --git a/src/main/java/wecui/util/Vector2m.java b/src/main/java/wecui/util/Vector2m.java deleted file mode 100644 index 503c340d..00000000 --- a/src/main/java/wecui/util/Vector2m.java +++ /dev/null @@ -1,126 +0,0 @@ -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; - } -} diff --git a/src/main/java/wecui/util/Vector3.java b/src/main/java/wecui/util/Vector3.java deleted file mode 100644 index 3768b5cf..00000000 --- a/src/main/java/wecui/util/Vector3.java +++ /dev/null @@ -1,573 +0,0 @@ -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; - } -} diff --git a/src/main/java/wecui/util/Vector3m.java b/src/main/java/wecui/util/Vector3m.java deleted file mode 100644 index 1ed7d18a..00000000 --- a/src/main/java/wecui/util/Vector3m.java +++ /dev/null @@ -1,159 +0,0 @@ -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; - } -} diff --git a/src/main/java/wecui/vendor/org/joor/Reflect.java b/src/main/java/wecui/vendor/org/joor/Reflect.java deleted file mode 100644 index 4ff492de..00000000 --- a/src/main/java/wecui/vendor/org/joor/Reflect.java +++ /dev/null @@ -1,539 +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 wecui.exception.ReflectException; -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; - -/** - * 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) 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 = type().getField(name); - if (!field.isAccessible()) { - field.setAccessible(true); - } - field.set(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 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 = type().getField(name); - if (!field.isAccessible()) { - field.setAccessible(true); - } - return on(field.get(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 : type().getFields()) { - if (!isClass ^ Modifier.isStatic(field.getModifiers())) { - String name = field.getName(); - result.put(name, 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 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 = type().getMethod(name, types); - return on(method, 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); - } - } - - 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 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 = 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)) { - 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; - } else { - return false; - } - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return object.hashCode(); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (obj instanceof Reflect) { - return object.equals(((Reflect) obj).get()); - } - - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return 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); - } else { - 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 (isClass) { - return (Class) object; - } else { - return 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 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 -