1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Merge pull request #136 from John000708/master

Feature Additions
This commit is contained in:
TheBusyBiscuit 2017-02-06 20:40:57 +01:00 committed by GitHub
commit ab14aa7a48
6 changed files with 55 additions and 19 deletions

View File

@ -8,6 +8,7 @@ options:
auto-save-delay-in-minutes: 10
show-vanilla-recipes-in-guide: true
allow-free-creative-research: true
emerald-enchantment-limit: 2
guide:
default-view-book: false
URID:

View File

@ -29,6 +29,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.material.MaterialData;
public class AutoEnchanter extends AContainer {
public static int max_emerald_enchantments = 2;
public AutoEnchanter(Category category, ItemStack item, String name, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, name, recipeType, recipe);
@ -51,7 +52,7 @@ public class AutoEnchanter extends AContainer {
public int getEnergyConsumption() {
return 9;
}
@SuppressWarnings("deprecation")
@Override
protected void tick(Block b) {
@ -68,9 +69,9 @@ public class AutoEnchanter extends AContainer {
lore.add(MachineHelper.getTimeLeft(timeleft / 2));
im.setLore(lore);
item.setItemMeta(im);
BlockStorage.getInventory(b).replaceExistingItem(22, item);
if (ChargableBlock.isChargable(b)) {
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) return;
ChargableBlock.addCharge(b, -getEnergyConsumption());
@ -81,7 +82,7 @@ public class AutoEnchanter extends AContainer {
else {
BlockStorage.getInventory(b).replaceExistingItem(22, new CustomItem(new MaterialData(Material.STAINED_GLASS_PANE, (byte) 15), " "));
pushItems(b, processing.get(b).getOutput());
progress.remove(b);
processing.remove(b);
}
@ -96,6 +97,7 @@ public class AutoEnchanter extends AContainer {
Map<Enchantment, Integer> enchantments = new HashMap<Enchantment, Integer>();
Set<ItemEnchantment> enchantments2 = new HashSet<ItemEnchantment>();
int amount = 0;
int special_amount = 0;
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) item.getItemMeta();
for (Map.Entry<Enchantment, Integer> e: meta.getStoredEnchants().entrySet()) {
if (e.getKey().canEnchantItem(target)) {
@ -107,12 +109,13 @@ public class AutoEnchanter extends AContainer {
for (ItemEnchantment enchantment: EmeraldEnchants.getInstance().getRegistry().getEnchantments(item)) {
if (EmeraldEnchants.getInstance().getRegistry().isApplicable(target, enchantment.getEnchantment()) && EmeraldEnchants.getInstance().getRegistry().getEnchantmentLevel(target, enchantment.getEnchantment().getName()) < enchantment.getLevel()) {
amount++;
special_amount++;
enchantments2.add(enchantment);
}
}
special_amount+=EmeraldEnchants.getInstance().getRegistry().getEnchantments(target).size();
}
if (amount > 0) {
if (amount > 0 && special_amount <= max_emerald_enchantments) {
ItemStack newItem = target.clone();
for (Map.Entry<Enchantment, Integer> e: enchantments.entrySet()) {
newItem.addUnsafeEnchantment(e.getKey(), e.getValue());
@ -125,7 +128,7 @@ public class AutoEnchanter extends AContainer {
break slots;
}
}
if (r != null) {
if (!fits(b, r.getOutput())) return;
for (int slot: getInputSlots()) {

View File

@ -13,11 +13,7 @@ import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Chest;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.block.Dispenser;
import org.bukkit.block.*;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Arrow;
@ -2008,6 +2004,7 @@ public class SlimefunSetup {
Block b = e.getBlock().getRelative(x, y, z);
if (b.getType() != Material.AIR && !StringUtils.equals(b.getType().toString(), explosiveblacklist)) {
if (CSCoreLib.getLib().getProtectionManager().canBuild(e.getPlayer().getUniqueId(), b)) {
if (SlimefunStartup.instance.isCoreProtectInstalled()) SlimefunStartup.instance.getCoreProtectAPI().logRemoval(e.getPlayer().getName(), b.getLocation(), b.getType(), b.getData());
b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType());
SlimefunItem sfItem = BlockStorage.check(b);
boolean allow = true;
@ -2022,6 +2019,9 @@ public class SlimefunSetup {
else if (b.getType().equals(Material.SKULL)) {
b.breakNaturally();
}
else if (b.getType().name().endsWith("_SHULKER_BOX")) {
b.breakNaturally();
}
else {
for (ItemStack drop: b.getDrops()) {
b.getWorld().dropItemNaturally(b.getLocation(), (b.getType().toString().endsWith("_ORE") && !b.getType().equals(Material.IRON_ORE) && !b.getType().equals(Material.GOLD_ORE)) ? new CustomItem(drop, fortune): drop);

View File

@ -15,6 +15,9 @@ import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines.AutoEnchanter;
import net.coreprotect.CoreProtect;
import net.coreprotect.CoreProtectAPI;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.block.Block;
@ -99,8 +102,11 @@ public class SlimefunStartup extends JavaPlugin {
public static TickerTask ticker;
private CoreProtectAPI coreProtectAPI;
private boolean clearlag = false;
private boolean exoticGarden = false;
private boolean coreProtect = false;
// Supported Versions of Minecraft
final String[] supported = {"v1_9_", "v1_10_", "v1_11_", "PluginBukkitBridge"};
@ -375,6 +381,8 @@ public class SlimefunStartup extends JavaPlugin {
clearlag = getServer().getPluginManager().isPluginEnabled("ClearLag");
coreProtect = getServer().getPluginManager().isPluginEnabled("CoreProtect");
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new BukkitRunnable() {
@Override
public void run() {
@ -384,7 +392,13 @@ public class SlimefunStartup extends JavaPlugin {
if (clearlag) new ClearLaggIntegration(this);
if (coreProtect) coreProtectAPI = ((CoreProtect)getServer().getPluginManager().getPlugin("CoreProtect")).getAPI();
SlimefunGuide.creative_research = config.getBoolean("options.allow-free-creative-research");
AutoEnchanter.max_emerald_enchantments = config.getInt("options.emerald-enchantment-limit");
// Do not show /sf elevator command in our Log, it could get quite spammy
CSCoreLib.getLib().filterLog("([A-Za-z0-9_]{3,16}) issued server command: /sf elevator (.{0,})");
}
@ -594,4 +608,12 @@ public class SlimefunStartup extends JavaPlugin {
public boolean isExoticGardenInstalled () {
return exoticGarden;
}
public boolean isCoreProtectInstalled() {
return coreProtect;
}
public CoreProtectAPI getCoreProtectAPI() {
return coreProtectAPI;
}
}

View File

@ -185,7 +185,7 @@ public class CargoManager {
return stack;
}
//Whitelist or blacklist slots
private static int[] slots = new int[] {19, 20, 21, 28, 29, 30, 37, 38, 39};
public static boolean matchesFilter(Block block, ItemStack item, int index) {

View File

@ -55,7 +55,8 @@ public class CargoNet {
public static Set<ItemRequest> requests = new HashSet<ItemRequest>();
private static int[] slots = new int[] {19, 20, 21, 28, 29, 30, 37, 38, 39};
//Chest Terminal Stuff
private static final ChestTerminalSorter sorter = new ChestTerminalSorter();
public static final int[] terminal_slots = new int[] {0, 1, 2, 3, 4, 5, 6, 9, 10, 11, 12, 13, 14, 15, 18, 19, 20, 21, 22, 23, 24, 27, 28, 29, 30, 31, 32, 33, 36, 37, 38, 39, 40, 41, 42};
private static final ItemStack terminal_noitem_item = new CustomItem(new MaterialData(Material.BARRIER), "&4No Item cached");
@ -66,11 +67,20 @@ public class CargoNet {
return false;
}
};
public static void tick(final Block b) {
/*
Input/Output Nodes can be found here after a scan.
Input Nodes:
Location = The location of the node.
Integer = The frequency of the node.
Output Nodes:
Integer = The frequency of the node.
List<Location> = The locations of the corresponding input nodes
*/
final Map<Location, Integer> input = new HashMap<Location, Integer>();
final Map<Integer, List<Location>> output = new HashMap<Integer, List<Location>>();
//Chest Terminal Stuff
final Set<Location> providers = new HashSet<Location>();
final Set<Location> terminals = new HashSet<Location>();
final Set<Location> imports = new HashSet<Location>();
@ -103,7 +113,7 @@ public class CargoNet {
}
}
}
//Chest Terminal Code
if (EXTRA_CHANNELS) {
for (Location bus: imports) {
BlockMenu menu = BlockStorage.getInventory(bus);
@ -225,7 +235,7 @@ public class CargoNet {
}
}
}
//All operations happen here: Everything gets iterated from the Input Nodes. (Apart from ChestTerminal Buses)
for (Map.Entry<Location, Integer> entry: input.entrySet()) {
Block inputTarget = getAttachedBlock(entry.getKey().getBlock());
ItemStack stack = null;
@ -289,7 +299,7 @@ public class CargoNet {
}
}
}
//Chest Terminal Code
if (EXTRA_CHANNELS) {
List<StoredItem> items = new ArrayList<StoredItem>();
for (Location l: providers) {