1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Refactoring

This commit is contained in:
TheBusyBiscuit 2020-06-17 01:24:47 +02:00
parent f0b5d55c48
commit 5c14bc5cbe
18 changed files with 552 additions and 588 deletions

View File

@ -20,6 +20,9 @@
## Release Candidate 14 (TBD)
#### Changes
* Coolant Cells now last twice as long
## Release Candidate 13 (16 Jun 2020)
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#13

View File

@ -29,7 +29,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.items.gps.GPSTransmitter;
import io.github.thebusybiscuit.slimefun4.implementation.items.gps.Teleporter;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import io.github.thebusybiscuit.slimefun4.utils.HeadTexture;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
@ -56,11 +56,6 @@ public class GPSNetwork {
private final TeleportationManager teleportation = new TeleportationManager();
private final ResourceManager resourceManager = new ResourceManager(SlimefunPlugin.instance);
private final ItemStack deathpointIcon = SlimefunUtils.getCustomHead("1ae3855f952cd4a03c148a946e3f812a5955ad35cbcb52627ea4acd47d3081");
private final ItemStack netherIcon = SlimefunUtils.getCustomHead("d83571ff589f1a59bb02b80800fc736116e27c3dcf9efebede8cf1fdde");
private final ItemStack endIcon = SlimefunUtils.getCustomHead("c6cac59b2aae489aa0687b5d802b2555eb14a40bd62b21eb116fa569cdb756");
private final ItemStack worldIcon = SlimefunUtils.getCustomHead("c9c8881e42915a9d29bb61a16fb26d059913204d265df5b439b3d792acd56");
/**
* This method updates the status of a {@link GPSTransmitter}.
*
@ -145,7 +140,7 @@ public class GPSNetwork {
menu.addItem(4, new CustomItem(SlimefunItems.GPS_CONTROL_PANEL, "&7Network Info", "", "&8\u21E8 &7Status: " + (complexity > 0 ? "&2&lONLINE" : "&4&lOFFLINE"), "&8\u21E8 &7Complexity: &r" + complexity));
menu.addMenuClickHandler(4, ChestMenuUtils.getEmptyClickHandler());
menu.addItem(6, new CustomItem(worldIcon, "&7" + SlimefunPlugin.getLocal().getMessage(p, "machines.GPS_CONTROL_PANEL.waypoints"), "", ChatColor.GRAY + "\u21E8 " + SlimefunPlugin.getLocal().getMessage(p, "guide.tooltips.open-category")));
menu.addItem(6, new CustomItem(HeadTexture.GLOBE_OVERWORLD.getAsItemStack(), "&7" + SlimefunPlugin.getLocal().getMessage(p, "machines.GPS_CONTROL_PANEL.waypoints"), "", ChatColor.GRAY + "\u21E8 " + SlimefunPlugin.getLocal().getMessage(p, "guide.tooltips.open-category")));
menu.addMenuClickHandler(6, (pl, slot, item, action) -> {
openWaypointControlPanel(pl);
return false;
@ -186,16 +181,16 @@ public class GPSNetwork {
*/
public ItemStack getIcon(String name, Environment environment) {
if (name.startsWith("player:death ")) {
return deathpointIcon;
return HeadTexture.DEATHPOINT.getAsItemStack();
}
else if (environment == Environment.NETHER) {
return netherIcon;
return HeadTexture.GLOBE_NETHER.getAsItemStack();
}
else if (environment == Environment.THE_END) {
return endIcon;
return HeadTexture.GLOBE_THE_END.getAsItemStack();
}
else {
return worldIcon;
return HeadTexture.GLOBE_OVERWORLD.getAsItemStack();
}
}
@ -217,7 +212,7 @@ public class GPSNetwork {
menu.addItem(4, new CustomItem(SlimefunItems.GPS_CONTROL_PANEL, "&7Network Info", "", "&8\u21E8 &7Status: " + (complexity > 0 ? "&2&lONLINE" : "&4&lOFFLINE"), "&8\u21E8 &7Complexity: &r" + complexity));
menu.addMenuClickHandler(4, ChestMenuUtils.getEmptyClickHandler());
menu.addItem(6, new CustomItem(worldIcon, "&7" + SlimefunPlugin.getLocal().getMessage(p, "machines.GPS_CONTROL_PANEL.waypoints")));
menu.addItem(6, new CustomItem(HeadTexture.GLOBE_OVERWORLD.getAsItemStack(), "&7" + SlimefunPlugin.getLocal().getMessage(p, "machines.GPS_CONTROL_PANEL.waypoints")));
menu.addMenuClickHandler(6, ChestMenuUtils.getEmptyClickHandler());
int index = 0;
@ -227,7 +222,7 @@ public class GPSNetwork {
Location l = waypoint.getLocation();
menu.addItem(slot, new CustomItem(waypoint.getIcon(), waypoint.getName().replace("player:death ", ""), "&8\u21E8 &7World: &r" + l.getWorld().getName(), "&8\u21E8 &7X: &r" + l.getX(), "&8\u21E8 &7Y: &r" + l.getY(), "&8\u21E8 &7Z: &r" + l.getZ(), "", "&8\u21E8 &cClick to delete"));
menu.addMenuClickHandler(slot, (pl, slotn, item, action) -> {
menu.addMenuClickHandler(slot, (pl, s, item, action) -> {
profile.removeWaypoint(waypoint);
pl.playSound(pl.getLocation(), Sound.UI_BUTTON_CLICK, 1F, 1F);

View File

@ -19,7 +19,7 @@ import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import io.github.thebusybiscuit.slimefun4.utils.HeadTexture;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.api.Slimefun;
@ -46,7 +46,7 @@ public final class TeleportationManager {
menu.addItem(slot, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
}
menu.addItem(4, new CustomItem(SlimefunUtils.getCustomHead("c9c8881e42915a9d29bb61a16fb26d059913204d265df5b439b3d792acd56"), ChatColor.YELLOW + SlimefunPlugin.getLocal().getMessage(p, "machines.TELEPORTER.gui.title")));
menu.addItem(4, new CustomItem(HeadTexture.GLOBE_OVERWORLD.getAsItemStack(), ChatColor.YELLOW + SlimefunPlugin.getLocal().getMessage(p, "machines.TELEPORTER.gui.title")));
menu.addMenuClickHandler(4, ChestMenuUtils.getEmptyClickHandler());
Location source = new Location(b.getWorld(), b.getX() + 0.5D, b.getY() + 2D, b.getZ() + 0.5D);
@ -60,7 +60,8 @@ public final class TeleportationManager {
int slot = teleporterInventory[index];
Location l = waypoint.getLocation();
menu.addItem(slot, new CustomItem(waypoint.getIcon(), waypoint.getName().replace("player:death ", ""), "", "&8\u21E8 &7" + SlimefunPlugin.getLocal().getResourceString(p, "tooltips.world") + ": &r" + l.getWorld().getName(), "&8\u21E8 &7X: &r" + l.getX(), "&8\u21E8 &7Y: &r" + l.getY(), "&8\u21E8 &7Z: &r" + l.getZ(), "&8\u21E8 &7" + SlimefunPlugin.getLocal().getMessage(p, "machines.TELEPORTER.gui.time") + ": &r" + DoubleHandler.fixDouble(0.5 * getTeleportationTime(complexity, source, l)) + "s", "", "&8\u21E8 &c" + SlimefunPlugin.getLocal().getMessage(p, "machines.TELEPORTER.gui.tooltip")));
menu.addItem(slot,
new CustomItem(waypoint.getIcon(), waypoint.getName().replace("player:death ", ""), "", "&8\u21E8 &7" + SlimefunPlugin.getLocal().getResourceString(p, "tooltips.world") + ": &r" + l.getWorld().getName(), "&8\u21E8 &7X: &r" + l.getX(), "&8\u21E8 &7Y: &r" + l.getY(), "&8\u21E8 &7Z: &r" + l.getZ(), "&8\u21E8 &7" + SlimefunPlugin.getLocal().getMessage(p, "machines.TELEPORTER.gui.time") + ": &r" + DoubleHandler.fixDouble(0.5 * getTeleportationTime(complexity, source, l)) + "s", "", "&8\u21E8 &c" + SlimefunPlugin.getLocal().getMessage(p, "machines.TELEPORTER.gui.tooltip")));
menu.addMenuClickHandler(slot, (pl, s, item, action) -> {
pl.closeInventory();
teleport(pl.getUniqueId(), complexity, source, l, false);

View File

@ -64,15 +64,15 @@ public final class SlimefunItems {
public static final SlimefunItemStack FILLED_FLASK_OF_KNOWLEDGE = new SlimefunItemStack("FILLED_FLASK_OF_KNOWLEDGE", Material.EXPERIENCE_BOTTLE, "&aFlask of Knowledge");
/* Backpacks */
public static final SlimefunItemStack BACKPACK_SMALL = new SlimefunItemStack("SMALL_BACKPACK", HeadTexture.BACKPACK, "&eSmall Backpack", "", "&7Size: &e9", "&7ID: <ID>", "", "&7&eRight Click&7 to open");
public static final SlimefunItemStack BACKPACK_MEDIUM = new SlimefunItemStack("MEDIUM_BACKPACK", HeadTexture.BACKPACK, "&eBackpack", "", "&7Size: &e18", "&7ID: <ID>", "", "&7&eRight Click&7 to open");
public static final SlimefunItemStack BACKPACK_LARGE = new SlimefunItemStack("LARGE_BACKPACK", HeadTexture.BACKPACK, "&eLarge Backpack", "", "&7Size: &e27", "&7ID: <ID>", "", "&7&eRight Click&7 to open");
public static final SlimefunItemStack WOVEN_BACKPACK = new SlimefunItemStack("WOVEN_BACKPACK", HeadTexture.BACKPACK, "&eWoven Backpack", "", "&7Size: &e36", "&7ID: <ID>", "", "&7&eRight Click&7 to open");
public static final SlimefunItemStack GILDED_BACKPACK = new SlimefunItemStack("GILDED_BACKPACK", HeadTexture.BACKPACK, "&eGilded Backpack", "", "&7Size: &e45", "&7ID: <ID>", "", "&7&eRight Click&7 to open");
public static final SlimefunItemStack RADIANT_BACKPACK = new SlimefunItemStack("RADIANT_BACKPACK", HeadTexture.BACKPACK, "&eRadiant Backpack", "", "&7Size: &e54 (Double chest)", "&7ID: <ID>", "", "&7&eRight Click&7 to open");
public static final SlimefunItemStack BOUND_BACKPACK = new SlimefunItemStack("BOUND_BACKPACK", HeadTexture.ENDER_BACKPACK, "&cSoulbound Backpack", "", "&7Size: &e36", "&7ID: <ID>", "", "&7&eRight Click&7 to open");
public static final SlimefunItemStack COOLER = new SlimefunItemStack("COOLER", HeadTexture.COOLER, "&bCooler", "&rAllows you to store Juices/Smoothies", "&rand automatically consumes them when you are hungry", "&rand you have this in your Inventory", "", "&7Size: &e27", "&7ID: <ID>", "", "&7&eRight Click&7 to open");
public static final SlimefunItemStack RESTORED_BACKPACK = new SlimefunItemStack("RESTORED_BACKPACK", HeadTexture.RESTORED_BACKPACK, "&eRestored Backpack", "", "&7Retrieve your lost items", "&7ID: <ID>", "", "&7&eRight Click&7 to open");
public static final SlimefunItemStack BACKPACK_SMALL = new SlimefunItemStack("SMALL_BACKPACK", HeadTexture.BACKPACK, "&eSmall Backpack", "", "&7Size: &e9", "&7ID: <ID>", "", LoreBuilder.RIGHT_CLICK_TO_OPEN);
public static final SlimefunItemStack BACKPACK_MEDIUM = new SlimefunItemStack("MEDIUM_BACKPACK", HeadTexture.BACKPACK, "&eBackpack", "", "&7Size: &e18", "&7ID: <ID>", "", LoreBuilder.RIGHT_CLICK_TO_OPEN);
public static final SlimefunItemStack BACKPACK_LARGE = new SlimefunItemStack("LARGE_BACKPACK", HeadTexture.BACKPACK, "&eLarge Backpack", "", "&7Size: &e27", "&7ID: <ID>", "", LoreBuilder.RIGHT_CLICK_TO_OPEN);
public static final SlimefunItemStack WOVEN_BACKPACK = new SlimefunItemStack("WOVEN_BACKPACK", HeadTexture.BACKPACK, "&eWoven Backpack", "", "&7Size: &e36", "&7ID: <ID>", "", LoreBuilder.RIGHT_CLICK_TO_OPEN);
public static final SlimefunItemStack GILDED_BACKPACK = new SlimefunItemStack("GILDED_BACKPACK", HeadTexture.BACKPACK, "&eGilded Backpack", "", "&7Size: &e45", "&7ID: <ID>", "", LoreBuilder.RIGHT_CLICK_TO_OPEN);
public static final SlimefunItemStack RADIANT_BACKPACK = new SlimefunItemStack("RADIANT_BACKPACK", HeadTexture.BACKPACK, "&eRadiant Backpack", "", "&7Size: &e54 (Double chest)", "&7ID: <ID>", "", LoreBuilder.RIGHT_CLICK_TO_OPEN);
public static final SlimefunItemStack BOUND_BACKPACK = new SlimefunItemStack("BOUND_BACKPACK", HeadTexture.ENDER_BACKPACK, "&cSoulbound Backpack", "", "&7Size: &e36", "&7ID: <ID>", "", LoreBuilder.RIGHT_CLICK_TO_OPEN);
public static final SlimefunItemStack COOLER = new SlimefunItemStack("COOLER", HeadTexture.COOLER, "&bCooler", "&rAllows you to store Juices/Smoothies", "&rand automatically consumes them when you are hungry", "&rand you have this in your Inventory", "", "&7Size: &e27", "&7ID: <ID>", "", LoreBuilder.RIGHT_CLICK_TO_OPEN);
public static final SlimefunItemStack RESTORED_BACKPACK = new SlimefunItemStack("RESTORED_BACKPACK", HeadTexture.RESTORED_BACKPACK, "&eRestored Backpack", "", "&7Retrieve your lost items", "&7ID: <ID>", "", LoreBuilder.RIGHT_CLICK_TO_OPEN);
/* Jetpacks */
public static final SlimefunItemStack DURALUMIN_JETPACK = new SlimefunItemStack("DURALUMIN_JETPACK", Material.LEATHER_CHESTPLATE, Color.SILVER, "&9Electric Jetpack &7- &eI", "", LoreBuilder.material("Duralumin"), LoreBuilder.powerCharged(0, 20), "&8\u21E8 &7Thrust: &c0.35", "", LoreBuilder.CROUCH_TO_USE);

View File

@ -43,24 +43,7 @@ public abstract class WoodcutterAndroid extends ProgrammableAndroid {
log.getWorld().playEffect(log.getLocation(), Effect.STEP_SOUND, log.getType());
if (SlimefunPlugin.getProtectionManager().hasPermission(Bukkit.getOfflinePlayer(UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner"))), log.getLocation(), ProtectableAction.BREAK_BLOCK)) {
ItemStack drop = new ItemStack(log.getType());
if (menu.fits(drop, getOutputSlots())) {
menu.pushItem(drop, getOutputSlots());
log.getWorld().playEffect(log.getLocation(), Effect.STEP_SOUND, log.getType());
if (log.getY() == b.getRelative(face).getY()) {
Optional<Material> sapling = MaterialConverter.getSaplingFromLog(log.getType());
if (sapling.isPresent()) {
log.setType(sapling.get());
}
}
else {
log.setType(Material.AIR);
}
}
breakLog(log, b, menu, face);
}
return false;
@ -70,4 +53,24 @@ public abstract class WoodcutterAndroid extends ProgrammableAndroid {
return true;
}
private void breakLog(Block log, Block android, BlockMenu menu, BlockFace face) {
ItemStack drop = new ItemStack(log.getType());
if (menu.fits(drop, getOutputSlots())) {
menu.pushItem(drop, getOutputSlots());
log.getWorld().playEffect(log.getLocation(), Effect.STEP_SOUND, log.getType());
if (log.getY() == android.getRelative(face).getY()) {
Optional<Material> sapling = MaterialConverter.getSaplingFromLog(log.getType());
if (sapling.isPresent()) {
log.setType(sapling.get());
}
}
else {
log.setType(Material.AIR);
}
}
}
}

View File

@ -0,0 +1,53 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.cargo;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import io.github.thebusybiscuit.slimefun4.utils.ChatUtils;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
abstract class AbstractCargoNode extends SlimefunItem {
protected static final String FREQUENCY = "frequency";
public AbstractCargoNode(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
super(category, item, recipeType, recipe, recipeOutput);
new BlockMenuPreset(getID(), ChatUtils.removeColorCodes(item.getItemMeta().getDisplayName())) {
@Override
public void init() {
createBorder(this);
}
@Override
public void newInstance(BlockMenu menu, Block b) {
updateBlockMenu(menu, b);
}
@Override
public boolean canOpen(Block b, Player p) {
return p.hasPermission("slimefun.cargo.bypass") || SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.ACCESS_INVENTORIES);
}
@Override
public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
return new int[0];
}
};
}
protected abstract void createBorder(BlockMenuPreset preset);
protected abstract void updateBlockMenu(BlockMenu menu, Block b);
}

View File

@ -9,7 +9,6 @@ import org.bukkit.inventory.meta.ItemMeta;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
@ -22,139 +21,22 @@ import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
public class AdvancedCargoOutputNode extends SlimefunItem {
public class AdvancedCargoOutputNode extends AbstractCargoNode {
private final int[] border = { 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17, 18, 22, 23, 24, 26, 27, 31, 32, 33, 34, 35, 36, 40, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 };
private final int[] slots = { 19, 20, 21, 28, 29, 30, 37, 38, 39 };
private static final int[] BORDER = { 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17, 18, 22, 23, 24, 26, 27, 31, 32, 33, 34, 35, 36, 40, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 };
private static final int[] SLOTS = { 19, 20, 21, 28, 29, 30, 37, 38, 39 };
public AdvancedCargoOutputNode(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
super(category, item, recipeType, recipe, recipeOutput);
new BlockMenuPreset(getID(), "&cOutput Node") {
@Override
public void init() {
constructMenu(this);
}
@Override
public void newInstance(BlockMenu menu, Block b) {
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-type") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-type").equals("whitelist")) {
menu.replaceExistingItem(15, new CustomItem(Material.WHITE_WOOL, "&7Type: &rWhitelist", "", "&e> Click to change it to Blacklist"));
menu.addMenuClickHandler(15, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-type", "blacklist");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(15, new CustomItem(Material.BLACK_WOOL, "&7Type: &8Blacklist", "", "&e> Click to change it to Whitelist"));
menu.addMenuClickHandler(15, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-type", "whitelist");
newInstance(menu, b);
return 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(Material.STONE_SWORD, "&7Include Sub-IDs/Durability: &4\u2718", "", "&e> Click to toggle whether the Durability has to match"));
menu.addMenuClickHandler(16, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-durability", "true");
newInstance(menu, b);
return false;
});
}
else {
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) -> {
BlockStorage.addBlockInfo(b, "filter-durability", "false");
newInstance(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore").equals("true")) {
menu.replaceExistingItem(25, new CustomItem(Material.MAP, "&7Include Lore: &2\u2714", "", "&e> Click to toggle whether the Lore has to match"));
menu.addMenuClickHandler(25, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-lore", "false");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(25, new CustomItem(Material.MAP, "&7Include Lore: &4\u2718", "", "&e> Click to toggle whether the Lore has to match"));
menu.addMenuClickHandler(25, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-lore", "true");
newInstance(menu, b);
return false;
});
}
menu.replaceExistingItem(41, new CustomItem(SlimefunUtils.getCustomHead("f2599bd986659b8ce2c4988525c94e19ddd39fad08a38284a197f1b70675acc"), "&bChannel", "", "&e> Click to decrease the Channel ID by 1"));
menu.addMenuClickHandler(41, (p, slot, item, action) -> {
int channel = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) - 1;
if (channel < 0) {
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) channel = 16;
else channel = 15;
}
BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channel));
newInstance(menu, b);
return false;
});
int channel = ((!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "frequency") == null) ? 0 : (Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency"))));
if (channel == 16) {
menu.replaceExistingItem(42, new CustomItem(SlimefunUtils.getCustomHead("7a44ff3a5f49c69cab676bad8d98a063fa78cfa61916fdef3e267557fec18283"), "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42, ChestMenuUtils.getEmptyClickHandler());
}
else {
menu.replaceExistingItem(42, new CustomItem(MaterialCollections.getAllWoolColors().get(channel), "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42, ChestMenuUtils.getEmptyClickHandler());
}
menu.replaceExistingItem(43, new CustomItem(SlimefunUtils.getCustomHead("c2f910c47da042e4aa28af6cc81cf48ac6caf37dab35f88db993accb9dfe516"), "&bChannel", "", "&e> Click to increase the Channel ID by 1"));
menu.addMenuClickHandler(43, (p, slot, item, action) -> {
int channeln = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) + 1;
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) {
if (channeln > 16) channeln = 0;
}
else {
if (channeln > 15) channeln = 0;
}
BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channeln));
newInstance(menu, b);
return false;
});
}
@Override
public boolean canOpen(Block b, Player p) {
return p.hasPermission("slimefun.cargo.bypass") || SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.ACCESS_INVENTORIES);
}
@Override
public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
return new int[0];
}
};
registerBlockHandler(getID(), new SlimefunBlockHandler() {
@Override
public void onPlace(Player p, Block b, SlimefunItem item) {
BlockStorage.addBlockInfo(b, "owner", p.getUniqueId().toString());
BlockStorage.addBlockInfo(b, "index", "0");
BlockStorage.addBlockInfo(b, "frequency", "0");
BlockStorage.addBlockInfo(b, FREQUENCY, "0");
BlockStorage.addBlockInfo(b, "filter-type", "whitelist");
BlockStorage.addBlockInfo(b, "filter-lore", "true");
BlockStorage.addBlockInfo(b, "filter-durability", "false");
@ -165,7 +47,7 @@ public class AdvancedCargoOutputNode extends SlimefunItem {
BlockMenu inv = BlockStorage.getInventory(b);
if (inv != null) {
for (int slot : slots) {
for (int slot : SLOTS) {
if (inv.getItemInSlot(slot) != null) {
b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
inv.replaceExistingItem(slot, null);
@ -177,12 +59,111 @@ public class AdvancedCargoOutputNode extends SlimefunItem {
});
}
private void constructMenu(BlockMenuPreset preset) {
for (int i : border) {
@Override
protected void createBorder(BlockMenuPreset preset) {
for (int i : BORDER) {
preset.addItem(i, new CustomItem(Material.CYAN_STAINED_GLASS_PANE, " "), ChestMenuUtils.getEmptyClickHandler());
}
preset.addItem(2, new CustomItem(Material.PAPER, "&3Items", "", "&bPut in all Items you want to", "&bblacklist/whitelist"), ChestMenuUtils.getEmptyClickHandler());
}
@Override
protected void updateBlockMenu(BlockMenu menu, Block b) {
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-type") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-type").equals("whitelist")) {
menu.replaceExistingItem(15, new CustomItem(Material.WHITE_WOOL, "&7Type: &rWhitelist", "", "&e> Click to change it to Blacklist"));
menu.addMenuClickHandler(15, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-type", "blacklist");
updateBlockMenu(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(15, new CustomItem(Material.BLACK_WOOL, "&7Type: &8Blacklist", "", "&e> Click to change it to Whitelist"));
menu.addMenuClickHandler(15, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-type", "whitelist");
updateBlockMenu(menu, b);
return 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(Material.STONE_SWORD, "&7Include Sub-IDs/Durability: &4\u2718", "", "&e> Click to toggle whether the Durability has to match"));
menu.addMenuClickHandler(16, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-durability", "true");
updateBlockMenu(menu, b);
return false;
});
}
else {
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) -> {
BlockStorage.addBlockInfo(b, "filter-durability", "false");
updateBlockMenu(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore").equals("true")) {
menu.replaceExistingItem(25, new CustomItem(Material.MAP, "&7Include Lore: &2\u2714", "", "&e> Click to toggle whether the Lore has to match"));
menu.addMenuClickHandler(25, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-lore", "false");
updateBlockMenu(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(25, new CustomItem(Material.MAP, "&7Include Lore: &4\u2718", "", "&e> Click to toggle whether the Lore has to match"));
menu.addMenuClickHandler(25, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-lore", "true");
updateBlockMenu(menu, b);
return false;
});
}
menu.replaceExistingItem(41, new CustomItem(SlimefunUtils.getCustomHead("f2599bd986659b8ce2c4988525c94e19ddd39fad08a38284a197f1b70675acc"), "&bChannel", "", "&e> Click to decrease the Channel ID by 1"));
menu.addMenuClickHandler(41, (p, slot, item, action) -> {
int channel = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY)) - 1;
if (channel < 0) {
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) channel = 16;
else channel = 15;
}
BlockStorage.addBlockInfo(b, FREQUENCY, String.valueOf(channel));
updateBlockMenu(menu, b);
return false;
});
int channel = ((!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY) == null) ? 0 : (Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY))));
if (channel == 16) {
menu.replaceExistingItem(42, new CustomItem(SlimefunUtils.getCustomHead("7a44ff3a5f49c69cab676bad8d98a063fa78cfa61916fdef3e267557fec18283"), "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42, ChestMenuUtils.getEmptyClickHandler());
}
else {
menu.replaceExistingItem(42, new CustomItem(MaterialCollections.getAllWoolColors().get(channel), "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42, ChestMenuUtils.getEmptyClickHandler());
}
menu.replaceExistingItem(43, new CustomItem(SlimefunUtils.getCustomHead("c2f910c47da042e4aa28af6cc81cf48ac6caf37dab35f88db993accb9dfe516"), "&bChannel", "", "&e> Click to increase the Channel ID by 1"));
menu.addMenuClickHandler(43, (p, slot, item, action) -> {
int channeln = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY)) + 1;
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) {
if (channeln > 16) channeln = 0;
}
else {
if (channeln > 15) channeln = 0;
}
BlockStorage.addBlockInfo(b, FREQUENCY, String.valueOf(channeln));
updateBlockMenu(menu, b);
return false;
});
}
}

View File

@ -9,7 +9,6 @@ import org.bukkit.inventory.meta.ItemMeta;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
@ -22,156 +21,22 @@ import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
public class CargoInputNode extends SlimefunItem {
public class CargoInputNode extends AbstractCargoNode {
private final int[] border = { 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17, 18, 22, 23, 26, 27, 31, 32, 33, 34, 35, 36, 40, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 };
private final int[] slots = { 19, 20, 21, 28, 29, 30, 37, 38, 39 };
private static final int[] BORDER = { 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17, 18, 22, 23, 26, 27, 31, 32, 33, 34, 35, 36, 40, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 };
private static final int[] SLOTS = { 19, 20, 21, 28, 29, 30, 37, 38, 39 };
public CargoInputNode(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
super(category, item, recipeType, recipe, recipeOutput);
new BlockMenuPreset(getID(), "&3Input Node") {
@Override
public void init() {
constructMenu(this);
}
@Override
public void newInstance(BlockMenu menu, Block b) {
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-type") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-type").equals("whitelist")) {
menu.replaceExistingItem(15, new CustomItem(Material.WHITE_WOOL, "&7Type: &rWhitelist", "", "&e> Click to change it to Blacklist"));
menu.addMenuClickHandler(15, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-type", "blacklist");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(15, new CustomItem(Material.BLACK_WOOL, "&7Type: &8Blacklist", "", "&e> Click to change it to Whitelist"));
menu.addMenuClickHandler(15, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-type", "whitelist");
newInstance(menu, b);
return 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(Material.STONE_SWORD, "&7Include Sub-IDs/Durability: &4\u2718", "", "&e> Click to toggle whether the Durability has to match"));
menu.addMenuClickHandler(16, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-durability", "true");
newInstance(menu, b);
return false;
});
}
else {
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) -> {
BlockStorage.addBlockInfo(b, "filter-durability", "false");
newInstance(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "round-robin") == null || BlockStorage.getLocationInfo(b.getLocation(), "round-robin").equals("false")) {
menu.replaceExistingItem(24, new CustomItem(SlimefunUtils.getCustomHead("d78f2b7e5e75639ea7fb796c35d364c4df28b4243e66b76277aadcd6261337"), "&7Round-Robin Mode: &4\u2718", "", "&e> Click to enable Round Robin Mode", "&e(Items will be equally distributed on the Channel)"));
menu.addMenuClickHandler(24, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "round-robin", "true");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(24, new CustomItem(SlimefunUtils.getCustomHead("d78f2b7e5e75639ea7fb796c35d364c4df28b4243e66b76277aadcd6261337"), "&7Round-Robin Mode: &2\u2714", "", "&e> Click to disable Round Robin Mode", "&e(Items will be equally distributed on the Channel)"));
menu.addMenuClickHandler(24, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "round-robin", "false");
newInstance(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore").equals("true")) {
menu.replaceExistingItem(25, new CustomItem(Material.MAP, "&7Include Lore: &2\u2714", "", "&e> Click to toggle whether the Lore has to match"));
menu.addMenuClickHandler(25, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-lore", "false");
newInstance(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(25, new CustomItem(Material.MAP, "&7Include Lore: &4\u2718", "", "&e> Click to toggle whether the Lore has to match"));
menu.addMenuClickHandler(25, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-lore", "true");
newInstance(menu, b);
return false;
});
}
menu.replaceExistingItem(41, new CustomItem(SlimefunUtils.getCustomHead("f2599bd986659b8ce2c4988525c94e19ddd39fad08a38284a197f1b70675acc"), "&bChannel", "", "&e> Click to decrease the Channel ID by 1"));
menu.addMenuClickHandler(41, (p, slot, item, action) -> {
int channel = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) - 1;
if (channel < 0) {
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) channel = 16;
else channel = 15;
}
BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channel));
newInstance(menu, b);
return false;
});
int channel = ((!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "frequency") == null) ? 0 : (Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency"))));
if (channel == 16) {
menu.replaceExistingItem(42, new CustomItem(SlimefunUtils.getCustomHead("7a44ff3a5f49c69cab676bad8d98a063fa78cfa61916fdef3e267557fec18283"), "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42, ChestMenuUtils.getEmptyClickHandler());
}
else {
menu.replaceExistingItem(42, new CustomItem(new ItemStack(MaterialCollections.getAllWoolColors().get(channel)), "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42, ChestMenuUtils.getEmptyClickHandler());
}
menu.replaceExistingItem(43, new CustomItem(SlimefunUtils.getCustomHead("c2f910c47da042e4aa28af6cc81cf48ac6caf37dab35f88db993accb9dfe516"), "&bChannel", "", "&e> Click to increase the Channel ID by 1"));
menu.addMenuClickHandler(43, (p, slot, item, action) -> {
int channeln = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) + 1;
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) {
if (channeln > 16) channeln = 0;
}
else {
if (channeln > 15) channeln = 0;
}
BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channeln));
newInstance(menu, b);
return false;
});
}
@Override
public boolean canOpen(Block b, Player p) {
return p.hasPermission("slimefun.cargo.bypass") || SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.ACCESS_INVENTORIES);
}
@Override
public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
return new int[0];
}
};
registerBlockHandler(getID(), new SlimefunBlockHandler() {
@Override
public void onPlace(Player p, Block b, SlimefunItem item) {
BlockStorage.addBlockInfo(b, "owner", p.getUniqueId().toString());
BlockStorage.addBlockInfo(b, "index", "0");
BlockStorage.addBlockInfo(b, "frequency", "0");
BlockStorage.addBlockInfo(b, FREQUENCY, "0");
BlockStorage.addBlockInfo(b, "filter-type", "whitelist");
BlockStorage.addBlockInfo(b, "filter-lore", "true");
BlockStorage.addBlockInfo(b, "filter-durability", "false");
@ -183,7 +48,7 @@ public class CargoInputNode extends SlimefunItem {
BlockMenu inv = BlockStorage.getInventory(b);
if (inv != null) {
for (int slot : slots) {
for (int slot : SLOTS) {
if (inv.getItemInSlot(slot) != null) {
b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
inv.replaceExistingItem(slot, null);
@ -195,12 +60,128 @@ public class CargoInputNode extends SlimefunItem {
});
}
private void constructMenu(BlockMenuPreset preset) {
for (int i : border) {
@Override
protected void createBorder(BlockMenuPreset preset) {
for (int i : BORDER) {
preset.addItem(i, new CustomItem(Material.CYAN_STAINED_GLASS_PANE, " "), ChestMenuUtils.getEmptyClickHandler());
}
preset.addItem(2, new CustomItem(Material.PAPER, "&3Items", "", "&bPut in all Items you want to", "&bblacklist/whitelist"), ChestMenuUtils.getEmptyClickHandler());
}
@Override
protected void updateBlockMenu(BlockMenu menu, Block b) {
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-type") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-type").equals("whitelist")) {
menu.replaceExistingItem(15, new CustomItem(Material.WHITE_WOOL, "&7Type: &rWhitelist", "", "&e> Click to change it to Blacklist"));
menu.addMenuClickHandler(15, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-type", "blacklist");
updateBlockMenu(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(15, new CustomItem(Material.BLACK_WOOL, "&7Type: &8Blacklist", "", "&e> Click to change it to Whitelist"));
menu.addMenuClickHandler(15, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-type", "whitelist");
updateBlockMenu(menu, b);
return 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(Material.STONE_SWORD, "&7Include Sub-IDs/Durability: &4\u2718", "", "&e> Click to toggle whether the Durability has to match"));
menu.addMenuClickHandler(16, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-durability", "true");
updateBlockMenu(menu, b);
return false;
});
}
else {
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) -> {
BlockStorage.addBlockInfo(b, "filter-durability", "false");
updateBlockMenu(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "round-robin") == null || BlockStorage.getLocationInfo(b.getLocation(), "round-robin").equals("false")) {
menu.replaceExistingItem(24, new CustomItem(SlimefunUtils.getCustomHead("d78f2b7e5e75639ea7fb796c35d364c4df28b4243e66b76277aadcd6261337"), "&7Round-Robin Mode: &4\u2718", "", "&e> Click to enable Round Robin Mode", "&e(Items will be equally distributed on the Channel)"));
menu.addMenuClickHandler(24, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "round-robin", "true");
updateBlockMenu(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(24, new CustomItem(SlimefunUtils.getCustomHead("d78f2b7e5e75639ea7fb796c35d364c4df28b4243e66b76277aadcd6261337"), "&7Round-Robin Mode: &2\u2714", "", "&e> Click to disable Round Robin Mode", "&e(Items will be equally distributed on the Channel)"));
menu.addMenuClickHandler(24, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "round-robin", "false");
updateBlockMenu(menu, b);
return false;
});
}
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore") == null || BlockStorage.getLocationInfo(b.getLocation(), "filter-lore").equals("true")) {
menu.replaceExistingItem(25, new CustomItem(Material.MAP, "&7Include Lore: &2\u2714", "", "&e> Click to toggle whether the Lore has to match"));
menu.addMenuClickHandler(25, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-lore", "false");
updateBlockMenu(menu, b);
return false;
});
}
else {
menu.replaceExistingItem(25, new CustomItem(Material.MAP, "&7Include Lore: &4\u2718", "", "&e> Click to toggle whether the Lore has to match"));
menu.addMenuClickHandler(25, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "filter-lore", "true");
updateBlockMenu(menu, b);
return false;
});
}
menu.replaceExistingItem(41, new CustomItem(SlimefunUtils.getCustomHead("f2599bd986659b8ce2c4988525c94e19ddd39fad08a38284a197f1b70675acc"), "&bChannel", "", "&e> Click to decrease the Channel ID by 1"));
menu.addMenuClickHandler(41, (p, slot, item, action) -> {
int channel = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY)) - 1;
if (channel < 0) {
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) channel = 16;
else channel = 15;
}
BlockStorage.addBlockInfo(b, FREQUENCY, String.valueOf(channel));
updateBlockMenu(menu, b);
return false;
});
int channel = ((!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY) == null) ? 0 : (Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY))));
if (channel == 16) {
menu.replaceExistingItem(42, new CustomItem(SlimefunUtils.getCustomHead("7a44ff3a5f49c69cab676bad8d98a063fa78cfa61916fdef3e267557fec18283"), "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42, ChestMenuUtils.getEmptyClickHandler());
}
else {
menu.replaceExistingItem(42, new CustomItem(new ItemStack(MaterialCollections.getAllWoolColors().get(channel)), "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(42, ChestMenuUtils.getEmptyClickHandler());
}
menu.replaceExistingItem(43, new CustomItem(SlimefunUtils.getCustomHead("c2f910c47da042e4aa28af6cc81cf48ac6caf37dab35f88db993accb9dfe516"), "&bChannel", "", "&e> Click to increase the Channel ID by 1"));
menu.addMenuClickHandler(43, (p, slot, item, action) -> {
int channeln = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY)) + 1;
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) {
if (channeln > 16) channeln = 0;
}
else {
if (channeln > 15) channeln = 0;
}
BlockStorage.addBlockInfo(b, FREQUENCY, String.valueOf(channeln));
updateBlockMenu(menu, b);
return false;
});
}
}

View File

@ -7,7 +7,6 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
@ -20,83 +19,20 @@ import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
public class CargoOutputNode extends SlimefunItem {
public class CargoOutputNode extends AbstractCargoNode {
private final int[] border = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 };
private static final int[] BORDER = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 };
public CargoOutputNode(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
super(category, item, recipeType, recipe, recipeOutput);
new BlockMenuPreset(getID(), "&6Output Node") {
@Override
public void init() {
constructMenu(this);
}
@Override
public void newInstance(BlockMenu menu, Block b) {
menu.replaceExistingItem(12, new CustomItem(SlimefunUtils.getCustomHead("f2599bd986659b8ce2c4988525c94e19ddd39fad08a38284a197f1b70675acc"), "&bChannel", "", "&e> Click to decrease the Channel ID by 1"));
menu.addMenuClickHandler(12, (p, slot, item, action) -> {
int channel = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) - 1;
if (channel < 0) {
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) channel = 16;
else channel = 15;
}
BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channel));
newInstance(menu, b);
return false;
});
int channel = ((!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "frequency") == null) ? 0 : (Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency"))));
if (channel == 16) {
menu.replaceExistingItem(13, new CustomItem(SlimefunUtils.getCustomHead("7a44ff3a5f49c69cab676bad8d98a063fa78cfa61916fdef3e267557fec18283"), "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(13, ChestMenuUtils.getEmptyClickHandler());
}
else {
menu.replaceExistingItem(13, new CustomItem(MaterialCollections.getAllWoolColors().get(channel), "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(13, ChestMenuUtils.getEmptyClickHandler());
}
menu.replaceExistingItem(14, new CustomItem(SlimefunUtils.getCustomHead("c2f910c47da042e4aa28af6cc81cf48ac6caf37dab35f88db993accb9dfe516"), "&bChannel", "", "&e> Click to increase the Channel ID by 1"));
menu.addMenuClickHandler(14, (p, slot, item, action) -> {
int channeln = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "frequency")) + 1;
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) {
if (channeln > 16) channeln = 0;
}
else {
if (channeln > 15) channeln = 0;
}
BlockStorage.addBlockInfo(b, "frequency", String.valueOf(channeln));
newInstance(menu, b);
return false;
});
}
@Override
public boolean canOpen(Block b, Player p) {
return p.hasPermission("slimefun.cargo.bypass") || SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.ACCESS_INVENTORIES);
}
@Override
public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
return new int[0];
}
};
registerBlockHandler(getID(), new SlimefunBlockHandler() {
@Override
public void onPlace(Player p, Block b, SlimefunItem item) {
BlockStorage.addBlockInfo(b, "owner", p.getUniqueId().toString());
BlockStorage.addBlockInfo(b, "frequency", "0");
BlockStorage.addBlockInfo(b, FREQUENCY, "0");
}
@Override
@ -106,10 +42,55 @@ public class CargoOutputNode extends SlimefunItem {
});
}
private void constructMenu(BlockMenuPreset preset) {
for (int i : border) {
@Override
protected void createBorder(BlockMenuPreset preset) {
for (int i : BORDER) {
preset.addItem(i, new CustomItem(Material.CYAN_STAINED_GLASS_PANE, " "), ChestMenuUtils.getEmptyClickHandler());
}
}
@Override
protected void updateBlockMenu(BlockMenu menu, Block b) {
menu.replaceExistingItem(12, new CustomItem(SlimefunUtils.getCustomHead("f2599bd986659b8ce2c4988525c94e19ddd39fad08a38284a197f1b70675acc"), "&bChannel", "", "&e> Click to decrease the Channel ID by 1"));
menu.addMenuClickHandler(12, (p, slot, item, action) -> {
int channel = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY)) - 1;
if (channel < 0) {
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) channel = 16;
else channel = 15;
}
BlockStorage.addBlockInfo(b, FREQUENCY, String.valueOf(channel));
updateBlockMenu(menu, b);
return false;
});
int channel = ((!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY) == null) ? 0 : (Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY))));
if (channel == 16) {
menu.replaceExistingItem(13, new CustomItem(SlimefunUtils.getCustomHead("7a44ff3a5f49c69cab676bad8d98a063fa78cfa61916fdef3e267557fec18283"), "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(13, ChestMenuUtils.getEmptyClickHandler());
}
else {
menu.replaceExistingItem(13, new CustomItem(MaterialCollections.getAllWoolColors().get(channel), "&bChannel ID: &3" + (channel + 1)));
menu.addMenuClickHandler(13, ChestMenuUtils.getEmptyClickHandler());
}
menu.replaceExistingItem(14, new CustomItem(SlimefunUtils.getCustomHead("c2f910c47da042e4aa28af6cc81cf48ac6caf37dab35f88db993accb9dfe516"), "&bChannel", "", "&e> Click to increase the Channel ID by 1"));
menu.addMenuClickHandler(14, (p, slot, item, action) -> {
int channeln = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), FREQUENCY)) + 1;
if (SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled()) {
if (channeln > 16) channeln = 0;
}
else {
if (channeln > 15) channeln = 0;
}
BlockStorage.addBlockInfo(b, FREQUENCY, String.valueOf(channeln));
updateBlockMenu(menu, b);
return false;
});
}
}

