Skip to content

Commit

Permalink
The dragon breath scroll now works across dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed Dec 19, 2024
1 parent d5ee43a commit ffca3df
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/main/java/com/minelittlepony/unicopia/entity/Living.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ private void updateDragonBreath() {
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();

Expand All @@ -300,7 +300,7 @@ private void updateDragonBreath() {
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++) {
Expand All @@ -326,7 +326,7 @@ private void updateDragonBreath() {
} 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand h
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) -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
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;

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;
Expand All @@ -29,7 +32,7 @@ public static DragonBreathStore get(World world) {
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));
});
});
}
Expand All @@ -55,6 +58,12 @@ public NbtCompound writeNbt(NbtCompound compound, WrapperLookup lookup) {
}
}

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);
Expand Down Expand Up @@ -100,7 +109,7 @@ public void put(String recipient, ItemStack payload) {
}
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));
}
}
}
Expand All @@ -122,10 +131,11 @@ private Map<String, List<Entry>> doPurge() {

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) {
Expand Down

0 comments on commit ffca3df

Please sign in to comment.