Skip to content

Commit

Permalink
Fixed some crafting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
NCBPFluffyBear committed Jan 18, 2021
1 parent 9da490f commit c0779e5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 26 deletions.
Expand Up @@ -16,15 +16,25 @@
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.BlastingRecipe;
import org.bukkit.inventory.CampfireRecipe;
import org.bukkit.inventory.CookingRecipe;
import org.bukkit.inventory.FurnaceRecipe;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Merchant;
import org.bukkit.inventory.MerchantRecipe;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.RecipeChoice;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.ShapelessRecipe;
import org.bukkit.inventory.SmithingRecipe;
import org.bukkit.inventory.SmokingRecipe;
import org.bukkit.inventory.StonecuttingRecipe;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.RayTraceResult;

Expand Down Expand Up @@ -86,9 +96,14 @@ public void onEnable() {
shapedVanillaRecipes.put(new ItemStack(sr.getResult().getType(), 1), new Pair<>(sr.getResult(), rc));
} else if (r instanceof ShapelessRecipe) {
ShapelessRecipe slr = (ShapelessRecipe) r;
shapelessVanillaRecipes.put(new ItemStack(slr.getResult().getType(), 1), new Pair<>(slr.getResult(), slr.getChoiceList()));
if (slr.getResult().getType() == Material.NETHERITE_INGOT && slr.getResult().getAmount() == 9) {
shapelessVanillaRecipes.put(new ItemStack(slr.getResult().getType(), 9), new Pair<>(slr.getResult(), slr.getChoiceList()));
} else {
shapelessVanillaRecipes.put(new ItemStack(slr.getResult().getType(), 1), new Pair<>(slr.getResult(), slr.getChoiceList()));
}
}
}

// Registering Items
FluffyItemSetup.setup(this);