View File

@ -120,46 +120,38 @@ public abstract class CropGrowthAccelerator extends SlimefunItem implements Inve
protected void tick(Block b) {
BlockMenu inv = BlockStorage.getInventory(b);
if (work(b, inv) > 0) {
for (int slot : getInputSlots()) {
if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFertilizer, false)) {
inv.consumeItem(slot);
break;
}
}
}
}
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
for (int x = -getRadius(); x <= getRadius(); x++) {
for (int z = -getRadius(); z <= getRadius(); z++) {
Block block = b.getRelative(x, 0, z);
private int work(Block b, BlockMenu inv) {
int work = 0;
for (int x = -getRadius(); x <= getRadius(); x++) {
for (int z = -getRadius(); z <= getRadius(); z++) {
Block block = b.getRelative(x, 0, z);
if (crops.contains(block.getType())) {
Ageable ageable = (Ageable) block.getBlockData();
if (ageable.getAge() < ageable.getMaximumAge()) {
for (int slot : getInputSlots()) {
if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFertilizer, false)) {
if (work > (getSpeed() - 1) || ChargableBlock.getCharge(b) < getEnergyConsumption()) return work;
ChargableBlock.addCharge(b, -getEnergyConsumption());
ageable.setAge(ageable.getAge() + 1);
block.setBlockData(ageable);
block.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, block.getLocation().add(0.5D, 0.5D, 0.5D), 4, 0.1F, 0.1F, 0.1F);
work++;
return work;
}
}
if (crops.contains(block.getType()) && grow(b, inv, block)) {
return;
}
}
}
}
}
return work;
private boolean grow(Block machine, BlockMenu inv, Block crop) {
Ageable ageable = (Ageable) crop.getBlockData();
if (ageable.getAge() < ageable.getMaximumAge()) {
for (int slot : getInputSlots()) {
if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFertilizer, false)) {
ChargableBlock.addCharge(machine, -getEnergyConsumption());
inv.consumeItem(slot);
ageable.setAge(ageable.getAge() + 1);
crop.setBlockData(ageable);
crop.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, crop.getLocation().add(0.5D, 0.5D, 0.5D), 4, 0.1F, 0.1F, 0.1F);
return true;
}
}
}
return false;
}
}

