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 9baf49ed9..987f0c8ee 100644 --- a/src/main/scala/li/cil/oc/Settings.scala +++ b/src/main/scala/li/cil/oc/Settings.scala @@ -294,6 +294,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 a1a594c74..447cd5458 100644 --- a/src/main/scala/li/cil/oc/common/EventHandler.scala +++ b/src/main/scala/li/cil/oc/common/EventHandler.scala @@ -20,11 +20,14 @@ 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.util.FakePlayer +import net.minecraftforge.event.entity.EntityJoinWorldEvent import net.minecraftforge.event.world.BlockEvent import net.minecraftforge.event.world.WorldEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -187,6 +190,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)