Add null check for A* finder, clone itemstacks in drop trait

This commit is contained in:
fullwall 2023-01-19 18:11:42 +08:00
parent 72c136e97a
commit 52955febf1
2 changed files with 6 additions and 4 deletions

View File

@ -89,16 +89,18 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
}
plan = planner.plan;
if (plan != null) {
vector = plan.getCurrentVector();
planner = null;
}
}
if (getCancelReason() != null || plan == null || plan.isComplete()) {
return true;
}
if (vector == null) {
vector = plan.getCurrentVector();
}
Location loc = npc.getEntity().getLocation(NPC_LOCATION);
/* Proper door movement - gets stuck on corners at times
Block block = currLoc.getWorld().getBlockAt(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
if (MinecraftBlockExaminer.isDoor(block.getType())) {
Door door = (Door) block.getState().getData();

View File

@ -48,7 +48,7 @@ public class DropsTrait extends Trait {
Random random = Util.getFastRandom();
for (ItemDrop drop : drops) {
if (random.nextDouble() < drop.chance) {
event.getDrops().add(drop.drop);
event.getDrops().add(drop.drop.clone());
}
}
}
@ -117,7 +117,7 @@ public class DropsTrait extends Trait {
ItemStack stack = inventory.getItem(slot);
if (stack == null || stack.getType() == Material.AIR)
continue;
drops.add(new ItemDrop(stack, chances.getOrDefault(slot, 1.0)));
drops.add(new ItemDrop(stack.clone(), chances.getOrDefault(slot, 1.0)));
}
}
this.trait.drops = drops;