Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@
<dependency>
<groupId>com.github.Slimefun</groupId>
<artifactId>Slimefun4</artifactId>
<version>b1aae439f3</version>
<version>RC-37</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.baked-libs.dough</groupId>
<artifactId>dough-api</artifactId>
<version>a2364de77c</version>
<version>f8ff251</version>
<scope>compile</scope>
</dependency>

Expand Down Expand Up @@ -169,4 +169,4 @@

</dependencies>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private void tryBreed(@Nonnull Block motherBlock, @Nonnull NetherSeed mother) {
final Block middleBlock = motherBlock.getRelative(face);
// There must be space for the new block
if (middleBlock.getType() != Material.AIR) {
return;
continue;
}
final Block potentialMate = middleBlock.getRelative(face);
final SlimefunItem mateItem = BlockStorage.check(potentialMate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,45 @@
import dev.sefiraat.netheopoiesis.api.RecipeTypes;
import dev.sefiraat.netheopoiesis.api.interfaces.WorldCrushable;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Item;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.inventory.ItemStack;

import javax.annotation.Nonnull;

/**
* The purpose of this listener is to drop registered items when breaking the specified vanilla
* block.
* The purpose of this listener is to drop registered items when crushing the specified recipe with an anvil
* Recipes should be registered using {@link RecipeTypes#createCrushingRecipe(SlimefunItem)}
* which returns an ItemStack array used for Slimefun's recipe
* {@link RecipeTypes#CRUSHING}
*/
public class CrushingListener implements Listener {

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onCrush(@Nonnull EntityDamageEvent event) {
//todo checkout why entity attack is needed here
if (event.getEntity() instanceof Item item
&& (event.getCause() == EntityDamageEvent.DamageCause.FALLING_BLOCK
|| event.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK)
) {
final SlimefunItem slimefunItem = SlimefunItem.getByItem(item.getItemStack());
if (slimefunItem instanceof WorldCrushable crushable) {
final ItemStack stackToDrop = crushable.crushingDrop();
if (stackToDrop == null) {
return;
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onCrush(@Nonnull EntityChangeBlockEvent event) {
if (event.getEntity() instanceof FallingBlock anvil && Tag.ANVIL.isTagged(anvil.getBlockData().getMaterial())) {
Location center = event.getBlock().getLocation().add(0.5, 0.5, 0.5);
for (Entity entity : center.getWorld().getNearbyEntities(center, 0.5, 0.5, 0.5, Item.class::isInstance)) {
Item item = (Item) entity;
final SlimefunItem slimefunItem = SlimefunItem.getByItem(item.getItemStack());
if (slimefunItem instanceof WorldCrushable crushable) {
final ItemStack stackToDrop = crushable.crushingDrop();
if (stackToDrop == null) {
continue;
}
for (int i = 0; i < item.getItemStack().getAmount(); i++) {
item.getWorld().dropItem(item.getLocation(), stackToDrop);
}
item.remove();
}
for (int i = 0; i < item.getItemStack().getAmount(); i++) {
item.getWorld().dropItem(item.getLocation(), stackToDrop);
}
item.remove();
}
}
}
Expand Down