当前位置: 首页>>代码示例>>Java>>正文


Java EntityPlayerMP.setHealth方法代码示例

本文整理汇总了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));
			}
		}
	}
}
 
开发者ID:blay09,项目名称:HardcoreRevival,代码行数:35,代码来源:RescueHandler.java

示例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);
    }
}
 
开发者ID:Yarichi,项目名称:Proyecto-DASI,代码行数:40,代码来源:ServerStateMachine.java

示例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"));
		}
	}
}
 
开发者ID:IvanSteklow,项目名称:VanillaExtras,代码行数:47,代码来源:MainCmd.java

示例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;
}
 
开发者ID:abused,项目名称:World-Border,代码行数:54,代码来源:BorderCheck.java


注:本文中的net.minecraft.entity.player.EntityPlayerMP.setHealth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。