mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-20 20:04:22 +01:00
The dragon breath scroll now works across dimensions
This commit is contained in:
parent
d5ee43abee
commit
ffca3df862
3 changed files with 20 additions and 10 deletions
|
@ -285,9 +285,9 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, 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<T extends LivingEntity> implements Equine<T>, 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<T extends LivingEntity> implements Equine<T>, 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(
|
||||
|
|
|
@ -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) -> {
|
||||
|
|
|
@ -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<Entry> popAll(MinecraftServer server, String recipient) {
|
||||
return StreamSupport.stream(server.getWorlds().spliterator(), false)
|
||||
.map(DragonBreathStore::get)
|
||||
.flatMap(store -> store.popEntries(recipient).stream());
|
||||
}
|
||||
|
||||
public List<Entry> popEntries(String recipient) {
|
||||
synchronized (locker) {
|
||||
List<Entry> 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) {
|
||||
|
|
Loading…
Reference in a new issue