Fixed placed spells not reflecting their correct location in the dismiss spell screen

This commit is contained in:
Sollace 2024-05-25 21:01:33 +01:00
parent e9114f9e12
commit 7937604c41
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
2 changed files with 22 additions and 13 deletions

View file

@ -139,8 +139,8 @@ public class PlacementControlSpell extends AbstractSpell implements OrientedSpel
super.fromNBT(compound);
delegate = Spell.readNbt(compound.getCompound("spell"));
placedEntityId = compound.containsUuid("placedEntityId") ? compound.getUuid("placedEntityId") : null;
position = compound.contains("position") ? Optional.of(NbtSerialisable.readVector(compound.getList("position", NbtElement.FLOAT_TYPE))) : Optional.empty();
orientation = compound.contains("orientation") ? Optional.of(NbtSerialisable.readVector(compound.getList("orientation", NbtElement.FLOAT_TYPE))) : Optional.empty();
position = compound.contains("position") ? Optional.of(NbtSerialisable.readVector(compound.getList("position", NbtElement.DOUBLE_TYPE))) : Optional.empty();
orientation = compound.contains("orientation") ? Optional.of(NbtSerialisable.readVector(compound.getList("orientation", NbtElement.DOUBLE_TYPE))) : Optional.empty();
if (compound.contains("dimension", NbtElement.STRING_TYPE)) {
dimension = Optional.ofNullable(Identifier.tryParse(compound.getString("dimension"))).map(id -> RegistryKey.of(RegistryKeys.WORLD, id));
}

View file

@ -57,15 +57,16 @@ public class DismissSpellScreen extends GameGui {
}
double minimalDistance = 75 * (ring - 1) - 25;
Vec3d origin = pony.getOriginVector();
Vec3d origin = pony.asEntity().getPos();
placeableSpells.forEach(placeable -> {
placeable.getPosition().ifPresent(position -> {
Vec3d relativePos = position.subtract(origin);
Vec3d relativePos = position.subtract(origin).multiply(1, 0, 1);
float yaw = client.gameRenderer.getCamera().getYaw();
Vec3d cartesian = relativePos
.normalize()
.multiply(minimalDistance + relativePos.length())
.rotateY((pony.asEntity().getYaw() - 180) * MathHelper.RADIANS_PER_DEGREE);
.multiply(minimalDistance + relativePos.horizontalLength())
.rotateY((180 + yaw) * MathHelper.RADIANS_PER_DEGREE);
addDrawableChild(new Entry(placeable).ofCartesian(cartesian));
});
});
@ -167,20 +168,28 @@ public class DismissSpellScreen extends GameGui {
copy.set(mouseX - width * 0.5F - x * 0.5F, mouseY - height * 0.5F - y * 0.5F, 0, 0);
DrawableUtil.drawLine(matrices, 0, 0, (int)x, (int)y, actualSpell.getAffinity().getColor().getColorValue());
DrawableUtil.renderItemIcon(context, actualSpell.isDead() ? UItems.BOTCHED_GEM.getDefaultStack() : type.getDefaultStack(),
x - 8 - copy.x * 0.2F,
y - 8 - copy.y * 0.2F,
1
);
int color = type.type().getColor() << 2;
matrices.push();
matrices.translate(x, y, 0);
DrawableUtil.drawArc(matrices, 7, 8, 0, DrawableUtil.TAU, color | 0x00000088, false);
matrices.push();
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(((MinecraftClient.getInstance().player.age + tickDelta) * 2) % 360));
DrawableUtil.renderItemIcon(context, actualSpell.isDead() ? UItems.BOTCHED_GEM.getDefaultStack() : type.getDefaultStack(),
-8,
-8,
1
);
matrices.pop();
if (isMouseOver(relativeMouseX, relativeMouseY)) {
boolean hovered = isMouseOver(relativeMouseX, relativeMouseY);
double radius = (hovered ? 9 + MathHelper.sin((MinecraftClient.getInstance().player.age + tickDelta) / 9F) : 7);
DrawableUtil.drawArc(matrices, radius, radius + 1, 0, DrawableUtil.TAU, color | 0x00000088, false);
if (hovered) {
DrawableUtil.drawArc(matrices, 0, 8, 0, DrawableUtil.TAU, color | 0x000000FF, false);
List<Text> tooltip = new ArrayList<>();