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.BlockFace;
|
||||
import org.bukkit.block.data.Levelled;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.block.data.Waterlogged;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
|
||||
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.events.ItemUseEvent;
|
||||
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
@ -59,12 +58,10 @@ public class Crucible extends SlimefunGadget {
|
||||
|
||||
return items.toArray(new ItemStack[0]);
|
||||
}
|
||||
@Override
|
||||
public void preRegister() {
|
||||
addItemHandler(new ItemInteractionHandler() {
|
||||
|
||||
@Override
|
||||
public boolean onRightClick(ItemUseEvent e, final Player p, ItemStack item) {
|
||||
public void preRegister() {
|
||||
addItemHandler((ItemInteractionHandler) (e, p, item) -> {
|
||||
if (e.getClickedBlock() != null) {
|
||||
String id = BlockStorage.checkID(e.getClickedBlock());
|
||||
if (id != null && id.equals("CRUCIBLE")) {
|
||||
@ -76,29 +73,50 @@ public class Crucible extends SlimefunGadget {
|
||||
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;
|
||||
boolean water = Tag.LEAVES.isTagged(input.getType());
|
||||
if (block.getType() == (water ? Material.WATER : Material.LAVA)) {
|
||||
int level = ((Levelled) block.getBlockData()).getLevel();
|
||||
if (level > 7)
|
||||
level -= 8;
|
||||
if (level == 0) {
|
||||
block.getWorld().playSound(block.getLocation(), water ? Sound.ENTITY_PLAYER_SPLASH : Sound.BLOCK_LAVA_POP, 1F, 1F);
|
||||
} else {
|
||||
int finalLevel = 7 - level;
|
||||
Slimefun.runSync(() -> runPostTask(block, water ? Sound.ENTITY_PLAYER_SPLASH : Sound.BLOCK_LAVA_POP, finalLevel), 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;
|
||||
}
|
||||
|
||||
Slimefun.runSync(() -> {
|
||||
if (input.getType() == Material.COBBLESTONE || input.getType() == Material.TERRACOTTA || MaterialCollections.getAllTerracottaColors().contains(input.getType())) {
|
||||
block.setType(Material.LAVA);
|
||||
Levelled le = (Levelled) block.getBlockData();
|
||||
le.setLevel(j);
|
||||
block.setBlockData(le, false);
|
||||
block.getWorld().playSound(block.getLocation(), Sound.BLOCK_LAVA_POP, 1F, 1F);
|
||||
}
|
||||
else if (Tag.LEAVES.isTagged(input.getType())) {
|
||||
block.setType(Material.WATER);
|
||||
Levelled le = (Levelled) block.getBlockData();
|
||||
le.setLevel(j);
|
||||
block.setBlockData(le, false);
|
||||
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;
|
||||
}
|
||||
}, i * 50L);
|
||||
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;
|
||||
}
|
||||
@ -110,8 +128,21 @@ public class Crucible extends SlimefunGadget {
|
||||
}
|
||||
}
|
||||
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