Fixed dismissing spells from the gui killing them without going through the normal removal process

This commit is contained in:
Sollace 2024-01-26 15:58:22 +00:00
parent 4151b66e99
commit 0910ad72ca
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
5 changed files with 27 additions and 8 deletions

View file

@ -39,6 +39,13 @@ public interface SpellContainer {
*/
void put(@Nullable Spell effect);
/**
* Cleanly removes a spell from this spell container.
*
* @param spellid ID of the spell to remove.
*/
void remove(UUID spellid);
/**
* Removes all active effects that match or contain a matching effect.
*

View file

@ -76,14 +76,10 @@ class PortalFrameBuffer implements AutoCloseable {
private boolean pendingDraw;
private final UUID id;
@Nullable
private Frustum frustum;
PortalFrameBuffer(UUID id) {
this.id = id;
}
PortalFrameBuffer(UUID id) { }
public void draw(MatrixStack matrices, VertexConsumerProvider vertices) {
matrices.translate(0, -0.001, 0);

View file

@ -10,7 +10,7 @@ import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.network.ServerPlayerEntity;
/**
* Sent to the server when a player activates an ability.
* Sent to the server when a player dismisses a spell from their dismiss spell screen
*/
public record MsgRemoveSpell (UUID id) implements HandledPacket<ServerPlayerEntity> {
MsgRemoveSpell(PacketByteBuf buffer) {
@ -30,7 +30,7 @@ public record MsgRemoveSpell (UUID id) implements HandledPacket<ServerPlayerEnti
public void handle(ServerPlayerEntity sender) {
Pony player = Pony.of(sender);
if (player != null) {
player.getSpellSlot().removeIf(spell -> spell.getUuid().equals(id), true);
player.getSpellSlot().remove(id);
}
}
}

View file

@ -93,6 +93,16 @@ public class EffectSync implements SpellContainer, NbtSerialisable {
}
}
@Override
public void remove(UUID id) {
Spell spell = spells.getReference(id);
spell.setDead();
spell.tickDying(owner);
if (spell.isDead()) {
spells.removeReference(id);
}
}
@Override
public boolean removeWhere(Predicate<Spell> test, boolean update) {
return reduce(update, (initial, effect) -> {

View file

@ -83,7 +83,13 @@ public class NetworkedReferenceSet<T> {
}
}
private synchronized void removeReference(UUID id) {
@Nullable
synchronized T getReference(UUID id) {
NetworkedReference<T> i = values.get(id);
return i == null ? null : i.getReference().orElse(null);
}
synchronized void removeReference(UUID id) {
dirty |= ids.remove(id);
NetworkedReference<T> i = values.remove(id);
if (i != null) {