Added Transfuse

This commit is contained in:
Auxilor 2020-08-30 11:35:04 +01:00
parent 8ac7b1a383
commit 0a6084703f
6 changed files with 111 additions and 3 deletions

View File

@ -224,6 +224,7 @@ public class EcoEnchants {
public static final EcoEnchant GRACEFUL = new Graceful();
public static final EcoEnchant BLOCK_BREATHER = new BlockBreather();
public static final EcoEnchant VOLTAGE = new Voltage();
public static final EcoEnchant TRANSFUSE = new Transfuse();
/**
* Get all registered {@link EcoEnchant}s

View File

@ -19,7 +19,7 @@ import org.bukkit.inventory.ItemStack;
public class StoneSwitcher extends EcoEnchant {
public StoneSwitcher() {
super(
new EcoEnchantBuilder("stone_switcher", EnchantmentType.NORMAL, Target.Applicable.PICKAXE, 4.0)
new EcoEnchantBuilder("stone_switcher", EnchantmentType.NORMAL, Target.Applicable.PICKAXE, 4.01)
);
}

View File

@ -0,0 +1,70 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.util.checks.EnchantChecks;
import com.willfp.ecoenchants.integrations.antigrief.AntigriefManager;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.queue.DropQueue;
import com.willfp.ecoenchants.util.EqualIfOver;
import com.willfp.ecoenchants.util.Rand;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
public class Transfuse extends EcoEnchant {
public Transfuse() {
super(
new EcoEnchantBuilder("transfuse", EnchantmentType.NORMAL, Target.Applicable.PICKAXE, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onBreak(BlockBreakEvent event) {
Player player = event.getPlayer();
Block block = event.getBlock();
if (!EnchantChecks.mainhand(player, this)) return;
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR)
return;
if(!block.getType().equals(Material.STONE)) return;
if (event.isCancelled())
return;
if (!AntigriefManager.canBreakBlock(player, block)) return;
int level = EnchantChecks.getMainhandLevel(player, this);
double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level");
if(Rand.randFloat(0, 1) > level * chance * 0.01)
return;
event.setDropItems(false);
Material material;
double random = Rand.randFloat(0, 1);
double band = 1/(double) this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks").size();
int selectedIndex = (int) Math.floor(random/band);
selectedIndex = EqualIfOver.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 = Material.COBBLESTONE;
ItemStack item = new ItemStack(material, 1);
new DropQueue(player)
.setLocation(block.getLocation())
.addItem(item)
.push();
}
}

View File

@ -2,7 +2,7 @@
# Stone Switcher EcoEnchant
#
config-version: 4.0 # Don't edit this.
config-version: 4.01 # Don't edit this.
name: "Stone Switcher"
@ -16,7 +16,9 @@ obtaining:
general-config:
grindstoneable: true
conflicts: []
conflicts:
- transfuse
- silk_touch
maximum-level: 3
config:

View File

@ -0,0 +1,31 @@
#
# Transfuse EcoEnchant
#
config-version: 4.0 # Don't edit this.
name: "Transfuse"
description: Breaking stone can drop as random ore.
obtaining:
table: true
villager: true
loot: true
rarity: legendary
general-config:
grindstoneable: true
conflicts:
- stone_switcher
- silk_touch
maximum-level: 4
config:
blocks:
- diamond_ore
- gold_ore
- lapis_ore
- redstone_ore
- iron_ore
chance-per-level: 0.05 # Chance for drop to be switched

View File

@ -243,6 +243,7 @@ permissions:
ecoenchants.fromtable.graceful: true
ecoenchants.fromtable.blockbreather: true
ecoenchants.fromtable.voltage: true
ecoenchants.fromtable.transfuse: true
ecoenchants.updateannounce:
description: Informs admins of a new update
@ -844,4 +845,7 @@ permissions:
default: true
ecoenchants.fromtable.voltage:
description: Allows getting voltage from an enchanting table
default: true
ecoenchants.fromtable.transfuse:
description: Allows getting transfuse from an enchanting table
default: true