1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00
This commit is contained in:
TheBusyBiscuit 2020-04-21 21:07:05 +02:00
parent 1baefd37b0
commit ca6170e64b
3 changed files with 56 additions and 21 deletions

View File

@ -68,6 +68,7 @@
* Fixed GEO Scanner being unable to deal with more than 28 different resources
* Fixed #893
* Fixed #1798
* Fixed #1490
## Release Candidate 10 (28 Mar 2020)
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#10

View File

@ -7,10 +7,11 @@ import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.NotPlaceable;
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class BasicCircuitBoard extends SimpleSlimefunItem<ItemUseHandler> {
public class BasicCircuitBoard extends SimpleSlimefunItem<ItemUseHandler> implements NotPlaceable {
private final ItemSetting<Boolean> dropSetting = new ItemSetting<>("drop-from-golems", true);

View File

@ -1,6 +1,7 @@
package io.github.thebusybiscuit.slimefun4.implementation.listeners;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Random;
import java.util.Set;
@ -9,7 +10,9 @@ import java.util.concurrent.ThreadLocalRandom;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.ChestedHorse;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
@ -23,6 +26,7 @@ import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.player.PlayerItemBreakEvent;
import org.bukkit.event.player.PlayerToggleSprintEvent;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.Damageable;
@ -32,8 +36,8 @@ import org.bukkit.util.Vector;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
import io.github.thebusybiscuit.slimefun4.implementation.items.magical.talismans.MagicianTalisman;
import io.github.thebusybiscuit.slimefun4.implementation.items.magical.talismans.Talisman;
import io.github.thebusybiscuit.slimefun4.implementation.items.magical.talismans.MagicianTalisman.TalismanEnchantment;
import io.github.thebusybiscuit.slimefun4.implementation.items.magical.talismans.Talisman;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.api.Slimefun;
@ -88,26 +92,54 @@ public class TalismanListener implements Listener {
@EventHandler(ignoreCancelled = true)
public void onKill(EntityDeathEvent e) {
if (e.getEntity().getKiller() != null && !(e.getEntity() instanceof Player) && !e.getEntity().getCanPickupItems() && Talisman.checkFor(e, SlimefunItems.TALISMAN_HUNTER)) {
List<ItemStack> extraDrops = new ArrayList<>(e.getDrops());
if (e.getDrops().isEmpty() || e.getEntity().getKiller() == null) {
return;
}
// Prevent doubling of items stored inside a Horse's chest
if (e.getEntity() instanceof ChestedHorse) {
ChestedHorse horse = ((ChestedHorse) e.getEntity());
for (ItemStack invItem : horse.getInventory().getStorageContents()) {
extraDrops.remove(invItem);
}
LivingEntity entity = e.getEntity();
// The chest is not included in getStorageContents()
extraDrops.remove(new ItemStack(Material.CHEST));
}
if (!(entity instanceof Player) && !(entity instanceof ArmorStand) && Talisman.checkFor(e, SlimefunItems.TALISMAN_HUNTER)) {
Collection<ItemStack> extraDrops = getExtraDrops(e.getEntity(), e.getDrops());
for (ItemStack drop : extraDrops) {
e.getDrops().add(drop);
if (drop != null) {
e.getDrops().add(drop.clone());
}
}
}
}
private Collection<ItemStack> getExtraDrops(LivingEntity entity, Collection<ItemStack> drops) {
List<ItemStack> items = new ArrayList<>(drops);
// Prevent duplication of items stored inside a Horse's chest
if (entity instanceof ChestedHorse) {
ChestedHorse horse = (ChestedHorse) entity;
if (horse.isCarryingChest()) {
// The chest is not included in getStorageContents()
items.remove(new ItemStack(Material.CHEST));
for (ItemStack item : horse.getInventory().getStorageContents()) {
items.remove(item);
}
}
}
// Prevent duplication of handheld items or armor
EntityEquipment equipment = entity.getEquipment();
if (equipment != null) {
for (ItemStack item : equipment.getArmorContents()) {
items.remove(item);
}
items.remove(equipment.getItemInMainHand());
items.remove(equipment.getItemInOffHand());
}
return items;
}
@EventHandler
public void onItemBreak(PlayerItemBreakEvent e) {
if (Talisman.checkFor(e, SlimefunItems.TALISMAN_ANVIL)) {
@ -173,21 +205,22 @@ public class TalismanListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent e) {
ItemStack item = e.getPlayer().getInventory().getItemInMainHand();
List<ItemStack> drops = new ArrayList<>(e.getBlock().getDrops(item));
int fortune = 1;
Random random = ThreadLocalRandom.current();
if (item.getType() != Material.AIR && item.getAmount() > 0) {
List<ItemStack> drops = new ArrayList<>(e.getBlock().getDrops(item));
int dropAmount = 1;
if (item.getEnchantments().containsKey(Enchantment.LOOT_BONUS_BLOCKS) && !item.getEnchantments().containsKey(Enchantment.SILK_TOUCH)) {
fortune = random.nextInt(item.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) + 2) - 1;
if (fortune <= 0) fortune = 1;
fortune = (e.getBlock().getType() == Material.LAPIS_ORE ? 4 + random.nextInt(5) : 1) * (fortune + 1);
Random random = ThreadLocalRandom.current();
dropAmount = random.nextInt(item.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) + 2) - 1;
dropAmount = Math.max(dropAmount, 1);
dropAmount = (e.getBlock().getType() == Material.LAPIS_ORE ? 4 + random.nextInt(5) : 1) * (dropAmount + 1);
}
if (!item.getEnchantments().containsKey(Enchantment.SILK_TOUCH) && MaterialCollections.getAllOres().contains(e.getBlock().getType()) && Talisman.checkFor(e, SlimefunItems.TALISMAN_MINER)) {
for (ItemStack drop : drops) {
if (!drop.getType().isBlock()) {
int amount = Math.max(1, (fortune * 2) - drop.getAmount());
int amount = Math.max(1, (dropAmount * 2) - drop.getAmount());
e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), new CustomItem(drop, amount));
}
}