diff --git a/src/main/java/com/minelittlepony/unicopia/entity/Living.java b/src/main/java/com/minelittlepony/unicopia/entity/Living.java index a63b6c01..339f5efb 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/Living.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/Living.java @@ -285,9 +285,9 @@ public abstract class Living implements Equine, Caste Vec3d targetPos = entity.getRotationVector().multiply(2).add(entity.getEyePos()); if (entity.getWorld().isAir(BlockPos.ofFloored(targetPos))) { - DragonBreathStore store = DragonBreathStore.get(entity.getWorld()); String name = entity.getDisplayName().getString(); - store.popEntries(name).forEach(stack -> { + + DragonBreathStore.popAll(entity.getServer(), name).forEach(stack -> { ItemStack payload = stack.payload(); Item item = payload.getItem(); @@ -300,7 +300,7 @@ public abstract class Living implements Equine, Caste ItemStack instance = payload.split(1); BlockPos pos = BlockPos.ofFloored(randomPos); if (!entity.getWorld().isAir(pos)) { - store.put(name, instance); + stack.store().put(name, instance); } else { for (int i = 0; i < 10; i++) { @@ -326,7 +326,7 @@ public abstract class Living implements Equine, Caste } while (!payload.isEmpty()); } else { if (!entity.getWorld().isAir(BlockPos.ofFloored(randomPos))) { - store.put(name, stack.payload()); + stack.store().put(name, stack.payload()); } else { for (int i = 0; i < 10; i++) { ParticleUtils.spawnParticle(entity.getWorld(), ParticleTypes.FLAME, randomPos.add( diff --git a/src/main/java/com/minelittlepony/unicopia/item/DragonBreathScrollItem.java b/src/main/java/com/minelittlepony/unicopia/item/DragonBreathScrollItem.java index 1639bbcb..4d81b7e5 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/DragonBreathScrollItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/DragonBreathScrollItem.java @@ -30,7 +30,7 @@ public class DragonBreathScrollItem extends Item { return TypedActionResult.fail(stack); } - ItemStack scroll = stack.split(1); + ItemStack scroll = stack.splitUnlessCreative(1, player); if (!world.isClient) { String recipient = scroll.get(DataComponentTypes.CUSTOM_NAME).getString(); UCriteria.SEND_DRAGON_BREATH.triggerSent(player, payload, recipient, (counterName, count) -> { diff --git a/src/main/java/com/minelittlepony/unicopia/server/world/DragonBreathStore.java b/src/main/java/com/minelittlepony/unicopia/server/world/DragonBreathStore.java index 20c4ff6f..f603a646 100644 --- a/src/main/java/com/minelittlepony/unicopia/server/world/DragonBreathStore.java +++ b/src/main/java/com/minelittlepony/unicopia/server/world/DragonBreathStore.java @@ -1,6 +1,8 @@ package com.minelittlepony.unicopia.server.world; import java.util.*; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.item.UItems; @@ -8,6 +10,7 @@ import com.minelittlepony.unicopia.item.UItems; import net.minecraft.item.ItemStack; import net.minecraft.nbt.*; import net.minecraft.registry.RegistryWrapper.WrapperLookup; +import net.minecraft.server.MinecraftServer; import net.minecraft.util.Identifier; import net.minecraft.world.PersistentState; import net.minecraft.world.World; @@ -29,7 +32,7 @@ public class DragonBreathStore extends PersistentState { this(world); compound.getKeys().forEach(key -> { compound.getList(key, NbtElement.COMPOUND_TYPE).forEach(entry -> { - put(key, new Entry((NbtCompound)entry, world.getRegistryManager())); + put(key, new Entry((NbtCompound)entry, world.getRegistryManager(), this)); }); }); } @@ -55,6 +58,12 @@ public class DragonBreathStore extends PersistentState { } } + public static Stream popAll(MinecraftServer server, String recipient) { + return StreamSupport.stream(server.getWorlds().spliterator(), false) + .map(DragonBreathStore::get) + .flatMap(store -> store.popEntries(recipient).stream()); + } + public List popEntries(String recipient) { synchronized (locker) { List entries = doPurge().get(recipient); @@ -100,7 +109,7 @@ public class DragonBreathStore extends PersistentState { } return false; })) { - put(recipient, new Entry(System.currentTimeMillis() + (long)(Math.random() * 1999), payload)); + put(recipient, new Entry(System.currentTimeMillis() + (long)(Math.random() * 1999), payload, this)); } } } @@ -122,10 +131,11 @@ public class DragonBreathStore extends PersistentState { public record Entry( long created, - ItemStack payload) { + ItemStack payload, + DragonBreathStore store) { - public Entry(NbtCompound compound, WrapperLookup lookup) { - this(compound.getLong("created"), ItemStack.fromNbtOrEmpty(lookup, compound.getCompound("payload"))); + public Entry(NbtCompound compound, WrapperLookup lookup, DragonBreathStore store) { + this(compound.getLong("created"), ItemStack.fromNbtOrEmpty(lookup, compound.getCompound("payload")), store); } public NbtCompound toNBT(NbtCompound compound) {