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


Java EntityPlayer.setGameType方法代码示例

本文整理汇总了Java中net.minecraft.entity.player.EntityPlayer.setGameType方法的典型用法代码示例。如果您正苦于以下问题:Java EntityPlayer.setGameType方法的具体用法?Java EntityPlayer.setGameType怎么用?Java EntityPlayer.setGameType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.minecraft.entity.player.EntityPlayer的用法示例。


在下文中一共展示了EntityPlayer.setGameType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onWorldTick

import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@SubscribeEvent
public void onWorldTick(TickEvent.WorldTickEvent e) {
    if (!e.world.isRemote && e.phase == TickEvent.Phase.START && e.world.provider.getDimension() == 0) {
        long now = Instant.now().getEpochSecond();
        if (now - lastCheck > checkInterval) {
            BlockPos spawn = e.world.getSpawnPoint();
            for (int i = 0; i < e.world.playerEntities.size(); i++)
            {
                EntityPlayer p = e.world.playerEntities.get(i);
                // If the user is inside the zone radius, force them back to creative
                if (p.getDistance(spawn.getX(), p.posY, spawn.getZ()) < zoneRadius) {
                    p.setGameType(GameType.CREATIVE);
                } else {
                    // Otherwise, the user is outside the radius and we need to force
                    // them back to survival (assuming they're not on the whitelist)
                    if (!whitelist.contains(p.getName())) {
                        p.setGameType(GameType.SURVIVAL);
                    }
                }
            }
            lastCheck = now;
        }
    }
}
 
开发者ID:dizzyd,项目名称:creativezone,代码行数:25,代码来源:CreativeZoneMod.java

示例2: processCommand

import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
/**
 * Callback when the command is invoked
 */
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
    if (args.length <= 0)
    {
        throw new WrongUsageException("commands.gamemode.usage", new Object[0]);
    }
    else
    {
        WorldSettings.GameType worldsettings$gametype = this.getGameModeFromCommand(sender, args[0]);
        EntityPlayer entityplayer = args.length >= 2 ? getPlayer(sender, args[1]) : getCommandSenderAsPlayer(sender);
        entityplayer.setGameType(worldsettings$gametype);
        entityplayer.fallDistance = 0.0F;

        if (sender.getEntityWorld().getGameRules().getBoolean("sendCommandFeedback"))
        {
            entityplayer.addChatMessage(new ChatComponentTranslation("gameMode.changed", new Object[0]));
        }

        IChatComponent ichatcomponent = new ChatComponentTranslation("gameMode." + worldsettings$gametype.getName(), new Object[0]);

        if (entityplayer != sender)
        {
            notifyOperators(sender, this, 1, "commands.gamemode.success.other", new Object[] {entityplayer.getName(), ichatcomponent});
        }
        else
        {
            notifyOperators(sender, this, 1, "commands.gamemode.success.self", new Object[] {ichatcomponent});
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:34,代码来源:CommandGameMode.java

示例3: execute

import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length <= 0)
    {
        throw new WrongUsageException("commands.gamemode.usage", new Object[0]);
    }
    else
    {
        GameType gametype = this.getGameModeFromCommand(sender, args[0]);
        EntityPlayer entityplayer = args.length >= 2 ? getPlayer(server, sender, args[1]) : getCommandSenderAsPlayer(sender);
        entityplayer.setGameType(gametype);
        ITextComponent itextcomponent = new TextComponentTranslation("gameMode." + gametype.getName(), new Object[0]);

        if (sender.getEntityWorld().getGameRules().getBoolean("sendCommandFeedback"))
        {
            entityplayer.addChatMessage(new TextComponentTranslation("gameMode.changed", new Object[] {itextcomponent}));
        }

        if (entityplayer == sender)
        {
            notifyCommandListener(sender, this, 1, "commands.gamemode.success.self", new Object[] {itextcomponent});
        }
        else
        {
            notifyCommandListener(sender, this, 1, "commands.gamemode.success.other", new Object[] {entityplayer.getName(), itextcomponent});
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:32,代码来源:CommandGameMode.java


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