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(); } } }
public ChunkCoordinates getRandomizedSpawnPoint() { ChunkCoordinates chunkcoordinates = new ChunkCoordinates(this.worldObj.getSpawnPoint()); boolean isAdventure = worldObj.getWorldInfo().getGameType() == GameType.ADVENTURE; int spawnFuzz = terrainType.getSpawnFuzz(); int spawnFuzzHalf = spawnFuzz / 2; if (!hasNoSky && !isAdventure) { chunkcoordinates.posX += this.worldObj.rand.nextInt(spawnFuzz) - spawnFuzzHalf; chunkcoordinates.posZ += this.worldObj.rand.nextInt(spawnFuzz) - spawnFuzzHalf; chunkcoordinates.posY = this.worldObj.getTopSolidOrLiquidBlock(chunkcoordinates.posX, chunkcoordinates.posZ); } return chunkcoordinates; }
@SubscribeEvent public void onEntityUpdate(LivingUpdateEvent event) { if(event.entityLiving.isPotionActive(ModPotions.bleeding)) { if(event.entityLiving.worldObj.rand.nextInt(40) == 0) { event.entityLiving.attackEntityFrom(new DamageSource("allthethings:bleeding"), 1); event.entityLiving.worldObj.spawnParticle("splash", event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ, 1.0D, 1.0D, 1.0D); } } else if(event.entityLiving.isPotionActive(ModPotions.leadPoison)) { if(event.entityLiving.worldObj.rand.nextInt(40) == 0) { event.entityLiving.attackEntityFrom(new DamageSource("allthethings:leadPoison"), 2); if (event.entityLiving instanceof EntityPlayer) { ((EntityPlayer)event.entityLiving).addExhaustion(20.0F); } event.entityLiving.worldObj.spawnParticle("splash", (event.entityLiving.posX+0.5F)-0.27000001072883606D, (event.entityLiving.posY+0.7F)+0.2199999988079071D, (event.entityLiving.posZ+0.5F), 0.0D, 0.0D, 0.0D); } } else if(event.entityLiving.isPotionActive(ModPotions.lessening)) { if(event.entityLiving instanceof EntityPlayerMP && ((EntityPlayerMP) event.entityLiving).theItemInWorldManager.getGameType() == GameType.CREATIVE) return; else if(event.entityLiving.getHealth() <= 1 || event.entityLiving.getEntityAttribute(SharedMonsterAttributes.maxHealth).getAttributeValue() <= 2.0) { event.entityLiving.attackEntityFrom(new DamageSource("allthethings:lessening"), 9001); } } }
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); } }
@Override public boolean createWorld(MissionInit missionInit) { long seed = getWorldSeedFromString(this.dwparams.getSeed()); WorldType.worldTypes[0].onGUICreateWorldPress(); WorldSettings worldsettings = new WorldSettings(seed, GameType.SURVIVAL, true, false, WorldType.worldTypes[0]); worldsettings.setWorldName(""); 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()); }
@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.setWorldName(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()); }
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; }
public void changeMode() { if (whatPlayerIsNearADVENTURE() != null && whatPlayerIsNearADVENTURE().capabilities.allowEdit == true) { whatPlayerIsNearADVENTURE().setGameType(GameType.ADVENTURE); } else if (whatPlayerIsNearSURVIVAL() != null && whatPlayerIsNearSURVIVAL().capabilities.allowEdit == false) { if(whatPlayerIsNearSURVIVAL() != whatPlayerIsNearADVENTURE()) whatPlayerIsNearSURVIVAL().setGameType(GameType.SURVIVAL); } }
@SubscribeEvent(priority = EventPriority.HIGHEST) public void onRespawnEvent(PlayerRespawnEvent event) { if (event.isCancelable()) return; if(!event.player.capabilities.allowEdit) { event.player.setGameType(GameType.SURVIVAL); } }
@SubscribeEvent public void onPlace(PlaceEvent event) { if(PlayerLogic.getGameType(event.player) != GameType.ADVENTURE) return; if(!PlayerLogic.canPlaceOn(event.player, event.itemInHand, event.placedAgainst)) event.setCanceled(true); }
@SubscribeEvent public void onPlayerInteract(PlayerInteractEvent event) { if(event.action != PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK || PlayerLogic.getGameType(event.entityPlayer) != GameType.ADVENTURE) return; if(Config.affectInteraction && !PlayerLogic.canRightClickOn(event.entityPlayer, event.entityPlayer.getHeldItem(), event.x, event.y, event.z)) event.setCanceled(true); }
@Override public void onUnequipped(ItemStack itemstack, EntityLivingBase player) { ((EntityPlayer)player).setGameType(GameType.SURVIVAL); for(ItemStack bau: PlayerHandler.getPlayerBaubles((EntityPlayer) player).stackList) if(bau != null && bau.getItem() == NFMain.flyBelt) ((EntityPlayer)player).capabilities.isFlying = true; }
@Override public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); // if clik exit end program if ("end".equals(command)) { Minecraft.getMinecraft().shutdown(); Main.debugWrite("Shutting down...."); } else if ("abort".equals(command)) { Main.debugWrite("ABORTING: I REALLY HOPE YOU MENT TO PRESS THIS"); System.exit(0); } else if (command.equals("survival")) { Main.debugWrite("GameMode set to survival"); nSetGameMode(0); } else if (command.equals("creative")) { Main.debugWrite("GameMode set to creative"); nSetGameMode(1); } else if (command.equals("day")) { for (int j = 0; j < MinecraftServer.getServer().worldServers.length; ++j) MinecraftServer.getServer().worldServers[j].setWorldTime(0); Main.debugWrite("Time set to day."); } else if (command.equals("night")) { for (int j = 0; j < MinecraftServer.getServer().worldServers.length; ++j) MinecraftServer.getServer().worldServers[j].setWorldTime(13000); Main.debugWrite("Time set to night."); } else if (command.equals("heal")) { Minecraft.getMinecraft().thePlayer.heal(30); } else if (command.equals("newWorld")) { Minecraft.getMinecraft().launchIntegratedServer("TESTING", "TESTING", new WorldSettings(12341234, GameType.CREATIVE, true, false, WorldType.FLAT)); } }
/** * Changes all players gamemodes <br> * HOLY SH*T THIS TOOK A LONG TIME AND IT SETS EVERYONES GAME TYPE *crys* * * @param modeType */ static void nSetGameMode(int modeType) { try { Minecraft.getMinecraft().thePlayer.setGameType(modeType == 0 ? GameType.SURVIVAL : GameType.CREATIVE); for (int j = 0; j < MinecraftServer.getServer().worldServers.length; ++j) for (int i = 0; i < MinecraftServer.getServer().worldServers[i].playerEntities.size(); ++i) ((EntityPlayerMP) (MinecraftServer.getServer().worldServers[j].playerEntities.get(i))).setGameType(modeType == 0 ? GameType.SURVIVAL : GameType.CREATIVE); } catch (Exception e) { System.err.println("Error occured when trying to change gamemode"); Main.debugWrite("Error occured when trying to change gamemode"); System.err.println(e.getLocalizedMessage()); } }
private void setPlayerGhostMode(EntityPlayer player, World par2World) { if(par2World.isRemote == false) //false means serverside { player.setGameType(GameType.SPECTATOR); ModSpells.incrementPlayerIntegerNBT(player, KEY_TIMER, GHOST_SECONDS * 20); player.getEntityData().setBoolean(KEY_BOOLEAN,true); player.getEntityData().setString(KEY_EATLOC, ModSpells.posToStringCSV(player.getPosition())); player.getEntityData().setInteger(KEY_EATDIM, player.dimension); } }
public static void onPlayerUpdate(LivingUpdateEvent event) { if(event.entityLiving instanceof EntityPlayer == false){return;}//just in case EntityPlayer player = (EntityPlayer)event.entityLiving; if(player.getEntityData().getBoolean(KEY_BOOLEAN))//if in_ghostmode == true { int playerGhost = player.getEntityData().getInteger(KEY_TIMER); if(playerGhost > 0) { ModSpells.incrementPlayerIntegerNBT(player, KEY_TIMER,-1); } else { if(player.getEntityData().getInteger(KEY_EATDIM) != player.dimension) { //if the player changed dimension while a ghost, thats not allowed player.setGameType(GameType.SURVIVAL); player.attackEntityFrom(DamageSource.magic, 50); } else { // : teleport back to source String posCSV = player.getEntityData().getString(KEY_EATLOC); String[] p = posCSV.split(","); player.fallDistance = 0.0F; player.setPositionAndUpdate(Double.parseDouble(p[0]),Double.parseDouble(p[1]),Double.parseDouble(p[2])); player.setGameType(GameType.SURVIVAL); } player.getEntityData().setBoolean(KEY_BOOLEAN, false);//then we are done } } }
@Override public void handleServerSide(EntityPlayerMP player) { Entity e = player.worldObj.getEntityByID(entityID); if (e != null) { try { GameType preGameType = player.theItemInWorldManager.getGameType(); e.readFromNBT(tag); NBTEdit.log(Level.FINE, player.getCommandSenderName() + " edited a tag -- Entity ID #" + entityID); NBTEdit.logTag(tag); if (e == player) { //Update player info player.sendContainerToPlayer(player.inventoryContainer); GameType type = player.theItemInWorldManager.getGameType(); if (preGameType != type) player.setGameType(type); player.playerNetServerHandler.sendPacket(new S06PacketUpdateHealth(player.getHealth(), player.getFoodStats().getFoodLevel(), player.getFoodStats().getSaturationLevel())); player.playerNetServerHandler.sendPacket(new S1FPacketSetExperience(player.experience, player.experienceTotal, player.experienceLevel)); player.sendPlayerAbilities(); } sendMessageToPlayer(player, "Your changes have been saved"); } catch(Throwable t) { sendMessageToPlayer(player, SECTION_SIGN + "cSave Failed - Invalid NBT format for Entity"); NBTEdit.log(Level.WARNING, player.getCommandSenderName() + " edited a tag and caused an exception"); NBTEdit.logTag(tag); NBTEdit.throwing("EntityNBTPacket", "handleServerSide", t); } } }
@Override public void applyAttributesModifiersToEntity(EntityLivingBase entity, BaseAttributeMap map, int p_111185_3_) { if(entity instanceof EntityPlayerMP && ((EntityPlayerMP) entity).theItemInWorldManager.getGameType() == GameType.CREATIVE) return; AttributeModifier modifier = new AttributeModifier("lessen", -0.1D*this.getEffectiveness(), 0); entity.getEntityAttribute(SharedMonsterAttributes.maxHealth).applyModifier(modifier); modifiers.add(modifier); if(new Random().nextInt(20) <= 2) entity.worldObj.playSoundAtEntity(entity, "minecraft:mob.zombiepig.zpigdeath", 1.0F, 0.7F); if(entity.getHealth() > entity.getMaxHealth()) entity.setHealth(entity.getMaxHealth()); super.applyAttributesModifiersToEntity(entity, map, p_111185_3_); }
public static GameType addGameType(String name, int id, String displayName) { return addEnum(GameType.class, name, id, displayName); }
public static BlockEvent.BreakEvent onBlockBreakEvent(World world, GameType gameType, EntityPlayerMP entityPlayer, int x, int y, int z) { // Logic from tryHarvestBlock for pre-canceling the event boolean preCancelEvent = false; if (gameType.func_82752_c() && !entityPlayer.func_82246_f(x, y, z)) { preCancelEvent = true; } else if (gameType.func_77145_d() && entityPlayer.func_70694_bm() != null && entityPlayer.func_70694_bm().func_77973_b() instanceof ItemSword) { preCancelEvent = true; } // Tell client the block is gone immediately then process events if (world.func_147438_o(x, y, z) == null) { S23PacketBlockChange packet = new S23PacketBlockChange(x, y, z, world); packet.field_148883_d = Blocks.field_150350_a; packet.field_148884_e = 0; entityPlayer.field_71135_a.func_147359_a(packet); } // Post the block break event Block block = world.func_147439_a(x, y, z); int blockMetadata = world.func_72805_g(x, y, z); BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(x, y, z, world, block, blockMetadata, entityPlayer); event.setCanceled(preCancelEvent); MinecraftForge.EVENT_BUS.post(event); // Handle if the event is canceled if (event.isCanceled()) { // Let the client know the block still exists entityPlayer.field_71135_a.func_147359_a(new S23PacketBlockChange(x, y, z, world)); // Update any tile entity data for this block TileEntity tileentity = world.func_147438_o(x, y, z); if (tileentity != null) { Packet pkt = tileentity.func_145844_m(); if (pkt != null) { entityPlayer.field_71135_a.func_147359_a(pkt); } } } return event; }
public ProxyWorld(int dimensionID) { super(Minecraft.getMinecraft().getNetHandler(), new WorldSettings(0L, GameType.SURVIVAL, true, false, WorldType.DEFAULT), dimensionID, Minecraft.getMinecraft().gameSettings.difficulty, Minecraft.getMinecraft().theWorld.theProfiler); }
public static BlockEvent.BreakEvent onBlockBreakEvent(World world, GameType gameType, EntityPlayerMP entityPlayer, int x, int y, int z) { // Logic from tryHarvestBlock for pre-canceling the event boolean preCancelEvent = false; if (gameType.isAdventure() && !entityPlayer.isCurrentToolAdventureModeExempt(x, y, z)) { preCancelEvent = true; } else if (gameType.isCreative() && entityPlayer.getHeldItem() != null && entityPlayer.getHeldItem().getItem() instanceof ItemSword) { preCancelEvent = true; } // Tell client the block is gone immediately then process events if (world.getTileEntity(x, y, z) == null) { S23PacketBlockChange packet = new S23PacketBlockChange(x, y, z, world); packet.field_148883_d = Blocks.air; packet.field_148884_e = 0; entityPlayer.playerNetServerHandler.sendPacket(packet); } // Post the block break event Block block = world.getBlock(x, y, z); int blockMetadata = world.getBlockMetadata(x, y, z); BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(x, y, z, world, block, blockMetadata, entityPlayer); event.setCanceled(preCancelEvent); MinecraftForge.EVENT_BUS.post(event); // Handle if the event is canceled if (event.isCanceled()) { // Let the client know the block still exists entityPlayer.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world)); // Update any tile entity data for this block TileEntity tileentity = world.getTileEntity(x, y, z); if (tileentity != null) { Packet pkt = tileentity.getDescriptionPacket(); if (pkt != null) { entityPlayer.playerNetServerHandler.sendPacket(pkt); } } } return event; }
private FakeWorldClient() { super(new NetHandlerPlayClient(Minecraft.getMinecraft(), null, new NetworkManager(true)), new WorldSettings(0, GameType.NOT_SET, false, false, WorldType.DEFAULT), 0, EnumDifficulty.PEACEFUL, Minecraft.getMinecraft().theWorld.theProfiler); }
public static BlockEvent.BreakEvent onBlockBreakEvent(World world, GameType gameType, EntityPlayerMP entityPlayer, int x, int y, int z) { // Cauldron - pre-cancel handled in BreakEvent /* // Logic from tryHarvestBlock for pre-canceling the event boolean preCancelEvent = false; if (gameType.isAdventure() && !entityPlayer.isCurrentToolAdventureModeExempt(x, y, z)) { preCancelEvent = true; } else if (gameType.isCreative() && entityPlayer.getHeldItem() != null && entityPlayer.getHeldItem().getItem() instanceof ItemSword) { preCancelEvent = true; } */ // Tell client the block is gone immediately then process events if (world.getTileEntity(x, y, z) == null && !(entityPlayer instanceof FakePlayer)) // Cauldron - don't send packets to fakeplayers { S23PacketBlockChange packet = new S23PacketBlockChange(x, y, z, world); packet.field_148883_d = Blocks.air; packet.field_148884_e = 0; entityPlayer.playerNetServerHandler.sendPacket(packet); } // Post the block break event Block block = world.getBlock(x, y, z); int blockMetadata = world.getBlockMetadata(x, y, z); BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(x, y, z, world, block, blockMetadata, entityPlayer); //event.setCanceled(preCancelEvent); // Cauldron MinecraftForge.EVENT_BUS.post(event); // Handle if the event is canceled if (event.isCanceled() && !(entityPlayer instanceof FakePlayer)) // Cauldron - don't send packets to fakeplayers { // Let the client know the block still exists entityPlayer.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world)); // Update any tile entity data for this block TileEntity tileentity = world.getTileEntity(x, y, z); if (tileentity != null) { Packet pkt = tileentity.getDescriptionPacket(); if (pkt != null) { entityPlayer.playerNetServerHandler.sendPacket(pkt); } } } return event; }
public void setGameType(int id) { player.setGameType(GameType.getByID(id)); }
public void setGameType(String name) { player.setGameType(GameType.getByName(name.toLowerCase())); }
@Override public void onEquipped(ItemStack itemstack, EntityLivingBase player) { MLib.printToPlayer("Creative Amulet Active"); MLib.printToPlayer("Effects are perminat unless removed"); ((EntityPlayer)player).setGameType(GameType.CREATIVE); }