Class CastingEnvironment

java.lang.Object
at.petrak.hexcasting.api.casting.eval.CastingEnvironment
Direct Known Subclasses:
CircleCastEnv, PlayerBasedCastEnv

public abstract class CastingEnvironment extends Object
Environment within which hexes are cast.

Stuff like "the player with a staff," "the player with a trinket," "spell circles,"

  • Field Details

  • Constructor Details

    • CastingEnvironment

      protected CastingEnvironment(net.minecraft.server.level.ServerLevel world)
  • Method Details

    • addCreateEventListener

      public static void addCreateEventListener(BiConsumer<CastingEnvironment,net.minecraft.nbt.CompoundTag> listener)
      Add a listener that will be called whenever a new CastingEnvironment is created.
    • addCreateEventListener

      @Deprecated(since="0.11.0-pre-660") public static void addCreateEventListener(Consumer<CastingEnvironment> listener)
      Deprecated.
      Add a listener that will be called whenever a new CastingEnvironment is created (legacy).
    • triggerCreateEvent

      public final void triggerCreateEvent(net.minecraft.nbt.CompoundTag userData)
    • getWorld

      public final net.minecraft.server.level.ServerLevel getWorld()
    • maxOpCount

      public int maxOpCount()
    • getCaster

      @Deprecated(since="0.11.1-7-pre-619") @Nullable public @Nullable net.minecraft.server.level.ServerPlayer getCaster()
      Deprecated.
      as of build 0.11.1-7-pre-619 you are recommended to use getCastingEntity()
      Get the caster. Might be null!

      Implementations should NOT rely on this in general, use the methods on this class instead. This is mostly for spells (flight, etc)

    • getCastingEntity

      @Nullable public abstract @Nullable net.minecraft.world.entity.LivingEntity getCastingEntity()
      Gets the caster. Can be null if getCaster() is also null
      Returns:
      the entity casting
    • getMishapEnvironment

      public abstract MishapEnvironment getMishapEnvironment()
      Get an interface used to do mishaps
    • addExtension

      public <T extends CastingEnvironmentComponent> void addExtension(@NotNull T extension)
    • removeExtension

      public void removeExtension(@NotNull CastingEnvironmentComponent.Key<?> key)
    • getExtension

      @Nullable public <T extends CastingEnvironmentComponent> T getExtension(@NotNull CastingEnvironmentComponent.Key<T> key)
    • precheckAction

      public void precheckAction(PatternShapeMatch match) throws at.petrak.hexcasting.api.casting.mishaps.Mishap
      If something about this ARE itself is invalid, mishap.

      This is used for stuff like requiring enlightenment and pattern denylists

      Throws:
      at.petrak.hexcasting.api.casting.mishaps.Mishap
    • actionKey

      @Nullable protected @Nullable net.minecraft.resources.ResourceLocation actionKey(PatternShapeMatch match)
    • postExecution

      public void postExecution(at.petrak.hexcasting.api.casting.eval.CastResult result)
      Do whatever you like after a pattern is executed.
    • postCast

      public void postCast(at.petrak.hexcasting.api.casting.eval.vm.CastingImage image)
      Do things after the whole cast is finished (i.e. every pattern to be executed has been executed).
    • mishapSprayPos

      public abstract net.minecraft.world.phys.Vec3 mishapSprayPos()
    • isEnlightened

      public boolean isEnlightened()
      Return whether this env can cast great spells.
    • extractMedia

      public long extractMedia(long cost, boolean simulate)
      Attempt to extract the given amount of media. Returns the amount of media left in the cost.

      If there was enough media found, it will return less or equal to zero; if there wasn't, it will be positive.

    • extractMediaEnvironment

      protected abstract long extractMediaEnvironment(long cost, boolean simulate)
      Attempt to extract the given amount of media. Returns the amount of media left in the cost.

      If there was enough media found, it will return less or equal to zero; if there wasn't, it will be positive.

    • isVecInRange

      public boolean isVecInRange(net.minecraft.world.phys.Vec3 vec)
      Get if the vec is close enough, to the player or sentinel ...

      Doesn't take into account being out of the world.

    • isVecInRangeEnvironment

      protected abstract boolean isVecInRangeEnvironment(net.minecraft.world.phys.Vec3 vec)
      Get if the vec is close enough, to the player or sentinel ...

      Doesn't take into account being out of the world.

    • hasEditPermissionsAt

      public boolean hasEditPermissionsAt(net.minecraft.core.BlockPos pos)
      Return whether the caster can edit blocks at the given permission (i.e. not adventure mode, etc.)
    • hasEditPermissionsAtEnvironment

      protected abstract boolean hasEditPermissionsAtEnvironment(net.minecraft.core.BlockPos pos)
      Return whether the caster can edit blocks at the given permission (i.e. not adventure mode, etc.)
    • isVecInWorld

      public final boolean isVecInWorld(net.minecraft.world.phys.Vec3 vec)
    • isVecInAmbit

      public final boolean isVecInAmbit(net.minecraft.world.phys.Vec3 vec)
    • isEntityInRange

      public final boolean isEntityInRange(net.minecraft.world.entity.Entity e)
    • isEntityInRange

      public final boolean isEntityInRange(net.minecraft.world.entity.Entity e, boolean ignoreTruenameAmbit)
    • assertVecInRange

      public final void assertVecInRange(net.minecraft.world.phys.Vec3 vec) throws at.petrak.hexcasting.api.casting.mishaps.MishapBadLocation
      Convenience function to throw if the vec is out of the caster's range or the world
      Throws:
      at.petrak.hexcasting.api.casting.mishaps.MishapBadLocation
    • assertPosInRange

      public final void assertPosInRange(net.minecraft.core.BlockPos vec) throws at.petrak.hexcasting.api.casting.mishaps.MishapBadLocation
      Throws:
      at.petrak.hexcasting.api.casting.mishaps.MishapBadLocation
    • assertPosInRangeForEditing

      public final void assertPosInRangeForEditing(net.minecraft.core.BlockPos vec) throws at.petrak.hexcasting.api.casting.mishaps.MishapBadLocation
      Throws:
      at.petrak.hexcasting.api.casting.mishaps.MishapBadLocation
    • canEditBlockAt

      public final boolean canEditBlockAt(net.minecraft.core.BlockPos vec)
    • assertEntityInRange

      public final void assertEntityInRange(net.minecraft.world.entity.Entity e) throws at.petrak.hexcasting.api.casting.mishaps.MishapEntityTooFarAway
      Convenience function to throw if the entity is out of the caster's range or the world
      Throws:
      at.petrak.hexcasting.api.casting.mishaps.MishapEntityTooFarAway
    • assertVecInWorld

      public final void assertVecInWorld(net.minecraft.world.phys.Vec3 vec) throws at.petrak.hexcasting.api.casting.mishaps.MishapBadLocation
      Convenience function to throw if the vec is out of the world (for GTP)
      Throws:
      at.petrak.hexcasting.api.casting.mishaps.MishapBadLocation
    • getCastingHand

      public abstract net.minecraft.world.InteractionHand getCastingHand()
    • getOtherHand

      public net.minecraft.world.InteractionHand getOtherHand()
    • getUsableStacks

      protected abstract List<net.minecraft.world.item.ItemStack> getUsableStacks(CastingEnvironment.StackDiscoveryMode mode)
      Get all the item stacks this env can use.
    • getUsableStacksForPlayer

      protected List<net.minecraft.world.item.ItemStack> getUsableStacksForPlayer(CastingEnvironment.StackDiscoveryMode mode, @Nullable @Nullable net.minecraft.world.InteractionHand castingHand, net.minecraft.server.level.ServerPlayer caster)
    • getPrimaryStacks

      protected abstract List<CastingEnvironment.HeldItemInfo> getPrimaryStacks()
      Get the primary/secondary item stacks this env can use (i.e. main hand and offhand for the player).
    • getPrimaryStacksForPlayer

      protected List<CastingEnvironment.HeldItemInfo> getPrimaryStacksForPlayer(net.minecraft.world.InteractionHand castingHand, net.minecraft.server.level.ServerPlayer caster)
    • queryForMatchingStack

      @Nullable public @Nullable net.minecraft.world.item.ItemStack queryForMatchingStack(Predicate<net.minecraft.world.item.ItemStack> stackOk)
      Return the slot from which to take blocks and items.
    • getHeldItemToOperateOn

      @Nullable public @Nullable CastingEnvironment.HeldItemInfo getHeldItemToOperateOn(Predicate<net.minecraft.world.item.ItemStack> stackOk)
      Return the slot from which to take blocks and items.
    • isCreativeMode

      protected boolean isCreativeMode()
      Whether to provide infinite items.
    • withdrawItem

      public boolean withdrawItem(Predicate<net.minecraft.world.item.ItemStack> stackOk, int count, boolean actuallyRemove)
      Attempt to withdraw some number of items from stacks available.

      Return whether it was successful.

    • replaceItem

      public abstract boolean replaceItem(Predicate<net.minecraft.world.item.ItemStack> stackOk, net.minecraft.world.item.ItemStack replaceWith, @Nullable @Nullable net.minecraft.world.InteractionHand hand)
      Attempt to replace the first stack found which matches the predicate with the stack to replace with.
      Returns:
      whether it was successful.
    • replaceItemForPlayer

      public boolean replaceItemForPlayer(Predicate<net.minecraft.world.item.ItemStack> stackOk, net.minecraft.world.item.ItemStack replaceWith, @Nullable @Nullable net.minecraft.world.InteractionHand hand, net.minecraft.server.level.ServerPlayer caster)
    • getPigment

      public abstract FrozenPigment getPigment()
    • setPigment

      @Nullable public abstract @Nullable FrozenPigment setPigment(@Nullable @Nullable FrozenPigment pigment)
    • produceParticles

      public abstract void produceParticles(at.petrak.hexcasting.api.casting.ParticleSpray particles, FrozenPigment colorizer)
    • printMessage

      public abstract void printMessage(net.minecraft.network.chat.Component message)