net.minecraft.world.GameType Java Examples

The following examples show how to use net.minecraft.world.GameType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServerStateMachine.java    From malmo with MIT License 6 votes vote down vote up
private void resetPlayerGameTypes()
{
    // Go through and set all the players to their correct game type:
    for (Map.Entry<String, String> entry : this.usernameToAgentnameMap.entrySet())
    {
        AgentSection as = getAgentSectionFromAgentName(entry.getValue());
        EntityPlayerMP player = getPlayerFromUsername(entry.getKey());
        if (as != null && player != null)
        {
            player.setGameType(GameType.getByName(as.getMode().name().toLowerCase()));
            // Also make sure we haven't accidentally left the player flying:
            player.capabilities.isFlying = false;
            player.sendPlayerAbilities();
        }
    }
}
 
Example #2
Source File: CmdGamemode.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCommand(String command, String[] args) throws Exception {
	int gm;
	
	try {
		gm = Integer.parseInt(args[0]);
	} catch (Exception e) {
		BleachLogger.errorMessage("Unable to parse gamemode.");
		return;
	}
	
	if (gm == 0) {
		mc.playerController.setGameType(GameType.SURVIVAL);
		BleachLogger.infoMessage("Set gamemode to survival.");
	} else if (gm == 1) {
		mc.playerController.setGameType(GameType.CREATIVE);
		BleachLogger.infoMessage("Set gamemode to creative.");
	} else if (gm == 2) {
		mc.playerController.setGameType(GameType.ADVENTURE);
		BleachLogger.infoMessage("Set gamemode to adventure.");
	} else if (gm == 3) {
		mc.playerController.setGameType(GameType.SPECTATOR);
		BleachLogger.infoMessage("Set gamemode to spectator.");
	} else {
		BleachLogger.warningMessage("Unknown Gamemode Number.");
	}
}
 
Example #3
Source File: CraftPlayer.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setGameMode(GameMode mode) {
    if (getHandle().connection == null) return;

    if (mode == null) {
        throw new IllegalArgumentException("Mode cannot be null");
    }

    getHandle().setGameType(GameType.getByID(mode.getValue()));
}
 
Example #4
Source File: MaterialCache.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
private MaterialCache()
{
    WorldSettings settings = new WorldSettings(0L, GameType.CREATIVE, false, false, WorldType.FLAT);

    this.tempWorld = new WorldSchematic(null, settings, -1, EnumDifficulty.PEACEFUL, Minecraft.getMinecraft().profiler);
    this.checkPos = new BlockPos(8, 0, 8);

    WorldUtils.loadChunksClientWorld(this.tempWorld, this.checkPos, new Vec3i(1, 1, 1));
}
 
Example #5
Source File: MixinCPacketPlayer.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Override
public void doPreProcessing(INetHandlerPlayServer server, boolean callingFromSponge) {
    if (isPacketOnMainThread(server, callingFromSponge)) {
        PhysicsWrapperEntity parent = getPacketParent((NetHandlerPlayServer) server);
        if (parent != null) {
            ISubspace parentSubspace = parent.getPhysicsObject().getSubspace();
            ISubspacedEntityRecord entityRecord = parentSubspace
                .getRecordForSubspacedEntity((ISubspacedEntity) getPacketPlayer(server));
            VectorImmutable positionGlobal = entityRecord.getPositionInGlobalCoordinates();
            VectorImmutable lookVectorGlobal = entityRecord
                .getLookDirectionInGlobalCoordinates();

            float pitch = (float) VSMath.getPitchFromVectorImmutable(lookVectorGlobal);
            float yaw = (float) VSMath.getYawFromVectorImmutable(lookVectorGlobal, pitch);

            // ===== Set the proper position values for the player packet ====
            thisPacket.moving = true;
            thisPacket.onGround = true;
            thisPacket.x = positionGlobal.getX();
            thisPacket.y = positionGlobal.getY();
            thisPacket.z = positionGlobal.getZ();

            // ===== Set the proper rotation values for the player packet =====
            thisPacket.rotating = true;
            thisPacket.yaw = yaw;
            thisPacket.pitch = pitch;

            // ===== Dangerous code here =====
            cachedPlayerGameType = getPacketPlayer(server).interactionManager.gameType;
            getPacketPlayer(server).interactionManager.gameType = GameType.CREATIVE;
        }
    }
}
 
