repo for my hex addons :3
0
fork

Configure Feed

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

add inventory view types

+46 -7
hexic.git

This is a binary file and will not be displayed.

+46 -7
src/main/scala/org/eu/net/pool/hexic/Hexic.scala
··· 2168 2168 else if x > max then max 2169 2169 else x 2170 2170 2171 - trait InventoryView: 2171 + trait InventoryView(val viewType: InventoryView.Type[?]): 2172 2172 def apply(idx: Int)(using CastingEnvironment): Option[SlotReference] = None 2173 2173 @throws[Mishap] 2174 2174 def tryWithdraw(variant: TransferVariant[?], amount: Long)(using TransactionContext, CastingEnvironment): Long = 0 2175 2175 def entities(using TransactionContext): Set[Entity] = Set() 2176 2176 @throws[Mishap] 2177 2177 def teleportEntity(ent: Entity)(using TransactionContext, CastingEnvironment): Boolean = false 2178 + def serialize = NbtCompound() 2178 2179 2179 2180 object InventoryView extends Registrar[InventoryView.Type[?]]("inventory"): 2180 - trait Type[T <: InventoryView]: 2181 - def serialize(view: T): NbtCompound 2181 + trait Type[+T <: InventoryView]: 2182 2182 def deserialize(data: NbtCompound)(using ServerWorld): T 2183 2183 object Events: 2184 2184 val forEntity: Event[Entity => ServerWorld ?=> Seq[InventoryView]] = EventFactory.createArrayBacked[Entity => ServerWorld ?=> Seq[InventoryView]](classOf, _ => Seq(), fns => e => fns.flatMap(_(e))) 2185 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 OfMerged(views: => Seq[InventoryView]) extends InventoryView: 2186 + abstract class OfMerged(viewType: InventoryView.Type[?], views: => Seq[InventoryView]) extends InventoryView(viewType): 2187 2187 def getViews = views 2188 2188 override def apply(idx: Int)(using CastingEnvironment): Option[SlotReference] = views.collectFirst(hexicVisibilityHack.unlifted(_(idx))) 2189 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 2190 override def entities(using TransactionContext) = views.flatMap(_.entities).toSet 2191 2191 override def teleportEntity(ent: Entity)(using TransactionContext, CastingEnvironment): Boolean = views.iterator∃(_.teleportEntity(ent)) 2192 - class OfEntity(entity: => Option[Entity])(using world: ServerWorld) extends OfMerged(entity.fold(Seq())(Events.forEntity.invoker()(_))) 2193 - class OfBlock(pos: BlockPos)(using world: ServerWorld) extends OfMerged(Events.forBlock.invoker()(pos, world.getBlockState(pos))) 2194 - class OfExactEntity(entity: => Entity)(using ServerWorld) extends InventoryView: 2192 + class OfSum private(private[InventoryView] val views: Seq[InventoryView]) extends OfMerged(typeOfSum, views): 2193 + override def serialize = 2194 + val c = NbtCompound() 2195 + val list = NbtList() 2196 + for view <- views do list.add(view.serialize) 2197 + c.put("c", list) 2198 + c 2199 + object OfSum: 2200 + def apply(views: InventoryView*) = new OfSum( 2201 + views.flatMap: 2202 + case v: OfSum => v.views 2203 + case v => Iterable(v) 2204 + ) 2205 + class OfEntity(id: UUID)(using server: MinecraftServer) extends OfMerged(typeOfEntity, server.getWorlds.collectFirst(hexicVisibilityHack.unlifted(w => Option(w.getEntity(id)).map(Events.forEntity.invoker()(_)(using w)))).getOrElse(Seq())): 2206 + override def serialize = 2207 + val c: NbtCompound() 2208 + c.put("m", id.getMostSignificantBits) 2209 + c.put("l", id.getLeastSignificantBits) 2210 + c 2211 + class OfBlock(pos: BlockPos)(using world: ServerWorld) extends OfMerged(typeOfBlock, Events.forBlock.invoker()(pos, world.getBlockState(pos))): 2212 + override def serialize = 2213 + val c = NbtCompound() 2214 + val w = world.getRegistryKey.getValue 2215 + if w.getNamespace != "minecraft" then c.put("m", w.getNamespace) 2216 + if w.getPath != "overworld" then c.put("w", w.getPath) 2217 + c.put("u", pos.getX) 2218 + c.put("x", pos.getY) 2219 + c.put("v", pos.getZ) 2220 + class OfExactEntity(entity: => Entity)(using ServerWorld) extends InventoryView(typeOfExactEntity): 2221 + override val viewType = typeOfExactEntity 2195 2222 override def entities(using TransactionContext) = Set(entity) 2223 + private given typeOfSum: InventoryView.Type[OfSum]: 2224 + override def deserialize(data: NbtCompound)(using ServerWorld): OfSum = ??? 2225 + private given typeOfEntity: InventoryView.Type[OfEntity]: 2226 + override def deserialize(data: NbtCompound)(using ServerWorld): OfEntity = ??? 2227 + private given typeOfBlock: InventoryView.Type[OfBlock]: 2228 + override def deserialize(data: NbtCompound)(using ServerWorld): OfBlock = ??? 2229 + private given typeOfExactEntity: InventoryView.Type[OfExactEntity]: 2230 + override def deserialize(data: NbtCompound)(using ServerWorld): OfExactEntity = ??? 2231 + registry("sum") = typeOfSum 2232 + registry("entity") = typeOfEntity 2233 + registry("block") = typeOfBlock 2234 + registry("exact") = typeOfExactEntity 2196 2235 2197 2236 object SlotReference extends Registrar[SlotReference.Type[?]]("slot"): 2198 2237 class Type[T <: SlotReference: Codec]