mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Merge branch 'chore/cleanup-deprecated-crafter'
This commit is contained in:
commit
e3171b37dc
@ -29,6 +29,7 @@
|
||||
* Added Enhanced Auto Crafter
|
||||
|
||||
#### Changes
|
||||
* Removed all functionality from the old Automated Crafting Chamber
|
||||
* Changed item order in guide for the Villager Rune and Nether Goo (All runes are now grouped together)
|
||||
|
||||
#### Fixes
|
||||
|
@ -3,9 +3,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machine
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
@ -23,19 +21,14 @@ import io.github.thebusybiscuit.slimefun4.api.events.BlockPlacerPlaceEvent;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.EnhancedCraftingTable;
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.auto_crafters.AbstractAutoCrafter;
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu.AdvancedMenuClickHandler;
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ClickAction;
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItemSerializer;
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItemSerializer.ItemFlag;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
||||
@ -47,7 +40,7 @@ import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
|
||||
* This class needs to be rewritten VERY BADLY.
|
||||
* But we should focus on rewriting the recipe system first.
|
||||
*
|
||||
* @deprecated This is horribly done. Someone needs to rewrite this.
|
||||
* @deprecated This has been replaced by the {@link AbstractAutoCrafter}.
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
@ -58,13 +51,11 @@ public abstract class AutomatedCraftingChamber extends SlimefunItem implements I
|
||||
private final int[] inputBorder = { 9, 10, 11, 12, 13, 18, 22, 27, 31, 36, 40, 45, 46, 47, 48, 49 };
|
||||
private final int[] outputBorder = { 23, 24, 25, 26, 32, 35, 41, 42, 43, 44 };
|
||||
|
||||
private final Map<String, ItemStack> craftingRecipes = new HashMap<>();
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public AutomatedCraftingChamber(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
||||
super(category, item, recipeType, recipe);
|
||||
|
||||
new BlockMenuPreset(getId(), "&4Deprecated item. Do not use.") {
|
||||
new BlockMenuPreset(getId(), "&4Machine is disabled.") {
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
@ -88,17 +79,11 @@ public abstract class AutomatedCraftingChamber extends SlimefunItem implements I
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
menu.replaceExistingItem(7, new CustomItem(Material.CRAFTING_TABLE, "&7Craft Last", "", "&e> Click to craft the last shaped recipe", "&cOnly works with the last one"));
|
||||
menu.addMenuClickHandler(7, (p, slot, item, action) -> {
|
||||
tick(b, true);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canOpen(Block b, Player p) {
|
||||
p.sendMessage(ChatColor.DARK_RED + "This item has been deprecated. It will be removed soon!");
|
||||
p.sendMessage(ChatColor.DARK_RED + "This item has been disabled and will be removed soon. Please switch over to the new Auto Crafters in the Cargo Category.");
|
||||
return p.hasPermission("slimefun.inventory.bypass") || SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.INTERACT_BLOCK);
|
||||
}
|
||||
|
||||
@ -150,7 +135,7 @@ public abstract class AutomatedCraftingChamber extends SlimefunItem implements I
|
||||
|
||||
@Override
|
||||
public void onPlayerPlace(BlockPlaceEvent e) {
|
||||
e.getPlayer().sendMessage(ChatColor.DARK_RED + "This item has been deprecated. It will be removed soon!");
|
||||
e.getPlayer().sendMessage(ChatColor.DARK_RED + "This item has been disabled and will be removed soon. Please switch over to the new Auto Crafters in the Cargo Category.");
|
||||
BlockStorage.addBlockInfo(e.getBlock(), "enabled", String.valueOf(false));
|
||||
}
|
||||
|
||||
@ -212,106 +197,4 @@ public abstract class AutomatedCraftingChamber extends SlimefunItem implements I
|
||||
public EnergyNetComponentType getEnergyComponentType() {
|
||||
return EnergyNetComponentType.CONSUMER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preRegister() {
|
||||
addItemHandler(new BlockTicker() {
|
||||
|
||||
@Override
|
||||
public void tick(Block b, SlimefunItem sf, Config data) {
|
||||
AutomatedCraftingChamber.this.tick(b, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSynchronized() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void tick(Block block, boolean craftLast) {
|
||||
if (!craftLast && BlockStorage.getLocationInfo(block.getLocation(), "enabled").equals(String.valueOf(false))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getCharge(block.getLocation()) < getEnergyConsumption()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String input = getSerializedInput(block, craftLast);
|
||||
testInputAgainstRecipes(block, input);
|
||||
}
|
||||
|
||||
private String getSerializedInput(Block block, boolean craftLast) {
|
||||
BlockMenu menu = BlockStorage.getInventory(block);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int i = 0;
|
||||
boolean lastIteration = false;
|
||||
|
||||
for (int j = 0; j < 9; j++) {
|
||||
if (i > 0) {
|
||||
builder.append(" </slot> ");
|
||||
}
|
||||
|
||||
ItemStack item = menu.getItemInSlot(getInputSlots()[j]);
|
||||
|
||||
if (item != null && item.getAmount() == 1) {
|
||||
if (craftLast) {
|
||||
lastIteration = true;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
builder.append(CustomItemSerializer.serialize(item, ItemFlag.MATERIAL, ItemFlag.ITEMMETA_DISPLAY_NAME, ItemFlag.ITEMMETA_LORE));
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
// we're only executing the last possible shaped recipe
|
||||
// we don't want to allow this to be pressed instead of the default timer-based
|
||||
// execution to prevent abuse and auto clickers
|
||||
if (craftLast && !lastIteration) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private void testInputAgainstRecipes(Block block, String input) {
|
||||
BlockMenu menu = BlockStorage.getInventory(block);
|
||||
|
||||
ItemStack output = craftingRecipes.get(input);
|
||||
if (output != null && menu.fits(output, getOutputSlots())) {
|
||||
menu.pushItem(output.clone(), getOutputSlots());
|
||||
removeCharge(block.getLocation(), getEnergyConsumption());
|
||||
|
||||
for (int j = 0; j < 9; j++) {
|
||||
if (menu.getItemInSlot(getInputSlots()[j]) != null) {
|
||||
menu.consumeItem(getInputSlots()[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void loadRecipes() {
|
||||
EnhancedCraftingTable machine = (EnhancedCraftingTable) SlimefunItems.ENHANCED_CRAFTING_TABLE.getItem();
|
||||
|
||||
for (ItemStack[] inputs : RecipeType.getRecipeInputList(machine)) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int i = 0;
|
||||
|
||||
for (ItemStack item : inputs) {
|
||||
if (i > 0) {
|
||||
builder.append(" </slot> ");
|
||||
}
|
||||
|
||||
builder.append(CustomItemSerializer.serialize(item, ItemFlag.MATERIAL, ItemFlag.ITEMMETA_DISPLAY_NAME, ItemFlag.ITEMMETA_LORE));
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
craftingRecipes.put(builder.toString(), RecipeType.getRecipeOutputList(machine, inputs));
|
||||
}
|
||||
}
|
||||
}
|
@ -27,7 +27,6 @@ import com.google.gson.JsonParser;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AutomatedCraftingChamber;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.GrindStone;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.MakeshiftSmeltery;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.OreCrusher;
|
||||
@ -78,7 +77,6 @@ public final class PostSetup {
|
||||
}
|
||||
}
|
||||
|
||||
loadAutomaticCraftingChamber();
|
||||
loadOreGrinderRecipes();
|
||||
loadSmelteryRecipes();
|
||||
|
||||
@ -128,14 +126,6 @@ public final class PostSetup {
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
private static void loadAutomaticCraftingChamber() {
|
||||
AutomatedCraftingChamber crafter = (AutomatedCraftingChamber) SlimefunItems.AUTOMATED_CRAFTING_CHAMBER.getItem();
|
||||
|
||||
if (crafter != null) {
|
||||
crafter.loadRecipes();
|
||||
}
|
||||
}
|
||||
|
||||
private static void loadOreGrinderRecipes() {
|
||||
List<ItemStack[]> grinderRecipes = new ArrayList<>();
|
||||
|
||||
|
@ -218,7 +218,6 @@ public final class ResearchSetup {
|
||||
register("cargo_nodes", 206, "Cargo Setup", 30, SlimefunItems.CARGO_INPUT_NODE, SlimefunItems.CARGO_OUTPUT_NODE);
|
||||
register("electric_ingot_machines", 207, "Electric Ingot Fabrication", 18, SlimefunItems.ELECTRIC_GOLD_PAN, SlimefunItems.ELECTRIC_DUST_WASHER, SlimefunItems.ELECTRIC_INGOT_FACTORY);
|
||||
register("high_tier_electric_ingot_machines", 209, "Super Fast Ingot Fabrication", 32, SlimefunItems.ELECTRIC_GOLD_PAN_3, SlimefunItems.ELECTRIC_DUST_WASHER_3, SlimefunItems.ELECTRIC_INGOT_FACTORY_3, SlimefunItems.ELECTRIC_ORE_GRINDER_2, SlimefunItems.ELECTRIC_ORE_GRINDER_3);
|
||||
register("automated_crafting_chamber", 210, "Automated Crafting", 20, SlimefunItems.AUTOMATED_CRAFTING_CHAMBER);
|
||||
register("better_food_fabricator", 211, "Upgraded Food Fabrication", 28, SlimefunItems.FOOD_FABRICATOR_2, SlimefunItems.FOOD_COMPOSTER_2);
|
||||
register("reactor_access_port", 212, "Reactor Interaction", 18, SlimefunItems.REACTOR_ACCESS_PORT);
|
||||
register("fluid_pump", 213, "Fluid Pump", 28, SlimefunItems.FLUID_PUMP);
|
||||
|
@ -109,9 +109,9 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting.AutoDisenchanter;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting.AutoEnchanter;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting.BookBinder;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.entities.ExpCollector;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.entities.IronGolemAssembler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.entities.WitherAssembler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.entities.ExpCollector;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.reactors.NetherStarReactor;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.reactors.NuclearReactor;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.elevator.ElevatorPlate;
|
||||
@ -2476,7 +2476,7 @@ public final class SlimefunItemSetup {
|
||||
.register(plugin);
|
||||
|
||||
new AutomatedCraftingChamber(categories.electricity, SlimefunItems.AUTOMATED_CRAFTING_CHAMBER, RecipeType.ENHANCED_CRAFTING_TABLE,
|
||||
new ItemStack[] {null, new ItemStack(Material.CRAFTING_TABLE), null, SlimefunItems.CARGO_MOTOR, SlimefunItems.BLISTERING_INGOT_3, SlimefunItems.CARGO_MOTOR, null, SlimefunItems.ELECTRIC_MOTOR, null}) {
|
||||
new ItemStack[] {null, null, null, null, new CustomItem(Material.BARRIER, "&4This Item has been disabled.", "&cIt will soon be removed!", "&cPlease switch over to the new", "&cAuto-Crafters from the Cargo Category."), null, null, null, null}) {
|
||||
|
||||
@Override
|
||||
public int getEnergyConsumption() {
|
||||
|
@ -1,117 +0,0 @@
|
||||
package me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* An old remnant of CS-CoreLib.
|
||||
* This will be removed once we updated everything.
|
||||
* Don't look at the code, it will be gone soon, don't worry.
|
||||
*
|
||||
* @deprecated This was a horrible idea. Don't use it.
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
public class CustomItemSerializer {
|
||||
|
||||
public enum ItemFlag {
|
||||
|
||||
MATERIAL(0),
|
||||
DATA(1),
|
||||
AMOUNT(2),
|
||||
DURABILITY(3),
|
||||
ENCHANTMENTS(4),
|
||||
ITEMMETA_DISPLAY_NAME(5),
|
||||
ITEMMETA_LORE(6);
|
||||
|
||||
private int weight;
|
||||
|
||||
ItemFlag(int weight) {
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public int getWeight() {
|
||||
return this.weight;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static ItemFlagComparator comparator = new ItemFlagComparator();
|
||||
|
||||
public static String serialize(ItemStack item, ItemFlag... flags) {
|
||||
if (item == null)
|
||||
return "NULL";
|
||||
List<ItemFlag> flaglist = Arrays.asList(flags);
|
||||
|
||||
Collections.sort(flaglist, comparator);
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
int i = 0;
|
||||
for (ItemFlag flag : flags) {
|
||||
if (i > 0)
|
||||
builder.append(" </sep> ");
|
||||
builder.append(flag.toString() + "=");
|
||||
|
||||
switch (flag) {
|
||||
case AMOUNT: {
|
||||
builder.append(item.getAmount());
|
||||
break;
|
||||
}
|
||||
case DATA: {
|
||||
builder.append((int) item.getData().getData());
|
||||
break;
|
||||
}
|
||||
case DURABILITY: {
|
||||
builder.append((int) item.getDurability());
|
||||
break;
|
||||
}
|
||||
case ENCHANTMENTS:
|
||||
for (Enchantment enchantment : Enchantment.values()) {
|
||||
if (item.getEnchantments().containsKey(enchantment)) {
|
||||
builder.append(enchantment.getName() + ":" + item.getEnchantmentLevel(enchantment));
|
||||
} else {
|
||||
builder.append(enchantment.getName() + ":0");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ITEMMETA_DISPLAY_NAME: {
|
||||
if (item.hasItemMeta() && item.getItemMeta().hasDisplayName()) {
|
||||
builder.append(item.getItemMeta().getDisplayName().replaceAll("\\u00a7", "&"));
|
||||
} else {
|
||||
builder.append("NONE");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ITEMMETA_LORE: {
|
||||
if (item.hasItemMeta() && item.getItemMeta().hasLore()) {
|
||||
builder.append(item.getItemMeta().getLore().toString().replaceAll("\\u00a7", "&"));
|
||||
} else {
|
||||
builder.append("NONE");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MATERIAL: {
|
||||
builder.append(item.getType().toString());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static boolean equals(ItemStack stack1, ItemStack stack2, ItemFlag... flags) {
|
||||
return serialize(stack1, flags).equals(serialize(stack2, flags));
|
||||
}
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItemSerializer.ItemFlag;
|
||||
|
||||
/**
|
||||
* An old remnant of CS-CoreLib.
|
||||
* This will be removed once we updated everything.
|
||||
* Don't look at the code, it will be gone soon, don't worry.
|
||||
*
|
||||
* @deprecated This was a horrible idea. Don't use it.
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
public class ItemFlagComparator implements Comparator<ItemFlag> {
|
||||
|
||||
@Override
|
||||
public int compare(ItemFlag flag1, ItemFlag flag2) {
|
||||
return flag1.getWeight() - flag2.getWeight();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user