mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Fixed some bugs with gravity
This commit is contained in:
parent
05ef379fc0
commit
e0fa8e092d
4 changed files with 99 additions and 7 deletions
|
@ -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<String> 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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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,16 +152,18 @@ 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float bodyHeight = getTargetBodyHeight(player);
|
||||
float eyeHeight = getTargetEyeHeight(player);
|
||||
|
|
|
@ -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 <get|set> <player> <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
|
||||
|
|
Loading…
Reference in a new issue