Expand Down
Expand Up @@ -22,6 +22,7 @@
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
import me.mrCookieSlime.Slimefun.cscorelib2.item.CustomItem;
import me.mrCookieSlime.Slimefun.cscorelib2.protection.ProtectableAction;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
Expand Down Expand Up @@ -165,6 +166,12 @@ private Comparator<Integer> compareSlots(DirtyChestMenu menu) {
protected void constructMenu(BlockMenuPreset preset) {
AutoAncientAltar.borders(preset, border, inputBorder, outputBorder);

preset.addItem(0, new CustomItem(new ItemStack(Material.RED_STAINED_GLASS_PANE),
"&c&lIMPORTANT",
"&cMake sure you have only 1 key item",
"&cunless you are crafting Netherite Ingots",
"&cfrom Netherite Blocks. Use 9 instead."));

for (int i : keyBorder) {
preset.addItem(i, new CustomItem(new ItemStack(Material.YELLOW_STAINED_GLASS_PANE), "&e&lKey Item Slot"),
(p, slot, item, action) -> false);
Expand Down Expand Up @@ -283,7 +290,7 @@ private void getResult(Block block) {
return;
}

List<Material> existingMats = new ArrayList<>();
List<ItemStack> existingItems = new ArrayList<>();
int blankCounter = 0;

// Put each input item into the array
Expand All @@ -305,7 +312,7 @@ private void getResult(Block block) {
continue;
}

Material existingMat = slotItem.getType();
ItemStack existingItem = new ItemStack(slotItem.getType());

// Checks if each slot has at least 1 item
if (slotItem.getAmount() == 1) {
Expand All @@ -317,47 +324,58 @@ private void getResult(Block block) {
return;
}

existingMats.add(existingMat);
existingItems.add(existingItem);

}

// New HashMap System
// This is semi-shapeless, since it reads left to right, top to bottom, and ignores empty spaces.
// However, this isn't a concern since we have the key item.
ItemStack craftingItem = new ItemStack(keyItem.getType(), 1);
boolean passOn = false;

if (FluffyMachines.shapedVanillaRecipes.containsKey(craftingItem)) {
List<RecipeChoice> rc = FluffyMachines.shapedVanillaRecipes.get(craftingItem).getSecondValue();
if (FluffyMachines.shapedVanillaRecipes.containsKey(keyItem)) {
List<RecipeChoice> rc = FluffyMachines.shapedVanillaRecipes.get(keyItem).getSecondValue();

if (existingMats.size() != rc.size()) {
if (existingItems.size() != rc.size()) {
if (menu.hasViewer()) {
menu.replaceExistingItem(statusSlot, new CustomItem(new ItemStack(Material.RED_STAINED_GLASS_PANE),
"&c&lIncorrect Recipe"));
}
return;
// The sizes don't match, but it can still be shapeless.
passOn = true;
}

for (int i = 0; i < rc.size(); i++) {
if (!rc.get(i).test(new ItemStack(existingMats.get(i)))) {
if (menu.hasViewer()) {
menu.replaceExistingItem(statusSlot, new CustomItem(new ItemStack(Material.RED_STAINED_GLASS_PANE),
"&c&lIncorrect Recipe"));
// If we already know this isn't a shaped recipe, no need to check.
if (!passOn) {
for (int i = 0; i < rc.size(); i++) {
if (!rc.get(i).test(existingItems.get(i))) {
if (menu.hasViewer()) {
menu.replaceExistingItem(statusSlot, new CustomItem(new ItemStack(Material.RED_STAINED_GLASS_PANE),
"&c&lIncorrect Recipe"));
}
// We need to pass on to shapeless in case the key is shapeless.
passOn = true;
break;
}
return;
}
}

// We found the entire recipe!
craft(menu, FluffyMachines.shapedVanillaRecipes.get(craftingItem).getFirstValue().clone());
// We found the entire recipe! No need to pass on.
if (!passOn) {
craft(menu, FluffyMachines.shapedVanillaRecipes.get(keyItem).getFirstValue().clone());
return;
}

}

} else if (FluffyMachines.shapelessVanillaRecipes.containsKey(craftingItem)) {
List<RecipeChoice> rc = FluffyMachines.shapelessVanillaRecipes.get(craftingItem).getSecondValue();
if (FluffyMachines.shapelessVanillaRecipes.containsKey(keyItem)) {
List<RecipeChoice> rc = FluffyMachines.shapelessVanillaRecipes.get(keyItem).getSecondValue();
List<RecipeChoice> rcCheck = new ArrayList<>(rc);
List<ItemStack> existingItems = new ArrayList<>();
for (Material mat : existingMats) {
// Skip all nulls
if (mat != null) {
existingItems.add(new ItemStack(mat));

if (existingItems.size() != rc.size()) {
if (menu.hasViewer()) {
menu.replaceExistingItem(statusSlot, new CustomItem(new ItemStack(Material.RED_STAINED_GLASS_PANE),
"&c&lIncorrect Recipe"));
}
}

Expand All @@ -378,15 +396,18 @@ private void getResult(Block block) {
new CustomItem(new ItemStack(Material.GREEN_STAINED_GLASS_PANE),
"&a&lCrafting"));
}
craft(menu, FluffyMachines.shapelessVanillaRecipes.get(craftingItem).getFirstValue().clone());
craft(menu, FluffyMachines.shapelessVanillaRecipes.get(keyItem).getFirstValue().clone());

} else {
if (menu.hasViewer()) {
menu.replaceExistingItem(statusSlot, new CustomItem(new ItemStack(Material.RED_STAINED_GLASS_PANE),
"&c&lIncorrect Recipe"));
}
}
} else if (menu.hasViewer()) {
return;
}

if (menu.hasViewer()) {
menu.replaceExistingItem(statusSlot, new CustomItem(new ItemStack(Material.RED_STAINED_GLASS_PANE),
"&c&lInvalid Key!"));
}
Expand Down

0 comments on commit c0779e5

Please sign in to comment.