What's inside?

- Blueprint crafting overlay now attempts to show a list of items matching an ingredient filter in the respective slot
- Fixed JEI prematurely transferring the blueprint recipe when viewed
This commit is contained in:
simibubi 2021-06-17 00:54:48 +02:00
parent bf1c86ed87
commit 06ca8b0d1c
3 changed files with 71 additions and 13 deletions

View file

@ -22,6 +22,8 @@ public class BlueprintTransferHandler implements IRecipeTransferHandler<Blueprin
PlayerEntity player, boolean maxTransfer, boolean doTransfer) {
if (!(recipe instanceof IRecipe))
return null;
if (!doTransfer)
return null;
IRecipe<?> iRecipe = (IRecipe<?>) recipe;
// Continued server-side in BlueprintItem.assignCompleteRecipe()
AllPackets.channel.sendToServer(new BlueprintAssignCompleteRecipePacket(iRecipe.getId()));

View file

@ -2,15 +2,19 @@ package com.simibubi.create.content.curiosities.tools;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import com.simibubi.create.AllItems;
import com.simibubi.create.content.curiosities.tools.BlueprintEntity.BlueprintCraftingInventory;
import com.simibubi.create.content.curiosities.tools.BlueprintEntity.BlueprintSection;
import com.simibubi.create.content.logistics.item.filter.AttributeFilterContainer.WhitelistMode;
import com.simibubi.create.content.logistics.item.filter.FilterItem;
import com.simibubi.create.content.logistics.item.filter.ItemAttribute;
import com.simibubi.create.foundation.gui.AllGuiTextures;
import com.simibubi.create.foundation.gui.GuiGameElement;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
@ -19,14 +23,21 @@ import com.simibubi.create.foundation.utility.Pair;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.crafting.ICraftingRecipe;
import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.ListNBT;
import net.minecraft.tags.ITag;
import net.minecraft.tags.TagCollectionManager;
import net.minecraft.util.math.EntityRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.RayTraceResult.Type;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.common.util.Constants.NBT;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.items.ItemStackHandler;
@ -37,6 +48,7 @@ public class BlueprintOverlayRenderer {
static boolean lastSneakState;
static BlueprintSection lastTargetedSection;
static Map<ItemStack, ItemStack[]> cachedRenderedFilters = new IdentityHashMap<>();
static List<Pair<ItemStack, Boolean>> ingredients = new ArrayList<>();
static ItemStack result = ItemStack.EMPTY;
static boolean resultCraftable = false;
@ -72,6 +84,7 @@ public class BlueprintOverlayRenderer {
}
public static void rebuild(BlueprintSection sectionAt, boolean sneak) {
cachedRenderedFilters.clear();
ItemStackHandler items = sectionAt.getItems();
boolean empty = true;
for (int i = 0; i < 9; i++) {
@ -206,13 +219,9 @@ public class BlueprintOverlayRenderer {
RenderSystem.enableBlend();
(pair.getSecond() ? AllGuiTextures.HOTSLOT_ACTIVE : AllGuiTextures.HOTSLOT).draw(ms, x, y);
ItemStack itemStack = pair.getFirst();
GuiGameElement.of(itemStack)
.at(x + 3, y + 3)
.render(ms);
mc.getItemRenderer()
.renderItemOverlayIntoGUI(mc.fontRenderer, itemStack, x + 3, y + 3,
pair.getSecond() || itemStack.getCount() == 1 ? null
: TextFormatting.GOLD.toString() + itemStack.getCount());
String count = pair.getSecond() || itemStack.getCount() == 1 ? null
: TextFormatting.GOLD.toString() + itemStack.getCount();
drawItemStack(ms, mc, x, y, itemStack, count);
x += 21;
}
@ -229,12 +238,59 @@ public class BlueprintOverlayRenderer {
} else {
(resultCraftable ? AllGuiTextures.HOTSLOT_SUPER_ACTIVE : AllGuiTextures.HOTSLOT).draw(ms,
resultCraftable ? x - 1 : x, resultCraftable ? y - 1 : y);
GuiGameElement.of(result)
.at(x + 3, y + 3)
.render(ms);
mc.getItemRenderer()
.renderItemOverlayIntoGUI(mc.fontRenderer, result, x + 3, y + 3, null);
drawItemStack(ms, mc, x, y, result, null);
}
}
public static void drawItemStack(MatrixStack ms, Minecraft mc, int x, int y, ItemStack itemStack, String count) {
if (itemStack.getItem() instanceof FilterItem) {
int step = AnimationTickHolder.getTicks(mc.world) / 10;
ItemStack[] itemsMatchingFilter = getItemsMatchingFilter(itemStack);
if (itemsMatchingFilter.length > 0)
itemStack = itemsMatchingFilter[step % itemsMatchingFilter.length];
}
GuiGameElement.of(itemStack)
.at(x + 3, y + 3)
.render(ms);
mc.getItemRenderer()
.renderItemOverlayIntoGUI(mc.fontRenderer, itemStack, x + 3, y + 3, count);
}
private static ItemStack[] getItemsMatchingFilter(ItemStack filter) {
return cachedRenderedFilters.computeIfAbsent(filter, itemStack -> {
CompoundNBT tag = itemStack.getOrCreateTag();
if (AllItems.FILTER.isIn(itemStack) && !tag.getBoolean("Blacklist")) {
ItemStackHandler filterItems = FilterItem.getFilterItems(itemStack);
List<ItemStack> list = new ArrayList<>();
for (int slot = 0; slot < filterItems.getSlots(); slot++) {
ItemStack stackInSlot = filterItems.getStackInSlot(slot);
if (!stackInSlot.isEmpty())
list.add(stackInSlot);
}
return list.toArray(new ItemStack[list.size()]);
}
if (AllItems.ATTRIBUTE_FILTER.isIn(itemStack)) {
WhitelistMode whitelistMode = WhitelistMode.values()[tag.getInt("WhitelistMode")];
ListNBT attributes = tag.getList("MatchedAttributes", NBT.TAG_COMPOUND);
if (whitelistMode == WhitelistMode.WHITELIST_DISJ && attributes.size() == 1) {
ItemAttribute fromNBT = ItemAttribute.fromNBT((CompoundNBT) attributes.get(0));
if (fromNBT instanceof ItemAttribute.InTag) {
ItemAttribute.InTag inTag = (ItemAttribute.InTag) fromNBT;
ITag<Item> itag = TagCollectionManager.getTagManager()
.getItems()
.get(inTag.tagName);
if (itag != null)
return Ingredient.fromTag(itag)
.getMatchingStacks();
}
}
}
return new ItemStack[0];
});
}
}

View file

@ -222,7 +222,7 @@ public interface ItemAttribute {
public static class InTag implements ItemAttribute {
ResourceLocation tagName;
public ResourceLocation tagName;
public InTag(ResourceLocation tagName) {
this.tagName = tagName;