Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class CraftingExtension implements ICraftingCategoryExtension {
Expand All @@ -23,10 +21,7 @@ public CraftingExtension(ProfessionRecipe recipe) {

@Override
public void setRecipe(IRecipeLayoutBuilder builder, ICraftingGridHelper craftingGridHelper, IFocusGroup focuses) {
List<List<ItemStack>> inputs = new ArrayList<>();
for (ItemStack m : recipe.getMaterials()) {
inputs.add(Arrays.asList(m));
}
List<List<ItemStack>> inputs = recipe.getMaterialsForJei();

ItemStack resultItem = recipe.toResultStackForJei();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.robertx22.mine_and_slash.database.data.profession;

import com.google.common.collect.ImmutableList;
import com.robertx22.library_of_exile.registry.ExileRegistryType;
import com.robertx22.library_of_exile.registry.IAutoGson;
import com.robertx22.library_of_exile.registry.JsonExileRegistry;
Expand All @@ -16,9 +17,13 @@
import com.robertx22.mine_and_slash.uncommon.utilityclasses.TooltipUtils;
import com.robertx22.temp.SkillItemTier;
import net.minecraft.ChatFormatting;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -128,23 +133,40 @@ public static class CraftingMaterial {
public Type type = Type.ITEM;

public boolean matches(ItemStack stack) {
if (type == Type.ITEM) {
return VanillaUTIL.REGISTRY.items().getKey(stack.getItem()).toString().equals(id) && stack.getCount() >= num;
}
return false;
if (stack.getCount() < num) return false;
return hasAnyCount(stack);
}

public boolean hasAnyCount(ItemStack stack) {
if (type == Type.ITEM) {
return VanillaUTIL.REGISTRY.items().getKey(stack.getItem()).toString().equals(id);
} else if (type == Type.TAG) {
return stack.is(TagKey.create(Registries.ITEM, new ResourceLocation(id)));
}
return false;
}

public ItemStack toStackForJei() {
return new ItemStack(VanillaUTIL.REGISTRY.items().get(new ResourceLocation(id)), num);
public List<ItemStack> toStackForJei() {
if (type == Type.ITEM) {
return List.of(new ItemStack(VanillaUTIL.REGISTRY.items().get(new ResourceLocation(id)), num));
} else if (type == Type.TAG) {
ImmutableList.Builder<ItemStack> builder = ImmutableList.builder();
for (Holder<Item> holder : BuiltInRegistries.ITEM.getTagOrEmpty(TagKey.create(Registries.ITEM, new ResourceLocation(id)))) {
builder.add(new ItemStack(holder.get(), num));
}
return builder.build();
}
return List.of();
}

public Component getDisplayName() {
if (type == Type.ITEM) {
return new ItemStack(VanillaUTIL.REGISTRY.items().get(new ResourceLocation(id)), num).getDisplayName();
} else if (type == Type.TAG) {
return Words.ANY_IN_TAG.locName(id);
}
return Component.literal("???");
}

public void spend(ItemStack stack) {
stack.shrink(num);
Expand Down Expand Up @@ -237,7 +259,7 @@ public ExplainedResult canCraft(List<ItemStack> stacks) {
}
if (stacks.stream().noneMatch(x -> mat.matches(x))) {
fail = true;
msg.append(reason.word.locName(mat.toStackForJei().getDisplayName(), mat.num, have));
msg.append(reason.word.locName(mat.getDisplayName(), mat.num, have));
}
}

Expand Down Expand Up @@ -271,8 +293,12 @@ public List<ItemStack> craft(Player p, List<ItemStack> stacks) {
}


public List<ItemStack> getMaterials() {
return this.mats.stream().map(x -> x.toStackForJei()).collect(Collectors.toList());
public List<List<ItemStack>> getMaterialsForJei() {
return this.mats.stream().map(CraftingMaterial::toStackForJei).collect(Collectors.toList());
}

public List<CraftingMaterial> getMaterials() {
return this.mats;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.robertx22.mine_and_slash.database.data.profession.Crafting_State;
import com.robertx22.mine_and_slash.database.data.profession.ProfessionBlockEntity;
import com.robertx22.mine_and_slash.database.data.profession.ProfessionRecipe;
import com.robertx22.mine_and_slash.mmorpg.registers.common.SlashContainers;
import com.robertx22.mine_and_slash.mmorpg.registers.common.items.SlashItems;
import net.minecraft.world.Container;
Expand Down Expand Up @@ -126,8 +127,8 @@ public boolean mayPlace(ItemStack pStack) {
if (be.last_recipe == null)
return false;

for (ItemStack item : be.last_recipe.getMaterials()) {
if (item.getItem() == pStack.getItem()) {
for (ProfessionRecipe.CraftingMaterial mat : be.last_recipe.getMaterials()) {
if (mat.hasAnyCount(pStack)) {
if (be.craftingState == Crafting_State.IDLE)
be.craftingState = Crafting_State.ACTIVE;
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ public void refreshRequiredMats(ProfessionRecipe recipe) {

int spacing = 18;

for (ItemStack stack : recipe.getMaterials()) {
var button = new ItemButton(stack, leftPos + 64 + xoff, topPos + 75 + yoff);
for (List<ItemStack> stack : recipe.getMaterialsForJei()) {
var button = new ItemButton(stack.isEmpty() ? ItemStack.EMPTY : stack.get(0), leftPos + 64 + xoff, topPos + 75 + yoff);

List<Component> tip = new ArrayList<>();
tip.add(Component.literal(UNICODE.CUBE + " ").append(Itemtips.RECIPE_MATERIAL.locName()).append(" " + UNICODE.CUBE).withStyle(ChatFormatting.RED, ChatFormatting.BOLD));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public enum Words implements IAutoLocName {
CRAFT_FAILED("Craft Failed due to incorrect materials"),
NO_ITEM_FOUND("\n- %1$s is missing"),
NOT_ENOUGH_ITEM_FOUND("\n- %1$s needs %2$s items but you only inserted %3$s "),
ANY_IN_TAG("Any Item in Tag #%1$s"),
OPTION_LOCKED_UNTIL_BOSS_KILLED("Option Locked Until Map Boss is Killed."),
MAP_IS_ALREADY_MAX_RARITY("Map is already at Maximum Rarity."),
NO_MAP_TO_UPGRADE("You don't have any map currently."),
Expand Down