View File

@ -1,25 +1,14 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
public abstract class Refinery extends AContainer implements RecipeDisplayItem {
@ -27,6 +16,11 @@ public abstract class Refinery extends AContainer implements RecipeDisplayItem {
super(category, item, recipeType, recipe);
}
@Override
protected void registerDefaultRecipes() {
registerRecipe(40, SlimefunItems.OIL_BUCKET, SlimefunItems.FUEL_BUCKET);
}
@Override
public String getInventoryTitle() {
return "&cRefinery";
@ -42,55 +36,4 @@ public abstract class Refinery extends AContainer implements RecipeDisplayItem {
return "REFINERY";
}
@Override
public List<ItemStack> getDisplayRecipes() {
return Arrays.asList(SlimefunItems.OIL_BUCKET, SlimefunItems.FUEL_BUCKET);
}
@Override
protected void tick(Block b) {
BlockMenu menu = BlockStorage.getInventory(b);
if (isProcessing(b)) {
int timeleft = progress.get(b);
if (timeleft > 0) {
ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar());
if (ChargableBlock.isChargable(b)) {
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
return;
}
ChargableBlock.addCharge(b, -getEnergyConsumption());
progress.put(b, timeleft - 1);
}
else progress.put(b, timeleft - 1);
}
else {
menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "));
menu.pushItem(processing.get(b).getOutput()[0], getOutputSlots());
progress.remove(b);
processing.remove(b);
}
}
else {
for (int slot : getInputSlots()) {
if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), SlimefunItems.OIL_BUCKET, true)) {
if (!menu.fits(SlimefunItems.FUEL_BUCKET, getOutputSlots())) {
return;
}
MachineRecipe recipe = new MachineRecipe(40, new ItemStack[0], new ItemStack[] { SlimefunItems.FUEL_BUCKET });
menu.consumeItem(slot);
processing.put(b, recipe);
progress.put(b, recipe.getTicks());
break;
}
}
}
}
}

