-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b37da35
commit a91538a
Showing
5 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/main/java/quarri6343/overcrafted/impl/block/BlockConveyor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package quarri6343.overcrafted.impl.block; | ||
|
||
import org.bukkit.Material; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.scheduler.BukkitTask; | ||
import quarri6343.overcrafted.Overcrafted; | ||
import quarri6343.overcrafted.impl.task.ConveyorRunnable; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class BlockConveyor extends BlockTable { | ||
|
||
/** | ||
* コンベヤとそのタスクのマップ | ||
*/ | ||
private static final Map<Block, BukkitTask> progressionMap = new HashMap<>(); | ||
|
||
public BlockConveyor() { | ||
super(Material.MAGENTA_GLAZED_TERRACOTTA); | ||
onPlace.add(block -> progressionMap.put(block, new ConveyorRunnable(this, block).runTaskTimer(Overcrafted.getInstance(), 20, 20))); | ||
onPickUp.add((block, player) -> { | ||
if(progressionMap.get(block) != null){ | ||
progressionMap.get(block).cancel(); | ||
progressionMap.remove(block); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/quarri6343/overcrafted/impl/task/ConveyorRunnable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package quarri6343.overcrafted.impl.task; | ||
|
||
import org.bukkit.block.Block; | ||
import org.bukkit.block.data.Directional; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.scheduler.BukkitRunnable; | ||
import quarri6343.overcrafted.core.handler.PlaceItemHandler; | ||
import quarri6343.overcrafted.impl.block.BlockConveyor; | ||
|
||
public class ConveyorRunnable extends BukkitRunnable { | ||
|
||
BlockConveyor blockConveyor; | ||
Block conveyorBlock; | ||
|
||
public ConveyorRunnable(BlockConveyor blockConveyor, Block conveyorBlock){ | ||
this.blockConveyor = blockConveyor; | ||
this.conveyorBlock = conveyorBlock; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
ItemStack itemOnConveyor = PlaceItemHandler.getItem(conveyorBlock); | ||
Block nextBlock = conveyorBlock.getRelative(((Directional)conveyorBlock.getBlockData()).getFacing().getOppositeFace()); | ||
if(nextBlock.getType() != conveyorBlock.getType()) | ||
return; | ||
|
||
if(PlaceItemHandler.placeItem(nextBlock,itemOnConveyor)){ | ||
blockConveyor.onPlace.forEach(blockConsumer -> blockConsumer.accept(nextBlock)); | ||
PlaceItemHandler.pickUpItem(conveyorBlock); | ||
blockConveyor.onPickUp.forEach(blockConsumer -> blockConsumer.accept(conveyorBlock, null)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters