diff --git a/README.md b/README.md index a6168f1..506bcef 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ Single Player Commands +This branch is an update for minecraft 1.7.2 +Lots of commands currently don't work! \ No newline at end of file diff --git a/spc1.6.2-src.zip b/spc1.6.2-src.zip new file mode 100644 index 0000000..1593493 Binary files /dev/null and b/spc1.6.2-src.zip differ diff --git a/src/build.gradle b/src/build.gradle new file mode 100644 index 0000000..0099f2e --- /dev/null +++ b/src/build.gradle @@ -0,0 +1,74 @@ +buildscript { + repositories { + mavenCentral() + maven { + name = "forge" + url = "http://files.minecraftforge.net/maven" + } + maven { + name = "sonatype" + url = "https://oss.sonatype.org/content/repositories/snapshots/" + } + } + dependencies { + classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT' + } +} + +apply plugin: 'forge' + +version = "5.0" +group= "com.sijobe.spc" // http://maven.apache.org/guides/mini/guide-naming-conventions.html +archivesBaseName = "spc" + +minecraft { + version = "1.7.2-10.12.2.1121" + assetDir = "eclipse/assets" +} + +dependencies { + // you may put jars on which you depend on in ./libs + // or you may define them like so.. + //compile "some.group:artifact:version:classifier" + //compile "some.group:artifact:version" + + // real examples + //compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env + //compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env + + // for more info... + // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html + // http://www.gradle.org/docs/current/userguide/dependency_management.html + +} + +processResources +{ + // this will ensure that this task is redone when the versions change. + inputs.property "version", project.version + inputs.property "mcversion", project.minecraft.version + + // replace stuff in mcmod.info, nothing else + from(sourceSets.main.resources.srcDirs) { + include 'mcmod.info' + + // replace version and mcversion + expand 'version':project.version, 'mcversion':project.minecraft.version + } + + // copy everything else, thats not the mcmod.info + from(sourceSets.main.resources.srcDirs) { + exclude 'mcmod.info' + } +} + +jar +{ + manifest + { + attributes( + "FMLCorePlugin": "com.sijobe.spc.asm.SpcCoreMod", + "FMLCorePluginContainsFMLMod": "true" + ) + } +} diff --git a/src/com/sijobe/spc/command/InstantMine.java b/src/com/sijobe/spc/command/InstantMine.java deleted file mode 100644 index bb3976f..0000000 --- a/src/com/sijobe/spc/command/InstantMine.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.sijobe.spc.command; - -import com.sijobe.spc.util.ForgeHelper; -import com.sijobe.spc.util.Settings; -import com.sijobe.spc.validation.Parameters; -import com.sijobe.spc.wrapper.CommandException; -import com.sijobe.spc.wrapper.CommandSender; -import com.sijobe.spc.wrapper.Player; - -import java.util.List; - -import net.minecraft.src.EntityPlayerMP; - -/** - * Command to toggle instant mining - * - * @author q3hardcore - * @version 1.0 - */ -@Command ( - name = "instantmine", - description = "Allows player to mine blocks instantly", - example = "", - videoURL = "", - enabled = true -) -public class InstantMine extends StandardCommand { - - @Override - public boolean isEnabled() { - return !ForgeHelper.HAS_FORGE; - } - - @Override - public void execute(CommandSender sender, List params) throws CommandException { - Player player = super.getSenderAsPlayer(sender); - if(player.getMinecraftPlayer() instanceof EntityPlayerMP) { - Settings config = super.loadSettings(player); - boolean instantMine = config.getBoolean("instantMine", false); - if (params.size() == 0) { - instantMine ^= true; - } else { - instantMine = ((Boolean)params.get(0)); - } - config.set("instantMine", instantMine); - super.saveSettings(player); - player.sendChatMessage("Instant mining " + (instantMine?"enabled.":"disabled.")); - } else { - throw new CommandException("Non-client command"); - } - } - - @Override - public Parameters getParameters() { - return Parameters.DEFAULT_BOOLEAN; - } - -} \ No newline at end of file diff --git a/src/com/sijobe/spc/command/Light.java b/src/com/sijobe/spc/command/Light.java deleted file mode 100644 index 9030cca..0000000 --- a/src/com/sijobe/spc/command/Light.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.sijobe.spc.command; - -import com.sijobe.spc.wrapper.CommandException; -import com.sijobe.spc.wrapper.CommandSender; -import com.sijobe.spc.wrapper.Minecraft; -import com.sijobe.spc.wrapper.Player; -import com.sijobe.spc.wrapper.World; - -import java.util.List; - -/** - * Light command from SinglePlayerCommands 3.2.2, - * ported to SinglePlayerConsole then back to SPC 4.1 - * - * @author q3hardcore - * @version 1.4 - */ -@Command ( - name = "light", - description = "Lights up world", - version = "1.4" -) -public class Light extends StandardCommand { - - public static boolean isLit = false; // is current world lit? - public static int litWorld = 0; // hashCode for currently lit world - - /** - * @see com.sijobe.spc.wrapper.CommandBase#execute(com.sijobe.spc.wrapper.CommandSender, java.util.List) - */ - @Override - public void execute(CommandSender sender, List params) throws CommandException { - Player player = super.getSenderAsPlayer(sender); // Why super.? Meh, Cannon has it like that - Player clientPlayer = Minecraft.getPlayer(); - - if(clientPlayer == null) { - throw new CommandException("No client player!"); - } - - World clientWorld = clientPlayer.getWorld(); - - if(player.getWorld().getMinecraftWorld().hashCode() != litWorld) { - isLit = false; - } - - // Note: provider is worldProvider - if(!isLit) { - sender.sendMessageToPlayer("Lighting world"); - float[] lightBrightnessTable = clientWorld.getMinecraftWorld().provider.lightBrightnessTable; - for(int i = 0; i < lightBrightnessTable.length; i++) { - lightBrightnessTable[i] = 1.0F; - } - litWorld = player.getWorld().getMinecraftWorld().hashCode(); // we go by the serverside hashcode - } else { - sender.sendMessageToPlayer("Restoring light levels"); - clientWorld.getMinecraftWorld().provider.registerWorld(clientWorld.getMinecraftWorld()); - } - isLit = !isLit; // toggle isLit - } - - /** - * Only enabled in single player since this is a client-side mod - * - * @see com.sijobe.spc.wrapper.CommandBase#isEnabled() - */ - @Override - public boolean isEnabled() { - return Minecraft.isSinglePlayer(); - } - -} diff --git a/src/com/sijobe/spc/command/Macro.java b/src/com/sijobe/spc/command/Macro.java deleted file mode 100644 index c6377c4..0000000 --- a/src/com/sijobe/spc/command/Macro.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.sijobe.spc.command; - -import com.sijobe.spc.core.Constants; -import com.sijobe.spc.validation.Parameter; -import com.sijobe.spc.validation.ParameterString; -import com.sijobe.spc.validation.Parameters; -import com.sijobe.spc.wrapper.CommandException; -import com.sijobe.spc.wrapper.CommandManager; -import com.sijobe.spc.wrapper.CommandSender; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.util.List; - -/** - * Macro command allows you to write a file with a list of commands in it then - * run the file. - * - * @author simo_415 - * @version 1.0 - */ -@Command ( - name = "macro", - description = "Macro based commands allow multiple commands to be run", - example = "test", - videoURL = "http://www.youtube.com/watch?v=hkQfslQJoQs", - version = "1.0" -) -public class Macro extends StandardCommand { - - /** - * The file extension of macro files - */ - public static final String MACRO_EXTENSION = ".txt"; - /** - * The directory that the macro files and retrieved from - */ - public static final File MACRO_DIR = new File(Constants.MOD_DIR, "macros"); - static { - if (!MACRO_DIR.exists()) { - MACRO_DIR.mkdirs(); - } - } - - /** - * Parameters of the command - */ - private static final Parameters PARAMETERS = new Parameters ( - new Parameter[] { - new ParameterString("", false), - new ParameterString("{PARAMETERS}", true, true) - } - ); - - /** - * @see com.sijobe.spc.wrapper.CommandBase#execute(com.sijobe.spc.wrapper.CommandSender, java.util.List) - */ - @Override - public void execute(CommandSender sender, List params) throws CommandException { - File macro = new File(MACRO_DIR, (String)params.get(0) + MACRO_EXTENSION); - if (!macro.exists()) { - throw new CommandException("Specified macro does not exist."); - } - - try { - BufferedReader br = new BufferedReader(new FileReader(macro)); - String split[] = null; - if (params.size() == 1) { - split = new String[] { (String)params.get(0) }; - } else { - split = (((String)params.get(0)) + " " + ((String)params.get(1))).split(" "); - } - String line = null; - while ((line = br.readLine()) != null) { - // Adds arguments to the line - for (int i = 0; i < split.length; i++) { - line = line.replaceAll("\\$_" + i, split[i]); - } - - // Remove all unspecified arguments from line - line = line.replaceAll("\\$_[0-9]+", ""); - - // Executes the line - CommandManager.runCommand(sender, line); - } - } catch (Exception e) { - throw new CommandException(e); - } - } - - /** - * @see com.sijobe.spc.wrapper.CommandBase#getParameters() - */ - @Override - public Parameters getParameters() { - return PARAMETERS; - } -} diff --git a/src/com/sijobe/spc/command/SetSpeed.java b/src/com/sijobe/spc/command/SetSpeed.java deleted file mode 100644 index 1467aa4..0000000 --- a/src/com/sijobe/spc/command/SetSpeed.java +++ /dev/null @@ -1,132 +0,0 @@ -package com.sijobe.spc.command; - -import com.sijobe.spc.core.IPlayerSP; -import com.sijobe.spc.util.FontColour; -import com.sijobe.spc.util.Settings; -import com.sijobe.spc.validation.Parameter; -import com.sijobe.spc.validation.ParameterString; -import com.sijobe.spc.validation.Parameters; -import com.sijobe.spc.wrapper.CommandException; -import com.sijobe.spc.wrapper.CommandSender; -import com.sijobe.spc.wrapper.Coordinate; -import com.sijobe.spc.wrapper.Minecraft; -import com.sijobe.spc.wrapper.Player; - -import java.util.List; - -/** - * The set speed command allows you to set the speed that the player moves at. - * By default the player speed is 1 where player speed 2 is twice as fast, - * etc.. - * - * @author simo_415 - * @version 1.1 - */ -@Command ( - name = "setspeed", - description = "Sets the players speed to the value specified", - example = "2", - videoURL = "http://www.youtube.com/watch?v=G48upLnQr-s", - version = "1.3", - enabled = true -) -public class SetSpeed extends StandardCommand implements IPlayerSP { - /** - * The parameters of the command - */ - private static final Parameters PARAMETERS = new Parameters ( - new Parameter[] { - new ParameterString("", false), - } - ); - - /** - * The default speed multiplier that the player moves - */ - private static final double DEFAULT_SPEED = 1; - - /** - * The key that is saved into the config - */ - private static final String CONFIG_KEY = "speed"; - - /** - * @see com.sijobe.spc.wrapper.CommandBase#execute(com.sijobe.spc.wrapper.CommandSender, java.util.List) - */ - @Override - public void execute(CommandSender sender, List params) throws CommandException { - Settings config = super.loadSettings(super.getSenderAsPlayer(sender)); - if (((String)params.get(0)).equalsIgnoreCase("reset")) { - config.set(CONFIG_KEY, DEFAULT_SPEED); - } else { - try { - config.set(CONFIG_KEY, Double.parseDouble((String)params.get(0))); - } catch (Exception e) { - throw new CommandException("Could not parse " + (String)params.get(0) + " as a speed."); - } - } - config.save(); - sender.sendMessageToPlayer("Player speed set to " + FontColour.AQUA - + config.getDouble(CONFIG_KEY, DEFAULT_SPEED) + FontColour.WHITE + "x normal speed"); - } - - /** - * @see com.sijobe.spc.wrapper.CommandBase#getParameters() - */ - @Override - public Parameters getParameters() { - return PARAMETERS; - } - - /** - * @see com.sijobe.spc.core.IHook#init(java.lang.Object[]) - */ - @Override - public void init(Object... params) { - } - - /** - * @see com.sijobe.spc.core.IPlayerMP#onTick(com.sijobe.spc.wrapper.Player) - */ - @Override - public void onTick(Player player) { - } - - /** - * Only enabled in single player since this is a client-side mod - * - * @see com.sijobe.spc.wrapper.CommandBase#isEnabled() - */ - @Override - public boolean isEnabled() { - return Minecraft.isSinglePlayer(); - } - - /** - * @see com.sijobe.spc.core.IPlayerSP#movePlayer(float, float, float) - */ - @Override - public void movePlayer(Player player, float forward, float strafe, float speed) { - Double pspeed = super.loadSettings(player).getDouble(CONFIG_KEY, DEFAULT_SPEED); - if (pspeed == null || pspeed == 1) { - return; - } - pspeed--; - double direction = Math.sqrt((forward * forward) + (strafe * strafe)); - if (direction < 0.01F) { - return; - } - if (direction < 1.0D) { - direction = 1D; - } - direction = speed / direction; - forward *= direction; - strafe *= direction; - double f4 = Math.sin(player.getYaw() * Math.PI / 180.0F); - double f5 = Math.cos(player.getYaw() * Math.PI / 180.0F); - Coordinate motion = player.getMotion(); - double motionx = forward * f5 - strafe * f4; - double motionz = strafe * f5 + forward * f4; - player.setMotion(new Coordinate(motion.getX() + motionx * pspeed, motion.getY(), motion.getZ() + motionz * pspeed)); - } -} diff --git a/src/com/sijobe/spc/command/SpawnPortal.java b/src/com/sijobe/spc/command/SpawnPortal.java deleted file mode 100644 index e7f42ad..0000000 --- a/src/com/sijobe/spc/command/SpawnPortal.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.sijobe.spc.command; - -import com.sijobe.spc.validation.Parameter; -import com.sijobe.spc.validation.ParameterString; -import com.sijobe.spc.validation.Parameters; -import com.sijobe.spc.wrapper.CommandException; -import com.sijobe.spc.wrapper.CommandSender; -import com.sijobe.spc.wrapper.Coordinate; -import com.sijobe.spc.wrapper.Player; -import java.lang.reflect.Method; -import net.minecraft.src.EntityDragon; -import net.minecraft.src.EntityPlayerMP; -import net.minecraft.src.MathHelper; -import net.minecraft.src.Teleporter; - -import java.util.List; - -/** - * Command spawns the specified type of portal - * - * @author q3hardcore - * @version 1.0 - */ -@Command ( - name = "spawnportal", - description = "Spawns a portal at the players location", - example = "nether", - version = "1.0" -) -public class SpawnPortal extends StandardCommand { - /** - * Specifies the parameters of the command - */ - private static final Parameters PARAMETERS = new Parameters ( - new Parameter[] { - new ParameterString("",false), - } - ); - - /** - * @see com.sijobe.spc.wrapper.CommandBase#execute(net.minecraft.src.ICommandSender, java.util.List) - */ - @Override - public void execute(CommandSender sender, List params) throws CommandException { - Player player = super.getSenderAsPlayer(sender); - String portalType = (String)params.get(0); - if (portalType.equalsIgnoreCase("end")) { - Coordinate coord = player.getPosition(); - int x = MathHelper.floor_double(coord.getX()); - int z = MathHelper.floor_double(coord.getZ()); - EntityDragon entityDragon = new EntityDragon(player.getWorld().getMinecraftWorld()); // EntityDragon - try { - Class[] args = new Class[]{Integer.TYPE, Integer.TYPE}; - Method method; - try { - method = entityDragon.getClass().getDeclaredMethod("c", args); - } catch (NoSuchMethodException nsme) { - method = entityDragon.getClass().getDeclaredMethod("createEnderPortal", args); - } - method.setAccessible(true); - method.invoke(entityDragon, new Object[]{x, z}); - } catch (Throwable t) { - t.printStackTrace(); - throw new CommandException("End portal generation is currently unsupported."); - } - } else if (portalType.equalsIgnoreCase("nether")) { - EntityPlayerMP playerEntity; - if(player.getMinecraftPlayer() instanceof EntityPlayerMP) { - playerEntity = (EntityPlayerMP)player.getMinecraftPlayer(); - } else { - throw new CommandException("SPC should *NOT* be processing commands client-side!"); - } - (new Teleporter(playerEntity.getServerForPlayer())).makePortal(playerEntity); - } else { - throw new CommandException("Invalid portal type specified."); - } - } - - /** - * @see com.sijobe.spc.wrapper.CommandBase#getParameters() - */ - @Override - public Parameters getParameters() { - return PARAMETERS; - } -} diff --git a/src/com/sijobe/spc/overwrite/ONetServerHandler.java b/src/com/sijobe/spc/overwrite/ONetServerHandler.java deleted file mode 100644 index ba9a836..0000000 --- a/src/com/sijobe/spc/overwrite/ONetServerHandler.java +++ /dev/null @@ -1,335 +0,0 @@ -package com.sijobe.spc.overwrite; - -import com.sijobe.spc.command.Noclip; -import com.sijobe.spc.util.ForgeHelper; -import com.sijobe.spc.util.Mappings; -import com.sijobe.spc.util.ReflectionHelper; - -import java.lang.reflect.Field; -import java.util.HashMap; - -import net.minecraft.server.MinecraftServer; -import net.minecraft.src.AxisAlignedBB; -import net.minecraft.src.EntityPlayerMP; -import net.minecraft.src.INetworkManager; -import net.minecraft.src.NetServerHandler; -import net.minecraft.src.Packet10Flying; -import net.minecraft.src.WorldServer; - -/** - * Custom server handler to allow noclip - * Note: use of reflection is neccessary, - * otherwise player cannot interact with world - * - * @author q3hardcore - * @version 1.4 - */ -public final class ONetServerHandler extends NetServerHandler { - - private final NetServerHandler oldInstance; - private final MinecraftServer mcServer; - private int ticksForFloatKick; - private double lastPosX; - private double lastPosY; - private double lastPosZ; - private boolean hasMoved = true; - - private static final HashMap fieldMappings; - - // mappings valid as of: Minecraft 1.5.2 (no changes) - static { - fieldMappings = new Mappings(); - fieldMappings.put("lastPosX", new String[]{"n", "field_72579_o"}); - fieldMappings.put("lastPosY", new String[]{"o", "field_72589_p"}); - fieldMappings.put("lastPosZ", new String[]{"p", "field_72588_q"}); - fieldMappings.put("hasMoved", new String[]{"q", "field_72587_r"}); - } - - public ONetServerHandler(MinecraftServer par1, INetworkManager par2, EntityPlayerMP par3, NetServerHandler instance) { - super(par1, par2, par3); - - if(instance instanceof ONetServerHandler) { - throw new RuntimeException("SPC: Critical error encountered!"); - } - - oldInstance = instance; - mcServer = par1; - connectionClosed = oldInstance.connectionClosed; - } - - public NetServerHandler getOldInstance() { - return oldInstance; - } - - private void updateHasMoved() { - Field field = ReflectionHelper.getField(oldInstance, fieldMappings.get("hasMoved")); - this.hasMoved = ReflectionHelper.getBoolean(field, oldInstance); - } - - private void updatePosition() { - Field field; - field = ReflectionHelper.getField(oldInstance, fieldMappings.get("lastPosX")); - this.lastPosX = ReflectionHelper.getDouble(field, oldInstance); - field = ReflectionHelper.getField(oldInstance, fieldMappings.get("lastPosY")); - this.lastPosY = ReflectionHelper.getDouble(field, oldInstance); - field = ReflectionHelper.getField(oldInstance, fieldMappings.get("lastPosZ")); - this.lastPosZ = ReflectionHelper.getDouble(field, oldInstance); - } - - private void setHasMoved(boolean bool) { - Field field = ReflectionHelper.getField(oldInstance, fieldMappings.get("hasMoved")); - ReflectionHelper.setField(field, oldInstance, bool); - } - - private void setPosition(double x, double y, double z) { - Field field; - field = ReflectionHelper.getField(oldInstance, fieldMappings.get("lastPosX")); - ReflectionHelper.setField(field, oldInstance, x); - field = ReflectionHelper.getField(oldInstance, fieldMappings.get("lastPosY")); - ReflectionHelper.setField(field, oldInstance, y); - field = ReflectionHelper.getField(oldInstance, fieldMappings.get("lastPosZ")); - ReflectionHelper.setField(field, oldInstance, z); - } - - @Override - public void handleFlying(Packet10Flying par1Packet10Flying) - { - // we use Forge's handleFlying method - if(!ForgeHelper.HAS_FORGE) { - updateHasMoved(); - updatePosition(); - } - - Noclip.checkSafe(this.playerEntity); - - // Forge has Noclip support - if(ForgeHelper.HAS_FORGE) { - super.handleFlying(par1Packet10Flying); - return; - } - - WorldServer var2 = this.mcServer.worldServerForDimension(oldInstance.playerEntity.dimension); - - if (!oldInstance.playerEntity.playerConqueredTheEnd) - { - double var3; - - if (!hasMoved) - { - var3 = par1Packet10Flying.yPosition - lastPosY; - - if (par1Packet10Flying.xPosition == lastPosX && var3 * var3 < 0.01D && par1Packet10Flying.zPosition == lastPosZ) - { - setHasMoved(true); - hasMoved = true; - } - } - - if (hasMoved) - { - double var5; - double var7; - double var9; - double var13; - - if (oldInstance.playerEntity.ridingEntity != null) - { - float var34 = oldInstance.playerEntity.rotationYaw; - float var4 = oldInstance.playerEntity.rotationPitch; - oldInstance.playerEntity.ridingEntity.updateRiderPosition(); - var5 = oldInstance.playerEntity.posX; - var7 = oldInstance.playerEntity.posY; - var9 = oldInstance.playerEntity.posZ; - double var35 = 0.0D; - var13 = 0.0D; - - if (par1Packet10Flying.rotating) - { - var34 = par1Packet10Flying.yaw; - var4 = par1Packet10Flying.pitch; - } - - if (par1Packet10Flying.moving && par1Packet10Flying.yPosition == -999.0D && par1Packet10Flying.stance == -999.0D) - { - if (Math.abs(par1Packet10Flying.xPosition) > 1.0D || Math.abs(par1Packet10Flying.zPosition) > 1.0D) - { - System.err.println(oldInstance.playerEntity.getUsername() + " was caught trying to crash the server with an invalid position."); - this.kickPlayerFromServer("Nope!"); - return; - } - - var35 = par1Packet10Flying.xPosition; - var13 = par1Packet10Flying.zPosition; - } - - this.playerEntity.onGround = par1Packet10Flying.onGround; - this.playerEntity.onUpdateEntity(); - this.playerEntity.moveEntity(var35, 0.0D, var13); - this.playerEntity.setPositionAndRotation(var5, var7, var9, var34, var4); - this.playerEntity.motionX = var35; - this.playerEntity.motionZ = var13; - - /*TODO if (this.playerEntity.ridingEntity != null) - { - var2.uncheckedUpdateEntity(this.playerEntity.ridingEntity, true); - }*/ - - if (this.playerEntity.ridingEntity != null) - { - this.playerEntity.ridingEntity.updateRiderPosition(); - } - - this.mcServer.getConfigurationManager().serverUpdateMountedMovingPlayer(this.playerEntity); - lastPosX = this.playerEntity.posX; - lastPosY = this.playerEntity.posY; - lastPosZ = this.playerEntity.posZ; - setPosition(lastPosX, lastPosY, lastPosZ); - var2.updateEntity(this.playerEntity); - return; - } - - if (this.playerEntity.isPlayerSleeping()) - { - this.playerEntity.onUpdateEntity(); - this.playerEntity.setPositionAndRotation(lastPosX, lastPosY, lastPosZ, this.playerEntity.rotationYaw, this.playerEntity.rotationPitch); - var2.updateEntity(this.playerEntity); - return; - } - - var3 = this.playerEntity.posY; - lastPosX = this.playerEntity.posX; - lastPosY = this.playerEntity.posY; - lastPosZ = this.playerEntity.posZ; - setPosition(lastPosX, lastPosY, lastPosZ); - var5 = this.playerEntity.posX; - var7 = this.playerEntity.posY; - var9 = this.playerEntity.posZ; - float var11 = this.playerEntity.rotationYaw; - float var12 = this.playerEntity.rotationPitch; - - if (par1Packet10Flying.moving && par1Packet10Flying.yPosition == -999.0D && par1Packet10Flying.stance == -999.0D) - { - par1Packet10Flying.moving = false; - } - - if (par1Packet10Flying.moving) - { - var5 = par1Packet10Flying.xPosition; - var7 = par1Packet10Flying.yPosition; - var9 = par1Packet10Flying.zPosition; - var13 = par1Packet10Flying.stance - par1Packet10Flying.yPosition; - - if (!this.playerEntity.isPlayerSleeping() && (var13 > 1.65D || var13 < 0.1D)) - { - this.kickPlayerFromServer("Illegal stance"); - this.mcServer.getLogAgent().logWarning(this.playerEntity.getUsername() + " had an illegal stance: " + var13); - return; - } - - if (Math.abs(par1Packet10Flying.xPosition) > 3.2E7D || Math.abs(par1Packet10Flying.zPosition) > 3.2E7D) - { - this.kickPlayerFromServer("Illegal position"); - return; - } - } - - if (par1Packet10Flying.rotating) - { - var11 = par1Packet10Flying.yaw; - var12 = par1Packet10Flying.pitch; - } - - this.playerEntity.onUpdateEntity(); - this.playerEntity.ySize = 0.0F; - this.playerEntity.setPositionAndRotation(lastPosX, lastPosY, lastPosZ, var11, var12); - - if (!hasMoved) - { - return; - } - - var13 = var5 - this.playerEntity.posX; - double var15 = var7 - this.playerEntity.posY; - double var17 = var9 - this.playerEntity.posZ; - double var19 = Math.min(Math.abs(var13), Math.abs(this.playerEntity.motionX)); - double var21 = Math.min(Math.abs(var15), Math.abs(this.playerEntity.motionY)); - double var23 = Math.min(Math.abs(var17), Math.abs(this.playerEntity.motionZ)); - double var25 = var19 * var19 + var21 * var21 + var23 * var23; - - if (var25 > 100.0D && (!this.mcServer.isSinglePlayer() || !this.mcServer.getServerOwner().equals(this.playerEntity.getUsername()))) - { - this.mcServer.getLogAgent().logWarning(this.playerEntity.getUsername() + " moved too quickly! " + var13 + "," + var15 + "," + var17 + " (" + var19 + ", " + var21 + ", " + var23 + ")"); - this.setPlayerLocation(lastPosX, lastPosY, lastPosZ, this.playerEntity.rotationYaw, this.playerEntity.rotationPitch); - return; - } - - float var27 = 0.0625F; - boolean var28 = var2.getCollidingBoundingBoxes(this.playerEntity, this.playerEntity.boundingBox.copy().contract(var27, var27, var27)).isEmpty(); - - if (this.playerEntity.onGround && !par1Packet10Flying.onGround && var15 > 0.0D) - { - this.playerEntity.addExhaustion(0.2F); - } - - this.playerEntity.moveEntity(var13, var15, var17); - this.playerEntity.onGround = par1Packet10Flying.onGround; - this.playerEntity.addMovementStat(var13, var15, var17); - double var29 = var15; - var13 = var5 - this.playerEntity.posX; - var15 = var7 - this.playerEntity.posY; - - if (var15 > -0.5D || var15 < 0.5D) - { - var15 = 0.0D; - } - - var17 = var9 - this.playerEntity.posZ; - var25 = var13 * var13 + var15 * var15 + var17 * var17; - boolean var31 = false; - - if (var25 > 0.0625D && !this.playerEntity.isPlayerSleeping() && !this.playerEntity.theItemInWorldManager.isCreative()) - { - var31 = true; - this.mcServer.getLogAgent().logWarning(this.playerEntity.getUsername() + " moved wrongly!"); - } - - this.playerEntity.setPositionAndRotation(var5, var7, var9, var11, var12); - boolean var32 = var2.getCollidingBoundingBoxes(this.playerEntity, this.playerEntity.boundingBox.copy().contract(var27, var27, var27)).isEmpty(); - - if(this.playerEntity.noClip) { - // do nothing - } - else if (var28 && (var31 || !var32) && !this.playerEntity.isPlayerSleeping()) - { - this.setPlayerLocation(lastPosX, lastPosY, lastPosZ, var11, var12); - return; - } - - AxisAlignedBB var33 = this.playerEntity.boundingBox.copy().expand(var27, var27, var27).addCoord(0.0D, -0.55D, 0.0D); - - if (!this.mcServer.isFlightAllowed() && !this.playerEntity.theItemInWorldManager.isCreative() && !var2.checkBlockCollision(var33)) - { - if (var29 >= -0.03125D) - { - ticksForFloatKick++; - - if (ticksForFloatKick > 80) - { - this.mcServer.getLogAgent().logWarning(this.playerEntity.getUsername() + " was kicked for floating too long!"); - this.kickPlayerFromServer("Flying is not enabled on this server"); - return; - } - } - } - else - { - ticksForFloatKick = 0; - } - - this.playerEntity.onGround = par1Packet10Flying.onGround; - this.mcServer.getConfigurationManager().serverUpdateMountedMovingPlayer(this.playerEntity); - this.playerEntity.updateFlyingState(this.playerEntity.posY - var3, par1Packet10Flying.onGround); - } - } - } -} diff --git a/src/com/sijobe/spc/util/ForgeHelper.java b/src/com/sijobe/spc/util/ForgeHelper.java deleted file mode 100644 index 32f079c..0000000 --- a/src/com/sijobe/spc/util/ForgeHelper.java +++ /dev/null @@ -1,197 +0,0 @@ -package com.sijobe.spc.util; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.ArrayList; - -import net.minecraft.src.ChunkCoordIntPair; -import net.minecraft.src.ChunkCoordinates; -import net.minecraft.src.DamageSource; -import net.minecraft.src.Entity; -import net.minecraft.src.EntityItem; -import net.minecraft.src.EntityLiving; -import net.minecraft.src.EntityPlayer; -import net.minecraft.src.EntityPlayerMP; -import net.minecraft.src.ItemInWorldManager; -import net.minecraft.src.WorldProvider; - -/** - * Helper for compatiblity with Minecraft Forge - * - * @author q3hardcore - * @version 1.0 - */ -public final class ForgeHelper { - - public static final boolean HAS_FORGE = getHasForge(); - - private final static Class forgeClass; - private final static Field eventBusField; - private final static Class eventClass; - private final static Class eventBusClass; - private final static Method post; - private final static Field capturedDropsField; - private final static Field captureDropsField; - private final static Class playerDropsEventClass; - private final static Constructor playerDropsEventConstructor; - private final static Class watchClass; - private final static Constructor watchConstructor; - private final static Method getBlockReachDistance; - private final static Method setBlockReachDistance; - private final static Class forgeHooksClass; - private final static Method onLivingDeath; - - private static boolean getHasForge() { - try { - Class.forName("net.minecraftforge.common.MinecraftForge"); - return true; - } catch (Throwable t) { - return false; - } - } - - public static ChunkCoordinates getRandomizedSpawnPoint(WorldProvider provider) { - ChunkCoordinates spawnPoint = new ChunkCoordinates(0, 64, 0); - try { - spawnPoint = (ChunkCoordinates)provider.getClass().getMethod("getRandomizedSpawnPoint").invoke(provider); - } catch (Throwable t) { - t.printStackTrace(); - } - return spawnPoint; - } - - public static void clearDrops(EntityPlayerMP entityPlayerMP) { - setCaptureDrops(entityPlayerMP, true); - getCapturedDrops(entityPlayerMP).clear(); - } - - @SuppressWarnings("unchecked") - public static void captureDrops(EntityPlayerMP entityPlayerMP, DamageSource damageSource, int recentlyHit) { - setCaptureDrops(entityPlayerMP, false); - Object event = createPlayerDropsEvent(entityPlayerMP, damageSource, getCapturedDrops(entityPlayerMP), recentlyHit > 0); - if(!postEvent(event)) { - for(EntityItem entityItem : getCapturedDrops(entityPlayerMP)) { - entityPlayerMP.worldObj.spawnEntityInWorld(entityItem); - } - } - } - - private static boolean postEvent(Object event) { - if(event == null) { - System.err.println("SPC/Forge: No event to post."); - return false; - } - try { - Object returnVal = post.invoke(eventBusField.get(null), new Object[]{event}); - return Boolean.parseBoolean(returnVal.toString()); - } catch (Throwable t) { - t.printStackTrace(); - return false; - } - } - - public static void watchChunk(ChunkCoordIntPair chunkCoord, EntityPlayerMP player) { - try { - Object event = watchConstructor.newInstance(new Object[]{chunkCoord, player}); - postEvent(event); - } catch (Throwable t) { - t.printStackTrace(); - } - } - - private static Object createPlayerDropsEvent(EntityPlayer player, DamageSource damageSource, - ArrayList drops, boolean wasRecentlyHit) { - Object playerDropsEvent = null; - try { - playerDropsEvent = playerDropsEventConstructor.newInstance(new Object[]{player, damageSource, drops, wasRecentlyHit}); - } catch (Throwable t) { - t.printStackTrace(); - } - return playerDropsEvent; - } - - private static void setCaptureDrops(Entity entity, boolean val) { - try { - captureDropsField.set(entity, val); - } catch (Throwable t) { - t.printStackTrace(); - } - } - - @SuppressWarnings("unchecked") - private static ArrayList getCapturedDrops(Entity entity) { - ArrayList capturedDrops = new ArrayList(); - try { - Object returnVal = capturedDropsField.get(entity); - if(returnVal instanceof ArrayList) { - capturedDrops = (ArrayList)returnVal; - } else { - System.err.println("SPC/Forge: Couldn't determine captured drops."); - } - } catch (Throwable t) { - t.printStackTrace(); - } - return capturedDrops; - } - - public static boolean onLivingDeath(EntityPlayerMP entityPlayerMP, DamageSource damageSource) { - try { - Object returnVal = onLivingDeath.invoke(null, entityPlayerMP, damageSource); - return Boolean.parseBoolean(returnVal.toString()); - } catch (Throwable t) { - t.printStackTrace(); - return false; - } - } - - public static double getBlockReachDistance(ItemInWorldManager manager) { - try { - Object returnVal = getBlockReachDistance.invoke(manager); - return Double.parseDouble(returnVal.toString()); - } catch (Throwable t) { - t.printStackTrace(); - return 5.0D; - } - } - - public static void setBlockReachDistance(ItemInWorldManager manager, double distance) { - try { - setBlockReachDistance.invoke(manager, distance); - } catch (Throwable t) { - t.printStackTrace(); - } - } - - static { - if(HAS_FORGE) { - System.out.println("SPC: Detected Forge."); - forgeClass = ReflectionHelper.getClass("net.minecraftforge.common.MinecraftForge"); - eventBusField = ReflectionHelper.getField(forgeClass, "EVENT_BUS"); - eventClass = ReflectionHelper.getClass("net.minecraftforge.event.Event"); - eventBusClass = ReflectionHelper.getClass("net.minecraftforge.event.EventBus"); - post = ReflectionHelper.getMethod(eventBusClass, "post", eventClass); - capturedDropsField = ReflectionHelper.getField(Entity.class, "capturedDrops"); - captureDropsField = ReflectionHelper.getField(Entity.class, "captureDrops"); - playerDropsEventClass = ReflectionHelper.getClass("net.minecraftforge.event.entity.player.PlayerDropsEvent"); - final Class[] params = new Class[]{ EntityPlayer.class, DamageSource.class, ArrayList.class, Boolean.TYPE }; - playerDropsEventConstructor = ReflectionHelper.getConstructor(playerDropsEventClass, params); - watchClass = ReflectionHelper.getClass("net.minecraftforge.event.world.ChunkWatchEvent$Watch"); - watchConstructor = ReflectionHelper.getConstructor(watchClass, new Class[]{ChunkCoordIntPair.class, EntityPlayerMP.class}); - getBlockReachDistance = ReflectionHelper.getMethod(ItemInWorldManager.class, "getBlockReachDistance"); - setBlockReachDistance = ReflectionHelper.getMethod(ItemInWorldManager.class, "setBlockReachDistance", Double.TYPE); - forgeHooksClass = ReflectionHelper.getClass("net.minecraftforge.common.ForgeHooks"); - onLivingDeath = ReflectionHelper.getMethod(forgeHooksClass, "onLivingDeath", EntityLiving.class, DamageSource.class); - } else { - System.out.println("SPC: Forge not detected."); - forgeClass = null; eventBusField = null; - eventClass = null; eventBusClass = null; - post = null; - capturedDropsField = null; captureDropsField = null; - playerDropsEventClass = null; playerDropsEventConstructor = null; - watchClass = null; watchConstructor = null; - getBlockReachDistance = null; setBlockReachDistance = null; - forgeHooksClass = null; onLivingDeath = null; - } - } -} \ No newline at end of file diff --git a/src/com/sijobe/spc/util/Mappings.java b/src/com/sijobe/spc/util/Mappings.java deleted file mode 100644 index b4e7d97..0000000 --- a/src/com/sijobe/spc/util/Mappings.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.sijobe.spc.util; - -import java.util.HashMap; - -/** - * Class for storing obfuscation mappings - * - * @author q3hardcore - * @version 1.3 - */ -public class Mappings extends HashMap { - - private static final long serialVersionUID = 1L; - - /** - * Adds a value to the map with all the alternate mappings - * - * @see java.util.HashMap#put(java.lang.Object, java.lang.Object) - */ - @Override - public String[] put(String mcpName, String[] alternateMappings) { - return super.put(mcpName, makeMapping(mcpName, alternateMappings)); - } - - /** - * Adds a value to the map without alteration - * - * @see java.util.HashMap#put(java.lang.Object, java.lang.Object) - */ - public String[] superPut(String key, String[] value) { - return super.put(key, value); - } - - /** - * Gets mappings for the specified value - * - * @see java.util.HashMap#get(java.lang.Object) - */ - @Override - public String[] get(Object key) { - String[] mappings = super.get(key); - if(mappings == null) { - return new String[]{ key.toString() }; - } else { - return mappings; - } - } - - /** - * @param mcpName - * @param mappings - * @return mappings with mcpName prepended - */ - private String[] makeMapping(String mcpName, String[] mappings) { - String[] newMappings = new String[mappings.length + 1]; - newMappings[0] = mcpName; - for(int i = 0; i < mappings.length; i++) { - newMappings[i+1] = mappings[i]; - } - return newMappings; - } -} \ No newline at end of file diff --git a/src/com/sijobe/spc/worldedit/LocalPlayer.java b/src/com/sijobe/spc/worldedit/LocalPlayer.java deleted file mode 100644 index cdb32f4..0000000 --- a/src/com/sijobe/spc/worldedit/LocalPlayer.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.sijobe.spc.worldedit; - -import com.sijobe.spc.core.ICUIEventHandler; -import com.sijobe.spc.util.FontColour; -import com.sijobe.spc.util.WorldEditCUIHelper; -import com.sijobe.spc.wrapper.Coordinate; -import com.sijobe.spc.wrapper.Player; -import com.sk89q.worldedit.ServerInterface; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.WorldVector; -import com.sk89q.worldedit.bags.BlockBag; -import com.sk89q.worldedit.cui.CUIEvent; - -public class LocalPlayer extends com.sk89q.worldedit.LocalPlayer { - - private Player player; - - protected LocalPlayer(Player player, ServerInterface server) { - super(server); - this.player = player; - } - - @Override - public String[] getGroups() { - // TODO Auto-generated method stub - return null; - } - - @Override - public BlockBag getInventoryBlockBag() { - // TODO Auto-generated method stub - return null; - } - - @Override - public int getItemInHand() { - return player.getCurrentItem(); - } - - @Override - public String getName() { - return player.getPlayerName(); - } - - @Override - public double getPitch() { - return player.getPitch(); - } - - @Override - public WorldVector getPosition() { - Coordinate c = player.getPosition(); - return new WorldVector(getWorld(), c.getX(), c.getY(), c.getZ()); - } - - @Override - public com.sk89q.worldedit.LocalWorld getWorld() { - return new LocalWorld(player.getWorld()); - } - - @Override - public double getYaw() { - return player.getYaw(); - } - - @Override - public void giveItem(int type, int quantity) { - player.givePlayerItem(type, quantity); - } - - @Override - public boolean hasPermission(String arg0) { - // TODO Check permissions - return true; - } - - @Override - public void print(String message) { - player.sendChatMessage(message); - } - - @Override - public void printDebug(String message) { - System.out.println("WORLDEDIT-DEBUG: " + message); - } - - @Override - public void printError(String message) { - player.sendChatMessage(FontColour.RED + message); - } - - @Override - public void printRaw(String message) { // TODO: Fix - player.sendChatMessage(message); - } - - @Override - public void setPosition(Vector pos, float pitch, float yaw) { - player.setPosition(new Coordinate(pos.getX(),pos.getY(),pos.getZ())); - player.setPitch(pitch); - player.setYaw(yaw); - } - - @Override - public boolean equals(Object object) { - if (object != null && object instanceof LocalPlayer) { - return ((LocalPlayer)object).getName().equals(getName()); - } - return false; - } - - @Override - public void dispatchCUIEvent(CUIEvent event) { - for (ICUIEventHandler hook : WorldEditCUIHelper.getCUIHooks()) { - if (hook.isEnabled()) { - hook.handleCUIEvent(event.getTypeId(), event.getParameters()); - } - } - } -} diff --git a/src/com/sijobe/spc/worldedit/LocalWorld.java b/src/com/sijobe/spc/worldedit/LocalWorld.java deleted file mode 100644 index 6dcf9e1..0000000 --- a/src/com/sijobe/spc/worldedit/LocalWorld.java +++ /dev/null @@ -1,302 +0,0 @@ -package com.sijobe.spc.worldedit; - -import com.sijobe.spc.wrapper.Coordinate; -import com.sijobe.spc.wrapper.World; -import com.sk89q.worldedit.BiomeType; -import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.EntityType; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; -import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.blocks.BaseItemStack; -import com.sk89q.worldedit.regions.Region; - -// q3 code ;) -import java.util.List; -import net.minecraft.server.MinecraftServer; -import net.minecraft.src.AxisAlignedBB; -import net.minecraft.src.DamageSource; -import net.minecraft.src.Entity; -import net.minecraft.src.EntityAnimal; -import net.minecraft.src.EntityLiving; -import net.minecraft.src.EntityMob; -import net.minecraft.src.EntityPig; -import net.minecraft.src.EntityPlayer; -import net.minecraft.src.EntityPlayerMP; -import net.minecraft.src.EntityTameable; -import net.minecraft.src.EntityVillager; -import net.minecraft.src.BiomeGenBase; -import net.minecraft.src.Chunk; - -/** - * Implements the WorldEdit local world class that provides necessary methods - * required to edit the world. - * - * TODO: (can this still happen?) - * java.util.ConcurrentModificationException - at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372) - at java.util.AbstractList$Itr.next(AbstractList.java:343) - at net.minecraft.src.PlayerManager.func_72693_b(PlayerManager.java:49) - at net.minecraft.src.WorldServer.tick(WorldServer.java:123) - at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:613) - at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:555) - at net.minecraft.src.IntegratedServer.tick(IntegratedServer.java:121) - at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:464) - at net.minecraft.src.ThreadServerApplication.run(ThreadServerApplication.java:17) - * - * @author simo_415 - * @version 1.2 - */ -public class LocalWorld extends com.sk89q.worldedit.LocalWorld { - - /** - * The world instance that the editing is carried out on - */ - private World world; - - /** - * Default constructor allows the world to be specified - * - * @param world - The world that the editing should be done on - */ - public LocalWorld(World world) { - this.world = world; - } - - @Override - public boolean clearContainerBlockContents(Vector pos) { - return world.emptyContainer(getCoordinate(pos)); - } - - @Override - public boolean copyFromWorld(Vector pos, BaseBlock type) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean copyToWorld(Vector pos, BaseBlock type) { - // TODO Auto-generated method stub - return false; - } - - @Override - public void dropItem(Vector pos, BaseItemStack item) { - // TODO Auto-generated method stub - - } - - @Override - public boolean equals(Object world) { - if (world instanceof LocalWorld) { - return ((LocalWorld)world).getName().equals(getName()); - } - return false; - } - - @Override - public BiomeType getBiome(Vector2D arg0) { - BiomeGenBase biome = this.world.getMinecraftWorld().getBiomeGenForCoords(arg0.getBlockX(), arg0.getBlockZ()); // world.getWorldChunkManager().getBiomeGenAt - try { - return MinecraftBiomeType.valueOf(biome.biomeName.toUpperCase(java.util.Locale.ENGLISH)); // name - } catch(IllegalArgumentException e) { - // e.printStackTrace(); - return BiomeType.UNKNOWN; - } - } - - /** - * TODO: Implements a custom block tile entity if required - * @see https://github.com/sk89q/worldedit/blob/master/src/main/java/com/sk89q/worldedit/bukkit/NmsBlock.java - * @see https://github.com/sk89q/worldedit/blob/master/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java#L962 - * - * @see com.sk89q.worldedit.LocalWorld#getBlock(com.sk89q.worldedit.Vector) - */ - @Override - public BaseBlock getBlock(Vector pos) { - try { - return new BaseBlock(getBlockType(pos), getBlockData(pos)); - } catch (Exception e) { - return null; - } - } - - @Override - public boolean isValidBlockType(int type) { - if (type == 0) { - return true; - } - return world.isValidBlockType(type); - } - - @Override - public int getBlockData(Vector pos) { - return world.getBlockData(getCoordinate(pos)); - } - - @Override - public int getBlockLightLevel(Vector pos) { - return world.getBlockLightLevel(getCoordinate(pos)); - } - - @Override - public int getBlockType(Vector pos) { - return world.getBlockId(getCoordinate(pos)); - } - - @Override - public String getName() { - return world.getName(); - } - - @Override - public int hashCode() { - return world.getName().hashCode(); - } - - @Override - public boolean regenerate(Region arg0, EditSession arg1) { - // TODO Auto-generated method stub - return false; - } - - @Override - public int removeEntities(EntityType entity, Vector pos, int area) { - // TODO Auto-generated method stub - return 0; - } - - @Override - public void setBiome(Vector2D arg0, BiomeType arg1) { - if(arg1 instanceof MinecraftBiomeType) { - int biomeId = ((MinecraftBiomeType) arg1).getBiomeID(); - - int x = arg0.getBlockX(); - int z = arg0.getBlockZ(); - - if(this.world.getMinecraftWorld().blockExists(x, 0, z)) { // blockExists - Chunk chunk = this.world.getMinecraftWorld().getChunkFromBlockCoords(x, z); // Chunk, getChunkFromBlockCoords - if(chunk != null) { - byte[] biomevals = chunk.getBiomeArray(); // getBiomeArray - biomevals[((z & 0xF) << 4 | x & 0xF)] = (byte)biomeId; - // work around for biome data not being updated on client - com.sijobe.spc.wrapper.Minecraft.getMinecraft().thePlayer.worldObj.getChunkFromBlockCoords(x, z).setBiomeArray(biomevals); - } else { - System.err.println("Can't set biome for null chunk."); - } - } else { - System.err.println("Not setting biome."); - } - } - } - - @Override - @Deprecated - public void setBlockData(Vector pos, int block) { - world.setBlockData(getCoordinate(pos), block); - } - - @Override - @Deprecated - public void setBlockDataFast(Vector pos, int block) { - world.setBlockData(getCoordinate(pos), block); - } - - @Override - @Deprecated - public boolean setBlockType(Vector pos, int block) { - return world.setBlock(getCoordinate(pos), block); - } - - @Override - @Deprecated - public boolean generateBigTree(EditSession session, Vector pos) { - return world.generateBigTree(getCoordinate(pos)); - } - - @Override - @Deprecated - public boolean generateTree(EditSession session, Vector pos) { - return world.generateTree(getCoordinate(pos)); - } - - @Override - @Deprecated - public boolean generateTallRedwoodTree(EditSession session, Vector pos) { - return world.generateTallRedwoodTree(getCoordinate(pos)); - } - - @Override - @Deprecated - public boolean generateRedwoodTree(EditSession session, Vector pos) { - return world.generateRedwoodTree(getCoordinate(pos)); - } - - @Override - @Deprecated - public boolean generateBirchTree(EditSession session, Vector pos) { - return world.generateBirchTree(getCoordinate(pos)); - } - - @SuppressWarnings("unchecked") - public int killMobsDo(Vector pos, double radius, boolean withLightning, boolean killAnimals, boolean killNPCs, boolean killPets) { - List entities = this.world.getMinecraftWorld().getEntitiesWithinAABBExcludingEntity(null, - AxisAlignedBB.getBoundingBox(pos.getX() - (double)radius, pos.getY() - (double)radius, pos.getZ() - (double)radius, - pos.getX() + (double)radius, pos.getY() + (double)radius, pos.getZ() + (double)radius)); - int count = 0; - EntityPlayerMP owner; - try { - String firstPlayer = MinecraftServer.getServer().getServerOwner(); - owner = MinecraftServer.getServer().getConfigurationManager().getPlayerForUsername(firstPlayer); - } catch (Exception e) { - owner = null; - e.printStackTrace(); - } - for(Entity entity : entities) { - if(entity instanceof EntityLiving) { - if(entity instanceof EntityPlayer) { - continue; // don't 'kill' players (it causes issues..) - } - if(!killAnimals && entity instanceof EntityAnimal) { - continue; - } - if(!killNPCs && entity instanceof EntityVillager) { - continue; - } - if(!killPets && entity instanceof EntityTameable) { - continue; - } - boolean isPig = entity instanceof EntityPig; - Coordinate entityPos = new Coordinate(entity.posX, entity.posY, entity.posZ); - if(withLightning && !isPig) { - world.useLightning(entityPos); - } - ((EntityLiving)entity).setEntityHealth(0); - if(owner != null) { - owner.destroyedItemsNetCache.add(entity.entityId); - } - count++; - } - } - return count; - } - - @Override - public int killMobs(Vector origin, double radius, int flags) { - boolean killPets = (flags & 0x1) != 0; - boolean killNPCs = (flags & 0x2) != 0; - boolean killAnimals = (flags & 0x4) != 0; - boolean withLightning = (flags & 0x100000) != 0; - return killMobsDo(origin, radius, withLightning, killAnimals, killNPCs, killPets); - } - - /** - * Gets the coordinate object that the specified Vector object represents - * - * @param pos - The position of the coordinate - * @return The matching coordinate object - */ - private Coordinate getCoordinate(Vector pos) { - return new Coordinate(pos.getX(), pos.getY(), pos.getZ()); - } -} diff --git a/src/com/sijobe/spc/worldedit/MinecraftBiomeType.java b/src/com/sijobe/spc/worldedit/MinecraftBiomeType.java deleted file mode 100644 index 1adf6d6..0000000 --- a/src/com/sijobe/spc/worldedit/MinecraftBiomeType.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.sijobe.spc.worldedit; - -import java.lang.reflect.Field; -import java.util.Locale; -import com.sk89q.worldedit.BiomeType; -import net.minecraft.src.BiomeGenBase; - -public enum MinecraftBiomeType implements BiomeType { - - OCEAN(BiomeGenBase.biomeList[0]), - PLAINS(BiomeGenBase.biomeList[1]), - DESERT(BiomeGenBase.biomeList[2]), - EXTREMEHILLS(BiomeGenBase.biomeList[3]), - FOREST(BiomeGenBase.biomeList[4]), - TAIGA(BiomeGenBase.biomeList[5]), - SWAMPLAND(BiomeGenBase.biomeList[6]), - RIVER(BiomeGenBase.biomeList[7]), - HELL(BiomeGenBase.biomeList[8]), - SKY(BiomeGenBase.biomeList[9]), - FROZENOCEAN(BiomeGenBase.biomeList[10]), - FROZENRIVER(BiomeGenBase.biomeList[11]), - ICEPLAINS(BiomeGenBase.biomeList[12]), - ICEMOUNTAINS(BiomeGenBase.biomeList[13]), - MUSHROOMISLAND(BiomeGenBase.biomeList[14]), - MUSHROOMISLANDSHORE(BiomeGenBase.biomeList[15]), - BEACH(BiomeGenBase.biomeList[16]), - DESERTHILLS(BiomeGenBase.biomeList[17]), - FORESTHILLS(BiomeGenBase.biomeList[18]), - TAIGAHILLS(BiomeGenBase.biomeList[19]), - EXTREMEHILLSEDGE(BiomeGenBase.biomeList[20]), - JUNGLE(BiomeGenBase.biomeList[21]), - JUNGLEHILLS(BiomeGenBase.biomeList[22]); - - private BiomeGenBase biome; - - private MinecraftBiomeType(BiomeGenBase biome) { - this.biome = biome; - } - - @Override - public String getName() { - return name().toLowerCase(Locale.ENGLISH); - } - - /* - public BiomeGenBase getSPCBiome() { - return biome; - } - */ - - public int getBiomeID() { - return biome.biomeID; - } - - /* - public String getBiomeName() { - return biome.biomeName; - } - */ - -} diff --git a/src/com/sijobe/spc/worldedit/MinecraftBiomeTypes.java b/src/com/sijobe/spc/worldedit/MinecraftBiomeTypes.java deleted file mode 100644 index 7ff0dd7..0000000 --- a/src/com/sijobe/spc/worldedit/MinecraftBiomeTypes.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.sijobe.spc.worldedit; - -// Obfuscated references: 0 - -import com.sk89q.worldedit.BiomeType; -import com.sk89q.worldedit.BiomeTypes; -import com.sk89q.worldedit.UnknownBiomeTypeException; -import java.util.Arrays; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - -public class MinecraftBiomeTypes implements BiomeTypes { - - @Override - public boolean has(String name) { - try { - MinecraftBiomeType.valueOf(name.toUpperCase(Locale.ENGLISH)); - return true; - } catch (IllegalArgumentException var3) { - return false; - } - } - - @Override - public BiomeType get(String name) throws UnknownBiomeTypeException { - try { - return MinecraftBiomeType.valueOf(name.toUpperCase(Locale.ENGLISH)); - } catch (IllegalArgumentException var3) { - throw new UnknownBiomeTypeException(name); - } - } - - @Override - public List all() { - return Arrays.asList(MinecraftBiomeType.values()); - } -} diff --git a/src/com/sijobe/spc/worldedit/PropertiesConfiguration.java b/src/com/sijobe/spc/worldedit/PropertiesConfiguration.java deleted file mode 100644 index aaa56bf..0000000 --- a/src/com/sijobe/spc/worldedit/PropertiesConfiguration.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.sijobe.spc.worldedit; - -import com.sijobe.spc.core.Constants; - -import java.io.File; - -public class PropertiesConfiguration extends com.sk89q.worldedit.util.PropertiesConfiguration { - - /** - * Initialises the class - */ - public PropertiesConfiguration() { - super(new File(Constants.MOD_DIR,"worldedit.properties")); - } - - /** - * @see com.sk89q.worldedit.LocalConfiguration#getWorkingDirectory() - */ - @Override - public File getWorkingDirectory() { - return Constants.MOD_DIR; - } -} diff --git a/src/com/sijobe/spc/worldedit/ServerInterface.java b/src/com/sijobe/spc/worldedit/ServerInterface.java deleted file mode 100644 index 035718a..0000000 --- a/src/com/sijobe/spc/worldedit/ServerInterface.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.sijobe.spc.worldedit; - -import com.sk89q.worldedit.BiomeTypes; - - -public class ServerInterface extends com.sk89q.worldedit.ServerInterface { - - private BiomeTypes biomes; - - /** - * Initialises the class - */ - public ServerInterface() { - super(); - biomes = new MinecraftBiomeTypes(); - } - - @Override - public BiomeTypes getBiomes() { - // TODO Auto-generated method stub - return biomes; - } - - @Override - public boolean isValidMobType(String arg0) { - // TODO Auto-generated method stub - return true; - } - - @Override - public void reload() { - // TODO Auto-generated method stub - - } - - @Override - public int resolveItem(String arg0) { - // TODO Auto-generated method stub - return 0; - } -} diff --git a/src/com/sijobe/spc/worldedit/WorldEditCommandSet.java b/src/com/sijobe/spc/worldedit/WorldEditCommandSet.java deleted file mode 100644 index 659aa1c..0000000 --- a/src/com/sijobe/spc/worldedit/WorldEditCommandSet.java +++ /dev/null @@ -1,199 +0,0 @@ -package com.sijobe.spc.worldedit; - -import com.sijobe.spc.command.MultipleCommands; -import com.sijobe.spc.core.IHook; -import com.sijobe.spc.util.WorldEditCUIHelper; -import com.sijobe.spc.wrapper.CommandSender; -import com.sijobe.spc.wrapper.Coordinate; -import com.sijobe.spc.wrapper.MinecraftServer; -import com.sijobe.spc.wrapper.Player; - -import java.util.List; - -/** - * The class that provides connection to WorldEdit. - * - * @author simo_415 - * @version 1.2 - */ -public class WorldEditCommandSet extends MultipleCommands { - - /*static { - DynamicClassLoader.addFile(new File(Minecraft.getMinecraftDirectory(),"bin/WorldEdit.jar")); - }*/ - - /** - * The WorldEdit object that the class communicates to WorldEdit with - */ - public static com.sk89q.worldedit.WorldEdit WORLDEDIT; - /** - * The server interface that WorldEdit is using - */ - public static ServerInterface SERVER; - /** - * The configuration that WorldEdit is using - */ - public static PropertiesConfiguration CONFIGURATION; - - /** - * Stores the last instance of this class that was created - */ - private static WorldEditCommandSet INSTANCE; - - /** - * Used to store the last time (in ms) that a left-click was sent - */ - private long leftClick; - /** - * Used to store the last time (in ms) that a right-click was sent - */ - private long rightClick; - - private long leftBlock; - private long rightBlock; - - /** - * Provides a delay between sending mouse updates to WorldEdit - */ - private static final int CLICK_DELAY = 200; - - public WorldEditCommandSet(String name) { - super(name); - - CONFIGURATION = new PropertiesConfiguration(); - CONFIGURATION.load(); - - SERVER = new ServerInterface(); - - WORLDEDIT = new com.sk89q.worldedit.WorldEdit(SERVER, CONFIGURATION); - - leftClick = rightClick = leftBlock = rightBlock = System.currentTimeMillis(); - - INSTANCE = this; - } - - /** - * Gets the currently constructed instance of the class. This allows reuse - * of the same class by multiple implementing classes without having to - * create new instances and deal with that. - * - * @return The current instance of this class - */ - public static WorldEditCommandSet getCurrentInstance() { - return INSTANCE; - } - - @Override - public String[] getCommands() { - return WORLDEDIT.getCommands().keySet().toArray(new String[]{}); - } - - @Override - public String getDescription() { - return WORLDEDIT.getCommands().get(getName()); - } - - @Override - public void execute(CommandSender sender, List params) { - String command[] = null; - if (params.size() == 1) { - String split[] = ((String)params.get(0)).split(" "); - command = new String[split.length + 1]; - for (int i = 1; i < command.length; i++) { - command[i] = split[i - 1]; - } - command[0] = "/" + getName(); - } else { - command = new String[] { "/" + getName() }; - } - handleCommand(getSenderAsPlayer(sender), command); - } - - /** - * Handles a command that is sent to a WorldEdit command - * - * @param player - The player that executed the command - * @param command - The arguments (command) that the player sent - */ - public void handleCommand(Player player, String command[]) { - LocalPlayer localPlayer = getLocalPlayer(player); - WORLDEDIT.handleCommand(localPlayer, command); - } - - private static LocalPlayer getLocalPlayer(Player player) { - LocalPlayer localPlayer = new LocalPlayer(player, SERVER); - if(player.getPlayerName().equals(MinecraftServer.getMinecraftServer().getServerOwner())) { - if(hasCUIHooks()) { - WORLDEDIT.getSession(localPlayer).setCUISupport(true); - WORLDEDIT.getSession(localPlayer).dispatchCUISetup(localPlayer); - } - } - return localPlayer; - } - - private static boolean hasCUIHooks() { - int cuiHooks = 0; - for(IHook hook : WorldEditCUIHelper.getCUIHooks()) { - if(hook.isEnabled()) { - cuiHooks++; - } - } - return (cuiHooks > 0); - } - - /** - * Handles a player arm swing event - * - * @param player - The player the event occurred on - */ - public void handleArmSwing(Player player) { - if (leftClick + CLICK_DELAY < System.currentTimeMillis()) { - LocalPlayer localPlayer = getLocalPlayer(MinecraftServer.getPlayerByUsername(player.getPlayerName())); - WORLDEDIT.handleArmSwing(localPlayer); - leftClick = System.currentTimeMillis(); - } - } - - /** - * Handles a player right-click event - * - * @param player - The player the event occurred on - */ - public void handleRightClick(Player player) { - if (rightClick + CLICK_DELAY < System.currentTimeMillis()) { - LocalPlayer localPlayer = getLocalPlayer(MinecraftServer.getPlayerByUsername(player.getPlayerName())); - WORLDEDIT.handleRightClick(localPlayer); - rightClick = System.currentTimeMillis(); - } - } - - /** - * Handles a player left clicking a block - * - * @param player - The player the event occurred on - * @param block - The block that the player clicked - */ - public void handleBlockLeftClick(Player player, Coordinate block) { - if (leftBlock + CLICK_DELAY < System.currentTimeMillis()) { - LocalPlayer localPlayer = getLocalPlayer(MinecraftServer.getPlayerByUsername(player.getPlayerName())); - com.sk89q.worldedit.WorldVector vector = new com.sk89q.worldedit.WorldVector(localPlayer.getWorld(), block.getBlockX(), block.getBlockY(), block.getBlockZ()); - WORLDEDIT.handleBlockLeftClick(localPlayer, vector); - leftBlock = System.currentTimeMillis(); - } - } - - /** - * Handles a player right clicking a block - * - * @param player - The player the event occurred on - * @param block - The block that the player clicked - */ - public void handleBlockRightClick(Player player, Coordinate block) { - if (rightBlock + CLICK_DELAY < System.currentTimeMillis()) { - LocalPlayer localPlayer = getLocalPlayer(MinecraftServer.getPlayerByUsername(player.getPlayerName())); - com.sk89q.worldedit.WorldVector vector = new com.sk89q.worldedit.WorldVector(localPlayer.getWorld(), block.getBlockX(), block.getBlockY(), block.getBlockZ()); - WORLDEDIT.handleBlockRightClick(localPlayer, vector); - rightBlock = System.currentTimeMillis(); - } - } -} diff --git a/src/com/sijobe/spc/worldedit/WorldEditEvents.java b/src/com/sijobe/spc/worldedit/WorldEditEvents.java deleted file mode 100644 index aa53540..0000000 --- a/src/com/sijobe/spc/worldedit/WorldEditEvents.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.sijobe.spc.worldedit; - -import com.sijobe.spc.core.PlayerSP; -import com.sijobe.spc.wrapper.Coordinate; -import com.sijobe.spc.wrapper.Minecraft; -import com.sijobe.spc.wrapper.Player; - -import java.util.HashMap; -import java.util.Map; - -import org.lwjgl.input.Mouse; - -/** - * Handles the client-side events that occur such as mouse events for - * WorldEdit. When the events are detected they are passed to the - * WorldEditCommandSet class. - * - * @author simo_415 - * @version 1.0 - */ -public class WorldEditEvents extends PlayerSP { - - private Map left; - private Map right; - private String lastCrash = ""; - private static boolean handleEvents = true; - - /** - * The max range that the mouse methods trace the blocks for - */ - private static final int TRACE_RANGE = 128; - - public WorldEditEvents() { - left = new HashMap(); - right = new HashMap(); - } - - /* - * Disable WorldEdit event handling. This is done when WorldEdit - * hasn't been loaded, so that possible exceptions are avoided. - */ - public static void disableHandleEvents() { - handleEvents = false; - } - - /** - * Returns whether or not WorldEdit event handling is enabled - * - * @return True if WE event handling enabled, false otherwise - */ - public static boolean getHandleEvents() { - return handleEvents; - } - - @Override - public void onTick(Player player) { - if (Minecraft.isGuiScreenOpen()) { - return; - } - if(!handleEvents) { - return; - } - try { - // Check left button down - checkLeftButton(player); - - // Check right button down - checkRightButton(player); - } catch (Throwable t) { - String currentCrash = t.toString(); - if(currentCrash.equals(lastCrash)) { - return; - } else { - lastCrash = currentCrash; - } - t.printStackTrace(); - } - } - - /** - * Checks if the left mouse button was pressed, if so then it will call the - * appropriate WorldEdit method for arm swinging or block hitting if they - * occur. - * - * @param player - The player that triggered the mouse button - */ - private void checkLeftButton(Player player) { - if (Mouse.isButtonDown(0)) { - Coordinate hit = null; - if ((hit = player.trace(TRACE_RANGE)) != null) { - WorldEditCommandSet.getCurrentInstance().handleArmSwing(player); - if (!hit.equals(left.get(player.getPlayerName()))) { - left.put(player.getPlayerName(), hit); - WorldEditCommandSet.getCurrentInstance().handleBlockLeftClick(player, hit); - } - } - } - } - - /** - * Checks if the right mouse button was pressed, if so then it will call the - * appropriate WorldEdit method for arm swinging or block hitting if they - * occur. - * - * @param player - The player that triggered the mouse button - */ - private void checkRightButton(Player player) { - if (Mouse.isButtonDown(1)) { - Coordinate hit = null; - if ((hit = player.trace(TRACE_RANGE)) != null) { - WorldEditCommandSet.getCurrentInstance().handleRightClick(player); - if (!hit.equals(right.get(player.getPlayerName()))) { - right.put(player.getPlayerName(), hit); - WorldEditCommandSet.getCurrentInstance().handleBlockRightClick(player, hit); - } - } - } - } -} diff --git a/src/main/java/com/sijobe/spc/ModSpc.java b/src/main/java/com/sijobe/spc/ModSpc.java new file mode 100644 index 0000000..c28d35f --- /dev/null +++ b/src/main/java/com/sijobe/spc/ModSpc.java @@ -0,0 +1,202 @@ +package com.sijobe.spc; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.player.PlayerEvent.BreakSpeed; +import net.minecraftforge.event.world.BlockEvent.BreakEvent; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.Mod; +import cpw.mods.fml.common.Mod.EventHandler; +import cpw.mods.fml.common.Mod.Instance; +import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLServerStartingEvent; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.TickEvent.Phase; +import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent; +import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; +import cpw.mods.fml.relauncher.Side; + +import com.sijobe.spc.core.HookManager; +import com.sijobe.spc.core.IBlockBroken; +import com.sijobe.spc.core.IBreakSpeed; +import com.sijobe.spc.wrapper.Block; +import com.sijobe.spc.wrapper.Item; +import com.sijobe.spc.wrapper.Player; +import com.sijobe.spc.wrapper.World; +import com.sijobe.spc.core.IPlayerMP; +import com.sijobe.spc.core.ICUIEventHandler; +import com.sijobe.spc.hooks.InitialiseCommands; +import com.sijobe.spc.network.ConfigMessageHandler; +import com.sijobe.spc.network.IClientConfig; +import com.sijobe.spc.network.PacketConfig; +import com.sijobe.spc.proxy.Proxy; + +/** + * the main mod class + * + * @author aucguy + * @version 1.0 + */ +@Mod( + useMetadata = true, + modid = "spc", + version = "5.0") +public class ModSpc { + /** + * the spc mod instance + */ + @Instance + public static ModSpc instance; + + /** + * the hook manager. Used for hooking things + */ + protected HookManager hookManager; + + /** + * the initialize commands instance. Used for initializing commands when the + * server is launched + */ + protected InitialiseCommands commands; + + /** + * the network handler instance. Used to set client sided settings (like + * light levels for the light command) + */ + public SimpleNetworkWrapper networkHandler; + + /** + * the side this mod is running on + */ + public Side side; + + /** + * the proxy instance. Used since sometimes it is neccessary to access the + * Minecraft instance. However, this is client-sided. Even though it may not + * be used on the server, loading any class that uses references the + * Minecraft instance will load net.minecraft.client.Minecraft. If this + * happens on the server, the server will crash. + */ + public Proxy proxy; + + /** + * construct me a mod! + */ + public ModSpc() { + this.hookManager = new HookManager(); + this.commands = new InitialiseCommands(); + } + + /** + * used to initialize everything + * + * @param event - the initialization event + * @throws InstantiationException - because of reflection + * @throws IllegalAccessException - because of reflection + * @throws ClassNotFoundException - because of reflection + */ + @EventHandler + public void init(FMLInitializationEvent event) throws InstantiationException, IllegalAccessException, ClassNotFoundException { + this.side = event.getSide(); + if (this.side == Side.CLIENT) { + // if reflection wasn't used then when this class was loaded the + // ClientProxy class would be loaded + // and since ClientProxy referrs to net.minecraft.client.Minecraft, + // that would be loaded + // loading net.minecraft.client.Minecraft on a server crashes it. + this.proxy = (Proxy) Class.forName("com.sijobe.spc.proxy.client.ClientProxy").newInstance(); + } else { + // using reflection to prevent client classes loading server side + this.proxy = (Proxy) Class.forName("com.sijobe.spc.proxy.server.ServerProxy").newInstance(); + } + + Block.init(); + Item.init(); + this.hookManager.loadHooks(IPlayerMP.class); + this.hookManager.loadHooks(ICUIEventHandler.class); + this.hookManager.loadHooks(IBreakSpeed.class); + this.hookManager.loadHooks(IBlockBroken.class); + this.hookManager.loadHooks(IClientConfig.class); + MinecraftForge.EVENT_BUS.register(this); + FMLCommonHandler.instance().bus().register(this); + this.networkHandler = new SimpleNetworkWrapper("spc.network"); + this.networkHandler.registerMessage(ConfigMessageHandler.class, PacketConfig.class, 0, Side.CLIENT); + this.loadClientSettingHooks(); + } + + /** + * initialize the spc commands + * + * @param event - the ServerStarting event + */ + @EventHandler + public void onServerStarting(FMLServerStartingEvent event) { + System.out.println("loading spc commands..."); + this.commands.loadCommands(); + } + + // TODO make void handleHook() + /** + * callss all of the player tick hooks + * + * @param event - the PlayerTick event + */ + @SubscribeEvent + public void onPlayerTick(PlayerTickEvent event) { + if (event.phase == Phase.START && event.side == Side.SERVER) { + if (event.player instanceof EntityPlayerMP) { + Player player = new Player((EntityPlayer) event.player); + for (IPlayerMP hook : this.hookManager.getHooks(IPlayerMP.class)) { + if (hook.isEnabled()) { + hook.onTick(player); + } + } + } + } + } + + /** + * calls of of the break speed hooks. Used to modify the time it takes to + * break something + * + * @param event - the breakSpeed event + */ + @SubscribeEvent + public void onBreakSpeed(BreakSpeed event) { + for (IBreakSpeed hook : this.hookManager.getHooks(IBreakSpeed.class)) { + if (hook.isEnabled()) { + // TODO pass same player instance instead of creating a new one each + // time + event.newSpeed = hook + .getBreakSpeed(new Player(event.entityPlayer), Block.fromMinecraftBlock(event.block), event.metadata, event.originalSpeed, event.x, event.y, event.z); + } + } + } + + /** + * calls of the the block broken hooks + * + * @param event - the break event + */ + @SubscribeEvent + public void onBlockBreak(BreakEvent event) { + for (IBlockBroken hook : this.hookManager.getHooks(IBlockBroken.class)) { + if (hook.isEnabled()) { + hook.onBreakBroken(event.x, event.y, event.z, new World(event.world), Block.fromMinecraftBlock(event.block), event.blockMetadata, new Player( + event.getPlayer())); + } + } + } + + /** + * loads all the client configuration hooks + */ + public void loadClientSettingHooks() { + for (IClientConfig hook : this.hookManager.getHooks(IClientConfig.class)) { + if (hook.isEnabled()) { + hook.getConfig().setHandler((IClientConfig) hook); + } + } + } +} diff --git a/src/main/java/com/sijobe/spc/asm/ClassTransformer.java b/src/main/java/com/sijobe/spc/asm/ClassTransformer.java new file mode 100644 index 0000000..0c31be5 --- /dev/null +++ b/src/main/java/com/sijobe/spc/asm/ClassTransformer.java @@ -0,0 +1,98 @@ +package com.sijobe.spc.asm; + +import java.util.Map; +import java.util.HashMap; + +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; + +/** + * used to transform a class + * + * @author aucguy + * @version 1.0 + */ +class ClassTransformer extends ClassVisitor { + /** + * the binary name of the class this transformer modifies + */ + protected String name; + + /** + * binds method ids to methodTransformerss + */ + protected Map methodTransformers; + + /** + * creates a ClassTransformer + * + * @param name - the binary name of the class this transformer modifies + */ + ClassTransformer(String name) { + super(Opcodes.ASM4, new ClassWriter(Opcodes.ASM4)); + this.name = name; + this.methodTransformers = new HashMap(); + } + + /** + * @return the binary name of the class this transformer modifies + */ + String getApplicableClass() { + return this.name; + } + + /** + * used to modify classes + * + * @return this instance's ClassWriter + */ + ClassWriter getWriter() { + return (ClassWriter) this.cv; + } + + @Override + public MethodVisitor visitMethod(int access, String name, String desc, + String signature, String[] exceptions) { + MethodVisitor writer = super + .visitMethod(access, name, desc, signature, exceptions); + String id = this.getApplicableClass() + ":" + name + ":" + desc; + + if (this.methodTransformers.containsKey(id)) { + MethodTransformer transformer = this.methodTransformers.get(id); + transformer.injectMethodWriter(writer); + return transformer.new Wrapper(transformer); + } else { + return writer; + } + } + + /** + * registers the given method transformer for the with this instance + * + * @param mt - the methodTransformer to register + * @throws IllegalArgumentExceptions - if the tranformer doesn't modify the a method of this instance's class + */ + void registerMethodTransformer(MethodTransformer mt) throws IllegalArgumentException { + String name = mt.getApplicableMethod(); + String clazz = name.split(":", 2)[0]; + if (!clazz.equals(this.getApplicableClass())) { + throw (new IllegalArgumentException( + "MethodTransformer not of correct class")); + } + this.methodTransformers.put(mt.getApplicableMethod(), mt); + } + + /** + * registers multiple methodTransformers + * + * @param mt - the MethodTransformers to register + * @throws IllegalArgumentException - if the tranformer doesn't modify the a method of this instance's class + */ + void regsiterMethodTransformers(MethodTransformer[] mt) throws IllegalArgumentException { + for (MethodTransformer i : mt) { + this.registerMethodTransformer(i); + } + } +} diff --git a/src/main/java/com/sijobe/spc/asm/EntityReacherClient.java b/src/main/java/com/sijobe/spc/asm/EntityReacherClient.java new file mode 100644 index 0000000..9511f0d --- /dev/null +++ b/src/main/java/com/sijobe/spc/asm/EntityReacherClient.java @@ -0,0 +1,66 @@ +package com.sijobe.spc.asm; + +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; + +/** + * makes the client allow customized reach distance for entities effectively + * removes the code: + * + * if (this.mc.playerController.extendedReach()) { d0 = 6.0D; d1 = 6.0D; } else + * { if (d0 > 3.0D) { d1 = 3.0D; } + * + * d0 = d1; } + * + * @author aucguy + * @version 1.0 + */ +public class EntityReacherClient extends MethodTransformer { + State state; + MethodVisitor writer; + + EntityReacherClient() { + super("net.minecraft.client.renderer.EntityRenderer:getMouseOver:(F)V"); + } + + @Override + void injectMethodWriter(MethodVisitor mv) { + this.mv = mv; + this.writer = mv; + } + + @Override + public void visitCode() { + this.state = State.PRE_CHANGE; + } + + @Override + public void visitMethodInsn(int opcode, String owner, String name, String desc) { + if (this.state == State.PRE_CHANGE && opcode == Opcodes.INVOKEVIRTUAL + && owner.equals("net/minecraft/client/multiplayer/PlayerControllerMP") && name.equals("extendedReach") + && desc.equals("()Z")) { + this.state = State.AFTER_EXTEND; + this.mv = null; + this.writer.visitInsn(Opcodes.POP); + } else { + super.visitMethodInsn(opcode, owner, name, desc); + } + } + + @Override + public void visitVarInsn(int opcode, int var) { + if (this.state == State.AFTER_EXTEND && var == 0) { + this.state = State.POST_CHANGE; + this.mv = this.writer; + super.visitVarInsn(opcode, var); + } else { + super.visitVarInsn(opcode, var); + } + } + + enum State { + PRE_CHANGE, // before extendedReach() is called + AFTER_EXTEND, // after extendedReach() is called + POST_CHANGE; // after all the changes + } +} diff --git a/src/main/java/com/sijobe/spc/asm/EntityReacherServer.java b/src/main/java/com/sijobe/spc/asm/EntityReacherServer.java new file mode 100644 index 0000000..2523af1 --- /dev/null +++ b/src/main/java/com/sijobe/spc/asm/EntityReacherServer.java @@ -0,0 +1,42 @@ +package com.sijobe.spc.asm; + +import net.minecraft.network.NetHandlerPlayServer; + +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; + +/** + * makes the server allow customized reach distance for entities effectively + * changes the line in NetHandlerPlayServer.processUseEntity double d0 = 36.0 to + * double d0 = ReachChanger.getEntityReachDistance(this); + * + * @author aucguy + * @version 1.0 + * + */ +public class EntityReacherServer extends MethodTransformer { + + EntityReacherServer() { + super("net.minecraft.network.NetHandlerPlayServer:processUseEntity:(Lnet/minecraft/network/play/client/C02PacketUseEntity;)V"); + } + + @Override + void injectMethodWriter(MethodVisitor mv) { + this.mv = mv; + } + + @Override + public void visitLdcInsn(Object cst) { + if(cst.equals(36.0D)) { + super.visitVarInsn(Opcodes.ALOAD, 0); + super.visitMethodInsn(Opcodes.INVOKESTATIC, "com/sijobe/spc/asm/EntityReacherServer", "getEntityReachDistance", "(Lnet/minecraft/network/NetHandlerPlayServer;)D"); + } + else{ + super.visitLdcInsn(cst); + } + } + + public static double getEntityReachDistance(NetHandlerPlayServer handler) { + return Math.pow(handler.playerEntity.theItemInWorldManager.getBlockReachDistance(), 2); + } +} diff --git a/src/main/java/com/sijobe/spc/asm/MethodHooker.java b/src/main/java/com/sijobe/spc/asm/MethodHooker.java new file mode 100644 index 0000000..448b303 --- /dev/null +++ b/src/main/java/com/sijobe/spc/asm/MethodHooker.java @@ -0,0 +1,56 @@ +package com.sijobe.spc.asm; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; + +import org.objectweb.asm.MethodVisitor; +/** + * base class for simple method transformers based on methods like in SimpleHooked + * @author aucguy + * @version 1.0 + */ +abstract class MethodHooker extends MethodTransformer { + /** + * the method that will call the necessary 'visit' methods of the methodWriter instead of or before the vanilla method. + */ + protected Method method; + + /** + * constructs a MethodHooker + * @param id - the id of the method to modify + * @param method - the method that will call the necessary 'visit' methods + * @throws IllegalArgumentException - the method is not static + */ + MethodHooker(String id, Method method) throws IllegalArgumentException { + super(id); + if (!Modifier.isStatic(method.getModifiers())) { + throw (new IllegalArgumentException( + "MethodTransformer not of correct class")); + } + this.method = method; + } + + /** + * returns this instance's methodWriter + * + * @return + */ + protected abstract MethodVisitor getWriter(); + + @Override + public void visitCode() { + try { + this.method.invoke(null, this.getWriter()); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/sijobe/spc/asm/MethodPrefixer.java b/src/main/java/com/sijobe/spc/asm/MethodPrefixer.java new file mode 100644 index 0000000..c9054a8 --- /dev/null +++ b/src/main/java/com/sijobe/spc/asm/MethodPrefixer.java @@ -0,0 +1,50 @@ +package com.sijobe.spc.asm; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.reflect.Method; + +import org.objectweb.asm.MethodVisitor; + +/** + * used to prefix vanilla methods with custom code + * + * @author aucguy + * @version 1.0 + */ +class MethodPrefixer extends MethodHooker { + /** + * constructs a MethodPrefixer + * + * @param id - the id of the vanilla method + * @param method - the method that calls the necessary 'visit' methods + * @throws IllegalArgumentException - if the method is not static + */ + MethodPrefixer(String id, Method method) throws IllegalArgumentException { + super(id, method); + } + + /** + * used to signify that a method is supposed to be used with a MethodPrefixer + */ + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + @interface Hook { + /** + * the id of the vanilla method + */ + String value(); + } + + @Override + void injectMethodWriter(MethodVisitor mv) { + this.mv = mv; + } + + @Override + protected MethodVisitor getWriter() { + return this.mv; + } +} diff --git a/src/main/java/com/sijobe/spc/asm/MethodReplacer.java b/src/main/java/com/sijobe/spc/asm/MethodReplacer.java new file mode 100644 index 0000000..25ab08d --- /dev/null +++ b/src/main/java/com/sijobe/spc/asm/MethodReplacer.java @@ -0,0 +1,48 @@ +package com.sijobe.spc.asm; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.reflect.Method; + +import org.objectweb.asm.MethodVisitor; + +/** + * used to replace vanilla methods + * + * @author aucguy + * @version 1.0 + */ +class MethodReplacer extends MethodHooker { + /** + * the MethodWriter instance. the normal 'mv' field is't used because if it were 'visit' methods would get called on it + */ + protected MethodVisitor writer; + + MethodReplacer(String id, Method method) throws IllegalArgumentException { + super(id, method); + } + + /** + * used to signify that a method is supposed to be used with a MethodReplacer + */ + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + @interface Hook { + /** + * the id of the vanilla method + */ + String value(); + } + + @Override + void injectMethodWriter(MethodVisitor mv) { + this.writer = mv; + } + + @Override + protected MethodVisitor getWriter() { + return this.writer; + } +} diff --git a/src/main/java/com/sijobe/spc/asm/MethodTransformer.java b/src/main/java/com/sijobe/spc/asm/MethodTransformer.java new file mode 100644 index 0000000..f174acb --- /dev/null +++ b/src/main/java/com/sijobe/spc/asm/MethodTransformer.java @@ -0,0 +1,156 @@ +package com.sijobe.spc.asm; + +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; + +/** + * used to transform methods + * + * @author aucguy + * @version 1.0 + */ +abstract class MethodTransformer extends MethodVisitor { + /** + * allows for deobfuscated names to go through the visit methods + */ + final class Wrapper extends MethodVisitor { + Wrapper(MethodVisitor mv) { + super(Opcodes.ASM4, mv); + } + + @Override + public void visitMethodInsn(int opcode, String owner, String name, String desc) { + String[] parts = convertMethod(owner.replace('/', '.'), name.replace('/', '.'), desc.replace('/', '.'), Processor + .getInstance().reversedMappings); + super.visitMethodInsn(opcode, parts[0].replace('.', '/'), parts[1].replace('.', '/'), parts[2] + .replace('.', '/')); + } + } + + /** + * the method id of this transformer a method id is in the format + * 'class:method:descriptor' + */ + String id; + + /** + * constructs a MethodTransformer + * + * @param id - the id for this instance + */ + MethodTransformer(String id) { + super(Opcodes.ASM4); + String[] parts = id.split(":"); + String[] changed = convertMethod(parts[0], parts[1], parts[2]); + this.id = changed[0] + ":" + changed[1] + ":" + changed[2]; + System.out.println("id changed from "+id+" to "+this.id); + } + + protected String[] convertMethod(String oldOwner, String oldName, String oldDesc) { + return convertMethod(oldOwner, oldName, oldDesc, Processor.getInstance().mappings); + } + + /** + * converts the given development-named method to the obfuscated method if + * necessary. + * + * @param oldOwner - the deobfuscated name of the class with the given method + * @param oldName - the deobfuscated name of the method + * @param oldDesc - the deobfuscated method descriptor + * @param slashes - whether or not the names contain slashes + */ + protected static String[] convertMethod(String oldOwner, String oldName, String oldDesc, Map mappings) { + if (Processor.getInstance().obfuscated) { + String newOwner = mappings.get(oldOwner); + String[] parts = mappings.get(oldOwner + "." + oldName).split("\\."); + String newName = parts[parts.length-1]; + + String[] partsDesc = oldDesc.split("\\)"); + String oldArgs = partsDesc[0].replace("(", ""); + String oldReturn = partsDesc[1]; + + String newArgs = ""; + for (int i = 0; i < oldArgs.length(); i++) { + if (oldArgs.charAt(i) == 'L') { + i++; + String arg = ""; + for (; oldArgs.charAt(i) != ';'; i++) { + arg += oldArgs.charAt(i); + } + newArgs += "L" + mappings.get(arg) + ";"; + } else { + newArgs += oldArgs.charAt(i); + } + } + + String newReturn; + if (oldReturn.startsWith("L")) { + newReturn = "L" + mappings.get(oldReturn.substring(1, oldReturn.length() - 1)) + ";"; + } else { + newReturn = oldReturn; + } + + String[] newId = new String[] { newOwner, newName, "(" + newArgs + ")" + newReturn }; + return newId; + } else { + return new String[] { oldOwner, oldName, oldDesc }; + } + } + + /** + * gives this MethodTrasnformer the method writer instance + * + * @param mv - the MethodWriter created for this instance. Made just before + * this instance will visit things + */ + abstract void injectMethodWriter(MethodVisitor mv); + + /** + * gets teh applicable method + * + * @return the id of the method that this transformer modifies + */ + String getApplicableMethod() { + return this.id; + } + + @Override + public void visitMethodInsn(int opcode, String owner, String name, String desc) { + String[] parts = convertMethod(owner.replace('/', '.'), name.replace('/', '.'), desc.replace('/', '.')); + super.visitMethodInsn(opcode, parts[0].replace('.', '/'), parts[1].replace('.', '/'), parts[2].replace('.', '/')); + } + + /** + * generates an array of MethodTransformers from a class of annotations. This + * allows for easy use of ASM modifications See com.sijobe.asm.SimpleHooked + * for an example. + * + * @param clazz - the class containing the modification methods. + * @return an array of MethodTransformers that were generated + */ + static MethodTransformer[] generateFromFunctions(Class clazz) { + List modifiers = new LinkedList(); + for (Method method : clazz.getDeclaredMethods()) { + if (Modifier.isStatic(method.getModifiers())) { + if (method.isAnnotationPresent(MethodReplacer.Hook.class)) { + String annotation = method.getAnnotation(MethodReplacer.Hook.class).value(); + System.out.println("found replacement for " + annotation); + modifiers.add(new MethodReplacer(annotation, method)); + } else if (method.isAnnotationPresent(MethodPrefixer.Hook.class)) { + String annotation = method.getAnnotation(MethodPrefixer.Hook.class).value(); + System.out.println("found prefix for " + annotation); + modifiers.add(new MethodPrefixer(annotation, method)); + } + } + } + + MethodTransformer[] r = new MethodTransformer[modifiers.size()]; + return modifiers.toArray(r); + } +} diff --git a/src/main/java/com/sijobe/spc/asm/ObfuscationData.java b/src/main/java/com/sijobe/spc/asm/ObfuscationData.java new file mode 100644 index 0000000..23fdb8a --- /dev/null +++ b/src/main/java/com/sijobe/spc/asm/ObfuscationData.java @@ -0,0 +1,89 @@ +package com.sijobe.spc.asm; + +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map.Entry; + +/** + * stores obfuscation mappings + * + * @author aucguy + * @version 1.0 + */ +class ObfuscationData extends HashMap { + private static final long serialVersionUID = 8501973207922800333L; + /** + * whether or not to warn about having no obfuscated mapping + */ + boolean shouldWarn = false; + + @Override + public String get(Object key) { + String str = ((String) key).replace('/', '.'); + if (this.containsKey(str)) { + return super.get(str); + } else { + if (shouldWarn && str.startsWith("net.minecraft.")) { + System.err.println("no obfuscated mapped for " + str); + } + return str; + } + } + + /** + * @param key - the key + * @param converted - if true, all '.' are replaced with '/' + * @return + */ + public String get(Object key, boolean converted) { + String value = this.get(key); + if(converted) { + value = value.replace('.', '/'); + } + return value; + } + + /** + * returns the value to key map of this + */ + + public ObfuscationData reverse() { + ObfuscationData map = new ObfuscationData(); + for(Entry entry : this.entrySet()) { + map.put(entry.getValue(), entry.getKey()); + } + return map; + } + + /** + * loads the obfuscated name mappings + */ + protected void loadMappings() { + try { + InputStream file = this.getClass().getResourceAsStream("renames.txt"); + if(file == null) { + throw(new IOException()); + } + byte[] data = new byte[file.available()]; + file.read(data); + String[] lines = new String(data).replace("\r", "\n").split("\n"); + for(String line : lines) { + if(line.length() == 0) { + continue; // blank line + } + line = line.split("#", 2)[0]; + String[] parts = line.split(" "); + if(parts.length != 2) { + continue; //invalid syntax + } + String deobfuscated = parts[0]; + String obfuscated = parts[1]; + this.put(deobfuscated, obfuscated); + } + } catch (IOException error) { + System.err.println("couldn't read obfuscation mappings"); + error.printStackTrace(); + } + } +} diff --git a/src/main/java/com/sijobe/spc/asm/Processor.java b/src/main/java/com/sijobe/spc/asm/Processor.java new file mode 100644 index 0000000..b030ca4 --- /dev/null +++ b/src/main/java/com/sijobe/spc/asm/Processor.java @@ -0,0 +1,115 @@ +package com.sijobe.spc.asm; + +import java.util.Map; +import java.util.HashMap; + +import org.objectweb.asm.ClassReader; + +/** + * Give it some bytecode and it will modify that class with the previously given + * transformers + * + * @author aucguy + * @version 1.0 + */ +class Processor { + /** + * the instance + */ + private static Processor instance = new Processor(); + + /** + * how to get the processor instance + * + * @return the Processor instance + */ + static Processor getInstance() { + return instance; + } + + /** + * obfuscated name storage + */ + public ObfuscationData mappings; + public ObfuscationData reversedMappings; + + /** + * maps class binary names to classTransformers + */ + protected Map classTransformers; + + /** + * whether or not the class files are obfuscated + */ + public boolean obfuscated; + + /** + * makes a Processor + */ + Processor() { + this.classTransformers = new HashMap(); + this.mappings = new ObfuscationData(); + this.mappings.loadMappings(); + this.reversedMappings = this.mappings.reverse(); + } + + /** + * modifies the given bytecode with previously given Transformers + * + * @param name - the binary name of the class + * @param data - the class's bytecode + * @return the modified bytecode + */ + byte[] process(String name, byte[] data) { + if (this.classTransformers.containsKey(name)) { + ClassTransformer transformer = this.classTransformers.get(name); + this.classTransformers.remove(name); + ClassReader reader = new ClassReader(data); + try { + reader.accept(transformer, 0); + } catch (RuntimeException error) { + error.printStackTrace(); + throw(error); + } + return transformer.getWriter().toByteArray(); + } else { + return data; + } + } + + /** + * registers a classTransformer with this Processor + * + * @param ct - the classTransformer to register + */ + void registerClassTransformer(ClassTransformer ct) { + this.classTransformers.put(ct.getApplicableClass(), ct); + } + + /** + * registers the given method transformer with whatever classTransformer it + * goes with + * + * @param mt - the methodTransformer to register + */ + void registerMethodTransformer(MethodTransformer mt) { + String id = mt.getApplicableMethod(); + System.out.println("registering method transformer " + id); + String clazz = id.split(":", 2)[0]; + if (!this.classTransformers.containsKey(clazz)) { + this.classTransformers.put(clazz, new ClassTransformer(clazz)); + } + this.classTransformers.get(clazz).registerMethodTransformer(mt); + } + + /** + * registers multiple method transformers + * + * @param mt - the methodTransformers to register + */ + void registerMethodTransformers(MethodTransformer[] mt) { + for (MethodTransformer i : mt) { + this.registerMethodTransformer(i); + } + } +} diff --git a/src/main/java/com/sijobe/spc/asm/SimpleHooked.java b/src/main/java/com/sijobe/spc/asm/SimpleHooked.java new file mode 100644 index 0000000..052eab1 --- /dev/null +++ b/src/main/java/com/sijobe/spc/asm/SimpleHooked.java @@ -0,0 +1,51 @@ +package com.sijobe.spc.asm; + +import org.objectweb.asm.Label; +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; + +/** + * simple ASM hooks that either replace or prefix methos + * + * @author aucguy + * @version 1.0 + */ +public class SimpleHooked { + /** + * Allows spc to have control over client-sided block reach + * effectively makes the method this: + * return com.sijobe.spc.command.BlockReach.reachDistance; + * + * @param mv - the MethodWriter instance + */ + @MethodReplacer.Hook("net.minecraft.client.multiplayer.PlayerControllerMP:getBlockReachDistance:()F") + public static void getBlockReachDistance(MethodVisitor mv) { + mv.visitCode(); + mv.visitFieldInsn(Opcodes.GETSTATIC, "com/sijobe/spc/command/BlockReach", "reachDistance", "F"); + mv.visitInsn(Opcodes.FRETURN); + mv.visitMaxs(1, 1); + mv.visitEnd(); + } + + /** + * Allows spc to have control over whether or not the inside of blocks are rendered + * effectivly prefixes the method with this + * if(com.sijobe.spc.ModSpc.instance.proxy.shouldNotRenderInsideOfBlock()) { + * return; + * } + * + * @param mv - the MethodWriter + */ + @MethodPrefixer.Hook("net.minecraft.client.renderer.ItemRenderer:renderInsideOfBlock:(FLnet/minecraft/util/IIcon;)V") + public static void renderInsideOfBlock(MethodVisitor mv) { + mv.visitCode(); + mv.visitFieldInsn(Opcodes.GETSTATIC, "com/sijobe/spc/ModSpc", "instance", "Lcom/sijobe/spc/ModSpc;"); + mv.visitFieldInsn(Opcodes.GETFIELD, "com/sijobe/spc/ModSpc", "proxy", "Lcom/sijobe/spc/proxy/Proxy;"); + mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/sijobe/spc/proxy/Proxy", "shouldNotRenderInsideOfBlock", "()Z"); + Label l0 = new Label(); + mv.visitJumpInsn(Opcodes.IFEQ, l0); + mv.visitInsn(Opcodes.RETURN); + mv.visitLabel(l0); + mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); + } +} diff --git a/src/main/java/com/sijobe/spc/asm/SlashPrefixer.java b/src/main/java/com/sijobe/spc/asm/SlashPrefixer.java new file mode 100644 index 0000000..966ff6e --- /dev/null +++ b/src/main/java/com/sijobe/spc/asm/SlashPrefixer.java @@ -0,0 +1,60 @@ +package com.sijobe.spc.asm; + +import net.minecraft.network.NetHandlerPlayServer; + +import org.objectweb.asm.MethodVisitor; + +import com.sijobe.spc.command.PrefixSlash; +import org.objectweb.asm.Opcodes; + +/** + * prefixes slashes onto commands if the player has it enabled + * effectivly replaces + * if(s.startsWith("/")) { + * this.handleSlashCommand(s); + * } + * to: + * if(com.sijobe.spc.asm.SlashPrefixer.isCommand(this, s)) { + * this.handleSlashCommand(s); + * } + * + * @author aucguy + * @version 1.0 + */ +public class SlashPrefixer extends MethodTransformer { + + SlashPrefixer() { + super("net.minecraft.network.NetHandlerPlayServer:processChatMessage:(Lnet/minecraft/network/play/client/C01PacketChatMessage;)V"); + } + + @Override + void injectMethodWriter(MethodVisitor mv) { + this.mv = mv; + } + + @Override + public void visitLdcInsn(Object cst) { + if (!cst.equals("/")) { + super.visitLdcInsn(cst); + } + } + + @Override + public void visitMethodInsn(int opcode, String owner, String name, String desc) { + if (opcode == Opcodes.INVOKEVIRTUAL && owner.equals("java/lang/String") && name.equals("startsWith") && desc.equals("(Ljava/lang/String;)Z")) { + super.visitVarInsn(Opcodes.ALOAD, 0); + super.visitMethodInsn(Opcodes.INVOKESTATIC, "com/sijobe/spc/asm/SlashPrefixer", "isCommand", "(Ljava/lang/String;Lnet/minecraft/network/NetHandlerPlayServer;)Z"); + } else { + super.visitMethodInsn(opcode, owner, name, desc); + } + } + + /** + * @param s - the chat that was sent + * @param handler - the netHandler instance for that player + * @return - whether of not the chat should be treated as a command + */ + public static boolean isCommand(String s, NetHandlerPlayServer handler) { + return s.startsWith("/") || PrefixSlash.playersUsing.contains(handler.playerEntity.getCommandSenderName()); + } +} diff --git a/src/main/java/com/sijobe/spc/asm/SpcCoreMod.java b/src/main/java/com/sijobe/spc/asm/SpcCoreMod.java new file mode 100644 index 0000000..4e8c129 --- /dev/null +++ b/src/main/java/com/sijobe/spc/asm/SpcCoreMod.java @@ -0,0 +1,48 @@ +package com.sijobe.spc.asm; + +import java.util.Map; + +import cpw.mods.fml.relauncher.IFMLLoadingPlugin; +import cpw.mods.fml.relauncher.IFMLLoadingPlugin.MCVersion; +import cpw.mods.fml.relauncher.IFMLLoadingPlugin.Name; +import cpw.mods.fml.relauncher.IFMLLoadingPlugin.TransformerExclusions; +import cpw.mods.fml.relauncher.IFMLLoadingPlugin.SortingIndex; + +/** + * the spc coremod class + * @author aucguy + * @version 1.0 + */ +@MCVersion("1.7.2") +@Name("spc Coremod") +@TransformerExclusions("com.sijobe.spc.asm") +@SortingIndex() //ensure notch names +public class SpcCoreMod implements IFMLLoadingPlugin { + @Override + public String[] getASMTransformerClass() { + return new String[] { Transformer.class.getName() }; + } + + @Override + public String getModContainerClass() { + return null; + } + + @Override + public String getSetupClass() { + return null; + } + + @Override + public void injectData(Map data) { + Processor processor = Processor.getInstance(); + processor.obfuscated = (Boolean) data.get("runtimeDeobfuscationEnabled"); + System.out.println("running in a" + (processor.obfuscated ? "n " : " de") + "obfuscated enviroment."); + Transformer.instance.hookTransformers(); + } + + @Override + public String getAccessTransformerClass() { + return null; + } +} diff --git a/src/main/java/com/sijobe/spc/asm/Transformer.java b/src/main/java/com/sijobe/spc/asm/Transformer.java new file mode 100644 index 0000000..1a4a2eb --- /dev/null +++ b/src/main/java/com/sijobe/spc/asm/Transformer.java @@ -0,0 +1,32 @@ +package com.sijobe.spc.asm; + +import net.minecraft.launchwrapper.IClassTransformer; + +/** + * the ASMtransformer + * + * @author aucguy + * @version 1.0 + */ +public class Transformer implements IClassTransformer { + static Transformer instance; + + public Transformer() { + instance = this; + } + + void hookTransformers() { + Processor processor = Processor.getInstance(); + processor.mappings.shouldWarn = true; + processor.registerMethodTransformers(MethodTransformer.generateFromFunctions(SimpleHooked.class)); + processor.registerMethodTransformer(new SlashPrefixer()); + processor.registerMethodTransformer(new EntityReacherClient()); + processor.registerMethodTransformer(new EntityReacherServer()); + processor.mappings.shouldWarn = false; + } + + @Override + public byte[] transform(String name, String transformedName, byte[] basicClass) { + return Processor.getInstance().process(name, basicClass); + } +} diff --git a/src/com/sijobe/spc/command/Achievement.java b/src/main/java/com/sijobe/spc/command/Achievement.java similarity index 92% rename from src/com/sijobe/spc/command/Achievement.java rename to src/main/java/com/sijobe/spc/command/Achievement.java index 8db9f7e..f78949a 100644 --- a/src/com/sijobe/spc/command/Achievement.java +++ b/src/main/java/com/sijobe/spc/command/Achievement.java @@ -5,7 +5,6 @@ import com.sijobe.spc.validation.ParameterString; import com.sijobe.spc.validation.Parameters; import com.sijobe.spc.wrapper.CommandSender; -import com.sijobe.spc.wrapper.Minecraft; import com.sijobe.spc.wrapper.Player; import com.sijobe.spc.wrapper.Stats; @@ -48,7 +47,7 @@ public void execute(CommandSender sender, List params) { achievements = achievements.substring(0, achievements.length() - 2); sender.sendMessageToPlayer(achievements); } else if (((String)params.get(0)).equalsIgnoreCase("unlock")) { - Player player = Minecraft.getPlayer(); + Player player = getSenderAsPlayer(sender); if (params.size() == 2) { if (player.addAchievement((String)params.get(1))) { player.sendChatMessage("The " + FontColour.AQUA + (String)params.get(1) @@ -69,9 +68,4 @@ public void execute(CommandSender sender, List params) { public Parameters getParameters() { return PARAMETERS; } - - @Override - public boolean isEnabled() { - return Minecraft.isSinglePlayer(); - } } diff --git a/src/com/sijobe/spc/command/Ascend.java b/src/main/java/com/sijobe/spc/command/Ascend.java similarity index 96% rename from src/com/sijobe/spc/command/Ascend.java rename to src/main/java/com/sijobe/spc/command/Ascend.java index d37d7d5..68e1924 100644 --- a/src/com/sijobe/spc/command/Ascend.java +++ b/src/main/java/com/sijobe/spc/command/Ascend.java @@ -13,6 +13,7 @@ * * @author simo_415 * @version 1.0 + * @status broken through 1.7.2 update -> fixed */ @Command ( name = "ascend", diff --git a/src/com/sijobe/spc/command/Bind.java b/src/main/java/com/sijobe/spc/command/Bind.java similarity index 58% rename from src/com/sijobe/spc/command/Bind.java rename to src/main/java/com/sijobe/spc/command/Bind.java index b7817d6..db0d43c 100644 --- a/src/com/sijobe/spc/command/Bind.java +++ b/src/main/java/com/sijobe/spc/command/Bind.java @@ -1,6 +1,9 @@ package com.sijobe.spc.command; -import com.sijobe.spc.core.Constants; +import com.sijobe.spc.ModSpc; +import com.sijobe.spc.network.Config; +import com.sijobe.spc.network.IClientConfig; +import com.sijobe.spc.network.PacketConfig; import com.sijobe.spc.util.FontColour; import com.sijobe.spc.util.KeyListener; import com.sijobe.spc.util.KeyboardHandler; @@ -10,106 +13,90 @@ import com.sijobe.spc.validation.ParameterString; import com.sijobe.spc.validation.Parameters; import com.sijobe.spc.wrapper.CommandException; -import com.sijobe.spc.wrapper.CommandManager; import com.sijobe.spc.wrapper.CommandSender; -import com.sijobe.spc.wrapper.Minecraft; -import com.sijobe.spc.wrapper.MinecraftServer; import com.sijobe.spc.wrapper.Player; -import java.io.File; import java.util.List; import org.lwjgl.input.Keyboard; +import net.minecraft.entity.player.EntityPlayerMP; + /** * Handles the bindings that the player has assigned to keys * * @author simo_415 * @version 1.1 */ -public class Bind extends MultipleCommands implements KeyListener { - +public class Bind extends MultipleCommands implements KeyListener, IClientConfig { /** - * The bindings that the player uses + * the settings prefix */ - private static Settings BINDINGS = new Settings(new File(Constants.MOD_DIR, "bindings.properties")); - + public static final String SETTINGS_PREFIX = "keybinding-"; + + /** + * the command that is sent everytime a bound key is pressed + */ + public static final String KEYPRESS_COMMAND = "/keypress "; + /** * The instance that all key bindings are associated against */ private static Bind INSTANCE = new Bind(""); - // Adds all the binding listeners - static { - INSTANCE.addKeyListeners(); - } - /** * The parameters for the bind command */ private static final Parameters BIND_PARAMS = new Parameters ( - new Parameter[] { - new ParameterString("", false), - new ParameterString("", false), - new ParameterString("{PARAMETERS}", true, true) - } - ); - + new Parameter[] { + new ParameterString("", false), + new ParameterString("", false), + new ParameterString("{PARAMETERS}", true, true) + } + ); + /** * The parameters for the bindid command */ private static final Parameters BINDID_PARAMS = new Parameters ( - new Parameter[] { - new ParameterInteger("", false), - new ParameterString("", false), - new ParameterString("{PARAMETERS}", true, true) - } - ); - + new Parameter[] { + new ParameterInteger("", false), + new ParameterString("", false), + new ParameterString("{PARAMETERS}", true, true) + } + ); + /** * The parameters for the unbind command */ private static final Parameters UNBIND_PARAMS = new Parameters ( - new Parameter[] { - new ParameterString("", false), - } - ); - - /** - * Initialises the instance using the specified command name - * - * @param name - The name of the command - */ - public Bind(String name) { - super(name); - } + new Parameter[] { + new ParameterString("", false), + } + ); /** - * Adds all the binding listeners to the key listener + * The parameters for the unbind command */ - private void addKeyListeners() { - for (Object key : BINDINGS.keySet()) { - try { - bind(Integer.parseInt((String)key)); - } catch (Exception e) { - System.err.println("Invalid key specified in bindings: " + key); - BINDINGS.remove(key); + private static final Parameters UNBINDID_PARAMS = new Parameters ( + new Parameter[] { + new ParameterInteger("", false), } - } + ); + + public Bind() { + super(""); } - + /** - * The bind commands are only enabled in single player mode since keyboard - * handling can only currently be done locally as key presses don't get sent - * to the server. + * Initialises the instance using the specified command name * - * @see com.sijobe.spc.wrapper.CommandBase#isEnabled() + * @param name - The name of the command */ - @Override - public boolean isEnabled() { - return Minecraft.isSinglePlayer(); + public Bind(String name) { + super(name); } - + /** * @see com.sijobe.spc.command.MultipleCommands#getCommands() */ @@ -117,12 +104,14 @@ public boolean isEnabled() { public String[] getCommands() { return new String[] {"bind", "unbind", "bindid", "unbindid"}; } - + /** * @see com.sijobe.spc.wrapper.CommandBase#execute(com.sijobe.spc.wrapper.CommandSender, java.util.List) */ @Override public void execute(CommandSender sender, List params) throws CommandException { + Player player = getSenderAsPlayer(sender); + Settings settings = loadSettings(player); if (getName().equalsIgnoreCase("bind") || getName().equalsIgnoreCase("bindid")) { int keycode = Keyboard.KEY_NONE; if (getName().equalsIgnoreCase("bind")) { @@ -139,21 +128,25 @@ public void execute(CommandSender sender, List params) throws CommandExceptio if (params.size() > 2) { param = (String)params.get(2); } - if (BINDINGS.get(keycode + "") == null) { - bind(keycode); - } - BINDINGS.set(keycode + "", command + " " + param); - BINDINGS.save(); + + ModSpc.instance.networkHandler.sendTo(new PacketConfig(this.getConfig(), keycode), (EntityPlayerMP) player.getMinecraftPlayer()); + settings.set(SETTINGS_PREFIX + keycode, command + " " + param); + settings.save(); sender.sendMessageToPlayer("Key " + FontColour.AQUA + params.get(0) + - FontColour.WHITE + " was successfully bound."); + FontColour.WHITE + " was successfully bound."); } else if (getName().equalsIgnoreCase("unbind") || getName().equalsIgnoreCase("unbindid")) { int keycode = Keyboard.KEY_NONE; if (getName().equalsIgnoreCase("unbind")) { String key = (String)params.get(0); if (key.equalsIgnoreCase("all")) { - BINDINGS.clear(); - BINDINGS.save(); + for(Object i : settings.entrySet()) { + if(i instanceof String && ((String) i).startsWith(SETTINGS_PREFIX)) { + settings.remove(i); + } + } + settings.save(); sender.sendMessageToPlayer("All bindings removed."); + ModSpc.instance.networkHandler.sendTo(new PacketConfig(this.getConfig(), 0x02000000), (EntityPlayerMP) player.getMinecraftPlayer()); return; } keycode = Keyboard.getKeyIndex(key.toUpperCase()); @@ -163,19 +156,21 @@ public void execute(CommandSender sender, List params) throws CommandExceptio if (keycode == Keyboard.KEY_NONE) { throw new CommandException("Unknown keycode " + params.get(0)); } - unbind(keycode); - if (BINDINGS.remove(keycode + "") == null) { + + + if (settings.remove(SETTINGS_PREFIX + keycode) == null) { throw new CommandException("No binding was found for key " + FontColour.AQUA + (String)params.get(0)); } else { - BINDINGS.save(); + settings.save(); + ModSpc.instance.networkHandler.sendTo(new PacketConfig(this.getConfig(), 0x01000000 | keycode), (EntityPlayerMP) player.getMinecraftPlayer()); sender.sendMessageToPlayer("Binding " + FontColour.AQUA + params.get(0) + - FontColour.WHITE + " was successfully removed."); + FontColour.WHITE + " was successfully removed."); } } else { assert false : "Invalid command " + getName(); } } - + /** * Binds a key to a listener * @@ -184,7 +179,6 @@ public void execute(CommandSender sender, List params) throws CommandExceptio private void bind(int key) { if (!KeyboardHandler.getInstance().addKeyPressedListener(key, INSTANCE)) { System.err.println("Invalid key specified in bindings: " + key); - BINDINGS.remove(key); } } @@ -196,7 +190,7 @@ private void bind(int key) { private void unbind(int key) { KeyboardHandler.getInstance().removeKeyPressedListener(key, INSTANCE); } - + @Override public Parameters getParameters() { if (getName().equalsIgnoreCase("bind")) { @@ -205,12 +199,14 @@ public Parameters getParameters() { return UNBIND_PARAMS; } else if (getName().equalsIgnoreCase("bindid")) { return BINDID_PARAMS; + } else if (getName().equalsIgnoreCase("unbindid")) { + return UNBINDID_PARAMS; } else { assert false : "Invalid command name initialsied " + getName(); return Parameters.DEFAULT; } } - + /** * Handles binding events * @@ -218,16 +214,13 @@ public Parameters getParameters() { */ @Override public void keyPressed(int key) { - if (Minecraft.isGuiScreenOpen()) { + if (ModSpc.instance.proxy.isClientGuiScreenOpen()) { return; } - Player player = Minecraft.getPlayer(); - if (player != null) { - CommandSender sender = new CommandSender(MinecraftServer.getPlayerByUsername(player.getPlayerName())); - CommandManager.runCommand(sender, BINDINGS.getString(key + "", "")); - } + + ModSpc.instance.proxy.sendClientChat(KEYPRESS_COMMAND + key); } - + /** * @see com.sijobe.spc.util.KeyListener#keyReleased(int) */ @@ -235,4 +228,36 @@ public void keyPressed(int key) { public void keyReleased(int key) { // Not required } + + @Override + public void init(Object... params) { + } + + + /** + * @see com.sijobe.spc.network.IClientConfig#onConfigRecieved(java.lang.Object) + * @param value the first byte determines the what action is required + * if it is zero, bind the key specified in the last byte + * if it is one, unbind the key specified in the last byte + * if it is two, unbind all keys + */ + @Override + public void onConfigRecieved(Integer value) { + int action = (value & 0xFF000000) >> 24; + int keycode = value & 0x000000FF; + if(action == 0) { + this.bind(keycode); + } + else if(action == 1) { + this.unbind(keycode); + } + else if(action == 2) { + KeyboardHandler.removeAllKeys(INSTANCE); + } + } + + @Override + public Config getConfig() { + return Config.BIND; + } } diff --git a/src/com/sijobe/spc/command/BlockReach.java b/src/main/java/com/sijobe/spc/command/BlockReach.java similarity index 57% rename from src/com/sijobe/spc/command/BlockReach.java rename to src/main/java/com/sijobe/spc/command/BlockReach.java index 9faefb3..91fb8fd 100644 --- a/src/com/sijobe/spc/command/BlockReach.java +++ b/src/main/java/com/sijobe/spc/command/BlockReach.java @@ -1,14 +1,16 @@ package com.sijobe.spc.command; -import com.sijobe.spc.util.ForgeHelper; +import com.sijobe.spc.ModSpc; +import com.sijobe.spc.network.Config; +import com.sijobe.spc.network.IClientConfig; +import com.sijobe.spc.network.PacketConfig; import com.sijobe.spc.validation.Parameter; import com.sijobe.spc.validation.Parameters; import com.sijobe.spc.validation.ParameterDouble; import com.sijobe.spc.wrapper.CommandException; import com.sijobe.spc.wrapper.CommandSender; -import com.sijobe.spc.wrapper.Minecraft; import com.sijobe.spc.wrapper.Player; -import net.minecraft.src.EntityPlayerMP; +import net.minecraft.entity.player.EntityPlayerMP; import java.util.List; @@ -17,22 +19,29 @@ * * @author q3hardcore * @version 1.0 + * @status broken through 1.7.2 update -> fixed */ @Command ( - name = "blockreach", - description = "Changes block reach distance", - alias = {"reach"} -) -public class BlockReach extends StandardCommand { - + name = "blockreach", + description = "Changes block reach distance", + alias = {"reach"} + ) +public class BlockReach extends StandardCommand implements IClientConfig{ + /** * The parameters of the command */ private static final Parameters PARAMETERS = new Parameters ( - new Parameter[] { - new ParameterDouble("[DISTANCE]", true), - } - ); + new Parameter[] { + new ParameterDouble("[DISTANCE]", true), + } + ); + + /** + * the block reachDistance for the client + * refered to through ASM modifications and is client sided + */ + public static float reachDistance = 4.5F; /** * @see com.sijobe.spc.wrapper.CommandBase#execute(com.sijobe.spc.wrapper.CommandSender, java.util.List) @@ -46,28 +55,18 @@ public void execute(CommandSender sender, List params) throws CommandExceptio EntityPlayerMP playerEntity = (EntityPlayerMP)player.getMinecraftPlayer(); if(params.size() == 0) { sender.sendMessageToPlayer("Current block reach distance: " + - ForgeHelper.getBlockReachDistance(playerEntity.theItemInWorldManager)); + playerEntity.theItemInWorldManager.getBlockReachDistance()); } else { double newReach = (Double)params.get(0); if(newReach < 4.5D || newReach > 255.0D) { throw new CommandException("Reach distance must be between 4.5 and 255."); } - ForgeHelper.setBlockReachDistance(playerEntity.theItemInWorldManager, newReach); - Minecraft.getMinecraft().thePlayer.setClientReach(newReach); + playerEntity.theItemInWorldManager.setBlockReachDistance(newReach); sender.sendMessageToPlayer("Set block reach distance to: " + newReach); + ModSpc.instance.networkHandler.sendTo(new PacketConfig(this.getConfig(), (float) newReach), playerEntity); } } - /** - * Only enabled in single player since this is a client-side mod - * - * @see com.sijobe.spc.wrapper.CommandBase#isEnabled() - */ - @Override - public boolean isEnabled() { - return Minecraft.isSinglePlayer() && ForgeHelper.HAS_FORGE; - } - /** * @see com.sijobe.spc.wrapper.CommandBase#getParameters() */ @@ -75,4 +74,18 @@ public boolean isEnabled() { public Parameters getParameters() { return PARAMETERS; } + + @Override + public void init(Object... params) { + } + + @Override + public void onConfigRecieved(Float value) { + reachDistance = value; + } + + @Override + public Config getConfig() { + return Config.BLOCK_REACH; + } } diff --git a/src/com/sijobe/spc/command/Bring.java b/src/main/java/com/sijobe/spc/command/Bring.java similarity index 90% rename from src/com/sijobe/spc/command/Bring.java rename to src/main/java/com/sijobe/spc/command/Bring.java index 928747b..48f0551 100644 --- a/src/com/sijobe/spc/command/Bring.java +++ b/src/main/java/com/sijobe/spc/command/Bring.java @@ -8,7 +8,6 @@ import com.sijobe.spc.wrapper.CommandSender; import com.sijobe.spc.wrapper.Entity; import com.sijobe.spc.wrapper.Player; -import net.minecraft.src.EntityPlayerMP; import java.util.List; @@ -18,6 +17,7 @@ * * @author q3hardcore * @version 1.0 + * @status survived 1.7.2 update */ @Command ( @@ -65,14 +65,14 @@ public void execute(CommandSender sender, List params) throws CommandExceptio if(radius <=0 || radius > 256) { throw new CommandException("Radius should be between 0 and 256."); } - List foundEntities = Entity.findEntities(entityType, player.getPosition(), player.getWorld(), radius); - net.minecraft.src.Vec3 vec3d = player.getMinecraftPlayer().getLook(1.0F); + List foundEntities = Entity.findEntities(entityType, player.getPosition(), player.getWorld(), radius); + net.minecraft.util.Vec3 vec3d = player.getMinecraftPlayer().getLook(1.0F); double d = 5.0D; double offsetY = player.getMinecraftPlayer().posY + player.getMinecraftPlayer().getEyeHeight(); double d1 = player.getMinecraftPlayer().posX + vec3d.xCoord * d; double d2 = offsetY + vec3d.yCoord * d; double d3 = player.getMinecraftPlayer().posZ + vec3d.zCoord * d; - for(net.minecraft.src.Entity entity : foundEntities) { + for(net.minecraft.entity.Entity entity : foundEntities) { if(entity == player.getMinecraftPlayer()) { continue; // don't allow the player to bring themselves } diff --git a/src/com/sijobe/spc/command/Cannon.java b/src/main/java/com/sijobe/spc/command/Cannon.java similarity index 94% rename from src/com/sijobe/spc/command/Cannon.java rename to src/main/java/com/sijobe/spc/command/Cannon.java index e6d5828..82b89b6 100644 --- a/src/com/sijobe/spc/command/Cannon.java +++ b/src/main/java/com/sijobe/spc/command/Cannon.java @@ -8,14 +8,15 @@ import java.util.List; -import net.minecraft.src.EntityTNTPrimed; -import net.minecraft.src.MathHelper; +import net.minecraft.entity.item.EntityTNTPrimed; +import net.minecraft.util.MathHelper; /** * Shoots a piece of cannon in the direction the player is facing * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 update */ @Command ( name = "cannon", diff --git a/src/com/sijobe/spc/command/Cheats.java b/src/main/java/com/sijobe/spc/command/Cheats.java similarity index 89% rename from src/com/sijobe/spc/command/Cheats.java rename to src/main/java/com/sijobe/spc/command/Cheats.java index 527f022..fa2b6a8 100644 --- a/src/com/sijobe/spc/command/Cheats.java +++ b/src/main/java/com/sijobe/spc/command/Cheats.java @@ -14,6 +14,7 @@ * * @author q3hardcore * @version 1.0 + * @status broken through 1.7.2 update -> fixed */ @Command ( name = "cheats", @@ -40,5 +41,9 @@ public void execute(CommandSender sender, List params) throws CommandExceptio public Parameters getParameters() { return Parameters.DEFAULT_BOOLEAN; } - + + @Override + public boolean hasPermission(CommandSender sender) { + return true; + } } \ No newline at end of file diff --git a/src/com/sijobe/spc/command/ClearDrops.java b/src/main/java/com/sijobe/spc/command/ClearDrops.java similarity index 91% rename from src/com/sijobe/spc/command/ClearDrops.java rename to src/main/java/com/sijobe/spc/command/ClearDrops.java index 7ef03e1..8ad76c8 100644 --- a/src/com/sijobe/spc/command/ClearDrops.java +++ b/src/main/java/com/sijobe/spc/command/ClearDrops.java @@ -8,16 +8,17 @@ import java.util.List; -import net.minecraft.src.AxisAlignedBB; -import net.minecraft.src.Entity; -import net.minecraft.src.EntityItem; -import net.minecraft.src.World; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.world.World; /** * Command to clear item drops * * @author q3hardcore * @version 1.0 + * @status survived 1.7.2 update */ @Command ( name = "cleardrops", diff --git a/src/com/sijobe/spc/command/Command.java b/src/main/java/com/sijobe/spc/command/Command.java similarity index 100% rename from src/com/sijobe/spc/command/Command.java rename to src/main/java/com/sijobe/spc/command/Command.java diff --git a/src/com/sijobe/spc/command/CriticalHit.java b/src/main/java/com/sijobe/spc/command/CriticalHit.java similarity index 100% rename from src/com/sijobe/spc/command/CriticalHit.java rename to src/main/java/com/sijobe/spc/command/CriticalHit.java diff --git a/src/com/sijobe/spc/command/Damage.java b/src/main/java/com/sijobe/spc/command/Damage.java similarity index 97% rename from src/com/sijobe/spc/command/Damage.java rename to src/main/java/com/sijobe/spc/command/Damage.java index d05a7ec..d28d30c 100644 --- a/src/com/sijobe/spc/command/Damage.java +++ b/src/main/java/com/sijobe/spc/command/Damage.java @@ -12,6 +12,7 @@ * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 update */ @Command ( name = "damage", diff --git a/src/com/sijobe/spc/command/Descend.java b/src/main/java/com/sijobe/spc/command/Descend.java similarity index 96% rename from src/com/sijobe/spc/command/Descend.java rename to src/main/java/com/sijobe/spc/command/Descend.java index f525b87..b8b2065 100644 --- a/src/com/sijobe/spc/command/Descend.java +++ b/src/main/java/com/sijobe/spc/command/Descend.java @@ -13,6 +13,7 @@ * * @author simo_415 * @version 1.0 + * @status broken through 1.7.2 update -> fixed */ @Command ( name = "descend", diff --git a/src/com/sijobe/spc/command/Difficulty.java b/src/main/java/com/sijobe/spc/command/Difficulty.java similarity index 83% rename from src/com/sijobe/spc/command/Difficulty.java rename to src/main/java/com/sijobe/spc/command/Difficulty.java index 2eb8a44..9669ed9 100644 --- a/src/com/sijobe/spc/command/Difficulty.java +++ b/src/main/java/com/sijobe/spc/command/Difficulty.java @@ -8,6 +8,8 @@ import com.sijobe.spc.wrapper.CommandSender; import com.sijobe.spc.wrapper.World; +import net.minecraft.world.EnumDifficulty; + import java.util.List; /** @@ -15,6 +17,7 @@ * * @author simo_415 * @version 1.0 + * @status broken through 1.7.2 update -> fixed */ @Command ( name = "difficulty", @@ -41,22 +44,22 @@ public class Difficulty extends StandardCommand { public void execute(CommandSender sender, List params) throws CommandException { World world = super.getSenderAsPlayer(sender).getWorld(); if (params.size() > 0) { - world.setDifficulty((Integer)params.get(0)); + world.setDifficulty(EnumDifficulty.getDifficultyEnum((Integer)params.get(0))); } else { - world.setDifficulty((world.getDifficulty() + 1) % 4); + world.setDifficulty(EnumDifficulty.getDifficultyEnum((world.getDifficulty().getDifficultyId() + 1) % 4)); } String difficulty = ""; switch (world.getDifficulty()) { - case 0: + case PEACEFUL: difficulty = FontColour.GREEN + "peaceful"; break; - case 1: + case EASY: difficulty = FontColour.YELLOW + "easy"; break; - case 2: + case NORMAL: difficulty = FontColour.ORANGE + "normal"; break; - case 3: + case HARD: difficulty = FontColour.RED + "hard"; break; } diff --git a/src/com/sijobe/spc/command/DoDrops.java b/src/main/java/com/sijobe/spc/command/DoDrops.java similarity index 89% rename from src/com/sijobe/spc/command/DoDrops.java rename to src/main/java/com/sijobe/spc/command/DoDrops.java index 42c67ea..e376d9c 100644 --- a/src/com/sijobe/spc/command/DoDrops.java +++ b/src/main/java/com/sijobe/spc/command/DoDrops.java @@ -5,8 +5,6 @@ import com.sijobe.spc.wrapper.CommandBase; import com.sijobe.spc.wrapper.CommandException; import com.sijobe.spc.wrapper.CommandSender; -import com.sijobe.spc.wrapper.Coordinate; -import com.sijobe.spc.wrapper.Minecraft; import com.sijobe.spc.wrapper.Player; import java.util.List; @@ -16,6 +14,7 @@ * * @author q3hardcore * @version 1.0 + * @status survived 1.7.2 update */ @Command ( name = "dodrops", @@ -28,11 +27,6 @@ public class DoDrops extends StandardCommand implements IPlayerMP { private static boolean removeDrops = false; - @Override - public boolean isEnabled() { - return Minecraft.isSinglePlayer(); - } - @Override public void execute(CommandSender sender, List params) throws CommandException { Player player = CommandBase.getSenderAsPlayer(sender); diff --git a/src/com/sijobe/spc/command/Effect.java b/src/main/java/com/sijobe/spc/command/Effect.java similarity index 99% rename from src/com/sijobe/spc/command/Effect.java rename to src/main/java/com/sijobe/spc/command/Effect.java index 838f04e..8981855 100644 --- a/src/com/sijobe/spc/command/Effect.java +++ b/src/main/java/com/sijobe/spc/command/Effect.java @@ -17,6 +17,7 @@ * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 updaets */ @Command ( name = "effect", diff --git a/src/com/sijobe/spc/command/Enchant.java b/src/main/java/com/sijobe/spc/command/Enchant.java similarity index 99% rename from src/com/sijobe/spc/command/Enchant.java rename to src/main/java/com/sijobe/spc/command/Enchant.java index c5a22c7..47b2bd2 100644 --- a/src/com/sijobe/spc/command/Enchant.java +++ b/src/main/java/com/sijobe/spc/command/Enchant.java @@ -17,6 +17,7 @@ * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 update */ @Command ( name = "enchant", diff --git a/src/com/sijobe/spc/command/EnderChest.java b/src/main/java/com/sijobe/spc/command/EnderChest.java similarity index 90% rename from src/com/sijobe/spc/command/EnderChest.java rename to src/main/java/com/sijobe/spc/command/EnderChest.java index 5fd3935..7d92c2d 100644 --- a/src/com/sijobe/spc/command/EnderChest.java +++ b/src/main/java/com/sijobe/spc/command/EnderChest.java @@ -1,33 +1,34 @@ -package com.sijobe.spc.command; - -import com.sijobe.spc.wrapper.CommandException; -import com.sijobe.spc.wrapper.CommandSender; - -import net.minecraft.src.EntityPlayer; - -import java.util.List; - -/** - * Open enderchest GUI anywhere - * - * @author q3hardcore - * @version 1.4.2 - */ -@Command ( - name = "enderchest", - description = "Opens EnderChest GUI without having EnderChest", - example = "", - version = "1.4.2" -) -public class EnderChest extends StandardCommand { - - /** - * @see com.sijobe.spc.wrapper.CommandBase#execute(com.sijobe.spc.wrapper.CommandSender, java.util.List) - */ - @Override - public void execute(CommandSender sender, List params) throws CommandException { - EntityPlayer player = getSenderAsPlayer(sender).getMinecraftPlayer(); - player.displayGUIChest(player.getInventoryEnderChest()); - } - -} +package com.sijobe.spc.command; + +import com.sijobe.spc.wrapper.CommandException; +import com.sijobe.spc.wrapper.CommandSender; + +import net.minecraft.entity.player.EntityPlayer; + +import java.util.List; + +/** + * Open enderchest GUI anywhere + * + * @author q3hardcore + * @version 1.4.2 + * @status survived 1.7.2 update + */ +@Command ( + name = "enderchest", + description = "Opens EnderChest GUI without having EnderChest", + example = "", + version = "1.4.2" +) +public class EnderChest extends StandardCommand { + + /** + * @see com.sijobe.spc.wrapper.CommandBase#execute(com.sijobe.spc.wrapper.CommandSender, java.util.List) + */ + @Override + public void execute(CommandSender sender, List params) throws CommandException { + EntityPlayer player = getSenderAsPlayer(sender).getMinecraftPlayer(); + player.displayGUIChest(player.getInventoryEnderChest()); + } + +} diff --git a/src/com/sijobe/spc/command/EnderCrystal.java b/src/main/java/com/sijobe/spc/command/EnderCrystal.java similarity index 96% rename from src/com/sijobe/spc/command/EnderCrystal.java rename to src/main/java/com/sijobe/spc/command/EnderCrystal.java index fdca101..96cfcfb 100644 --- a/src/com/sijobe/spc/command/EnderCrystal.java +++ b/src/main/java/com/sijobe/spc/command/EnderCrystal.java @@ -13,6 +13,7 @@ * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 update */ @Command ( name = "endercrystal", diff --git a/src/com/sijobe/spc/command/Explode.java b/src/main/java/com/sijobe/spc/command/Explode.java similarity index 98% rename from src/com/sijobe/spc/command/Explode.java rename to src/main/java/com/sijobe/spc/command/Explode.java index 14ef90a..cecd7f5 100644 --- a/src/com/sijobe/spc/command/Explode.java +++ b/src/main/java/com/sijobe/spc/command/Explode.java @@ -16,6 +16,7 @@ * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 update */ @Command ( name = "explode", diff --git a/src/com/sijobe/spc/command/Firework.java b/src/main/java/com/sijobe/spc/command/Firework.java similarity index 84% rename from src/com/sijobe/spc/command/Firework.java rename to src/main/java/com/sijobe/spc/command/Firework.java index 0811c80..0c3a754 100644 --- a/src/com/sijobe/spc/command/Firework.java +++ b/src/main/java/com/sijobe/spc/command/Firework.java @@ -9,10 +9,11 @@ import com.sijobe.spc.wrapper.Player; /** - * Creates an endercrystal where the player is pointing + * Creates an endercrystal where the player is pointing //TODO why does it say endercrystal? * * @author simo_415 * @version 1.0 + * @status broken through 1.7.2 update (worked before?) */ @Command ( name = "firework", diff --git a/src/com/sijobe/spc/command/Fly.java b/src/main/java/com/sijobe/spc/command/Fly.java similarity index 95% rename from src/com/sijobe/spc/command/Fly.java rename to src/main/java/com/sijobe/spc/command/Fly.java index a63952b..9f93978 100644 --- a/src/com/sijobe/spc/command/Fly.java +++ b/src/main/java/com/sijobe/spc/command/Fly.java @@ -9,6 +9,11 @@ import java.util.List; +/** + * TODO add doc + * @status survived 1.7.2 update + */ + @Command ( name = "fly", description = "Enables and disables the ability to fly for the player", diff --git a/src/com/sijobe/spc/command/Gamemode.java b/src/main/java/com/sijobe/spc/command/Gamemode.java similarity index 98% rename from src/com/sijobe/spc/command/Gamemode.java rename to src/main/java/com/sijobe/spc/command/Gamemode.java index 427a8c5..b6efa45 100644 --- a/src/com/sijobe/spc/command/Gamemode.java +++ b/src/main/java/com/sijobe/spc/command/Gamemode.java @@ -15,6 +15,7 @@ * * @author simo_415 * @version 1.0 + * @survived 1.7.2 update */ @Command ( name = "gamemode", diff --git a/src/com/sijobe/spc/command/Give.java b/src/main/java/com/sijobe/spc/command/Give.java similarity index 88% rename from src/com/sijobe/spc/command/Give.java rename to src/main/java/com/sijobe/spc/command/Give.java index 7d54ece..18e79b7 100644 --- a/src/com/sijobe/spc/command/Give.java +++ b/src/main/java/com/sijobe/spc/command/Give.java @@ -15,6 +15,7 @@ * * @author simo_415 * @version 1.0 + * @status broken through 1.7.2 update -> fixed */ @Command ( name = "give", @@ -54,16 +55,9 @@ public void execute(CommandSender sender, List params) throws CommandExceptio } } - // Get the item id - int code = -1; - try { - code = Integer.parseInt(split[0]); - } catch (NumberFormatException e) { - code = -1; - } - if (code <= 0) { - code = Item.getItemId((split[0]).replace('_', ' ')); - } + // Get the item + Item code = null; + code = Item.getItem((split[0])); if (!Item.isValidItem(code)) { throw new CommandException("Cannot find specified item: " + split[0]); } @@ -72,7 +66,7 @@ public void execute(CommandSender sender, List params) throws CommandExceptio int quantity = params.size() > 1 ? (Integer)params.get(1) : 0; damage = params.size() > 2 ? (Integer)params.get(2) : damage; if (quantity == 0) { - super.getSenderAsPlayer(sender).givePlayerItem(code); + super.getSenderAsPlayer(sender).givePlayerItemWithDrop(code); } else if (damage == 0) { super.getSenderAsPlayer(sender).givePlayerItem(code, quantity); } else { diff --git a/src/com/sijobe/spc/command/Hardcore.java b/src/main/java/com/sijobe/spc/command/Hardcore.java similarity index 97% rename from src/com/sijobe/spc/command/Hardcore.java rename to src/main/java/com/sijobe/spc/command/Hardcore.java index adea8d9..514db1b 100644 --- a/src/com/sijobe/spc/command/Hardcore.java +++ b/src/main/java/com/sijobe/spc/command/Hardcore.java @@ -13,6 +13,7 @@ * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 update */ @Command ( name = "hardcore", diff --git a/src/com/sijobe/spc/command/Heal.java b/src/main/java/com/sijobe/spc/command/Heal.java similarity index 97% rename from src/com/sijobe/spc/command/Heal.java rename to src/main/java/com/sijobe/spc/command/Heal.java index e569d69..828ea9f 100644 --- a/src/com/sijobe/spc/command/Heal.java +++ b/src/main/java/com/sijobe/spc/command/Heal.java @@ -13,6 +13,7 @@ * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 update */ @Command ( name = "heal", diff --git a/src/com/sijobe/spc/command/Health.java b/src/main/java/com/sijobe/spc/command/Health.java similarity index 96% rename from src/com/sijobe/spc/command/Health.java rename to src/main/java/com/sijobe/spc/command/Health.java index de8502e..69963b7 100644 --- a/src/com/sijobe/spc/command/Health.java +++ b/src/main/java/com/sijobe/spc/command/Health.java @@ -15,6 +15,7 @@ * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 update but infinite option doesn't work */ @Command ( name = "health", diff --git a/src/com/sijobe/spc/command/Help.java b/src/main/java/com/sijobe/spc/command/Help.java similarity index 99% rename from src/com/sijobe/spc/command/Help.java rename to src/main/java/com/sijobe/spc/command/Help.java index 5b83ff7..5cf3bc0 100644 --- a/src/com/sijobe/spc/command/Help.java +++ b/src/main/java/com/sijobe/spc/command/Help.java @@ -16,6 +16,7 @@ * * @author simo_415 * @version 1.1 + * @status survived 1.7.2 update */ @Command ( name = "help", diff --git a/src/com/sijobe/spc/command/Home.java b/src/main/java/com/sijobe/spc/command/Home.java similarity index 96% rename from src/com/sijobe/spc/command/Home.java rename to src/main/java/com/sijobe/spc/command/Home.java index 3077b0a..e1dc42d 100644 --- a/src/com/sijobe/spc/command/Home.java +++ b/src/main/java/com/sijobe/spc/command/Home.java @@ -11,6 +11,7 @@ * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 update */ @Command ( name = "home", diff --git a/src/com/sijobe/spc/command/Hunger.java b/src/main/java/com/sijobe/spc/command/Hunger.java similarity index 98% rename from src/com/sijobe/spc/command/Hunger.java rename to src/main/java/com/sijobe/spc/command/Hunger.java index 9001abe..78fce8e 100644 --- a/src/com/sijobe/spc/command/Hunger.java +++ b/src/main/java/com/sijobe/spc/command/Hunger.java @@ -15,6 +15,7 @@ * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 update */ @Command ( name = "hunger", diff --git a/src/com/sijobe/spc/command/Ignite.java b/src/main/java/com/sijobe/spc/command/Ignite.java similarity index 84% rename from src/com/sijobe/spc/command/Ignite.java rename to src/main/java/com/sijobe/spc/command/Ignite.java index 914da0e..7f9a8e8 100644 --- a/src/com/sijobe/spc/command/Ignite.java +++ b/src/main/java/com/sijobe/spc/command/Ignite.java @@ -1,5 +1,7 @@ package com.sijobe.spc.command; +import com.sijobe.spc.wrapper.Block; +import com.sijobe.spc.wrapper.Blocks; import com.sijobe.spc.wrapper.CommandException; import com.sijobe.spc.wrapper.CommandSender; import com.sijobe.spc.wrapper.Coordinate; @@ -8,11 +10,13 @@ import java.util.List; + /** * Ignites the top of the block that the player is pointing at * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 update */ @Command ( name = "ignite", @@ -25,7 +29,7 @@ public class Ignite extends StandardCommand { /** * The block ID of fire */ - public static final int BLOCK_FIRE = 51; + public static final Block BLOCK_FIRE = Blocks.fire; /** * @see com.sijobe.spc.wrapper.CommandBase#execute(com.sijobe.spc.wrapper.CommandSender, java.util.List) @@ -38,7 +42,7 @@ public void execute(CommandSender sender, List params) throws CommandExceptio throw new CommandException("No block within range."); } Coordinate fire = new Coordinate(block.getBlockX(), block.getBlockY() + 1, block.getBlockZ()); - if (player.getWorld().getBlockId(fire) == 0) { + if (player.getWorld().getBlock(fire) == Blocks.air) { player.getWorld().setBlock(fire, BLOCK_FIRE); } } diff --git a/src/main/java/com/sijobe/spc/command/InstantMine.java b/src/main/java/com/sijobe/spc/command/InstantMine.java new file mode 100644 index 0000000..4b07653 --- /dev/null +++ b/src/main/java/com/sijobe/spc/command/InstantMine.java @@ -0,0 +1,87 @@ +package com.sijobe.spc.command; + +import com.sijobe.spc.ModSpc; +import com.sijobe.spc.core.IBlockBroken; +import com.sijobe.spc.core.IBreakSpeed; +import com.sijobe.spc.network.Config; +import com.sijobe.spc.network.IClientConfig; +import com.sijobe.spc.util.Settings; +import com.sijobe.spc.validation.Parameters; +import com.sijobe.spc.wrapper.Block; +import com.sijobe.spc.wrapper.CommandException; +import com.sijobe.spc.wrapper.CommandSender; +import com.sijobe.spc.wrapper.Player; +import com.sijobe.spc.wrapper.World; + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayerMP; + +/** + * Command to toggle instant mining + * + * @author q3hardcore + * @version 1.0 + * @status broken through 1.7.2 update -> fixed + */ +@Command ( + name = "instantmine", + description = "Allows player to mine blocks instantly", + example = "", + videoURL = "", + enabled = true + ) +public class InstantMine extends StandardCommand implements IBreakSpeed, IBlockBroken, IClientConfig{ + public static boolean instantMiningEnabled; //TODO load initial value from config + + @Override + public void execute(CommandSender sender, List params) throws CommandException { + Player player = super.getSenderAsPlayer(sender); + if(player.getMinecraftPlayer() instanceof EntityPlayerMP) { + Settings config = super.loadSettings(player); + boolean instantMine = config.getBoolean("instantMine", false); + if (params.size() == 0) { + instantMine ^= true; + } else { + instantMine = ((Boolean)params.get(0)); + } + + config.set("instantMine", instantMine); + super.saveSettings(player); + instantMiningEnabled = instantMine; + player.sendChatMessage("Instant mining " + (instantMine?"enabled.":"disabled.")); + } else { + throw new CommandException("Non-client command"); + } + } + + @Override + public Parameters getParameters() { + return Parameters.DEFAULT_BOOLEAN; + } + + @Override + public void init(Object... params) {} + + @Override + public float getBreakSpeed(Player player, Block block, int metadata, float orginalSpeed, int x, int y, int z) { + return instantMiningEnabled ? 50000000.0F : orginalSpeed; + } + + @Override + public void onBreakBroken(int x, int y, int z, World world, Block block, int metadata, Player player) { + if(instantMiningEnabled) { + ModSpc.instance.proxy.setClientHitDelay(5); + } + } + + @Override + public void onConfigRecieved(Boolean value) { + instantMiningEnabled = value; + } + + @Override + public Config getConfig() { + return Config.INSTANT_MINE; + } +} \ No newline at end of file diff --git a/src/com/sijobe/spc/command/Jump.java b/src/main/java/com/sijobe/spc/command/Jump.java similarity index 95% rename from src/com/sijobe/spc/command/Jump.java rename to src/main/java/com/sijobe/spc/command/Jump.java index dd0cabb..d915f51 100644 --- a/src/com/sijobe/spc/command/Jump.java +++ b/src/main/java/com/sijobe/spc/command/Jump.java @@ -8,11 +8,12 @@ import java.util.List; /** - * Sets the players spawn based on the player position or the arguments + * Sets the players spawn based on the player position or the arguments //TODO make doc correct * provided * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 update */ @Command ( name = "jump", diff --git a/src/main/java/com/sijobe/spc/command/Keypress.java b/src/main/java/com/sijobe/spc/command/Keypress.java new file mode 100644 index 0000000..ae4257c --- /dev/null +++ b/src/main/java/com/sijobe/spc/command/Keypress.java @@ -0,0 +1,43 @@ +package com.sijobe.spc.command; + +import java.util.List; + +import com.sijobe.spc.util.Settings; +import com.sijobe.spc.validation.Parameter; +import com.sijobe.spc.validation.ParameterInteger; +import com.sijobe.spc.validation.Parameters; +import com.sijobe.spc.wrapper.CommandException; +import com.sijobe.spc.wrapper.CommandManager; +import com.sijobe.spc.wrapper.CommandSender; + +/** + * Executes the command bound to the given key. + * + * @author aucguy + * @version 1.0 + */ +@Command ( + name = "keypress", + description = "Executes the command bound to the given key. Internally used command", + videoURL = "none, as I said, this is an internally used command.", + version = "1.0" + ) +public class Keypress extends StandardCommand { + private static final Parameters PARAMETERS = new Parameters ( + new Parameter[] { + new ParameterInteger("[keycode]",true) + } + ); + + @Override + public Parameters getParameters() { + return PARAMETERS; + } + + @Override + public void execute(CommandSender sender, List params) throws CommandException { + Settings settings = loadSettings(getSenderAsPlayer(sender)); + String command = settings.getProperty(Bind.SETTINGS_PREFIX+params.get(0)); + CommandManager.runCommand(sender, command); + } +} diff --git a/src/com/sijobe/spc/command/Kill.java b/src/main/java/com/sijobe/spc/command/Kill.java similarity index 92% rename from src/com/sijobe/spc/command/Kill.java rename to src/main/java/com/sijobe/spc/command/Kill.java index fb64fd6..ef9f0c0 100644 --- a/src/com/sijobe/spc/command/Kill.java +++ b/src/main/java/com/sijobe/spc/command/Kill.java @@ -3,7 +3,7 @@ import com.sijobe.spc.wrapper.CommandSender; import com.sijobe.spc.wrapper.Player; -import net.minecraft.src.DamageSource; +import net.minecraft.util.DamageSource; import java.util.List; @@ -12,6 +12,7 @@ * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 update */ @Command ( name = "kill", diff --git a/src/com/sijobe/spc/command/KillAll.java b/src/main/java/com/sijobe/spc/command/KillAll.java similarity index 96% rename from src/com/sijobe/spc/command/KillAll.java rename to src/main/java/com/sijobe/spc/command/KillAll.java index da02026..0e0a44a 100644 --- a/src/com/sijobe/spc/command/KillAll.java +++ b/src/main/java/com/sijobe/spc/command/KillAll.java @@ -8,7 +8,6 @@ import com.sijobe.spc.wrapper.CommandSender; import com.sijobe.spc.wrapper.Entity; import com.sijobe.spc.wrapper.Player; -import net.minecraft.src.EntityPlayerMP; import java.util.List; @@ -18,6 +17,7 @@ * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 update */ @Command ( @@ -65,7 +65,7 @@ public void execute(CommandSender sender, List params) throws CommandExceptio if(radius <=0 || radius > 256) { throw new CommandException("Radius should be between 0 and 256."); } - List removedEntities = + List removedEntities = Entity.killEntities(entityType, player.getPosition(), player.getWorld(), radius); sender.sendMessageToPlayer(removedEntities.size() + " entity(s) removed."); } diff --git a/src/main/java/com/sijobe/spc/command/Light.java b/src/main/java/com/sijobe/spc/command/Light.java new file mode 100644 index 0000000..315719b --- /dev/null +++ b/src/main/java/com/sijobe/spc/command/Light.java @@ -0,0 +1,58 @@ +package com.sijobe.spc.command; + +import com.sijobe.spc.ModSpc; +import com.sijobe.spc.network.Config; +import com.sijobe.spc.network.IClientConfig; +import com.sijobe.spc.network.PacketConfig; +import com.sijobe.spc.util.Settings; +import com.sijobe.spc.wrapper.CommandException; +import com.sijobe.spc.wrapper.CommandSender; +import com.sijobe.spc.wrapper.Player; + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayerMP; + +/** + * Light command from SinglePlayerCommands 3.2.2, + * ported to SinglePlayerConsole then back to SPC 4.1 + * + * @author q3hardcore + * @version 1.4 + * @status survived 1.7.2 update + */ +@Command ( + name = "light", + description = "Lights up world", + version = "1.4" + ) +public class Light extends StandardCommand implements IClientConfig { + + public static boolean isLit = false; // is current world lit? client sided + + /** + * @see com.sijobe.spc.wrapper.CommandBase#execute(com.sijobe.spc.wrapper.CommandSender, java.util.List) + */ + @Override + public void execute(CommandSender sender, List params) throws CommandException { + Player player = super.getSenderAsPlayer(sender); // Why super.? Meh, Cannon has it like that + Settings config = loadSettings(player); + boolean lit = !config.getBoolean("light", false); + config.set("light", lit); + ModSpc.instance.networkHandler.sendTo(new PacketConfig(this.getConfig(), lit), (EntityPlayerMP) player.getMinecraftPlayer()); + } + + @Override + public void init(Object... params) { + } + + @Override + public void onConfigRecieved(Boolean value) { + ModSpc.instance.proxy.setClientLighting(value); + } + + @Override + public Config getConfig() { + return Config.LIGHT; + } +} diff --git a/src/com/sijobe/spc/command/LongerLegs.java b/src/main/java/com/sijobe/spc/command/LongerLegs.java similarity index 58% rename from src/com/sijobe/spc/command/LongerLegs.java rename to src/main/java/com/sijobe/spc/command/LongerLegs.java index 8b5b18d..44fc526 100644 --- a/src/com/sijobe/spc/command/LongerLegs.java +++ b/src/main/java/com/sijobe/spc/command/LongerLegs.java @@ -2,10 +2,15 @@ import java.util.List; +import net.minecraft.entity.player.EntityPlayerMP; + +import com.sijobe.spc.ModSpc; +import com.sijobe.spc.network.Config; +import com.sijobe.spc.network.IClientConfig; +import com.sijobe.spc.network.PacketConfig; import com.sijobe.spc.util.FontColour; import com.sijobe.spc.wrapper.CommandException; import com.sijobe.spc.wrapper.CommandSender; -import com.sijobe.spc.wrapper.Minecraft; import com.sijobe.spc.wrapper.Player; /** @@ -16,6 +21,7 @@ * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 update */ @Command ( name = "longerlegs", @@ -24,17 +30,12 @@ videoURL = "http://www.youtube.com/watch?v=1Qy2jhvCkDk", version = "1.4.6" ) -public class LongerLegs extends StandardCommand { - - @Override - public boolean isEnabled() { - return Minecraft.isSinglePlayer(); - } +public class LongerLegs extends StandardCommand implements IClientConfig { @Override public void execute(CommandSender sender, List params) throws CommandException { - Player player = Minecraft.getPlayer(); + Player player = getSenderAsPlayer(sender); if (player.getStepHeight() != 0.5F) { player.setStepHeight(0.5F); sender.sendMessageToPlayer("Longer legs is "+FontColour.AQUA+"disabled"); @@ -42,6 +43,21 @@ public void execute(CommandSender sender, List params) player.setStepHeight(1.0F); sender.sendMessageToPlayer("Longer legs is "+FontColour.AQUA+"enabled"); } + ModSpc.instance.networkHandler.sendTo(new PacketConfig(this.getConfig(), player.getStepHeight()), (EntityPlayerMP) player.getMinecraftPlayer()); + } + + @Override + public void init(Object... params) { + } + + @Override + public void onConfigRecieved(Float value) { + System.out.println("foo"); + ModSpc.instance.proxy.getClientPlayer().setStepHeight(value); } -} + @Override + public Config getConfig() { + return Config.LONGER_LEGS; + } +} \ No newline at end of file diff --git a/src/main/java/com/sijobe/spc/command/Macro.java b/src/main/java/com/sijobe/spc/command/Macro.java new file mode 100644 index 0000000..2f259eb --- /dev/null +++ b/src/main/java/com/sijobe/spc/command/Macro.java @@ -0,0 +1,200 @@ +package com.sijobe.spc.command; + +import com.sijobe.spc.core.Constants; +import com.sijobe.spc.util.Settings; +import com.sijobe.spc.validation.Parameter; +import com.sijobe.spc.validation.ParameterString; +import com.sijobe.spc.validation.Parameters; +import com.sijobe.spc.wrapper.CommandException; +import com.sijobe.spc.wrapper.CommandManager; +import com.sijobe.spc.wrapper.CommandSender; +import com.sijobe.spc.wrapper.Player; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.List; + +/** + * Macro command allows you to write a file with a list of commands in it then + * run the file. + * + * @author simo_415 + * @version 1.0 + * @status survived 1.7.2 update + */ +@Command(name = "macro", description = "Macro based commands allow multiple commands to be run", example = "test", videoURL = "http://www.youtube.com/watch?v=hkQfslQJoQs", version = "1.0") +public class Macro extends MultipleCommands { + /** + * The prefix in a player's settings for player specific macros + */ + public static final String SETTINGS_PREFIX = "macro-"; + + /** + * The file extension of macro files + */ + public static final String MACRO_EXTENSION = ".txt"; + /** + * The directory that the macro files and retrieved from + */ + public static final File MACRO_DIR = new File(Constants.MOD_DIR, "macros"); + static { + if (!MACRO_DIR.exists()) { + MACRO_DIR.mkdirs(); + } + } + + /** + * Parameters of the macro command + */ + private static final Parameters MACRO_PARAMS = new Parameters( + new Parameter[] { new ParameterString("", false), + new ParameterString("{PARAMETERS}", true, true) }); + + /** + * Parameters of the setmacro command + */ + private static final Parameters SETMACRO_PARAMS = new Parameters( + new Parameter[] { new ParameterString("", false), + new ParameterString("{COMMANDS}", true, true) }); + + /** + * Parameters of the remove macro command + */ + private static final Parameters REMOVEMACRO_PARAMS = new Parameters( + new Parameter[] { new ParameterString("", false) + }); + + public Macro(String name) { + super(name); + } + + /** + * @see com.sijobe.spc.wrapper.CommandBase#execute(com.sijobe.spc.wrapper.CommandSender, + * java.util.List) + */ + @Override + public void execute(CommandSender sender, List params) + throws CommandException { + + if(getName().equalsIgnoreCase("macro")) { + String macro; + try { + macro = getMacro((String) params.get(0), sender); + } catch (IOException e) { + throw new CommandException("Unable to opening file."); + } + + String split[] = null; + if (params.size() == 1) { + split = new String[] { (String) params.get(0) }; + } else { + split = (((String) params.get(0)) + " " + ((String) params.get(1))) + .split(" "); + } + + String[] lines = macro.replace("\r", "\n").split("\n"); + for (String line : lines) { + if(line.equals("")) { + continue; + } + // Adds arguments to the line + for (int i = 0; i < split.length; i++) { + line = line.replaceAll("\\$_" + i, split[i]); + } + + // Remove all unspecified arguments from line + line = line.replaceAll("\\$_[0-9]+", ""); + + // Executes the line + CommandManager.runCommand(sender, line); + } + } else if(getName().equalsIgnoreCase("setmacro")) { + Player player = getSenderAsPlayer(sender); + if(player == null) { + throw new CommandException("sender must be player"); + } + Settings settings = loadSettings(player); + settings.set(SETTINGS_PREFIX + (String)params.get(0), ((String) params.get(1)).replace("/", "\n\r")); + } else if(getName().equalsIgnoreCase("removemacro")) { + String macro = (String) params.get(0); + Player player = getSenderAsPlayer(sender); + if(player == null) { + throw new CommandException("sender must be player"); + } + Settings settings = loadSettings(player); + if(macro.equals("all")) { + for(Object i : settings.keySet().toArray()) { + if(i instanceof String && ((String) i).startsWith(SETTINGS_PREFIX)) { + settings.remove(i); + } + } + settings.save(); + sender.sendMessageToPlayer("All macros removed."); + return; + } + settings.remove(SETTINGS_PREFIX + macro); + sender.sendMessageToPlayer("Macro " + macro + " removed."); + } else { + assert false : "Invalid command " + getName(); + } + } + + /** + * gets the macro file for a given macro name + * + * @param name + * - the name of the macro (ie. passed through the chat like + * '/macro test') + * @param sender + * - the sender who sent the command + * @return the macro contents (ie the contents of the macro file) + * @throws CommandException + * @throws IOException + * */ + public String getMacro(String name, CommandSender sender) + throws CommandException, IOException { + Player player = getSenderAsPlayer(sender); + if (player != null) { + Settings settings = loadSettings(player); + String key = SETTINGS_PREFIX + name; + if (settings.containsKey(key)) { + return settings.getProperty(key); + } + } + File file = new File(MACRO_DIR, name + MACRO_EXTENSION); + FileInputStream reader; + try { + reader = new FileInputStream(file); + } catch (FileNotFoundException error) { + throw new CommandException("Specified macro does not exist."); + } + byte[] data = new byte[(int) file.length()]; + reader.read(data); + reader.close(); + return new String(data); + } + + /** + * @see com.sijobe.spc.wrapper.CommandBase#getParameters() + */ + @Override + public Parameters getParameters() { + if (getName().equalsIgnoreCase("macro")) { + return MACRO_PARAMS; + } else if (getName().equalsIgnoreCase("setmacro")) { + return SETMACRO_PARAMS; + } else if (getName().equalsIgnoreCase("removemacro")) { + return REMOVEMACRO_PARAMS; + } else { + assert false : "Invalid command name initialsied " + getName(); + return Parameters.DEFAULT; + } + } + + @Override + public String[] getCommands() { + return new String[]{"macro", "setmacro", "removemacro"}; + } +} diff --git a/src/com/sijobe/spc/command/MovePlayer.java b/src/main/java/com/sijobe/spc/command/MovePlayer.java similarity index 93% rename from src/com/sijobe/spc/command/MovePlayer.java rename to src/main/java/com/sijobe/spc/command/MovePlayer.java index 38fd095..426ec2d 100644 --- a/src/com/sijobe/spc/command/MovePlayer.java +++ b/src/main/java/com/sijobe/spc/command/MovePlayer.java @@ -17,6 +17,7 @@ * * @author simo_415 * @version 1.0 + * @status broken through 1.7.2 update -> fixed */ @Command ( name = "moveplayer", @@ -45,10 +46,11 @@ public void execute(CommandSender sender, List params) throws CommandExceptio Player player = super.getSenderAsPlayer(sender); Coordinate c = player.getPosition(); int distance = 0; - try { - distance = Integer.parseInt((String)params.get(0)); - } catch (NumberFormatException e) { - throw new CommandException("Could not parse disance specified as integer: " + params.get(0)); + if(params.get(0) instanceof Integer){ + distance = (Integer)params.get(0); + } + else{ + throw new CommandException("Could not parse disance specified as integer: " + params.get(0)); } if (((String)params.get(1)).toUpperCase().startsWith("N")) { diff --git a/src/com/sijobe/spc/command/MultipleCommands.java b/src/main/java/com/sijobe/spc/command/MultipleCommands.java similarity index 100% rename from src/com/sijobe/spc/command/MultipleCommands.java rename to src/main/java/com/sijobe/spc/command/MultipleCommands.java diff --git a/src/com/sijobe/spc/command/Noclip.java b/src/main/java/com/sijobe/spc/command/Noclip.java similarity index 50% rename from src/com/sijobe/spc/command/Noclip.java rename to src/main/java/com/sijobe/spc/command/Noclip.java index c105e7c..822e506 100644 --- a/src/com/sijobe/spc/command/Noclip.java +++ b/src/main/java/com/sijobe/spc/command/Noclip.java @@ -1,120 +1,77 @@ package com.sijobe.spc.command; -import com.sijobe.spc.overwrite.ONetServerHandler; +import com.sijobe.spc.ModSpc; +import com.sijobe.spc.core.IPlayerMP; +import com.sijobe.spc.network.Config; +import com.sijobe.spc.network.IClientConfig; +import com.sijobe.spc.network.PacketConfig; import com.sijobe.spc.util.FontColour; import com.sijobe.spc.validation.Parameters; import com.sijobe.spc.wrapper.CommandBase; import com.sijobe.spc.wrapper.CommandException; import com.sijobe.spc.wrapper.CommandSender; import com.sijobe.spc.wrapper.Coordinate; -import com.sijobe.spc.wrapper.Minecraft; import com.sijobe.spc.wrapper.Player; import java.util.List; -import net.minecraft.server.MinecraftServer; -import net.minecraft.src.EntityPlayerMP; -import net.minecraft.src.NetServerHandler; +import net.minecraft.util.ChatComponentText; +import net.minecraft.entity.player.EntityPlayerMP; /** * Command for disabling clipping * * @author q3hardcore * @version 1.2 + * @status survived 1.7.2 update but can't see anything while inside blocks -> fixed */ @Command ( - name = "noclip", - description = "Enables and disables the ability to clip for the player", - example = "", - videoURL = "http://www.youtube.com/watch?v=4ZOvu3hf7k0", // video for fly command - enabled = true -) -public class Noclip extends StandardCommand { - + name = "noclip", + description = "Enables and disables the ability to clip for the player", + example = "", + videoURL = "http://www.youtube.com/watch?v=4ZOvu3hf7k0", // video for fly command + enabled = true + ) +public class Noclip extends StandardCommand implements IPlayerMP, IClientConfig { + @Override public void execute(CommandSender sender, List params) throws CommandException { Player player = CommandBase.getSenderAsPlayer(sender); - - System.out.println(player.getUsername() + " " + MinecraftServer.getServer().getServerOwner()); + /*if(!player.getUsername().equals(MinecraftServer.getServer().getServerOwner())) { throw new CommandException("Must be server host"); }*/ if(!player.getMinecraftPlayer().capabilities.isFlying && !player.getMinecraftPlayer().noClip) { throw new CommandException("Must be flying"); } - + if (params.size() == 0) { player.getMinecraftPlayer().noClip ^= true; } else { player.getMinecraftPlayer().noClip = (Boolean)params.get(0); } - - // replace server handler - if(player.getMinecraftPlayer() instanceof EntityPlayerMP) { - updateServerHandler((EntityPlayerMP)player.getMinecraftPlayer()); - } else { - player.getMinecraftPlayer().noClip = false; - throw new CommandException("Noclip unavailable"); - } - + if(player.getMinecraftPlayer().noClip == false) { ascendPlayer(player); } - Minecraft.getMinecraft().thePlayer.noClip = player.getMinecraftPlayer().noClip; + ModSpc.instance.networkHandler.sendTo(new PacketConfig(this.getConfig(), player.getMinecraftPlayer().noClip), (EntityPlayerMP) player.getMinecraftPlayer()); player.sendChatMessage("Noclip is now " + FontColour.AQUA + (!player.getMinecraftPlayer().noClip ? "disabled" : "enabled")); } - + @Override public Parameters getParameters() { return Parameters.DEFAULT_BOOLEAN; } - - private static boolean hasXCommands() { - try { - NetServerHandler.class.getDeclaredField("clientHasXCommands"); - return true; - } catch (Throwable t) { - return false; - } - } - - /** - * Changes server handler to SPC's server handler if noclip is enabled, - * otherwise restores the default server handler. - */ - private static void updateServerHandler(EntityPlayerMP playerEntity) { - if(hasXCommands()) { - return; - } - - NetServerHandler handler = playerEntity.playerNetServerHandler; - - if(playerEntity.noClip) { - if(!(handler instanceof ONetServerHandler)) { - playerEntity.playerNetServerHandler = new ONetServerHandler(MinecraftServer.getServer(), - handler.netManager, handler.playerEntity, handler); - } - } else { - if(handler instanceof ONetServerHandler) { - NetServerHandler oldInstance = ((ONetServerHandler)handler).getOldInstance(); - if(oldInstance != null) { - handler.netManager.setNetHandler(oldInstance); - playerEntity.playerNetServerHandler = oldInstance; - } - } - } - } - + public static void checkSafe(EntityPlayerMP player) { if(player.noClip && !player.capabilities.isFlying) { player.noClip = false; - Minecraft.getMinecraft().thePlayer.noClip = false; - player.addChatMessage("Noclip auto-disabled. (Player not flying)"); - updateServerHandler(player); + ModSpc.instance.networkHandler.sendTo(new PacketConfig(Config.NOCLIP, false), player); + player.addChatMessage(new ChatComponentText("Noclip auto-disabled. (Player not flying)")); ascendPlayer(new Player(player)); } } - + private static boolean ascendPlayer(Player player) { Coordinate playerPos = player.getPosition(); if(player.isClearBelow(playerPos) && playerPos.getY() > 0) { @@ -136,4 +93,23 @@ private static boolean ascendPlayer(Player player) { } return true; } + + @Override + public void init(Object... params) { + } + + @Override + public void onConfigRecieved(Boolean value) { + ModSpc.instance.proxy.getClientPlayer().getMinecraftPlayer().noClip = value; + } + + @Override + public Config getConfig() { + return Config.NOCLIP; + } + + @Override + public void onTick(Player player) { + checkSafe((EntityPlayerMP) player.getMinecraftPlayer()); + } } \ No newline at end of file diff --git a/src/com/sijobe/spc/command/Path.java b/src/main/java/com/sijobe/spc/command/Path.java similarity index 76% rename from src/com/sijobe/spc/command/Path.java rename to src/main/java/com/sijobe/spc/command/Path.java index 37770be..d8a2d46 100644 --- a/src/com/sijobe/spc/command/Path.java +++ b/src/main/java/com/sijobe/spc/command/Path.java @@ -1,26 +1,29 @@ package com.sijobe.spc.command; import com.sijobe.spc.core.IPlayerMP; +import com.sijobe.spc.util.PathData; import com.sijobe.spc.validation.Parameter; import com.sijobe.spc.validation.ParameterInteger; import com.sijobe.spc.validation.ParameterString; import com.sijobe.spc.validation.Parameters; +import com.sijobe.spc.wrapper.Block; +import com.sijobe.spc.wrapper.Blocks; import com.sijobe.spc.wrapper.CommandException; import com.sijobe.spc.wrapper.CommandSender; import com.sijobe.spc.wrapper.Coordinate; -import com.sijobe.spc.wrapper.Item; import com.sijobe.spc.wrapper.Player; import java.util.HashMap; import java.util.List; -import net.minecraft.src.MathHelper; +import net.minecraft.util.MathHelper; /** * Creates a path with the specified size. * * @author q3hardcore * @version 1.4 + * @status broken through 1.7.2 update -> fixed */ @Command ( name = "path", @@ -43,7 +46,7 @@ public class Path extends StandardCommand implements IPlayerMP { /** * A hashmap containing path settings for each player */ - private static HashMap playerConfig = new HashMap(); + private static HashMap playerConfig = new HashMap(); /** * Name of the current world @@ -61,25 +64,25 @@ public void execute(CommandSender sender, List params) throws CommandExceptio if (params.size() >= 1) { String args[] = ((String)params.get(0)).split("(\\^|:)"); - int block = -1; + Block block; int size = 3; int meta = 0; try { - block = Integer.parseInt(args[0]); + block = Block.fromId(Integer.parseInt(args[0])); } catch (NumberFormatException e) { - block = -1; + block = null; } - if (block == -1) { - block = Item.getItemId((args[0]).replace('_', ' ')); + if (block == null) { + block = (Block) Block.blockRegistry.getObject(args[0]); } if (args[0].equalsIgnoreCase("air")) { - block = 0; + block = null; } - if (!player.getWorld().isValidBlockType(block) && block != 0) { // isValidBlockType should be static + if (!player.getWorld().isValidBlockType(block)) { // isValidBlockType should be static throw new CommandException("Unknown block: " + args[0]); } @@ -108,17 +111,17 @@ public void execute(CommandSender sender, List params) throws CommandExceptio } if(playerConfig.containsKey(playerName)) { - int[] plrData = playerConfig.get(playerName); - if(plrData[0] == block && plrData[1] == meta && plrData[2] == size) { + PathData plrData = playerConfig.get(playerName); + if(plrData.block == block && plrData.meta == meta && plrData.size == size) { throw new CommandException("Already making specified type of path!"); } } sender.sendMessageToPlayer("Path mode enabled."); - playerConfig.put(playerName, new int[]{block, meta, size, -1, -1, -1}); - } else if(playerConfig.containsKey(playerName) && playerConfig.get(playerName)[0] > -1) { + playerConfig.put(playerName, new PathData(block, meta, size)); + } else if(playerConfig.containsKey(playerName) && playerConfig.get(playerName).block != null) { sender.sendMessageToPlayer("Path mode disabled."); - playerConfig.get(playerName)[0] = -1; + playerConfig.get(playerName).block = null; } else { throw new CommandException("Must specify block."); } @@ -157,7 +160,7 @@ public void onTick(Player player) { checkWorld(player); String playerName = player.getPlayerName(); if (playerConfig.containsKey(playerName)) { - int[] plrData = playerConfig.get(playerName); + PathData plrData = playerConfig.get(playerName); makePath(player, plrData); } else { return; @@ -171,30 +174,30 @@ public void onTick(Player player) { * @param player - The player that is making a path * @param data - Path data for player */ - private void makePath(Player player, int[] data) { - if (data[0] >= 0) { // block + private void makePath(Player player, PathData data) { + if (data.block != null) { // block Coordinate position = player.getPosition(); int x = MathHelper.floor_double(position.getX()); int y = MathHelper.floor_double(position.getY()); // used to take away 1 int z = MathHelper.floor_double(position.getZ()); - if (x != data[3] || y != data[4] || z != data[5]) { // prevx, prevy, prevz - int start = data[2] * -1 + 1; // size + if (x != data.prevx || y != data.prevy || z != data.prevz) { // prevx, prevy, prevz + int start = data.size * -1 + 1; // size - for (int i = start; i < data[2]; i++) { - for (int j = -1; j < data[2]; j++) { - for (int k = start; k < data[2]; k++) { + for (int i = start; i < data.size; i++) { + for (int j = -1; j < data.size; j++) { + for (int k = start; k < data.size; k++) { if (j == -1) { - this.setBlock(player, x + i, y + j, z + k, data[0], data[1]); + this.setBlock(player, x + i, y + j, z + k, data.block, data.meta); } else { - this.setBlock(player, x + i, y + j, z + k, 0, 0); + this.setBlock(player, x + i, y + j, z + k, Blocks.air, 0); } } } } - data[3] = x; - data[4] = y; - data[5] = z; + data.prevx = x; + data.prevy = y; + data.prevz = z; } } } @@ -211,8 +214,7 @@ private void makePath(Player player, int[] data) { * @param k - The Z position of the block * @param type - The type (ID) of the block */ - private void setBlock(Player player, int i, int j, int k, int type, int meta) { - //player.getWorld().getMinecraftWorld().func_94575_c(i, j, k, type); + private void setBlock(Player player, int i, int j, int k, Block type, int meta) { player.getWorld().setBlockDataWithMeta(new Coordinate(i, j, k), type, meta); } } diff --git a/src/com/sijobe/spc/command/Platform.java b/src/main/java/com/sijobe/spc/command/Platform.java similarity index 88% rename from src/com/sijobe/spc/command/Platform.java rename to src/main/java/com/sijobe/spc/command/Platform.java index 14e2639..e8bb09f 100644 --- a/src/com/sijobe/spc/command/Platform.java +++ b/src/main/java/com/sijobe/spc/command/Platform.java @@ -1,10 +1,13 @@ package com.sijobe.spc.command; +import com.sijobe.spc.wrapper.Block; +import com.sijobe.spc.wrapper.Blocks; import com.sijobe.spc.wrapper.CommandException; import com.sijobe.spc.wrapper.CommandSender; import com.sijobe.spc.wrapper.Coordinate; import com.sijobe.spc.wrapper.Player; + import java.util.List; /** @@ -14,6 +17,7 @@ * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 update */ @Command ( name = "platform", @@ -26,7 +30,7 @@ public class Platform extends StandardCommand { /** * The block ID of glass */ - public static final int BLOCK_GLASS = 20; + public static final Block BLOCK_GLASS = Blocks.glass; /** * @see com.sijobe.spc.wrapper.CommandBase#execute(com.sijobe.spc.wrapper.CommandSender, java.util.List) diff --git a/src/com/sijobe/spc/command/Position.java b/src/main/java/com/sijobe/spc/command/Position.java similarity index 97% rename from src/com/sijobe/spc/command/Position.java rename to src/main/java/com/sijobe/spc/command/Position.java index b7df089..51174f6 100644 --- a/src/com/sijobe/spc/command/Position.java +++ b/src/main/java/com/sijobe/spc/command/Position.java @@ -13,6 +13,7 @@ * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 update */ @Command ( name = "pos", diff --git a/src/com/sijobe/spc/command/PrefixSlash.java b/src/main/java/com/sijobe/spc/command/PrefixSlash.java similarity index 61% rename from src/com/sijobe/spc/command/PrefixSlash.java rename to src/main/java/com/sijobe/spc/command/PrefixSlash.java index c849517..341ed33 100644 --- a/src/com/sijobe/spc/command/PrefixSlash.java +++ b/src/main/java/com/sijobe/spc/command/PrefixSlash.java @@ -6,31 +6,32 @@ import com.sijobe.spc.wrapper.CommandBase; import com.sijobe.spc.wrapper.CommandException; import com.sijobe.spc.wrapper.CommandSender; -import com.sijobe.spc.wrapper.Minecraft; import com.sijobe.spc.wrapper.Player; +import java.util.HashSet; import java.util.List; +import java.util.Set; /** * Command to toggle requiring '/' * * @author q3hardcore * @version 1.0 + * @status broken through 1.7.2 update -> fixed */ @Command ( - name = "prefixslash", - description = "Enables and disables auto slash-prefixing", - example = "", - videoURL = "", - enabled = true -) + name = "prefixslash", + description = "Enables and disables auto slash-prefixing", + example = "", + videoURL = "", + enabled = true + ) public class PrefixSlash extends StandardCommand { - - @Override - public boolean isEnabled() { - return Minecraft.isSinglePlayer(); - } - + /** + * a list of players that have slashes prefixed + */ + public static Set playersUsing = new HashSet(); + @Override public void execute(CommandSender sender, List params) throws CommandException { Player player = CommandBase.getSenderAsPlayer(sender); @@ -41,15 +42,20 @@ public void execute(CommandSender sender, List params) throws CommandExceptio } else { prefixSlash = ((Boolean)params.get(0)); } + if(playersUsing.contains(sender.getSenderName()) && !prefixSlash) { + playersUsing.remove(sender.getSenderName()); + } + else if(!playersUsing.contains(sender.getSenderName()) && prefixSlash){ + playersUsing.add(sender.getSenderName()); + } config.set("prefixSlash", prefixSlash); super.saveSettings(player); player.sendChatMessage("Slash prefixing is now " + FontColour.AQUA - + (prefixSlash ? "enabled" : "disabled")); + + (prefixSlash ? "enabled" : "disabled")); } @Override public Parameters getParameters() { return Parameters.DEFAULT_BOOLEAN; } - } \ No newline at end of file diff --git a/src/com/sijobe/spc/command/Repair.java b/src/main/java/com/sijobe/spc/command/Repair.java similarity index 98% rename from src/com/sijobe/spc/command/Repair.java rename to src/main/java/com/sijobe/spc/command/Repair.java index 89ced34..dc750e8 100644 --- a/src/com/sijobe/spc/command/Repair.java +++ b/src/main/java/com/sijobe/spc/command/Repair.java @@ -15,6 +15,7 @@ * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 update */ @Command ( name = "repair", diff --git a/src/com/sijobe/spc/command/SPC.java b/src/main/java/com/sijobe/spc/command/SPC.java similarity index 98% rename from src/com/sijobe/spc/command/SPC.java rename to src/main/java/com/sijobe/spc/command/SPC.java index 848dfc1..c48de20 100644 --- a/src/com/sijobe/spc/command/SPC.java +++ b/src/main/java/com/sijobe/spc/command/SPC.java @@ -15,6 +15,7 @@ * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 update */ @Command ( name = "spc", diff --git a/src/com/sijobe/spc/command/Scuba.java b/src/main/java/com/sijobe/spc/command/Scuba.java similarity index 98% rename from src/com/sijobe/spc/command/Scuba.java rename to src/main/java/com/sijobe/spc/command/Scuba.java index 8d6ac91..7852609 100644 --- a/src/com/sijobe/spc/command/Scuba.java +++ b/src/main/java/com/sijobe/spc/command/Scuba.java @@ -15,6 +15,7 @@ * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 update */ @Command ( name = "scuba", diff --git a/src/com/sijobe/spc/command/SetSpawn.java b/src/main/java/com/sijobe/spc/command/SetSpawn.java similarity index 98% rename from src/com/sijobe/spc/command/SetSpawn.java rename to src/main/java/com/sijobe/spc/command/SetSpawn.java index 1652ff7..b337068 100644 --- a/src/com/sijobe/spc/command/SetSpawn.java +++ b/src/main/java/com/sijobe/spc/command/SetSpawn.java @@ -17,6 +17,7 @@ * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 update */ @Command ( name = "setspawn", diff --git a/src/main/java/com/sijobe/spc/command/SetSpeed.java b/src/main/java/com/sijobe/spc/command/SetSpeed.java new file mode 100644 index 0000000..b40dfee --- /dev/null +++ b/src/main/java/com/sijobe/spc/command/SetSpeed.java @@ -0,0 +1,86 @@ +package com.sijobe.spc.command; + +import com.sijobe.spc.util.FontColour; +import com.sijobe.spc.util.ReflectionHelper; +import com.sijobe.spc.util.Settings; +import com.sijobe.spc.validation.Parameter; +import com.sijobe.spc.validation.ParameterString; +import com.sijobe.spc.validation.Parameters; +import com.sijobe.spc.wrapper.CommandException; +import com.sijobe.spc.wrapper.CommandSender; + +import java.util.List; + +import net.minecraft.entity.player.PlayerCapabilities; + +/** + * The set speed command allows you to set the speed that the player moves at. + * By default the player speed is 1 where player speed 2 is twice as fast, + * etc.. + * + * @author simo_415 + * @version 1.1 + * @status broken through 1.7.2 update -> fixed + */ +@Command ( + name = "setspeed", + description = "Sets the players speed to the value specified", + example = "2", + videoURL = "http://www.youtube.com/watch?v=G48upLnQr-s", + version = "1.3", + enabled = true + ) +public class SetSpeed extends StandardCommand { + /** + * The parameters of the command + */ + private static final Parameters PARAMETERS = new Parameters ( + new Parameter[] { + new ParameterString("", false), + } + ); + + /** + * The default speed multiplier that the player moves + */ + private static final double DEFAULT_SPEED = 1; + + /** + * The key that is saved into the config + */ + private static final String CONFIG_KEY = "speed"; + + /** + * @see com.sijobe.spc.wrapper.CommandBase#execute(com.sijobe.spc.wrapper.CommandSender, java.util.List) + */ + @Override + public void execute(CommandSender sender, List params) throws CommandException { + Settings config = super.loadSettings(super.getSenderAsPlayer(sender)); + if (((String)params.get(0)).equalsIgnoreCase("reset")) { + config.set(CONFIG_KEY, DEFAULT_SPEED); + } else { + try { + float speed = Float.parseFloat((String)params.get(0)); + config.set(CONFIG_KEY, speed); + PlayerCapabilities capabilities = super.getSenderAsPlayer(sender).getMinecraftPlayer().capabilities; + ReflectionHelper.setField(ReflectionHelper.walkSpeed, capabilities, speed/10); + ReflectionHelper.setField(ReflectionHelper.flySpeed, capabilities, speed/20); + super.getSenderAsPlayer(sender).getMinecraftPlayer().sendPlayerAbilities(); + } catch (NumberFormatException e) { + throw new CommandException("Could not parse " + (String)params.get(0) + " as a speed."); + } + } + config.save(); + + sender.sendMessageToPlayer("Player speed set to " + FontColour.AQUA + + config.getDouble(CONFIG_KEY, DEFAULT_SPEED) + FontColour.WHITE + "x normal speed"); + } + + /** + * @see com.sijobe.spc.wrapper.CommandBase#getParameters() + */ + @Override + public Parameters getParameters() { + return PARAMETERS; + } +} diff --git a/src/com/sijobe/spc/command/Skin.java b/src/main/java/com/sijobe/spc/command/Skin.java similarity index 98% rename from src/com/sijobe/spc/command/Skin.java rename to src/main/java/com/sijobe/spc/command/Skin.java index a06bacc..638cef2 100644 --- a/src/com/sijobe/spc/command/Skin.java +++ b/src/main/java/com/sijobe/spc/command/Skin.java @@ -14,6 +14,7 @@ * * @author simo_415 * @version 1.0 + * @status disabled */ @Command ( name = "skin", diff --git a/src/com/sijobe/spc/command/Spawn.java b/src/main/java/com/sijobe/spc/command/Spawn.java similarity index 96% rename from src/com/sijobe/spc/command/Spawn.java rename to src/main/java/com/sijobe/spc/command/Spawn.java index 7aeacbf..cb2c02e 100644 --- a/src/com/sijobe/spc/command/Spawn.java +++ b/src/main/java/com/sijobe/spc/command/Spawn.java @@ -17,7 +17,10 @@ * the player is looking at. If no position it specified the mobs will spawn * nearby (under 5 blocks from) the player. * + * note: spawning falling sand crashes game * @author simo_415 + * @status survived 1.7.2 update + * @deprecated use summon command instead */ @Command ( name = "spawn", diff --git a/src/main/java/com/sijobe/spc/command/SpawnPortal.java b/src/main/java/com/sijobe/spc/command/SpawnPortal.java new file mode 100644 index 0000000..56446c8 --- /dev/null +++ b/src/main/java/com/sijobe/spc/command/SpawnPortal.java @@ -0,0 +1,140 @@ +package com.sijobe.spc.command; + +import com.sijobe.spc.validation.Parameter; +import com.sijobe.spc.validation.ParameterString; +import com.sijobe.spc.validation.Parameters; +import com.sijobe.spc.wrapper.CommandException; +import com.sijobe.spc.wrapper.CommandSender; +import com.sijobe.spc.wrapper.Coordinate; +import com.sijobe.spc.wrapper.Player; +import com.sijobe.spc.wrapper.World; +import com.sijobe.spc.wrapper.Blocks; + +import net.minecraft.block.BlockEndPortal; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.util.MathHelper; +import net.minecraft.world.Teleporter; + +import java.util.List; + +/** + * Command spawns the specified type of portal + * + * @author q3hardcore + * @version 1.0 + * @survived 1.7.2 update but end portal doesn't work + */ +@Command ( + name = "spawnportal", + description = "Spawns a portal at the players location", + example = "nether", + version = "1.0" +) +public class SpawnPortal extends StandardCommand { + /** + * Specifies the parameters of the command + */ + private static final Parameters PARAMETERS = new Parameters ( + new Parameter[] { + new ParameterString("",false), + } + ); + + /** + * @see com.sijobe.spc.wrapper.CommandBase#execute(net.minecraft.src.ICommandSender, java.util.List) + */ + @Override + public void execute(CommandSender sender, List params) throws CommandException { + Player player = super.getSenderAsPlayer(sender); + String portalType = (String)params.get(0); + if (portalType.equalsIgnoreCase("end")) { + Coordinate coord = player.getPosition(); + int x = MathHelper.floor_double(coord.getX()); + int y = MathHelper.floor_double(coord.getY()+1); + int z = MathHelper.floor_double(coord.getZ()); + this.createEnderPortal(x, z, y, new World(sender.getMinecraftISender().getEntityWorld())); + } else if (portalType.equalsIgnoreCase("nether")) { + EntityPlayerMP playerEntity; + if(player.getMinecraftPlayer() instanceof EntityPlayerMP) { + playerEntity = (EntityPlayerMP)player.getMinecraftPlayer(); + } else { + throw new CommandException("SPC should *NOT* be processing commands client-side!"); + } + (new Teleporter(playerEntity.getServerForPlayer())).makePortal(playerEntity); + } else { + throw new CommandException("Invalid portal type specified."); + } + } + + /** + * @see com.sijobe.spc.wrapper.CommandBase#getParameters() + */ + @Override + public Parameters getParameters() { + return PARAMETERS; + } + + /** + * taken from EntityDragon.createEnderPortal + * Creates the ender portal leading back to the normal world after defeating the enderdragon. + */ + public void createEnderPortal(int x, int z, int level, World worldObj) + { + //byte level = 64; //used to be this in minecraft method + BlockEndPortal.field_149948_a = true; //so dragon eggs don't despawn + byte radius = 4; + + for (int coordy = level - 1; coordy <= level + 32; ++coordy) + { + for (int coordx = x - radius; coordx <= x + radius; ++coordx) + { + for (int coordz = z - radius; coordz <= z + radius; ++coordz) + { + double offsetx = (double)(coordx - x); + double offsetz = (double)(coordz - z); + double dist = offsetx * offsetx + offsetz * offsetz; + + //sqrt isn't used for distance calculations because + //sqrt(x1*x1+y2*y2) < sqrt(x2*x2+y2*y2) will have the same result as + //x1*x1+y2*y2 < x2*x2+y2*y2 + //this takes advantage of the multiplication property of equality + + if (dist <= ((double)radius - 0.5D) * ((double)radius - 0.5D)) //must be within distance + { + if (coordy < level) //lower level + { + //-1 so one block smaller radius + if (dist <= ((double)(radius - 1) - 0.5D) * ((double)(radius - 1) - 0.5D)) //right under end portal + { + worldObj.setBlock(new Coordinate(coordx, coordy, coordz), Blocks.bedrock); + } + } + else if (coordy > level) //above frame + { + worldObj.setBlock(new Coordinate(coordx, coordy, coordz), Blocks.air); + } + else if (dist > ((double)(radius - 1) - 0.5D) * ((double)(radius - 1) - 0.5D)) //forms the end portal ring + { + worldObj.setBlock(new Coordinate(coordx, coordy, coordz), Blocks.bedrock); + } + else //the actual end portal (only occurs on the level) + { + worldObj.setBlock(new Coordinate(coordx, coordy, coordz), Blocks.end_portal); + } + } + } + } + } + + worldObj.setBlock(new Coordinate(x, level + 0, z), Blocks.bedrock); //the column + worldObj.setBlock(new Coordinate(x, level + 1, z), Blocks.bedrock); + worldObj.setBlock(new Coordinate(x, level + 2, z), Blocks.bedrock); + worldObj.setBlock(new Coordinate(x - 1, level + 2, z), Blocks.torch); //torches on the clumn + worldObj.setBlock(new Coordinate(x + 1, level + 2, z), Blocks.torch); + worldObj.setBlock(new Coordinate(x, level + 2, z - 1), Blocks.torch); + worldObj.setBlock(new Coordinate(x, level + 2, z + 1), Blocks.torch); + worldObj.setBlock(new Coordinate(x, level + 3, z), Blocks.bedrock); //another block for the column + worldObj.setBlock(new Coordinate(x, level + 4, z), Blocks.dragon_egg); //tops it off + BlockEndPortal.field_149948_a = false; //reset this field + } +} diff --git a/src/com/sijobe/spc/command/StandardCommand.java b/src/main/java/com/sijobe/spc/command/StandardCommand.java similarity index 72% rename from src/com/sijobe/spc/command/StandardCommand.java rename to src/main/java/com/sijobe/spc/command/StandardCommand.java index 3ab942e..8404ef0 100644 --- a/src/com/sijobe/spc/command/StandardCommand.java +++ b/src/main/java/com/sijobe/spc/command/StandardCommand.java @@ -1,7 +1,6 @@ package com.sijobe.spc.command; import com.sijobe.spc.wrapper.CommandBase; -import com.sijobe.spc.wrapper.CommandSender; /** * Provides an abstract class for a standard (single) command to extend @@ -14,8 +13,4 @@ public abstract class StandardCommand extends CommandBase { /** * @see com.sijobe.spc.wrapper.CommandBase#hasPermission(com.sijobe.spc.wrapper.CommandSender) */ - @Override - public boolean hasPermission(CommandSender sender) { - return true; - } } diff --git a/src/com/sijobe/spc/command/Sudo.java b/src/main/java/com/sijobe/spc/command/Sudo.java similarity index 87% rename from src/com/sijobe/spc/command/Sudo.java rename to src/main/java/com/sijobe/spc/command/Sudo.java index 695a25e..10db27b 100644 --- a/src/com/sijobe/spc/command/Sudo.java +++ b/src/main/java/com/sijobe/spc/command/Sudo.java @@ -16,6 +16,7 @@ * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 update */ @Command ( name = "sudo", @@ -36,16 +37,6 @@ public class Sudo extends StandardCommand { } ); - /** - * Command is only enabled in LAN/SMP mode - * - * @see com.sijobe.spc.wrapper.CommandBase#isEnabled() - */ - /*@Override - public boolean isEnabled() { - return !Minecraft.isSinglePlayer(); - }*/ - @Override public void execute(CommandSender sender, List params) throws CommandException { Player su = (Player)params.get(0); diff --git a/src/com/sijobe/spc/command/SuperHeat.java b/src/main/java/com/sijobe/spc/command/SuperHeat.java similarity index 77% rename from src/com/sijobe/spc/command/SuperHeat.java rename to src/main/java/com/sijobe/spc/command/SuperHeat.java index d2dd511..3f9f054 100644 --- a/src/com/sijobe/spc/command/SuperHeat.java +++ b/src/main/java/com/sijobe/spc/command/SuperHeat.java @@ -8,16 +8,16 @@ import com.sijobe.spc.wrapper.Player; import java.util.List; -import java.util.Map; -import net.minecraft.src.FurnaceRecipes; -import net.minecraft.src.ItemStack; +import net.minecraft.item.crafting.FurnaceRecipes; +import net.minecraft.item.ItemStack; /** * Cooks player's current item or all items * * @author q3hardcore * @version 1.0 + * @status broken through 1.7.2 update -> fixed */ @Command ( name = "superheat", @@ -38,9 +38,6 @@ public class SuperHeat extends StandardCommand { @Override public void execute(CommandSender sender, List params) throws CommandException { - @SuppressWarnings("unchecked") - Map smelt = FurnaceRecipes.smelting().getSmeltingList(); - Player player = getSenderAsPlayer(sender); boolean all = false; @@ -58,13 +55,12 @@ public void execute(CommandSender sender, List params) throws CommandExceptio if (oldStack == null) { continue; } - int key = oldStack.itemID; - if (smelt.containsKey(key) && smelt.get(key) != null) { + + ItemStack newStack = FurnaceRecipes.smelting().getSmeltingResult(oldStack); + if (newStack != null) { int amt = oldStack.stackSize; - ItemStack temp = smelt.get(key); - int id = temp.itemID; - int damage = temp.getItemDamage(); - ItemStack item = new ItemStack(id, amt, damage); + int damage = newStack.getItemDamage(); + ItemStack item = new ItemStack(newStack.getItem(), amt, damage); mainInventory[i] = item; } } diff --git a/src/com/sijobe/spc/command/Teleport.java b/src/main/java/com/sijobe/spc/command/Teleport.java similarity index 98% rename from src/com/sijobe/spc/command/Teleport.java rename to src/main/java/com/sijobe/spc/command/Teleport.java index e1a3a97..c87caf1 100644 --- a/src/com/sijobe/spc/command/Teleport.java +++ b/src/main/java/com/sijobe/spc/command/Teleport.java @@ -16,6 +16,7 @@ * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 update */ @Command ( name = "teleport", diff --git a/src/com/sijobe/spc/command/Test.java b/src/main/java/com/sijobe/spc/command/Test.java similarity index 100% rename from src/com/sijobe/spc/command/Test.java rename to src/main/java/com/sijobe/spc/command/Test.java diff --git a/src/com/sijobe/spc/command/Time.java b/src/main/java/com/sijobe/spc/command/Time.java similarity index 99% rename from src/com/sijobe/spc/command/Time.java rename to src/main/java/com/sijobe/spc/command/Time.java index 8d3ca55..e87e8b1 100644 --- a/src/com/sijobe/spc/command/Time.java +++ b/src/main/java/com/sijobe/spc/command/Time.java @@ -14,6 +14,7 @@ * Provides methods of changing the current Minecraft time * * @author simo_415 + * @status survived 1.7.2 update */ @Command ( name = "time", diff --git a/src/com/sijobe/spc/command/UsePortal.java b/src/main/java/com/sijobe/spc/command/UsePortal.java similarity index 79% rename from src/com/sijobe/spc/command/UsePortal.java rename to src/main/java/com/sijobe/spc/command/UsePortal.java index 45427ab..0c60380 100644 --- a/src/com/sijobe/spc/command/UsePortal.java +++ b/src/main/java/com/sijobe/spc/command/UsePortal.java @@ -14,6 +14,7 @@ * * @author simo_415 * @version 1.0 + * @status broken through 1.7.2 update */ @Command ( name = "useportal", @@ -40,14 +41,14 @@ public void execute(CommandSender sender, List params) throws CommandExceptio Player player = super.getSenderAsPlayer(sender); String type = (String)params.get(0); if (type.equalsIgnoreCase("normal")) { - player.changeDimension(DIMENSION_NORMAL); - } else if (type.equalsIgnoreCase("nether")) { - player.changeDimension(DIMENSION_NETHER); - } else if (type.equalsIgnoreCase("end")) { - player.changeDimension(DIMENSION_END); - } else { - throw new CommandException("Unknown dimension specified"); - } + player.changeDimension(DIMENSION_NORMAL); + } else if (type.equalsIgnoreCase("nether")) { + player.changeDimension(DIMENSION_NETHER); + } else if (type.equalsIgnoreCase("end")) { + player.changeDimension(DIMENSION_END); + } else { + throw new CommandException("Unknown dimension specified"); + } } @Override diff --git a/src/com/sijobe/spc/command/Waypoint.java b/src/main/java/com/sijobe/spc/command/Waypoint.java similarity index 98% rename from src/com/sijobe/spc/command/Waypoint.java rename to src/main/java/com/sijobe/spc/command/Waypoint.java index 7bafcda..72c8d06 100644 --- a/src/com/sijobe/spc/command/Waypoint.java +++ b/src/main/java/com/sijobe/spc/command/Waypoint.java @@ -19,6 +19,7 @@ * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 update */ public class Waypoint extends MultipleCommands { @@ -37,11 +38,6 @@ public Waypoint(String name) { super(name); } - @Override - public boolean isEnabled() { - return true; - } - @Override public String[] getCommands() { return new String[] {"set", "rem", "goto"}; diff --git a/src/com/sijobe/spc/command/Weather.java b/src/main/java/com/sijobe/spc/command/Weather.java similarity index 98% rename from src/com/sijobe/spc/command/Weather.java rename to src/main/java/com/sijobe/spc/command/Weather.java index 86d6e13..af6e957 100644 --- a/src/com/sijobe/spc/command/Weather.java +++ b/src/main/java/com/sijobe/spc/command/Weather.java @@ -22,6 +22,7 @@ * * @author simo_415 * @version 1.0 + * @status survived 1.7.2 update */ @Command ( name = "weather", diff --git a/src/com/sijobe/spc/core/Constants.java b/src/main/java/com/sijobe/spc/core/Constants.java similarity index 78% rename from src/com/sijobe/spc/core/Constants.java rename to src/main/java/com/sijobe/spc/core/Constants.java index 4b946dd..f7ee7ab 100644 --- a/src/com/sijobe/spc/core/Constants.java +++ b/src/main/java/com/sijobe/spc/core/Constants.java @@ -2,7 +2,7 @@ import com.sijobe.spc.updater.ModVersion; import com.sijobe.spc.util.Settings; -import com.sijobe.spc.wrapper.Minecraft; +import com.sijobe.spc.wrapper.MinecraftServer; import java.io.File; import java.util.Date; @@ -14,11 +14,10 @@ * @version 1.0 */ public class Constants { - - /** + /** * Contains the version string of the current Minecraft version */ - public static final String VERSION = "4.9"; + public static final String VERSION = "1.7.2"; /** * The name of the mod @@ -28,12 +27,12 @@ public class Constants { /** * The current version of the mod */ - public static final ModVersion SPC_VERSION = new ModVersion(NAME, VERSION, new Date(1374315917859L)); // 2013-07-20 20:25:17 + public static final ModVersion SPC_VERSION = new ModVersion(NAME, VERSION, new Date(1415419100)); // November 7, 2014 9:58 pm /** * The directory that the mod saves/loads global settings from */ - public static final File MOD_DIR = new File(Minecraft.getMinecraftDirectory(), "mods/spc"); + public static final File MOD_DIR = new File(MinecraftServer.getDirectoryName(), "mods/spc"); // Creates the mod directory if it doesn't already exist static { @@ -50,7 +49,7 @@ public class Constants { /** * Directory where the Minecraft level saves are located */ - public static final File SAVES_DIR = new File(Minecraft.getMinecraftDirectory(), "saves"); + public static final File SAVES_DIR = new File(MinecraftServer.getDirectoryName(), MinecraftServer.getMinecraftServer().isDedicatedServer() ? "" : "saves"); /** * @return the version diff --git a/src/com/sijobe/spc/core/HookManager.java b/src/main/java/com/sijobe/spc/core/HookManager.java similarity index 100% rename from src/com/sijobe/spc/core/HookManager.java rename to src/main/java/com/sijobe/spc/core/HookManager.java diff --git a/src/main/java/com/sijobe/spc/core/IBlockBroken.java b/src/main/java/com/sijobe/spc/core/IBlockBroken.java new file mode 100644 index 0000000..d382372 --- /dev/null +++ b/src/main/java/com/sijobe/spc/core/IBlockBroken.java @@ -0,0 +1,9 @@ +package com.sijobe.spc.core; + +import com.sijobe.spc.wrapper.Block; +import com.sijobe.spc.wrapper.Player; +import com.sijobe.spc.wrapper.World; + +public interface IBlockBroken extends IHook { + public void onBreakBroken(int x, int y, int z, World world, Block block, int metadata, Player player); +} diff --git a/src/main/java/com/sijobe/spc/core/IBreakSpeed.java b/src/main/java/com/sijobe/spc/core/IBreakSpeed.java new file mode 100644 index 0000000..b992984 --- /dev/null +++ b/src/main/java/com/sijobe/spc/core/IBreakSpeed.java @@ -0,0 +1,27 @@ +package com.sijobe.spc.core; + +import com.sijobe.spc.wrapper.Block; +import com.sijobe.spc.wrapper.Player; + + +/** + * Allows commands to change break speed + * Basically a wrapper for forge's BreakSpeed event + * @author aucguy + * + */ +public interface IBreakSpeed extends IHook { + /**called when a player damages a block + * + * @param player - the player that the event occurred on + * @param Block - the block being damaged + * @param metadata - the metadata of the block + * @param originalSpeed - the orginal break speed of the block + * @param x - the x positon of the block + * @param y - the y position of the block + * @param z - the z position of the block + * @return the new breaking speed + * */ + + public float getBreakSpeed(Player player, Block block, int metadata, float orginalSpeed, int x, int y, int z); +} diff --git a/src/com/sijobe/spc/core/ICUIEventHandler.java b/src/main/java/com/sijobe/spc/core/ICUIEventHandler.java similarity index 100% rename from src/com/sijobe/spc/core/ICUIEventHandler.java rename to src/main/java/com/sijobe/spc/core/ICUIEventHandler.java diff --git a/src/com/sijobe/spc/core/IHook.java b/src/main/java/com/sijobe/spc/core/IHook.java similarity index 100% rename from src/com/sijobe/spc/core/IHook.java rename to src/main/java/com/sijobe/spc/core/IHook.java diff --git a/src/com/sijobe/spc/core/IPlayerMP.java b/src/main/java/com/sijobe/spc/core/IPlayerMP.java similarity index 100% rename from src/com/sijobe/spc/core/IPlayerMP.java rename to src/main/java/com/sijobe/spc/core/IPlayerMP.java diff --git a/src/com/sijobe/spc/core/IPlayerSP.java b/src/main/java/com/sijobe/spc/core/IPlayerSP.java similarity index 100% rename from src/com/sijobe/spc/core/IPlayerSP.java rename to src/main/java/com/sijobe/spc/core/IPlayerSP.java diff --git a/src/com/sijobe/spc/core/PlayerMP.java b/src/main/java/com/sijobe/spc/core/PlayerMP.java similarity index 100% rename from src/com/sijobe/spc/core/PlayerMP.java rename to src/main/java/com/sijobe/spc/core/PlayerMP.java diff --git a/src/com/sijobe/spc/core/PlayerSP.java b/src/main/java/com/sijobe/spc/core/PlayerSP.java similarity index 100% rename from src/com/sijobe/spc/core/PlayerSP.java rename to src/main/java/com/sijobe/spc/core/PlayerSP.java diff --git a/src/com/sijobe/spc/core/SPCLoader.java b/src/main/java/com/sijobe/spc/core/SPCLoader.java similarity index 89% rename from src/com/sijobe/spc/core/SPCLoader.java rename to src/main/java/com/sijobe/spc/core/SPCLoader.java index 3fc6be1..0ead5b4 100644 --- a/src/com/sijobe/spc/core/SPCLoader.java +++ b/src/main/java/com/sijobe/spc/core/SPCLoader.java @@ -1,7 +1,7 @@ package com.sijobe.spc.core; import com.sijobe.spc.util.DynamicClassLoader; -import com.sijobe.spc.wrapper.Minecraft; +import com.sijobe.spc.wrapper.MinecraftServer; import java.io.File; @@ -36,8 +36,8 @@ public static void load() { */ private static void loadClasspath() { File classpath[] = DynamicClassLoader.getClasspath(); - //System.out.println("Minecraft: " + Minecraft.getMinecraftDirectory().getAbsolutePath()); - File files[] = (new File(Minecraft.getMinecraftDirectory(),"bin")).listFiles(); + System.out.println("Minecraft: " + MinecraftServer.getDirectoryName()); + File files[] = (new File(MinecraftServer.getDirectoryName(),"bin")).listFiles(); if (files == null) { return; } diff --git a/src/com/sijobe/spc/hooks/CheckUpdates.java b/src/main/java/com/sijobe/spc/hooks/CheckUpdates.java similarity index 100% rename from src/com/sijobe/spc/hooks/CheckUpdates.java rename to src/main/java/com/sijobe/spc/hooks/CheckUpdates.java diff --git a/src/com/sijobe/spc/hooks/InitialiseCommands.java b/src/main/java/com/sijobe/spc/hooks/InitialiseCommands.java similarity index 87% rename from src/com/sijobe/spc/hooks/InitialiseCommands.java rename to src/main/java/com/sijobe/spc/hooks/InitialiseCommands.java index 7d38e62..ff61847 100644 --- a/src/com/sijobe/spc/hooks/InitialiseCommands.java +++ b/src/main/java/com/sijobe/spc/hooks/InitialiseCommands.java @@ -6,7 +6,6 @@ import com.sijobe.spc.core.SPCLoader; import com.sijobe.spc.util.DynamicClassLoader; import com.sijobe.spc.util.FontColour; -import com.sijobe.spc.worldedit.WorldEditEvents; import com.sijobe.spc.wrapper.CommandBase; import com.sijobe.spc.wrapper.CommandManager; import com.sijobe.spc.wrapper.Player; @@ -17,10 +16,14 @@ import java.util.List; /** + * back in 1.6.2... + * * Initialises SPC by adding the commands to the system. The class is * dynamically loaded by the HookManager when hooks of type PlayerMP are * loaded, this is done by the Minecraft class EntityPlayerMP when it is * first referenced using static invokes. + * + * Now this happens through ModSpc.init * * @author simo_415 * @version 1.0 @@ -41,15 +44,22 @@ public class InitialiseCommands extends PlayerMP { * The welcome message to send */ private static final String WELCOME_MESSAGE = FontColour.GREY + - "Single Player Commands (" + Constants.VERSION + ") - " + FontColour.ORANGE + "http://bit.ly/spcmod"; + "Single Player Commands (" + Constants.VERSION + ") - " + FontColour.ORANGE + "http://bit.ly/spcmod <-- link to simo_415 website, not the updater's\n" + + FontColour.WHITE + + "This version of SPC is untested and may contain bugs\n" + + "or cause minecraft to crash.\n" + + "Use at your own risk\n" + + "Also, SPC will not notify you if there is another update;\n" + + "you must check manually.\n" + + "Now SPC does not contain World Edit;\n" + + "you must download it manually."; /** * Pending messages */ - private static final List pendingMessages = new ArrayList(); + public static final List pendingMessages = new ArrayList(); public InitialiseCommands() { - loadCommands(); } @Override @@ -71,14 +81,17 @@ public void onTick(Player player) { * Sends the startup message when the mod has loaded */ private void sendStartupMessage(Player player) { - player.sendChatMessage(WELCOME_MESSAGE); + for(String line : WELCOME_MESSAGE.split("\n")) + { + player.sendChatMessage(line); + } } /** * Loads standard and multiple commands into the game. This method is run * as a thread to keep execution time to a minimum. */ - private void loadCommands() { + public void loadCommands() { (new Thread() { @Override public void run() { @@ -88,17 +101,6 @@ public void run() { // Load Commands Sets loadMultipleCommands(); - try { - if(com.sijobe.spc.worldedit.WorldEditCommandSet.getCurrentInstance() == null) { - Class.forName("com.sk89q.worldedit.WorldEdit"); - System.out.println("SPCommands: Forcing command re-load."); - loadMultipleCommands(); - } - } catch (Throwable t) { - WorldEditEvents.disableHandleEvents(); - pendingMessages.add("WorldEdit.jar not found in .minecraft/bin - WE unavailable."); - } - // Load Standard Commands loadStandardCommands(); IS_LOADED = true; @@ -120,9 +122,11 @@ private void loadStandardCommands() { if (!cmd.isEnabled()) { continue; } + if (doesCommandExist(cmd)) { // TODO: review this System.out.println("Overwriting existing command named: " + cmd.getName()); } + CommandManager.registerCommand(cmd); } catch (Exception e) { System.err.println("There was an issue initialising class " + diff --git a/src/com/sijobe/spc/hooks/TestPlayerMP.java b/src/main/java/com/sijobe/spc/hooks/TestPlayerMP.java similarity index 100% rename from src/com/sijobe/spc/hooks/TestPlayerMP.java rename to src/main/java/com/sijobe/spc/hooks/TestPlayerMP.java diff --git a/src/com/sijobe/spc/hooks/WorldEditCUI.java b/src/main/java/com/sijobe/spc/hooks/WorldEditCUI.java similarity index 91% rename from src/com/sijobe/spc/hooks/WorldEditCUI.java rename to src/main/java/com/sijobe/spc/hooks/WorldEditCUI.java index f2b2414..90c4ce0 100644 --- a/src/com/sijobe/spc/hooks/WorldEditCUI.java +++ b/src/main/java/com/sijobe/spc/hooks/WorldEditCUI.java @@ -5,10 +5,7 @@ import com.sijobe.spc.util.WorldEditCUIHelper; import java.lang.reflect.Field; import java.lang.reflect.Method; -import java.util.Iterator; -import java.util.LinkedList; import java.util.List; -import net.minecraft.src.BaseMod; public class WorldEditCUI implements ICUIEventHandler { @@ -99,12 +96,17 @@ private Object getWorldEditCUIMod() { if(WorldEditCUIMod == null && hasModLoader) { try { Method method = mlClass.getMethod("getLoadedMods"); - List mods = (List)method.invoke(null); - for(BaseMod mod : mods) { - if(mod.getName().equals("mod_WorldEditCUI")) { - loadedWorldEditCUI = true; - return mod; - } + List mods = (List)method.invoke(null); + for(Object mod : mods) { + if(mod.getClass().getName() == "BaseMod") + { + Method meth = mod.getClass().getMethod("getName"); + if(meth.invoke(mod).equals("mod_WorldEditCUI")) + { + loadedWorldEditCUI = true; + return mod; + } + } } } catch (Throwable t) { t.printStackTrace(); @@ -115,7 +117,6 @@ private Object getWorldEditCUIMod() { return null; } - @SuppressWarnings("unchecked") private boolean setWorldEditCUIMod() { WorldEditCUIMod = getWorldEditCUIMod(); return (WorldEditCUIMod != null); diff --git a/src/main/java/com/sijobe/spc/network/Config.java b/src/main/java/com/sijobe/spc/network/Config.java new file mode 100644 index 0000000..dad05db --- /dev/null +++ b/src/main/java/com/sijobe/spc/network/Config.java @@ -0,0 +1,66 @@ +package com.sijobe.spc.network; + +/** + * used to keep track of client side configuration somethings have to be done client side, + * like lighting up the world + * + * @author aucguy + * @version 1.0 + * @param + */ +public final class Config { + /** + * the array of configs. used to bind configs to ids + */ + static Config[] configs = new Config[256]; + public static final Config BLOCK_REACH = new Config(0, Float.class); + public static final Config NOCLIP = new Config(1, Boolean.class); + public static final Config LIGHT = new Config(2, Boolean.class); + public static final Config INSTANT_MINE = new Config(3, Boolean.class); + public static final Config LONGER_LEGS = new Config(4, Float.class); + public static final Config BIND = new Config(5, Integer.class); + + /** + * the id of the Config. Used to find out the contents of a PacketConfig + */ + int id; + + /** + * the payload of the packet and its config type. Used as a workaround of Paramatized types + */ + Class kind; + + /** + * the command that uses the client configurations + */ + private IClientConfig handler; + + /** + * constructs a Config + * @param id - the id of this config + * @param kind - the payload type of this config + */ + private Config(int id, Class kind) { + this.id = id; + this.kind = kind; + configs[this.id] = this; + } + + /** + * Sets the client configuration + * @param value - the value of the config set from the server + */ + void callHook(T value) { + if (this.handler != null) { + this.handler.onConfigRecieved(value); + } + } + + /** + * sets the command that uses this config + * @param handler - the command + */ + public void setHandler(IClientConfig handler) { + this.handler = handler; + } +} diff --git a/src/main/java/com/sijobe/spc/network/ConfigMessageHandler.java b/src/main/java/com/sijobe/spc/network/ConfigMessageHandler.java new file mode 100644 index 0000000..82e5e1a --- /dev/null +++ b/src/main/java/com/sijobe/spc/network/ConfigMessageHandler.java @@ -0,0 +1,27 @@ +package com.sijobe.spc.network; + +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import cpw.mods.fml.relauncher.Side; + +/** + * handles Config Packets from the server + * + * @author aucguy + * @version 1.0 + */ +public class ConfigMessageHandler implements IMessageHandler { + @Override + public DummyMessage onMessage(PacketConfig message, MessageContext ctx) { + if(ctx.side != Side.CLIENT) { + System.out.println("Config packet handled on server side. Abandon Ship!"); + return null; + } + + if(message.value != null) { + message.config.callHook(message.value); + } + return null; + } +} diff --git a/src/main/java/com/sijobe/spc/network/DummyMessage.java b/src/main/java/com/sijobe/spc/network/DummyMessage.java new file mode 100644 index 0000000..6b60682 --- /dev/null +++ b/src/main/java/com/sijobe/spc/network/DummyMessage.java @@ -0,0 +1,15 @@ +package com.sijobe.spc.network; + +import io.netty.buffer.ByteBuf; +import cpw.mods.fml.common.network.simpleimpl.IMessage; + +public class DummyMessage implements IMessage { + + @Override + public void fromBytes(ByteBuf buf) { + } + + @Override + public void toBytes(ByteBuf buf) { + } +} diff --git a/src/main/java/com/sijobe/spc/network/IClientConfig.java b/src/main/java/com/sijobe/spc/network/IClientConfig.java new file mode 100644 index 0000000..f0bc5db --- /dev/null +++ b/src/main/java/com/sijobe/spc/network/IClientConfig.java @@ -0,0 +1,16 @@ +package com.sijobe.spc.network; + +import com.sijobe.spc.core.IHook; + +/** + * used to signify that a command uses client-sided configurations + * + * @author aucguy + * + * @param - the payload and configuration type + */ +public interface IClientConfig extends IHook { + public void onConfigRecieved(T value); + + Config getConfig(); +} diff --git a/src/main/java/com/sijobe/spc/network/PacketConfig.java b/src/main/java/com/sijobe/spc/network/PacketConfig.java new file mode 100644 index 0000000..09f32c3 --- /dev/null +++ b/src/main/java/com/sijobe/spc/network/PacketConfig.java @@ -0,0 +1,58 @@ +package com.sijobe.spc.network; + +import io.netty.buffer.ByteBuf; +import cpw.mods.fml.common.network.simpleimpl.IMessage; + +/** + * Sets client configurations + * + * @author aucguy + * @version 1.0 + */ +public class PacketConfig implements IMessage { + Config config; + Object value; + + public PacketConfig() { + } + + public PacketConfig(Config config, Object value) { + this.config = config; + this.value = value; + if (!this.value.getClass().equals(this.config.kind)) { + throw (new IllegalArgumentException("value must be of type " + this.config.kind.getName() + " but instead was of type " + this.value.getClass().getName())); + } + } + + @Override + public void fromBytes(ByteBuf buf) { + byte id = buf.readByte(); + if (id > Config.configs.length || Config.configs[id] == null) { + return; + } + this.config = Config.configs[id]; + if (this.config.kind.equals(Boolean.class)) { + this.value = buf.readBoolean(); + } else if (this.config.kind.equals(Integer.class)) { + this.value = buf.readInt(); + } else if (this.config.kind.equals(Double.class)) { + this.value = buf.readDouble(); + } else if (this.config.kind.equals(Float.class)) { + this.value = buf.readFloat(); + } + } + + @Override + public void toBytes(ByteBuf buf) { + buf.writeByte(this.config.id); + if (this.config.kind.equals(Boolean.class)) { + buf.writeBoolean((Boolean) this.value); + } else if (this.config.kind.equals(Integer.class)) { + buf.writeInt((Integer) this.value); + } else if (this.config.kind.equals(Double.class)) { + buf.writeDouble((Double) this.value); + } else if (this.config.kind.equals(Float.class)) { + buf.writeFloat((Float) this.value); + } + } +} diff --git a/src/main/java/com/sijobe/spc/proxy/Proxy.java b/src/main/java/com/sijobe/spc/proxy/Proxy.java new file mode 100644 index 0000000..ab39085 --- /dev/null +++ b/src/main/java/com/sijobe/spc/proxy/Proxy.java @@ -0,0 +1,69 @@ +package com.sijobe.spc.proxy; + +import java.io.File; + +import com.sijobe.spc.wrapper.Player; + +import net.minecraft.world.EnumDifficulty; + +/** + * used so that side specific classes don't load on the wrong side + * + * @author aucguy + * @version 1.0 + */ +public abstract class Proxy { + /** + * @return file directory for the Minecraft Client + */ + public abstract File getDataDirectory(); + + /** + * @return the player on the client + */ + public abstract Player getClientPlayer(); + + /** + * @return whethor or not minecraft should render the inside of a block while + * inside of a block + */ + public abstract boolean shouldNotRenderInsideOfBlock(); + + /** + * sets the difficulty client-side (so it displays up correctly on the pause + * menu) + * + * @param difficulty - what to set the difficulty to + */ + public abstract void setDifficulty(EnumDifficulty difficulty); + + /** + * sets the client lighting status + * + * @param isLit - false if the world is lit normally, true if the world is to + * be fully lit + */ + public abstract void setClientLighting(boolean isLit); + + /** + * returns whether or not the client has a gui screen open + * + * @return + */ + public abstract boolean isClientGuiScreenOpen(); + + /** + * sends a chat packet to the server + * + * @param string - the chat to send + */ + public abstract void sendClientChat(String string); + + /** + * sets the block hit delay for the client. The block hit delay is how long to + * wait before the player starts the mine the next block + * + * @param delay - the block hit delay + */ + public abstract void setClientHitDelay(int delay); +} diff --git a/src/main/java/com/sijobe/spc/proxy/client/ClientProxy.java b/src/main/java/com/sijobe/spc/proxy/client/ClientProxy.java new file mode 100644 index 0000000..5922d17 --- /dev/null +++ b/src/main/java/com/sijobe/spc/proxy/client/ClientProxy.java @@ -0,0 +1,84 @@ +package com.sijobe.spc.proxy.client; + +import java.io.File; +import java.lang.reflect.Field; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.PlayerControllerMP; +import net.minecraft.client.network.NetHandlerPlayClient; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.network.Packet; +import net.minecraft.network.play.client.C01PacketChatMessage; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.EnumDifficulty; + +import com.sijobe.spc.proxy.Proxy; +import com.sijobe.spc.util.ReflectionHelper; +import com.sijobe.spc.wrapper.Player; + +public class ClientProxy extends Proxy { + public static final Field blockHitDelayField = ReflectionHelper.getField(PlayerControllerMP.class, "blockHitDelay", "i", "field_78781_i"); + + @Override + public File getDataDirectory() { + return MinecraftClient.getMinecraftDirectory(); + } + + @Override + public Player getClientPlayer() { + return new Player(Minecraft.getMinecraft().thePlayer); + } + + @Override + public boolean shouldNotRenderInsideOfBlock() { + return Minecraft.getMinecraft().thePlayer.noClip; + } + + @Override + public void setDifficulty(EnumDifficulty difficulty) { + Minecraft.getMinecraft().gameSettings.difficulty = difficulty; + } + + @Override + public void setClientLighting(boolean isLit) { + EntityPlayer player = Minecraft.getMinecraft().thePlayer; + if (isLit) { + player.addChatMessage(new ChatComponentText("Lighting world")); + float[] lightBrightnessTable = player.worldObj.provider.lightBrightnessTable; + for (int i = 0; i < lightBrightnessTable.length; i++) { + lightBrightnessTable[i] = 1.0F; + } + } else { + player.addChatMessage(new ChatComponentText("Restoring light levels")); + /*copied from WorldProvider.generateLightBrightnessTable*/ + float f = 0.0F; + + for (int i = 0; i <= 15; ++i) { + float f1 = 1.0F - (float) i / 15.0F; + player.worldObj.provider.lightBrightnessTable[i] = (1.0F - f1) / (f1 * 3.0F + 1.0F) + * (1.0F - f) + f; + } + } + } + + @Override + public boolean isClientGuiScreenOpen() { + return MinecraftClient.isGuiScreenOpen(); + } + + @Override + public void sendClientChat(String message) { + NetHandlerPlayClient handler = MinecraftClient.getMinecraft() + .getNetHandler(); + if (handler != null) { + Packet packet = new C01PacketChatMessage(message); + handler.addToSendQueue(packet); + } + } + + @Override + public void setClientHitDelay(int delay) { + ReflectionHelper.setField(blockHitDelayField, Minecraft + .getMinecraft().playerController, delay); + } +} \ No newline at end of file diff --git a/src/com/sijobe/spc/wrapper/Minecraft.java b/src/main/java/com/sijobe/spc/proxy/client/MinecraftClient.java similarity index 85% rename from src/com/sijobe/spc/wrapper/Minecraft.java rename to src/main/java/com/sijobe/spc/proxy/client/MinecraftClient.java index b969814..2f50002 100644 --- a/src/com/sijobe/spc/wrapper/Minecraft.java +++ b/src/main/java/com/sijobe/spc/proxy/client/MinecraftClient.java @@ -1,14 +1,16 @@ -package com.sijobe.spc.wrapper; +package com.sijobe.spc.proxy.client; import java.io.File; +import com.sijobe.spc.wrapper.Player; + /** * Provides a wrapper around the Minecraft class * * @author simo_415 * @version 1.0 */ -public class Minecraft { +public class MinecraftClient { /** * Gets the directory that Minecraft is installed in @@ -24,8 +26,8 @@ public static File getMinecraftDirectory() { * * @return The Minecraft instance */ - public static net.minecraft.src.Minecraft getMinecraft() { - return net.minecraft.src.Minecraft.getMinecraft(); + public static net.minecraft.client.Minecraft getMinecraft() { + return net.minecraft.client.Minecraft.getMinecraft(); } /** diff --git a/src/main/java/com/sijobe/spc/proxy/server/ServerProxy.java b/src/main/java/com/sijobe/spc/proxy/server/ServerProxy.java new file mode 100644 index 0000000..430cc64 --- /dev/null +++ b/src/main/java/com/sijobe/spc/proxy/server/ServerProxy.java @@ -0,0 +1,56 @@ +package com.sijobe.spc.proxy.server; + +import java.io.File; +import java.lang.reflect.Field; + +import net.minecraft.server.dedicated.DedicatedServer; +import net.minecraft.world.EnumDifficulty; +import net.minecraft.server.dedicated.PropertyManager; + +import com.sijobe.spc.proxy.Proxy; +import com.sijobe.spc.util.ReflectionHelper; +import com.sijobe.spc.wrapper.MinecraftServer; +import com.sijobe.spc.wrapper.Player; + +public class ServerProxy extends Proxy { + public static final Field settingsField = ReflectionHelper.getField(DedicatedServer.class, "settings", "l", "field_71340_o"); + + @Override + public File getDataDirectory() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Player getClientPlayer() { + return null; + } + + @Override + public boolean shouldNotRenderInsideOfBlock() { + return false; + } + + @Override + public void setDifficulty(EnumDifficulty difficulty) { + DedicatedServer server = (DedicatedServer) MinecraftServer.getMinecraftServer(); + ((PropertyManager) ReflectionHelper.getObj(settingsField, server)).setProperty("difficulty", difficulty.getDifficultyId()); + } + + @Override + public void setClientLighting(boolean isLit) { + } + + @Override + public boolean isClientGuiScreenOpen() { + return false; + } + + @Override + public void sendClientChat(String string) { + } + + @Override + public void setClientHitDelay(int delay) { + } +} diff --git a/src/com/sijobe/spc/updater/CheckVersion.java b/src/main/java/com/sijobe/spc/updater/CheckVersion.java similarity index 99% rename from src/com/sijobe/spc/updater/CheckVersion.java rename to src/main/java/com/sijobe/spc/updater/CheckVersion.java index 2173fe4..9657ff2 100644 --- a/src/com/sijobe/spc/updater/CheckVersion.java +++ b/src/main/java/com/sijobe/spc/updater/CheckVersion.java @@ -45,6 +45,7 @@ public CheckVersion(ModVersion project[], String mcver, UpdateCallback callback) * * @see java.lang.Thread#run() */ + @SuppressWarnings("unchecked") public void run() { // download file File f = downloadFile(MANIFEST); diff --git a/src/com/sijobe/spc/updater/ModVersion.java b/src/main/java/com/sijobe/spc/updater/ModVersion.java similarity index 100% rename from src/com/sijobe/spc/updater/ModVersion.java rename to src/main/java/com/sijobe/spc/updater/ModVersion.java diff --git a/src/com/sijobe/spc/updater/UpdateCallback.java b/src/main/java/com/sijobe/spc/updater/UpdateCallback.java similarity index 100% rename from src/com/sijobe/spc/updater/UpdateCallback.java rename to src/main/java/com/sijobe/spc/updater/UpdateCallback.java diff --git a/src/com/sijobe/spc/util/CommandBlockHelper.java b/src/main/java/com/sijobe/spc/util/CommandBlockHelper.java similarity index 71% rename from src/com/sijobe/spc/util/CommandBlockHelper.java rename to src/main/java/com/sijobe/spc/util/CommandBlockHelper.java index 8a75d83..53fe8cb 100644 --- a/src/com/sijobe/spc/util/CommandBlockHelper.java +++ b/src/main/java/com/sijobe/spc/util/CommandBlockHelper.java @@ -4,20 +4,21 @@ import java.util.List; import net.minecraft.server.MinecraftServer; -import net.minecraft.src.CommandBase; -import net.minecraft.src.CommandDifficulty; -import net.minecraft.src.CommandEffect; -import net.minecraft.src.CommandEnchant; -import net.minecraft.src.CommandException; -import net.minecraft.src.CommandGameMode; -import net.minecraft.src.CommandGive; -import net.minecraft.src.CommandHelp; -import net.minecraft.src.CommandTime; -import net.minecraft.src.CommandWeather; -import net.minecraft.src.EntityPlayerMP; -import net.minecraft.src.EnumChatFormatting; -import net.minecraft.src.ICommandSender; -import net.minecraft.src.StatCollector; +import net.minecraft.command.CommandBase; +import net.minecraft.command.CommandDifficulty; +import net.minecraft.command.CommandEffect; +import net.minecraft.command.CommandEnchant; +import net.minecraft.command.CommandException; +import net.minecraft.command.CommandGameMode; +import net.minecraft.command.CommandGive; +import net.minecraft.command.CommandHelp; +import net.minecraft.command.CommandTime; +import net.minecraft.command.CommandWeather; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.command.ICommandSender; +import net.minecraft.util.StatCollector; /** * Helper to make command blocks execute vanilla commands @@ -42,7 +43,7 @@ public static boolean handleCommand(String cmdName, ICommandSender sender, Strin for(EntityPlayerMP plr : players) { if(plr.canCommandSenderUseCommand(2, "") && plr.capabilities.isCreativeMode) { String cmdErr = StatCollector.translateToLocalFormatted(ce.getMessage(), ce.getErrorOjbects()); - plr.addChatMessage(EnumChatFormatting.RED + cmdErr); + plr.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + cmdErr)); } } } diff --git a/src/com/sijobe/spc/util/DynamicClassLoader.java b/src/main/java/com/sijobe/spc/util/DynamicClassLoader.java similarity index 97% rename from src/com/sijobe/spc/util/DynamicClassLoader.java rename to src/main/java/com/sijobe/spc/util/DynamicClassLoader.java index fcb4465..efdd620 100644 --- a/src/com/sijobe/spc/util/DynamicClassLoader.java +++ b/src/main/java/com/sijobe/spc/util/DynamicClassLoader.java @@ -30,14 +30,6 @@ public class DynamicClassLoader { */ private static URLClassLoader CLASSLOADER; - /** - * Flag designates whether the populateClassLoaderWithClasses method has - * been called yet or not. - * - * @see DynamicClassLoader#populateClassLoaderWithClasses() - */ - private static boolean POPULATED = false; - /* * A vector used to store all SPC classes */ @@ -150,7 +142,7 @@ private static Vector> getSPCClasses() throws Exception { System.out.println("SPC: " + root); tempSPCClasses = loadSPCClassesFromJAR(root); } else { - File dynamicClassLoader = new File(location.getFile()); + File dynamicClassLoader = new File(location.getFile().replace("%20", " ")); //added replace for paths with spaces File parentDir = getSPCParent(dynamicClassLoader); if(parentDir == null) { System.out.println("SPC: Not loading."); @@ -203,9 +195,9 @@ public static List> loadSPCClassesFromDirectory(File directory, String File files[] = directory.listFiles(); for (File file : files) { try { - if (file.isFile()) { + if (file.isFile() && file.getPath().endsWith(".class")) { //TODO add class file type check to loadSPCClassesFromJar classes.add(loadClass(file.getName(),parent)); - } else { + } else if(file.isDirectory()){ classes.addAll(loadSPCClassesFromDirectory(file,parent + file.getName() + "/")); } } catch (Exception e) { @@ -242,6 +234,7 @@ public static List> loadSPCClassesFromJAR(File jar) { } catch (Throwable t) { } } + jf.close(); } catch (Exception e) { e.printStackTrace(); return null; diff --git a/src/com/sijobe/spc/util/FontColour.java b/src/main/java/com/sijobe/spc/util/FontColour.java similarity index 100% rename from src/com/sijobe/spc/util/FontColour.java rename to src/main/java/com/sijobe/spc/util/FontColour.java diff --git a/src/com/sijobe/spc/util/KeyListener.java b/src/main/java/com/sijobe/spc/util/KeyListener.java similarity index 100% rename from src/com/sijobe/spc/util/KeyListener.java rename to src/main/java/com/sijobe/spc/util/KeyListener.java diff --git a/src/com/sijobe/spc/util/KeyboardHandler.java b/src/main/java/com/sijobe/spc/util/KeyboardHandler.java similarity index 97% rename from src/com/sijobe/spc/util/KeyboardHandler.java rename to src/main/java/com/sijobe/spc/util/KeyboardHandler.java index e1c39a5..ad036b4 100644 --- a/src/com/sijobe/spc/util/KeyboardHandler.java +++ b/src/main/java/com/sijobe/spc/util/KeyboardHandler.java @@ -19,7 +19,7 @@ * @see org.lwjgl.input.Keyboard */ public class KeyboardHandler extends Thread { - + /** * The delay in milliseconds that the keyboard events are checked */ @@ -36,12 +36,12 @@ public class KeyboardHandler extends Thread { public static KeyboardHandler getInstance() { return KEYBOARD; } - + /** * Holds the value of whether the instance is currently listening or not */ private boolean listening; - + /** * A List of keys that are currently registered with this listener */ @@ -50,7 +50,7 @@ public static KeyboardHandler getInstance() { * A List of keys that have currently been pressed */ private List pressed; - + /** * A Map containing the registered pressed event listeners */ @@ -59,7 +59,7 @@ public static KeyboardHandler getInstance() { * A Map containing the registered released event listeners */ private Map> registeredReleased; - + /** * Default private constructor sets up the instance */ @@ -70,7 +70,7 @@ private KeyboardHandler() { keys = new CopyOnWriteArrayList(); listening = false; } - + /** * Checks for key press and key release events * @@ -106,7 +106,7 @@ public void run() { listening = false; } } - + /** * Calls all of the necessary listeners based off the key pressed * @@ -121,7 +121,7 @@ private void keyPressed(int key) { listener.keyPressed(key); } } - + /** * Calls all of the necessary listeners based off the key released * @@ -136,14 +136,14 @@ private void keyReleased(int key) { listener.keyReleased(key); } } - + /** * Stops the instance from listening */ public void stopListening() { listening = false; } - + /** * Adds a key press listener to the specified key. See the Keyboard class * for details on the key codes. @@ -156,7 +156,7 @@ public void stopListening() { public boolean addKeyPressedListener(int key, KeyListener listener) { return addListener(key, listener, registeredPressed); } - + /** * Adds a key release listener to the specified key. See the Keyboard class * for details on the key codes. @@ -169,7 +169,7 @@ public boolean addKeyPressedListener(int key, KeyListener listener) { public boolean addKeyReleasedListener(int key, KeyListener listener) { return addListener(key, listener, registeredReleased); } - + /** * Generic implementation that adds the specified key and listener to the * provided internal listener map. @@ -220,7 +220,7 @@ public void removeKeyPressedListener(int key, KeyListener listener) { public void removeKeyReleasedListener(int key, KeyListener listener) { removeListener(key, listener, registeredReleased); } - + /** * Removes the specified key and listener instance from the specified Map * listener. @@ -242,7 +242,7 @@ private void removeListener(int key, KeyListener listener, Map getBaseClass(Class clazz) { - if(clazz == null) { - System.err.println("No class specified."); - return null; - } - Class baseClass; - while((baseClass = clazz.getSuperclass()) != null && !baseClass.getName().equals(blacklistedClass)) { - clazz = baseClass; - } - return clazz; - } + if (clazz == null) { + System.err.println("No class specified."); + return null; + } + Class baseClass; + while ((baseClass = clazz.getSuperclass()) != null + && !baseClass.getName().equals(blacklistedClass)) { + clazz = baseClass; + } + return clazz; + } /** - * Finds the first method with that matches the specified name and parameters length - * + * Finds the first method with that matches the specified name and parameters + * length + * * @param clazz - The class to search * @param name - The method name * @param length - The parameter length * @return The first matching method, or null - */ + */ public static Method getPublicMethodWithParamsLength(Class clazz, String name, int length) { - if(clazz == null) { + if (clazz == null) { System.err.println("No class specified."); return null; } try { Method[] methods = clazz.getMethods(); - for(Method method : methods) { + for (Method method : methods) { boolean correctName = method.getName().equals(name); - if(correctName && method.getParameterTypes().length == length) { + if (correctName && method.getParameterTypes().length == length) { return method; } } @@ -65,19 +79,20 @@ public static Method getPublicMethodWithParamsLength(Class clazz, String name /** * Finds the first class that matches one of the names specified - * + * * @param classes - A list of all class names * @return The first class found, or null - */ - public static Class getClass(String ... classes) { - if(classes.length == 0) { + */ + public static Class getClass(String... classes) { + if (classes.length == 0) { System.err.println("No classes specified."); return null; } - for(String name : classes) { + for (String name : classes) { try { return Class.forName(name); - } catch (Throwable t) {} + } catch (Throwable t) { + } } return null; @@ -91,18 +106,19 @@ public static Class getClass(String ... classes) { * @return The value of the field */ public static boolean getBoolean(Field field, Object instance) { - if(field == null) { + if (field == null) { System.err.println("Null field"); return false; } try { return field.getBoolean(instance); } catch (Exception e) { - System.err.println(field.getType() + " not assignable from " + Boolean.TYPE); + System.err.println(field.getType() + " not assignable from " + + Boolean.TYPE); return false; } } - + /** * Gets a double value from the specified field * @@ -111,18 +127,19 @@ public static boolean getBoolean(Field field, Object instance) { * @return The value of the field */ public static double getDouble(Field field, Object instance) { - if(field == null) { + if (field == null) { System.err.println("Null field"); return -1.0D; } try { return field.getDouble(instance); } catch (Exception e) { - System.err.println(field.getType() + " not assignable from " + Double.TYPE); + System.err.println(field.getType() + " not assignable from " + + Double.TYPE); return -1.0D; } } - + /** * Gets an integer value from the specified field * @@ -131,50 +148,72 @@ public static double getDouble(Field field, Object instance) { * @return The value of the field */ public static int getInt(Field field, Object instance) { - if(field == null) { + if (field == null) { System.err.println("Null field"); return -1; } try { return field.getInt(instance); } catch (Exception e) { - System.err.println(field.getType() + " not assignable from " + Integer.TYPE); + System.err.println(field.getType() + " not assignable from " + + Integer.TYPE); return -1; } } - /** - * Sets the specified field to the specified value in the instance. + * Gets an object value from the specified field + * + * @param field - The field to get the value for + * @param instance - The instance to retrieve the value from + * @return The value of the field + */ + public static Object getObj(Field field, Object instance) { + if (field == null) { + System.err.println("Null field"); + return null; + } + try { + return field.get(instance); + } catch (Exception e) { + System.err.println(field.getType() + " not assignable from " + + Integer.TYPE); + return null; + } + } + + /** + * Sets the specified field to the specified value in the instance. * * @param field - The field to set * @param instance - The instance of the field to set * @param value - The value to set the field - * @return True if setting the field was successful. + * @return True if setting the field was successful. */ public static boolean setField(Field field, Object instance, Object value) { - if(field == null) { + if (field == null) { System.err.println("Null field"); return false; } try { field.set(instance, value); } catch (Exception e) { - System.err.println(field.getType() + " not assignable from " + value.getClass()); + System.err.println(field.getType() + " not assignable from " + + value.getClass()); return false; } return true; } - + /** * Attempts to get a constructor from the specified class - * + * * @param class - The class to retrieve constructor from * @param params - The parameters for the constructor * @return The constructor if found, otherwise null - */ - public static Constructor getConstructor(Class clazz, Class ... params) { - if(clazz == null) { + */ + public static Constructor getConstructor(Class clazz, Class... params) { + if (clazz == null) { System.err.println("No class specified."); return null; } @@ -183,13 +222,15 @@ public static Constructor getConstructor(Class clazz, Class ... params) constructor = clazz.getDeclaredConstructor(params); } catch (NoSuchMethodException nsme) { } - if(constructor == null) { - System.err.println(clazz.getName() + "does not have specified constructor"); + if (constructor == null) { + System.err.println(clazz.getName() + + "does not have specified constructor"); return null; } else { try { constructor.setAccessible(true); - } catch (SecurityException se) {} + } catch (SecurityException se) { + } return constructor; } } @@ -202,8 +243,8 @@ public static Constructor getConstructor(Class clazz, Class ... params) * @param params - A list of the methods parameters * @return The Method that matched, or null */ - public static Method getMethod(Class clazz, String methodName, Class ... params) { - return getMethod(clazz, new String[]{methodName}, params); + public static Method getMethod(Class clazz, String methodName, Class... params) { + return getMethod(clazz, new String[] { methodName }, params); } /** @@ -214,17 +255,17 @@ public static Method getMethod(Class clazz, String methodName, Class ... p * @param params - A list of the methods parameters * @return The Method that matched, or null */ - public static Method getMethod(Class clazz, String[] methodNames, Class ... params) { - if(clazz == null) { + public static Method getMethod(Class clazz, String[] methodNames, Class... params) { + if (clazz == null) { System.err.println("No class specified."); return null; } - if(methodNames == null || methodNames.length < 1) { + if (methodNames == null || methodNames.length < 1) { System.err.println("No methodNames specified."); return null; } Method method = null; - for(String methodName : methodNames) { + for (String methodName : methodNames) { try { method = clazz.getDeclaredMethod(methodName, params); break; @@ -234,16 +275,18 @@ public static Method getMethod(Class clazz, String[] methodNames, Class .. continue; } } - if(method == null) { - System.err.println(clazz.getName() + " does not have method " + methodNames[0]); - return null; + if (method == null) { + System.err.println(clazz.getName() + " does not have method " + + methodNames[0]); + return null; } else { try { method.setAccessible(true); - } catch (SecurityException se) {} + } catch (SecurityException se) { + } return method; } - } + } /** * Gets a field based off the field names provided by return the first one @@ -253,17 +296,17 @@ public static Method getMethod(Class clazz, String[] methodNames, Class .. * @param clazz - The class to retrieve the field from * @return The Field that matched, or null */ - public static Field getField(Class clazz, String ... fieldNames) { - if(clazz == null) { + public static Field getField(Class clazz, String... fieldNames) { + if (clazz == null) { System.err.println("No class specified."); return null; } - if(fieldNames == null || fieldNames.length < 1) { + if (fieldNames == null || fieldNames.length < 1) { System.err.println("No field name(s) specified."); return null; } Field field = null; - for(String fieldName : fieldNames) { + for (String fieldName : fieldNames) { try { field = clazz.getDeclaredField(fieldName); break; @@ -271,17 +314,19 @@ public static Field getField(Class clazz, String ... fieldNames) { continue; } } - if(field == null) { - System.err.println(clazz.getName() + " does not have field " + fieldNames[0]); - return null; + if (field == null) { + System.err.println(clazz.getName() + " does not have field " + + fieldNames[0]); + return null; } else { try { field.setAccessible(true); - } catch (SecurityException se) {} + } catch (SecurityException se) { + } return field; } } - + /** * Gets the field that matches the field names * @@ -289,12 +334,12 @@ public static Field getField(Class clazz, String ... fieldNames) { * @param instance - The instance (class) of the field * @return The field if found, or null */ - public static Field getField(Object instance, String ... fieldNames) { - if(instance != null) { + public static Field getField(Object instance, String... fieldNames) { + if (instance != null) { return getField(instance.getClass(), fieldNames); } else { return null; } } - + } \ No newline at end of file diff --git a/src/main/java/com/sijobe/spc/util/RegistryIdCompatible.java b/src/main/java/com/sijobe/spc/util/RegistryIdCompatible.java new file mode 100644 index 0000000..5e21be9 --- /dev/null +++ b/src/main/java/com/sijobe/spc/util/RegistryIdCompatible.java @@ -0,0 +1,21 @@ +package com.sijobe.spc.util; + +import net.minecraft.util.RegistryNamespaced; + +public class RegistryIdCompatible extends RegistryNamespaced { + @Override + public Object getObject(String name) { + if(this.containsKey(name)) { + return super.getObject(name); + } + else { + try { + int num = Integer.parseInt(name); + return this.getObjectById(num); + } + catch(NumberFormatException error) { + return null; + } + } + } +} diff --git a/src/com/sijobe/spc/util/Settings.java b/src/main/java/com/sijobe/spc/util/Settings.java similarity index 100% rename from src/com/sijobe/spc/util/Settings.java rename to src/main/java/com/sijobe/spc/util/Settings.java diff --git a/src/com/sijobe/spc/util/SettingsManager.java b/src/main/java/com/sijobe/spc/util/SettingsManager.java similarity index 100% rename from src/com/sijobe/spc/util/SettingsManager.java rename to src/main/java/com/sijobe/spc/util/SettingsManager.java diff --git a/src/com/sijobe/spc/util/WorldEditCUIHelper.java b/src/main/java/com/sijobe/spc/util/WorldEditCUIHelper.java similarity index 100% rename from src/com/sijobe/spc/util/WorldEditCUIHelper.java rename to src/main/java/com/sijobe/spc/util/WorldEditCUIHelper.java diff --git a/src/com/sijobe/spc/validation/Parameter.java b/src/main/java/com/sijobe/spc/validation/Parameter.java similarity index 100% rename from src/com/sijobe/spc/validation/Parameter.java rename to src/main/java/com/sijobe/spc/validation/Parameter.java diff --git a/src/com/sijobe/spc/validation/ParameterBoolean.java b/src/main/java/com/sijobe/spc/validation/ParameterBoolean.java similarity index 100% rename from src/com/sijobe/spc/validation/ParameterBoolean.java rename to src/main/java/com/sijobe/spc/validation/ParameterBoolean.java diff --git a/src/com/sijobe/spc/validation/ParameterDouble.java b/src/main/java/com/sijobe/spc/validation/ParameterDouble.java similarity index 100% rename from src/com/sijobe/spc/validation/ParameterDouble.java rename to src/main/java/com/sijobe/spc/validation/ParameterDouble.java diff --git a/src/com/sijobe/spc/validation/ParameterInteger.java b/src/main/java/com/sijobe/spc/validation/ParameterInteger.java similarity index 100% rename from src/com/sijobe/spc/validation/ParameterInteger.java rename to src/main/java/com/sijobe/spc/validation/ParameterInteger.java diff --git a/src/com/sijobe/spc/validation/ParameterLong.java b/src/main/java/com/sijobe/spc/validation/ParameterLong.java similarity index 100% rename from src/com/sijobe/spc/validation/ParameterLong.java rename to src/main/java/com/sijobe/spc/validation/ParameterLong.java diff --git a/src/com/sijobe/spc/validation/ParameterPlayer.java b/src/main/java/com/sijobe/spc/validation/ParameterPlayer.java similarity index 100% rename from src/com/sijobe/spc/validation/ParameterPlayer.java rename to src/main/java/com/sijobe/spc/validation/ParameterPlayer.java diff --git a/src/com/sijobe/spc/validation/ParameterString.java b/src/main/java/com/sijobe/spc/validation/ParameterString.java similarity index 100% rename from src/com/sijobe/spc/validation/ParameterString.java rename to src/main/java/com/sijobe/spc/validation/ParameterString.java diff --git a/src/com/sijobe/spc/validation/Parameters.java b/src/main/java/com/sijobe/spc/validation/Parameters.java similarity index 100% rename from src/com/sijobe/spc/validation/Parameters.java rename to src/main/java/com/sijobe/spc/validation/Parameters.java diff --git a/src/com/sijobe/spc/validation/ValidationException.java b/src/main/java/com/sijobe/spc/validation/ValidationException.java similarity index 100% rename from src/com/sijobe/spc/validation/ValidationException.java rename to src/main/java/com/sijobe/spc/validation/ValidationException.java diff --git a/src/main/java/com/sijobe/spc/wrapper/Block.java b/src/main/java/com/sijobe/spc/wrapper/Block.java new file mode 100644 index 0000000..3e10830 --- /dev/null +++ b/src/main/java/com/sijobe/spc/wrapper/Block.java @@ -0,0 +1,85 @@ +package com.sijobe.spc.wrapper; + +import java.util.HashMap; +import java.util.Map; + +import com.sijobe.spc.util.RegistryIdCompatible; + +import net.minecraft.util.RegistryNamespaced; + +/** + * a wrapper block class + * + * @author aucguy + * @version 1.0 + */ +public class Block { + /** + * the wrapped block registry + */ + public static final RegistryNamespaced blockRegistry = new RegistryIdCompatible(); + + /** + * minecraft to wrapped block bindings + */ + public static final Map conversionRegistry = new HashMap(); + + /** + * the minecraft block registry + */ + public static final RegistryNamespaced realBlockRegistry = net.minecraft.block.Block.blockRegistry; + + /** + * initializes the block and conversion registry + */ + public static void init() { + /* registers blocks */ + for (Object i : realBlockRegistry) { + net.minecraft.block.Block block = (net.minecraft.block.Block) i; + int id = realBlockRegistry.getIDForObject(block); + Block wrapped = new Block(block); + blockRegistry.addObject(id, realBlockRegistry.getNameForObject(block), wrapped); + conversionRegistry.put(block, wrapped); + } + Blocks.init(); + } + + /** + * + * @param id - the id of the block + * @return the block with the given id + */ + public static Block fromId(int id) { + return (Block) blockRegistry.getObject(realBlockRegistry.getNameForObject(realBlockRegistry.getObjectById(id))); + } + + /** + * converts a minecraft block to a wrapped block. opposite of Block.convert() + * + * @param block - the minecraft block to convert + * @return - the wrapped block + */ + public static Block fromMinecraftBlock(net.minecraft.block.Block block) { + return conversionRegistry.get(block); + } + + /** + * the minecraft block associated with this instance + */ + protected net.minecraft.block.Block block; + + /** + * constructs a wrapped block + * @param block - the minecraft block + */ + public Block(net.minecraft.block.Block block) { + this.block = block; + } + + /** + * @return the equivant minecraft block + */ + public net.minecraft.block.Block convert() { + return this.block; + } +} diff --git a/src/main/java/com/sijobe/spc/wrapper/Blocks.java b/src/main/java/com/sijobe/spc/wrapper/Blocks.java new file mode 100644 index 0000000..cf6d910 --- /dev/null +++ b/src/main/java/com/sijobe/spc/wrapper/Blocks.java @@ -0,0 +1,32 @@ +package com.sijobe.spc.wrapper; + +/** + * kinda like net.minecraft.init.Blocks, but a wrapper + * + * @author aucguy + * @version 1.0 + */ +public class Blocks +{ + public static Block air; + public static Block fire; + public static Block glass; + public static Block bedrock; + public static Block end_portal; + public static Block torch; + public static Block dragon_egg; + + /** + * initializes the blocks + */ + static void init() + { + air = (Block) Block.blockRegistry.getObject("minecraft:air"); + fire = (Block) Block.blockRegistry.getObject("minecraft:fire"); + glass = (Block) Block.blockRegistry.getObject("minecraft:glass"); + bedrock = (Block) Block.blockRegistry.getObject("minecraft:bedrock"); + end_portal = (Block) Block.blockRegistry.getObject("minecraft:end_portal"); + torch = (Block) Block.blockRegistry.getObject("minecraft:torch"); + dragon_egg = (Block) Block.blockRegistry.getObject("minecraft:dragon_egg"); + } +} diff --git a/src/com/sijobe/spc/wrapper/CommandBase.java b/src/main/java/com/sijobe/spc/wrapper/CommandBase.java similarity index 95% rename from src/com/sijobe/spc/wrapper/CommandBase.java rename to src/main/java/com/sijobe/spc/wrapper/CommandBase.java index da0dcf7..10f11ab 100644 --- a/src/com/sijobe/spc/wrapper/CommandBase.java +++ b/src/main/java/com/sijobe/spc/wrapper/CommandBase.java @@ -15,9 +15,9 @@ import java.util.List; import java.util.Map; -import net.minecraft.src.ChatMessageComponent; -import net.minecraft.src.EntityPlayerMP; -import net.minecraft.src.ICommandSender; +import net.minecraft.util.ChatComponentText; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.command.ICommandSender; /** * Provides a base class for all custom commands to extend. All non-abstract @@ -29,7 +29,7 @@ * @author simo_415 * @version 1.3 */ -public abstract class CommandBase extends net.minecraft.src.CommandBase { +public abstract class CommandBase extends net.minecraft.command.CommandBase { /** * A map containing all settings managers that have been loaded for worlds @@ -104,7 +104,7 @@ public void processCommand(final ICommandSender sender, String[] args) { if(sender.getCommandSenderName().equals("@")) { if(args.length >= 1) { if(getName().equals("sudo")) { - args[0] = func_82359_c(sender, args[0]).getCommandSenderName(); + args[0] = getPlayer(sender, args[0]).getCommandSenderName(); } else { String cmd = getCommandName(); for(String part : args) { @@ -114,8 +114,8 @@ public void processCommand(final ICommandSender sender, String[] args) { System.out.println("SPC/CommandBlock: " + cmd); EntityPlayerMP player; try { - player = func_82359_c(sender, args[0]); - } catch (net.minecraft.src.PlayerNotFoundException pnfe) { + player = getPlayer(sender, args[0]); + } catch (net.minecraft.command.PlayerNotFoundException pnfe) { System.out.println("SPC/CommandBlock: Warning - " + getCommandName() + " is a player command."); throw pnfe; } @@ -150,7 +150,7 @@ public void processCommand(final ICommandSender sender, String[] args) { } private void sendChatMessage(ICommandSender sender, String message) { - sender.sendChatToPlayer(ChatMessageComponent.func_111066_d(message)); + sender.addChatMessage(new ChatComponentText(message)); } /** @@ -332,7 +332,7 @@ public static Settings loadSettings(Player player) { if (player == null) { return null; } - String directoryName = MinecraftServer.getDirectoryName(); + String directoryName = MinecraftServer.getWorldFolder(); SettingsManager manager = MANAGER.get(directoryName); if (manager == null) { File spcPlayers = new File(MinecraftServer.getWorldDirectory(), "spc/players"); diff --git a/src/com/sijobe/spc/wrapper/CommandException.java b/src/main/java/com/sijobe/spc/wrapper/CommandException.java similarity index 100% rename from src/com/sijobe/spc/wrapper/CommandException.java rename to src/main/java/com/sijobe/spc/wrapper/CommandException.java diff --git a/src/com/sijobe/spc/wrapper/CommandManager.java b/src/main/java/com/sijobe/spc/wrapper/CommandManager.java similarity index 96% rename from src/com/sijobe/spc/wrapper/CommandManager.java rename to src/main/java/com/sijobe/spc/wrapper/CommandManager.java index 913fdde..1e22179 100644 --- a/src/com/sijobe/spc/wrapper/CommandManager.java +++ b/src/main/java/com/sijobe/spc/wrapper/CommandManager.java @@ -4,8 +4,8 @@ import java.util.List; import java.util.Map; -import net.minecraft.src.ICommand; -import net.minecraft.src.ServerCommandManager; +import net.minecraft.command.ICommand; +import net.minecraft.command.ServerCommandManager; /** * Provides methods to allow easy access to the server command manager and its @@ -63,6 +63,7 @@ public static boolean doesCommandExist(String name) { * * @return A List of command names in Minecraft */ + @SuppressWarnings("unchecked") public static List getCommandNames() { return new ArrayList(getCommandManager().getCommands().keySet()); } @@ -162,6 +163,7 @@ public static boolean hasPermission(String name, Player player) { * * @return The command map */ + @SuppressWarnings("unchecked") private static Map getCommandMap() { return getCommandManager().getCommands(); } diff --git a/src/com/sijobe/spc/wrapper/CommandSender.java b/src/main/java/com/sijobe/spc/wrapper/CommandSender.java similarity index 90% rename from src/com/sijobe/spc/wrapper/CommandSender.java rename to src/main/java/com/sijobe/spc/wrapper/CommandSender.java index 97e142a..1baa9a0 100644 --- a/src/com/sijobe/spc/wrapper/CommandSender.java +++ b/src/main/java/com/sijobe/spc/wrapper/CommandSender.java @@ -1,9 +1,9 @@ package com.sijobe.spc.wrapper; -import net.minecraft.src.ChatMessageComponent; -import net.minecraft.src.EntityPlayer; -import net.minecraft.src.ICommandSender; -import net.minecraft.src.StatCollector; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.command.ICommandSender; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.StatCollector; /** * Provides a wrapper around the ICommandSender interface @@ -57,7 +57,7 @@ public boolean canUseCommand(String command) { * @param message - The message to display */ public void sendMessageToPlayer(String message) { - sender.sendChatToPlayer(ChatMessageComponent.func_111066_d(message)); + sender.addChatMessage(new ChatComponentText(message)); } /** diff --git a/src/com/sijobe/spc/wrapper/Coordinate.java b/src/main/java/com/sijobe/spc/wrapper/Coordinate.java similarity index 100% rename from src/com/sijobe/spc/wrapper/Coordinate.java rename to src/main/java/com/sijobe/spc/wrapper/Coordinate.java diff --git a/src/com/sijobe/spc/wrapper/Entity.java b/src/main/java/com/sijobe/spc/wrapper/Entity.java similarity index 77% rename from src/com/sijobe/spc/wrapper/Entity.java rename to src/main/java/com/sijobe/spc/wrapper/Entity.java index 96be054..616cbfb 100644 --- a/src/com/sijobe/spc/wrapper/Entity.java +++ b/src/main/java/com/sijobe/spc/wrapper/Entity.java @@ -5,11 +5,11 @@ import java.util.List; import java.util.Map; -import net.minecraft.src.DamageSource; -import net.minecraft.src.EntityList; -import net.minecraft.src.EntityLiving; -import net.minecraft.src.EntityLivingData; -import net.minecraft.src.EntityPlayer; +import net.minecraft.util.DamageSource; +import net.minecraft.entity.EntityList; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.IEntityLivingData; +import net.minecraft.entity.player.EntityPlayer; /** * Contains methods that manage entities within the game @@ -43,6 +43,7 @@ public class Entity { * @param value - The class of the value * @return The matching entity list, or null if not found */ + @SuppressWarnings("unchecked") private static Map getEntityList(Class key, Class value) { Map map = null; try { @@ -136,10 +137,10 @@ public static boolean spawnEntity(String entity, Coordinate location, World worl Class entityClass = getEntityClass(entity); try { if (entityClass != null) { - net.minecraft.src.Entity entityInstance = (net.minecraft.src.Entity)entityClass.getConstructor(net.minecraft.src.World.class).newInstance(world.getMinecraftWorld()); + net.minecraft.entity.Entity entityInstance = (net.minecraft.entity.Entity)entityClass.getConstructor(net.minecraft.world.World.class).newInstance(world.getMinecraftWorld()); entityInstance.setPosition(location.getX(), location.getY() + 1, location.getZ()); if(entityInstance instanceof EntityLiving) { - ((EntityLiving)entityInstance).func_110161_a((EntityLivingData)null); + ((EntityLiving)entityInstance).onSpawnWithEgg((IEntityLivingData)null); //func_110161_a in 1.6.2, I don't know if I changed it to the right method } world.getMinecraftWorld().spawnEntityInWorld(entityInstance); if(entityInstance instanceof EntityLiving) { @@ -153,15 +154,15 @@ public static boolean spawnEntity(String entity, Coordinate location, World worl return false; } - public static List killEntities(String entity, Coordinate location, World world, double distance) { - List removedEntities = new ArrayList(); + public static List killEntities(String entity, Coordinate location, World world, double distance) { + List removedEntities = new ArrayList(); Class entityClass = getEntityClass(entity); int count = 0; try { if (entityClass != null) { - List toremove = new ArrayList(); - List entities = getLoadedEntities(world); - for (net.minecraft.src.Entity loaded : entities) { + List toremove = new ArrayList(); + List entities = getLoadedEntities(world); + for (net.minecraft.entity.Entity loaded : entities) { if(!(entityClass.isInstance(loaded))) { continue; } @@ -169,7 +170,7 @@ public static List killEntities(String entity, Coordin toremove.add(loaded); } } - for (net.minecraft.src.Entity remove : toremove) { + for (net.minecraft.entity.Entity remove : toremove) { if(remove instanceof EntityPlayer) { continue; } @@ -189,15 +190,15 @@ public static List killEntities(String entity, Coordin return removedEntities; } - public static List findEntities(String entity, Coordinate location, World world, double distance) { - List foundEntities = new ArrayList(); + public static List findEntities(String entity, Coordinate location, World world, double distance) { + List foundEntities = new ArrayList(); Class entityClass = getEntityClass(entity); int count = 0; try { if (entityClass != null) { - List found = new ArrayList(); - List entities = getLoadedEntities(world); - for (net.minecraft.src.Entity loaded : entities) { + List found = new ArrayList(); + List entities = getLoadedEntities(world); + for (net.minecraft.entity.Entity loaded : entities) { if(!(entityClass.isInstance(loaded))) { continue; } @@ -205,7 +206,7 @@ public static List findEntities(String entity, Coordin found.add(loaded); } } - for (net.minecraft.src.Entity foundEntity : found) { + for (net.minecraft.entity.Entity foundEntity : found) { // we don't currently exclude any entities foundEntities.add(foundEntity); count++; @@ -223,7 +224,8 @@ public static List findEntities(String entity, Coordin * @param world - The world to get the loaded entities from * @return A List of loaded entities */ - private static List getLoadedEntities(World world) { + @SuppressWarnings("unchecked") + private static List getLoadedEntities(World world) { return world.getMinecraftWorld().loadedEntityList; } } diff --git a/src/com/sijobe/spc/wrapper/Item.java b/src/main/java/com/sijobe/spc/wrapper/Item.java similarity index 57% rename from src/com/sijobe/spc/wrapper/Item.java rename to src/main/java/com/sijobe/spc/wrapper/Item.java index b1139cf..3b5ec28 100644 --- a/src/com/sijobe/spc/wrapper/Item.java +++ b/src/main/java/com/sijobe/spc/wrapper/Item.java @@ -2,75 +2,102 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; -import net.minecraft.src.Enchantment; -import net.minecraft.src.ItemStack; -import net.minecraft.src.StatCollector; +import com.sijobe.spc.util.RegistryIdCompatible; -public class Item { +import net.minecraft.enchantment.Enchantment; +import net.minecraft.item.ItemStack; +import net.minecraft.util.RegistryNamespaced; +import net.minecraft.util.StatCollector; +public class Item { /** * A list of item names that are loaded in the game */ - private static final List ITEM_NAMES; - static { - ITEM_NAMES = new ArrayList(); - for (net.minecraft.src.Item item : net.minecraft.src.Item.itemsList) { - if (item != null) { - ITEM_NAMES.add(StatCollector.translateToLocal(item.getUnlocalizedName())); - } else { - ITEM_NAMES.add(null); - } + public static final RegistryNamespaced itemRegistry = new RegistryIdCompatible(); + + /** + * binds minecraft items to wrapped items + */ + public static final Map conversionRegistry = new HashMap(); + + /** + * the minecraft item registry + */ + public static final RegistryNamespaced realItemRegistry = net.minecraft.item.Item.itemRegistry; + + /** + * initializes the itemRegistry and conversionRegistry + */ + public static void init() { + for (Object i : net.minecraft.item.Item.itemRegistry) { + net.minecraft.item.Item item = (net.minecraft.item.Item) i; + int id = realItemRegistry.getIDForObject(item); + Item wrapped = new Item(item); + itemRegistry.addObject(id, realItemRegistry.getNameForObject(item), wrapped); + conversionRegistry.put(item, wrapped); } } - + /** - * Translates the item code name into the item display name - * - * @param toTranslate - The item name to translate - * @return The display name of the item + * the equivalent minecraft item */ - /*public static String translateItemName(String toTranslate) { - return StringTranslate.getInstance().translateNamedKey(toTranslate).toString().trim(); - }*/ - + protected net.minecraft.item.Item item; + + public Item(net.minecraft.item.Item item) { + this.item = item; + } + + /** + * convert a wrapped item into a minecraft item + * @return the wrapped item + */ + public net.minecraft.item.Item convert() { + return this.item; + } + /** * Gets the item id of the specified item denoted by the string name * - * @param itemName - The name of the item - * @return the id of the item. If the item doesn't exist -1 is returned + * @param itemName - The name of the item + * @return the id of the item. If the item doesn't exist null is returned */ - public static int getItemId(String itemName) { - return ITEM_NAMES.indexOf(itemName.toLowerCase()); + public static Item getItem(String itemName) { + return (Item) itemRegistry.getObject(itemName); } - + + /** + * the converts the item to a minecraft item + * @param item - the minecraft item + * @return - the wrapped item + */ + public static Item getMinecraftItem(net.minecraft.item.Item item) { + return conversionRegistry.get(item); + } + /** * Returns true if the specified item id denotes a valid item * * @param id - The id of the item to check * @return true is returned if the id is valid, false otherwise */ - public static boolean isValidItem(int id) { - if (id < 0 || id > ITEM_NAMES.size()) { - return false; - } - return ITEM_NAMES.get(id) != null; + public static boolean isValidItem(Item item) { + return !(item == null) && itemRegistry.containsKey(itemRegistry.getNameForObject(item)); } - + /** - * Gets the maximum stack size of the specified item + * TODO: remove arguement Gets the maximum stack size of the specified item * - * @param id - The id of the item + * @param id - does nothing * @return The stack size of the item, or 0 if not valid */ - public static int getMaxStack(int id) { - if (isValidItem(id)) { - return net.minecraft.src.Item.itemsList[id].getItemStackLimit(); - } - return 0; + public int getMaxStack(Item id) { + return this.item.getItemStackLimit(); } - + /** * Gets a list containing all of the loaded enchantments * @@ -88,11 +115,11 @@ public static List getEnchantments() { } return names; } - + /** - * Adds the specified enchantment to the currently selected item in the + * Adds the specified enchantment to the currently selected item in the * players inventory - * + * * @param player - The player to add the enchantment to * @param enchantment - The enchantment to add * @param level - The level of the enchantment diff --git a/src/com/sijobe/spc/wrapper/MinecraftServer.java b/src/main/java/com/sijobe/spc/wrapper/MinecraftServer.java similarity index 65% rename from src/com/sijobe/spc/wrapper/MinecraftServer.java rename to src/main/java/com/sijobe/spc/wrapper/MinecraftServer.java index e3794c1..4061fe8 100644 --- a/src/com/sijobe/spc/wrapper/MinecraftServer.java +++ b/src/main/java/com/sijobe/spc/wrapper/MinecraftServer.java @@ -1,10 +1,15 @@ package com.sijobe.spc.wrapper; import java.io.File; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; +import com.sijobe.spc.ModSpc; import com.sijobe.spc.core.Constants; +import com.sijobe.spc.util.ReflectionHelper; + +import cpw.mods.fml.relauncher.Side; /** * Wrapper around the MinecraftServer class providing. @@ -12,7 +17,7 @@ * @author simo_415 */ public class MinecraftServer { - + /** * Gets the instance of the Minecraft server that is running * @@ -80,7 +85,7 @@ public static Player getPlayerByUsername(String username) { * @see CommandManager#runCommand(CommandSender, String) */ public static String runCommand(String command) { - return getMinecraftServer().executeCommand(command); + return getMinecraftServer().handleRConCommand(command); } /** @@ -88,7 +93,7 @@ public static String runCommand(String command) { * * @return The directory name of the world */ - public static String getDirectoryName() { + public static String getDirectoryName_() { return getMinecraftServer().getFolderName(); } @@ -98,6 +103,44 @@ public static String getDirectoryName() { * @return The location where the world is located */ public static File getWorldDirectory() { - return new File(Constants.SAVES_DIR, getDirectoryName()); + return new File(Constants.SAVES_DIR, getWorldFolder()); + } + + public static String getWorldFolder() { + return getMinecraftServer().getFolderName(); + } + + public static String getDirectoryName() { + if(ModSpc.instance.side == Side.SERVER) { + String dir = null; + try { + dir = ((File) ReflectionHelper.getDataDirectory.invoke(getMinecraftServer())).getAbsolutePath(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if(dir == null) { + return dir; + } + if(dir.endsWith(".")) { + dir = dir.substring(0, dir.length()-1); + } + return dir; + } + else if(ModSpc.instance.side == Side.CLIENT){ + return ModSpc.instance.proxy.getDataDirectory().getAbsolutePath(); + } + else { + return null; + } } -} +} \ No newline at end of file diff --git a/src/com/sijobe/spc/wrapper/Player.java b/src/main/java/com/sijobe/spc/wrapper/Player.java similarity index 81% rename from src/com/sijobe/spc/wrapper/Player.java rename to src/main/java/com/sijobe/spc/wrapper/Player.java index 488a2ef..87d78b7 100644 --- a/src/com/sijobe/spc/wrapper/Player.java +++ b/src/main/java/com/sijobe/spc/wrapper/Player.java @@ -1,13 +1,16 @@ package com.sijobe.spc.wrapper; -import net.minecraft.src.EntityClientPlayerMP; -import net.minecraft.src.EntityPlayer; -import net.minecraft.src.EntityPlayerMP; -import net.minecraft.src.EnumGameType; -import net.minecraft.src.ItemStack; -import net.minecraft.src.MovingObjectPosition; -import net.minecraft.src.PotionEffect; -import net.minecraft.src.Vec3; +import net.minecraft.client.entity.EntityClientPlayerMP; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.world.WorldSettings.GameType; + + +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.Vec3; /** * Provides a wrapper around the Minecraft player classes. @@ -103,7 +106,7 @@ public World getWorld() { * @param message - The message to send to the user */ public void sendChatMessage(String message) { - player.addChatMessage(message); + player.addChatMessage(new ChatComponentText(message)); } /** @@ -111,8 +114,8 @@ public void sendChatMessage(String message) { * * @param id - The item id */ - public void givePlayerItem(int id) { - givePlayerItem(id, Item.getMaxStack(id)); + public void givePlayerItem(Item item) { + givePlayerItem(item, item.getMaxStack(item)); } /** @@ -121,7 +124,7 @@ public void givePlayerItem(int id) { * @param id - The item id * @param quantity - The quantity of the item */ - public void givePlayerItem(int id, int quantity) { + public void givePlayerItem(Item id, int quantity) { givePlayerItem(id, quantity, 0); } @@ -132,12 +135,21 @@ public void givePlayerItem(int id, int quantity) { * @param quantity - The quantity of the item * @param damage - The "damage" (metadata) value of the item */ - public void givePlayerItem(int id, int quantity, int damage) { - ItemStack itemStack = new ItemStack(id, quantity, damage); + public void givePlayerItem(Item item, int quantity, int damage) { + ItemStack itemStack = new ItemStack(item.convert(), quantity, damage); if (!player.inventory.addItemStackToInventory(itemStack)) { - player.dropPlayerItem(itemStack); + player.dropPlayerItemWithRandomChoice(itemStack, false); } } + + /*in 1.6.2 givePlayerItem(Item) + * gives the player the item but the player will drop something their inventory is full*/ + public void givePlayerItemWithDrop(Item item) { + ItemStack itemStack = new ItemStack(item.convert()); + if (!player.inventory.addItemStackToInventory(itemStack)) { + player.dropPlayerItemWithRandomChoice(itemStack, false); + } + } /** * Gets the players current health @@ -145,7 +157,7 @@ public void givePlayerItem(int id, int quantity, int damage) { * @return The value of the players health */ public float getHealth() { - return player.func_110143_aJ(); + return player.getHealth(); } /** @@ -154,7 +166,7 @@ public float getHealth() { * @param health - The health amount */ public void setHealth(float health) { - player.setEntityHealth(health); + player.setHealth(health); } /** @@ -212,17 +224,17 @@ public void setDamage(boolean damage) { * @param damage - The item "damage" value * @return True if the slot was correctly set, false otherwise */ - public boolean setInventorySlot(int slot, int id, int quantity, int damage) { + public boolean setInventorySlot(int slot, Item item, int quantity, int damage) { if (slot < 0 || slot >= player.inventory.mainInventory.length) { return false; - } else if (!Item.isValidItem(id)) { - if (id == 0) { + } else if (!Item.isValidItem(item)) { + if (item == null) { player.inventory.mainInventory[slot] = null; return true; } return false; } - player.inventory.mainInventory[slot] = new ItemStack(id, quantity, damage); + player.inventory.mainInventory[slot] = new ItemStack(item.convert(), quantity, damage); return true; } @@ -244,10 +256,11 @@ public Coordinate trace(double distance) { } public MovingObjectPosition rayTrace(double distance, float partialTickTime) { + //was this rayTrace supposed to include liquids or not? //probably not liquids Vec3 positionVec = getPositionVec(partialTickTime); Vec3 lookVec = player.getLook(partialTickTime); Vec3 hitVec = positionVec.addVector(lookVec.xCoord * distance, lookVec.yCoord * distance, lookVec.zCoord * distance); - return player.worldObj.rayTraceBlocks_do_do(positionVec, hitVec, false, true); // TODO: Validate correct params + return player.worldObj.rayTraceBlocks(positionVec, hitVec, false); // TODO: Validate correct params } /** @@ -275,8 +288,8 @@ public Vec3 getPositionVec(float partialTickTime) { * @return True if the specified gametype was found */ public boolean setGameType(String gametype) { - EnumGameType chosen = null; - if ((chosen = EnumGameType.getByName(gametype)) == null) { + GameType chosen = null; + if ((chosen = GameType.getByName(gametype)) == null) { return false; } player.setGameType(chosen); @@ -289,7 +302,7 @@ public boolean setGameType(String gametype) { * @return The players name */ public String getPlayerName() { - return player.getEntityName(); + return player.getCommandSenderName(); } /** @@ -297,11 +310,11 @@ public String getPlayerName() { * * @return The ID of the currently held item */ - public int getCurrentItem() { + public Item getCurrentItem() { try { - return player.inventory.mainInventory[getCurrentSlot()].itemID; + return new Item(player.inventory.mainInventory[getCurrentSlot()].getItem()); } catch (NullPointerException e) { - return 0; + return null; } } @@ -355,9 +368,9 @@ public Coordinate getMotion() { * @return True if the player can stand in the specified location */ public boolean isClear(Coordinate location) { - return getWorld().getBlockId(location.getBlockX(), location.getBlockY(), location.getBlockZ()) == 0 - && getWorld().getBlockId(location.getBlockX(), location.getBlockY() + 1, location.getBlockZ()) == 0 - && !(getWorld().getBlockId(location.getBlockX(), location.getBlockY() - 1, location.getBlockZ()) == 0); + return getWorld().getBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ()) == Blocks.air + && getWorld().getBlock(location.getBlockX(), location.getBlockY() + 1, location.getBlockZ()) == Blocks.air + && !(getWorld().getBlock(location.getBlockX(), location.getBlockY() - 1, location.getBlockZ()) == Blocks.air); } /** @@ -372,9 +385,9 @@ && getWorld().getBlockId(location.getBlockX(), location.getBlockY() + 1, locatio * @return True if the player can fall in the specified location */ public boolean isClearBelow(Coordinate location) { - return getWorld().getBlockId(location.getBlockX(), location.getBlockY(), location.getBlockZ()) == 0 - && getWorld().getBlockId(location.getBlockX(), location.getBlockY() + 1, location.getBlockZ()) == 0 - && getWorld().getBlockId(location.getBlockX(), location.getBlockY() - 1, location.getBlockZ()) == 0; + return getWorld().getBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ()) == Blocks.air + && getWorld().getBlock(location.getBlockX(), location.getBlockY() + 1, location.getBlockZ()) == Blocks.air + && getWorld().getBlock(location.getBlockX(), location.getBlockY() - 1, location.getBlockZ()) == Blocks.air; } /** @@ -386,9 +399,9 @@ && getWorld().getBlockId(location.getBlockX(), location.getBlockY() + 1, locatio */ public float getMovementForward() { if (player instanceof EntityPlayerMP) { - return ((EntityPlayerMP) player).getMoveForwardField(); + return ((EntityPlayerMP) player).moveForward; } else if (player instanceof EntityClientPlayerMP) { - return ((EntityClientPlayerMP) player).getMovementForward(); + return ((EntityClientPlayerMP) player).moveForward; } else { return 0F; } @@ -403,9 +416,9 @@ public float getMovementForward() { */ public float getMovementStrafe() { if (player instanceof EntityPlayerMP) { - return ((EntityPlayerMP) player).getMoveStrafingField(); + return ((EntityPlayerMP) player).moveStrafing; } else if (player instanceof EntityClientPlayerMP) { - return ((EntityClientPlayerMP) player).getMovementStrafe(); + return ((EntityClientPlayerMP) player).moveStrafing; } else { return 0F; } @@ -472,6 +485,7 @@ public void addPotionEffect(int id, int duration, int strength) { */ public void changeDimension(int dimension) { player.travelToDimension(dimension); + player.timeUntilPortal = player.getPortalCooldown(); } /** @@ -537,9 +551,9 @@ public boolean isCreativeMode() { */ public String getUsername() { if (player instanceof EntityClientPlayerMP) { - return ((EntityClientPlayerMP) player).getUsername(); + return ((EntityClientPlayerMP) player).getCommandSenderName(); } else if (player instanceof EntityPlayerMP) { - ((EntityPlayerMP) player).getUsername(); + ((EntityPlayerMP) player).getCommandSenderName(); } return ""; } diff --git a/src/com/sijobe/spc/wrapper/Potion.java b/src/main/java/com/sijobe/spc/wrapper/Potion.java similarity index 68% rename from src/com/sijobe/spc/wrapper/Potion.java rename to src/main/java/com/sijobe/spc/wrapper/Potion.java index cf8c962..1b0e55f 100644 --- a/src/com/sijobe/spc/wrapper/Potion.java +++ b/src/main/java/com/sijobe/spc/wrapper/Potion.java @@ -14,9 +14,9 @@ public class Potion { */ private static Map retrievePotions() { Map potions = new HashMap(); - for (int i = 0; i < net.minecraft.src.Potion.potionTypes.length; i++) { - if (net.minecraft.src.Potion.potionTypes[i] != null) { - potions.put(net.minecraft.src.StatCollector.translateToLocal(net.minecraft.src.Potion.potionTypes[i].getName()).replace(' ', '_').toLowerCase(), i); + for (int i = 0; i < net.minecraft.potion.Potion.potionTypes.length; i++) { + if (net.minecraft.potion.Potion.potionTypes[i] != null) { + potions.put(net.minecraft.util.StatCollector.translateToLocal(net.minecraft.potion.Potion.potionTypes[i].getName()).replace(' ', '_').toLowerCase(), i); } } return potions; diff --git a/src/com/sijobe/spc/wrapper/Stats.java b/src/main/java/com/sijobe/spc/wrapper/Stats.java similarity index 96% rename from src/com/sijobe/spc/wrapper/Stats.java rename to src/main/java/com/sijobe/spc/wrapper/Stats.java index daca12d..136c151 100644 --- a/src/com/sijobe/spc/wrapper/Stats.java +++ b/src/main/java/com/sijobe/spc/wrapper/Stats.java @@ -5,8 +5,8 @@ import java.util.List; import java.util.Map; -import net.minecraft.src.Achievement; -import net.minecraft.src.AchievementList; +import net.minecraft.stats.Achievement; +import net.minecraft.stats.AchievementList; /** * Contains methods that interact with the Minecraft statistics engine diff --git a/src/com/sijobe/spc/wrapper/World.java b/src/main/java/com/sijobe/spc/wrapper/World.java similarity index 82% rename from src/com/sijobe/spc/wrapper/World.java rename to src/main/java/com/sijobe/spc/wrapper/World.java index c8bec2c..50308b1 100644 --- a/src/com/sijobe/spc/wrapper/World.java +++ b/src/main/java/com/sijobe/spc/wrapper/World.java @@ -3,16 +3,19 @@ import java.lang.reflect.Field; import java.util.Random; -import net.minecraft.src.Block; -import net.minecraft.src.EntityLightningBolt; -import net.minecraft.src.IInventory; -import net.minecraft.src.NBTTagCompound; -import net.minecraft.src.WorldGenBigTree; -import net.minecraft.src.WorldGenForest; -import net.minecraft.src.WorldGenTaiga1; -import net.minecraft.src.WorldGenTaiga2; -import net.minecraft.src.WorldGenTrees; -import net.minecraft.src.WorldInfo; +import com.sijobe.spc.ModSpc; +import com.sijobe.spc.util.ReflectionHelper; + +import net.minecraft.entity.effect.EntityLightningBolt; +import net.minecraft.inventory.IInventory; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.EnumDifficulty; +import net.minecraft.world.gen.feature.WorldGenBigTree; +import net.minecraft.world.gen.feature.WorldGenForest; +import net.minecraft.world.gen.feature.WorldGenTaiga1; +import net.minecraft.world.gen.feature.WorldGenTaiga2; +import net.minecraft.world.gen.feature.WorldGenTrees; +import net.minecraft.world.storage.WorldInfo; /** * Provides methods that interact with the Minecraft world @@ -24,7 +27,7 @@ public class World { /** * The world instance this class wraps around */ - private final net.minecraft.src.World world; + private final net.minecraft.world.World world; /** * A random instance provides random numbers for methods */ @@ -35,7 +38,7 @@ public class World { * * @param world - The world instance to wrap around */ - public World(net.minecraft.src.World world) { + public World(net.minecraft.world.World world) { this.world = world; random = new Random(); } @@ -46,10 +49,10 @@ public World(net.minecraft.src.World world) { * @param x - The X coordinate of the block to get * @param y - The Y coordinate of the block to get * @param z - The Z coordinate of the block to get - * @return The ID of the block + * @return the block at (x, y, z) */ - public int getBlockId(int x, int y, int z) { - return world.getBlockId(x, y, z); + public Block getBlock(int x, int y, int z) { + return Block.fromMinecraftBlock(this.getMinecraftWorld().getBlock(x, y, z)); } /** @@ -58,8 +61,8 @@ public int getBlockId(int x, int y, int z) { * @param coord - The coordinate of the block to get * @return The ID of the block */ - public int getBlockId(Coordinate coord) { - return world.getBlockId(coord.getBlockX(), coord.getBlockY(), coord.getBlockZ()); + public Block getBlock(Coordinate coord) { + return this.getBlock(coord.getBlockX(), coord.getBlockY(), coord.getBlockZ()); } /** @@ -106,6 +109,7 @@ public boolean isCheats() { */ public void setCheats(boolean cheats) { changeWorldInfo("allowCommands", cheats); + ReflectionHelper.setField(ReflectionHelper.commandsAllowedForAll, MinecraftServer.getMinecraftServer().getConfigurationManager(), cheats); } /** @@ -127,7 +131,7 @@ private void changeWorldInfo(String key, Object value) { } WorldInfo info = new WorldInfo(nbt); try { - Field fields[] = net.minecraft.src.World.class.getDeclaredFields(); + Field fields[] = net.minecraft.world.World.class.getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); if (field.get(this.world) instanceof WorldInfo) { @@ -145,8 +149,8 @@ private void changeWorldInfo(String key, Object value) { * * @return The difficulty of the world */ - public int getDifficulty() { - return world.difficultySetting; + public EnumDifficulty getDifficulty() { + return MinecraftServer.getMinecraftServer().func_147135_j(); } /** @@ -154,8 +158,9 @@ public int getDifficulty() { * * @param difficulty - The difficulty of the world */ - public void setDifficulty(int difficulty) { - world.difficultySetting = difficulty; + public void setDifficulty(EnumDifficulty difficulty) { + MinecraftServer.getMinecraftServer().func_147139_a(difficulty); + ModSpc.instance.proxy.setDifficulty(difficulty); } /** @@ -165,8 +170,8 @@ public void setDifficulty(int difficulty) { * @param type - The BlockID to change the specified location to * @return True if the data was set correctly */ - public boolean setBlock(Coordinate coord, int type) { - return world.setBlock(coord.getBlockX(), coord.getBlockY(), coord.getBlockZ(), type, 0, 2); + public boolean setBlock(Coordinate coord, Block type) { + return world.setBlock(coord.getBlockX(), coord.getBlockY(), coord.getBlockZ(), type.convert(), 0, 2); } /** @@ -188,8 +193,8 @@ public boolean setBlockData(Coordinate coord, int type) { * @param meta - The metadata to set on the block * @return True if the data was set correctly */ - public boolean setBlockDataWithMeta(Coordinate coord, int type, int meta) { - return world.setBlock(coord.getBlockX(), coord.getBlockY(), coord.getBlockZ(), type, meta, 2); + public boolean setBlockDataWithMeta(Coordinate coord, Block type, int meta) { + return world.setBlock(coord.getBlockX(), coord.getBlockY(), coord.getBlockZ(), type.convert(), meta, 2); // 2 = setblock, 3 = notify } @@ -287,7 +292,7 @@ public int getBlockLightLevel(Coordinate coordinate) { */ public boolean emptyContainer(Coordinate coordinate) { try { - IInventory i = (IInventory)world.getBlockTileEntity(coordinate.getBlockX(), coordinate.getBlockY(), coordinate.getBlockZ()); + IInventory i = (IInventory)world.getTileEntity(coordinate.getBlockX(), coordinate.getBlockY(), coordinate.getBlockZ()); for (int j = 0; j < i.getSizeInventory(); j++) { i.setInventorySlotContents(j, null); } @@ -345,7 +350,8 @@ public boolean generateTree(Coordinate coordinate) { * @return True if the generation was successful, false otherwise */ public boolean generateBirchTree(Coordinate coordinate) { - return (new WorldGenForest(true)).generate(world, random, coordinate.getBlockX(), coordinate.getBlockY(), coordinate.getBlockZ()); + //second arg for WorldGenForest constructor might need to be true + return (new WorldGenForest(true, false)).generate(world, random, coordinate.getBlockX(), coordinate.getBlockY(), coordinate.getBlockZ()); } /** @@ -384,16 +390,13 @@ public void createExplosion(Player player, Coordinate coordinate, int size) { } /** - * Checks if the specified block type (block ID) is valid in Minecraft + * Checks if the specified block type is valid in Minecraft * * @param type - The type of block * @return True if it is a valid block type */ - public boolean isValidBlockType(int type) { - if (type < 0 || type >= Block.blocksList.length) { - return false; - } - return Block.blocksList[type] != null; + public boolean isValidBlockType(Block type) { + return Block.blockRegistry.getNameForObject(type) != null; } /** @@ -401,7 +404,7 @@ public boolean isValidBlockType(int type) { * * @return The Minecraft World object */ - public net.minecraft.src.World getMinecraftWorld() { + public net.minecraft.world.World getMinecraftWorld() { return world; } } diff --git a/src/main/resources/com/sijobe/spc/asm/renames.txt b/src/main/resources/com/sijobe/spc/asm/renames.txt new file mode 100644 index 0000000..280d6d0 --- /dev/null +++ b/src/main/resources/com/sijobe/spc/asm/renames.txt @@ -0,0 +1,14 @@ +#mc version 1.7.2 +net.minecraft.client.multiplayer.PlayerControllerMP biy +net.minecraft.client.multiplayer.PlayerControllerMP.getBlockReachDistance biy.d +net.minecraft.client.multiplayer.PlayerControllerMP.extendedReach biy.i +net.minecraft.client.renderer.ItemRenderer blq +net.minecraft.client.renderer.ItemRenderer.renderInsideOfBlock blq.a +net.minecraft.util.IIcon ps +net.minecraft.network.NetHandlerPlayServer mx +net.minecraft.network.NetHandlerPlayServer.processChatMessage mx.a +net.minecraft.network.NetHandlerPlayServer.processUseEntity mx.a +net.minecraft.network.play.client.C01PacketChatMessage ie +net.minecraft.network.play.client.C02PacketUseEntity io +net.minecraft.client.renderer.EntityRenderer bll +net.minecraft.client.renderer.EntityRenderer.getMouseOver bll.a \ No newline at end of file diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info new file mode 100644 index 0000000..e8830b0 --- /dev/null +++ b/src/main/resources/mcmod.info @@ -0,0 +1,18 @@ +[ +{ + "modid": "spc", + "name": "Single Player Commands", + "description": "Adds various commands to minecraft", + "version": "5.0", + "mcversion": "1.7.2", + "url": "", + "updateUrl": "", + "authorList": ["sijobe", "q3hardcore", "Lamp-Post", "aucguy"], + "credits": "simo_415 for making this mod in the first place, + q3hardcore and Lamp-Post for adding some commands and + aucguy for updating the mod to minecraft 1.7.2", + "logoFile": "", + "screenshots": [], + "dependencies": [] +} +]