diff --git a/src/main/java/com/minelittlepony/unicopia/command/CommandGravity.java b/src/main/java/com/minelittlepony/unicopia/command/CommandGravity.java new file mode 100644 index 00000000..00164585 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/command/CommandGravity.java @@ -0,0 +1,86 @@ +package com.minelittlepony.unicopia.command; + +import java.util.ArrayList; +import java.util.List; + +import com.minelittlepony.unicopia.Race; +import com.minelittlepony.unicopia.player.IPlayer; +import com.minelittlepony.unicopia.player.PlayerSpeciesList; + +import net.minecraft.command.CommandBase; +import net.minecraft.command.CommandException; +import net.minecraft.command.ICommandSender; +import net.minecraft.command.WrongUsageException; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.TextComponentTranslation; + +class CommandGravity extends CommandBase { + + public String getName() { + return "gravity"; + } + + public int getRequiredPermissionLevel() { + return 4; + } + + public String getUsage(ICommandSender sender) { + return "commands.gravity.usage"; + } + + public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { + if (args.length < 2) { + throw new WrongUsageException(getUsage(sender)); + } + + EntityPlayer player = getCommandSenderAsPlayer(sender); + IPlayer iplayer = PlayerSpeciesList.instance().getPlayer(player); + + + + if (args[0].contentEquals("get")) { + String translationKey = "commands.gravity.get"; + + float gravity = iplayer.getGravity().getGravitationConstant(); + + if (sender == player) { + player.sendMessage(new TextComponentTranslation(translationKey, gravity)); + } + + notifyCommandListener(sender, this, 1, translationKey + ".other", player.getName(), gravity); + + } else if (args[0].contentEquals("set") || args.length > 2) { + String translationKey = "commands.gravity.set"; + + float gravity = Float.valueOf(args[2]); + + iplayer.getGravity().setGraviationConstant(gravity); + iplayer.sendCapabilities(true); + + if (sender == player) { + player.sendMessage(new TextComponentTranslation(translationKey, gravity)); + } + + notifyCommandListener(sender, this, 1, translationKey + ".other", player.getName(), gravity); + } else { + throw new WrongUsageException(getUsage(sender)); + } + } + + /** + * Adds the strings available in this command to the given list of tab completion options. + */ + public List getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) { + if (args.length == 1) { + return getListOfStringsMatchingLastWord(args, "get", "set"); + } + + if (args.length == 2) { + return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames()); + } + + return null; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/command/Commands.java b/src/main/java/com/minelittlepony/unicopia/command/Commands.java index 8f963e6d..549157a0 100644 --- a/src/main/java/com/minelittlepony/unicopia/command/Commands.java +++ b/src/main/java/com/minelittlepony/unicopia/command/Commands.java @@ -9,6 +9,7 @@ public class Commands { event.registerServerCommand(new CommandSpecies()); event.registerServerCommand(new CommandRacelist()); event.registerServerCommand(new CommandDisguise()); + event.registerServerCommand(new CommandGravity()); event.getServer().setAllowFlight(true); } diff --git a/src/main/java/com/minelittlepony/unicopia/player/PlayerGravityDelegate.java b/src/main/java/com/minelittlepony/unicopia/player/PlayerGravityDelegate.java index c6bcf5a0..29a04f18 100644 --- a/src/main/java/com/minelittlepony/unicopia/player/PlayerGravityDelegate.java +++ b/src/main/java/com/minelittlepony/unicopia/player/PlayerGravityDelegate.java @@ -125,9 +125,6 @@ class PlayerGravityDelegate implements IUpdatable, IGravity, InbtSerialisable, I @Override public void onUpdate() { - - gravity = -0.008F; - EntityPlayer entity = player.getOwner(); if (isExperienceCritical() && player.isRemote()) { @@ -155,14 +152,16 @@ class PlayerGravityDelegate implements IUpdatable, IGravity, InbtSerialisable, I if (gravity != 0) { if (!entity.capabilities.isFlying) { - entity.motionY += 0.08; + entity.motionY += 0.038; entity.motionY -= gravity; } - entity.onGround = !entity.world.isAirBlock(new BlockPos(entity.posX, entity.posY + entity.height + 0.5F, entity.posZ)); + if (gravity < 0) { + entity.onGround = !entity.world.isAirBlock(new BlockPos(entity.posX, entity.posY + entity.height + 0.5F, entity.posZ)); - if (entity.onGround) { - entity.capabilities.isFlying = isFlying = false; + if (entity.onGround) { + entity.capabilities.isFlying = isFlying = false; + } } } diff --git a/src/main/resources/assets/unicopia/lang/en_US.lang b/src/main/resources/assets/unicopia/lang/en_US.lang index 7cf6a6ec..30dcfeef 100644 --- a/src/main/resources/assets/unicopia/lang/en_US.lang +++ b/src/main/resources/assets/unicopia/lang/en_US.lang @@ -237,6 +237,12 @@ commands.disguise.success.other=%1$s is now disguised as %2$s commands.disguise.success.self=Updated disguise to %s commands.disguise.success.otherself=%1$s changed their disguise to %2$s +commands.gravity.usage=/gravity +commands.gravity.get=Your gravity is %f +commands.gravity.get.other=%1$s has a gravity of %f +commands.gravity.set=Your gravity was set to %f +commands.gravity.set.other=Set %1$s's gravity to %f + unicopia.race.human=Human unicopia.race.human.alt=Humans unicopia.race.earth=Earth Pony