1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 19:55:48 +00:00

Implemented this for androids

This commit is contained in:
TheBusyBiscuit 2020-09-15 11:09:15 +02:00
parent 816e9004ca
commit eeff9411a3

View File

@ -3,10 +3,14 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.androids;
import java.util.Collection;
import java.util.UUID;
import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.inventory.ItemStack;
@ -15,9 +19,9 @@ import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import io.github.thebusybiscuit.slimefun4.api.events.AndroidMineEvent;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.InfiniteBlockGenerator;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
@ -27,6 +31,7 @@ public class MinerAndroid extends ProgrammableAndroid {
// Determines the drops a miner android will get
private final ItemStack effectivePickaxe = new ItemStack(Material.DIAMOND_PICKAXE);
@ParametersAreNonnullByDefault
public MinerAndroid(Category category, int tier, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, tier, item, recipeType, recipe);
}
@ -52,16 +57,9 @@ public class MinerAndroid extends ProgrammableAndroid {
}
// We only want to break non-Slimefun blocks
String blockId = BlockStorage.checkID(block);
if (blockId == null) {
for (ItemStack drop : drops) {
if (menu.fits(drop, getOutputSlots())) {
menu.pushItem(drop, getOutputSlots());
}
}
if (!BlockStorage.hasBlockInfo(block)) {
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType());
block.setType(Material.AIR);
breakBlock(menu, drops, block);
}
}
}
@ -83,17 +81,9 @@ public class MinerAndroid extends ProgrammableAndroid {
}
// We only want to break non-Slimefun blocks
SlimefunItem blockId = BlockStorage.check(block);
if (blockId == null) {
for (ItemStack drop : drops) {
if (menu.fits(drop, getOutputSlots())) {
menu.pushItem(drop, getOutputSlots());
}
}
if (!BlockStorage.hasBlockInfo(block)) {
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType());
block.setType(Material.AIR);
breakBlock(menu, drops, block);
move(b, face, block);
}
}
@ -106,4 +96,23 @@ public class MinerAndroid extends ProgrammableAndroid {
}
}
@ParametersAreNonnullByDefault
private void breakBlock(BlockMenu menu, Collection<ItemStack> drops, Block block) {
// Push our drops to the inventory
for (ItemStack drop : drops) {
menu.pushItem(drop, getOutputSlots());
}
InfiniteBlockGenerator generator = InfiniteBlockGenerator.findAt(block);
if (generator != null) {
// "poof" a "new" block was generated
block.getWorld().playSound(block.getLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 0.04F, 0.8F);
block.getWorld().spawnParticle(Particle.SMOKE_NORMAL, block.getX() + 0.5, block.getY() + 1.5, block.getZ() + 0.5, 6, 0.5, 0.5, 0.5);
}
else {
block.setType(Material.AIR);
}
}
}