Made Circles able to have a player again. Made the AABB of the circle used. Made StaffCastEnv and PackagedItemCastEnv give creative players inf media.

This commit is contained in:
Talia-12 2023-04-02 21:22:13 +10:00
parent 9d0c828b4f
commit 337736e32d
5 changed files with 66 additions and 19 deletions

View file

@ -13,15 +13,13 @@ import net.minecraft.nbt.NbtUtils;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.phys.AABB;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.Stack;
import java.util.*;
/**
* See {@link BlockEntityAbstractImpetus}, this is what's stored in it
@ -31,7 +29,8 @@ public class CircleExecutionState {
TAG_KNOWN_POSITIONS = "known_positions",
TAG_CURRENT_POS = "current_pos",
TAG_ENTERED_FROM = "entered_from",
TAG_IMAGE = "image";
TAG_IMAGE = "image",
TAG_CASTER = "caster";
// Does contain the starting impetus
public final Set<BlockPos> knownPositions;
@ -41,19 +40,22 @@ public class CircleExecutionState {
public final AABB bounds;
public @Nullable UUID caster;
protected CircleExecutionState(Set<BlockPos> knownPositions, BlockPos currentPos, Direction enteredFrom,
CastingImage currentImage) {
CastingImage currentImage, @Nullable UUID caster) {
this.knownPositions = knownPositions;
this.currentPos = currentPos;
this.enteredFrom = enteredFrom;
this.currentImage = currentImage;
this.caster = caster;
this.bounds = BlockEntityAbstractImpetus.getBounds(new ArrayList<>(this.knownPositions));
}
// Return null if the circle does not close.
public static @Nullable CircleExecutionState createNew(BlockEntityAbstractImpetus impetus) {
public static @Nullable CircleExecutionState createNew(BlockEntityAbstractImpetus impetus, @Nullable ServerPlayer caster) {
var level = (ServerLevel) impetus.getLevel();
if (level == null)
@ -95,8 +97,11 @@ public class CircleExecutionState {
}
var start = seenGoodPositions.get(0);
return new CircleExecutionState(new HashSet<>(seenGoodPositions), start, impetus.getStartDirection(),
new CastingImage());
if (caster == null)
return new CircleExecutionState(new HashSet<>(seenGoodPositions), start, impetus.getStartDirection(), new CastingImage(), null);
else
return new CircleExecutionState(new HashSet<>(seenGoodPositions), start, impetus.getStartDirection(), new CastingImage(), caster.getUUID());
}
public CompoundTag save() {
@ -112,6 +117,9 @@ public class CircleExecutionState {
out.putByte(TAG_ENTERED_FROM, (byte) this.enteredFrom.ordinal());
out.put(TAG_IMAGE, this.currentImage.serializeToNbt());
if (this.caster != null)
out.putUUID(TAG_CASTER, this.caster);
return out;
}
@ -126,7 +134,11 @@ public class CircleExecutionState {
var enteredFrom = Direction.values()[nbt.getByte(TAG_ENTERED_FROM)];
var image = CastingImage.loadFromNbt(nbt.getCompound(TAG_IMAGE), world);
return new CircleExecutionState(knownPositions, currentPos, enteredFrom, image);
UUID caster = null;
if (nbt.hasUUID(TAG_CASTER))
caster = nbt.getUUID(TAG_CASTER);
return new CircleExecutionState(knownPositions, currentPos, enteredFrom, image, caster);
}
/**
@ -140,7 +152,11 @@ public class CircleExecutionState {
if (world == null)
return true; // if the world is null, try again next tick.
var env = new CircleCastEnv(world, impetus.getBlockPos(), impetus.getStartDirection());
ServerPlayer caster = null;
if (this.caster != null && world.getEntity(this.caster) instanceof ServerPlayer player)
caster = player;
var env = new CircleCastEnv(world, impetus.getBlockPos(), impetus.getStartDirection(), caster, this.bounds);
var executorBlock = world.getBlockState(this.currentPos);
if (!(executorBlock instanceof ICircleComponent executor)) {
@ -151,7 +167,7 @@ public class CircleExecutionState {
boolean halt = false;
var ctrl = executor.acceptControlFlow(this.currentImage, env, this.enteredFrom, this.currentPos,
executorBlock, world);
if (ctrl instanceof ICircleComponent.ControlFlow.Stop stop) {
if (ctrl instanceof ICircleComponent.ControlFlow.Stop) {
// acceptControlFlow should have already posted the error
halt = true;
} else if (ctrl instanceof ICircleComponent.ControlFlow.Continue cont) {

View file

@ -1,5 +1,6 @@
package at.petrak.hexcasting.api.casting.eval.env;
import at.petrak.hexcasting.api.HexAPI;
import at.petrak.hexcasting.api.casting.ParticleSpray;
import at.petrak.hexcasting.api.casting.circles.BlockEntityAbstractImpetus;
import at.petrak.hexcasting.api.casting.eval.CastResult;
@ -17,28 +18,34 @@ import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import static at.petrak.hexcasting.api.casting.eval.env.PlayerBasedCastEnv.SENTINEL_RADIUS;
public class CircleCastEnv extends CastingEnvironment {
protected EvalSound sound = HexEvalSounds.NOTHING;
protected final BlockPos impetusLoc;
protected final Direction startDir;
protected final @Nullable ServerPlayer caster;
protected final AABB bounds;
public CircleCastEnv(ServerLevel world, BlockPos impetusLoc, Direction startDir) {
public CircleCastEnv(ServerLevel world, BlockPos impetusLoc, Direction startDir, @Nullable ServerPlayer caster, AABB bounds) {
super(world);
this.impetusLoc = impetusLoc;
this.startDir = startDir;
this.caster = caster;
this.bounds = bounds;
}
@Override
public @Nullable ServerPlayer getCaster() {
return null;
return this.caster;
}
public @Nullable BlockEntityAbstractImpetus getCircle() {
@ -59,7 +66,7 @@ public class CircleCastEnv extends CastingEnvironment {
@Override
public MishapEnvironment getMishapEnvironment() {
return new CircleMishapEnv(this.world, this.impetusLoc, this.startDir);
return new CircleMishapEnv(this.world, this.impetusLoc, this.startDir, this.caster, this.bounds);
}
@Override
@ -96,7 +103,18 @@ public class CircleCastEnv extends CastingEnvironment {
@Override
public boolean isVecInRange(Vec3 vec) {
return false;
if (this.caster != null) {
var sentinel = HexAPI.instance().getSentinel(this.caster);
if (sentinel != null
&& sentinel.extendsRange()
&& this.caster.getLevel().dimension() == sentinel.dimension()
&& vec.distanceToSqr(sentinel.position()) <= SENTINEL_RADIUS * SENTINEL_RADIUS
) {
return true;
}
}
return this.bounds.contains(vec);
}
@Override

View file

@ -4,16 +4,23 @@ import at.petrak.hexcasting.api.casting.eval.MishapEnvironment;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.Nullable;
public class CircleMishapEnv extends MishapEnvironment {
protected final BlockPos impetusLoc;
protected final Direction startDir;
protected final @Nullable ServerPlayer caster;
protected final AABB bounds;
protected CircleMishapEnv(ServerLevel world, BlockPos impetusLoc, Direction startDir) {
protected CircleMishapEnv(ServerLevel world, BlockPos impetusLoc, Direction startDir, @Nullable ServerPlayer caster, AABB bounds) {
super(world, null);
this.impetusLoc = impetusLoc;
this.startDir = startDir;
this.caster = caster;
this.bounds = bounds;
}
@Override

View file

@ -34,6 +34,9 @@ public class PackagedItemCastEnv extends PlayerBasedCastEnv {
@Override
public long extractMedia(long costLeft) {
if (this.caster.isCreative())
return 0;
var casterStack = this.caster.getItemInHand(this.castingHand);
var casterHexHolder = IXplatAbstractions.INSTANCE.findHexHolder(casterStack);
var canCastFromInv = casterHexHolder.canDrawMediaFromInventory();

View file

@ -20,7 +20,7 @@ import java.util.HashSet;
import java.util.List;
public class StaffCastEnv extends PlayerBasedCastEnv {
private InteractionHand castingHand;
private final InteractionHand castingHand;
public StaffCastEnv(ServerPlayer caster, InteractionHand castingHand) {
@ -40,6 +40,9 @@ public class StaffCastEnv extends PlayerBasedCastEnv {
@Override
public long extractMedia(long cost) {
if (this.caster.isCreative())
return 0;
var canOvercast = this.canOvercast();
var remaining = this.extractMediaFromInventory(cost, canOvercast);
if (remaining > 0 && !canOvercast) {