repo for my hex addons :3
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add compound views

+26 -1
+26 -1
src/main/scala/org/eu/net/pool/hexic/Hexic.scala
··· 94 94 import java.{lang, util} 95 95 import scala.annotation.unchecked.uncheckedVariance 96 96 import scala.annotation.{elidable, experimental, showAsInfix, tailrec, targetName, unused} 97 + import scala.collection.IterableOnceOps 97 98 import scala.ref.WeakReference 98 99 import scala.util.{Failure, Success, Try} 99 100 export scala.collection.convert.ImplicitConversions.* ··· 2173 2174 def tryWithdraw(variant: TransferVariant[?], amount: Long)(using TransactionContext, CastingEnvironment): Long = 0 2174 2175 def entities(using TransactionContext): Iterable[Entity] = Iterable() 2175 2176 @throws[Mishap] 2176 - def teleportEntity(ent: Entity)(using TransactionContext, CastingEnvironment): Unit = ??? // TODO: make a mishap for this 2177 + def teleportEntity(ent: Entity)(using TransactionContext, CastingEnvironment): Boolean = false 2177 2178 2178 2179 object InventoryView extends Registrar[InventoryView.Type[?]]("inventory"): 2179 2180 trait Type[T <: InventoryView]: ··· 2182 2183 object Events: 2183 2184 val forEntity: Event[Entity => ServerWorld ?=> Seq[InventoryView]] = EventFactory.createArrayBacked[Entity => ServerWorld ?=> Seq[InventoryView]](classOf, _ => Seq(), fns => e => fns.flatMap(_(e))) 2184 2185 val forBlock: Event[(BlockPos, BlockState) => ServerWorld ?=> Seq[InventoryView]] = EventFactory.createArrayBacked[(BlockPos, BlockState) => ServerWorld ?=> Seq[InventoryView]](classOf, (_, _) => Seq(), fns => (pos, state) => fns.flatMap(_(pos, state))) 2186 + class OfEntity(entity: => Entity)(using ServerWorld) extends InventoryView: 2187 + def views = Events.forEntity.invoker()(entity) 2188 + override def apply(idx: Int)(using CastingEnvironment): Option[SlotReference] = views.collectFirst(hexicVisibilityHack.unlifted(_(idx))) 2189 + override def tryWithdraw(variant: TransferVariant[?], amount: Long)(using TransactionContext, CastingEnvironment): Long = LazyList.from(views).scanLeft(0L)((n, view) => view.tryWithdraw(variant, amount - n) + n).findFirstOrLast(_ >= amount).getOrElse(0) 2190 + override def entities(using TransactionContext): Iterable[Entity] = views.flatMap(_.entities) 2191 + override def teleportEntity(ent: Entity)(using TransactionContext, CastingEnvironment): Boolean = views.iterator∃(_.teleportEntity(ent)) 2192 + class OfBlock(pos: BlockPos)(using world: ServerWorld) extends InventoryView: 2193 + def views = Events.forBlock.invoker()(pos, world.getBlockState(pos)) 2194 + override def apply(idx: Int)(using CastingEnvironment): Option[SlotReference] = views.collectFirst(hexicVisibilityHack.unlifted(_(idx))) 2195 + override def tryWithdraw(variant: TransferVariant[?], amount: Long)(using TransactionContext, CastingEnvironment): Long = LazyList.from(views).scanLeft(0L)((n, view) => view.tryWithdraw(variant, amount - n) + n).findFirstOrLast(_ >= amount).getOrElse(0) 2196 + override def entities(using TransactionContext): Iterable[Entity] = views.flatMap(_.entities) 2197 + override def teleportEntity(ent: Entity)(using TransactionContext, CastingEnvironment): Boolean = views.iterator∃(_.teleportEntity(ent)) 2198 + 2185 2199 object SlotReference extends Registrar[SlotReference.Type[?]]("slot"): 2186 2200 class Type[T <: SlotReference: Codec] 2187 2201 ··· 2321 2335 summonFrom: 2322 2336 case y: T => Some((x, y)) 2323 2337 case _ => None 2338 + 2339 + implicit class IterExt[T](i: IterableOnceOps[T, ?, ?]): 2340 + export i.{exists => ∃, forall => ∀} 2341 + def findFirstOrLast(p: T => Boolean): Option[T] = 2342 + boundary: 2343 + (None /: i): 2344 + case (ctx, x) => 2345 + if p(x) then 2346 + boundary.break(Some(x)) 2347 + else 2348 + Some(x) 2324 2349 2325 2350 //noinspection UnstableApiUsage 2326 2351 object MediaVariant extends TransferVariant[MediaVariant.type]: