repo for my hex addons :3
0
fork

Configure Feed

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

*guardian curse noise*

+79 -35
+1
project/hexic/src/client/scala/org/eu/net/pool/hexic/client.scala
··· 350 350 "staffcast_factory" -> "Lani's Greater Gambit", 351 351 "staffcast_factory/lazy" -> "Lani's Lesser Gambit", 352 352 "take" -> "Retention Distillation", 353 + "thinkaboutit" -> "Inquiry Purification", 353 354 "unfox" -> "Vulpine Expulsion", 354 355 "where" -> "Deductive Purification", 355 356 ) do gen.add(s"hexcasting.action.hexic:$action", name)
+78 -35
project/hexic/src/main/scala/org/eu/net/pool/hexic/views.scala
··· 12 12 import com.samsthenerd.inline.impl.InlineStyle 13 13 import net.fabricmc.fabric.api.dimension.v1.FabricDimensions 14 14 import net.fabricmc.fabric.api.event.{Event, EventFactory} 15 + import net.fabricmc.fabric.api.resource.ResourceReloadListenerKeys 15 16 import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant 16 17 import net.fabricmc.fabric.api.transfer.v1.item.{ItemStorage, ItemVariant} 17 18 import net.fabricmc.fabric.api.transfer.v1.storage.{Storage, TransferVariant} 18 19 import net.fabricmc.fabric.api.transfer.v1.transaction.base.SnapshotParticipant 19 20 import net.fabricmc.fabric.api.transfer.v1.transaction.{Transaction, TransactionContext} 20 - import net.minecraft.block.BlockState 21 + import net.minecraft.block.{AbstractFurnaceBlock, BlockState} 21 22 import net.minecraft.block.entity.AbstractFurnaceBlockEntity 22 - import net.minecraft.entity.Entity 23 + import net.minecraft.entity.decoration.ItemFrameEntity 23 24 import net.minecraft.entity.player.PlayerEntity 24 - import net.minecraft.fluid.Fluid 25 - import net.minecraft.item.Item 25 + import net.minecraft.entity.{Entity, ItemEntity} 26 + import net.minecraft.fluid.{Fluid, Fluids} 27 + import net.minecraft.item.{Item, Items} 26 28 import net.minecraft.nbt.{NbtCompound, NbtElement, NbtList, NbtLong} 27 29 import net.minecraft.registry.{RegistryKey, RegistryKeys} 28 30 import net.minecraft.server.MinecraftServer ··· 30 32 import net.minecraft.text.{HoverEvent, MutableText, Text} 31 33 import net.minecraft.util.Identifier 32 34 import net.minecraft.util.math.{BlockPos, Box} 33 - import net.minecraft.world.{TeleportTarget, World} 35 + import net.minecraft.world.{BlockView, TeleportTarget, World} 34 36 import org.eu.net.pool.phlib.{*, given} 35 37 import org.slf4j.{Logger, LoggerFactory} 38 + import ram.talia.moreiotas.api.casting.iota.{ItemStackIota, ItemTypeIota} 36 39 37 40 import java.util.UUID 41 + import scala.annotation.tailrec 38 42 import scala.collection.immutable.ArraySeq.unsafeWrapArray 39 43 import scala.collection.mutable 40 44 import scala.reflect.ClassTag 41 - import scala.util.{Failure, Success, Using} 45 + import scala.util.{Failure, Success, Using, boundary} 42 46 43 47 trait InventoryView(val viewType: InventoryView.Type[?]) extends InventoryView.Handler: 44 48 def isTruthy = true ··· 48 52 def deserialize(data: NbtCompound)(using ServerWorld): Option[T] 49 53 trait Handler: 50 54 def apply(idx: Int)(using CastingEnvironment): Option[SlotReference] = None 55 + def contents(using TransactionContext, CastingEnvironment): Set[VariantIota[?]] = Set() 51 56 def tryExtract(variant: TransferVariant[?], amount: Long)(using TransactionContext, CastingEnvironment): Long = 0 52 57 def tryInsert(variant: TransferVariant[?], amount: Long)(using TransactionContext, CastingEnvironment): Long = 0 53 58 def capacity(variant: TransferVariant[?])(using TransactionContext, CastingEnvironment): Long = ··· 72 77 abstract class OfMerged(viewType: InventoryView.Type[?], views: => Seq[Handler]) extends InventoryView(viewType): 73 78 def getViews = views 74 79 override def apply(idx: Int)(using CastingEnvironment): Option[SlotReference] = views.collectFirst(Function.unlift(_(idx))) 80 + override def contents(using TransactionContext, CastingEnvironment) = views.flatMap(_.contents).toSet 75 81 override def tryExtract(variant: TransferVariant[?], amount: Long)(using TransactionContext, CastingEnvironment): Long = LazyList.from(views).scanLeft(0L)((n, view) => view.tryExtract(variant, amount - n) + n).findFirstOrLast(_ >= amount).getOrElse(0) 76 82 override def tryInsert(variant: TransferVariant[?], amount: Long)(using TransactionContext, CastingEnvironment): Long = LazyList.from(views).scanLeft(0L)((n, view) => view.tryInsert(variant, amount - n) + n).findFirstOrLast(_ >= amount).getOrElse(0) 77 83 override def capacity(variant: TransferVariant[?])(using TransactionContext, CastingEnvironment) = views.map(_.capacity(variant)).sum ··· 105 111 if w.getPath != "overworld" then c.put("w", w.getPath) 106 112 c.putLong("p", pos.asLong) 107 113 c 108 - class OfExactEntity(entity: => Entity)(using ServerWorld) extends InventoryView(typeOfExactEntity): 109 - override val viewType = typeOfExactEntity 110 - override def entities(using TransactionContext) = Set(entity) 111 - override def serialize = 112 - val c = super.serialize 113 - // TODO 114 - c 115 114 def deserialize(data: NbtCompound)(using ServerWorld): Option[InventoryView] = for 116 115 id <- Option(Identifier.tryParse(data.getString("id"))) 117 116 viewType <- Option(InventoryView.registry.get(id)) ··· 126 125 view <- InventoryView.deserialize(c) 127 126 yield view)*)) 128 127 private given typeOfEntity: InventoryView.Type[OfEntity]: 129 - override def deserialize(data: NbtCompound)(using ServerWorld): Option[OfEntity] = ??? 128 + override def deserialize(data: NbtCompound)(using world: ServerWorld): Option[OfEntity] = 129 + given MinecraftServer = world.getServer 130 + Some(OfEntity(UUID(data.getLong("m"), data.getLong("l")))) 130 131 private given typeOfBlock: InventoryView.Type[OfBlock]: 131 132 override def deserialize(data: NbtCompound)(using ServerWorld): Option[OfBlock] = 132 133 for ··· 137 138 key = RegistryKey.of(RegistryKeys.WORLD, Identifier.of(namespace, path)) 138 139 given ServerWorld <- Option(summon[ServerWorld].getServer.getWorld(key)) 139 140 yield OfBlock(pos) 140 - private given typeOfExactEntity: InventoryView.Type[OfExactEntity]: 141 - override def deserialize(data: NbtCompound)(using ServerWorld): Option[OfExactEntity] = ??? 142 141 registry("sum") = typeOfSum 143 142 registry("entity") = typeOfEntity 144 143 registry("block") = typeOfBlock 145 - registry("exact") = typeOfExactEntity 146 144 Events.forBlock.register: (pos, state) => 147 145 val storage = ItemStorage.SIDED.find(summon, pos, null): Storage[ItemVariant] 148 146 if storage == null then Seq() 149 147 else Seq( 150 148 new Handler: 149 + override def contents(using TransactionContext, CastingEnvironment): Set[VariantIota[?]] = storage.nonEmptyIterator.map(v => VariantIota(v.getResource, RegistryKey.of(VariantIota.key, Identifier("item")))).toSet 151 150 override def tryInsert(variant: TransferVariant[?], amount: Long)(using TransactionContext, CastingEnvironment): Long = 152 151 variant match 153 152 case i: ItemVariant => storage.insert(i, amount, summon) ··· 167 166 true 168 167 ) 169 168 else Seq() 170 - trait SingleVariantHandler(variant: TransferVariant[?]) extends Handler: 169 + trait SingleVariantHandler[O: ClassTag](variant: TransferVariant[O], key: RegistryKey[VariantIota.Reader]) extends Handler: 170 + def asIota = VariantIota(variant, key) 171 + def isPresent(using TransactionContext, CastingEnvironment): Boolean = true 172 + override def contents(using TransactionContext, CastingEnvironment): Set[VariantIota[?]] = if isPresent then Set(asIota) else Set() 171 173 override def tryExtract(variant: TransferVariant[?], amount: Long)(using TransactionContext, CastingEnvironment): Long = if variant == this.variant then trySubtract(amount) else 0L 172 174 override def tryInsert(variant: TransferVariant[?], amount: Long)(using TransactionContext, CastingEnvironment): Long = if variant == this.variant then tryAdd(amount) else 0L 173 175 override def capacity(variant: TransferVariant[?])(using TransactionContext, CastingEnvironment): Long = if variant == this.variant then cap else 0L ··· 177 179 178 180 Events.forBlock.register: (pos, state) => 179 181 summon[ServerWorld].getBlockEntity(pos) match 180 - case e: BlockEntityAbstractImpetus => Seq(new SingleVariantHandler(SingletonVariant.media) { 182 + case e: BlockEntityAbstractImpetus => Seq(new SingleVariantHandler(SingletonVariant.media, RegistryKey.of(VariantIota.key, "media")) { 181 183 private def mediaCapacity = 9000000000000000000L - e.getMedia 182 184 override def trySubtract(amount: Long)(using TransactionContext, CastingEnvironment): Long = 183 185 val toExtract = amount min e.getMedia ··· 193 195 Events.forBlock.register: (pos, state) => 194 196 summon[ServerWorld].getBlockEntity(pos) match 195 197 case e: AbstractFurnaceBlockEntity => Seq( 196 - new SingleVariantHandler(SingletonVariant.heat): 198 + new SingleVariantHandler(SingletonVariant.heat, RegistryKey.of(VariantIota.key, "heat")): 197 199 override def trySubtract(amount: Long)(using TransactionContext, CastingEnvironment): Long = 198 200 val action = (amount min e.burnTime).toInt 199 201 doSnapshot(e.burnTime, e.burnTime = _)(e.burnTime - action) 202 + doSnapshot(summon[ServerWorld].getBlockState(pos), summon[ServerWorld].setBlockState(pos, _, 3))(summon[ServerWorld].getBlockState(pos).`with`(AbstractFurnaceBlock.LIT, true)) 200 203 action 201 204 override def tryAdd(amount: Long)(using TransactionContext, CastingEnvironment): Long = 202 205 val action = (amount min cap).toInt ··· 230 233 231 234 object BoxedView extends IotaType[BoxedView.Instance]: 232 235 InventoryView 233 - class Instance(val view: InventoryView) extends Iota(BoxedView, view): 236 + case class Instance(view: InventoryView) extends Iota(BoxedView, view): 234 237 export view.{isTruthy, serialize} 235 238 override def toleratesOther(that: Iota): Boolean = that match 236 239 case that: BoxedView.Instance => view == that.view ··· 297 300 setConceptScale[SingletonVariant.heat.type](20) 298 301 Patterns.register("moveconcept", se"wawdwawqdewewedqwawdwaw"): 299 302 Patterns.mkConstAction(4): 300 - case Seq(isIota[BoxedView.Instance, 3](from), isIota[BoxedView.Instance, 2](into), typ: VariantIota[?], isIota[DoubleIota, 0](count)) => 301 - Using.resource(Transaction.openOuter()): 303 + case Seq(isIota[BoxedView.Instance, 3](BoxedView.Instance(from)), isIota[BoxedView.Instance, 2](BoxedView.Instance(into)), typ: VariantIota[?], isIota[DoubleIota, 0](count)) => 304 + val key = ClassTag(typ.data.getClass) 305 + val scale = conceptScale(key) 306 + @tailrec def negotiate(limit: Long): Seq[Iota] = 307 + val compromise = Using.resource(Transaction.openOuter()): 308 + case tx@given TransactionContext => 309 + val extracted = (from: InventoryView).tryExtract((typ: VariantIota[?]).data, limit) 310 + val inserted = (into: InventoryView).tryInsert((typ: VariantIota[?]).data, extracted) 311 + if extracted == inserted then 312 + tx.commit() 313 + return Seq(DoubleIota(inserted / scale)) 314 + else 315 + inserted 316 + negotiate(compromise) 317 + val initialLimit = Using.resource(Transaction.openOuter()): 302 318 case tx@given TransactionContext => 303 - val key = ClassTag(typ.data.getClass) 304 - val scale = conceptScale(key) 305 - val toExtract = (scale * count.getDouble).toLong 306 - val extract = from.view.tryExtract(typ.data, toExtract) 307 - if extract < toExtract then 308 - ??? // TODO: mishap 309 - val insert = into.view.tryInsert(typ.data, extract) 310 - if insert < extract then 311 - ??? // TODO: mishap 312 - tx.commit() 313 - Seq(DoubleIota(insert / scale)) 319 + val value = (into: InventoryView).tryInsert(typ.data, (scale * count.getDouble).toLong) 320 + tx.abort() 321 + value 322 + negotiate(initialLimit) 323 + 314 324 Patterns.register("moveentity", se"edeeewawdweaaddaqwqwqaddaaewdwawewdqd"): 315 325 Patterns.mkConstAction(3): 316 326 case Seq(isIota[BoxedView.Instance, 2](from), isIota[BoxedView.Instance, 1](into), isIota[DoubleIota, 0](count)) => ··· 319 329 val count = from.view.entities.count(into.view.teleportEntity) 320 330 if count > 0 then tx.commit() 321 331 Seq(DoubleIota(count)) 322 - 332 + Patterns.register("thinkaboutit", e"awqawewaqw"): 333 + Patterns.mkConstAction(1): 334 + case Seq(iota) => 335 + def dieOfBadType() = throw MishapInvalidIota.of(iota, 0, "hexic:not_eldritch_horror") 336 + iota match 337 + case BoxedView.Instance(view) => 338 + Using.resource(Transaction.openOuter()): 339 + case given TransactionContext => 340 + Seq(ListIota(view.contents.toSeq)) 341 + case i: ItemStackIota => Seq(if i.getItemStack.getItem == Items.AIR then NullIota() else VariantIota(ItemVariant.of(i.getItemStack), RegistryKey.of(VariantIota.key, Identifier("item")))) 342 + case i: ItemTypeIota => Seq(if i.getItem == Items.AIR then NullIota() else VariantIota(ItemVariant.of(i.getItem), RegistryKey.of(VariantIota.key, Identifier("item")))) 343 + case v: Vec3Iota => 344 + val pos = BlockPos.ofFloored(v.getVec3) 345 + summon[CastingEnvironment].assertPosInRange(pos) 346 + val state = summon[BlockView].getBlockState(pos) 347 + if state.isAir then 348 + Seq(NullIota()) 349 + else 350 + state.getFluidState.getFluid match 351 + case Fluids.EMPTY => 352 + state.getBlock.asItem match 353 + case null | Items.AIR => 354 + state.getBlock.getPickStack(summon, pos, state) match 355 + case null | Items.AIR => 356 + Seq(NullIota()) 357 + case item => Seq(VariantIota(ItemVariant.of(item), RegistryKey.of(VariantIota.key, Identifier("item")))) 358 + case item => Seq(VariantIota(ItemVariant.of(item), RegistryKey.of(VariantIota.key, Identifier("item")))) 359 + case fluid => Seq(VariantIota(FluidVariant.of(fluid), RegistryKey.of(VariantIota.key, Identifier("fluid")))) 360 + case e: EntityIota if !e.getEntity.isRemoved => 361 + e.getEntity match 362 + case s: ItemEntity => Seq(if s.getStack.getItem == Items.AIR then NullIota() else VariantIota(ItemVariant.of(s.getStack), RegistryKey.of(VariantIota.key, Identifier("item")))) 363 + case s: ItemFrameEntity => Seq(if s.getHeldItemStack.getItem == Items.AIR then NullIota() else VariantIota(ItemVariant.of(s.getHeldItemStack), RegistryKey.of(VariantIota.key, Identifier("item")))) 364 + case _ => dieOfBadType() 365 + case _ => dieOfBadType() 323 366 //noinspection UnstableApiUsage 324 367 case class VariantIota[T: ClassTag](data: TransferVariant[T], key: RegistryKey[VariantIota.Reader]) extends Iota(VariantIota, data): 325 368 override def isTruthy: Boolean = true