Advertisement
Guest User

Untitled

a guest
Aug 16th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 2.21 KB | None | 0 0
  1. package me.amuxix.runes
  2.  
  3. import cats.data.EitherT
  4. import cats.effect.IO
  5. import cats.implicits.{catsStdInstancesForOption, toTraverseOps}
  6. import me.amuxix._
  7. import me.amuxix.inventory.Item
  8. import me.amuxix.material.Material.{Dirt, RedstoneBlock, RedstoneTorch, RedstoneWire}
  9. import me.amuxix.pattern._
  10. import me.amuxix.position.BlockPosition
  11.  
  12. object Disenchanter extends RunePattern[Disenchanter] {
  13.   override val runeCreator: RuneCreator = Disenchanter.apply
  14.   override val activatesWith: Option[Item] =|> Boolean = {
  15.     case Some(item) if item.isEnchanted => true
  16.   }
  17.   // format: off
  18.   override val layers: List[BaseLayer] = List(
  19.     ActivationLayer(
  20.       RedstoneWire, RedstoneWire,  RedstoneWire,
  21.       RedstoneWire, RedstoneTorch, RedstoneWire,
  22.       RedstoneWire, RedstoneWire,  RedstoneWire,
  23.     ),
  24.     Layer(
  25.       NotInRune, NotInRune,     NotInRune,
  26.       NotInRune, RedstoneBlock, NotInRune,
  27.       NotInRune, NotInRune,     NotInRune,
  28.     ),
  29.   )
  30.   // format: on
  31. }
  32.  
  33. case class Disenchanter(
  34.   center: BlockPosition,
  35.   creator: Player,
  36.   direction: Direction,
  37.   rotation: Matrix4,
  38.   pattern: Pattern
  39. ) extends Rune {
  40.  
  41.   override def validateActivationItem(
  42.     activationItem: Option[Item]): Option[String] =
  43.     activationItem match {
  44.       case Some(item) if item.isEnchanted => None
  45.       case _ => Some("This rune must be activated with an enchanted item")
  46.     }
  47.  
  48.   /**
  49.     * Internal activate method that should contain all code to activate a rune.
  50.     */
  51.   override protected def onActivate(activationItem: Option[Item]): EitherT[IO, String, Boolean] = {
  52.     val setRedstoneBlockToStone = (center + Down).block.setMaterial(Dirt).toLeft(())
  53.     activationMessage = activationItem.fold(activationMessage)(_.name + " has been disenchanted")
  54.  
  55.     for {
  56.       item <- EitherT.fromOption[IO](activationItem, "No activation tool.")
  57.       _ <- EitherT.liftF(center.strikeLightningEffect)
  58.       _ <- EitherT.liftF(activator.position.traverse(_.strikeLightningEffect))
  59.       _ <- setRedstoneBlockToStone
  60.       _ <- item.disenchant
  61.     } yield true
  62.   }
  63.  
  64.   /**
  65.     * Should this rune use a true name if the activator is wearing one?
  66.     */
  67.   override val shouldUseTrueName: Boolean = true
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement