Skip to content

Commit

Permalink
Merge pull request #590 from walksanatora/caster-relaxation
Browse files Browse the repository at this point in the history
Open up ability for entity-based casting environments
  • Loading branch information
object-Object authored Feb 7, 2024
2 parents 74bafe2 + de59322 commit b0a8530
Show file tree
Hide file tree
Showing 35 changed files with 96 additions and 299 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;
Expand Down Expand Up @@ -82,9 +83,20 @@ public final ServerLevel getWorld() {
* <p>
* Implementations should NOT rely on this in general, use the methods on this class instead.
* This is mostly for spells (flight, etc)
* @deprecated as of build 0.11.1-7-pre-619 you are recommended to use {@link #getCastingEntity}
*/
@Deprecated(since="0.11.1-7-pre-619")
@Nullable
public abstract ServerPlayer getCaster();
public ServerPlayer getCaster() {
return getCastingEntity() instanceof ServerPlayer sp ? sp : null;
};

/**
* Gets the caster. Can be null if {@link #getCaster()} is also null
* @return the entity casting
*/
@Nullable
public abstract LivingEntity getCastingEntity();

/**
* Get an interface used to do mishaps
Expand Down Expand Up @@ -168,15 +180,15 @@ public void postExecution(CastResult result) {
* Return whether this env can cast great spells.
*/
public boolean isEnlightened() {
var caster = this.getCaster();
if (caster == null)
return false;

var adv = this.world.getServer().getAdvancements().getAdvancement(modLoc("enlightenment"));
if (adv == null)
return false;

return caster.getAdvancements().getOrStartProgress(adv).isDone();
var caster = this.getCastingEntity();
if (caster instanceof ServerPlayer player)
return player.getAdvancements().getOrStartProgress(adv).isDone();

return false;
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.Nullable;
Expand All @@ -38,6 +39,11 @@ public CircleCastEnv(ServerLevel world, CircleExecutionState execState) {
this.execState = execState;
}

@Override
public @Nullable LivingEntity getCastingEntity() {
return this.execState.getCaster(this.world);
}

@Override
public @Nullable ServerPlayer getCaster() {
return this.execState.getCaster(this.world);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.GameType;
Expand All @@ -46,6 +47,11 @@ protected PlayerBasedCastEnv(ServerPlayer caster, InteractionHand castingHand) {
this.castingHand = castingHand;
}

@Override
public LivingEntity getCastingEntity() {
return this.caster;
}

@Override
public ServerPlayer getCaster() {
return this.caster;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import at.petrak.hexcasting.api.pigment.FrozenPigment
import at.petrak.hexcasting.api.utils.asTranslatedComponent
import at.petrak.hexcasting.common.lib.HexItems
import net.minecraft.Util
import net.minecraft.server.level.ServerPlayer
import net.minecraft.world.item.DyeColor
import net.minecraft.world.item.ItemStack

Expand All @@ -21,7 +22,7 @@ sealed class OperatorSideEffect {

data class RequiredEnlightenment(val awardStat: Boolean) : OperatorSideEffect() {
override fun performEffect(harness: CastingVM): Boolean {
harness.env.caster?.sendSystemMessage("hexcasting.message.cant_great_spell".asTranslatedComponent)
harness.env.castingEntity?.sendSystemMessage("hexcasting.message.cant_great_spell".asTranslatedComponent)


return true
Expand All @@ -38,7 +39,7 @@ sealed class OperatorSideEffect {
override fun performEffect(harness: CastingVM): Boolean {
this.spell.cast(harness.env, harness.image)?.let { harness.image = it }
if (awardStat)
harness.env.caster?.awardStat(HexStatistics.SPELLS_CAST)
(harness.env.castingEntity as? ServerPlayer)?.awardStat(HexStatistics.SPELLS_CAST)

return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MishapAlreadyBrainswept(val mob: Mob) : Mishap() {
dyeColor(DyeColor.GREEN)

override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
mob.hurt(mob.damageSources().source(HexDamageTypes.OVERCAST, ctx.caster), mob.health)
mob.hurt(mob.damageSources().source(HexDamageTypes.OVERCAST, ctx.castingEntity), mob.health)
}

override fun particleSpray(ctx: CastingEnvironment) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MishapBadBrainsweep(val mob: Mob, val pos: BlockPos) : Mishap() {
dyeColor(DyeColor.GREEN)

override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
trulyHurt(mob, mob.damageSources().source(HexDamageTypes.OVERCAST, ctx.caster), 1f)
trulyHurt(mob, mob.damageSources().source(HexDamageTypes.OVERCAST, ctx.castingEntity), 1f)
}

override fun particleSpray(ctx: CastingEnvironment): ParticleSpray {
Expand Down
Loading

0 comments on commit b0a8530

Please sign in to comment.