本文整理匯總了Java中net.minecraft.entity.player.EntityPlayerMP.setHealth方法的典型用法代碼示例。如果您正苦於以下問題:Java EntityPlayerMP.setHealth方法的具體用法?Java EntityPlayerMP.setHealth怎麽用?Java EntityPlayerMP.setHealth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.minecraft.entity.player.EntityPlayerMP
的用法示例。
在下文中一共展示了EntityPlayerMP.setHealth方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: finishRescue
import net.minecraft.entity.player.EntityPlayerMP; //導入方法依賴的package包/類
public static void finishRescue(EntityPlayer player) {
IHardcoreRevival revival = player.getCapability(CapabilityHardcoreRevival.REVIVAL_CAPABILITY, null);
if (revival != null) {
EntityPlayer target = revival.getRescueTarget();
if (target != null) {
MinecraftServer server = target.getServer();
if (server != null) {
BlockPos prevSpawnPos = target.getBedLocation(target.dimension);
boolean prevSpawnForced = target.isSpawnForced(target.dimension);
target.setSpawnPoint(target.getPosition(), true);
if (ModConfig.glowOnDeath) {
target.setGlowing(false);
}
EntityPlayerMP newPlayer = server.getPlayerList().recreatePlayerEntity((EntityPlayerMP) target, target.dimension, false);
((EntityPlayerMP) target).connection.player = newPlayer;
newPlayer.setHealth(1f);
newPlayer.getFoodStats().setFoodLevel(5);
newPlayer.addPotionEffect(new PotionEffect(MobEffects.HUNGER, 20 * 30));
newPlayer.addPotionEffect(new PotionEffect(MobEffects.WEAKNESS, 20 * 60));
newPlayer.inventory.copyInventory(target.inventory);
newPlayer.experienceLevel = target.experienceLevel;
newPlayer.experienceTotal = target.experienceTotal;
newPlayer.experience = target.experience;
newPlayer.extinguish();
newPlayer.setFlag(0, false); // burning flag
newPlayer.setScore(target.getScore());
newPlayer.setSpawnPoint(prevSpawnPos, prevSpawnForced);
NetworkHandler.instance.sendToAllAround(new MessageRevivalSuccess(newPlayer.getEntityId()), new NetworkRegistry.TargetPoint(newPlayer.dimension, newPlayer.posX, newPlayer.posY, newPlayer.posZ, 32));
}
}
}
}
示例2: initialisePlayer
import net.minecraft.entity.player.EntityPlayerMP; //導入方法依賴的package包/類
private void initialisePlayer(String username, String agentname)
{
AgentSection as = getAgentSectionFromAgentName(agentname);
EntityPlayerMP player = getPlayerFromUsername(username);
if (player != null && as != null)
{
if ((player.getHealth() <= 0 || player.isDead || !player.isEntityAlive()))
{
player.markPlayerActive();
player = MinecraftServer.getServer().getConfigurationManager().recreatePlayerEntity(player, player.dimension, false);
player.playerNetServerHandler.playerEntity = player;
}
// Reset their food and health:
player.setHealth(player.getMaxHealth());
player.getFoodStats().addStats(20, 40);
player.maxHurtResistantTime = 1; // Set this to a low value so that lava will kill the player straight away.
disablePlayerGracePeriod(player); // Otherwise player will be invulnerable for the first 60 ticks.
player.extinguish(); // In case the player was left burning.
// Set their initial position and speed:
PosAndDirection pos = as.getAgentStart().getPlacement();
if (pos != null) {
player.rotationYaw = pos.getYaw().floatValue();
player.rotationPitch = pos.getPitch().floatValue();
player.setPositionAndUpdate(pos.getX().doubleValue(),pos.getY().doubleValue(),pos.getZ().doubleValue());
player.onUpdate(); // Needed to force scene to redraw
}
player.setVelocity(0, 0, 0); // Minimise chance of drift!
// Set their inventory:
if (as.getAgentStart().getInventory() != null)
initialiseInventory(player, as.getAgentStart().getInventory());
// Set their game mode to spectator for now, to protect them while we wait for the rest of the cast to assemble:
player.setGameType(GameType.SPECTATOR);
}
}
示例3: execute
import net.minecraft.entity.player.EntityPlayerMP; //導入方法依賴的package包/類
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
World world = sender.getEntityWorld();
if (!world.isRemote) {
EntityPlayerMP player = getCommandSenderAsPlayer(sender);
if (args.length <= 0) {
player.sendMessage(new TextComponentString("[ISH] Usage:"));
player.sendMessage(new TextComponentString("[ISH] /ish killa (killall) - kill all mobs and drops"));
player.sendMessage(new TextComponentString("[ISH] /ish heal (healme) - heal player"));
player.sendMessage(
new TextComponentString("[ISH] /ish oheart (oneheart) - set minimal health and hunger"));
return;
}
if (args[0].equals("killa") || args[0].equals("killall")) {
server.commandManager.executeCommand(server.getServer(), "/kill @e[type=!Player]");
} else if (args[0].equals("heal") || args[0].equals("healme")) {
player.setHealth(player.getMaxHealth());
player.getFoodStats().setFoodLevel(20);
} else if (args[0].equals("oheart") || args[0].equals("oneheart")) {
player.setHealth(1.0f);
player.getFoodStats().setFoodLevel(1);
} else if (args[0].equals("help") || args[0].equals("?")) {
player.sendMessage(new TextComponentString("[ISH] Usage:"));
player.sendMessage(new TextComponentString("[ISH] /ish killa (killall) - kill all mobs and drops"));
player.sendMessage(new TextComponentString("[ISH] /ish heal (healme) - heal player"));
player.sendMessage(
new TextComponentString("[ISH] /ish oheart (oneheart) - set minimal health and hunger"));
} else if (args[0].equals("out")) {
if (args[1].equals("0")) {
server.commandManager.executeCommand(player.getCommandSenderEntity(),
"/gamerule commandBlockOutput false");
} else if (args[1].equals("1")) {
server.commandManager.executeCommand(player.getCommandSenderEntity(),
"/gamerule commandBlockOutput true");
}
} else {
player.sendMessage(new TextComponentString("[ISH] Wrong usage! Usage:"));
player.sendMessage(new TextComponentString("[ISH] /ish killa (killall) - kill all mobs and drops"));
player.sendMessage(new TextComponentString("[ISH] /ish heal (healme) - heal player"));
player.sendMessage(
new TextComponentString("[ISH] /ish oheart (oneheart) - set minimal health and hunger"));
}
}
}
示例4: newLocation
import net.minecraft.entity.player.EntityPlayerMP; //導入方法依賴的package包/類
private static Location newLocation(EntityPlayerMP player, Location loc, BorderData border, boolean notify)
{
Log.trace(
"%s @ world '%s'. Border: %s",
(notify ? "Border crossing" : "Check was run"),
Worlds.getWorldName(loc.world), border
);
Log.trace("Player @ X: %.2f Y: %.2f Z: %.2f", loc.posX, loc.posY, loc.posZ);
Location newLoc = border.correctedPosition(loc, Config.getShapeRound(), player.capabilities.isFlying);
// it's remotely possible (such as in the Nether) a suitable location isn't available, in which case...
if (newLoc == null)
{
Log.debug("Target new location unviable, trying again with border center.");
double safeY = border.getSafeY(
loc.world, (int) border.getX(), 64, (int) border.getZ(),
player.capabilities.isFlying
);
if (safeY != 1)
{
newLoc = new Location(loc);
newLoc.posX = Math.floor( border.getX() ) + 0.5;
newLoc.posY = safeY;
newLoc.posZ = Math.floor( border.getZ() ) + 0.5;
}
}
if (newLoc == null)
{
Log.debug("Target new location still unviable, using spawn or killing player.");
if ( Config.doPlayerKill() )
{
player.setHealth(0.0F);
return null;
}
newLoc = new Location( (WorldServer) player.worldObj );
}
Log.trace(
"New position @ X: %.2f Y: %.2f Z: %.2f",
newLoc.posX, newLoc.posY, newLoc.posZ
);
if (notify)
Util.chat( player, Config.getMessage() );
return newLoc;
}