From 10a640d8ee1ea5a9d03b1bfab7fc21346477dcff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sun, 12 Apr 2015 16:46:03 +0200 Subject: [PATCH] Give a free manual to players once. --- src/main/resources/application.conf | 5 +++++ src/main/scala/li/cil/oc/Settings.scala | 1 + .../scala/li/cil/oc/common/EventHandler.scala | 20 +++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf index a6ae0505f..441d15e02 100644 --- a/src/main/resources/application.conf +++ b/src/main/resources/application.conf @@ -1069,6 +1069,11 @@ opencomputers { # avoid issues with computers timing out, but can also lead to higher # server load. AGAIN, USE WITH CARE! threadPriority: -1 + + # Whether to give a new player a free copy of the manual. This will only + # happen one time per game, not per world, not per death. Once. If this + # is still too much for your taste, disable it here ;-) + giveManualToNewPlayers: true } # Settings for mod integration (the mod previously known as OpenComponents). diff --git a/src/main/scala/li/cil/oc/Settings.scala b/src/main/scala/li/cil/oc/Settings.scala index 339478458..72a2a4f2e 100644 --- a/src/main/scala/li/cil/oc/Settings.scala +++ b/src/main/scala/li/cil/oc/Settings.scala @@ -293,6 +293,7 @@ class Settings(val config: Config) { val presentChance = config.getDouble("misc.presentChance") max 0 min 1 val assemblerBlacklist = config.getStringList("misc.assemblerBlacklist") val threadPriority = config.getInt("misc.threadPriority") + val giveManualToNewPlayers = config.getBoolean("misc.giveManualToNewPlayers") // ----------------------------------------------------------------------- // // printer diff --git a/src/main/scala/li/cil/oc/common/EventHandler.scala b/src/main/scala/li/cil/oc/common/EventHandler.scala index eaf3223a8..7dbd5c594 100644 --- a/src/main/scala/li/cil/oc/common/EventHandler.scala +++ b/src/main/scala/li/cil/oc/common/EventHandler.scala @@ -28,13 +28,16 @@ import li.cil.oc.server.machine.Machine import li.cil.oc.server.{PacketSender => ServerPacketSender} import li.cil.oc.util._ import net.minecraft.client.Minecraft +import net.minecraft.entity.player.EntityPlayer import net.minecraft.entity.player.EntityPlayerMP import net.minecraft.item.ItemStack +import net.minecraft.nbt.NBTTagCompound import net.minecraft.server.MinecraftServer import net.minecraft.tileentity.TileEntity import net.minecraftforge.common.MinecraftForge import net.minecraftforge.common.util.FakePlayer import net.minecraftforge.common.util.ForgeDirection +import net.minecraftforge.event.entity.EntityJoinWorldEvent import net.minecraftforge.event.world.BlockEvent import net.minecraftforge.event.world.WorldEvent @@ -227,6 +230,23 @@ object EventHandler { keyboards.foreach(_.releasePressedKeys(e.player)) } + @SubscribeEvent + def onEntityJoinWorld(e: EntityJoinWorldEvent): Unit = { + if (Settings.get.giveManualToNewPlayers && !e.world.isRemote) e.entity match { + case player: EntityPlayer if !player.isInstanceOf[FakePlayer] => + val nbt = player.getEntityData + if (!nbt.hasKey(EntityPlayer.PERSISTED_NBT_TAG)) { + nbt.setTag(EntityPlayer.PERSISTED_NBT_TAG, new NBTTagCompound()) + } + val ocData = nbt.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG) + if (!ocData.getBoolean(Settings.namespace + "receivedManual")) { + ocData.setBoolean(Settings.namespace + "receivedManual", true) + player.inventory.addItemStackToInventory(api.Items.get(Constants.ItemName.Manual).createItemStack(1)) + } + case _ => + } + } + lazy val drone = api.Items.get(Constants.ItemName.Drone) lazy val eeprom = api.Items.get(Constants.ItemName.EEPROM) lazy val mcu = api.Items.get(Constants.BlockName.Microcontroller)