Skip to content

Commit

Permalink
F
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberpwnn committed May 23, 2023
1 parent 5396d8c commit 01b1ec0
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@
import com.volmit.react.React;
import com.volmit.react.api.tweak.ReactTweak;
import com.volmit.react.content.sampler.SamplerHopperTickTime;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Container;
import org.bukkit.block.Hopper;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.inventory.Inventory;

public class TweakHopperLimit extends ReactTweak implements Listener {
private static final BlockFace[] directions = new BlockFace[] {
BlockFace.NORTH,
BlockFace.EAST,
BlockFace.SOUTH,
BlockFace.WEST
};
public static final String ID = "hopper-limit";
private double maxHopperTickTime = 0.75;
private boolean optimizeHopperTransfers = true;
Expand All @@ -31,10 +42,35 @@ public int getTickInterval() {
return -1;
}

public boolean shouldCompare(Block b) {
if(b.getType().equals(Material.COMPARATOR)) {
return true;
}

return false;
}

@EventHandler
public void on(InventoryMoveItemEvent e) {
if(optimizeHopperTransfers) {
boolean skip = true;
if(e.getSource().getHolder() instanceof Container a) {
if(e.getDestination().getHolder() instanceof Container b) {
for(BlockFace i : directions) {
if(shouldCompare(b.getBlock().getRelative(i)) || shouldCompare(a.getBlock().getRelative(i))) {
skip = false;
break;
}
}

if(skip) {
e.setCancelled(true);
e.getSource().remove(e.getItem());
e.getDestination().addItem(e.getItem());
return;
}
}
}
}

if (e.getDestination().getHolder() instanceof Hopper h) {
Expand Down

0 comments on commit 01b1ec0

Please sign in to comment.