View File

@ -112,46 +112,38 @@ public class TreeGrowthAccelerator extends SlimefunItem implements InventoryBloc
protected void tick(Block b) {
BlockMenu inv = BlockStorage.getInventory(b);
if (work(b, inv) > 0) {
for (int slot : getInputSlots()) {
if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFertilizer, false)) {
inv.consumeItem(slot);
break;
}
}
}
}
if (ChargableBlock.getCharge(b) < ENERGY_CONSUMPTION) {
for (int x = -RADIUS; x <= RADIUS; x++) {
for (int z = -RADIUS; z <= RADIUS; z++) {
Block block = b.getRelative(x, 0, z);
private int work(Block b, BlockMenu inv) {
int work = 0;
if (Tag.SAPLINGS.isTagged(block.getType())) {
Sapling sapling = (Sapling) block.getBlockData();
for (int x = -RADIUS; x <= RADIUS; x++) {
for (int z = -RADIUS; z <= RADIUS; z++) {
Block block = b.getRelative(x, 0, z);
if (Tag.SAPLINGS.isTagged(block.getType())) {
Sapling sapling = (Sapling) block.getBlockData();
if (sapling.getStage() < sapling.getMaximumStage()) {
for (int slot : getInputSlots()) {
if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFertilizer, false)) {
if (work > 3 || ChargableBlock.getCharge(b) < ENERGY_CONSUMPTION) return work;
ChargableBlock.addCharge(b, -ENERGY_CONSUMPTION);
sapling.setStage(sapling.getStage() + 1);
block.setBlockData(sapling);
block.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, block.getLocation().add(0.5D, 0.5D, 0.5D), 4, 0.1F, 0.1F, 0.1F);
work++;
return work;
}
if (sapling.getStage() < sapling.getMaximumStage() && grow(b, block, inv, sapling)) {
return;
}
}
}
}
}
}
return work;
private boolean grow(Block machine, Block block, BlockMenu inv, Sapling sapling) {
for (int slot : getInputSlots()) {
if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFertilizer, false)) {
ChargableBlock.addCharge(machine, -ENERGY_CONSUMPTION);
sapling.setStage(sapling.getStage() + 1);
block.setBlockData(sapling);
inv.consumeItem(slot);
block.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, block.getLocation().add(0.5D, 0.5D, 0.5D), 4, 0.1F, 0.1F, 0.1F);
return true;
}
}
return false;
}
}

