mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Merge pull request #1290 from SoSeDiK/crucible
Updated Crucible's mechanics
This commit is contained in:
commit
34fc70698a
@ -9,12 +9,11 @@ import org.bukkit.Tag;
|
|||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.data.Levelled;
|
import org.bukkit.block.data.Levelled;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.block.data.Waterlogged;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
|
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
|
||||||
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
|
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
|
||||||
import me.mrCookieSlime.CSCoreLibPlugin.events.ItemUseEvent;
|
|
||||||
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||||
@ -59,59 +58,91 @@ public class Crucible extends SlimefunGadget {
|
|||||||
|
|
||||||
return items.toArray(new ItemStack[0]);
|
return items.toArray(new ItemStack[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preRegister() {
|
public void preRegister() {
|
||||||
addItemHandler(new ItemInteractionHandler() {
|
addItemHandler((ItemInteractionHandler) (e, p, item) -> {
|
||||||
|
if (e.getClickedBlock() != null) {
|
||||||
|
String id = BlockStorage.checkID(e.getClickedBlock());
|
||||||
|
if (id != null && id.equals("CRUCIBLE")) {
|
||||||
|
if (p.hasPermission("slimefun.inventory.bypass") || SlimefunPlugin.getProtectionManager().hasPermission(p, e.getClickedBlock().getLocation(), ProtectableAction.ACCESS_INVENTORIES)) {
|
||||||
|
final ItemStack input = p.getInventory().getItemInMainHand();
|
||||||
|
final Block block = e.getClickedBlock().getRelative(BlockFace.UP);
|
||||||
|
SlimefunItem machine = SlimefunItem.getByID(id);
|
||||||
|
|
||||||
@Override
|
for (ItemStack convert: RecipeType.getRecipeInputs(machine)) {
|
||||||
public boolean onRightClick(ItemUseEvent e, final Player p, ItemStack item) {
|
if (SlimefunManager.isItemSimilar(input, convert, true)) {
|
||||||
if (e.getClickedBlock() != null) {
|
e.setCancelled(true);
|
||||||
String id = BlockStorage.checkID(e.getClickedBlock());
|
|
||||||
if (id != null && id.equals("CRUCIBLE")) {
|
|
||||||
if (p.hasPermission("slimefun.inventory.bypass") || SlimefunPlugin.getProtectionManager().hasPermission(p, e.getClickedBlock().getLocation(), ProtectableAction.ACCESS_INVENTORIES)) {
|
|
||||||
final ItemStack input = p.getInventory().getItemInMainHand();
|
|
||||||
final Block block = e.getClickedBlock().getRelative(BlockFace.UP);
|
|
||||||
SlimefunItem machine = SlimefunItem.getByID(id);
|
|
||||||
|
|
||||||
for (ItemStack convert: RecipeType.getRecipeInputs(machine)) {
|
|
||||||
if (SlimefunManager.isItemSimilar(input, convert, true)) {
|
|
||||||
e.setCancelled(true);
|
|
||||||
ItemStack removing = input.clone();
|
|
||||||
removing.setAmount(convert.getAmount());
|
|
||||||
|
|
||||||
p.getInventory().removeItem(removing);
|
|
||||||
|
|
||||||
for (int i = 1; i < 9; i++) {int j = 8 - i;
|
ItemStack removing = input.clone();
|
||||||
Slimefun.runSync(() -> {
|
removing.setAmount(convert.getAmount());
|
||||||
if (input.getType() == Material.COBBLESTONE || input.getType() == Material.TERRACOTTA || MaterialCollections.getAllTerracottaColors().contains(input.getType())) {
|
p.getInventory().removeItem(removing);
|
||||||
block.setType(Material.LAVA);
|
|
||||||
Levelled le = (Levelled) block.getBlockData();
|
boolean water = Tag.LEAVES.isTagged(input.getType());
|
||||||
le.setLevel(j);
|
if (block.getType() == (water ? Material.WATER : Material.LAVA)) {
|
||||||
block.setBlockData(le, false);
|
int level = ((Levelled) block.getBlockData()).getLevel();
|
||||||
block.getWorld().playSound(block.getLocation(), Sound.BLOCK_LAVA_POP, 1F, 1F);
|
if (level > 7)
|
||||||
}
|
level -= 8;
|
||||||
else if (Tag.LEAVES.isTagged(input.getType())) {
|
if (level == 0) {
|
||||||
block.setType(Material.WATER);
|
block.getWorld().playSound(block.getLocation(), water ? Sound.ENTITY_PLAYER_SPLASH : Sound.BLOCK_LAVA_POP, 1F, 1F);
|
||||||
Levelled le = (Levelled) block.getBlockData();
|
} else {
|
||||||
le.setLevel(j);
|
int finalLevel = 7 - level;
|
||||||
block.setBlockData(le, false);
|
Slimefun.runSync(() -> runPostTask(block, water ? Sound.ENTITY_PLAYER_SPLASH : Sound.BLOCK_LAVA_POP, finalLevel), 50L);
|
||||||
block.getWorld().playSound(block.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1F, 1F);
|
|
||||||
}
|
|
||||||
}, i * 50L);
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
} else if (block.getType() == (water ? Material.LAVA : Material.WATER)) {
|
||||||
|
int level = ((Levelled) block.getBlockData()).getLevel();
|
||||||
|
block.setType(level == 0 || level == 8 ? Material.OBSIDIAN : Material.STONE);
|
||||||
|
block.getWorld().playSound(block.getLocation(), Sound.BLOCK_LAVA_EXTINGUISH, 1F, 1F);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Slimefun.runSync(() -> {
|
||||||
|
if (!block.getType().isAir()) {
|
||||||
|
if (water) {
|
||||||
|
if (block.getBlockData() instanceof Waterlogged) {
|
||||||
|
Waterlogged wl = (Waterlogged) block.getBlockData();
|
||||||
|
wl.setWaterlogged(true);
|
||||||
|
block.setBlockData(wl, false);
|
||||||
|
block.getWorld().playSound(block.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1F, 1F);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
block.getWorld().playSound(block.getLocation(), Sound.BLOCK_METAL_BREAK, 1F, 1F);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (BlockStorage.hasBlockInfo(block))
|
||||||
|
BlockStorage.clearBlockInfo(block);
|
||||||
|
block.getWorld().playSound(block.getLocation(), Sound.BLOCK_LAVA_EXTINGUISH, 1F, 1F);
|
||||||
|
}
|
||||||
|
block.setType(water ? Material.WATER : Material.LAVA);
|
||||||
|
runPostTask(block, water ? Sound.ENTITY_PLAYER_SPLASH : Sound.BLOCK_LAVA_POP, 1);
|
||||||
|
}, 50L);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
SlimefunPlugin.getLocal().sendMessage(p, "machines.wrong-item", true);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
SlimefunPlugin.getLocal().sendMessage(p, "machines.wrong-item", true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void runPostTask(Block block, Sound sound, int times) {
|
||||||
|
if (!(block.getBlockData() instanceof Levelled)) {
|
||||||
|
block.getWorld().playSound(block.getLocation(), Sound.BLOCK_METAL_BREAK, 1F, 1F);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
block.getWorld().playSound(block.getLocation(), sound, 1F, 1F);
|
||||||
|
int level = 8 - times;
|
||||||
|
Levelled le = (Levelled) block.getBlockData();
|
||||||
|
le.setLevel(level);
|
||||||
|
block.setBlockData(le, false);
|
||||||
|
if (times < 8)
|
||||||
|
Slimefun.runSync(() -> runPostTask(block, sound, times + 1), 50L);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user