You will explode twice when the alicorn amulet breaks

This commit is contained in:
Sollace 2019-02-19 12:44:50 +02:00
parent ee84215649
commit 373a2c64cd
3 changed files with 58 additions and 10 deletions

View file

@ -11,6 +11,7 @@ import com.minelittlepony.unicopia.UClient;
import com.minelittlepony.unicopia.player.IPlayer;
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
import com.minelittlepony.unicopia.spell.SpellAffinity;
import com.minelittlepony.unicopia.world.UWorld;
import com.minelittlepony.util.MagicalDamageSource;
import com.minelittlepony.util.lang.ClientLocale;
import com.minelittlepony.util.vector.VecHelper;
@ -56,7 +57,6 @@ public class ItemAlicornAmulet extends ItemArmor implements IDependable {
setTranslationKey(name);
setRegistryName(domain, name);
setMaxDamage(0);
}
@Override
@ -204,6 +204,21 @@ public class ItemAlicornAmulet extends ItemArmor implements IDependable {
}
}
if (itemStack.getItemDamage() >= getMaxDamage(itemStack) - 1) {
itemStack.damageItem(10, player);
player.attackEntityFrom(DAMAGE_SOURCE, player.getMaxHealth() - 0.01F);
player.getFoodStats().setFoodLevel(1);
Vec3d pos = player.getPositionVector();
player.world.newExplosion(player, pos.x, pos.y, pos.z, 10, false, false);
UWorld.scheduleTask(w -> {
w.newExplosion(player, pos.x, pos.y, pos.z, 6, false, true);
}, 50);
}
iplayer.getInventory().enforceDependency(this);
}

View file

@ -179,9 +179,7 @@ public class PowerStomp implements IPower<PowerStomp.Data> {
if (harmed || player.world.rand.nextInt(5) == 0) {
if (!harmed || player.world.rand.nextInt(30) == 0) {
UWorld.enqueueTask(() -> {
removeTree(player.world, data.pos());
});
UWorld.enqueueTask(w -> removeTree(w, data.pos()));
}
IPower.takeFromPlayer(player, 3);
@ -331,10 +329,10 @@ public class PowerStomp implements IPower<PowerStomp.Data> {
dropApplesPart(capturedDrops, new ArrayList<BlockPos>(), w, log, pos, 0);
UWorld.enqueueTask(() -> {
UWorld.enqueueTask(wo -> {
capturedDrops.forEach(item -> {
item.setNoPickupDelay();
w.spawnEntity(item);
wo.spawnEntity(item);
});
});

View file

@ -1,8 +1,12 @@
package com.minelittlepony.unicopia.world;
import java.util.List;
import java.util.Queue;
import java.util.Random;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import com.google.common.collect.Lists;
import com.google.common.collect.Queues;
import com.minelittlepony.jumpingcastle.Exceptions;
import com.minelittlepony.unicopia.Unicopia;
@ -27,16 +31,23 @@ public class UWorld implements IWorldGenerator {
return instance;
}
private static final Queue<Runnable> tickTasks = Queues.newArrayDeque();
private static final Queue<Consumer<World>> tickTasks = Queues.newArrayDeque();
private static List<DelayedTask> delayedTasks = Lists.newArrayList();
private static final Object locker = new Object();
public static void enqueueTask(Runnable task) {
public static void enqueueTask(Consumer<World> task) {
synchronized (locker) {
tickTasks.add(task);
}
}
public static void scheduleTask(Consumer<World> task, int ticksLater) {
synchronized (locker) {
delayedTasks.add(new DelayedTask(task, ticksLater));
}
}
private final BlockInteractions blocks = new BlockInteractions();
private final CloudGen cloudsGen = new CloudGen();
@ -53,9 +64,12 @@ public class UWorld implements IWorldGenerator {
public void onUpdate(World world) {
synchronized (locker) {
Runnable task;
delayedTasks = delayedTasks.stream().filter(DelayedTask::tick).collect(Collectors.toList());
Consumer<World> task;
while ((task = tickTasks.poll()) != null) {
Exceptions.logged(task, Unicopia.log);
Consumer<World> i = task;
Exceptions.logged(() -> i.accept(world), Unicopia.log);
}
}
}
@ -86,4 +100,25 @@ public class UWorld implements IWorldGenerator {
}
}
}
private static class DelayedTask {
final Consumer<World> task;
int ticksDelay;
DelayedTask(Consumer<World> task, int ticks) {
this.task = task;
this.ticksDelay = ticks;
}
boolean tick() {
if (ticksDelay-- <= 0) {
tickTasks.add(task);
return false;
}
return true;
}
}
}