mirror of
https://github.com/songoda/EpicHoppers.git
synced 2025-02-19 05:11:33 +01:00
Redstone functionality patch
This commit is contained in:
parent
67ba061bf2
commit
4c42850f3e
@ -30,8 +30,9 @@ public class Hopper {
|
|||||||
private Filter filter;
|
private Filter filter;
|
||||||
private TeleportTrigger teleportTrigger;
|
private TeleportTrigger teleportTrigger;
|
||||||
private ItemStack autoCrafting;
|
private ItemStack autoCrafting;
|
||||||
private int autoSellTimer = 0;
|
private int autoSellTimer;
|
||||||
private boolean autoBreaking = false;
|
private boolean autoBreaking;
|
||||||
|
private int transferTick;
|
||||||
|
|
||||||
public Hopper(Location location, Level level, UUID lastPlayer, UUID placedBy, List<Location> linkedBlocks, Filter filter, TeleportTrigger teleportTrigger, ItemStack autoCrafting) {
|
public Hopper(Location location, Level level, UUID lastPlayer, UUID placedBy, List<Location> linkedBlocks, Filter filter, TeleportTrigger teleportTrigger, ItemStack autoCrafting) {
|
||||||
this.location = location;
|
this.location = location;
|
||||||
@ -42,6 +43,9 @@ public class Hopper {
|
|||||||
this.placedBy = placedBy;
|
this.placedBy = placedBy;
|
||||||
this.teleportTrigger = teleportTrigger;
|
this.teleportTrigger = teleportTrigger;
|
||||||
this.autoCrafting = autoCrafting;
|
this.autoCrafting = autoCrafting;
|
||||||
|
this.autoSellTimer = 0;
|
||||||
|
this.autoBreaking = false;
|
||||||
|
this.transferTick = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Hopper(Block block, Level level, UUID lastPlayer, UUID placedBy, List<Location> linkedBlocks, Filter filter, TeleportTrigger teleportTrigger, ItemStack autoCrafting) {
|
public Hopper(Block block, Level level, UUID lastPlayer, UUID placedBy, List<Location> linkedBlocks, Filter filter, TeleportTrigger teleportTrigger, ItemStack autoCrafting) {
|
||||||
@ -176,6 +180,25 @@ public class Hopper {
|
|||||||
instance.getPlayerDataManager().getPlayerData(player).setSyncType(null);
|
instance.getPlayerDataManager().getPlayerData(player).setSyncType(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ticks a hopper to determine when it can transfer items next
|
||||||
|
* @param maxTick The maximum amount the hopper can be ticked before next transferring items
|
||||||
|
* @param allowLooping If true, the hopper is allowed to transfer items if the tick is also valid
|
||||||
|
* @return true if the hopper should transfer an item, otherwise false
|
||||||
|
*/
|
||||||
|
public boolean tryTick(int maxTick, boolean allowLooping) {
|
||||||
|
this.transferTick++;
|
||||||
|
if (this.transferTick >= maxTick) {
|
||||||
|
if (allowLooping) {
|
||||||
|
this.transferTick = 0;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
this.transferTick = maxTick;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public Location getLocation() {
|
public Location getLocation() {
|
||||||
return location.clone();
|
return location.clone();
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.Particle;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.Hopper;
|
import org.bukkit.block.Hopper;
|
||||||
@ -40,10 +39,12 @@ public class HopTask extends BukkitRunnable {
|
|||||||
private static EpicHoppers plugin;
|
private static EpicHoppers plugin;
|
||||||
|
|
||||||
private final Map<InventoryHolder, ItemStack> blacklist = new HashMap<>();
|
private final Map<InventoryHolder, ItemStack> blacklist = new HashMap<>();
|
||||||
|
private final int hopTicks;
|
||||||
|
|
||||||
public HopTask(EpicHoppers plug) {
|
public HopTask(EpicHoppers plug) {
|
||||||
plugin = plug;
|
plugin = plug;
|
||||||
runTaskTimer(plugin, 0, Setting.HOP_TICKS.getInt());
|
this.hopTicks = Setting.HOP_TICKS.getInt() / 2; // Purposeful integer division
|
||||||
|
this.runTaskTimer(plugin, 0, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -73,7 +74,12 @@ public class HopTask extends BukkitRunnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If hopper block is powered continue.
|
// If hopper block is powered continue.
|
||||||
if (block.isBlockPowered() || block.isBlockIndirectlyPowered())
|
if (block.isBlockPowered() || block.isBlockIndirectlyPowered()) {
|
||||||
|
hopper.tryTick(this.hopTicks, false);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hopper.tryTick(this.hopTicks, true))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Get hopper state.
|
// Get hopper state.
|
||||||
@ -110,7 +116,7 @@ public class HopTask extends BukkitRunnable {
|
|||||||
ItemStack[] hopperContents = hopperState.getInventory().getContents();
|
ItemStack[] hopperContents = hopperState.getInventory().getContents();
|
||||||
|
|
||||||
// Get filter endpoint
|
// Get filter endpoint
|
||||||
InventoryHolder filterEndpoint = getFilterEndpoint(hopper);
|
InventoryHolder filterEndpoint = this.getFilterEndpoint(hopper);
|
||||||
|
|
||||||
// Loop through our container list.
|
// Loop through our container list.
|
||||||
for (Location destinationLocation : linkedContainers) {
|
for (Location destinationLocation : linkedContainers) {
|
||||||
@ -146,12 +152,8 @@ public class HopTask extends BukkitRunnable {
|
|||||||
ItemStack item = hopperContents[i];
|
ItemStack item = hopperContents[i];
|
||||||
|
|
||||||
// Skip if item blacklisted.
|
// Skip if item blacklisted.
|
||||||
System.out.println(blacklist.size() + " | " + blacklist.containsKey(hopperState) + " | " + (blacklist.containsKey(hopperState) && blacklist.get(hopperState).isSimilar(item)));
|
if ((this.blacklist.containsKey(hopperState) && this.blacklist.get(hopperState).isSimilar(item)) || blockedMaterials.contains(item.getType()))
|
||||||
System.out.println("Blacklist check: " + hopperState);
|
|
||||||
if ((blacklist.containsKey(hopperState) && blacklist.get(hopperState).isSimilar(item)) || blockedMaterials.contains(item.getType())) {
|
|
||||||
destinationLocation.getWorld().spawnParticle(Particle.CRIT, destinationLocation.clone().add(0.5, 1, 0.5), 10);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
// Get amount to move.
|
// Get amount to move.
|
||||||
int amountToMove = item.getAmount() < amount ? item.getAmount() : amount;
|
int amountToMove = item.getAmount() < amount ? item.getAmount() : amount;
|
||||||
@ -176,13 +178,13 @@ public class HopTask extends BukkitRunnable {
|
|||||||
// If blocked check to see if a movement can be made if blacklist skip to the next slot
|
// If blocked check to see if a movement can be made if blacklist skip to the next slot
|
||||||
// otherwise set the current destination to the endpoint.
|
// otherwise set the current destination to the endpoint.
|
||||||
if (blocked) {
|
if (blocked) {
|
||||||
if (filterEndpoint == null || !canMove(filterEndpoint.getInventory(), itemToMove))
|
if (filterEndpoint == null || !this.canMove(filterEndpoint.getInventory(), itemToMove))
|
||||||
break;
|
break;
|
||||||
currentDestination = filterEndpoint;
|
currentDestination = filterEndpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add item to container and continue on success.
|
// Add item to container and continue on success.
|
||||||
if (addItem(hopper, hopperState, currentDestination, destinationBlock.getType(), item, itemToMove, amountToMove))
|
if (this.addItem(hopper, hopperState, currentDestination, destinationBlock.getType(), item, itemToMove, amountToMove))
|
||||||
continue main;
|
continue main;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -259,7 +261,7 @@ public class HopTask extends BukkitRunnable {
|
|||||||
|
|
||||||
brewerInventory.setItem(entry.getKey(), currentOutput);
|
brewerInventory.setItem(entry.getKey(), currentOutput);
|
||||||
}
|
}
|
||||||
debt(item, amountToMove, currentHolder);
|
this.debt(item, amountToMove, currentHolder);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "BLAST_FURNACE":
|
case "BLAST_FURNACE":
|
||||||
@ -284,14 +286,14 @@ public class HopTask extends BukkitRunnable {
|
|||||||
} else {
|
} else {
|
||||||
furnaceInventory.setSmelting(output);
|
furnaceInventory.setSmelting(output);
|
||||||
}
|
}
|
||||||
debt(item, amountToMove, currentHolder);
|
this.debt(item, amountToMove, currentHolder);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Continue if move would fail.
|
// Continue if move would fail.
|
||||||
if (!canMove(destinationInventory, itemToMove))
|
if (!this.canMove(destinationInventory, itemToMove))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Prevent item from being moved again during this cycle.
|
// Prevent item from being moved again during this cycle.
|
||||||
@ -303,7 +305,7 @@ public class HopTask extends BukkitRunnable {
|
|||||||
destinationInventory.addItem(itemToMove);
|
destinationInventory.addItem(itemToMove);
|
||||||
|
|
||||||
// Debt hopper
|
// Debt hopper
|
||||||
debt(item, amountToMove, currentHolder);
|
this.debt(item, amountToMove, currentHolder);
|
||||||
|
|
||||||
// Update comparators for destination hopper.
|
// Update comparators for destination hopper.
|
||||||
updateAdjacentComparators(((BlockState) currentDestination).getLocation());
|
updateAdjacentComparators(((BlockState) currentDestination).getLocation());
|
||||||
|
Loading…
Reference in New Issue
Block a user