Example #6
Source File: ClientStateMachine.java    From malmo with MIT License 5 votes vote down vote up
protected void handleLan()
{
    // Get our name from the Mission:
    List<AgentSection> agents = currentMissionInit().getMission().getAgentSection();
    //if (agents == null || agents.size() <= currentMissionInit().getClientRole())
    //    throw new Exception("No agent section for us!"); // TODO
    this.agentName = agents.get(currentMissionInit().getClientRole()).getName();

    if (agents.size() > 1 && currentMissionInit().getClientRole() == 0) // Multi-agent mission - make sure the server is open to the LAN:
    {
        MinecraftServerConnection msc = new MinecraftServerConnection();
        String address = currentMissionInit().getClientAgentConnection().getClientIPAddress();
        // Do we need to open to LAN?
        if (Minecraft.getMinecraft().isSingleplayer() && !Minecraft.getMinecraft().getIntegratedServer().getPublic())
        {
            String portstr = Minecraft.getMinecraft().getIntegratedServer().shareToLAN(GameType.SURVIVAL, true); // Set to true to stop spam kicks.
            ClientStateMachine.this.integratedServerPort = Integer.valueOf(portstr);
        }

        TCPUtils.Log(Level.INFO,"Integrated server port: " + ClientStateMachine.this.integratedServerPort);
        msc.setPort(ClientStateMachine.this.integratedServerPort);
        msc.setAddress(address);

        if (envServer != null) {
            envServer.notifyIntegrationServerStarted(ClientStateMachine.this.integratedServerPort);
        }
        currentMissionInit().setMinecraftServerConnection(msc);
    }
}
 
Example #7
Source File: DefaultWorldGeneratorImplementation.java    From malmo with MIT License 5 votes vote down vote up
@Override
public boolean createWorld(MissionInit missionInit)
{
    long seed = getWorldSeedFromString(this.dwparams.getSeed());
    WorldType.WORLD_TYPES[0].onGUICreateWorldPress();
    WorldSettings worldsettings = new WorldSettings(seed, GameType.SURVIVAL, true, false, WorldType.WORLD_TYPES[0]);
    worldsettings.enableCommands();
    // Create a filename for this map - we use the time stamp to make sure it is different from other worlds, otherwise no new world
    // will be created, it will simply load the old one.
    return MapFileHelper.createAndLaunchWorld(worldsettings, this.dwparams.isDestroyAfterUse());
}
 
Example #8
Source File: FlatWorldGeneratorImplementation.java    From malmo with MIT License 5 votes vote down vote up
@Override
public boolean createWorld(MissionInit missionInit)
{
    long seed = DefaultWorldGeneratorImplementation.getWorldSeedFromString(this.fwparams.getSeed());
    WorldSettings worldsettings = new WorldSettings(seed, GameType.SURVIVAL, false, false, WorldType.FLAT);
    // This call to setWorldName allows us to specify the layers of our world, and also the features that will be created.
    // This website provides a handy way to generate these strings: http://chunkbase.com/apps/superflat-generator
    worldsettings.setGeneratorOptions(this.fwparams.getGeneratorString());
    worldsettings.enableCommands(); // Enables cheat commands.
    // Create a filename for this map - we use the time stamp to make sure it is different from other worlds, otherwise no new world
    // will be created, it will simply load the old one.
    return MapFileHelper.createAndLaunchWorld(worldsettings, this.fwparams.isDestroyAfterUse());
}
 
Example #9
Source File: BiomeGeneratorImplementation.java    From malmo with MIT License 5 votes vote down vote up
@Override
public boolean createWorld(MissionInit missionInit) {
	long seed = getWorldSeedFromString();
	WorldType.WORLD_TYPES[0].onGUICreateWorldPress();
	WorldSettings worldsettings = new WorldSettings(seed, GameType.SURVIVAL, true, false, WorldType.WORLD_TYPES[0]);
	worldsettings.enableCommands();
	// Create a filename for this map - we use the time stamp to make sure
	// it is different from other worlds, otherwise no new world
	// will be created, it will simply load the old one.
	return MapFileHelper.createAndLaunchWorld(worldsettings, this.bparams.isDestroyAfterUse());
}
 
Example #10
Source File: NEIServerUtils.java    From NotEnoughItems with MIT License 5 votes vote down vote up
public static GameType getGameType(int mode) {
    switch (mode) {
        case 0:
            return GameType.SURVIVAL;
        case 1:
        case 2:
            return GameType.CREATIVE;
        case 3:
            return GameType.ADVENTURE;
    }
    return null;
}
 
Example #11
Source File: ServerStateMachine.java    From malmo with MIT License 4 votes vote down vote up
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 = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().recreatePlayerEntity(player, player.dimension, false);
            player.connection.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());
        // And their Ender inventory:
        if (as.getAgentStart().getEnderBoxInventory() != null)
            initialiseEnderInventory(player, as.getAgentStart().getEnderBoxInventory());

        // 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);
    }
}
 
Example #12
Source File: GuiEntityRender.java    From WearableBackpacks with MIT License 4 votes vote down vote up
public DummyWorld()
{ this(new WorldSettings(0, GameType.SURVIVAL, false, false, WorldType.DEFAULT)); }