Skip to content
Permalink
Browse files

Rework XP Orb removal, and fixed the signs radius being ignored.

  • Loading branch information...
me4502 committed Oct 19, 2016
1 parent 721e01a commit 6ca50c5057882586f06357414518d7f965a31ecd
Showing with 20 additions and 5 deletions.
  1. +20 −5 src/main/java/com/sk89q/craftbook/mechanics/XPStorer.java
@@ -25,6 +25,9 @@
import com.sk89q.craftbook.bukkit.CraftBookPlugin;
import com.sk89q.util.yaml.YAMLProcessor;

import java.util.ArrayList;
import java.util.List;

public class XPStorer extends AbstractCraftBookMechanic {

@EventHandler
@@ -200,12 +203,20 @@ public void onThink(SelfTriggerThinkEvent event) {

event.setHandled(true);

int signRadius = radius;
try {
signRadius = Math.max(radius, Integer.parseInt(sign.getLine(2)));
} catch (Exception e) {
}

int xp = 0;

for (Entity entity : LocationUtil.getNearbyEntities(SignUtil.getBackBlock(event.getBlock()).getLocation(), new Vector(radius,radius,radius))) {
List<ExperienceOrb> orbs = new ArrayList<ExperienceOrb>();

for (Entity entity : LocationUtil.getNearbyEntities(SignUtil.getBackBlock(event.getBlock()).getLocation(), new Vector(signRadius,signRadius,signRadius))) {
if (entity instanceof ExperienceOrb && entity.getTicksLived() > 20) {
xp += ((ExperienceOrb) entity).getExperience();
entity.remove();
orbs.add((ExperienceOrb) entity);
}
}

@@ -248,9 +259,13 @@ public void onThink(SelfTriggerThinkEvent event) {
}

int remainingXP = xp - bottleCount * xpPerBottle;
if (remainingXP > 0) {
ExperienceOrb orb = (ExperienceOrb) event.getBlock().getWorld().spawnEntity(LocationUtil.getCenterOfBlock(SignUtil.getBackBlock(event.getBlock())), EntityType.EXPERIENCE_ORB);
orb.setExperience(remainingXP);
for (ExperienceOrb orb : orbs) {
if (remainingXP > 0) {
orb.setExperience(Math.min(5, remainingXP));
remainingXP -= 5;
} else {
orb.remove();
}
}
}

0 comments on commit 6ca50c5

Please sign in to comment.
You can’t perform that action at this time.