Skip to content

Commit

Permalink
Rewrite redstone listener
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerS1066 committed Jun 1, 2024
1 parent c9d11e2 commit ac80f51
Showing 1 changed file with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,17 @@ public void onBlockFromTo(BlockFromToEvent e) {

// process certain redstone on cruising crafts
@EventHandler(priority = EventPriority.HIGHEST)
public void onRedstoneEvent(BlockRedstoneEvent event) {
public void onRedstoneEvent(@NotNull BlockRedstoneEvent event) {
Block block = event.getBlock();
CraftManager.getInstance().getCraftsInWorld(block.getWorld());
for (Craft tcraft : CraftManager.getInstance().getCraftsInWorld(block.getWorld())) {
MovecraftLocation mloc = new MovecraftLocation(block.getX(), block.getY(), block.getZ());
if (MathUtils.locIsNearCraftFast(tcraft, mloc) &&
tcraft.getCruising() && (block.getType() == Material.STICKY_PISTON ||
block.getType() == Material.PISTON || block.getType() == Material.DISPENSER &&
!tcraft.isNotProcessing())) {
event.setNewCurrent(event.getOldCurrent()); // don't allow piston movement on cruising crafts
return;
}
}
MovecraftLocation loc = MathUtils.bukkit2MovecraftLoc(block.getLocation());
Craft craft = MathUtils.fastNearestCraftToLoc(CraftManager.getInstance().getCrafts(), block.getLocation());
if (craft == null || craft.isNotProcessing() || !craft.getHitBox().contains((loc)))
return;

if (block.getType() != Material.STICKY_PISTON || block.getType() != Material.PISTON || block.getType() != Material.DISPENSER)
return;

event.setNewCurrent(event.getOldCurrent()); // don't allow piston movement on cruising crafts
}

// prevent pistons on cruising crafts
Expand Down

0 comments on commit ac80f51

Please sign in to comment.