mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Merge branch 'master' into cleanup/blockplacing
This commit is contained in:
commit
54aa45d1d2
@ -42,6 +42,10 @@
|
||||
* Fixed Reinforced Spawners not working sometimes
|
||||
* Fixed Explosive Pickaxe not handling normal Shulker boxes correctly
|
||||
* Fixed #2103
|
||||
* Fixed #2184
|
||||
* Fixed #2183
|
||||
* Fixed #2181
|
||||
* Fixed #2180
|
||||
|
||||
## Release Candidate 15 (01 Aug 2020)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Material;
|
||||
@ -33,7 +33,7 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
|
||||
public abstract class CropGrowthAccelerator extends SlimefunItem implements InventoryBlock, EnergyNetComponent {
|
||||
|
||||
private final int[] border = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 };
|
||||
private final Set<Material> crops = new HashSet<>();
|
||||
private final Set<Material> crops = EnumSet.noneOf(Material.class);
|
||||
|
||||
// We wanna strip the Slimefun Item id here
|
||||
private static final ItemStack organicFertilizer = new ItemStackWrapper(SlimefunItems.FERTILIZER);
|
||||
|
@ -17,7 +17,6 @@ import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemDropHandler;
|
||||
@ -70,7 +69,7 @@ public class EnchantmentRune extends SimpleSlimefunItem<ItemDropHandler> {
|
||||
if (Slimefun.hasUnlocked(p, this, true)) {
|
||||
Slimefun.runSync(() -> {
|
||||
try {
|
||||
addRandomEnchantment(p, e, item);
|
||||
addRandomEnchantment(p, item);
|
||||
}
|
||||
catch (Exception x) {
|
||||
error("An Exception occured while trying to apply an Enchantment Rune", x);
|
||||
@ -85,21 +84,21 @@ public class EnchantmentRune extends SimpleSlimefunItem<ItemDropHandler> {
|
||||
};
|
||||
}
|
||||
|
||||
private void addRandomEnchantment(Player p, PlayerDropItemEvent e, Item item) {
|
||||
private void addRandomEnchantment(Player p, Item rune) {
|
||||
// Being sure the entity is still valid and not picked up or whatsoever.
|
||||
if (!item.isValid()) {
|
||||
if (!rune.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Location l = item.getLocation();
|
||||
Location l = rune.getLocation();
|
||||
Collection<Entity> entites = l.getWorld().getNearbyEntities(l, RANGE, RANGE, RANGE, this::findCompatibleItem);
|
||||
Optional<Entity> optional = entites.stream().findFirst();
|
||||
|
||||
if (optional.isPresent()) {
|
||||
Item entity = (Item) optional.get();
|
||||
ItemStack target = entity.getItemStack();
|
||||
Item item = (Item) optional.get();
|
||||
ItemStack itemStack = item.getItemStack();
|
||||
|
||||
List<Enchantment> potentialEnchantments = applicableEnchantments.get(target.getType());
|
||||
List<Enchantment> potentialEnchantments = applicableEnchantments.get(itemStack.getType());
|
||||
|
||||
if (potentialEnchantments == null) {
|
||||
SlimefunPlugin.getLocalization().sendMessage(p, "messages.enchantment-rune.fail", true);
|
||||
@ -111,7 +110,7 @@ public class EnchantmentRune extends SimpleSlimefunItem<ItemDropHandler> {
|
||||
|
||||
// Removing the enchantments that the item already has from enchantmentSet
|
||||
// This also removes any conflicting enchantments
|
||||
removeIllegalEnchantments(target, potentialEnchantments);
|
||||
removeIllegalEnchantments(itemStack, potentialEnchantments);
|
||||
|
||||
if (potentialEnchantments.isEmpty()) {
|
||||
SlimefunPlugin.getLocalization().sendMessage(p, "messages.enchantment-rune.no-enchantment", true);
|
||||
@ -119,30 +118,24 @@ public class EnchantmentRune extends SimpleSlimefunItem<ItemDropHandler> {
|
||||
}
|
||||
|
||||
Enchantment enchantment = potentialEnchantments.get(ThreadLocalRandom.current().nextInt(potentialEnchantments.size()));
|
||||
int level = 1;
|
||||
|
||||
if (enchantment.getMaxLevel() != 1) {
|
||||
level = ThreadLocalRandom.current().nextInt(enchantment.getMaxLevel()) + 1;
|
||||
}
|
||||
|
||||
target.addEnchantment(enchantment, level);
|
||||
|
||||
if (target.getAmount() == 1) {
|
||||
e.setCancelled(true);
|
||||
int level = getRandomlevel(enchantment);
|
||||
|
||||
if (itemStack.getAmount() == 1) {
|
||||
// This lightning is just an effect, it deals no damage.
|
||||
l.getWorld().strikeLightningEffect(l);
|
||||
|
||||
Slimefun.runSync(() -> {
|
||||
// Being sure entities are still valid and not picked up or whatsoever.
|
||||
if (item.isValid() && entity.isValid() && target.getAmount() == 1) {
|
||||
if (rune.isValid() && item.isValid() && itemStack.getAmount() == 1) {
|
||||
|
||||
l.getWorld().spawnParticle(Particle.CRIT_MAGIC, l, 1);
|
||||
l.getWorld().playSound(l, Sound.ENTITY_ZOMBIE_VILLAGER_CURE, 1F, 1F);
|
||||
|
||||
entity.remove();
|
||||
item.remove();
|
||||
l.getWorld().dropItemNaturally(l, target);
|
||||
rune.remove();
|
||||
|
||||
itemStack.addEnchantment(enchantment, level);
|
||||
l.getWorld().dropItemNaturally(l, itemStack);
|
||||
|
||||
SlimefunPlugin.getLocalization().sendMessage(p, "messages.enchantment-rune.success", true);
|
||||
}
|
||||
@ -154,6 +147,16 @@ public class EnchantmentRune extends SimpleSlimefunItem<ItemDropHandler> {
|
||||
}
|
||||
}
|
||||
|
||||
private int getRandomlevel(Enchantment enchantment) {
|
||||
int level = 1;
|
||||
|
||||
if (enchantment.getMaxLevel() != 1) {
|
||||
level = ThreadLocalRandom.current().nextInt(enchantment.getMaxLevel()) + 1;
|
||||
}
|
||||
|
||||
return level;
|
||||
}
|
||||
|
||||
private void removeIllegalEnchantments(ItemStack target, List<Enchantment> potentialEnchantments) {
|
||||
for (Enchantment enchantment : target.getEnchantments().keySet()) {
|
||||
Iterator<Enchantment> iterator = potentialEnchantments.iterator();
|
||||
|
@ -8,7 +8,6 @@ import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.Soulbound;
|
||||
@ -51,7 +50,7 @@ public class SoulboundRune extends SimpleSlimefunItem<ItemDropHandler> {
|
||||
return true;
|
||||
}
|
||||
|
||||
Slimefun.runSync(() -> activate(p, e, item), 20L);
|
||||
Slimefun.runSync(() -> activate(p, item), 20L);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -59,7 +58,7 @@ public class SoulboundRune extends SimpleSlimefunItem<ItemDropHandler> {
|
||||
};
|
||||
}
|
||||
|
||||
private void activate(Player p, PlayerDropItemEvent e, Item rune) {
|
||||
private void activate(Player p, Item rune) {
|
||||
// Being sure the entity is still valid and not picked up or whatsoever.
|
||||
if (!rune.isValid()) {
|
||||
return;
|
||||
@ -74,9 +73,6 @@ public class SoulboundRune extends SimpleSlimefunItem<ItemDropHandler> {
|
||||
ItemStack itemStack = item.getItemStack();
|
||||
|
||||
if (itemStack.getAmount() == 1) {
|
||||
// Prevent other plugins from processing this Item as we will remove it soon
|
||||
e.setCancelled(true);
|
||||
|
||||
// This lightning is just an effect, it deals no damage.
|
||||
l.getWorld().strikeLightningEffect(l);
|
||||
|
||||
|
@ -73,12 +73,15 @@ public class EnhancedCraftingTable extends BackpackCrafter {
|
||||
ItemUtils.consumeItem(item, true);
|
||||
}
|
||||
}
|
||||
|
||||
p.getWorld().playSound(b.getLocation(), Sound.BLOCK_WOODEN_BUTTON_CLICK_ON, 1, 1);
|
||||
|
||||
outputInv.addItem(output);
|
||||
|
||||
}
|
||||
else SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
|
||||
else {
|
||||
SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isCraftable(Inventory inv, ItemStack[] recipe) {
|
||||
|
@ -25,8 +25,16 @@ import io.papermc.lib.PaperLib;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
/**
|
||||
* The {@link OreCrusher} is a {@link MultiBlockMachine} which allows you to double ores
|
||||
* and crush some other {@link Material Materials} into various resources.
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
*/
|
||||
public class OreCrusher extends MultiBlockMachine {
|
||||
|
||||
private final DoubleOreSetting doubleOres = new DoubleOreSetting();
|
||||
@ -96,15 +104,18 @@ public class OreCrusher extends MultiBlockMachine {
|
||||
if (convert != null && SlimefunUtils.isItemSimilar(current, convert, true)) {
|
||||
ItemStack adding = RecipeType.getRecipeOutput(this, convert);
|
||||
Inventory outputInv = findOutputInventory(adding, dispBlock, inv);
|
||||
if (outputInv != null) {
|
||||
ItemStack removing = current.clone();
|
||||
removing.setAmount(convert.getAmount());
|
||||
inv.removeItem(removing);
|
||||
outputInv.addItem(adding);
|
||||
p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, 1);
|
||||
}
|
||||
else {
|
||||
SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
|
||||
|
||||
if (Slimefun.hasUnlocked(p, adding, true)) {
|
||||
if (outputInv != null) {
|
||||
ItemStack removing = current.clone();
|
||||
removing.setAmount(convert.getAmount());
|
||||
inv.removeItem(removing);
|
||||
outputInv.addItem(adding);
|
||||
p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, 1);
|
||||
}
|
||||
else {
|
||||
SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -63,14 +63,13 @@ public class ExplosiveBow extends SlimefunBow {
|
||||
double distanceSquared = distanceVector.lengthSquared();
|
||||
double damage = calculateDamage(distanceSquared, e.getDamage());
|
||||
|
||||
Vector knockback = velocity.add(distanceVector.normalize().multiply((int) (e.getDamage() / damage)));
|
||||
entity.setVelocity(knockback);
|
||||
|
||||
if (!entity.getUniqueId().equals(target.getUniqueId())) {
|
||||
EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(e.getDamager(), entity, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION, damage);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (!event.isCancelled()) {
|
||||
Vector knockback = velocity.add(distanceVector.normalize().multiply((int) (e.getDamage() / damage)));
|
||||
entity.setVelocity(knockback);
|
||||
entity.damage(event.getDamage());
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package io.github.thebusybiscuit.slimefun4.implementation.listeners;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
@ -35,7 +35,7 @@ import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
public class BlockListener implements Listener {
|
||||
|
||||
// Materials that require a Block under it, e.g. Pressure Plates
|
||||
private final Set<Material> sensitiveMaterials = new HashSet<>();
|
||||
private final Set<Material> sensitiveMaterials = EnumSet.noneOf(Material.class);
|
||||
|
||||
public BlockListener(SlimefunPlugin plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
@ -82,11 +82,9 @@ public class BlockListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockUnregister(BlockBreakEvent e) {
|
||||
if (hasSensitiveBlockAbove(e.getPlayer(), e.getBlock())) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
checkForSensitiveBlockAbove(e.getPlayer(), e.getBlock());
|
||||
|
||||
SlimefunItem sfItem = BlockStorage.check(e.getBlock());
|
||||
ItemStack item = e.getPlayer().getInventory().getItemInMainHand();
|
||||
int fortune = getBonusDropsWithFortune(item, e.getBlock());
|
||||
List<ItemStack> drops = new ArrayList<>();
|
||||
@ -155,7 +153,17 @@ public class BlockListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasSensitiveBlockAbove(Player p, Block b) {
|
||||
/**
|
||||
* This method checks for a sensitive {@link Block}.
|
||||
* Sensitive {@link Block Blocks} are pressure plates or saplings, which should be broken
|
||||
* when the block beneath is broken as well.
|
||||
*
|
||||
* @param p
|
||||
* The {@link Player} who broke this {@link Block}
|
||||
* @param b
|
||||
* The {@link Block} that was broken
|
||||
*/
|
||||
private void checkForSensitiveBlockAbove(Player p, Block b) {
|
||||
Block blockAbove = b.getRelative(BlockFace.UP);
|
||||
|
||||
if (sensitiveMaterials.contains(blockAbove.getType())) {
|
||||
@ -169,14 +177,13 @@ public class BlockListener implements Listener {
|
||||
blockAbove.getWorld().dropItemNaturally(blockAbove.getLocation(), BlockStorage.retrieve(blockAbove));
|
||||
blockAbove.setType(Material.AIR);
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
blockAbove.getWorld().dropItemNaturally(blockAbove.getLocation(), BlockStorage.retrieve(blockAbove));
|
||||
blockAbove.setType(Material.AIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private int getBonusDropsWithFortune(ItemStack item, Block b) {
|
||||
|
@ -8,6 +8,7 @@ import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
@ -67,16 +68,14 @@ public class SlimefunBowListener implements Listener {
|
||||
}, 4L);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onArrowSuccessfulHit(EntityDamageByEntityEvent e) {
|
||||
if (e.getDamager() instanceof Arrow && e.getEntity() instanceof LivingEntity && e.getCause() != EntityDamageEvent.DamageCause.ENTITY_EXPLOSION) {
|
||||
SlimefunBow bow = projectiles.get(e.getDamager().getUniqueId());
|
||||
SlimefunBow bow = projectiles.remove(e.getDamager().getUniqueId());
|
||||
|
||||
if (bow != null) {
|
||||
if (!e.isCancelled() && bow != null) {
|
||||
bow.callItemHandler(BowShootHandler.class, handler -> handler.onHit(e, (LivingEntity) e.getEntity()));
|
||||
}
|
||||
|
||||
projectiles.remove(e.getDamager().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -223,7 +223,7 @@ public class SlimefunItem implements Placeable {
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Optional<ItemSetting<T>> getItemSetting(String key, Class<T> c) {
|
||||
for (ItemSetting<?> setting : itemSettings) {
|
||||
if (setting.getKey().equals(key) && c.isInstance(setting.getDefaultValue())) {
|
||||
if (setting.getKey().equals(key) && setting.isType(c)) {
|
||||
return Optional.of((ItemSetting<T>) setting);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user