Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 17 additions & 20 deletions src/main/java/com/sk89q/craftbook/mechanics/pipe/Pipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,17 @@ private void searchNearbyPipes(Block block, Set<Vector> visitedPipes, List<ItemS
} else if (fac.getType() == Material.JUKEBOX) {
Jukebox juke = (Jukebox) fac.getState();
List<ItemStack> its = new ArrayList<>(event.getItems());
if (juke.getPlaying() != Material.AIR) {
if (juke.getPlaying() == Material.AIR) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From memory this was done the old way because when getPlaying was AIR, it would fail to actually accept something (and silently eat the item). This might no longer be the case, but worth testing/validating on Spigot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested it on a 1.21 server. Pushing a disc through a pipe into an empty jukebox works: the disc ends up in the jukebox, the block ends up as jukebox[has_record=true], and nothing is dropped or lost. CraftJukebox.setRecord sets HAS_RECORD from the item and update() writes the block back, so the old failure looks like it is gone.

Also checked the other direction, pulling from a playing jukebox into a chest gives exactly one disc, and when the delivery is refused exactly one disc drops at the piston instead of two.

Iterator<ItemStack> iter = its.iterator();
while (iter.hasNext()) {
ItemStack st = iter.next();
if (!st.getType().isRecord()) continue;
juke.setPlaying(st.getType());
juke.update();
iter.remove();
if (st.getAmount() > 1)
st.setAmount(st.getAmount() - 1);
else
iter.remove();
break;
}
}
Expand Down Expand Up @@ -430,27 +433,21 @@ private void startPipe(Block block, List<ItemStack> items, boolean request) {

if (juke.getPlaying() != Material.AIR) {
items.add(new ItemStack(juke.getPlaying()));
juke.setPlaying(Material.AIR);
juke.update();
}

PipeSuckEvent event = new PipeSuckEvent(block, new ArrayList<>(items), fac);
Bukkit.getPluginManager().callEvent(event);
items.clear();
items.addAll(event.getItems());

if (!event.isCancelled()) {
visitedPipes.add(fac.getLocation().toVector());
searchNearbyPipes(block, visitedPipes, items);
}
PipeSuckEvent event = new PipeSuckEvent(block, new ArrayList<>(items), fac);
Bukkit.getPluginManager().callEvent(event);
items.clear();
items.addAll(event.getItems());

if (!items.isEmpty()) {
for (ItemStack item : items) {
if (!ItemUtil.isStackValid(item)) continue;
block.getWorld().dropItem(BlockUtil.getBlockCentre(block), item);
}
} else {
juke.setPlaying(Material.AIR);
juke.update();
}
if (!event.isCancelled() && !items.isEmpty()) {
visitedPipes.add(fac.getLocation().toVector());
searchNearbyPipes(block, visitedPipes, items);
}

leftovers.addAll(items);
} else {
PipeSuckEvent event = new PipeSuckEvent(block, new ArrayList<>(items), fac);
Bukkit.getPluginManager().callEvent(event);
Expand Down
Loading