mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-22 15:05:18 +01:00
Added wood switcher
This commit is contained in:
parent
ea6521ee9b
commit
230cdc7163
@ -203,6 +203,7 @@ import com.willfp.ecoenchants.enchantments.ecoenchants.normal.WaterAffinity;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.WaterAspect;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Weakening;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Wisdom;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.WoodSwitcher;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Wound;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Zeus;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.Aiming;
|
||||
@ -488,6 +489,7 @@ public class EcoEnchants {
|
||||
public static final EcoEnchant NAUTILUS_ARTIFACT = new NautilusArtifact();
|
||||
public static final EcoEnchant SWEEP_ARTIFACT = new SweepArtifact();
|
||||
public static final EcoEnchant REAPER = new Reaper();
|
||||
public static final EcoEnchant WOOD_SWITCHER = new WoodSwitcher();
|
||||
|
||||
/**
|
||||
* Get all registered {@link EcoEnchant}s.
|
||||
|
@ -0,0 +1,63 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import com.willfp.eco.util.drops.DropQueue;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class WoodSwitcher extends EcoEnchant {
|
||||
public WoodSwitcher() {
|
||||
super(
|
||||
"wood_switcher", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(@NotNull final Player player,
|
||||
@NotNull final Block block,
|
||||
final int level,
|
||||
@NotNull final BlockBreakEvent event) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Tag.LOGS.isTagged(block.getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setDropItems(false);
|
||||
|
||||
Material material;
|
||||
double random = NumberUtils.randFloat(0, 1);
|
||||
double band = 1 / (double) this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks").size();
|
||||
int selectedIndex = (int) Math.floor(random / band);
|
||||
selectedIndex = NumberUtils.equalIfOver(selectedIndex, this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks").size() - 1);
|
||||
String materialName = this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks").get(selectedIndex);
|
||||
material = Material.getMaterial(materialName.toUpperCase());
|
||||
|
||||
if (material == null) {
|
||||
material = block.getType();
|
||||
}
|
||||
|
||||
ItemStack item = new ItemStack(material, 1);
|
||||
|
||||
new DropQueue(player)
|
||||
.setLocation(block.getLocation())
|
||||
.addItem(item)
|
||||
.push();
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
#
|
||||
# Wood Switcher EcoEnchant
|
||||
#
|
||||
|
||||
name: "Wood Switcher"
|
||||
description: Breaking logs can drop as other logs.
|
||||
enabled: true
|
||||
|
||||
obtaining:
|
||||
table: true
|
||||
villager: true
|
||||
loot: true
|
||||
rarity: epic
|
||||
|
||||
general-config:
|
||||
targets:
|
||||
- axe
|
||||
grindstoneable: true
|
||||
disabled-in-worlds: []
|
||||
conflicts:
|
||||
- silk_touch
|
||||
maximum-level: 6
|
||||
|
||||
config:
|
||||
blocks:
|
||||
- oak_log
|
||||
- birch_log
|
||||
- spruce_log
|
||||
- jungle_log
|
||||
- acacia_log
|
||||
- dark_oak_log
|
||||
chance-per-level: 10 # Chance for drop to be switched
|
Loading…
Reference in New Issue
Block a user