EDIT: You call the tick() method of your main class from GuiIngame's method renderIngameOverlay(...), or something similar.
(Almost) Every single tutorial you come across on the internet about how to make a hacked client wants you to edit the base classes of Minecraft. Which you shouldn't really do. Editing the base classes makes your client much harder to maintain, as well as not being 'java-style', since Java is an OOP (Object-Oriented Programming) language.
By the end of this, hopefully, you'll have a better idea of how to do this.
DISCLAIMER
I cannot claim full credit for this. A shoutout goes to Rza1337 and Darkstorm_ at Hack Forums for their wonderful tutorials on how to do this; I'm just passing their information along. Thanks to Darkstorm_ again for his wonderful GUI API.
Also, I'm doing this for the people who care; I don't care if it gets skidded.
We'll start with the base class.
Main class
package com.godshawk.colony.core;
import java.util.ArrayList;
import net.minecraft.client.Minecraft;
import net.minecraft.src.Gui;
import org.darkstorm.minecraft.gui.GuiManagerImpl;
import org.darkstorm.minecraft.gui.component.Frame;
import org.lwjgl.input.Keyboard;
import com.godshawk.colony.gui.CGuiIngame;
import com.godshawk.colony.gui.ModsGui;
import com.godshawk.colony.gui.theme.ColonyTheme;
import com.godshawk.colony.mods.AutoFish;
import com.godshawk.colony.mods.ChestESP;
import com.godshawk.colony.mods.Fly;
import com.godshawk.colony.mods.Fullbright;
import com.godshawk.colony.mods.KillAura;
import com.godshawk.colony.mods.NoFall;
import com.godshawk.colony.mods.Nuker;
import com.godshawk.colony.mods.PlayerESP;
import com.godshawk.colony.mods.Sprint;
import com.godshawk.colony.mods.Tracer;
import com.godshawk.colony.mods.Waterwalk;
import com.godshawk.colony.mods.Xray;
import com.godshawk.colony.util.Console;
import com.godshawk.colony.util.Tickable;
import com.godshawk.colony.util.Utils;
public class Colony {
public Colony( Minecraft mc ) {
minecraft = mc;
ck = new CheckKey( mc );
manager = new GuiManagerImpl( );
init( );
}
public static ArrayList<String> enabledMods = new ArrayList<String>( );
public void init( ) {
utils = new Utils( minecraft );
fullbright = new Fullbright( this, minecraft );
killaura = new KillAura( this, minecraft );
nuker = new Nuker( this, minecraft );
t = new Tracer( this, minecraft );
pesp = new PlayerESP( this, minecraft );
cesp = new ChestESP( this, minecraft );
fly = new Fly( this, minecraft );
nof = new NoFall( this, minecraft );
spr = new Sprint( this, minecraft );
xray = new Xray( this, minecraft );
ww = new Waterwalk( this, minecraft );
af = new AutoFish( this, minecraft );
manager.setTheme( new ColonyTheme( ) );
modgui = new ModsGui( manager );
}
public void tick( ) {
for ( Tickable tick : tickables ) { // For (tickable in tickables)
// {tickable.tick()}
tick.tick( );
}
if ( this.minecraft.ingameGUI.getClass( ) != CGuiIngame.class ) {
this.minecraft.ingameGUI = new CGuiIngame( this.minecraft );
}
updateArray( );
checkForKeyPress( );
updatePinnedFrames( );
}
public Utils getUtils( ) {
return utils;
}
public void updatePinnedFrames( ) {
if ( ( minecraft.currentScreen == null ) || ( minecraft.currentScreen == (Gui) minecraft.ingameGUI ) ) {
for ( Frame frame : manager.getFrames( ) ) {
if ( frame.isPinned( ) ) {
frame.update( );
}
}
}
}
public void renderPinnedFrames( ) {
if ( ( minecraft.currentScreen == null ) || ( minecraft.currentScreen == (Gui) minecraft.ingameGUI ) ) {
for ( Frame frame : manager.getFrames( ) ) {
if ( frame.isPinned( ) ) {
frame.render( );
}
}
}
}
public void addToTick( Tickable tickable ) {
if ( !tickables.contains( tickable ) ) {
tickables.add( tickable );
}
}
public void removeFromTick( Tickable tickable ) {
if ( tickables.contains( tickable ) ) {
tickables.remove( tickable );
}
}
public void checkForKeyPress( ) {
// GUI
if ( ck.checkKey( Keyboard.KEY_Y ) ) {
minecraft.displayGuiScreen( modgui );
}
if ( ck.checkKey( Keyboard.KEY_GRAVE ) ) {
// TODO Console
minecraft.displayGuiScreen( new Console( ) );
}
// Keybinds
if ( ck.checkKey( Keyboard.KEY_F ) ) {
fullbright.toggle( );
}
if ( ck.checkKey( Keyboard.KEY_P ) ) {
killaura.toggle( );
}
if ( ck.checkKey( Keyboard.KEY_L ) ) {
nuker.toggle( );
}
if ( ck.checkKey( Keyboard.KEY_M ) ) {
t.toggle( );
}
if ( ck.checkKey( Keyboard.KEY_R ) ) {
pesp.toggle( );
}
if ( ck.checkKey( Keyboard.KEY_C ) ) {
cesp.toggle( );
}
if ( ck.checkKey( Keyboard.KEY_J ) ) {
fly.toggle( );
}
if ( ck.checkKey( Keyboard.KEY_O ) ) {
nof.toggle( );
}
if ( ck.checkKey( Keyboard.KEY_K ) ) {
spr.toggle( );
}
if ( ck.checkKey( Keyboard.KEY_X ) ) {
// ol.toggle();
xray.toggle( );
}
}
public void updateArray( ) {
if ( nof.isActive( ) && !enabledMods.contains( "NoFall" ) ) {
enabledMods.add( "NoFall" );
} else {
if ( !nof.isActive( ) ) {
enabledMods.remove( "NoFall" );
}
}
if ( fly.isActive( ) && !enabledMods.contains( "Fly" ) ) {
enabledMods.add( "Fly" );
} else {
if ( !fly.isActive( ) ) {
enabledMods.remove( "Fly" );
}
}
if ( cesp.isActive( ) && !enabledMods.contains( "Chest ESP" ) ) {
enabledMods.add( "Chest ESP" );
} else {
if ( !cesp.isActive( ) ) {
enabledMods.remove( "Chest ESP" );
}
}
if ( pesp.isActive( ) && !enabledMods.contains( "Player ESP" ) ) {
enabledMods.add( "Player ESP" );
} else {
if ( !pesp.isActive( ) ) {
enabledMods.remove( "Player ESP" );
}
}
if ( t.isActive( ) && !enabledMods.contains( "Tracers" ) ) {
enabledMods.add( "Tracers" );
} else {
if ( !t.isActive( ) ) {
enabledMods.remove( "Tracers" );
}
}
if ( nuker.isActive( ) && !enabledMods.contains( "Nuker" ) ) {
enabledMods.add( "Nuker" );
} else {
if ( !nuker.isActive( ) ) {
enabledMods.remove( "Nuker" );
}
}
if ( killaura.isActive( ) && !enabledMods.contains( "KillAura" ) ) {
enabledMods.add( "KillAura" );
} else {
if ( !killaura.isActive( ) ) {
enabledMods.remove( "KillAura" );
}
}
if ( fullbright.isActive( ) && !enabledMods.contains( "Fullbright" ) ) {
enabledMods.add( "Fullbright" );
} else {
if ( !fullbright.isActive( ) ) {
enabledMods.remove( "Fullbright" );
}
}
if ( spr.isActive( ) && !enabledMods.contains( "Sprint" ) ) {
enabledMods.add( "Sprint" );
} else {
if ( !spr.isActive( ) ) {
enabledMods.remove( "Sprint" );
}
}
if ( xray.isActive( ) && !enabledMods.contains( "X-Ray" ) ) {
enabledMods.add( "X-Ray" );
} else {
if ( !xray.isActive( ) ) {
enabledMods.remove( "X-Ray" );
}
}
if ( ww.isActive( ) && !enabledMods.contains( "Waterwalk" ) ) {
enabledMods.add( "Waterwalk" );
} else {
if ( !ww.isActive( ) ) {
enabledMods.remove( "Waterwalk" );
}
}
if ( af.isActive( ) && !enabledMods.contains( "AutoFish" ) ) {
enabledMods.add( "AutoFish" );
} else {
if ( !af.isActive( ) ) {
enabledMods.remove( "AutoFish" );
}
}
}
public static KillAura killaura;
public static Fullbright fullbright;
public static Nuker nuker;
public static Tracer t;
public static PlayerESP pesp;
public static ChestESP cesp;
public static Fly fly;
public static NoFall nof;
public static Sprint spr;
public static Xray xray;
public static Waterwalk ww;
public static AutoFish af;
public CheckKey ck;
public Utils utils;
public static Minecraft minecraft;
public ArrayList<Tickable> tickables = new ArrayList<Tickable>( );
public static GuiManagerImpl manager;
public ModsGui modgui;
}
DISCLAIMER II
Yeah, I know this is ugly, but I'm kinda a noob at OOP; this is just (way) more OOP than most coding tutorials.
(Disclaimer III: This is NOT what your first class will look like; this is mine after a ton of work. I was just too lazy to edit all my stuff out.)
This looks big and scary, right? Let's break it down.
Code:
public static KillAura killaura;
public static Fullbright fullbright;
public static Nuker nuker;
public static Tracer t;
public static PlayerESP pesp;
public static ChestESP cesp;
public static Fly fly;
public static NoFall nof;
public static Sprint spr;
public static Xray xray;
public static Waterwalk ww;
public static AutoFish af;
Rather than have hacks all over the place, we do our best to store the hacks in their own separate classes; this makes it MUCH easier to maintain your code, as well as making it OOP. This part is just the declaration of all our hacks.
Code:
// Hack utilities
public CheckKey ck;
public Utils utils;
// Reference to the Minecraft instance
public static Minecraft minecraft;
// ArrayList of all our hacks; the hacks all run their stuff every tick
public ArrayList<Tickable> tickables = new ArrayList<Tickable>( );
// Used for Darkstorm_'s GUI API
public static GuiManagerImpl manager;
public ModsGui modgui;
The comments should be pretty self explanatory in that, but in case they aren't:
CheckKey and Utils are the utility classes for our hacks. Not much else.
Minecraft should be obvious.
ArrayList<Tickable> tickables ... is where it starts getting confusing. Basically, what it's doing is this:
All our hacks are 'tickables', or they all get ticked while activated. What we're doing here is making an ArrayList of 'tickables', ie the activated hacks, so that every tick we can just run through and tick them all easily.
GuiManagerImpl/ModsGui I will get to, just not right now.
Let's continue.
Code:
public Colony( Minecraft mc ) {
minecraft = mc;
ck = new CheckKey( mc );
manager = new GuiManagerImpl( );
init( );
}
This is the constructor for our class. This gets called once in GuiIngame (which I'll talk about later) to create the instance of the main class of your client. It initializes our Minecraft instance, initializes the CheckKey instance, initializes the manager for Darkstorm_'s GUI API, and does the init() void.
Code:
public void init( ) {
utils = new Utils( minecraft );
fullbright = new Fullbright( this, minecraft );
killaura = new KillAura( this, minecraft );
nuker = new Nuker( this, minecraft );
t = new Tracer( this, minecraft );
pesp = new PlayerESP( this, minecraft );
cesp = new ChestESP( this, minecraft );
fly = new Fly( this, minecraft );
nof = new NoFall( this, minecraft );
spr = new Sprint( this, minecraft );
xray = new Xray( this, minecraft );
ww = new Waterwalk( this, minecraft );
af = new AutoFish( this, minecraft );
manager.setTheme( new ColonyTheme( ) );
modgui = new ModsGui( manager );
}
This void creates all the instances of our hacks (as well as some GUI stuff). That's all it does; that's all it has to do.
Code:
public static ArrayList<String> enabledMods = new ArrayList<String>( );
This creates an ArrayList of Strings for our ArrayList/Enabled Mods List. You use the contents of this list to render your ArrayList on-screen.
Code:
public void tick( ) {
for ( Tickable tick : tickables ) { // For (tickable in tickables)
// {tickable.tick()}
tick.tick( );
}
if ( this.minecraft.ingameGUI.getClass( ) != CGuiIngame.class ) {
this.minecraft.ingameGUI = new CGuiIngame( this.minecraft );
}
updateArray( );
checkForKeyPress( );
updatePinnedFrames( );
}
This method is called every tick (usually from GuiIngame). What it does is:
1) Check the list of tickables to see what hacks are enabled. If there's a hack in the list, it gets ticked.
2) Switches the GuiIngame to a custom GuiIngame, literally
Code:
public class CGuiIngame extends GuiIngame
. The idea behind this is that we mod the base classes as little as possible.
3) Updates the ArrayList.
4) CheckKey.
5) Update pinned frames (Darkstorm_'s GUI API).
Code:
public void updateArray( ) {
if ( nof.isActive( ) && !enabledMods.contains( "NoFall" ) ) {
enabledMods.add( "NoFall" );
} else {
if ( !nof.isActive( ) ) {
enabledMods.remove( "NoFall" );
}
}
if ( fly.isActive( ) && !enabledMods.contains( "Fly" ) ) {
enabledMods.add( "Fly" );
} else {
if ( !fly.isActive( ) ) {
enabledMods.remove( "Fly" );
}
}
if ( cesp.isActive( ) && !enabledMods.contains( "Chest ESP" ) ) {
enabledMods.add( "Chest ESP" );
} else {
if ( !cesp.isActive( ) ) {
enabledMods.remove( "Chest ESP" );
}
}
if ( pesp.isActive( ) && !enabledMods.contains( "Player ESP" ) ) {
enabledMods.add( "Player ESP" );
} else {
if ( !pesp.isActive( ) ) {
enabledMods.remove( "Player ESP" );
}
}
if ( t.isActive( ) && !enabledMods.contains( "Tracers" ) ) {
enabledMods.add( "Tracers" );
} else {
if ( !t.isActive( ) ) {
enabledMods.remove( "Tracers" );
}
}
if ( nuker.isActive( ) && !enabledMods.contains( "Nuker" ) ) {
enabledMods.add( "Nuker" );
} else {
if ( !nuker.isActive( ) ) {
enabledMods.remove( "Nuker" );
}
}
if ( killaura.isActive( ) && !enabledMods.contains( "KillAura" ) ) {
enabledMods.add( "KillAura" );
} else {
if ( !killaura.isActive( ) ) {
enabledMods.remove( "KillAura" );
}
}
if ( fullbright.isActive( ) && !enabledMods.contains( "Fullbright" ) ) {
enabledMods.add( "Fullbright" );
} else {
if ( !fullbright.isActive( ) ) {
enabledMods.remove( "Fullbright" );
}
}
if ( spr.isActive( ) && !enabledMods.contains( "Sprint" ) ) {
enabledMods.add( "Sprint" );
} else {
if ( !spr.isActive( ) ) {
enabledMods.remove( "Sprint" );
}
}
if ( xray.isActive( ) && !enabledMods.contains( "X-Ray" ) ) {
enabledMods.add( "X-Ray" );
} else {
if ( !xray.isActive( ) ) {
enabledMods.remove( "X-Ray" );
}
}
if ( ww.isActive( ) && !enabledMods.contains( "Waterwalk" ) ) {
enabledMods.add( "Waterwalk" );
} else {
if ( !ww.isActive( ) ) {
enabledMods.remove( "Waterwalk" );
}
}
if ( af.isActive( ) && !enabledMods.contains( "AutoFish" ) ) {
enabledMods.add( "AutoFish" );
} else {
if ( !af.isActive( ) ) {
enabledMods.remove( "AutoFish" );
}
}
}
This is quite possibly the ugliest code I've ever written. All it does is update the ArrayList.
Code:
public void checkForKeyPress( ) {
// GUI
if ( ck.checkKey( Keyboard.KEY_Y ) ) {
minecraft.displayGuiScreen( modgui );
}
if ( ck.checkKey( Keyboard.KEY_GRAVE ) ) {
// TODO Console
minecraft.displayGuiScreen( new Console( ) );
}
// Keybinds
if ( ck.checkKey( Keyboard.KEY_F ) ) {
fullbright.toggle( );
}
if ( ck.checkKey( Keyboard.KEY_P ) ) {
killaura.toggle( );
}
if ( ck.checkKey( Keyboard.KEY_L ) ) {
nuker.toggle( );
}
if ( ck.checkKey( Keyboard.KEY_M ) ) {
t.toggle( );
}
if ( ck.checkKey( Keyboard.KEY_R ) ) {
pesp.toggle( );
}
if ( ck.checkKey( Keyboard.KEY_C ) ) {
cesp.toggle( );
}
if ( ck.checkKey( Keyboard.KEY_J ) ) {
fly.toggle( );
}
if ( ck.checkKey( Keyboard.KEY_O ) ) {
nof.toggle( );
}
if ( ck.checkKey( Keyboard.KEY_K ) ) {
spr.toggle( );
}
if ( ck.checkKey( Keyboard.KEY_X ) ) {
// ol.toggle();
xray.toggle( );
}
}
This just checks for key presses; should be self-explanatory.
Code:
public void updatePinnedFrames( ) {
if ( ( minecraft.currentScreen == null ) || ( minecraft.currentScreen == (Gui) minecraft.ingameGUI ) ) {
for ( Frame frame : manager.getFrames( ) ) {
if ( frame.isPinned( ) ) {
frame.update( );
}
}
}
}
public void renderPinnedFrames( ) {
if ( ( minecraft.currentScreen == null ) || ( minecraft.currentScreen == (Gui) minecraft.ingameGUI ) ) {
for ( Frame frame : manager.getFrames( ) ) {
if ( frame.isPinned( ) ) {
frame.render( );
}
}
}
}
Again, Darkstorm_'s GUI API. I'll get to this towards the end.
Code:
public void addToTick( Tickable tickable ) {
if ( !tickables.contains( tickable ) ) {
tickables.add( tickable );
}
}
public void removeFromTick( Tickable tickable ) {
if ( tickables.contains( tickable ) ) {
tickables.remove( tickable );
}
}
This code just adds the hacks to the list of things that we need to tick, so that when the tick() method is called, the hack gets ticked, and whatever the hack needs to have happen happens.
Now that we have the main class explained, we can move on to the rest of them.
CheckKey
package com.godshawk.colony.core;
import net.minecraft.client.Minecraft;
import org.lwjgl.input.Keyboard;
public class CheckKey {
public CheckKey( Minecraft minecraft ) {
mc = minecraft;
}
public boolean checkKey( int i ) {
if ( mc.currentScreen != null ) {
return false;
}
if ( Keyboard.isKeyDown( i ) != keyStates [ i ] ) {
return keyStates [ i ] = !keyStates [ i ];
} else {
return false;
}
}
private Minecraft mc;
private boolean keyStates[] = new boolean[ 256 ];
}
This should be self-explanatory. Even if it's not, there's tutorials about it all over. So I'm skipping over it.
Utils
package com.godshawk.colony.util;
import net.minecraft.client.Minecraft;
import net.minecraft.src.Entity;
public class Utils {
public Utils( Minecraft mc ) {
minecraft = mc;
}
// Used to append the [ClientNameHere] to the chat message
public void addChatMessage( String message ) {
String toSend = ChatColour.DARK_RED + "[The Colony] " + message;
minecraft.thePlayer.addChatMessage( toSend );
}
private Minecraft minecraft;
}
Not much to say here either. This just sends you the "[ClientNameHere] HackNameHere enabled/disabled" message.
ChatColour
package com.godshawk.colony.util;
public class ChatColour {
public static final String BLACK = "\2470";
public static final String DARK_BLUE = "\2471";
public static final String DARK_GREEN = "\2472";
public static final String DARK_AQUA = "\2473";
public static final String DARK_RED = "\2474";
public static final String DARK_PURPLE = "\2475";
public static final String GOLD = "\2476";
public static final String GRAY = "\2477";
public static final String DARK_GRAY = "\2478";
public static final String BLUE = "\2479";
public static final String GREEN = "\247a";
public static final String AQUA = "\247b";
public static final String RED = "\247c";
public static final String LIGHT_PURPLE = "\247d";
public static final String YELLOW = "\247e";
public static final String WHITE = "\247f";
public static final String MAGIC = "\247k";
public static final String BOLD = "\247l";
public static final String STRIKETHROUGH = "\247m";
public static final String UNDERLINE = "\247n";
public static final String ITALIC = "\247o";
public static final String RESET = "\247r";
}
Colors the chat. You know, the &<...> in EssentialsChat?
Okay, now we need to make an enum of our mods; ie a list of them. This is for getting the names of the hacks for the enabled/disabled messages.
Mods
package com.godshawk.colony.mods;
public enum Mods {
FULLBRIGHT, KILLAURA, NUKER, TRACER, PLAYERESP, CHESTESP, FLY, NOFALL, SPRINT, OVERLAY, XRAY, WATERWALK, AUTOFISH;
// This is just for my convenience
public String getName( ) {
return this.name( );
}
}
Again, should be pretty self-explanatory.
All our hacks will extend one base class. This abstract class has all the base methods our hacks will use.
Abstract Mod Class
package com.godshawk.colony.mods;
import com.godshawk.colony.util.ChatColour;
public abstract class Mod {
public Mod( Mods mod ) {
this.mod = mod;
name = mod.getName( );
}
public final void turnOn( ) {
active = true;
onEnable( );
}
public final void turnOff( ) {
active = false;
onDisable( );
}
public final void toggle( ) {
active = !active;
if ( active ) {
onEnable( );
} else {
onDisable( );
}
}
public final boolean isActive( ) {
return active;
}
public final String getActive( ) {
if ( active ) {
return ChatColour.WHITE + name + ChatColour.GREEN + " Active";
} else {
return ChatColour.WHITE + name + ChatColour.RED + " Inactive";
}
}
public abstract void onEnable( );
public abstract void onDisable( );
private Mods mod;
private String name;
private boolean active = false;
}
Code:
public Mod( Mods mod ) {
this.mod = mod;
name = mod.getName( );
}
This is the constructor for the class. You pass in an item from the Mods enum to get the name.
Code:
public final void turnOn( ) {
active = true;
onEnable( );
}
public final void turnOff( ) {
active = false;
onDisable( );
}
public final void toggle( ) {
active = !active;
if ( active ) {
onEnable( );
} else {
onDisable( );
}
}
The names of these methods should tell you everything. They enable/disable/toggle the given hack.
Code:
public final boolean isActive( ) {
return active;
}
public final String getActive( ) {
if ( active ) {
return ChatColour.WHITE + name + ChatColour.GREEN + " Active";
} else {
return ChatColour.WHITE + name + ChatColour.RED + " Inactive";
}
}
The first method returns true if the hack is active, otherwise returns false.
getActive() is used like Utils.java - for the "[InsertClientName] InsertHackName enabled/disabled" thing.
Code:
public abstract void onEnable( );
public abstract void onDisable( );
private Mods mod;
private String name;
private boolean active = false;
Abstract methods that define what the hack does when it's enabled/disabled. These are not defined, so to speak, because each individual hack overrides the given method.
"private Mods mod;" just creates a private instance of our hack list enum.
"private String name;" holds the name of the hack.
"private boolean active = false;" holds the state of the hack - true if active, false if inactive. All hacks are disabled by default.
Now we have to define 'tickable', or make it so that we can tick our hacks.
Tickable
package com.godshawk.colony.util;
public interface Tickable {
public void tick( );
}
Yeah, that's it. If you use it right.
Now we can get into some hack examples. I'm NOT going to just dump all my hack code here (although I'm considering opensourcing my client), so I'll just show a couple hacks.
Fullbright
package com.godshawk.colony.mods;
import com.godshawk.colony.core.Colony;
import net.minecraft.client.Minecraft;
public class Fullbright extends Mod {
public Fullbright( Colony rc, Minecraft mc ) {
super( Mods.FULLBRIGHT );
colony = rc;
minecraft = mc;
oldGamma = minecraft.gameSettings.gammaSetting;
}
@override
public void onEnable( ) {
colony.getUtils( ).addChatMessage( getActive( ) );
oldGamma = minecraft.gameSettings.gammaSetting;
minecraft.gameSettings.gammaSetting = 1000000;
}
@override
public void onDisable( ) {
colony.getUtils( ).addChatMessage( getActive( ) );
minecraft.gameSettings.gammaSetting = oldGamma;
}
private float oldGamma;
private Colony colony;
private Minecraft minecraft;
}
Just your basic fullbright. When it's enabled, it jacks the brightness setting up to 1,000,000; ie enough to see in the dark. (Nodus, on the other hand, makes it 900, and WeepCraft does 1000.)
When it's enabled, it increases the brightness, and sends you a chat message telling you that it's enabled.
Same idea for onDisable(). It resets the brightness, and sends you the message that it's disabled.
------------------
Xray
package com.godshawk.colony.mods;
import net.minecraft.client.Minecraft;
import com.godshawk.colony.core.Colony;
import com.godshawk.colony.util.Tickable;
public class Xray extends Mod implements Tickable {
private static Colony colony;
private static Minecraft mc;
public Xray( Colony co, Minecraft m ) {
super( Mods.XRAY );
colony = co;
mc = m;
// TODO Auto-generated constructor stub
}
@override
public void tick( ) {
// TODO Auto-generated method stub
}
@override
public void onEnable( ) {
colony.addToTick( this );
Vars.xray = true;
mc.renderGlobal.loadRenderers( );
colony.getUtils( ).addChatMessage( getActive( ) );
}
@override
public void onDisable( ) {
colony.removeFromTick( this );
Vars.xray = false;
mc.renderGlobal.loadRenderers( );
colony.getUtils( ).addChatMessage( getActive( ) );
}
}
For this, you're probably thinking, "Huh!?" because this doesn't directly show you how the xray works. This just handles the enable/disable.
What you need to make this work is the Vars.java, which I'll show below.
Vars.java
package com.godshawk.colony.mods;
public class Vars {
public static boolean tracer = false;
public static boolean pesp = false;
public static boolean cesp = false;
public static boolean nofall = false;
public static boolean overlay = false;
public static boolean xray = false;
public static boolean ww = false;
public static boolean afish = false;
/**
* Blocks for xray to show. You can't have List<int>, so you instead do
* List<Integer>.
*/
public static Integer[ ] xrayBlocks = new Integer[ ] { 8, 9, 10, 11, 21, 14, 15, 16, 56, 73, 129, 153, 88, 112 };
}
Yup, we're doing xray in a new way. We make an Integer[] here so that in Block.java, we can convert it into a List<Integer> and run through it to check whether we should render the blocks.
Now plod on over to Block.java, and we can finish up the xray.
Block.java xray method
public boolean shouldSideBeRendered( IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5 )
{
if ( !Vars.xray ) {
// Normal return method here; it was too long to show.
} else {
return Arrays.asList( Vars.xrayBlocks ).contains( blockID );
}
}
This converts our Integer[] into a List<Integer>, then goes through it to see if the list contains the given id. If it does, that block gets rendered.
The reason we did an Integer[] instead of an int[] is because you can't make a list of a primitive, literally List<int>.
That's much cleaner than doing
Code:
return blockID == 1 || blockID == 2 || ...
right?
Custom GuiIngame time!
CGuiIngame.java
package com.godshawk.colony.gui;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.src.Direction;
import net.minecraft.src.Entity;
import net.minecraft.src.EntityAnimal;
import net.minecraft.src.EntityBat;
import net.minecraft.src.EntityClientPlayerMP;
import net.minecraft.src.EntityMob;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.EntitySlime;
import net.minecraft.src.EntitySquid;
import net.minecraft.src.EntityVillager;
import net.minecraft.src.FontRenderer;
import net.minecraft.src.GuiIngame;
import net.minecraft.src.MathHelper;
import net.minecraft.src.TcpConnection;
import org.lwjgl.opengl.GL11;
import com.godshawk.colony.util.ChatColour;
public class CGuiIngame extends GuiIngame {
int tick = 0;
public CGuiIngame( Minecraft par1Minecraft ) {
super( par1Minecraft );
// TODO Auto-generated constructor stub
}
/**
* Render the ingame overlay with quick icon bar, ...
*/
@override
public void renderGameOverlay( float par1, boolean par2, int par3, int par4 ) {
super.renderGameOverlay( par1, par2, par3, par4 );
int var6 = ModGuiUtils.getWidth( );
FontRenderer var8 = this.mc.fontRenderer;
drawRadar( );
this.drawRect( var6 - 100, 150, var6, 150 + ( ( colony.enabledMods.size( ) + 1 ) * 10 ) + 3, 0x77000000 );
this.drawString( var8, ChatColour.DARK_RED + ChatColour.UNDERLINE + "Enabled Mods", var6 - 98, 151, 0xffffff );
for ( int i = 0; i < colony.enabledMods.size( ); i++ ) {
this.drawString( var8, colony.enabledMods.get( i ), var6 - 98, 150 + colony.enabledMods.size( ) + ( ( 12 * ( i + 1 ) ) - ( i * 3 ) ), 0x00ff00 );
}
int d = this.mc.thePlayer.dimension;
String dim = "Overworld";
if ( d == -1 ) {
dim = "Nether";
}
if ( d == 0 ) {
dim = "Overworld";
}
if ( d == 1 ) {
dim = "The End";
}
int var24 = MathHelper.floor_double( ( ( this.mc.thePlayer****tationYaw * 4.0F ) / 360.0F ) + 0.5D ) & 3;
String dir = Direction.directions [ var24 ];
this.drawRect( 0, 0, 150, 102, 0x77000000 );
this.drawString( var8, "HP: " + ( this.mc.thePlayer.getHealth( ) * 5 ) + "%", 2, 2, 0x00ff88 );
this.drawString( var8, "Armor: " + ( this.mc.thePlayer.getTotalArmorValue( ) * 5 ) + "%", 50, 2, 0x00ff88 );
this.drawString( var8, "Air: " + ( this.mc.thePlayer.getAir( ) / 3 ) + "%", 2, 12, 0x00ff88 );
this.drawString( var8, "Level: " + this.mc.thePlayer.experienceLevel, 52, 12, 0x00ff88 );
this.drawString( var8, "XP: " + Math****und( this.mc.thePlayer.experience * 100 ), 2, 22, 0x00ff88 );
this.drawString( var8, "Next level: " + ( 100 - Math****und( this.mc.thePlayer.experience * 100 ) ), 40, 22, 0x00ff88 );
this.drawString( var8, "X: " + Math****und( this.mc.thePlayer.posX ), 2, 32, 0x00ff88 );
this.drawString( var8, "Y: " + Math****und( this.mc.thePlayer.posY ), 2, 42, 0x00ff88 );
this.drawString( var8, "Z: " + Math****und( this.mc.thePlayer.posZ ), 2, 52, 0x00ff88 );
this.drawString( var8, this.mc.debugFPS + " FPS", 2, 62, 0x00ff88 );
this.drawString( var8, "Dimension: " + dim, 2, 72, 0x00ff88 );
this.drawString( var8, "Lagg: " + TcpConnection.field_74490_x, 2, 82, 0x00ff88 );
this.drawString( var8, "Facing " + dir, 2, 92, 0x00ff88 );
colony.renderPinnedFrames( );
}
public void drawRadar( ) {
tick++ ;
if ( tick >= 50 ) {
tick = 0;
}
GL11.glLineWidth( 2.0F );
ModGuiUtils.drawFilledCircle( ModGuiUtils.getWidth( ) - 60, 60, 50, 0x77007700 );
ModGuiUtils.drawCircle( ModGuiUtils.getWidth( ) - 60, 60, 50, 0xff000000 );
ModGuiUtils.drawCircle( ModGuiUtils.getWidth( ) - 60, 60, 38, 0xff000000 );
ModGuiUtils.drawCircle( ModGuiUtils.getWidth( ) - 60, 60, 25, 0xff000000 );
ModGuiUtils.drawCircle( ModGuiUtils.getWidth( ) - 60, 60, 13, 0xff000000 );
ModGuiUtils.drawCircle( ModGuiUtils.getWidth( ) - 60, 60, tick, 0xff00ffff );
ModGuiUtils.dr( ModGuiUtils.getWidth( ) - 110, 59.5, ModGuiUtils.getWidth( ) - 10, 60.5, 0xff00ffff );
ModGuiUtils.dr( ModGuiUtils.getWidth( ) - 59.5, 10, ModGuiUtils.getWidth( ) - 60.5, 110, 0xff00ffff );
ModGuiUtils.drawCircle( ModGuiUtils.getWidth( ) - 60, 60, 1, 0xffffffff ); // Player
List list1 = this.mc.theWorld.loadedEntityList;
GL11.glLineWidth( 1.0F );
for ( int i = 0; i < list1.size( ); i++ ) {
Entity entity = (Entity) list1.get( i );
double xdis = this.mc.thePlayer.posX - entity.posX;
double zdis = this.mc.thePlayer.posZ - entity.posZ;
double tdis = Math.sqrt( ( xdis * xdis ) + ( zdis * zdis ) );
double difInAng = MathHelper.wrapAngleTo180_double( this.mc.thePlayer****tationYaw - ( ( Math.atan2( zdis, xdis ) * 180.0D ) / Math.PI ) );
double finalX = Math.cos( Math.toRadians( difInAng ) ) * tdis;
double finalY = -Math.sin( Math.toRadians( difInAng ) ) * tdis;
GL11.glPushMatrix( );
GL11.glTranslatef( ModGuiUtils.getWidth( ) - 60, 60, 0 );
if ( tdis <= 100 ) {
if ( !( entity instanceof EntityClientPlayerMP ) ) {
if ( entity instanceof EntityPlayer ) {
ModGuiUtils.drawCircle( (int) finalX / 2, (int) finalY / 2, 1, 0xff0000ff );
GL11.glScalef( 0.5F, 0.5F, 0.5F );
EntityPlayer p = (EntityPlayer) entity;
String u = p.username;
this.mc.fontRenderer.drawString( u, (int) ( finalX ) - ( this.mc.fontRenderer.getStringWidth( u ) / 2 ), (int) finalY - 10, 0xffffff );
GL11.glScalef( 1F, 0.5F, 1F );
}
if ( entity instanceof EntityAnimal ) {
ModGuiUtils.drawCircle( (int) finalX / 2, (int) finalY / 2, 1, 0xff00ff00 );
}
if ( entity instanceof EntityMob ) {
ModGuiUtils.drawCircle( (int) finalX / 2, (int) finalY / 2, 1, 0xffff0000 );
}
if ( entity instanceof EntitySlime ) {
ModGuiUtils.drawCircle( (int) finalX / 2, (int) finalY / 2, 1, 0xffff88cc );
}
if ( entity instanceof EntityVillager ) {
ModGuiUtils.drawCircle( (int) finalX / 2, (int) finalY / 2, 1, 0xff8b4513 );
}
if ( entity instanceof EntityBat ) {
ModGuiUtils.drawCircle( (int) finalX / 2, (int) finalY / 2, 1, 0xfff4a460 );
}
if ( entity instanceof EntitySquid ) {
ModGuiUtils.drawCircle( (int) finalX / 2, (int) finalY / 2, 1, 0xff003399 );
}
}
}
GL11.glPopMatrix( );
}
}
}
I can't claim credit for the GUI methods; I just forgot who wrote them. Credit to the guy who did, though.
ModGuiUtils.java
package com.godshawk.colony.gui;
import net.minecraft.src.Entity;
import net.minecraft.src.ScaledResolution;
import net.minecraft.src.Tessellator;
import org.lwjgl.opengl.GL11;
import com.godshawk.colony.core.Colony;
public class ModGuiUtils {
public static void drawRect( float g, float h, float i, float j, int col1 ) {
float f = ( ( col1 >> 24 ) & 0xFF ) / 255F;
float f1 = ( ( col1 >> 16 ) & 0xFF ) / 255F;
float f2 = ( ( col1 >> 8 ) & 0xFF ) / 255F;
float f3 = ( col1 & 0xFF ) / 255F;
GL11.glEnable( GL11.GL_BLEND );
GL11.glDisable( GL11.GL_TEXTURE_2D );
GL11.glBlendFunc( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA );
GL11.glEnable( GL11.GL_LINE_SMOOTH );
GL11.glPushMatrix( );
GL11.glColor4f( f1, f2, f3, f );
GL11.glBegin( GL11.GL_QUADS );
GL11.glVertex2d( i, h );
GL11.glVertex2d( g, h );
GL11.glVertex2d( g, j );
GL11.glVertex2d( i, j );
GL11.glEnd( );
GL11.glPopMatrix( );
GL11.glEnable( GL11.GL_TEXTURE_2D );
GL11.glDisable( GL11.GL_BLEND );
GL11.glDisable( GL11.GL_LINE_SMOOTH );
}
public static void drawGradientRect( int x, int y, int x2, int y2, int col1, int col2 ) {
float f = ( ( col1 >> 24 ) & 0xFF ) / 255F;
float f1 = ( ( col1 >> 16 ) & 0xFF ) / 255F;
float f2 = ( ( col1 >> 8 ) & 0xFF ) / 255F;
float f3 = ( col1 & 0xFF ) / 255F;
float f4 = ( ( col2 >> 24 ) & 0xFF ) / 255F;
float f5 = ( ( col2 >> 16 ) & 0xFF ) / 255F;
float f6 = ( ( col2 >> 8 ) & 0xFF ) / 255F;
float f7 = ( col2 & 0xFF ) / 255F;
GL11.glEnable( GL11.GL_BLEND );
GL11.glDisable( GL11.GL_TEXTURE_2D );
GL11.glBlendFunc( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA );
GL11.glEnable( GL11.GL_LINE_SMOOTH );
GL11.glShadeModel( GL11.GL_SMOOTH );
GL11.glPushMatrix( );
GL11.glBegin( GL11.GL_QUADS );
GL11.glColor4f( f1, f2, f3, f );
GL11.glVertex2d( x2, y );
GL11.glVertex2d( x, y );
GL11.glColor4f( f5, f6, f7, f4 );
GL11.glVertex2d( x, y2 );
GL11.glVertex2d( x2, y2 );
GL11.glEnd( );
GL11.glPopMatrix( );
GL11.glEnable( GL11.GL_TEXTURE_2D );
GL11.glDisable( GL11.GL_BLEND );
GL11.glDisable( GL11.GL_LINE_SMOOTH );
GL11.glShadeModel( GL11.GL_FLAT );
}
public static void drawSideGradientRect( float x, float y, float x2, float y2, int col1, int col2 ) {
float f = ( ( col1 >> 24 ) & 0xFF ) / 255F;
float f1 = ( ( col1 >> 16 ) & 0xFF ) / 255F;
float f2 = ( ( col1 >> 8 ) & 0xFF ) / 255F;
float f3 = ( col1 & 0xFF ) / 255F;
float f4 = ( ( col2 >> 24 ) & 0xFF ) / 255F;
float f5 = ( ( col2 >> 16 ) & 0xFF ) / 255F;
float f6 = ( ( col2 >> 8 ) & 0xFF ) / 255F;
float f7 = ( col2 & 0xFF ) / 255F;
GL11.glEnable( GL11.GL_BLEND );
GL11.glDisable( GL11.GL_TEXTURE_2D );
GL11.glBlendFunc( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA );
GL11.glEnable( GL11.GL_LINE_SMOOTH );
GL11.glShadeModel( GL11.GL_SMOOTH );
GL11.glPushMatrix( );
GL11.glBegin( GL11.GL_QUADS );
GL11.glColor4f( f1, f2, f3, f );
GL11.glVertex2d( x2, y );
GL11.glColor4f( f5, f6, f7, f4 );
GL11.glVertex2d( x, y );
GL11.glVertex2d( x, y2 );
GL11.glColor4f( f1, f2, f3, f );
GL11.glVertex2d( x2, y2 );
GL11.glEnd( );
GL11.glPopMatrix( );
GL11.glEnable( GL11.GL_TEXTURE_2D );
GL11.glDisable( GL11.GL_BLEND );
GL11.glDisable( GL11.GL_LINE_SMOOTH );
GL11.glShadeModel( GL11.GL_FLAT );
}
public static void drawBorderedRect( int x, int y, int x2, int y2, float l1, int col1, int col2 ) {
drawRect( x, y, x2, y2, col2 );
float f = ( ( col1 >> 24 ) & 0xFF ) / 255F;
float f1 = ( ( col1 >> 16 ) & 0xFF ) / 255F;
float f2 = ( ( col1 >> 8 ) & 0xFF ) / 255F;
float f3 = ( col1 & 0xFF ) / 255F;
GL11.glEnable( GL11.GL_BLEND );
GL11.glDisable( GL11.GL_TEXTURE_2D );
GL11.glBlendFunc( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA );
GL11.glEnable( GL11.GL_LINE_SMOOTH );
GL11.glPushMatrix( );
GL11.glColor4f( f1, f2, f3, f );
GL11.glLineWidth( l1 );
GL11.glBegin( GL11.GL_LINES );
GL11.glVertex2d( x, y );
GL11.glVertex2d( x, y2 );
GL11.glVertex2d( x2, y2 );
GL11.glVertex2d( x2, y );
GL11.glVertex2d( x, y );
GL11.glVertex2d( x2, y );
GL11.glVertex2d( x, y2 );
GL11.glVertex2d( x2, y2 );
GL11.glEnd( );
GL11.glPopMatrix( );
GL11.glEnable( GL11.GL_TEXTURE_2D );
GL11.glDisable( GL11.GL_BLEND );
GL11.glDisable( GL11.GL_LINE_SMOOTH );
}
public static void drawHollowBorderedRect( int x, int y, int x2, int y2, float l1, int col1 ) {
float f = ( ( col1 >> 24 ) & 0xFF ) / 255F;
float f1 = ( ( col1 >> 16 ) & 0xFF ) / 255F;
float f2 = ( ( col1 >> 8 ) & 0xFF ) / 255F;
float f3 = ( col1 & 0xFF ) / 255F;
GL11.glEnable( GL11.GL_BLEND );
GL11.glDisable( GL11.GL_TEXTURE_2D );
GL11.glBlendFunc( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA );
GL11.glEnable( GL11.GL_LINE_SMOOTH );
GL11.glPushMatrix( );
GL11.glColor4f( f1, f2, f3, f );
GL11.glLineWidth( l1 );
GL11.glBegin( GL11.GL_LINES );
GL11.glVertex2d( x, y );
GL11.glVertex2d( x, y2 );
GL11.glVertex2d( x2, y2 );
GL11.glVertex2d( x2, y );
GL11.glVertex2d( x, y );
GL11.glVertex2d( x2, y );
GL11.glVertex2d( x, y2 );
GL11.glVertex2d( x2, y2 );
GL11.glEnd( );
GL11.glPopMatrix( );
GL11.glEnable( GL11.GL_TEXTURE_2D );
GL11.glDisable( GL11.GL_BLEND );
GL11.glDisable( GL11.GL_LINE_SMOOTH );
}
public static void drawGradientBorderedRect( int x, int y, int x2, int y2, float l1, int col1, int col2, int col3 ) {
drawGradientRect( x, y, x2, y2, col2, col3 );
float f = ( ( col1 >> 24 ) & 0xFF ) / 255F;
float f1 = ( ( col1 >> 16 ) & 0xFF ) / 255F;
float f2 = ( ( col1 >> 8 ) & 0xFF ) / 255F;
float f3 = ( col1 & 0xFF ) / 255F;
GL11.glEnable( GL11.GL_BLEND );
GL11.glDisable( GL11.GL_TEXTURE_2D );
GL11.glBlendFunc( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA );
GL11.glEnable( GL11.GL_LINE_SMOOTH );
GL11.glPushMatrix( );
GL11.glColor4f( f1, f2, f3, f );
GL11.glLineWidth( l1 );
GL11.glBegin( GL11.GL_LINES );
GL11.glVertex2d( x, y );
GL11.glVertex2d( x, y2 );
GL11.glVertex2d( x2, y2 );
GL11.glVertex2d( x2, y );
GL11.glVertex2d( x, y );
GL11.glVertex2d( x2, y );
GL11.glVertex2d( x, y2 );
GL11.glVertex2d( x2, y2 );
GL11.glEnd( );
GL11.glPopMatrix( );
GL11.glEnable( GL11.GL_TEXTURE_2D );
GL11.glDisable( GL11.GL_BLEND );
GL11.glDisable( GL11.GL_LINE_SMOOTH );
}
public static void drawVerticalLine( int x, int y, int y2, float l1, int col1 ) {
float f = ( ( col1 >> 24 ) & 0xFF ) / 255F;
float f1 = ( ( col1 >> 16 ) & 0xFF ) / 255F;
float f2 = ( ( col1 >> 8 ) & 0xFF ) / 255F;
float f3 = ( col1 & 0xFF ) / 255F;
GL11.glEnable( GL11.GL_BLEND );
GL11.glDisable( GL11.GL_TEXTURE_2D );
GL11.glBlendFunc( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA );
GL11.glEnable( GL11.GL_LINE_SMOOTH );
GL11.glPushMatrix( );
GL11.glColor4f( f1, f2, f3, f );
GL11.glLineWidth( l1 );
GL11.glBegin( GL11.GL_LINES );
GL11.glVertex2d( x, y );
GL11.glVertex2d( x, y2 );
GL11.glEnd( );
GL11.glPopMatrix( );
GL11.glEnable( GL11.GL_TEXTURE_2D );
GL11.glDisable( GL11.GL_BLEND );
GL11.glDisable( GL11.GL_LINE_SMOOTH );
}
public static void drawHorizontalLine( int x, int x2, int y, float l1, int col1 ) {
float f = ( ( col1 >> 24 ) & 0xFF ) / 255F;
float f1 = ( ( col1 >> 16 ) & 0xFF ) / 255F;
float f2 = ( ( col1 >> 8 ) & 0xFF ) / 255F;
float f3 = ( col1 & 0xFF ) / 255F;
GL11.glEnable( GL11.GL_BLEND );
GL11.glDisable( GL11.GL_TEXTURE_2D );
GL11.glBlendFunc( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA );
GL11.glEnable( GL11.GL_LINE_SMOOTH );
GL11.glPushMatrix( );
GL11.glColor4f( f1, f2, f3, f );
GL11.glLineWidth( l1 );
GL11.glBegin( GL11.GL_LINES );
GL11.glVertex2d( x, y );
GL11.glVertex2d( x2, y );
GL11.glEnd( );
GL11.glPopMatrix( );
GL11.glEnable( GL11.GL_TEXTURE_2D );
GL11.glDisable( GL11.GL_BLEND );
GL11.glDisable( GL11.GL_LINE_SMOOTH );
}
public static void drawDiagonalLine( int x, int x2, int y, float l1, int col1 ) {
float f = ( ( col1 >> 24 ) & 0xFF ) / 255F;
float f1 = ( ( col1 >> 16 ) & 0xFF ) / 255F;
float f2 = ( ( col1 >> 8 ) & 0xFF ) / 255F;
float f3 = ( col1 & 0xFF ) / 255F;
GL11.glEnable( GL11.GL_BLEND );
GL11.glDisable( GL11.GL_TEXTURE_2D );
GL11.glBlendFunc( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA );
GL11.glEnable( GL11.GL_LINE_SMOOTH );
GL11.glPushMatrix( );
GL11.glColor4f( f1, f2, f3, f );
GL11.glLineWidth( l1 );
GL11.glBegin( GL11.GL_LINES );
GL11.glVertex2d( x, y );
GL11.glVertex2d( y, x2 );
GL11.glEnd( );
GL11.glPopMatrix( );
GL11.glEnable( GL11.GL_TEXTURE_2D );
GL11.glDisable( GL11.GL_BLEND );
GL11.glDisable( GL11.GL_LINE_SMOOTH );
}
public static int getWidth( ) {
ScaledResolution sr = new ScaledResolution( Colony.minecraft.gameSettings, Colony.minecraft.displayWidth, Colony.minecraft.displayHeight );
return sr.getScaledWidth( );
}
public static int getHeight( ) {
ScaledResolution sr = new ScaledResolution( Colony.minecraft.gameSettings, Colony.minecraft.displayWidth, Colony.minecraft.displayHeight );
return sr.getScaledHeight( );
}
public void drawBorderedRect( double x, double y, double x1, double y1, double size, int borderC, int insideC ) {
dr( x + size, y + size, x1 - size, y1 - size, insideC );
dr( x + size, y + size, x1 - 0.5, y, borderC );
dr( x, y + 0.5, x + size, y1 - 0.5, borderC );
dr( x1, y1 - 0.5, x1 - size, y + size, borderC );
dr( x + 0.5, y1 - size, x1 - 0.5, y1, borderC );
}
public static void dr( double i, double j, double k, double l, int i1 ) {
if ( i < k ) {
double j1 = i;
i = k;
k = j1;
}
if ( j < l ) {
double k1 = j;
j = l;
l = k1;
}
float f = ( ( i1 >> 24 ) & 0xff ) / 255F;
float f1 = ( ( i1 >> 16 ) & 0xff ) / 255F;
float f2 = ( ( i1 >> 8 ) & 0xff ) / 255F;
float f3 = ( i1 & 0xff ) / 255F;
Tessellator tessellator = Tessellator.instance;
GL11.glEnable( 3042 );
GL11.glDisable( 3553 );
GL11.glBlendFunc( 770, 771 );
GL11.glColor4f( f1, f2, f3, f );
tessellator.startDrawingQuads( );
tessellator.addVertex( i, l, 0.0D );
tessellator.addVertex( k, l, 0.0D );
tessellator.addVertex( k, j, 0.0D );
tessellator.addVertex( i, j, 0.0D );
tessellator.draw( );
GL11.glEnable( 3553 );
GL11.glDisable( 3042 );
}
public static void drawCircle( int x, int y, double r, int c ) {
float f = ( ( c >> 24 ) & 0xff ) / 255F;
float f1 = ( ( c >> 16 ) & 0xff ) / 255F;
float f2 = ( ( c >> 8 ) & 0xff ) / 255F;
float f3 = ( c & 0xff ) / 255F;
GL11.glEnable( 3042 /* GL_BLEND */);
GL11.glDisable( 3553 /* GL_TEXTURE_2D */);
GL11.glEnable( 2848 /* GL_LINE_SMOOTH */);
GL11.glBlendFunc( 770, 771 );
GL11.glColor4f( f1, f2, f3, f );
GL11.glBegin( 2 /* GL_LINE_LOOP */);
for ( int i = 0; i <= 360; i++ ) {
double x2 = Math.sin( ( ( i * 3.141526D ) / 180 ) ) * r;
double y2 = Math.cos( ( ( i * 3.141526D ) / 180 ) ) * r;
GL11.glVertex2d( x + x2, y + y2 );
}
GL11.glEnd( );
GL11.glDisable( 2848 /* GL_LINE_SMOOTH */);
GL11.glEnable( 3553 /* GL_TEXTURE_2D */);
GL11.glDisable( 3042 /* GL_BLEND */);
}
public static void drawFilledCircle( int x, int y, double r, int c ) {
float f = ( ( c >> 24 ) & 0xff ) / 255F;
float f1 = ( ( c >> 16 ) & 0xff ) / 255F;
float f2 = ( ( c >> 8 ) & 0xff ) / 255F;
float f3 = ( c & 0xff ) / 255F;
GL11.glEnable( 3042 /* GL_BLEND */);
GL11.glDisable( 3553 /* GL_TEXTURE_2D */);
GL11.glEnable( 2848 /* GL_LINE_SMOOTH */);
GL11.glBlendFunc( 770, 771 );
GL11.glColor4f( f1, f2, f3, f );
GL11.glBegin( 6 /* GL_TRIANGLE_FAN */);
for ( int i = 0; i <= 360; i++ ) {
double x2 = Math.sin( ( ( i * 3.141526D ) / 180 ) ) * r;
double y2 = Math.cos( ( ( i * 3.141526D ) / 180 ) ) * r;
GL11.glVertex2d( x + x2, y + y2 );
}
GL11.glEnd( );
GL11.glDisable( 2848 /* GL_LINE_SMOOTH */);
GL11.glEnable( 3553 /* GL_TEXTURE_2D */);
GL11.glDisable( 3042 /* GL_BLEND */);
}
public static void drawTri( int cx, int cy, int c ) {
GL11.glRotatef( 180, 0F, 0F, 1.0F );
float f = ( ( c >> 24 ) & 0xff ) / 255F;
float f1 = ( ( c >> 16 ) & 0xff ) / 255F;
float f2 = ( ( c >> 8 ) & 0xff ) / 255F;
float f3 = ( c & 0xff ) / 255F;
GL11.glColor4f( f1, f2, f3, f );
GL11.glEnable( 3042 );
GL11.glDisable( 3553 );
GL11.glEnable( GL11.GL_LINE_SMOOTH );
GL11.glBlendFunc( 770, 771 );
GL11.glBegin( GL11.GL_TRIANGLES );
GL11.glRotatef( 180, 0F, 0F, 1.0F );
GL11.glVertex2d( cx, cy + 2 );
GL11.glVertex2d( cx + 2, cy - 2 );
GL11.glVertex2d( cx - 2, cy - 2 );
GL11.glEnd( );
GL11.glDisable( GL11.GL_LINE_SMOOTH );
GL11.glEnable( 3553 );
GL11.glDisable( 3042 );
GL11.glRotatef( -180, 0F, 0F, 1.0F );
}
public static void drawTriangle( Entity e, double cx, double cy, int c ) {
GL11.glPushMatrix( );
GL11.glTranslated( cx, cy, 0 );
GL11.glRotatef( -e****tationYaw, 0F, 0F, 1.0F );
float f = ( ( c >> 24 ) & 0xff ) / 255F;
float f1 = ( ( c >> 16 ) & 0xff ) / 255F;
float f2 = ( ( c >> 8 ) & 0xff ) / 255F;
float f3 = ( c & 0xff ) / 255F;
GL11.glColor4f( f1, f2, f3, f );
GL11.glEnable( 3042 );
GL11.glDisable( 3553 );
GL11.glEnable( GL11.GL_LINE_SMOOTH );
GL11.glBlendFunc( 770, 771 );
GL11.glBegin( GL11.GL_TRIANGLES );
GL11.glVertex2d( 0, 0 + 6 );
GL11.glVertex2d( 0 + 3, 0 - 2 );
GL11.glVertex2d( 0 - 3, 0 - 2 );
GL11.glEnd( );
GL11.glDisable( GL11.GL_LINE_SMOOTH );
GL11.glEnable( 3553 );
GL11.glDisable( 3042 );
GL11.glRotatef( e****tationYaw, 0F, 0F, 1.0F );
GL11.glPopMatrix( );
}
}
All right, couple hundred lines of code to explain here. I won't explain the ModGuiUtils class, because I don't understand OpenGL well enough to do it.
Used for our radar's animation.
Code:
public CGuiIngame( Minecraft par1Minecraft ) {
super( par1Minecraft );
// TODO Auto-generated constructor stub
}
Constructor for the class. Just calls GuiIngame's constructor.
Code:
/**
* Render the ingame overlay with quick icon bar, ...
*/
@override
public void renderGameOverlay( float par1, boolean par2, int par3, int par4 ) {
super.renderGameOverlay( par1, par2, par3, par4 );
int var6 = ModGuiUtils.getWidth( );
FontRenderer var8 = this.mc.fontRenderer;
drawRadar( );
this.drawRect( var6 - 100, 150, var6, 150 + ( ( colony.enabledMods.size( ) + 1 ) * 10 ) + 3, 0x77000000 );
this.drawString( var8, ChatColour.DARK_RED + ChatColour.UNDERLINE + "Enabled Mods", var6 - 98, 151, 0xffffff );
for ( int i = 0; i < colony.enabledMods.size( ); i++ ) {
this.drawString( var8, colony.enabledMods.get( i ), var6 - 98, 150 + colony.enabledMods.size( ) + ( ( 12 * ( i + 1 ) ) - ( i * 3 ) ), 0x00ff00 );
}
int d = this.mc.thePlayer.dimension;
String dim = "Overworld";
if ( d == -1 ) {
dim = "Nether";
}
if ( d == 0 ) {
dim = "Overworld";
}
if ( d == 1 ) {
dim = "The End";
}
int var24 = MathHelper.floor_double( ( ( this.mc.thePlayer****tationYaw * 4.0F ) / 360.0F ) + 0.5D ) & 3;
String dir = Direction.directions [ var24 ];
this.drawRect( 0, 0, 150, 102, 0x77000000 );
this.drawString( var8, "HP: " + ( this.mc.thePlayer.getHealth( ) * 5 ) + "%", 2, 2, 0x00ff88 );
this.drawString( var8, "Armor: " + ( this.mc.thePlayer.getTotalArmorValue( ) * 5 ) + "%", 50, 2, 0x00ff88 );
this.drawString( var8, "Air: " + ( this.mc.thePlayer.getAir( ) / 3 ) + "%", 2, 12, 0x00ff88 );
this.drawString( var8, "Level: " + this.mc.thePlayer.experienceLevel, 52, 12, 0x00ff88 );
this.drawString( var8, "XP: " + Math****und( this.mc.thePlayer.experience * 100 ), 2, 22, 0x00ff88 );
this.drawString( var8, "Next level: " + ( 100 - Math****und( this.mc.thePlayer.experience * 100 ) ), 40, 22, 0x00ff88 );
this.drawString( var8, "X: " + Math****und( this.mc.thePlayer.posX ), 2, 32, 0x00ff88 );
this.drawString( var8, "Y: " + Math****und( this.mc.thePlayer.posY ), 2, 42, 0x00ff88 );
this.drawString( var8, "Z: " + Math****und( this.mc.thePlayer.posZ ), 2, 52, 0x00ff88 );
this.drawString( var8, this.mc.debugFPS + " FPS", 2, 62, 0x00ff88 );
this.drawString( var8, "Dimension: " + dim, 2, 72, 0x00ff88 );
this.drawString( var8, "Lagg: " + TcpConnection.field_74490_x, 2, 82, 0x00ff88 );
this.drawString( var8, "Facing " + dir, 2, 92, 0x00ff88 );
colony.renderPinnedFrames( );
}
First, this code calls GuiIngame's method with the same name. It then gets a few useful things, like screen width and the FontRenderer. Next, we draw the radar (Explained next). The next bit just renders a bunch of useful information in the upper left of the screen. By the way, you have to change TcpConnection.field_74490_x to public and static for that to work.
Finally, it renders the pinned frames we make with Darkstorm_'s GUI API.
Code:
public void drawRadar( ) {
tick++ ;
if ( tick >= 50 ) {
tick = 0;
}
GL11.glLineWidth( 2.0F );
ModGuiUtils.drawFilledCircle( ModGuiUtils.getWidth( ) - 60, 60, 50, 0x77007700 );
ModGuiUtils.drawCircle( ModGuiUtils.getWidth( ) - 60, 60, 50, 0xff000000 );
ModGuiUtils.drawCircle( ModGuiUtils.getWidth( ) - 60, 60, 38, 0xff000000 );
ModGuiUtils.drawCircle( ModGuiUtils.getWidth( ) - 60, 60, 25, 0xff000000 );
ModGuiUtils.drawCircle( ModGuiUtils.getWidth( ) - 60, 60, 13, 0xff000000 );
ModGuiUtils.drawCircle( ModGuiUtils.getWidth( ) - 60, 60, tick, 0xff00ffff );
ModGuiUtils.dr( ModGuiUtils.getWidth( ) - 110, 59.5, ModGuiUtils.getWidth( ) - 10, 60.5, 0xff00ffff );
ModGuiUtils.dr( ModGuiUtils.getWidth( ) - 59.5, 10, ModGuiUtils.getWidth( ) - 60.5, 110, 0xff00ffff );
ModGuiUtils.drawCircle( ModGuiUtils.getWidth( ) - 60, 60, 1, 0xffffffff ); // Player
List list1 = this.mc.theWorld.loadedEntityList;
GL11.glLineWidth( 1.0F );
for ( int i = 0; i < list1.size( ); i++ ) {
Entity entity = (Entity) list1.get( i );
double xdis = this.mc.thePlayer.posX - entity.posX;
double zdis = this.mc.thePlayer.posZ - entity.posZ;
double tdis = Math.sqrt( ( xdis * xdis ) + ( zdis * zdis ) );
double difInAng = MathHelper.wrapAngleTo180_double( this.mc.thePlayer****tationYaw - ( ( Math.atan2( zdis, xdis ) * 180.0D ) / Math.PI ) );
double finalX = Math.cos( Math.toRadians( difInAng ) ) * tdis;
double finalY = -Math.sin( Math.toRadians( difInAng ) ) * tdis;
GL11.glPushMatrix( );
GL11.glTranslatef( ModGuiUtils.getWidth( ) - 60, 60, 0 );
if ( tdis <= 100 ) {
if ( !( entity instanceof EntityClientPlayerMP ) ) {
if ( entity instanceof EntityPlayer ) {
ModGuiUtils.drawCircle( (int) finalX / 2, (int) finalY / 2, 1, 0xff0000ff );
GL11.glScalef( 0.5F, 0.5F, 0.5F );
EntityPlayer p = (EntityPlayer) entity;
String u = p.username;
this.mc.fontRenderer.drawString( u, (int) ( finalX ) - ( this.mc.fontRenderer.getStringWidth( u ) / 2 ), (int) finalY - 10, 0xffffff );
GL11.glScalef( 1F, 0.5F, 1F );
}
if ( entity instanceof EntityAnimal ) {
ModGuiUtils.drawCircle( (int) finalX / 2, (int) finalY / 2, 1, 0xff00ff00 );
}
if ( entity instanceof EntityMob ) {
ModGuiUtils.drawCircle( (int) finalX / 2, (int) finalY / 2, 1, 0xffff0000 );
}
if ( entity instanceof EntitySlime ) {
ModGuiUtils.drawCircle( (int) finalX / 2, (int) finalY / 2, 1, 0xffff88cc );
}
if ( entity instanceof EntityVillager ) {
ModGuiUtils.drawCircle( (int) finalX / 2, (int) finalY / 2, 1, 0xff8b4513 );
}
if ( entity instanceof EntityBat ) {
ModGuiUtils.drawCircle( (int) finalX / 2, (int) finalY / 2, 1, 0xfff4a460 );
}
if ( entity instanceof EntitySquid ) {
ModGuiUtils.drawCircle( (int) finalX / 2, (int) finalY / 2, 1, 0xff003399 );
}
}
}
GL11.glPopMatrix( );
}
}
Draws some nice circles for the radar. Gets the list of all entities in the world, and starts scrolling through them.
For each entity, it gets where it is in relation to the player, then does some trig to rotate it around you. The " / 2"'s are because my radar is small scale; yours can be as large as you want, just scale appropriately.
It draws friendly mobs in one color, unfriendly mobs in another, villagers in a third, bats in a fourth, slimes in a fifth, and players in a sixth. It also does some OpenGL to scale a string so we can render the player's name.
Now, finally, we get to Darkstorm_'s GUI API.
I really can't explain most of it, you'll have to find his Hack Forums thread to really get it.
I can, however, give you an idea of how to use it.
ModsGui.java
package com.godshawk.colony.gui;
import java.awt.Dimension;
import java.awt.Rectangle;
import net.minecraft.src.GuiScreen;
import org.darkstorm.minecraft.gui.GuiManager;
import org.darkstorm.minecraft.gui.component.Button;
import org.darkstorm.minecraft.gui.componen*****mboBox;
import org.darkstorm.minecraft.gui.componen*****mponent;
import org.darkstorm.minecraft.gui.component.Frame;
import org.darkstorm.minecraft.gui.component.basic.BasicButton;
import org.darkstorm.minecraft.gui.component.basic.BasicComboBox;
import org.darkstorm.minecraft.gui.component.basic.BasicFrame;
import org.darkstorm.minecraft.gui.component.basic.BasicLabel;
import org.darkstorm.minecraft.gui.listener.ButtonListener;
import org.darkstorm.minecraft.gui.listener.ComboBoxListener;
import org.darkstorm.minecraft.gui.theme.Theme;
import org.darkstorm.minecraft.gui.theme.simple.SimpleTheme;
import com.godshawk.colony.core.Colony;
import com.godshawk.colony.gui.theme.ColonyTheme;
public class ModsGui extends GuiScreen {
private final GuiManager guiManager;
private final Theme theme;
public boolean setup = false;
public ModsGui( GuiManager guiManager ) {
this.guiManager = guiManager;
theme = new ColonyTheme( );
this.setup( );
}
public void setup( ) {
if ( setup ) {
return;
}
setup = true;
createPlayerFrame( );
createWorldFrame( );
createKeybindList( );
createThemeFrame( );
}
@override
protected void mouseClicked( int x, int y, int button ) {
super.mouseClicked( x, y, button );
for ( Frame frame : guiManager.getFrames( ) ) {
if ( !frame.isVisible( ) ) {
continue;
}
if ( !frame.isMinimized( ) && !frame.getArea( ).contains( x, y ) ) {
for ( Component component : frame.getChildren( ) ) {
for ( Rectangle area : component.getTheme( ).getUIForComponent( component ).getInteractableRegions( component ) ) {
if ( are*****ntains( x - frame.getX( ) - component.getX( ), y - frame.getY( ) - component.getY( ) ) ) {
frame.onMousePress( x - frame.getX( ), y - frame.getY( ), button );
guiManager.bringForward( frame );
return;
}
}
}
}
}
for ( Frame frame : guiManager.getFrames( ) ) {
if ( !frame.isVisible( ) ) {
continue;
}
if ( !frame.isMinimized( ) && frame.getArea( ).contains( x, y ) ) {
frame.onMousePress( x - frame.getX( ), y - frame.getY( ), button );
guiManager.bringForward( frame );
break;
} else if ( frame.isMinimized( ) ) {
for ( Rectangle area : frame.getTheme( ).getUIForComponent( frame ).getInteractableRegions( frame ) ) {
if ( are*****ntains( x - frame.getX( ), y - frame.getY( ) ) ) {
frame.onMousePress( x - frame.getX( ), y - frame.getY( ), button );
guiManager.bringForward( frame );
return;
}
}
}
}
}
@override
public void mouseMovedOrUp( int x, int y, int button ) {
super.mouseMovedOrUp( x, y, button );
for ( Frame frame : guiManager.getFrames( ) ) {
if ( !frame.isVisible( ) ) {
continue;
}
if ( !frame.isMinimized( ) && !frame.getArea( ).contains( x, y ) ) {
for ( Component component : frame.getChildren( ) ) {
for ( Rectangle area : component.getTheme( ).getUIForComponent( component ).getInteractableRegions( component ) ) {
if ( are*****ntains( x - frame.getX( ) - component.getX( ), y - frame.getY( ) - component.getY( ) ) ) {
frame.onMouseRelease( x - frame.getX( ), y - frame.getY( ), button );
guiManager.bringForward( frame );
return;
}
}
}
}
}
for ( Frame frame : guiManager.getFrames( ) ) {
if ( !frame.isVisible( ) ) {
continue;
}
if ( !frame.isMinimized( ) && frame.getArea( ).contains( x, y ) ) {
frame.onMouseRelease( x - frame.getX( ), y - frame.getY( ), button );
guiManager.bringForward( frame );
break;
} else if ( frame.isMinimized( ) ) {
for ( Rectangle area : frame.getTheme( ).getUIForComponent( frame ).getInteractableRegions( frame ) ) {
if ( are*****ntains( x - frame.getX( ), y - frame.getY( ) ) ) {
frame.onMouseRelease( x - frame.getX( ), y - frame.getY( ), button );
guiManager.bringForward( frame );
return;
}
}
}
}
}
@override
public void drawScreen( int par2, int par3, float par4 ) {
Frame[ ] frames = guiManager.getFrames( );
for ( int i = frames.length - 1; i >= 0; i-- ) {
frames [ i ].render( );
}
super.drawScreen( par2, par3, par4 );
}
private void createPlayerFrame( ) {
final Frame playerFrame = new BasicFrame( "Player" );
playerFrame.setTheme( theme );
BasicButton pespButton = new BasicButton( "Player ESP" );
pespButton.addButtonListener( new ButtonListener( ) {
@override
public void onButtonPress( Button button ) {
Colony.pesp.toggle( );
}
} );
BasicButton kaButton = new BasicButton( "Kill Aura" );
kaButton.addButtonListener( new ButtonListener( ) {
@override
public void onButtonPress( Button button ) {
Colony.killaura.toggle( );
}
} );
BasicButton tracerButton = new BasicButton( "Tracers" );
tracerButton.addButtonListener( new ButtonListener( ) {
@override
public void onButtonPress( Button button ) {
Colony.t.toggle( );
}
} );
BasicButton flyButton = new BasicButton( "Fly" );
flyButton.addButtonListener( new ButtonListener( ) {
@override
public void onButtonPress( Button button ) {
Colony.fly.toggle( );
}
} );
BasicButton nofallButton = new BasicButton( "NoFall" );
nofallButton.addButtonListener( new ButtonListener( ) {
@override
public void onButtonPress( Button button ) {
Colony.nof.toggle( );
}
} );
BasicButton sprintButton = new BasicButton( "Sprint" );
sprintButton.addButtonListener( new ButtonListener( ) {
@override
public void onButtonPress( Button button ) {
Colony.spr.toggle( );
}
} );
playerFrame.add( pespButton );
playerFrame.add( kaButton );
playerFrame.add( tracerButton );
playerFrame.add( flyButton );
playerFrame.add( nofallButton );
playerFrame.add( sprintButton );
playerFrame.setX( 10 );
playerFrame.setY( 10 );
Dimension defaultDimension = theme.getUIForComponent( playerFrame ).getDefaultSize( playerFrame );
playerFrame.setWidth( defaultDimension.width );
playerFrame.setHeight( defaultDimension.height );
playerFrame.layoutChildren( );
playerFrame.setPinnable( false );
playerFrame.setClosable( false );
playerFrame.setVisible( true );
playerFrame.setMinimized( true );
Colony.manager.addFrame( playerFrame );
}
private void createWorldFrame( ) {
final Frame worldFrame = new BasicFrame( "World" );
worldFrame.setTheme( theme );
BasicButton nukerButton = new BasicButton( "Nuker" );
nukerButton.addButtonListener( new ButtonListener( ) {
@override
public void onButtonPress( Button button ) {
Colony.nuker.toggle( );
}
} );
BasicButton chestButton = new BasicButton( "Chest ESP" );
chestButton.addButtonListener( new ButtonListener( ) {
@override
public void onButtonPress( Button button ) {
Colony.cesp.toggle( );
}
} );
BasicButton brightButton = new BasicButton( "Fullbright" );
brightButton.addButtonListener( new ButtonListener( ) {
@override
public void onButtonPress( Button button ) {
Colony.fullbright.toggle( );
}
} );
BasicButton xrayButton = new BasicButton( "X-Ray" );
xrayButton.addButtonListener( new ButtonListener( ) {
@override
public void onButtonPress( Button button ) {
Colony.xray.toggle( );
}
} );
BasicButton wwButton = new BasicButton( "Waterwalk" );
wwButton.addButtonListener( new ButtonListener( ) {
@override
public void onButtonPress( Button button ) {
Colony.ww.toggle( );
}
} );
BasicButton afButton = new BasicButton( "AutoFish" );
afButton.addButtonListener( new ButtonListener( ) {
@override
public void onButtonPress( Button button ) {
Colony.af.toggle( );
}
} );
worldFrame.add( nukerButton );
worldFrame.add( chestButton );
worldFrame.add( brightButton );
worldFrame.add( xrayButton );
worldFrame.add( wwButton );
worldFrame.add( afButton );
worldFrame.setX( 110 );
worldFrame.setY( 10 );
Dimension defaultDimension = theme.getUIForComponent( worldFrame ).getDefaultSize( worldFrame );
worldFrame.setWidth( defaultDimension.width );
worldFrame.setHeight( defaultDimension.height );
worldFrame.layoutChildren( );
worldFrame.setPinnable( false );
worldFrame.setClosable( false );
worldFrame.setVisible( true );
worldFrame.setMinimized( true );
Colony.manager.addFrame( worldFrame );
}
private void createKeybindList( ) {
final Frame keybindsFrame = new BasicFrame( "Keybinds" );
keybindsFrame.setTheme( theme );
keybindsFrame.add( new BasicLabel( "F - Fullbright" ) );
keybindsFrame.add( new BasicLabel( "R - Player ESP" ) );
keybindsFrame.add( new BasicLabel( "C - Chestfinder" ) );
keybindsFrame.add( new BasicLabel( "O - NoFall" ) );
keybindsFrame.add( new BasicLabel( "J - Fly" ) );
keybindsFrame.add( new BasicLabel( "M - Tracers" ) );
keybindsFrame.add( new BasicLabel( "L - Nuker" ) );
keybindsFrame.add( new BasicLabel( "P - KillAura" ) );
keybindsFrame.add( new BasicLabel( "K - Sprint" ) );
keybindsFrame.add( new BasicLabel( "X - X-Ray" ) );
keybindsFrame.add( new BasicLabel( "~ - Console" ) );
keybindsFrame.setX( 210 );
keybindsFrame.setY( 10 );
Dimension defaultDimension = theme.getUIForComponent( keybindsFrame ).getDefaultSize( keybindsFrame );
keybindsFrame.setWidth( defaultDimension.width );
keybindsFrame.setHeight( defaultDimension.height );
keybindsFrame.layoutChildren( );
keybindsFrame.setPinnable( true );
keybindsFrame.setClosable( false );
keybindsFrame.setVisible( true );
keybindsFrame.setMinimized( true );
Colony.manager.addFrame( keybindsFrame );
}
private void createThemeFrame( ) {
Frame themeFrame = new BasicFrame( "Theme" );
themeFrame.setTheme( theme );
ComboBox comboBox = new BasicComboBox( "Colony theme", "Simple theme" );
comboBox.addComboBoxListener( new ComboBoxListener( ) {
@override
public void onComboBoxSelectionChanged( ComboBox comboBox ) {
Theme theme;
switch ( comboBox.getSelectedIndex( ) ) {
case 0:
theme = new ColonyTheme( );
break;
case 1:
theme = new SimpleTheme( );
break;
default:
return;
}
Colony.manager.setTheme( theme );
}
} );
themeFrame.add( comboBox );
themeFrame.setX( 310 );
themeFrame.setY( 10 );
Dimension defaultDimension = theme.getUIForComponent( themeFrame ).getDefaultSize( themeFrame );
themeFrame.setWidth( defaultDimension.width );
themeFrame.setHeight( defaultDimension.height );
themeFrame.layoutChildren( );
themeFrame.setVisible( true );
themeFrame.setMinimized( true );
themeFrame.setClosable( false );
themeFrame.setPinnable( false );
Colony.manager.addFrame( themeFrame );
}
}
There ya go. 300+ lines of code, not as OOP as I'd like. Also not going to give out my theme classes, because I don't want skids stealing it.
Frame Methods
private void createPlayerFrame( ) {
final Frame playerFrame = new BasicFrame( "Player" );
playerFrame.setTheme( theme );
BasicButton pespButton = new BasicButton( "Player ESP" );
pespButton.addButtonListener( new ButtonListener( ) {
@override
public void onButtonPress( Button button ) {
Colony.pesp.toggle( );
}
} );
BasicButton kaButton = new BasicButton( "Kill Aura" );
kaButton.addButtonListener( new ButtonListener( ) {
@override
public void onButtonPress( Button button ) {
Colony.killaura.toggle( );
}
} );
BasicButton tracerButton = new BasicButton( "Tracers" );
tracerButton.addButtonListener( new ButtonListener( ) {
@override
public void onButtonPress( Button button ) {
Colony.t.toggle( );
}
} );
BasicButton flyButton = new BasicButton( "Fly" );
flyButton.addButtonListener( new ButtonListener( ) {
@override
public void onButtonPress( Button button ) {
Colony.fly.toggle( );
}
} );
BasicButton nofallButton = new BasicButton( "NoFall" );
nofallButton.addButtonListener( new ButtonListener( ) {
@override
public void onButtonPress( Button button ) {
Colony.nof.toggle( );
}
} );
BasicButton sprintButton = new BasicButton( "Sprint" );
sprintButton.addButtonListener( new ButtonListener( ) {
@override
public void onButtonPress( Button button ) {
Colony.spr.toggle( );
}
} );
playerFrame.add( pespButton );
playerFrame.add( kaButton );
playerFrame.add( tracerButton );
playerFrame.add( flyButton );
playerFrame.add( nofallButton );
playerFrame.add( sprintButton );
playerFrame.setX( 10 );
playerFrame.setY( 10 );
Dimension defaultDimension = theme.getUIForComponent( playerFrame ).getDefaultSize( playerFrame );
playerFrame.setWidth( defaultDimension.width );
playerFrame.setHeight( defaultDimension.height );
playerFrame.layoutChildren( );
playerFrame.setPinnable( false );
playerFrame.setClosable( false );
playerFrame.setVisible( true );
playerFrame.setMinimized( true );
Colony.manager.addFrame( playerFrame );
}
private void createWorldFrame( ) {
final Frame worldFrame = new BasicFrame( "World" );
worldFrame.setTheme( theme );
BasicButton nukerButton = new BasicButton( "Nuker" );
nukerButton.addButtonListener( new ButtonListener( ) {
@override
public void onButtonPress( Button button ) {
Colony.nuker.toggle( );
}
} );
BasicButton chestButton = new BasicButton( "Chest ESP" );
chestButton.addButtonListener( new ButtonListener( ) {
@override
public void onButtonPress( Button button ) {
Colony.cesp.toggle( );
}
} );
BasicButton brightButton = new BasicButton( "Fullbright" );
brightButton.addButtonListener( new ButtonListener( ) {
@override
public void onButtonPress( Button button ) {
Colony.fullbright.toggle( );
}
} );
BasicButton xrayButton = new BasicButton( "X-Ray" );
xrayButton.addButtonListener( new ButtonListener( ) {
@override
public void onButtonPress( Button button ) {
Colony.xray.toggle( );
}
} );
BasicButton wwButton = new BasicButton( "Waterwalk" );
wwButton.addButtonListener( new ButtonListener( ) {
@override
public void onButtonPress( Button button ) {
Colony.ww.toggle( );
}
} );
BasicButton afButton = new BasicButton( "AutoFish" );
afButton.addButtonListener( new ButtonListener( ) {
@override
public void onButtonPress( Button button ) {
Colony.af.toggle( );
}
} );
worldFrame.add( nukerButton );
worldFrame.add( chestButton );
worldFrame.add( brightButton );
worldFrame.add( xrayButton );
worldFrame.add( wwButton );
worldFrame.add( afButton );
worldFrame.setX( 110 );
worldFrame.setY( 10 );
Dimension defaultDimension = theme.getUIForComponent( worldFrame ).getDefaultSize( worldFrame );
worldFrame.setWidth( defaultDimension.width );
worldFrame.setHeight( defaultDimension.height );
worldFrame.layoutChildren( );
worldFrame.setPinnable( false );
worldFrame.setClosable( false );
worldFrame.setVisible( true );
worldFrame.setMinimized( true );
Colony.manager.addFrame( worldFrame );
}
private void createKeybindList( ) {
final Frame keybindsFrame = new BasicFrame( "Keybinds" );
keybindsFrame.setTheme( theme );
keybindsFrame.add( new BasicLabel( "F - Fullbright" ) );
keybindsFrame.add( new BasicLabel( "R - Player ESP" ) );
keybindsFrame.add( new BasicLabel( "C - Chestfinder" ) );
keybindsFrame.add( new BasicLabel( "O - NoFall" ) );
keybindsFrame.add( new BasicLabel( "J - Fly" ) );
keybindsFrame.add( new BasicLabel( "M - Tracers" ) );
keybindsFrame.add( new BasicLabel( "L - Nuker" ) );
keybindsFrame.add( new BasicLabel( "P - KillAura" ) );
keybindsFrame.add( new BasicLabel( "K - Sprint" ) );
keybindsFrame.add( new BasicLabel( "X - X-Ray" ) );
keybindsFrame.add( new BasicLabel( "~ - Console" ) );
keybindsFrame.setX( 210 );
keybindsFrame.setY( 10 );
Dimension defaultDimension = theme.getUIForComponent( keybindsFrame ).getDefaultSize( keybindsFrame );
keybindsFrame.setWidth( defaultDimension.width );
keybindsFrame.setHeight( defaultDimension.height );
keybindsFrame.layoutChildren( );
keybindsFrame.setPinnable( true );
keybindsFrame.setClosable( false );
keybindsFrame.setVisible( true );
keybindsFrame.setMinimized( true );
Colony.manager.addFrame( keybindsFrame );
}
private void createThemeFrame( ) {
Frame themeFrame = new BasicFrame( "Theme" );
themeFrame.setTheme( theme );
ComboBox comboBox = new BasicComboBox( "Colony theme", "Simple theme" );
comboBox.addComboBoxListener( new ComboBoxListener( ) {
@override
public void onComboBoxSelectionChanged( ComboBox comboBox ) {
Theme theme;
switch ( comboBox.getSelectedIndex( ) ) {
case 0:
theme = new ColonyTheme( );
break;
case 1:
theme = new SimpleTheme( );
break;
default:
return;
}
Colony.manager.setTheme( theme );
}
} );
themeFrame.add( comboBox );
themeFrame.setX( 310 );
themeFrame.setY( 10 );
Dimension defaultDimension = theme.getUIForComponent( themeFrame ).getDefaultSize( themeFrame );
themeFrame.setWidth( defaultDimension.width );
themeFrame.setHeight( defaultDimension.height );
themeFrame.layoutChildren( );
themeFrame.setVisible( true );
themeFrame.setMinimized( true );
themeFrame.setClosable( false );
themeFrame.setPinnable( false );
Colony.manager.addFrame( themeFrame );
}
These four methods create the frames for your clickable/draggable/OOP GUI. They add the relevant stuff, and SHOULD be pretty self explanatory, because Darkstorm_ really did a good job with this API.
mouseMovedUpOrDown(...)/mouseClicked(...) I can't really explain, because I didn't write it. Darkstorm_ did. Basically what it does is handle mouse clicks, ie clicking buttons/sliders, moving the windows....
And setup() and the constructor should explain themselves pretty well too.
If I missed anything, please, please, PLEASE tell me!
Example pictures attached.