View File

@ -319,25 +319,13 @@ class ActiveMiner implements Runnable {
else if (block.getType() == Material.PISTON) {
Block above = block.getRelative(BlockFace.UP);
// Check if the above block is valid
if (above.isEmpty() || above.getType() == Material.PISTON_HEAD) {
Piston piston = (Piston) block.getBlockData();
// Check if the piston is actually facing upwards
if (piston.getFacing() == BlockFace.UP) {
piston.setExtended(extended);
block.setBlockData(piston, false);
// Updating the Piston Head
if (extended) {
PistonHead head = (PistonHead) Material.PISTON_HEAD.createBlockData();
head.setFacing(BlockFace.UP);
block.getRelative(BlockFace.UP).setBlockData(head, false);
}
else {
block.getRelative(BlockFace.UP).setType(Material.AIR);
}
block.getWorld().playSound(block.getLocation(), extended ? Sound.BLOCK_PISTON_EXTEND : Sound.BLOCK_PISTON_CONTRACT, 0.1F, 1F);
setExtended(block, piston, extended);
}
else {
// The pistons must be facing upwards
@ -360,4 +348,22 @@ class ActiveMiner implements Runnable {
}
}
private void setExtended(Block block, Piston piston, boolean extended) {
piston.setExtended(extended);
block.setBlockData(piston, false);
// Updating the Piston Head
if (extended) {
PistonHead head = (PistonHead) Material.PISTON_HEAD.createBlockData();
head.setFacing(BlockFace.UP);
block.getRelative(BlockFace.UP).setBlockData(head, false);
}
else {
block.getRelative(BlockFace.UP).setType(Material.AIR);
}
block.getWorld().playSound(block.getLocation(), extended ? Sound.BLOCK_PISTON_EXTEND : Sound.BLOCK_PISTON_CONTRACT, 0.1F, 1F);
}
}

View File

@ -65,7 +65,7 @@ public class AncientAltarTask implements Runnable {
this.running = true;
this.stage = 0;
for (Block pedestal : this.pedestals) {
for (Block pedestal : pedestals) {
Item item = listener.findItem(pedestal);
this.itemLock.put(item, item.getLocation().clone());
}
@ -135,7 +135,10 @@ public class AncientAltarTask implements Runnable {
private void abort() {
running = false;
pedestals.forEach(b -> listener.getAltarsInUse().remove(b.getLocation()));
for (Block b : pedestals) {
listener.getAltarsInUse().remove(b.getLocation());
}
// This should re-enable altar blocks on craft failure.
listener.getAltarsInUse().remove(altar.getLocation());
@ -156,7 +159,9 @@ public class AncientAltarTask implements Runnable {
dropLocation.getWorld().dropItemNaturally(dropLocation.add(0, -0.5, 0), event.getItem());
}
pedestals.forEach(b -> listener.getAltarsInUse().remove(b.getLocation()));
for (Block b : pedestals) {
listener.getAltarsInUse().remove(b.getLocation());
}
// This should re-enable altar blocks on craft completion.
listener.getAltarsInUse().remove(altar.getLocation());

View File

@ -87,7 +87,11 @@ public enum HeadTexture {
SCRIPT_FARM_FORWARD("4de9a522c3d9e7d85f3d82c375dc37fecc856dbd801eb3bcedc1165198bf"),
SCRIPT_FARM_DOWN("2d4296b333d25319af3f33051797f9e6d821cd19a014fb7137beb86a4e9e96"),
SCRIPT_PUSH_ITEMS("90a4dbf6625c42be57a8ba2c330954a76bdf22785540e87a5c9672685238ec"),
SCRIPT_PULL_FUEL("2432f5282a50745b912be14deda581bd4a09b977a3c32d7e9578491fee8fa7");
SCRIPT_PULL_FUEL("2432f5282a50745b912be14deda581bd4a09b977a3c32d7e9578491fee8fa7"),
GLOBE_OVERWORLD("c9c8881e42915a9d29bb61a16fb26d059913204d265df5b439b3d792acd56"),
GLOBE_NETHER("d83571ff589f1a59bb02b80800fc736116e27c3dcf9efebede8cf1fdde"),
GLOBE_THE_END("c6cac59b2aae489aa0687b5d802b2555eb14a40bd62b21eb116fa569cdb756"),
DEATHPOINT("1ae3855f952cd4a03c148a946e3f812a5955ad35cbcb52627ea4acd47d3081");
private final String texture;

View File

@ -43,6 +43,8 @@ import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
* exclusively used for Reactors.
*
* @author John000708
* @author AlexLander123
* @author TheBusyBiscuit
*
* @see AGenerator
* @see NuclearReactor
@ -54,7 +56,9 @@ public abstract class AReactor extends AbstractEnergyGenerator {
public static Map<Location, MachineFuel> processing = new HashMap<>();
public static Map<Location, Integer> progress = new HashMap<>();
private static final BlockFace[] coolantBlocks = { BlockFace.NORTH, BlockFace.NORTH_EAST, BlockFace.EAST, BlockFace.SOUTH_EAST, BlockFace.SOUTH, BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST };
private static final int INFO_SLOT = 49;
private static final int COOLANT_DURATION = 50;
private static final BlockFace[] WATER_BLOCKS = { BlockFace.NORTH, BlockFace.NORTH_EAST, BlockFace.EAST, BlockFace.SOUTH_EAST, BlockFace.SOUTH, BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST };
private static final int[] border = { 0, 1, 2, 3, 5, 6, 7, 8, 12, 13, 14, 21, 23 };
private static final int[] border_1 = { 9, 10, 11, 18, 20, 27, 29, 36, 38, 45, 46, 47 };
@ -63,7 +67,6 @@ public abstract class AReactor extends AbstractEnergyGenerator {
// No coolant border
private static final int[] border_4 = { 25, 34, 43 };
private static final int INFO_SLOT = 49;
public AReactor(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
@ -257,12 +260,12 @@ public abstract class AReactor extends AbstractEnergyGenerator {
protected GeneratorTicker onTick() {
return new GeneratorTicker() {
private final Set<Location> explode = new HashSet<>();
private final Set<Location> explosionsQueue = new HashSet<>();
@Override
public double generateEnergy(Location l, SlimefunItem sf, Config data) {
BlockMenu menu = BlockStorage.getInventory(l);
BlockMenu port = getAccessPort(l);
BlockMenu inv = BlockStorage.getInventory(l);
BlockMenu accessPort = getAccessPort(l);
int charge = ChargableBlock.getCharge(l);
if (isProcessing(l)) {
@ -275,20 +278,12 @@ public abstract class AReactor extends AbstractEnergyGenerator {
if (space >= produced || !"generator".equals(BlockStorage.getLocationInfo(l, "reactor-mode"))) {
progress.put(l, timeleft - 1);
checkForWaterBlocks(l);
Slimefun.runSync(() -> {
// We will pick a surrounding block at random and see if this is water.
// If it isn't, then we will make it explode.
BlockFace randomNeighbour = coolantBlocks[ThreadLocalRandom.current().nextInt(coolantBlocks.length)];
if (l.getBlock().getRelative(randomNeighbour).getType() != Material.WATER) {
explode.add(l);
}
});
ChestMenuUtils.updateProgressbar(inv, 22, timeleft, processing.get(l).getTicks(), getProgressBar());
ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(l).getTicks(), getProgressBar());
if (needsCooling() && !isProperlyCooled(l, menu, port, timeleft)) {
explode.add(l);
if (needsCooling() && !hasSufficientCoolant(l, inv, accessPort, timeleft)) {
explosionsQueue.add(l);
return 0;
}
}
@ -302,49 +297,19 @@ public abstract class AReactor extends AbstractEnergyGenerator {
}
}
else {
menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "));
if (processing.get(l).getOutput() != null) {
menu.pushItem(processing.get(l).getOutput(), getOutputSlots());
}
if (port != null) {
for (int slot : getOutputSlots()) {
if (menu.getItemInSlot(slot) != null) {
menu.replaceExistingItem(slot, port.pushItem(menu.getItemInSlot(slot), ReactorAccessPort.getOutputSlots()));
}
}
}
progress.remove(l);
processing.remove(l);
createByproduct(l, inv, accessPort);
return charge;
}
}
else {
Map<Integer, Integer> found = new HashMap<>();
MachineFuel fuel = findRecipe(menu, found);
if (port != null) {
restockFuel(menu, port);
}
if (fuel != null) {
for (Map.Entry<Integer, Integer> entry : found.entrySet()) {
menu.consumeItem(entry.getKey(), entry.getValue());
}
processing.put(l, fuel);
progress.put(l, fuel.getTicks());
}
burnNextFuel(l, inv, accessPort);
return charge;
}
}
@Override
public boolean explode(Location l) {
boolean explosion = explode.contains(l);
boolean explosion = explosionsQueue.contains(l);
if (explosion) {
Slimefun.runSync(() -> {
@ -352,15 +317,65 @@ public abstract class AReactor extends AbstractEnergyGenerator {
SimpleHologram.remove(l.getBlock());
});
explode.remove(l);
explosionsQueue.remove(l);
processing.remove(l);
progress.remove(l);
}
return explosion;
}
private void checkForWaterBlocks(Location l) {
Slimefun.runSync(() -> {
// We will pick a surrounding block at random and see if this is water.
// If it isn't, then we will make it explode.
BlockFace randomNeighbour = WATER_BLOCKS[ThreadLocalRandom.current().nextInt(WATER_BLOCKS.length)];
if (l.getBlock().getRelative(randomNeighbour).getType() != Material.WATER) {
explosionsQueue.add(l);
}
});
}
};
}
private void createByproduct(Location l, BlockMenu inv, BlockMenu accessPort) {
inv.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "));
if (processing.get(l).getOutput() != null) {
inv.pushItem(processing.get(l).getOutput(), getOutputSlots());
}
if (accessPort != null) {
for (int slot : getOutputSlots()) {
if (inv.getItemInSlot(slot) != null) {
inv.replaceExistingItem(slot, accessPort.pushItem(inv.getItemInSlot(slot), ReactorAccessPort.getOutputSlots()));
}
}
}
progress.remove(l);
processing.remove(l);
}
private void burnNextFuel(Location l, BlockMenu inv, BlockMenu accessPort) {
Map<Integer, Integer> found = new HashMap<>();
MachineFuel fuel = findFuel(inv, found);
if (accessPort != null) {
restockFuel(inv, accessPort);
}
if (fuel != null) {
for (Map.Entry<Integer, Integer> entry : found.entrySet()) {
inv.consumeItem(entry.getKey(), entry.getValue());
}
processing.put(l, fuel);
progress.put(l, fuel.getTicks());
}
}
/**
* This method cools the given {@link AReactor}.
*
@ -368,21 +383,21 @@ public abstract class AReactor extends AbstractEnergyGenerator {
* The {@link Location} of this {@link AReactor}
* @param menu
* The {@link Inventory} of this {@link AReactor}
* @param port
* @param accessPort
* The {@link ReactorAccessPort}, if available
* @param timeleft
* The time left
*
* @return Whether the {@link AReactor} was successfully cooled, if not it should explode
*/
private boolean isProperlyCooled(Location reactor, BlockMenu menu, BlockMenu port, int timeleft) {
boolean coolant = (processing.get(reactor).getTicks() - timeleft) % 25 == 0;
private boolean hasSufficientCoolant(Location reactor, BlockMenu menu, BlockMenu accessPort, int timeleft) {
boolean coolant = (processing.get(reactor).getTicks() - timeleft) % COOLANT_DURATION == 0;
if (coolant) {
if (port != null) {
if (accessPort != null) {
for (int slot : getCoolantSlots()) {
if (SlimefunUtils.isItemSimilar(port.getItemInSlot(slot), getCoolant(), true)) {
port.replaceExistingItem(slot, menu.pushItem(port.getItemInSlot(slot), getCoolantSlots()));
if (SlimefunUtils.isItemSimilar(accessPort.getItemInSlot(slot), getCoolant(), true)) {
accessPort.replaceExistingItem(slot, menu.pushItem(accessPort.getItemInSlot(slot), getCoolantSlots()));
}
}
}
@ -405,14 +420,14 @@ public abstract class AReactor extends AbstractEnergyGenerator {
}
private float getPercentage(int time, int total) {
int passed = ((total - time) % 25);
return Math.round(((((25 - passed) * 100.0F) / 25) * 100.0F) / 100.0F);
int passed = ((total - time) % COOLANT_DURATION);
return Math.round(((((COOLANT_DURATION - passed) * 100.0F) / COOLANT_DURATION) * 100.0F) / 100.0F);
}
private void restockFuel(BlockMenu menu, BlockMenu port) {
for (int slot : getFuelSlots()) {
for (MachineFuel recipe : fuelTypes) {
if (SlimefunUtils.isItemSimilar(port.getItemInSlot(slot), recipe.getInput(), true) && menu.fits(new CustomItem(port.getItemInSlot(slot), 1), getFuelSlots())) {
for (MachineFuel fuelType : fuelTypes) {
if (fuelType.test(port.getItemInSlot(slot)) && menu.fits(new CustomItem(port.getItemInSlot(slot), 1), getFuelSlots())) {
port.replaceExistingItem(slot, menu.pushItem(port.getItemInSlot(slot), getFuelSlots()));
return;
}
@ -420,7 +435,7 @@ public abstract class AReactor extends AbstractEnergyGenerator {
}
}
private MachineFuel findRecipe(BlockMenu menu, Map<Integer, Integer> found) {
private MachineFuel findFuel(BlockMenu menu, Map<Integer, Integer> found) {
for (MachineFuel fuel : fuelTypes) {
for (int slot : getInputSlots()) {
if (fuel.test(menu.getItemInSlot(slot))) {

View File

@ -14,6 +14,7 @@ import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
// This interface should be reconsidered and moved at some point too
public interface InventoryBlock {
/**

View File

@ -1,5 +1,6 @@
package io.github.thebusybiscuit.slimefun4.testing.tests.utils;
import org.bukkit.ChatColor;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@ -22,4 +23,11 @@ public class TestChatUtils {
Assertions.assertEquals(expected, ChatUtils.christmas(input));
}
@Test
public void testColorCodeRemoval() {
String expected = "Hello world";
Assertions.assertEquals(expected, ChatUtils.removeColorCodes("&4&lHello &6world"));
Assertions.assertEquals(expected, ChatUtils.removeColorCodes(ChatColor.GREEN + "Hello " + ChatColor.RED + "world"));
}
}