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

Merge pull request #1 from TheBusyBiscuit/master

t
This commit is contained in:
CyberPatriot 2019-08-03 16:17:18 -05:00 committed by GitHub
commit c9bdac1277
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 863 additions and 566 deletions

126
pom.xml
View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>me.mrCookieSlime</groupId> <groupId>me.mrCookieSlime</groupId>
<artifactId>Slimefun</artifactId> <artifactId>Slimefun</artifactId>
<version>4.1.17</version> <version>DEV - 100 (git null)</version>
<properties> <properties>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
@ -30,16 +30,67 @@
<id>jitpack.io</id> <id>jitpack.io</id>
<url>https://jitpack.io</url> <url>https://jitpack.io</url>
</repository> </repository>
<repository>
<id>CodeMC</id>
<url>https://repo.codemc.org/repository/maven-public</url>
</repository>
</repositories> </repositories>
<build> <build>
<sourceDirectory>${project.basedir}/src</sourceDirectory> <sourceDirectory>${project.basedir}/src</sourceDirectory>
<testSourceDirectory>${project.basedir}/tests/java</testSourceDirectory>
<testResources>
<testResource>
<directory>${project.basedir}/tests/resources</directory>
</testResource>
</testResources>
<finalName>${project.name} v${project.version}</finalName> <finalName>${project.name} v${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<filters>
<filter>
<artifact>com.github.thebusybiscuit:CS-CoreLib2</artifact>
<includes>
<include>**/cscorelib2/updater/**</include>
</includes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>me.mrCookieSlime.Slimefun.bstats</shadedPattern>
</relocation>
<relocation>
<pattern>io.github.thebusybiscuit.cscorelib2</pattern>
<shadedPattern>me.mrCookieSlime.Slimefun.cscorelib2</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources> <resources>
<resource> <resource>
<directory>${basedir}/src</directory> <directory>${basedir}/src</directory>
@ -55,76 +106,59 @@
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId> <artifactId>bukkit</artifactId>
<version>1.14.2-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.sk89q.worldedit</groupId> <groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId> <artifactId>worldedit-bukkit</artifactId>
<version>7.0.0</version>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.TheBusyBiscuit</groupId> <groupId>com.github.TheBusyBiscuit</groupId>
<artifactId>CS-CoreLib</artifactId> <artifactId>CS-CoreLib</artifactId>
<version>v1.6.1</version>
<scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.github.thebusybiscuit</groupId>
<artifactId>CS-CoreLib2</artifactId>
<version>0.3.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>1.5</version>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>me.minebuilders</groupId> <groupId>me.minebuilders</groupId>
<artifactId>clearlag-core</artifactId> <artifactId>clearlag-core</artifactId>
<version>2.9.7</version>
<scope>system</scope> <scope>system</scope>
<systemPath>${project.basedir}/lib/Clearlag.jar</systemPath> <systemPath>${project.basedir}/lib/Clearlag.jar</systemPath>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.coreprotect</groupId> <groupId>net.coreprotect</groupId>
<artifactId>coreprotect</artifactId> <artifactId>coreprotect</artifactId>
<version>2.16.3</version>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>me.mrCookieSlime</groupId> <groupId>me.mrCookieSlime</groupId>
<artifactId>EmeraldEnchants</artifactId> <artifactId>EmeraldEnchants</artifactId>
<version>2.0</version>
<scope>system</scope> <scope>system</scope>
<systemPath>${project.basedir}/lib/EmeraldEnchants v2.0.jar</systemPath> <systemPath>${project.basedir}/lib/EmeraldEnchants v2.0.jar</systemPath>
</dependency> </dependency>
<dependency> <dependency>
<groupId>me.mrCookieSlime</groupId> <groupId>me.mrCookieSlime</groupId>
<artifactId>ExoticGarden</artifactId> <artifactId>ExoticGarden</artifactId>
<version>1.2.0</version>
<scope>system</scope> <scope>system</scope>
<systemPath>${project.basedir}/lib/ExoticGarden v1.2.0.jar</systemPath> <systemPath>${project.basedir}/lib/ExoticGarden v1.2.0.jar</systemPath>
</dependency> </dependency>
</dependencies> </dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.14.2-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>7.0.0</version>
</dependency>
<dependency>
<groupId>com.github.TheBusyBiscuit</groupId>
<artifactId>CS-CoreLib</artifactId>
<version>v1.6.1</version>
</dependency>
<dependency>
<groupId>me.minebuilders</groupId>
<artifactId>clearlag-core</artifactId>
<version>2.9.7</version>
</dependency>
<dependency>
<groupId>net.coreprotect</groupId>
<artifactId>coreprotect</artifactId>
<version>2.16.3</version>
</dependency>
<dependency>
<groupId>me.mrCookieSlime</groupId>
<artifactId>EmeraldEnchants</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>me.mrCookieSlime</groupId>
<artifactId>ExoticGarden</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
</dependencyManagement>
</project> </project>

View File

@ -1,13 +1,19 @@
package me.mrCookieSlime.Slimefun.AncientAltar; package me.mrCookieSlime.Slimefun.AncientAltar;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import me.mrCookieSlime.Slimefun.SlimefunStartup; import me.mrCookieSlime.Slimefun.SlimefunStartup;
import me.mrCookieSlime.Slimefun.listeners.AncientAltarListener; import me.mrCookieSlime.Slimefun.listeners.AncientAltarListener;
import me.mrCookieSlime.Slimefun.Variables; import me.mrCookieSlime.Slimefun.Variables;
import org.bukkit.*; import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -23,6 +29,7 @@ public class RitualAnimation implements Runnable {
List<ItemStack> items; List<ItemStack> items;
List<Location> particles; List<Location> particles;
Map<Item,Location> itemLock = new HashMap<>();
boolean running; boolean running;
int stage; int stage;
@ -38,11 +45,19 @@ public class RitualAnimation implements Runnable {
this.running = true; this.running = true;
this.stage = 0; this.stage = 0;
for(Block ped:this.pedestals) {
Item itm = AncientAltarListener.findItem(ped);
this.itemLock.put(itm, itm.getLocation().clone());
}
} }
@Override @Override
public void run() { public void run() {
idle(); idle();
if(!checkLockedItems()) {
abort();
return;
}
if(this.stage == 36) { if(this.stage == 36) {
finish(); finish();
return; return;
@ -54,6 +69,15 @@ public class RitualAnimation implements Runnable {
SlimefunStartup.instance.getServer().getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, this, 8); SlimefunStartup.instance.getServer().getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, this, 8);
} }
private boolean checkLockedItems() {
for(Item itm:this.itemLock.keySet())
if(itm.getLocation().distance(this.itemLock.get(itm)) > 0.3)
return false;
return true;
}
private void idle() { private void idle() {
try { try {
l.getWorld().spawnParticle(Particle.SPELL_WITCH, l,16, 1.2F, 0F, 1.2F); l.getWorld().spawnParticle(Particle.SPELL_WITCH, l,16, 1.2F, 0F, 1.2F);
@ -69,7 +93,12 @@ public class RitualAnimation implements Runnable {
private void checkPedestal(Block pedestal) { private void checkPedestal(Block pedestal) {
Item item = AncientAltarListener.findItem(pedestal); Item item = AncientAltarListener.findItem(pedestal);
if (item == null) abort();
if(item == null || itemLock.remove(item) == null) {
abort();
}
else { else {
particles.add(pedestal.getLocation().add(0.5, 1.5, 0.5)); particles.add(pedestal.getLocation().add(0.5, 1.5, 0.5));
items.add(AncientAltarListener.fixItemStack(item.getItemStack(), item.getCustomName())); items.add(AncientAltarListener.fixItemStack(item.getItemStack(), item.getCustomName()));
@ -82,7 +111,9 @@ public class RitualAnimation implements Runnable {
e.printStackTrace(); e.printStackTrace();
} }
itemLock.remove(item);
item.remove(); item.remove();
pedestal.removeMetadata("item_placed", SlimefunStartup.instance); pedestal.removeMetadata("item_placed", SlimefunStartup.instance);
} }
} }
@ -96,6 +127,7 @@ public class RitualAnimation implements Runnable {
Variables.altarinuse.remove(altar.getLocation()); // should re-enable altar blocks on craft failure. Variables.altarinuse.remove(altar.getLocation()); // should re-enable altar blocks on craft failure.
l.getWorld().playSound(l, Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, 5F, 1F); l.getWorld().playSound(l, Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, 5F, 1F);
itemLock.clear();
altars.remove(altar); altars.remove(altar);
} }

View File

@ -20,10 +20,10 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.data.Ageable;
import org.bukkit.block.data.Rotatable;
import org.bukkit.block.Dispenser; import org.bukkit.block.Dispenser;
import org.bukkit.block.Skull; import org.bukkit.block.Skull;
import org.bukkit.block.data.Ageable;
import org.bukkit.block.data.Rotatable;
import org.bukkit.entity.Animals; import org.bukkit.entity.Animals;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;

View File

@ -1,10 +1,10 @@
package me.mrCookieSlime.Slimefun.Android; package me.mrCookieSlime.Slimefun.Android;
import org.bukkit.inventory.ItemStack;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem; import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem;
import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull; import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull;
import org.bukkit.inventory.ItemStack;
public enum ScriptPart { public enum ScriptPart {
// Start and End Parts // Start and End Parts

View File

@ -12,9 +12,10 @@ import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import com.google.gson.JsonArray;
import org.json.simple.JSONValue; import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
public class CSCoreLibLoader { public class CSCoreLibLoader {
@ -62,9 +63,11 @@ public class CSCoreLibLoader {
connection.setDoOutput(true); connection.setDoOutput(true);
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
final JSONArray array = (JSONArray) JSONValue.parse(reader.readLine()); final JsonArray array = new JsonParser().parse(reader).getAsJsonArray();
download = traceURL(((String) ((JSONObject) array.get(array.size() - 1)).get("downloadUrl")).replace("https:", "http:")); final JsonObject json = array.get(array.size() - 1).getAsJsonObject();
file = new File("plugins/" + (String) ((JSONObject) array.get(array.size() - 1)).get("name") + ".jar");
download = traceURL(json.get("downloadUrl").getAsString().replace("https:", "http:"));
file = new File("plugins/" + json.get("name").getAsString() + ".jar");
return true; return true;
} catch (IOException e) { } catch (IOException e) {

View File

@ -234,6 +234,8 @@ public class SlimefunItems {
public static ItemStack ANCIENT_PEDESTAL = new CustomItem(Material.DISPENSER, "&dAncient Pedestal", "", "&5Part of the Ancient Altar"); public static ItemStack ANCIENT_PEDESTAL = new CustomItem(Material.DISPENSER, "&dAncient Pedestal", "", "&5Part of the Ancient Altar");
public static ItemStack ANCIENT_ALTAR = new CustomItem(Material.ENCHANTING_TABLE, "&dAncient Altar", "", "&5Multi-Block Altar for", "&5magical Crafting Processes"); public static ItemStack ANCIENT_ALTAR = new CustomItem(Material.ENCHANTING_TABLE, "&dAncient Altar", "", "&5Multi-Block Altar for", "&5magical Crafting Processes");
public static ItemStack DUCT_TAPE = null; public static ItemStack DUCT_TAPE = null;
public static ItemStack COPPER_WIRE = new CustomItem(Material.STRING, "&6Copper Wire", "", "&6Crucial component in electric modules");
public static ItemStack RAINBOW_WOOL = new CustomItem(Material.WHITE_WOOL, "&5Rainbow Wool", "", "&dCycles through all Colors of the Rainbow!"); public static ItemStack RAINBOW_WOOL = new CustomItem(Material.WHITE_WOOL, "&5Rainbow Wool", "", "&dCycles through all Colors of the Rainbow!");
public static ItemStack RAINBOW_GLASS = new CustomItem(Material.WHITE_STAINED_GLASS, "&5Rainbow Glass", "", "&dCycles through all Colors of the Rainbow!"); public static ItemStack RAINBOW_GLASS = new CustomItem(Material.WHITE_STAINED_GLASS, "&5Rainbow Glass", "", "&dCycles through all Colors of the Rainbow!");
@ -365,7 +367,8 @@ public class SlimefunItems {
public static ItemStack PRESSURE_CHAMBER = new CustomItem(Material.GLASS, "&bPressure Chamber", "", "&a&oCompresses Items even more"); public static ItemStack PRESSURE_CHAMBER = new CustomItem(Material.GLASS, "&bPressure Chamber", "", "&a&oCompresses Items even more");
public static ItemStack MAGIC_WORKBENCH = new CustomItem(Material.CRAFTING_TABLE, "&6Magic Workbench", "Infuses Items with magical Energy"); public static ItemStack MAGIC_WORKBENCH = new CustomItem(Material.CRAFTING_TABLE, "&6Magic Workbench", "Infuses Items with magical Energy");
public static ItemStack ORE_WASHER = new CustomItem(Material.CAULDRON, "&6Ore Washer", "", "&a&oWashes Sifted Ore to filter Ores", "&a&oand gives you small Stone Chunks"); public static ItemStack ORE_WASHER = new CustomItem(Material.CAULDRON, "&6Ore Washer", "", "&a&oWashes Sifted Ore to filter Ores", "&a&oand gives you small Stone Chunks");
public static ItemStack SAW_MILL = new CustomItem(Material.IRON_BARS, "&6Saw Mill", "", "&a&oAllows you to get 8 planks from 1 Log"); public static ItemStack TABLE_SAW = new CustomItem(Material.STONECUTTER, "&6Table Saw", "", "&a&oAllows you get 8 planks from 1 Log", "&a&o(Works with all log types)");
public static ItemStack SAW_MILL = new CustomItem(Material.BARRIER, "&6Saw Mill", "", "&cObsolete! Use the Table Saw instead");
public static ItemStack COMPOSTER = new CustomItem(Material.CAULDRON, "&aComposter", "", "&a&oCan convert various Materials over Time..."); public static ItemStack COMPOSTER = new CustomItem(Material.CAULDRON, "&aComposter", "", "&a&oCan convert various Materials over Time...");
public static ItemStack ENHANCED_CRAFTING_TABLE = new CustomItem(Material.CRAFTING_TABLE, "&eEnhanced Crafting Table", "", "&a&oA regular Crafting Table cannot", "&a&ohold this massive Amount of Power..."); public static ItemStack ENHANCED_CRAFTING_TABLE = new CustomItem(Material.CRAFTING_TABLE, "&eEnhanced Crafting Table", "", "&a&oA regular Crafting Table cannot", "&a&ohold this massive Amount of Power...");
public static ItemStack CRUCIBLE = new CustomItem(Material.CAULDRON, "&cCrucible", "", "&a&oUsed to smelt Items into Liquids"); public static ItemStack CRUCIBLE = new CustomItem(Material.CAULDRON, "&cCrucible", "", "&a&oUsed to smelt Items into Liquids");
@ -376,7 +379,7 @@ public class SlimefunItems {
public static ItemStack DIGITAL_MINER = new CustomItem(Material.IRON_PICKAXE, "&bDigital Miner", "", "&a&oDigs out everything!"); public static ItemStack DIGITAL_MINER = new CustomItem(Material.IRON_PICKAXE, "&bDigital Miner", "", "&a&oDigs out everything!");
public static ItemStack ADVANCED_DIGITAL_MINER = new CustomItem(Material.DIAMOND_PICKAXE, "&6Advanced Digital Miner", "", "&a&oDigs out everything!", "&a&oAutomatically crushes your Ores"); public static ItemStack ADVANCED_DIGITAL_MINER = new CustomItem(Material.DIAMOND_PICKAXE, "&6Advanced Digital Miner", "", "&a&oDigs out everything!", "&a&oAutomatically crushes your Ores");
public static ItemStack AUTOMATED_PANNING_MACHINE = new CustomItem(Material.BOWL, "&aAutomated Panning Machine", "", "&a&oA MultiBlock Version of the Gold Pan"); public static ItemStack AUTOMATED_PANNING_MACHINE = new CustomItem(Material.BOWL, "&aAutomated Panning Machine", "", "&a&oA MultiBlock Version of the Gold Pan");
public static ItemStack OUTPUT_CHEST = new CustomItem(Material.CHEST, "&4Output Chest", "", "&c&oA basic machine will try to put", "&c&oitems in this chest if it's placed", "&c&oadjacent to the dispenser.");
public static ItemStack HOLOGRAM_PROJECTOR = new CustomItem(Material.QUARTZ_SLAB, "&bHologram Projector", "", "&rProjects an Editable Hologram"); public static ItemStack HOLOGRAM_PROJECTOR = new CustomItem(Material.QUARTZ_SLAB, "&bHologram Projector", "", "&rProjects an Editable Hologram");
/* Enhanced Furnaces */ /* Enhanced Furnaces */

View File

@ -2,11 +2,17 @@ package me.mrCookieSlime.Slimefun.Objects.SlimefunItem;
import java.util.*; import java.util.*;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.InvUtils;
import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.MultiBlock; import me.mrCookieSlime.Slimefun.Objects.MultiBlock;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Container;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public class SlimefunMachine extends SlimefunItem { public class SlimefunMachine extends SlimefunItem {
@ -14,6 +20,14 @@ public class SlimefunMachine extends SlimefunItem {
private List<ItemStack[]> recipes; private List<ItemStack[]> recipes;
private List<ItemStack> shownRecipes; private List<ItemStack> shownRecipes;
private Material trigger; private Material trigger;
//Adjacent blockfaces for iterative output chest checks
private static final BlockFace[] outputFaces = {
BlockFace.UP,
BlockFace.NORTH,
BlockFace.EAST,
BlockFace.SOUTH,
BlockFace.WEST
};
public SlimefunMachine(Category category, ItemStack item, String id, ItemStack[] recipe, ItemStack[] machineRecipes, Material trigger) { public SlimefunMachine(Category category, ItemStack item, String id, ItemStack[] recipe, ItemStack[] machineRecipes, Material trigger) {
super(category, item, id, RecipeType.MULTIBLOCK, recipe); super(category, item, id, RecipeType.MULTIBLOCK, recipe);
@ -47,6 +61,10 @@ public class SlimefunMachine extends SlimefunItem {
return this.shownRecipes; return this.shownRecipes;
} }
public static BlockFace[] getOutputFaces() {
return outputFaces;
}
public void addRecipe(ItemStack[] input, ItemStack output) { public void addRecipe(ItemStack[] input, ItemStack output) {
this.recipes.add(input); this.recipes.add(input);
this.recipes.add(new ItemStack[] {output}); this.recipes.add(new ItemStack[] {output});
@ -81,4 +99,34 @@ public class SlimefunMachine extends SlimefunItem {
return this.recipes.iterator(); return this.recipes.iterator();
} }
// Overloaded method for finding a potential output chest. Fallbacks to the old system of putting the adding back into the dispenser.
// Optional last argument Inventory placeCheckerInv is for multiblock machines that create a dummy inventory to check if there's a space for the adding,
// i.e. Enhanced crafting table
public static Inventory findValidOutputInv(ItemStack adding, Block dispBlock, Inventory dispInv) {
return findValidOutputInv(adding, dispBlock, dispInv, dispInv);
}
public static Inventory findValidOutputInv(ItemStack product, Block dispBlock, Inventory dispInv, Inventory placeCheckerInv) {
Inventory outputInv = null;
for (BlockFace face : outputFaces) {
Block potentialOutput = dispBlock.getRelative(face);
String id = BlockStorage.checkID(potentialOutput);
if (id != null && id.equals("OUTPUT_CHEST")) {
// Found the output chest! Now, let's check if we can fit the product in it.
Inventory inv = ((Container) potentialOutput.getState()).getInventory();
if (InvUtils.fits(inv, product)) {
// It fits! Let's set the inventory to that now.
outputInv = inv;
break;
}
}
}
// This if-clause will trigger if no suitable output chest was found. It's functionally the same as the old fit check for the dispenser, only refactored.
if (outputInv == null && InvUtils.fits(placeCheckerInv, product)) outputInv = dispInv;
return outputInv;
}
} }

View File

@ -4,6 +4,8 @@ import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib;
import me.mrCookieSlime.CSCoreLibPlugin.compatibility.MaterialHelper; import me.mrCookieSlime.CSCoreLibPlugin.compatibility.MaterialHelper;
@ -57,7 +59,12 @@ public class AdvancedCargoOutputNode extends SlimefunItem {
} }
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability").equals("false")) { if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability").equals("false")) {
menu.replaceExistingItem(16, new CustomItem(new ItemStack(Material.STONE_SWORD, (byte) 20), "&7Include Sub-IDs/Durability: &4\u2718", "", "&e> Click to toggle whether the Durability has to match")); ItemStack is = new ItemStack(Material.STONE_SWORD);
Damageable dmg = (Damageable) is.getItemMeta();
dmg.setDamage(20);
is.setItemMeta((ItemMeta) dmg);
menu.replaceExistingItem(16, new CustomItem(is, "&7Include Sub-IDs/Durability: &4\u2718", "", "&e> Click to toggle whether the Durability has to match"));
menu.addMenuClickHandler(16, (p, slot, item, action) -> { menu.addMenuClickHandler(16, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-durability", "true"); BlockStorage.addBlockInfo(b, "filter-durability", "true");
newInstance(menu, b); newInstance(menu, b);
@ -65,7 +72,11 @@ public class AdvancedCargoOutputNode extends SlimefunItem {
}); });
} }
else { else {
menu.replaceExistingItem(16, new CustomItem(new ItemStack(Material.GOLDEN_SWORD, (byte) 20), "&7Include Sub-IDs/Durability: &2\u2714", "", "&e> Click to toggle whether the Durability has to match")); ItemStack is = new ItemStack(Material.GOLDEN_SWORD);
Damageable dmg = (Damageable) is.getItemMeta();
dmg.setDamage(20);
is.setItemMeta((ItemMeta) dmg);
menu.replaceExistingItem(16, new CustomItem(is, "&7Include Sub-IDs/Durability: &2\u2714", "", "&e> Click to toggle whether the Durability has to match"));
menu.addMenuClickHandler(16, (p, slot, item, action) -> { menu.addMenuClickHandler(16, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-durability", "false"); BlockStorage.addBlockInfo(b, "filter-durability", "false");
newInstance(menu, b); newInstance(menu, b);

View File

@ -5,6 +5,8 @@ import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem; import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem;
@ -57,7 +59,11 @@ public class CargoInputNode extends SlimefunItem {
} }
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability").equals("false")) { if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-durability").equals("false")) {
menu.replaceExistingItem(16, new CustomItem(new ItemStack(Material.STONE_SWORD, (byte) 20), "&7Include Sub-IDs/Durability: &4\u2718", "", "&e> Click to toggle whether the Durability has to match")); ItemStack is = new ItemStack(Material.STONE_SWORD);
Damageable dmg = (Damageable) is.getItemMeta();
dmg.setDamage(20);
is.setItemMeta((ItemMeta) dmg);
menu.replaceExistingItem(16, new CustomItem(is, "&7Include Sub-IDs/Durability: &4\u2718", "", "&e> Click to toggle whether the Durability has to match"));
menu.addMenuClickHandler(16, (p, slot, item, action) -> { menu.addMenuClickHandler(16, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-durability", "true"); BlockStorage.addBlockInfo(b, "filter-durability", "true");
newInstance(menu, b); newInstance(menu, b);
@ -65,7 +71,11 @@ public class CargoInputNode extends SlimefunItem {
}); });
} }
else { else {
menu.replaceExistingItem(16, new CustomItem(new ItemStack(Material.GOLDEN_SWORD, (byte) 20), "&7Include Sub-IDs/Durability: &2\u2714", "", "&e> Click to toggle whether the Durability has to match")); ItemStack is = new ItemStack(Material.GOLDEN_SWORD);
Damageable dmg = (Damageable) is.getItemMeta();
dmg.setDamage(20);
is.setItemMeta((ItemMeta) dmg);
menu.replaceExistingItem(16, new CustomItem(is, "&7Include Sub-IDs/Durability: &2\u2714", "", "&e> Click to toggle whether the Durability has to match"));
menu.addMenuClickHandler(16, (p, slot, item, action) -> { menu.addMenuClickHandler(16, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-durability", "false"); BlockStorage.addBlockInfo(b, "filter-durability", "false");
newInstance(menu, b); newInstance(menu, b);

View File

@ -10,7 +10,7 @@ import org.bukkit.inventory.ItemStack;
public class ResearchSetup { public class ResearchSetup {
public static void setupResearches() { public static void setupResearches() {
Slimefun.registerResearch(new Research(0, "Walking Sticks", 1), SlimefunItems.GRANDMAS_WALKING_STICK, SlimefunItems.GRANDPAS_WALKING_STICK); Slimefun.registerResearch(new Research(0, "Walking Sticks", 1), SlimefunItems.GRANDMAS_WALKING_STICK, SlimefunItems.GRANDPAS_WALKING_STICK);
Slimefun.registerResearch(new Research(1, "Portable Crafter", 1), SlimefunItems.PORTABLE_CRAFTER); Slimefun.registerResearch(new Research(1, "Portable Crafter", 1), SlimefunItems.PORTABLE_CRAFTER);
Slimefun.registerResearch(new Research(2, "Fortune Cookie", 1), SlimefunItems.FORTUNE_COOKIE); Slimefun.registerResearch(new Research(2, "Fortune Cookie", 1), SlimefunItems.FORTUNE_COOKIE);
Slimefun.registerResearch(new Research(4, "Portable Dustbin", 2), SlimefunItems.PORTABLE_DUSTBIN); Slimefun.registerResearch(new Research(4, "Portable Dustbin", 2), SlimefunItems.PORTABLE_DUSTBIN);
@ -94,7 +94,7 @@ public class ResearchSetup {
Slimefun.registerResearch(new Research(89, "Night Vision Goggles", 10), SlimefunItems.NIGHT_VISION_GOGGLES); Slimefun.registerResearch(new Research(89, "Night Vision Goggles", 10), SlimefunItems.NIGHT_VISION_GOGGLES);
Slimefun.registerResearch(new Research(90, "Pickaxe of Containment", 14), SlimefunItems.PICKAXE_OF_CONTAINMENT, SlimefunItems.BROKEN_SPAWNER); Slimefun.registerResearch(new Research(90, "Pickaxe of Containment", 14), SlimefunItems.PICKAXE_OF_CONTAINMENT, SlimefunItems.BROKEN_SPAWNER);
Slimefun.registerResearch(new Research(91, "Hercules Pickaxe", 28), SlimefunItems.HERCULES_PICKAXE); Slimefun.registerResearch(new Research(91, "Hercules Pickaxe", 28), SlimefunItems.HERCULES_PICKAXE);
Slimefun.registerResearch(new Research(92, "Saw Mill", 2), SlimefunItems.SAW_MILL); Slimefun.registerResearch(new Research(92, "Table Saw", 2), SlimefunItems.SAW_MILL, SlimefunItems.TABLE_SAW);
Slimefun.registerResearch(new Research(93, "Slimy Steel Armor", 27), SlimefunItems.SLIME_HELMET_STEEL, SlimefunItems.SLIME_CHESTPLATE_STEEL, SlimefunItems.SLIME_LEGGINGS_STEEL, SlimefunItems.SLIME_BOOTS_STEEL); Slimefun.registerResearch(new Research(93, "Slimy Steel Armor", 27), SlimefunItems.SLIME_HELMET_STEEL, SlimefunItems.SLIME_CHESTPLATE_STEEL, SlimefunItems.SLIME_LEGGINGS_STEEL, SlimefunItems.SLIME_BOOTS_STEEL);
Slimefun.registerResearch(new Research(94, "Blade of Vampires", 26), SlimefunItems.BLADE_OF_VAMPIRES); Slimefun.registerResearch(new Research(94, "Blade of Vampires", 26), SlimefunItems.BLADE_OF_VAMPIRES);
Slimefun.registerResearch(new Research(95, "Lazy Mining", 40), SlimefunItems.DIGITAL_MINER); Slimefun.registerResearch(new Research(95, "Lazy Mining", 40), SlimefunItems.DIGITAL_MINER);
@ -235,5 +235,7 @@ public class ResearchSetup {
Slimefun.registerResearch(new Research(236, "Nether Star Reactor", 60), SlimefunItems.NETHERSTAR_REACTOR); Slimefun.registerResearch(new Research(236, "Nether Star Reactor", 60), SlimefunItems.NETHERSTAR_REACTOR);
Slimefun.registerResearch(new Research(237, "Blistering Radioactivity", 38), SlimefunItems.BLISTERING_INGOT, SlimefunItems.BLISTERING_INGOT_2, SlimefunItems.BLISTERING_INGOT_3); Slimefun.registerResearch(new Research(237, "Blistering Radioactivity", 38), SlimefunItems.BLISTERING_INGOT, SlimefunItems.BLISTERING_INGOT_2, SlimefunItems.BLISTERING_INGOT_3);
Slimefun.registerResearch(new Research(239, "Automatic Ignition Chamber", 12), SlimefunItems.IGNITION_CHAMBER); Slimefun.registerResearch(new Research(239, "Automatic Ignition Chamber", 12), SlimefunItems.IGNITION_CHAMBER);
Slimefun.registerResearch(new Research(240, "Basic machinery output chest", 20), SlimefunItems.OUTPUT_CHEST);
Slimefun.registerResearch(new Research(241, "Thinned-down Conductivity", 15), SlimefunItems.COPPER_WIRE);
} }
} }

View File

@ -14,6 +14,7 @@ import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.Tag;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.Chest; import org.bukkit.block.Chest;
@ -21,6 +22,7 @@ import org.bukkit.block.CreatureSpawner;
import org.bukkit.block.Dispenser; import org.bukkit.block.Dispenser;
import org.bukkit.block.Hopper; import org.bukkit.block.Hopper;
import org.bukkit.block.data.Ageable; import org.bukkit.block.data.Ageable;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Levelled; import org.bukkit.block.data.Levelled;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
@ -189,6 +191,10 @@ public class SlimefunSetup {
new ItemStack[] {new ItemStack(Material.COOKIE), new ItemStack(Material.PAPER), null, null, null, null, null, null, null}) new ItemStack[] {new ItemStack(Material.COOKIE), new ItemStack(Material.PAPER), null, null, null, null, null, null, null})
.register(true); .register(true);
new SlimefunItem(Categories.MACHINES_1, SlimefunItems.OUTPUT_CHEST, "OUTPUT_CHEST", RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] {SlimefunItems.LEAD_INGOT, new ItemStack(Material.HOPPER), SlimefunItems.LEAD_INGOT, SlimefunItems.LEAD_INGOT, new ItemStack(Material.CHEST), SlimefunItems.LEAD_INGOT, null, SlimefunItems.LEAD_INGOT, null})
.register(true);
new SlimefunMachine(Categories.MACHINES_1, SlimefunItems.ENHANCED_CRAFTING_TABLE, "ENHANCED_CRAFTING_TABLE", new SlimefunMachine(Categories.MACHINES_1, SlimefunItems.ENHANCED_CRAFTING_TABLE, "ENHANCED_CRAFTING_TABLE",
new ItemStack[] {null, null, null, null, new ItemStack(Material.CRAFTING_TABLE), null, null, new ItemStack(Material.DISPENSER), null}, new ItemStack[] {null, null, null, null, new ItemStack(Material.CRAFTING_TABLE), null, null, new ItemStack(Material.DISPENSER), null},
new ItemStack[0], Material.CRAFTING_TABLE) new ItemStack[0], Material.CRAFTING_TABLE)
@ -202,9 +208,13 @@ public class SlimefunSetup {
if (mb.isMultiBlock(machine)) { if (mb.isMultiBlock(machine)) {
if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) { if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) {
if (Slimefun.hasUnlocked(p, machine.getItem(), true)) { if (Slimefun.hasUnlocked(p, machine.getItem(), true)) {
Dispenser disp = (Dispenser) b.getRelative(BlockFace.DOWN).getState(); // Objects dispBlock and disp have been split up, in order to add the output chest functionallity, which is the only functionallity
// that is dependant on the dispenser's block methods.
// the Dispenser disp still remains the same though, and as such doesn't break any existing code which involves said object.
Block dispBlock = b.getRelative(BlockFace.DOWN);
Dispenser disp = (Dispenser) dispBlock.getState();
Inventory inv = disp.getInventory();
final Inventory inv = disp.getInventory();
List<ItemStack[]> inputs = RecipeType.getRecipeInputList(machine); List<ItemStack[]> inputs = RecipeType.getRecipeInputList(machine);
for (int i = 0; i < inputs.size(); i++) { for (int i = 0; i < inputs.size(); i++) {
@ -231,9 +241,11 @@ public class SlimefunSetup {
for (int j = 0; j < inv.getContents().length; j++) { for (int j = 0; j < inv.getContents().length; j++) {
inv2.setItem(j, inv.getContents()[j] != null ? (inv.getContents()[j].getAmount() > 1 ? new CustomItem(inv.getContents()[j], inv.getContents()[j].getAmount() - 1): null): null); inv2.setItem(j, inv.getContents()[j] != null ? (inv.getContents()[j].getAmount() > 1 ? new CustomItem(inv.getContents()[j], inv.getContents()[j].getAmount() - 1): null): null);
} }
if (InvUtils.fits(inv2, adding)) {
SlimefunItem sfItem = SlimefunItem.getByItem(adding);
Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv, inv2);
if (outputInv != null) {
SlimefunItem sfItem = SlimefunItem.getByItem(adding);
if (sfItem instanceof SlimefunBackpack) { if (sfItem instanceof SlimefunBackpack) {
ItemStack backpack = null; ItemStack backpack = null;
@ -300,7 +312,8 @@ public class SlimefunSetup {
} }
p.getWorld().playSound(b.getLocation(), Sound.BLOCK_WOODEN_BUTTON_CLICK_ON, 1, 1); p.getWorld().playSound(b.getLocation(), Sound.BLOCK_WOODEN_BUTTON_CLICK_ON, 1, 1);
inv.addItem(adding); outputInv.addItem(adding);
} }
else Messages.local.sendTranslation(p, "machines.full-inventory", true); else Messages.local.sendTranslation(p, "machines.full-inventory", true);
} }
@ -338,7 +351,7 @@ public class SlimefunSetup {
new SlimefunMachine(Categories.MACHINES_1, SlimefunItems.GRIND_STONE, "GRIND_STONE", new SlimefunMachine(Categories.MACHINES_1, SlimefunItems.GRIND_STONE, "GRIND_STONE",
new ItemStack[] {null, null, null, null, new ItemStack(Material.OAK_FENCE), null, null, new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), null}, new ItemStack[] {null, null, null, null, new ItemStack(Material.OAK_FENCE), null, null, new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), null},
new ItemStack[] {new ItemStack(Material.BLAZE_ROD), new ItemStack(Material.BLAZE_POWDER, 4), new ItemStack(Material.BONE), new ItemStack(Material.BONE_MEAL, 4), new ItemStack(Material.GRAVEL), new ItemStack(Material.FLINT), new ItemStack(Material.NETHER_WART), new CustomItem(SlimefunItems.MAGIC_LUMP_1, 2), new ItemStack(Material.ENDER_EYE), new CustomItem(SlimefunItems.ENDER_LUMP_1, 2), new ItemStack(Material.COBBLESTONE), new ItemStack(Material.GRAVEL), new ItemStack(Material.WHEAT), SlimefunItems.WHEAT_FLOUR, new ItemStack(Material.DIRT), SlimefunItems.STONE_CHUNK}, new ItemStack[] {new ItemStack(Material.BLAZE_ROD), new ItemStack(Material.BLAZE_POWDER, 4), new ItemStack(Material.BONE), new ItemStack(Material.BONE_MEAL, 4), new ItemStack(Material.GRAVEL), new ItemStack(Material.FLINT), new ItemStack(Material.NETHER_WART), new CustomItem(SlimefunItems.MAGIC_LUMP_1, 2), new ItemStack(Material.ENDER_EYE), new CustomItem(SlimefunItems.ENDER_LUMP_1, 2), new ItemStack(Material.COBBLESTONE), new ItemStack(Material.GRAVEL), new ItemStack(Material.WHEAT), SlimefunItems.WHEAT_FLOUR, new ItemStack(Material.DIRT), SlimefunItems.STONE_CHUNK, new ItemStack(Material.SANDSTONE), new ItemStack(Material.SAND, 4), new ItemStack(Material.RED_SANDSTONE), new ItemStack(Material.RED_SAND, 4)},
Material.OAK_FENCE) Material.OAK_FENCE)
.register(true, new MultiBlockInteractionHandler() { .register(true, new MultiBlockInteractionHandler() {
@ -350,17 +363,19 @@ public class SlimefunSetup {
if (mb.isMultiBlock(machine)) { if (mb.isMultiBlock(machine)) {
if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) { if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) {
if (Slimefun.hasUnlocked(p, machine.getItem(), true)) { if (Slimefun.hasUnlocked(p, machine.getItem(), true)) {
Dispenser disp = (Dispenser) b.getRelative(BlockFace.DOWN).getState(); Block dispBlock = b.getRelative(BlockFace.DOWN);
Dispenser disp = (Dispenser) dispBlock.getState();
Inventory inv = disp.getInventory(); Inventory inv = disp.getInventory();
for (ItemStack current: inv.getContents()) { for (ItemStack current: inv.getContents()) {
for (ItemStack convert: RecipeType.getRecipeInputs(machine)) { for (ItemStack convert: RecipeType.getRecipeInputs(machine)) {
if (convert != null && SlimefunManager.isItemSimiliar(current, convert, true)) { if (convert != null && SlimefunManager.isItemSimiliar(current, convert, true)) {
ItemStack output = RecipeType.getRecipeOutput(machine, convert); ItemStack output = RecipeType.getRecipeOutput(machine, convert);
if (InvUtils.fits(inv, output)) { Inventory outputInv = SlimefunMachine.findValidOutputInv(output, dispBlock, inv);
if (outputInv != null) {
ItemStack removing = current.clone(); ItemStack removing = current.clone();
removing.setAmount(1); removing.setAmount(1);
inv.removeItem(removing); inv.removeItem(removing);
inv.addItem(output); outputInv.addItem(output);
p.getWorld().playSound(p.getLocation(), Sound.BLOCK_WOODEN_BUTTON_CLICK_ON, 1, 1); p.getWorld().playSound(p.getLocation(), Sound.BLOCK_WOODEN_BUTTON_CLICK_ON, 1, 1);
} }
else Messages.local.sendTranslation(p, "machines.full-inventory", true); else Messages.local.sendTranslation(p, "machines.full-inventory", true);
@ -391,8 +406,9 @@ public class SlimefunSetup {
if (mb.isMultiBlock(machine)) { if (mb.isMultiBlock(machine)) {
if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) { if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) {
if (Slimefun.hasUnlocked(p, machine.getItem(), true)) { if (Slimefun.hasUnlocked(p, machine.getItem(), true)) {
Dispenser disp = (Dispenser) b.getRelative(BlockFace.DOWN).getState(); Block dispBlock = b.getRelative(BlockFace.DOWN);
final Inventory inv = disp.getInventory(); Dispenser disp = (Dispenser) dispBlock.getState();
Inventory inv = disp.getInventory();
List<ItemStack[]> inputs = RecipeType.getRecipeInputList(machine); List<ItemStack[]> inputs = RecipeType.getRecipeInputList(machine);
for (int i = 0; i < inputs.size(); i++) { for (int i = 0; i < inputs.size(); i++) {
@ -407,7 +423,8 @@ public class SlimefunSetup {
if (craft) { if (craft) {
final ItemStack adding = RecipeType.getRecipeOutputList(machine, inputs.get(i)).clone(); final ItemStack adding = RecipeType.getRecipeOutputList(machine, inputs.get(i)).clone();
if (Slimefun.hasUnlocked(p, adding, true)) { if (Slimefun.hasUnlocked(p, adding, true)) {
if (InvUtils.fits(inv, adding)) { Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv);
if (outputInv != null) {
for (ItemStack removing: inputs.get(i)) { for (ItemStack removing: inputs.get(i)) {
if (removing != null) inv.removeItem(removing); if (removing != null) inv.removeItem(removing);
} }
@ -418,7 +435,7 @@ public class SlimefunSetup {
p.getWorld().playSound(p.getLocation(), Sound.BLOCK_ANVIL_USE, 1F, 2F); p.getWorld().playSound(p.getLocation(), Sound.BLOCK_ANVIL_USE, 1F, 2F);
} else { } else {
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1F, 1F); p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1F, 1F);
inv.addItem(adding); outputInv.addItem(adding);
} }
}, j*20L); }, j*20L);
} }
@ -451,17 +468,19 @@ public class SlimefunSetup {
if (mb.isMultiBlock(machine)) { if (mb.isMultiBlock(machine)) {
if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) { if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) {
if (Slimefun.hasUnlocked(p, machine.getItem(), true)) { if (Slimefun.hasUnlocked(p, machine.getItem(), true)) {
Dispenser disp = (Dispenser) b.getRelative(BlockFace.DOWN).getState(); Block dispBlock = b.getRelative(BlockFace.DOWN);
Dispenser disp = (Dispenser) dispBlock.getState();
Inventory inv = disp.getInventory(); Inventory inv = disp.getInventory();
for (ItemStack current: inv.getContents()) { for (ItemStack current: inv.getContents()) {
for (ItemStack convert: RecipeType.getRecipeInputs(machine)) { for (ItemStack convert: RecipeType.getRecipeInputs(machine)) {
if (convert != null && SlimefunManager.isItemSimiliar(current, convert, true)) { if (convert != null && SlimefunManager.isItemSimiliar(current, convert, true)) {
ItemStack adding = RecipeType.getRecipeOutput(machine, convert); ItemStack adding = RecipeType.getRecipeOutput(machine, convert);
if (InvUtils.fits(inv, adding)) { Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv);
if (outputInv != null) {
ItemStack removing = current.clone(); ItemStack removing = current.clone();
removing.setAmount(convert.getAmount()); removing.setAmount(convert.getAmount());
inv.removeItem(removing); inv.removeItem(removing);
inv.addItem(adding); outputInv.addItem(adding);
p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, 1); p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, 1);
} }
else Messages.local.sendTranslation(p, "machines.full-inventory", true); else Messages.local.sendTranslation(p, "machines.full-inventory", true);
@ -492,13 +511,15 @@ public class SlimefunSetup {
if (mb.isMultiBlock(machine)) { if (mb.isMultiBlock(machine)) {
if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) { if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) {
if (Slimefun.hasUnlocked(p, machine.getItem(), true)) { if (Slimefun.hasUnlocked(p, machine.getItem(), true)) {
Dispenser disp = (Dispenser) b.getRelative(BlockFace.DOWN).getState(); Block dispBlock = b.getRelative(BlockFace.DOWN);
final Inventory inv = disp.getInventory(); Dispenser disp = (Dispenser) dispBlock.getState();
Inventory inv = disp.getInventory();
for (ItemStack current: inv.getContents()) { for (ItemStack current: inv.getContents()) {
for (ItemStack convert: RecipeType.getRecipeInputs(machine)) { for (ItemStack convert: RecipeType.getRecipeInputs(machine)) {
if (convert != null && SlimefunManager.isItemSimiliar(current, convert, true)) { if (convert != null && SlimefunManager.isItemSimiliar(current, convert, true)) {
final ItemStack adding = RecipeType.getRecipeOutput(machine, convert); final ItemStack adding = RecipeType.getRecipeOutput(machine, convert);
if (InvUtils.fits(inv, adding)) { Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv);
if (outputInv != null) {
ItemStack removing = current.clone(); ItemStack removing = current.clone();
removing.setAmount(convert.getAmount()); removing.setAmount(convert.getAmount());
inv.removeItem(removing); inv.removeItem(removing);
@ -509,7 +530,7 @@ public class SlimefunSetup {
p.getWorld().playSound(p.getLocation(), j == 1 ? Sound.BLOCK_PISTON_CONTRACT : Sound.BLOCK_PISTON_EXTEND, 1F, j == 0 ? 1F : 2F); p.getWorld().playSound(p.getLocation(), j == 1 ? Sound.BLOCK_PISTON_CONTRACT : Sound.BLOCK_PISTON_EXTEND, 1F, j == 0 ? 1F : 2F);
} else { } else {
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1F, 1F); p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1F, 1F);
inv.addItem(adding); outputInv.addItem(adding);
} }
}, i*20L); }, i*20L);
} }
@ -709,7 +730,8 @@ public class SlimefunSetup {
if (mb.isMultiBlock(machine)) { if (mb.isMultiBlock(machine)) {
if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) { if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) {
if (Slimefun.hasUnlocked(p, machine.getItem(), true)) { if (Slimefun.hasUnlocked(p, machine.getItem(), true)) {
Dispenser disp = (Dispenser) b.getRelative(BlockFace.DOWN).getState(); Block dispBlock = b.getRelative(BlockFace.DOWN);
Dispenser disp = (Dispenser) dispBlock.getState();
Inventory inv = disp.getInventory(); Inventory inv = disp.getInventory();
List<ItemStack[]> inputs = RecipeType.getRecipeInputList(machine); List<ItemStack[]> inputs = RecipeType.getRecipeInputList(machine);
@ -730,23 +752,27 @@ public class SlimefunSetup {
if (craft) { if (craft) {
ItemStack adding = RecipeType.getRecipeOutputList(machine, inputs.get(i)).clone(); ItemStack adding = RecipeType.getRecipeOutputList(machine, inputs.get(i)).clone();
if (Slimefun.hasUnlocked(p, adding, true)) { if (Slimefun.hasUnlocked(p, adding, true)) {
if (InvUtils.fits(inv, adding)) { Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv);
if (outputInv != null) {
for (ItemStack removing: inputs.get(i)) { for (ItemStack removing: inputs.get(i)) {
if (removing != null) inv.removeItem(removing); if (removing != null) inv.removeItem(removing);
} }
inv.addItem(adding); outputInv.addItem(adding);
p.getWorld().playSound(p.getLocation(), Sound.BLOCK_LAVA_POP, 1, 1); p.getWorld().playSound(p.getLocation(), Sound.BLOCK_LAVA_POP, 1, 1);
p.getWorld().playEffect(b.getLocation(), Effect.MOBSPAWNER_FLAMES, 1); p.getWorld().playEffect(b.getLocation(), Effect.MOBSPAWNER_FLAMES, 1);
Block raw_disp = b.getRelative(BlockFace.DOWN); // Block raw_disp = b.getRelative(BlockFace.DOWN);
// raw_disp has been removed since the outputInv functionality already uses such an object which is declared above as dispBlock.
// The chamber methods have been updated to reflect this change.
// Maybe this code snippet should be turned into a loop?
Hopper chamber = null; Hopper chamber = null;
if (BlockStorage.check(raw_disp.getRelative(BlockFace.EAST).getState().getBlock(), "IGNITION_CHAMBER")) { if (BlockStorage.check(dispBlock.getRelative(BlockFace.EAST).getState().getBlock(), "IGNITION_CHAMBER")) {
chamber = (Hopper) raw_disp.getRelative(BlockFace.EAST).getState(); chamber = (Hopper) dispBlock.getRelative(BlockFace.EAST).getState();
} else if (BlockStorage.check(raw_disp.getRelative(BlockFace.WEST).getState().getBlock(), "IGNITION_CHAMBER")) { } else if (BlockStorage.check(dispBlock.getRelative(BlockFace.WEST).getState().getBlock(), "IGNITION_CHAMBER")) {
chamber = (Hopper) raw_disp.getRelative(BlockFace.WEST).getState(); chamber = (Hopper) dispBlock.getRelative(BlockFace.WEST).getState();
} else if (BlockStorage.check(raw_disp.getRelative(BlockFace.NORTH).getState().getBlock(), "IGNITION_CHAMBER")) { } else if (BlockStorage.check(dispBlock.getRelative(BlockFace.NORTH).getState().getBlock(), "IGNITION_CHAMBER")) {
chamber = (Hopper) raw_disp.getRelative(BlockFace.NORTH).getState(); chamber = (Hopper) dispBlock.getRelative(BlockFace.NORTH).getState();
} else if (BlockStorage.check(raw_disp.getRelative(BlockFace.SOUTH).getState().getBlock(), "IGNITION_CHAMBER")){ } else if (BlockStorage.check(dispBlock.getRelative(BlockFace.SOUTH).getState().getBlock(), "IGNITION_CHAMBER")){
chamber = (Hopper) raw_disp.getRelative(BlockFace.SOUTH).getState(); chamber = (Hopper) dispBlock.getRelative(BlockFace.SOUTH).getState();
} }
if (SlimefunStartup.chance(100, (Integer) Slimefun.getItemValue("SMELTERY", "chance.fireBreak"))) { if (SlimefunStartup.chance(100, (Integer) Slimefun.getItemValue("SMELTERY", "chance.fireBreak"))) {
@ -810,13 +836,15 @@ public class SlimefunSetup {
if (mb.isMultiBlock(machine)) { if (mb.isMultiBlock(machine)) {
if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) { if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) {
if (Slimefun.hasUnlocked(p, machine.getItem(), true)) { if (Slimefun.hasUnlocked(p, machine.getItem(), true)) {
Dispenser disp = (Dispenser) b.getRelative(BlockFace.UP).getRelative(BlockFace.UP).getState(); Block dispBlock = b.getRelative(BlockFace.UP).getRelative(BlockFace.UP);
Dispenser disp = (Dispenser) dispBlock.getState();
final Inventory inv = disp.getInventory(); final Inventory inv = disp.getInventory();
for (ItemStack current: inv.getContents()) { for (ItemStack current: inv.getContents()) {
for (ItemStack convert: RecipeType.getRecipeInputs(machine)) { for (ItemStack convert: RecipeType.getRecipeInputs(machine)) {
if (convert != null && SlimefunManager.isItemSimiliar(current, convert, true)) { if (convert != null && SlimefunManager.isItemSimiliar(current, convert, true)) {
final ItemStack adding = RecipeType.getRecipeOutput(machine, convert); final ItemStack adding = RecipeType.getRecipeOutput(machine, convert);
if (InvUtils.fits(inv, adding)) { Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv);
if (outputInv != null) {
ItemStack removing = current.clone(); ItemStack removing = current.clone();
removing.setAmount(convert.getAmount()); removing.setAmount(convert.getAmount());
inv.removeItem(removing); inv.removeItem(removing);
@ -831,7 +859,7 @@ public class SlimefunSetup {
p.getWorld().playSound(b.getLocation(), Sound.ENTITY_TNT_PRIMED, 1F, 1F); p.getWorld().playSound(b.getLocation(), Sound.ENTITY_TNT_PRIMED, 1F, 1F);
} else { } else {
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1F, 1F); p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1F, 1F);
inv.addItem(adding); outputInv.addItem(adding);
} }
}, i*20L); }, i*20L);
} }
@ -1130,13 +1158,14 @@ public class SlimefunSetup {
if (mb.isMultiBlock(machine)) { if (mb.isMultiBlock(machine)) {
if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) { if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) {
if (Slimefun.hasUnlocked(p, machine.getItem(), true)) { if (Slimefun.hasUnlocked(p, machine.getItem(), true)) {
Dispenser disp = null; Block dispBlock = null;
// Maybe this could be implemented by instead looping over a BlockFace<> array?
if (b.getRelative(1, 0, 0).getType() == Material.DISPENSER) disp = (Dispenser) b.getRelative(1, 0, 0).getState(); if (b.getRelative(1, 0, 0).getType() == Material.DISPENSER) dispBlock = b.getRelative(1, 0, 0);
else if (b.getRelative(0, 0, 1).getType() == Material.DISPENSER) disp = (Dispenser) b.getRelative(0, 0, 1).getState(); else if (b.getRelative(0, 0, 1).getType() == Material.DISPENSER) dispBlock = b.getRelative(0, 0, 1);
else if (b.getRelative(-1, 0, 0).getType() == Material.DISPENSER) disp = (Dispenser) b.getRelative(-1, 0, 0).getState(); else if (b.getRelative(-1, 0, 0).getType() == Material.DISPENSER) dispBlock = b.getRelative(-1, 0, 0);
else if (b.getRelative(0, 0, -1).getType() == Material.DISPENSER) disp = (Dispenser) b.getRelative(0, 0, -1).getState(); else if (b.getRelative(0, 0, -1).getType() == Material.DISPENSER) dispBlock = b.getRelative(0, 0, -1);
Dispenser disp = (Dispenser) dispBlock.getState();
final Inventory inv = disp.getInventory(); final Inventory inv = disp.getInventory();
List<ItemStack[]> inputs = RecipeType.getRecipeInputList(machine); List<ItemStack[]> inputs = RecipeType.getRecipeInputList(machine);
@ -1164,7 +1193,8 @@ public class SlimefunSetup {
for (int j = 0; j < inv.getContents().length; j++) { for (int j = 0; j < inv.getContents().length; j++) {
inv2.setItem(j, inv.getContents()[j] != null ? (inv.getContents()[j].getAmount() > 1 ? new CustomItem(inv.getContents()[j], inv.getContents()[j].getAmount() - 1): null): null); inv2.setItem(j, inv.getContents()[j] != null ? (inv.getContents()[j].getAmount() > 1 ? new CustomItem(inv.getContents()[j], inv.getContents()[j].getAmount() - 1): null): null);
} }
if (InvUtils.fits(inv2, adding)) { Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv, inv2);
if (outputInv != null) {
SlimefunItem sfItem = SlimefunItem.getByItem(adding); SlimefunItem sfItem = SlimefunItem.getByItem(adding);
if (sfItem instanceof SlimefunBackpack) { if (sfItem instanceof SlimefunBackpack) {
@ -1238,7 +1268,7 @@ public class SlimefunSetup {
p.getWorld().playSound(b.getLocation(), Sound.BLOCK_WOODEN_BUTTON_CLICK_ON, 1F, 1F); p.getWorld().playSound(b.getLocation(), Sound.BLOCK_WOODEN_BUTTON_CLICK_ON, 1F, 1F);
} else { } else {
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1F, 1F); p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1F, 1F);
inv.addItem(adding); outputInv.addItem(adding);
} }
}, j*20L); }, j*20L);
} }
@ -1352,7 +1382,8 @@ public class SlimefunSetup {
if (mb.isMultiBlock(machine)) { if (mb.isMultiBlock(machine)) {
if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) { if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) {
if (Slimefun.hasUnlocked(p, machine.getItem(), true)) { if (Slimefun.hasUnlocked(p, machine.getItem(), true)) {
Dispenser disp = (Dispenser) b.getRelative(BlockFace.UP).getState(); Block dispBlock = b.getRelative(BlockFace.UP);
Dispenser disp = (Dispenser) dispBlock.getState();
Inventory inv = disp.getInventory(); Inventory inv = disp.getInventory();
for (ItemStack current: inv.getContents()) { for (ItemStack current: inv.getContents()) {
if (current != null) { if (current != null) {
@ -1367,25 +1398,37 @@ public class SlimefunSetup {
else if (SlimefunStartup.chance(100, 25)) adding = SlimefunItems.LEAD_DUST; else if (SlimefunStartup.chance(100, 25)) adding = SlimefunItems.LEAD_DUST;
else if (SlimefunStartup.chance(100, 25)) adding = SlimefunItems.SILVER_DUST; else if (SlimefunStartup.chance(100, 25)) adding = SlimefunItems.SILVER_DUST;
if (inv.firstEmpty() != -1 || (legacy_ore_washer && InvUtils.fits(inv, adding))) { Inventory outputInv = null;
if (!legacy_ore_washer) {
// This is a fancy way of checking if there is empty space in the inv; by checking if an unobtainable item could fit in it.
// However, due to the way the method findValidOutputInv() functions, the dummyAdding will never actually be added to the real inventory,
// so it really doesn't matter what item the ItemStack is made by. SlimefunItems.DEBUG_FISH however, signals that it's
// not supposed to be given to the player.
ItemStack dummyAdding = SlimefunItems.DEBUG_FISH;
outputInv = SlimefunMachine.findValidOutputInv(dummyAdding, dispBlock, inv);
} else outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv);
if (outputInv != null) {
ItemStack removing = current.clone(); ItemStack removing = current.clone();
removing.setAmount(1); removing.setAmount(1);
inv.removeItem(removing); inv.removeItem(removing);
inv.addItem(adding); outputInv.addItem(adding);
p.getWorld().playSound(b.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1, 1); p.getWorld().playSound(b.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1, 1);
p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.WATER); p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.WATER);
if (InvUtils.fits(inv, SlimefunItems.STONE_CHUNK)) inv.addItem(SlimefunItems.STONE_CHUNK); if (InvUtils.fits(outputInv, SlimefunItems.STONE_CHUNK)) outputInv.addItem(SlimefunItems.STONE_CHUNK);
} }
else Messages.local.sendTranslation(p, "machines.full-inventory", true); else Messages.local.sendTranslation(p, "machines.full-inventory", true);
return true; return true;
} }
else if (SlimefunManager.isItemSimiliar(current, new ItemStack(Material.SAND, 4), false)) { else if (SlimefunManager.isItemSimiliar(current, new ItemStack(Material.SAND, 4), false)) {
ItemStack adding = SlimefunItems.SALT; ItemStack adding = SlimefunItems.SALT;
if (InvUtils.fits(inv, adding)) { Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv);
if (outputInv != null) {
ItemStack removing = current.clone(); ItemStack removing = current.clone();
removing.setAmount(4); removing.setAmount(4);
inv.removeItem(removing); inv.removeItem(removing);
inv.addItem(adding); outputInv.addItem(adding);
p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.WATER); p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.WATER);
p.getWorld().playSound(b.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1, 1); p.getWorld().playSound(b.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1, 1);
} }
@ -1394,11 +1437,12 @@ public class SlimefunSetup {
} }
else if (SlimefunManager.isItemSimiliar(current, SlimefunItems.PULVERIZED_ORE, true)) { else if (SlimefunManager.isItemSimiliar(current, SlimefunItems.PULVERIZED_ORE, true)) {
ItemStack adding = SlimefunItems.PURE_ORE_CLUSTER; ItemStack adding = SlimefunItems.PURE_ORE_CLUSTER;
if (InvUtils.fits(inv, adding)) { Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv);
if (outputInv != null) {
ItemStack removing = current.clone(); ItemStack removing = current.clone();
removing.setAmount(1); removing.setAmount(1);
inv.removeItem(removing); inv.removeItem(removing);
inv.addItem(adding); outputInv.addItem(adding);
p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.WATER); p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.WATER);
p.getWorld().playSound(b.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1, 1); p.getWorld().playSound(b.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1, 1);
} }
@ -1794,17 +1838,18 @@ public class SlimefunSetup {
@Override @Override
public boolean onBlockBreak(BlockBreakEvent e, ItemStack item, int fortune, List<ItemStack> drops) { public boolean onBlockBreak(BlockBreakEvent e, ItemStack item, int fortune, List<ItemStack> drops) {
if (SlimefunManager.isItemSimiliar(item, SlimefunItems.PICKAXE_OF_CONTAINMENT, true)) { if (SlimefunManager.isItemSimiliar(item, SlimefunItems.PICKAXE_OF_CONTAINMENT, true)) {
if (e.getBlock().getType() != Material.SPAWNER) return true; Block b = e.getBlock(); // Refactored it into this so we don't need to call e.getBlock() all the time.
BlockStorage.clearBlockInfo(e.getBlock()); if (b.getType() != Material.SPAWNER || BlockStorage.hasBlockInfo(b)) return true;
// If the spawner's BlockStorage has BlockInfo, then it's not a vanilla spawner and shouldn't give a broken spawner.
ItemStack spawner = SlimefunItems.BROKEN_SPAWNER.clone(); ItemStack spawner = SlimefunItems.BROKEN_SPAWNER.clone();
ItemMeta im = spawner.getItemMeta(); ItemMeta im = spawner.getItemMeta();
List<String> lore = im.getLore(); List<String> lore = im.getLore();
for (int i = 0; i < lore.size(); i++) { for (int i = 0; i < lore.size(); i++) {
if (lore.get(i).contains("<Type>")) lore.set(i, lore.get(i).replace("<Type>", StringUtils.format(((CreatureSpawner) e.getBlock().getState()).getSpawnedType().toString()))); if (lore.get(i).contains("<Type>")) lore.set(i, lore.get(i).replace("<Type>", StringUtils.format(((CreatureSpawner) b.getState()).getSpawnedType().toString())));
} }
im.setLore(lore); im.setLore(lore);
spawner.setItemMeta(im); spawner.setItemMeta(im);
e.getBlock().getLocation().getWorld().dropItemNaturally(e.getBlock().getLocation(), spawner); b.getLocation().getWorld().dropItemNaturally(b.getLocation(), spawner);
e.setExpToDrop(0); e.setExpToDrop(0);
return true; return true;
} }
@ -1832,6 +1877,44 @@ public class SlimefunSetup {
} }
}); });
new SlimefunMachine(Categories.MACHINES_1, SlimefunItems.TABLE_SAW, "TABLE_SAW",
new ItemStack[] {null, null, null, new ItemStack(Material.STONE_SLAB), new ItemStack(Material.STONECUTTER), new ItemStack(Material.STONE_SLAB), null, new ItemStack(Material.IRON_BLOCK), null},
new ItemStack[] {}, Material.STONECUTTER)
.register(true, new MultiBlockInteractionHandler() {
@Override
public boolean onInteract(Player p, MultiBlock mb, Block b) {
if (mb.isMultiBlock(SlimefunItem.getByID("TABLE_SAW"))) {
if (CSCoreLib.getLib().getProtectionManager().canBuild(p.getUniqueId(), b.getRelative(BlockFace.UP), true)) {
if (Slimefun.hasUnlocked(p, SlimefunItems.TABLE_SAW, true)) {
if(p.getInventory().getItemInMainHand() != null && Tag.LOGS.getValues().contains(p.getInventory().getItemInMainHand().getType())) {
ItemStack log = p.getInventory().getItemInMainHand();
ItemStack item = new ItemStack(MaterialHelper.getWoodFromLog(log.getType()), 8);
b.getWorld().dropItemNaturally(b.getLocation(), item);
b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, log.getType());
log.setAmount(log.getAmount() -1);
if(log.getAmount() <= 0)
p.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
}
}
}
return true;
}
else return false;
}
});
/*
* dNiym 7/30/2019 added the Table_Saw machine to replace the Saw_mill, as the sawmill's design does not work with
* the new types of log's in minecraft. Now that there are multiple types with their own object ID the existing
* way of detecting multi blocks limits us to using specific material types in a build, therefore having a block that
* needs to change like for the sawmill is not possible to do without major overhauling of multiblocks. The Saw_Mill
* machine has been left in as to not break machines on existing servers however it should no longer show up in the
* slimefun guide.
*/
new SlimefunMachine(Categories.MACHINES_1, SlimefunItems.SAW_MILL, "SAW_MILL", new SlimefunMachine(Categories.MACHINES_1, SlimefunItems.SAW_MILL, "SAW_MILL",
new ItemStack[] {null, null, null, new ItemStack(Material.IRON_BARS), new ItemStack(Material.OAK_LOG), new ItemStack(Material.IRON_BARS), new ItemStack(Material.OAK_LOG), new ItemStack(Material.CRAFTING_TABLE), new ItemStack(Material.OAK_LOG)}, new ItemStack[] {null, null, null, new ItemStack(Material.IRON_BARS), new ItemStack(Material.OAK_LOG), new ItemStack(Material.IRON_BARS), new ItemStack(Material.OAK_LOG), new ItemStack(Material.CRAFTING_TABLE), new ItemStack(Material.OAK_LOG)},
new ItemStack[] {}, Material.CRAFTING_TABLE) new ItemStack[] {}, Material.CRAFTING_TABLE)
@ -2535,17 +2618,19 @@ public class SlimefunSetup {
if (mb.isMultiBlock(machine)) { if (mb.isMultiBlock(machine)) {
if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) { if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) {
if (Slimefun.hasUnlocked(p, SlimefunItems.JUICER, true)) { if (Slimefun.hasUnlocked(p, SlimefunItems.JUICER, true)) {
Dispenser disp = (Dispenser) b.getRelative(BlockFace.DOWN).getState(); Block dispBlock = b.getRelative(BlockFace.DOWN);
Dispenser disp = (Dispenser) dispBlock.getState();
Inventory inv = disp.getInventory(); Inventory inv = disp.getInventory();
for (ItemStack current: inv.getContents()) { for (ItemStack current: inv.getContents()) {
for (ItemStack convert: RecipeType.getRecipeInputs(machine)) { for (ItemStack convert: RecipeType.getRecipeInputs(machine)) {
if (convert != null && SlimefunManager.isItemSimiliar(current, convert, true)) { if (convert != null && SlimefunManager.isItemSimiliar(current, convert, true)) {
ItemStack adding = RecipeType.getRecipeOutput(machine, convert); ItemStack adding = RecipeType.getRecipeOutput(machine, convert);
if (InvUtils.fits(inv, adding)) { Inventory outputInv = SlimefunMachine.findValidOutputInv(adding, dispBlock, inv);
if (outputInv != null) {
ItemStack removing = current.clone(); ItemStack removing = current.clone();
removing.setAmount(1); removing.setAmount(1);
inv.removeItem(removing); inv.removeItem(removing);
inv.addItem(adding); outputInv.addItem(adding);
p.getWorld().playSound(b.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1F, 1F); p.getWorld().playSound(b.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1F, 1F);
p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.HAY_BLOCK); p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.HAY_BLOCK);
} }
@ -2679,13 +2764,18 @@ public class SlimefunSetup {
.register(true); .register(true);
new SlimefunItem(Categories.TECH_MISC, SlimefunItems.ELECTRIC_MOTOR, "ELECTRIC_MOTOR", RecipeType.ENHANCED_CRAFTING_TABLE, new SlimefunItem(Categories.TECH_MISC, SlimefunItems.ELECTRIC_MOTOR, "ELECTRIC_MOTOR", RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] {SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, null, SlimefunItems.ELECTRO_MAGNET, null, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT}) new ItemStack[] {SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, null, SlimefunItems.ELECTRO_MAGNET, null, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE})
.register(true); .register(true);
new SlimefunItem(Categories.TECH_MISC, SlimefunItems.HEATING_COIL, "HEATING_COIL", RecipeType.ENHANCED_CRAFTING_TABLE, new SlimefunItem(Categories.TECH_MISC, SlimefunItems.HEATING_COIL, "HEATING_COIL", RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] {SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, SlimefunItems.ELECTRIC_MOTOR, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT}) new ItemStack[] {SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.ELECTRIC_MOTOR, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE})
.register(true); .register(true);
new SlimefunItem(Categories.TECH_MISC, SlimefunItems.COPPER_WIRE, "COPPER_WIRE", RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] {null, null, null, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, null, null, null}, new CustomItem(SlimefunItems.COPPER_WIRE, 8))
.register(true);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
final String[] blockPlacerBlacklist = Slimefun.getItemValue("BLOCK_PLACER", "unplaceable-blocks") != null ? ((List<String>) Slimefun.getItemValue("BLOCK_PLACER", "unplaceable-blocks")).toArray(new String[((List<String>) Slimefun.getItemValue("BLOCK_PLACER", "unplaceable-blocks")).size()]) : new String[] {"STRUCTURE_BLOCK"}; final String[] blockPlacerBlacklist = Slimefun.getItemValue("BLOCK_PLACER", "unplaceable-blocks") != null ? ((List<String>) Slimefun.getItemValue("BLOCK_PLACER", "unplaceable-blocks")).toArray(new String[((List<String>) Slimefun.getItemValue("BLOCK_PLACER", "unplaceable-blocks")).size()]) : new String[] {"STRUCTURE_BLOCK"};
@ -3611,30 +3701,30 @@ public class SlimefunSetup {
registerFuel(new MachineFuel(3, new ItemStack(Material.POTATO))); registerFuel(new MachineFuel(3, new ItemStack(Material.POTATO)));
registerFuel(new MachineFuel(3, new ItemStack(Material.SUGAR_CANE))); registerFuel(new MachineFuel(3, new ItemStack(Material.SUGAR_CANE)));
registerFuel(new MachineFuel(3, new ItemStack(Material.NETHER_WART))); registerFuel(new MachineFuel(3, new ItemStack(Material.NETHER_WART)));
registerFuel(new MachineFuel(2, new ItemStack(Material.DANDELION)));
registerFuel(new MachineFuel(2, new ItemStack(Material.POPPY)));
registerFuel(new MachineFuel(2, new ItemStack(Material.RED_MUSHROOM))); registerFuel(new MachineFuel(2, new ItemStack(Material.RED_MUSHROOM)));
registerFuel(new MachineFuel(2, new ItemStack(Material.BROWN_MUSHROOM))); registerFuel(new MachineFuel(2, new ItemStack(Material.BROWN_MUSHROOM)));
registerFuel(new MachineFuel(2, new ItemStack(Material.VINE))); registerFuel(new MachineFuel(2, new ItemStack(Material.VINE)));
registerFuel(new MachineFuel(2, new ItemStack(Material.CACTUS))); registerFuel(new MachineFuel(2, new ItemStack(Material.CACTUS)));
registerFuel(new MachineFuel(2, new ItemStack(Material.LILY_PAD))); registerFuel(new MachineFuel(2, new ItemStack(Material.LILY_PAD)));
registerFuel(new MachineFuel(8, new ItemStack(Material.CHORUS_FRUIT))); registerFuel(new MachineFuel(8, new ItemStack(Material.CHORUS_FRUIT)));
registerFuel(new MachineFuel(1, new ItemStack(Material.BAMBOO)));
registerFuel(new MachineFuel(1, new ItemStack(Material.KELP)));
registerFuel(new MachineFuel(2, new ItemStack(Material.DRIED_KELP)));
registerFuel(new MachineFuel(20, new ItemStack(Material.DRIED_KELP_BLOCK)));
registerFuel(new MachineFuel(1, new ItemStack(Material.SEAGRASS)));
registerFuel(new MachineFuel(2, new ItemStack(Material.SEA_PICKLE)));
// Leaves // Leaves
registerFuel(new MachineFuel(1, new ItemStack(Material.OAK_LEAVES))); for(Material m:Tag.LEAVES.getValues())
registerFuel(new MachineFuel(1, new ItemStack(Material.BIRCH_LEAVES))); registerFuel(new MachineFuel(1, new ItemStack(m)));
registerFuel(new MachineFuel(1, new ItemStack(Material.SPRUCE_LEAVES)));
registerFuel(new MachineFuel(1, new ItemStack(Material.JUNGLE_LEAVES)));
registerFuel(new MachineFuel(1, new ItemStack(Material.ACACIA_LEAVES)));
registerFuel(new MachineFuel(1, new ItemStack(Material.DARK_OAK_LEAVES)));
// Saplings // Saplings
registerFuel(new MachineFuel(1, new ItemStack(Material.OAK_SAPLING))); for (Material m:Tag.SAPLINGS.getValues())
registerFuel(new MachineFuel(1, new ItemStack(Material.BIRCH_SAPLING))); registerFuel(new MachineFuel(1, new ItemStack(m)));
registerFuel(new MachineFuel(1, new ItemStack(Material.SPRUCE_SAPLING)));
registerFuel(new MachineFuel(1, new ItemStack(Material.JUNGLE_SAPLING))); // Small Flowers (formally just dandelions and poppies.
registerFuel(new MachineFuel(1, new ItemStack(Material.ACACIA_SAPLING))); for(Material m:Tag.SMALL_FLOWERS.getValues())
registerFuel(new MachineFuel(1, new ItemStack(Material.DARK_OAK_SAPLING))); registerFuel(new MachineFuel(1, new ItemStack(m)));
} }
@Override @Override

View File

@ -2,6 +2,7 @@ package me.mrCookieSlime.Slimefun;
import java.io.File; import java.io.File;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -10,6 +11,9 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import io.github.thebusybiscuit.cscorelib2.updater.BukkitUpdater;
import io.github.thebusybiscuit.cscorelib2.updater.GitHubBuildsUpdater;
import io.github.thebusybiscuit.cscorelib2.updater.Updater;
import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib;
import me.mrCookieSlime.CSCoreLibPlugin.PluginUtils; import me.mrCookieSlime.CSCoreLibPlugin.PluginUtils;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
@ -152,14 +156,29 @@ public class SlimefunStartup extends JavaPlugin {
items = new Config(Files.ITEMS); items = new Config(Files.ITEMS);
whitelist = new Config(Files.WHITELIST); whitelist = new Config(Files.WHITELIST);
// Init Config, Updater, Metrics and messages.yml // Setup Config and messages.yml
utils.setupUpdater(53485, getFile());
utils.setupMetrics();
utils.setupLocalization(); utils.setupLocalization();
config = utils.getConfig(); config = utils.getConfig();
Messages.local = utils.getLocalization(); Messages.local = utils.getLocalization();
Messages.setup(); Messages.setup();
// Setting up bStats
new Metrics(this);
// Setting up the Auto-Updater
Updater updater;
if (!getDescription().getVersion().startsWith("DEV - ")) {
// We are using an official build, use the BukkitDev Updater
updater = new BukkitUpdater(this, getFile(), 53485);
}
else {
// If we are using a development build, we want to switch to our custom
updater = new GitHubBuildsUpdater(this, getFile(), "TheBusyBiscuit/Slimefun4/master");
}
if (config.getBoolean("options.auto-update")) updater.start();
// Creating all necessary Folders // Creating all necessary Folders
String[] storage = {"blocks", "stored-blocks", "stored-inventories", "stored-chunks", "universal-inventories", "waypoints", "block-backups"}; String[] storage = {"blocks", "stored-blocks", "stored-inventories", "stored-chunks", "universal-inventories", "waypoints", "block-backups"};
String[] general = {"scripts", "generators", "error-reports", "cache/github"}; String[] general = {"scripts", "generators", "error-reports", "cache/github"};

View File

@ -75,6 +75,29 @@ public class ItemListener implements Listener {
} }
} }
@EventHandler
public void onGrindstone(InventoryClickEvent e){
if (e.getRawSlot() == 2 && e.getWhoClicked() instanceof Player && e.getInventory().getType() == InventoryType.GRINDSTONE) {
ItemStack slot0 = e.getInventory().getContents()[0];
ItemStack slot1 = e.getInventory().getContents()[1];
if (SlimefunItem.getByItem(slot0) != null && !SlimefunItem.isDisabled(slot0))
e.setCancelled(true);
else if (SlimefunItem.getByItem(slot1) != null && !SlimefunItem.isDisabled(slot1))
e.setCancelled(true);
if (SlimefunManager.isItemSimiliar(slot0, SlimefunGuide.getItem(BookDesign.BOOK), true))
e.setCancelled(true);
else if (SlimefunManager.isItemSimiliar(slot0, SlimefunGuide.getItem(BookDesign.CHEST), true))
e.setCancelled(true);
if (SlimefunManager.isItemSimiliar(slot1, SlimefunGuide.getItem(BookDesign.BOOK), true))
e.setCancelled(true);
else if (SlimefunManager.isItemSimiliar(slot1, SlimefunGuide.getItem(BookDesign.CHEST), true))
e.setCancelled(true);
}
}
@EventHandler @EventHandler
public void debug(PlayerInteractEvent e) { public void debug(PlayerInteractEvent e) {
if (e.getAction().equals(Action.PHYSICAL) || !e.getHand().equals(EquipmentSlot.HAND)) return; if (e.getAction().equals(Action.PHYSICAL) || !e.getHand().equals(EquipmentSlot.HAND)) return;
@ -388,8 +411,30 @@ public class ItemListener implements Listener {
@EventHandler @EventHandler
public void onAnvil(InventoryClickEvent e) { public void onAnvil(InventoryClickEvent e) {
if (e.getRawSlot() == 2 && e.getWhoClicked() instanceof Player && e.getInventory().getType() == InventoryType.ANVIL) { if (e.getRawSlot() == 2 && e.getWhoClicked() instanceof Player && e.getInventory().getType() == InventoryType.ANVIL) {
if (SlimefunManager.isItemSimiliar(e.getInventory().getContents()[0], SlimefunItems.ELYTRA, true)) return; ItemStack slot0 = e.getInventory().getContents()[0];
if (SlimefunItem.getByItem(e.getInventory().getContents()[0]) != null && !SlimefunItem.isDisabled(e.getInventory().getContents()[0])) { ItemStack slot1 = e.getInventory().getContents()[1];
if (SlimefunManager.isItemSimiliar(slot0, SlimefunItems.ELYTRA, true)) return;
if (SlimefunItem.getByItem(slot0) != null && !SlimefunItem.isDisabled(slot0)) {
e.setCancelled(true);
Messages.local.sendTranslation((Player) e.getWhoClicked(), "anvil.not-working", true);
} else if (SlimefunItem.getByItem(slot1) != null && !SlimefunItem.isDisabled(slot1)) {
e.setCancelled(true);
Messages.local.sendTranslation((Player) e.getWhoClicked(), "anvil.not-working", true);
}
if (SlimefunManager.isItemSimiliar(slot0, SlimefunGuide.getItem(BookDesign.BOOK), true)) {
e.setCancelled(true);
Messages.local.sendTranslation((Player) e.getWhoClicked(), "anvil.not-working", true);
} else if (SlimefunManager.isItemSimiliar(slot0, SlimefunGuide.getItem(BookDesign.CHEST), true)) {
e.setCancelled(true);
Messages.local.sendTranslation((Player) e.getWhoClicked(), "anvil.not-working", true);
}
if (SlimefunManager.isItemSimiliar(slot1, SlimefunGuide.getItem(BookDesign.BOOK), true)) {
e.setCancelled(true);
Messages.local.sendTranslation((Player) e.getWhoClicked(), "anvil.not-working", true);
} else if (SlimefunManager.isItemSimiliar(slot1, SlimefunGuide.getItem(BookDesign.CHEST), true)) {
e.setCancelled(true); e.setCancelled(true);
Messages.local.sendTranslation((Player) e.getWhoClicked(), "anvil.not-working", true); Messages.local.sendTranslation((Player) e.getWhoClicked(), "anvil.not-working", true);
} }