Class CastingEnvironment
java.lang.Object
at.petrak.hexcasting.api.casting.eval.CastingEnvironment
- Direct Known Subclasses:
CircleCastEnv,PlayerBasedCastEnv
Environment within which hexes are cast.
Stuff like "the player with a staff," "the player with a trinket," "spell circles,"
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordprotected static enumThe order/mode stacks should be discovered in -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Map<CastingEnvironmentComponent.Key<?>,@NotNull CastingEnvironmentComponent> protected final net.minecraft.server.level.ServerLevel -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCastingEnvironment(net.minecraft.server.level.ServerLevel world) -
Method Summary
Modifier and TypeMethodDescriptionprotected @Nullable net.minecraft.resources.ResourceLocationactionKey(PatternShapeMatch match) static voidaddCreateEventListener(BiConsumer<CastingEnvironment, net.minecraft.nbt.CompoundTag> listener) Add a listener that will be called whenever a new CastingEnvironment is created.static voidaddCreateEventListener(Consumer<CastingEnvironment> listener) Deprecated.<T extends CastingEnvironmentComponent>
voidaddExtension(T extension) final voidassertEntityInRange(net.minecraft.world.entity.Entity e) Convenience function to throw if the entity is out of the caster's range or the worldfinal voidassertPosInRange(net.minecraft.core.BlockPos vec) final voidassertPosInRangeForEditing(net.minecraft.core.BlockPos vec) final voidassertVecInRange(net.minecraft.world.phys.Vec3 vec) Convenience function to throw if the vec is out of the caster's range or the worldfinal voidassertVecInWorld(net.minecraft.world.phys.Vec3 vec) Convenience function to throw if the vec is out of the world (for GTP)final booleancanEditBlockAt(net.minecraft.core.BlockPos vec) longextractMedia(long cost, boolean simulate) Attempt to extract the given amount of media.protected abstract longextractMediaEnvironment(long cost, boolean simulate) Attempt to extract the given amount of media.@Nullable net.minecraft.server.level.ServerPlayerDeprecated.as of build 0.11.1-7-pre-619 you are recommended to usegetCastingEntity()abstract @Nullable net.minecraft.world.entity.LivingEntityGets the caster.abstract net.minecraft.world.InteractionHand<T extends CastingEnvironmentComponent>
T@Nullable CastingEnvironment.HeldItemInfogetHeldItemToOperateOn(Predicate<net.minecraft.world.item.ItemStack> stackOk) Return the slot from which to take blocks and items.abstract MishapEnvironmentGet an interface used to do mishapsnet.minecraft.world.InteractionHandabstract FrozenPigmentprotected abstract List<CastingEnvironment.HeldItemInfo>Get the primary/secondary item stacks this env can use (i.e.protected List<CastingEnvironment.HeldItemInfo>getPrimaryStacksForPlayer(net.minecraft.world.InteractionHand castingHand, net.minecraft.server.level.ServerPlayer caster) protected abstract List<net.minecraft.world.item.ItemStack>Get all the item stacks this env can use.protected List<net.minecraft.world.item.ItemStack>getUsableStacksForPlayer(CastingEnvironment.StackDiscoveryMode mode, @Nullable net.minecraft.world.InteractionHand castingHand, net.minecraft.server.level.ServerPlayer caster) final net.minecraft.server.level.ServerLevelgetWorld()booleanhasEditPermissionsAt(net.minecraft.core.BlockPos pos) Return whether the caster can edit blocks at the given permission (i.e.protected abstract booleanhasEditPermissionsAtEnvironment(net.minecraft.core.BlockPos pos) Return whether the caster can edit blocks at the given permission (i.e.protected booleanWhether to provide infinite items.booleanReturn whether this env can cast great spells.final booleanisEntityInRange(net.minecraft.world.entity.Entity e) final booleanisEntityInRange(net.minecraft.world.entity.Entity e, boolean ignoreTruenameAmbit) final booleanisVecInAmbit(net.minecraft.world.phys.Vec3 vec) booleanisVecInRange(net.minecraft.world.phys.Vec3 vec) Get if the vec is close enough, to the player or sentinel ...protected abstract booleanisVecInRangeEnvironment(net.minecraft.world.phys.Vec3 vec) Get if the vec is close enough, to the player or sentinel ...final booleanisVecInWorld(net.minecraft.world.phys.Vec3 vec) intabstract net.minecraft.world.phys.Vec3voidpostCast(at.petrak.hexcasting.api.casting.eval.vm.CastingImage image) Do things after the whole cast is finished (i.e.voidpostExecution(at.petrak.hexcasting.api.casting.eval.CastResult result) Do whatever you like after a pattern is executed.voidprecheckAction(PatternShapeMatch match) If something about this ARE itself is invalid, mishap.abstract voidprintMessage(net.minecraft.network.chat.Component message) abstract voidproduceParticles(at.petrak.hexcasting.api.casting.ParticleSpray particles, FrozenPigment colorizer) @Nullable net.minecraft.world.item.ItemStackqueryForMatchingStack(Predicate<net.minecraft.world.item.ItemStack> stackOk) Return the slot from which to take blocks and items.voidabstract booleanreplaceItem(Predicate<net.minecraft.world.item.ItemStack> stackOk, net.minecraft.world.item.ItemStack replaceWith, @Nullable net.minecraft.world.InteractionHand hand) Attempt to replace the first stack found which matches the predicate with the stack to replace with.booleanreplaceItemForPlayer(Predicate<net.minecraft.world.item.ItemStack> stackOk, net.minecraft.world.item.ItemStack replaceWith, @Nullable net.minecraft.world.InteractionHand hand, net.minecraft.server.level.ServerPlayer caster) abstract @Nullable FrozenPigmentsetPigment(@Nullable FrozenPigment pigment) final voidtriggerCreateEvent(net.minecraft.nbt.CompoundTag userData) booleanwithdrawItem(Predicate<net.minecraft.world.item.ItemStack> stackOk, int count, boolean actuallyRemove) Attempt to withdraw some number of items from stacks available.
-
Field Details
-
world
protected final net.minecraft.server.level.ServerLevel world -
componentMap
-
-
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.replaced byaddCreateEventListener(BiConsumer)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 usegetCastingEntity()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 ifgetCaster()is also null- Returns:
- the entity casting
-
getMishapEnvironment
Get an interface used to do mishaps -
addExtension
-
removeExtension
-
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
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
-
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)
-
addCreateEventListener(BiConsumer)